18
18
Functions to autenticate and handle reqests for a connection
20
#include <drizzled/server_includes.h>
21
#include <drizzled/authentication.h>
22
#include <drizzled/drizzled_error_messages.h>
21
#include "mysql_priv.h"
24
23
#define MIN_HANDSHAKE_SIZE 6
70
69
should be done with this in mind; 'thd' is INOUT, all other params
72
@retval 0 OK; thd->security_ctx->user/master_access/priv_user/db_access and
73
thd->db are updated; OK is sent to the client.
74
74
@retval 1 error, e.g. access denied or handshake error, not sent to
75
75
the client. A message is pushed into the error stack.
79
79
check_user(THD *thd, enum enum_server_command command,
80
const char *passwd __attribute__((unused)),
81
81
uint passwd_len, const char *db,
84
84
LEX_STRING db_str= { (char *) db, db ? strlen(db) : 0 };
85
bool is_authenticated;
88
87
Clear thd->db as it points to something, that will be freed when
93
92
thd->reset_db(NULL, 0);
95
if (passwd_len != 0 && passwd_len != SCRAMBLE_LENGTH)
97
my_error(ER_HANDSHAKE_ERROR, MYF(0), thd->main_security_ctx.ip);
101
is_authenticated= authenticate_user(thd, passwd);
103
if (is_authenticated != true)
105
my_error(ER_ACCESS_DENIED_ERROR, MYF(0),
106
thd->main_security_ctx.user,
107
thd->main_security_ctx.ip,
108
passwd_len ? ER(ER_YES) : ER(ER_NO));
94
bool opt_secure_auth_local;
95
pthread_mutex_lock(&LOCK_global_system_variables);
96
opt_secure_auth_local= opt_secure_auth;
97
pthread_mutex_unlock(&LOCK_global_system_variables);
100
If the server is running in secure auth mode, short scrambles are
103
if (opt_secure_auth_local && passwd_len == SCRAMBLE_LENGTH_323)
105
my_error(ER_NOT_SUPPORTED_AUTH_MODE, MYF(0));
106
general_log_print(thd, COM_CONNECT, ER(ER_NOT_SUPPORTED_AUTH_MODE));
109
if (passwd_len != 0 &&
110
passwd_len != SCRAMBLE_LENGTH &&
111
passwd_len != SCRAMBLE_LENGTH_323)
113
my_error(ER_HANDSHAKE_ERROR, MYF(0), thd->main_security_ctx.host_or_ip);
114
117
USER_RESOURCES ur;
115
118
thd->security_ctx->skip_grants();
134
137
break-in attempts.
136
139
general_log_print(thd, command,
137
((char*) "%s@%s on %s"),
140
(thd->main_security_ctx.priv_user ==
141
thd->main_security_ctx.user ?
142
(char*) "%s@%s on %s" :
143
(char*) "%s@%s as anonymous on %s"),
138
144
thd->main_security_ctx.user,
139
thd->main_security_ctx.ip,
145
thd->main_security_ctx.host_or_ip,
140
146
db ? db : (char*) "");
149
This is the default access rights for the current database. It's
150
set to 0 here because we don't have an active database yet (and we
151
may not have an active database to set.
153
thd->main_security_ctx.db_access=0;
142
155
/* Change database if necessary */
240
253
thd->set_active_vio(net->vio);
256
if (!thd->main_security_ctx.host) // If TCP/IP connection
245
258
char ip[NI_MAXHOST];
247
260
if (vio_peer_addr(net->vio, ip, &thd->peer_port, NI_MAXHOST))
249
my_error(ER_BAD_HOST_ERROR, MYF(0), thd->main_security_ctx.ip);
262
my_error(ER_BAD_HOST_ERROR, MYF(0), thd->main_security_ctx.host_or_ip);
252
265
if (!(thd->main_security_ctx.ip= my_strdup(ip,MYF(MY_WME))))
253
266
return 1; /* The error is set by my_strdup(). */
267
thd->main_security_ctx.host_or_ip= thd->main_security_ctx.ip;
268
thd->main_security_ctx.host= ip_to_hostname(&net->vio->remote,
270
thd->main_security_ctx.host_or_ip= thd->main_security_ctx.host;
272
else /* Hostname given means that the connection was on a socket */
274
thd->main_security_ctx.host_or_ip= thd->main_security_ctx.host;
275
thd->main_security_ctx.ip= 0;
277
memset((char*) &net->vio->remote, 0, sizeof(net->vio->remote));
255
279
vio_keepalive(net->vio, true);
299
323
pkt_len < MIN_HANDSHAKE_SIZE)
301
325
my_error(ER_HANDSHAKE_ERROR, MYF(0),
302
thd->main_security_ctx.ip);
326
thd->main_security_ctx.host_or_ip);
330
#ifdef _CUSTOMCONFIG_
331
#include "_cust_sql_parse.h"
306
333
if (thd->packet.alloc(thd->variables.net_buffer_length))
307
334
return 1; /* The error is set by alloc(). */
309
336
thd->client_capabilities= uint2korr(net->read_pos);
312
thd->client_capabilities|= ((ulong) uint2korr(net->read_pos+2)) << 16;
313
thd->max_client_packet_length= uint4korr(net->read_pos+4);
314
thd_init_client_charset(thd, (uint) net->read_pos[8]);
315
thd->update_charset();
316
end= (char*) net->read_pos+32;
337
if (thd->client_capabilities & CLIENT_PROTOCOL_41)
339
thd->client_capabilities|= ((ulong) uint2korr(net->read_pos+2)) << 16;
340
thd->max_client_packet_length= uint4korr(net->read_pos+4);
341
thd_init_client_charset(thd, (uint) net->read_pos[8]);
342
thd->update_charset();
343
end= (char*) net->read_pos+32;
347
thd->max_client_packet_length= uint3korr(net->read_pos+2);
348
end= (char*) net->read_pos+5;
319
351
Disable those bits which are not supported by the server.
320
352
This is a precautionary measure, if the client lies. See Bug#27944.
327
359
if (end >= (char*) net->read_pos+ pkt_len +2)
330
my_error(ER_HANDSHAKE_ERROR, MYF(0), thd->main_security_ctx.ip);
362
my_error(ER_HANDSHAKE_ERROR, MYF(0), thd->main_security_ctx.host_or_ip);
365
397
if (passwd + passwd_len + db_len > (char *)net->read_pos + pkt_len)
367
my_error(ER_HANDSHAKE_ERROR, MYF(0), thd->main_security_ctx.ip);
399
my_error(ER_HANDSHAKE_ERROR, MYF(0), thd->main_security_ctx.host_or_ip);
493
525
sql_print_warning(ER(ER_NEW_ABORTING_CONNECTION),
494
526
thd->thread_id,(thd->db ? thd->db : "unconnected"),
495
527
sctx->user ? sctx->user : "unauthenticated",
497
529
(thd->main_da.is_error() ? thd->main_da.message() :
498
530
ER(ER_UNKNOWN_ERROR)));
535
567
sql_print_warning(ER(ER_NEW_ABORTING_CONNECTION),
536
568
thd->thread_id,(thd->db ? thd->db : "unconnected"),
537
569
sctx->user ? sctx->user : "unauthenticated",
538
sctx->ip, "init_connect command failed");
570
sctx->host_or_ip, "init_connect command failed");
539
571
sql_print_warning("%s", thd->main_da.message());
541
573
thd->proc_info=0;