[CONC-441] Default user name for C/C is wrong if login user is different from effective user Created: 2019-10-05 Updated: 2020-03-17 Resolved: 2020-03-12 |
|
| Status: | Closed |
| Project: | MariaDB Connector/C |
| Component/s: | None |
| Affects Version/s: | 3.1.3 |
| Fix Version/s: | 3.1.8 |
| Type: | Bug | Priority: | Major |
| Reporter: | Geoff Montee (Inactive) | Assignee: | Georg Richter |
| Resolution: | Fixed | Votes: | 2 |
| Labels: | None | ||
| Issue Links: |
|
||||||||||||||||||||
| Description |
|
For command-line tools, if no user name is provided, then the default behavior is supposed to be that the client will use the name of the current Unix user. From the MySQL documentation:
https://dev.mysql.com/doc/refman/5.7/en/user-names.html And from the MariaDB documentation:
https://mariadb.com/kb/en/library/mysql-command-line-client/ However, at the moment, the wrong user name is used by default if the login user is different from the effective user. How the Default User Name is DeterminedMariaDB Connector/C determines the default user name by calling read_user_name() to get the current user: https://github.com/MariaDB/mariadb-connector-c/blob/v3.1.3/libmariadb/mariadb_lib.c#L498 It is called in send_client_reply_packet(): https://github.com/MariaDB/mariadb-connector-c/blob/v3.1.3/plugins/auth/my_auth.c#L311 The read_user_name() function gets the user name by checking the following items in the following order:
This order can cause unexpected results in some cases. How to ReproduceFor example, let's say that we change users by doing something like this:
In this case, our effective user is mysql, but the login user is still ec2-user. Let's start tcpdump:
And then let's run a client without providing a user name:
Authentication will fail, because the user name is wrong. Let's read the tcpdump file:
The client handshake response looks like this for me:
We can see from the packet content that C/C thinks the user name is ec2-user instead of mysql. The error message sent by the server also references this incorrect ec2-user user name:
Suggested FixMariaDB Connector/C's version of the read_user_name() function should be fixed to use the effective user as the default user. |
| Comments |
| Comment by Geoff Montee (Inactive) [ 2019-10-08 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
I see that the read_user_name() function gets the user name by going through the following order:
See here: https://github.com/MariaDB/mariadb-connector-c/blob/v3.1.4/libmariadb/mariadb_lib.c#L499 I created a quick test program to check the return values of getlogin() and getpwuid(geteuid()):
This seems to indicate that getpwuid(geteuid()) returns the correct user name, but getlogin() does not. For example:
Since the connector defaults to the return value of getlogin(), this is why the mysql client is using the wrong user name:
| ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Georg Richter [ 2019-11-09 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
fixed in rev. e8023f3bf05839aaf4d797747f265822ea4a0514 | ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Geoff Montee (Inactive) [ 2019-11-09 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
This commit doesn't look like it would fix this issue: https://github.com/MariaDB/mariadb-connector-c/commit/e8023f3bf05839aaf4d797747f265822ea4a0514 As far as I can tell, the problem is that getlogin() is used over getpwuid(geteuid()). See my previous comment for a test program that shows the difference. | ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Michal Schorm [ 2020-03-12 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
Hello, Red Hat here, we've just got hit (rather) hard by this issue. — We have put MariaDB 10.4.12 into Fedora 32 - which is now in BETA freeze. Unfortunattely we were searching for the bug in auth_socket plugin, which is now default in MariaDB 10.4. — There are other packages, which builds on top of (or utilizes) MariaDB. Those packages have build-time tests which rely on switching the user. We would be grateful for fix or a workaround ASAP. We have only two spots left for the fix in Fedora - either for F32 Final Freeze, or as a F32 zero-day update (which would cause various other issues, since the F32 images would be distributed without the fix) — Thanks Geoff for the fine detective job | ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Georg Richter [ 2020-03-12 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
fixed. rev. 8c773db1fb4b59f2c428589398c7d47b88756aa5 | ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Geoff Montee (Inactive) [ 2020-03-12 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
Hi mschorm, georg's fix will be in MariaDB Connector/C 3.1.8, which should be released with MariaDB Server 10.4.13. I believe that release is currently planned for sometime around the end of April, but ralf.gebhardt@mariadb.com can correct me if I'm wrong. I hope that timeline works for you guys. Thanks! | ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Michal Schorm [ 2020-03-17 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
I can´t wait for the fix, but that's fine. This is our chance to get the fixed version available to the users with Fedora 32. Thanks for the patch ! |