an3l / my_playground

My playground with python, nginx, docker and server!
0 stars 0 forks source link

PR:1360 MYSQL_PWD env variable #12

Open an3l opened 4 years ago

an3l commented 4 years ago

First we have to test unix socket in mariadb:

unix_socket


MariaDB [(none)]> show grants; +-----------------------------------------------------------------------------------------------------------------------------------------+ | Grants for anel@localhost | +-----------------------------------------------------------------------------------------------------------------------------------------+ | GRANT ALL PRIVILEGES ON . TO 'anel'@'localhost' IDENTIFIED VIA mysql_native_password USING 'invalid' OR unix_socket WITH GRANT OPTION | +-----------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.000 sec)

MariaDB [(none)]> select user,host from mysql.user\G 1. row User: Host: localhost 2. row User: anel Host: localhost 3. row User: root Host: localhost 4. row User: Host: ubuntu 4 rows in set (0.002 sec)

M ariaDB [(none)]> select * from mysql.global_priv\G 1. row Host: localhost User: root Priv: {"access":18446744073709551615,"plugin":"mysql_native_password","authentication_string":"invalid","auth_or":[{},{"plugin":"unix_socket"}]} 2. row Host: localhost User: anel Priv: {"access":18446744073709551615,"plugin":"mysql_native_password","authentication_string":"invalid","auth_or":[{},{"plugin":"unix_socket"}]} 3. row Host: localhost User: Priv: {} 4. row Host: ubuntu User: Priv: {} 4 rows in set (0.000 sec)


+ Now let's try to connect with other user, not created yet `melisa`:
```sql
./client/mysql -u melisa
MariaDB [(none)]> select user(), current_user;
+------------------+--------------+
| user()           | current_user |
+------------------+--------------+
| melisa@localhost | @localhost   |
+------------------+--------------+
1 row in set (0.000 sec)

MariaDB [(none)]> show grants;
+--------------------------------------+
| Grants for @localhost                |
+--------------------------------------+
| GRANT USAGE ON *.* TO ''@'localhost' |
+--------------------------------------+
1 row in set (0.000 sec)

MariaDB [(none)]> select user,host from mysql.user\G
ERROR 1142 (42000): SELECT command denied to user ''@'localhost' for table 'user'

MariaDB [(none)]> select user,host from mysql.user\G 1. row User: melisa Host: %

Grant privileges

MariaDB [(none)]> show grants for melisa; +-------------------------------------------------------------------------------------------------------+ | Grants for melisa@% | +-------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON . TO 'melisa'@'%' IDENTIFIED BY PASSWORD '279018759837D91FAB7BB5939852F3E940F3334B' | +-------------------------------------------------------------------------------------------------------+ MariaDB [(none)]> grant all on . to melisa@localhost; ERROR 1133 (28000): Can't find any matching row in the user table MariaDB [(none)]> grant all on .* to 'melisa'@'%'; Query OK, 0 rows affected (0.001 sec) MariaDB [(none)]> flush privileges;

   + #### But I cannot to connect 
```sql
./client/mysql -umelisa -p
Enter password: 
2019-10-23  3:26:42 29 [Warning] Access denied for user 'melisa'@'localhost' (using password: YES)
ERROR 1045 (28000): Access denied for user 'melisa'@'localhost' (using password: YES)

mysql_real_connect(MYSQL mysql,const char host, const char user, const char passwd, const char db, uint port, const char unix_socket,ulong client_flag)

get_one_option()

argument, opt_password

< /proc/$(pidof mysql)/environ tr '\0' '\n' | grep MYSQL_PWD ???

TESTING THE PATCH

get_tty_password (opt_message=0x0) at mysys/get_password.c:149 (gdb) bt +bt

0 get_tty_password (opt_message=0x0) at mysys/get_password.c:149

1 0x00005555555b6da7 in get_options (argc=0, argv=0x555555c012c8) at client/mysql.cc:1977

2 0x00005555555b56bd in main (argc=4, argv=0x555555c012c0, envp=0x7fffffffdbc0) at client/mysql.cc:1199



I don't get it how to catch if on /proc/$pid/cmdline ?
cat /proc/77478/cmdline | strings -1
./sql/mysqld