1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

Client attributes

This commit is contained in:
unknown
2013-10-03 18:00:44 +03:00
parent dd7339676b
commit c776f5ac26
22 changed files with 597 additions and 27 deletions

View File

@ -638,7 +638,6 @@ void init_embedded_mysql(MYSQL *mysql, int client_flag)
thd->mysql= mysql;
mysql->server_version= server_version;
mysql->client_flag= client_flag;
//mysql->server_capabilities= client_flag;
init_alloc_root(&mysql->field_alloc, 8192, 0, MYF(0));
}
@ -698,12 +697,38 @@ err:
}
static void
emb_transfer_connect_attrs(MYSQL *mysql)
{
#ifdef HAVE_PSI_THREAD_INTERFACE
if (mysql->options.extension &&
mysql->options.extension->connection_attributes_length)
{
uchar *buf, *ptr;
THD *thd= (THD*)mysql->thd;
size_t length= mysql->options.extension->connection_attributes_length;
/* 9 = max length of the serialized length */
ptr= buf= (uchar *) my_alloca(length + 9);
send_client_connect_attrs(mysql, buf);
net_field_length_ll(&ptr);
PSI_THREAD_CALL(set_thread_connect_attrs)((char *) ptr, length, thd->charset());
my_afree(buf);
}
#endif
}
#ifdef NO_EMBEDDED_ACCESS_CHECKS
int check_embedded_connection(MYSQL *mysql, const char *db)
{
int result;
LEX_STRING db_str = { (char*)db, db ? strlen(db) : 0 };
THD *thd= (THD*)mysql->thd;
/* the server does the same as the client */
mysql->server_capabilities= mysql->client_flag;
thd_init_client_charset(thd, mysql->charset->number);
thd->update_charset();
Security_context *sctx= thd->security_ctx;
@ -713,6 +738,7 @@ int check_embedded_connection(MYSQL *mysql, const char *db)
sctx->user= my_strdup(mysql->user, MYF(0));
sctx->proxy_user[0]= 0;
sctx->master_access= GLOBAL_ACLS; // Full rights
emb_transfer_connect_attrs(mysql);
/* Change database if necessary */
if (!(result= (db && db[0] && mysql_change_db(thd, &db_str, FALSE))))
my_ok(thd);
@ -728,11 +754,16 @@ int check_embedded_connection(MYSQL *mysql, const char *db)
we emulate a COM_CHANGE_USER user here,
it's easier than to emulate the complete 3-way handshake
*/
char buf[USERNAME_LENGTH + SCRAMBLE_LENGTH + 1 + 2*NAME_LEN + 2], *end;
char *buf, *end;
NET *net= &mysql->net;
THD *thd= (THD*)mysql->thd;
Security_context *sctx= thd->security_ctx;
size_t connect_attrs_len=
(mysql->options.extension) ?
mysql->options.extension->connection_attributes_length : 0;
buf= my_alloca(USERNAME_LENGTH + SCRAMBLE_LENGTH + 1 + 2*NAME_LEN + 2 +
connect_attrs_len + 2);
if (mysql->options.client_ip)
{
sctx->host= my_strdup(mysql->options.client_ip, MYF(0));
@ -766,6 +797,13 @@ int check_embedded_connection(MYSQL *mysql, const char *db)
int2store(end, (ushort) mysql->charset->number);
end+= 2;
end= strmake(end, "mysql_native_password", NAME_LEN) + 1;
/* the server does the same as the client */
mysql->server_capabilities= mysql->client_flag;
end= (char *) send_client_connect_attrs(mysql, (uchar *) end);
/* acl_authenticate() takes the data from thd->net->read_pos */
thd->net.read_pos= (uchar*)buf;
@ -774,6 +812,7 @@ int check_embedded_connection(MYSQL *mysql, const char *db)
my_free(thd->security_ctx->user);
goto err;
}
my_afree(buf);
return 0;
err:
@ -781,6 +820,7 @@ err:
memcpy(net->sqlstate,
mysql_errno_to_sqlstate(thd->get_stmt_da()->sql_errno()),
sizeof(net->sqlstate)-1);
my_afree(buf);
return 1;
}
#endif