55
55
{ C_STRING_WITH_LEN("Quit") },
56
56
{ C_STRING_WITH_LEN("Init DB") },
57
57
{ C_STRING_WITH_LEN("Query") },
58
{ C_STRING_WITH_LEN("Field List") },
59
{ C_STRING_WITH_LEN("Create DB") },
60
{ C_STRING_WITH_LEN("Drop DB") },
61
{ C_STRING_WITH_LEN("Refresh") },
62
58
{ C_STRING_WITH_LEN("Shutdown") },
63
{ C_STRING_WITH_LEN("Processlist") },
64
59
{ C_STRING_WITH_LEN("Connect") },
65
{ C_STRING_WITH_LEN("Kill") },
66
60
{ C_STRING_WITH_LEN("Ping") },
67
{ C_STRING_WITH_LEN("Time") },
68
{ C_STRING_WITH_LEN("Change user") },
69
{ C_STRING_WITH_LEN("Connect Out") },
70
{ C_STRING_WITH_LEN("Set option") },
71
{ C_STRING_WITH_LEN("Daemon") },
72
61
{ C_STRING_WITH_LEN("Error") } // Last command number
483
case COM_CHANGE_USER:
485
status_var_increment(session->status_var.com_other);
486
char *user= (char*) packet, *packet_end= packet + packet_length;
487
/* Safe because there is always a trailing \0 at the end of the packet */
488
char *passwd= strchr(user, '\0')+1;
491
session->clear_error(); // if errors from rollback
494
Old clients send null-terminated string ('\0' for empty string) for
495
password. New clients send the size (1 byte) + string (not null
496
terminated, so also '\0' for empty string).
498
Cast *passwd to an unsigned char, so that it doesn't extend the sign
499
for *passwd > 127 and become 2**32-127 after casting to uint32_t.
501
char db_buff[NAME_LEN+1]; // buffer to store db in utf8
505
If there is no password supplied, the packet must contain '\0',
506
in any type of handshake (4.1 or pre-4.1).
508
if (passwd >= packet_end)
510
my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0));
513
uint32_t passwd_len= (session->client_capabilities & CLIENT_SECURE_CONNECTION ?
514
(unsigned char)(*passwd++) : strlen(passwd));
515
uint32_t dummy_errors, save_db_length, db_length;
517
USER_CONN *save_user_connect;
522
Database name is always NUL-terminated, so in case of empty database
523
the packet must contain at least the trailing '\0'.
525
if (db >= packet_end)
527
my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0));
530
db_length= strlen(db);
532
char *ptr= db + db_length + 1;
533
uint32_t cs_number= 0;
535
if (ptr < packet_end)
537
if (ptr + 2 > packet_end)
539
my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0));
543
cs_number= uint2korr(ptr);
546
/* Convert database name to utf8 */
547
db_buff[copy_and_convert(db_buff, sizeof(db_buff)-1,
548
system_charset_info, db, db_length,
549
session->charset(), &dummy_errors)]= 0;
552
/* Save user and privileges */
553
save_db_length= session->db_length;
554
save_db= session->db;
555
save_user_connect= session->user_connect;
557
old_username= session->security_ctx.user;
558
session->security_ctx.user.assign(user);
560
/* Clear variables that are allocated */
561
session->user_connect= 0;
562
res= check_user(session, passwd, passwd_len, db);
566
session->security_ctx.user= old_username;
567
session->user_connect= save_user_connect;
568
session->db= save_db;
569
session->db_length= save_db_length;
578
session->update_charset();
585
474
if (alloc_query(session, packet, packet_length))
628
case COM_FIELD_LIST: // This isn't actually needed
630
char *fields, *packet_end= packet + packet_length, *arg_end;
631
/* Locked closure of all tables */
632
TableList table_list;
633
LEX_STRING conv_name;
635
/* used as fields initializator */
638
status_var_increment(session->status_var.com_stat[SQLCOM_SHOW_FIELDS]);
639
memset(&table_list, 0, sizeof(table_list));
640
if (session->copy_db_to(&table_list.db, &table_list.db_length))
643
We have name + wildcard in packet, separated by endzero
645
arg_end= strchr(packet, '\0');
646
session->convert_string(&conv_name, system_charset_info,
647
packet, (uint32_t) (arg_end - packet), session->charset());
648
table_list.alias= table_list.table_name= conv_name.str;
651
if (!my_strcasecmp(system_charset_info, table_list.db,
652
INFORMATION_SCHEMA_NAME.c_str()))
654
ST_SCHEMA_TABLE *schema_table= find_schema_table(session, table_list.alias);
656
table_list.schema_table= schema_table;
659
session->query_length= (uint32_t) (packet_end - packet); // Don't count end \0
660
if (!(session->query=fields= (char*) session->memdup(packet,session->query_length+1)))
662
if (lower_case_table_names)
663
my_casedn_str(files_charset_info, table_list.table_name);
665
/* init structures for VIEW processing */
666
table_list.select_lex= &(session->lex->select_lex);
669
session->reset_for_next_command();
672
select_lex.table_list.link_in_list((unsigned char*) &table_list,
673
(unsigned char**) &table_list.next_local);
674
session->lex->add_to_query_tables(&table_list);
676
/* switch on VIEW optimisation: do not fill temporary tables */
677
session->lex->sql_command= SQLCOM_SHOW_FIELDS;
678
mysqld_list_fields(session,&table_list,fields);
679
session->lex->unit.cleanup();
680
session->cleanup_after_query();
684
518
/* We don't calculate statistics for this command */
685
519
net->error=0; // Don't give 'abort' message
699
533
status_var_increment(session->status_var.com_other);
700
534
session->my_ok(); // Tell client we are alive
702
case COM_PROCESS_INFO:
703
status_var_increment(session->status_var.com_stat[SQLCOM_SHOW_PROCESSLIST]);
704
mysqld_list_processes(session, NULL, 0);
706
case COM_PROCESS_KILL:
708
status_var_increment(session->status_var.com_stat[SQLCOM_KILL]);
709
ulong id=(ulong) uint4korr(packet);
710
sql_kill(session,id,false);
715
status_var_increment(session->status_var.com_stat[SQLCOM_SET_OPTION]);
716
uint32_t opt_command= uint2korr(packet);
718
switch (opt_command) {
719
case (int) DRIZZLE_OPTION_MULTI_STATEMENTS_ON:
720
session->client_capabilities|= CLIENT_MULTI_STATEMENTS;
723
case (int) DRIZZLE_OPTION_MULTI_STATEMENTS_OFF:
724
session->client_capabilities&= ~CLIENT_MULTI_STATEMENTS;
728
my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0));
734
537
case COM_CONNECT: // Impossible here
735
case COM_TIME: // Impossible from client
738
540
my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0));