mcshadow: ~ $ mysql --user = mcshadow --password = mike mysql> select current_user (); + ---------------- + | current_user () | + ---------------- + | mike @ localhost | + ---------------- + mcshadow: ~ $ mysql --user = mcshadow --password = root mysql> select current_user (); + ---------------- + | current_user () | + ---------------- + | root @ localhost | + ---------------- +
mike: ~ $ mysql --user = mcshadow --password = mike ERROR 1698 (28000): Access denied for user 'mcshadow' @ 'localhost'
mysqld: User: mcshadow TRY access from: localhost with privileges: mike
mysqld: User: mcshadow SUCCESS access from: localhost with privileges: mike
mysql: SYSTEM_USER: 'mcshadow', MYSQL_USER: 'mcshadow', CONNECTION_ID: 5, DB_SERVER: '-', DB: '-', COMMAND_RESULT: SUCCESS, QUERY: 'select current_user ();'
mysqld: User: mcshadow TRY access from: localhost with privileges: root
mysqld: User: mcshadow SUCCESS access from: localhost with privileges: root
mysql: SYSTEM_USER: 'mcshadow', MYSQL_USER: 'mcshadow', CONNECTION_ID: 6, DB_SERVER: '-', DB: '-', COMMAND_RESULT: SUCCESS, QUERY: 'select current_user ();'
mysqld: User: mcshadow TRY access from: localhost with privileges: mike
mysqld: User: mcshadow FAILED access from: localhost with privileges: mike
GRANT PROXY ON 'priv_user' @ 'localhost' TO 'real_user' @ 'localhost';
CREATE USER 'real_user' @ 'localhost' IDENTIFIED WITH 'auth_plugin_xxx' AS 'auth_string';
#include <violite.h> // Linux syslog #ifndef __WIN__ #include "syslog.h" #endif ... void tee_putc(int c, FILE *file); // void write_syslog(String *buffer); ... // Percona . : mysql_error(&mysql)[0] void write_syslog(String *line){ #ifndef __WIN__ uint length= line->length(); uint chunk_len= min(MAX_SYSLOG_MESSAGE, length); char *ptr= line->c_ptr_safe(); char buff[MAX_SYSLOG_MESSAGE + 1]; for (; length; length-= chunk_len, ptr+= chunk_len, chunk_len= min(MAX_SYSLOG_MESSAGE, length)) { char *str; if (length == chunk_len) str= ptr; // last chunk => skip copy else { memcpy(buff, ptr, chunk_len); buff[chunk_len]= '\0'; str= buff; } syslog(LOG_INFO, "SYSTEM_USER:'%s', MYSQL_USER:'%s', CONNECTION_ID:%lu, " "DB_SERVER:'%s', DB:'%s', COMMAND_RESULT:%s, QUERY:'%s'", getenv("SUDO_USER") ? getenv("SUDO_USER") : getenv("USER") ? getenv("USER") : "--", current_user ? current_user : "--", mysql_thread_id(&mysql), current_host ? current_host : "--", current_db ? current_db : "--", mysql_error(&mysql)[0]?"FAILED":"SUCCESS", str); } #endif } ... #endif /*HAVE_READLINE*/ // #ifndef __WIN__ if (buffer->length() && connect_flag == CLIENT_INTERACTIVE){ write_syslog(buffer); } #endif
// PCI DSS patch #ifndef __WIN__ #include "syslog.h" #endif // end PCI DSS patch ... // login_failed_error - general_log_print(thd, COM_CONNECT, ER(ER_ACCESS_DENIED_NO_PASSWORD_ERROR), mpvio->auth_info.user_name, mpvio->auth_info.host_or_ip); // PCI DSS patch syslog(LOG_WARNING, "User:%s FAILED access from:%s with privileges:%s", mpvio->auth_info.user_name, mpvio->auth_info.host_or_ip, mpvio->auth_info.authenticated_as); // end PCI DSS patch ... general_log_print(thd, COM_CONNECT, ER(ER_ACCESS_DENIED_ERROR), mpvio->auth_info.user_name, mpvio->auth_info.host_or_ip, passwd_used ? ER(ER_YES) : ER(ER_NO)); // PCI DSS patch syslog(LOG_WARNING, "User:%s FAILED access from:%s with privileges:%s", mpvio->auth_info.user_name, mpvio->auth_info.host_or_ip, mpvio->auth_info.authenticated_as); // end PCI DSS patch ... // secure_auth - if (mpvio->client_capabilities & CLIENT_PROTOCOL_41) { my_error(ER_SERVER_IS_IN_SECURE_AUTH_MODE, MYF(0), mpvio->auth_info.user_name, mpvio->auth_info.host_or_ip); general_log_print(thd, COM_CONNECT, ER(ER_SERVER_IS_IN_SECURE_AUTH_MODE), mpvio->auth_info.user_name, mpvio->auth_info.host_or_ip); // PCI DSS patch syslog(LOG_WARNING, "User:%s FAILED access from:%s with privileges:%s", mpvio->auth_info.user_name, mpvio->auth_info.host_or_ip, mpvio->auth_info.authenticated_as); // end PCI DSS patch } else { my_error(ER_NOT_SUPPORTED_AUTH_MODE, MYF(0)); general_log_print(thd, COM_CONNECT, ER(ER_NOT_SUPPORTED_AUTH_MODE)); // PCI DSS patch syslog(LOG_WARNING, "Auth mode not supported"); // end PCI DSS patch } ... // send_plugin_request_packet - general_log_print(current_thd, COM_CONNECT, ER(ER_NOT_SUPPORTED_AUTH_MODE)); // PCI DSS patch syslog(LOG_WARNING, "Auth mode not supported"); // end PCI DSS patch ... // find_mpvio_user general_log_print(current_thd, COM_CONNECT, ER(ER_NOT_SUPPORTED_AUTH_MODE)); // PCI DSS patch syslog(LOG_WARNING, "Auth mode not supported"); // end PCI DSS patch ... // acl_authenticate - main if (strcmp(mpvio.auth_info.authenticated_as, mpvio.auth_info.user_name)) { general_log_print(thd, command, "%s@%s as %s on %s", mpvio.auth_info.user_name, mpvio.auth_info.host_or_ip, mpvio.auth_info.authenticated_as ? mpvio.auth_info.authenticated_as : "anonymous", mpvio.db.str ? mpvio.db.str : (char*) ""); // PCI DSS patch syslog(LOG_WARNING, "User:%s TRY access from:%s with privileges:%s", mpvio.auth_info.user_name, mpvio.auth_info.host_or_ip, mpvio.auth_info.authenticated_as); // end PCI DSS patch } else { general_log_print(thd, command, (char*) "%s@%s on %s", mpvio.auth_info.user_name, mpvio.auth_info.host_or_ip, mpvio.db.str ? mpvio.db.str : (char*) ""); // PCI DSS patch syslog(LOG_WARNING, "User:%s TRY access from:%s with privileges:%s", mpvio.auth_info.user_name, mpvio.auth_info.host_or_ip, mpvio.auth_info.authenticated_as); // end PCI DSS patch } ... if (res > CR_OK && mpvio.status != MPVIO_EXT::SUCCESS) { DBUG_ASSERT(mpvio.status == MPVIO_EXT::FAILURE); if (!thd->is_error()) login_failed_error(&mpvio, mpvio.auth_info.password_used); DBUG_RETURN (1); } // PCI DSS patch else syslog(LOG_WARNING, "User:%s SUCCESS access from:%s with privileges:%s", mpvio.auth_info.user_name, mpvio.auth_info.host_or_ip, mpvio.auth_info.authenticated_as); // end PCI DSS patch
general_log_print(thd, COM_INIT_DB, ER(ER_DBACCESS_DENIED_ERROR), sctx->priv_user, sctx->priv_host, new_db_file_name.str); // PCI DSS patch syslog(LOG_WARNING, "User:%s FAILED access from:%s with privileges:%s", sctx->proxy_user, sctx->priv_host, sctx->priv_user); // end PCI DSS patch
general_log_print(thd,COM_INIT_DB,ER(ER_DBACCESS_DENIED_ERROR), sctx->priv_user, sctx->host_or_ip, dbname); // PCI DSS patch syslog(LOG_WARNING, "User:%s FAILED access from:%s with privileges:%s", sctx->proxy_user, sctx->priv_host, sctx->priv_user); // end PCI DSS patch
#define PASSWORD_USED_NO 0 #define PASSWORD_USED_YES 1 #define PASSWORD_USED_NO_MENTION 2
static int auth_test_plugin(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info) { unsigned char *pkt; int pkt_len; MYSQL_PLUGIN_VIO_INFO vio_info; struct ucred cred; socklen_t cred_len= sizeof(cred); struct passwd pwd_buf, *pwd; char buf[1024]; /* */ if (vio->write_packet(vio, (const unsigned char *) PASSWORD_QUESTION, 1)) return CR_ERROR; /* */ if ((pkt_len= vio->read_packet(vio, &pkt)) < 0) return CR_ERROR; /* */ info->password_used= PASSWORD_USED_NO_MENTION; /* */ strcpy (info->authenticated_as, (const char *) pkt); vio->info(vio, &vio_info); if (vio_info.protocol != MYSQL_VIO_SOCKET) return CR_ERROR; /* get the UID of the client process */ if (getsockopt(vio_info.socket, SOL_SOCKET, SO_PEERCRED, &cred, &cred_len)) return CR_ERROR; if (cred_len != sizeof(cred)) return CR_ERROR; /* and find the username for this uid */ getpwuid_r(cred.uid, &pwd_buf, buf, sizeof(buf), &pwd); if (pwd == NULL) return CR_ERROR; /* MySQL */ return strcmp(pwd->pw_name, info->user_name) ? CR_ERROR : CR_OK; }
cmake -DCMAKE_INSTALL_PREFIX = / opt / mysql-5.5.15 - this is the folder where we put, you do not want to kill your muscular. make make install
install plugin test_plugin_server soname 'auth_test_plugin.so'; show plugins; + ----------------------- + -------- + ---------------- ---- + --------------------- + --------- + | Name | Status | Type | Library | License | + ----------------------- + -------- + ---------------- ---- + --------------------- + --------- + ... | test_plugin_server | ACTIVE | AUTHENTICATION | auth_test_plugin.so | GPL | + ----------------------- + -------- + ---------------- ---- + --------------------- + --------- + create user 'mike' @ 'localhost'; create user 'mcshadow' @ 'localhost' identified with 'test_plugin_server' as 'volki'; grant proxy on 'root' @ 'localhost' to 'mcshadow' @ 'localhost'; grant proxy on 'mike' @ 'localhost' to 'mcshadow' @ 'localhost'; select * from mysql.proxies_priv; + ----------- + ---------- + ----------------- + -------- ------ + ------------ + ---------------- + ------------- -------- + | Host | User | Proxied_host | Proxied_user | With_grant | Grantor | Timestamp | + ----------- + ---------- + ----------------- + -------- ------ + ------------ + ---------------- + ------------- -------- + ... | localhost | mcshadow | localhost | root | 0 | root @ localhost | 2011-08-17 01:15:09 | | localhost | mcshadow | localhost | mike | 0 | root @ localhost | 2011-08-17 01:30:35 | + ----------- + ---------- + ----------------- + -------- ------ + ------------ + ---------------- + ------------- -------- +
Source: https://habr.com/ru/post/126519/
All Articles