Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Unable to commit transaction" when running a CALL in Sendmail.conf #639

Closed
scotia70 opened this issue Jan 14, 2021 · 1 comment · Fixed by #670
Closed

"Unable to commit transaction" when running a CALL in Sendmail.conf #639

scotia70 opened this issue Jan 14, 2021 · 1 comment · Fixed by #670
Assignees
Milestone

Comments

@scotia70
Copy link

I'm bringing this over from cyrusimap/cyrus-imapd#2792 at the urging of @dilyanpalauzov.

I won't recapitulate the entire thread; here's the gist:

Hi,

I'm using cyrus-sasl-sql 2.1.27 on FreeBSD 11 and 12 and builtin sendmail.
I use Cyrus SASL to authenticate SMTP users.
My /usr/local/lib/sasl2/Sendmail.conf looks like:

auxprop_plugin: sql
sql_engine: mysql
sql_user: xxx
sql_passwd: yyy
sql_hostnames: sql-host
sql_database: userdb
sql_select: CALL select_smtp_password('%u')
sql_usessl: no
log_level: 3

When inbound SMTP users perform a LOGIN my auth.log is populated with:

Jun  8 17:48:03 mail-01 sm-mta[93492]: Unable to commit transaction
Jun  8 17:48:03 mail-01 sm-mta[93492]: sql query failed: Commands out of sync; you can't run this command now
Jun  8 17:48:03 mail-01 sm-mta[93492]: sql query failed: Commands out of sync; you can't run this command now
Jun  8 17:48:03 mail-01 sm-mta[93492]: Unable to commit transaction`
for each LOGIN attempt.

Note that the query succeeds and everything works. I'm wondering if using a stored procedure and a CALL (which I do) is interacting poorly with the ./plugins/sql.c code (which I assume is normally called with an SQL SELECT statement).

I have tried two variants of the stored procedure:

START TRANSACTION;
INSERT INTO smtp_auths (name,count,last) VALUES (my_id,'1',NOW()) ON DUPLICATE KEY UPDATE count=count+1, last=NOW();
COMMIT;
SELECT clear FROM userdb WHERE id = my_id AND smtpauth = 'Y';
END

AND

INSERT INTO smtp_auths (name,count,last) VALUES (my_id,'1',NOW()) ON DUPLICATE KEY UPDATE count=count+1, last=NOW();
SELECT clear FROM userdb WHERE id = my_id AND smtpauth = 'Y';
END

I think the final "settings->sql_engine->sql_commit_txn" in ./plugins/sql.c is perhaps the culprit.

@scotia70
Copy link
Author

And the fix:

Because of nature of the CALL statement, there is residual return data that needs to be consumed before another query can be made.

See https://bugs.mysql.com/bug.php?id=71044

My fix was to add the line:

mysql_next_result(conn);

after

mysql_free_result(result);

(line 158 of plugins/sql.c).

The change works regardless of the type of query (SELECT or CALL).

@quanah quanah added this to the 2.1.28 milestone Jun 21, 2021
@quanah quanah self-assigned this Oct 12, 2021
quanah added a commit to quanah/cyrus-sasl that referenced this issue Oct 12, 2021
quanah added a commit to quanah/cyrus-sasl that referenced this issue Oct 12, 2021
quanah added a commit to quanah/cyrus-sasl that referenced this issue Oct 12, 2021
quanah added a commit to quanah/cyrus-sasl that referenced this issue Oct 13, 2021
@quanah quanah linked a pull request Oct 13, 2021 that will close this issue
quanah added a commit that referenced this issue Oct 14, 2021
quanah added a commit that referenced this issue Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants