2011-06-30 17:37:13 +02:00
|
|
|
/*
|
2011-07-03 17:47:37 +02:00
|
|
|
Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
|
2007-02-23 12:13:55 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; version 2 of the License.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2011-06-30 17:37:13 +02:00
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2007-02-23 12:13:55 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Functions to autenticate and handle reqests for a connection
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mysql_priv.h"
|
|
|
|
|
2011-05-09 12:57:17 +02:00
|
|
|
/** Size of the header fields of an authentication packet. */
|
|
|
|
#define AUTH_PACKET_HEADER_SIZE_PROTO_41 32
|
|
|
|
#define AUTH_PACKET_HEADER_SIZE_PROTO_40 5
|
2011-07-01 16:15:50 +02:00
|
|
|
#define AUTH_PACKET_HEADER_SIZE_CONNJ_SSL 4
|
2007-02-23 12:13:55 +01:00
|
|
|
|
|
|
|
#ifdef __WIN__
|
2008-02-19 14:25:26 +01:00
|
|
|
extern void win_install_sigabrt_handler();
|
2007-02-23 12:13:55 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
Get structure for logging connection data for the current user
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
|
|
|
static HASH hash_user_connections;
|
|
|
|
|
|
|
|
static int get_or_create_user_conn(THD *thd, const char *user,
|
|
|
|
const char *host,
|
|
|
|
USER_RESOURCES *mqh)
|
|
|
|
{
|
|
|
|
int return_val= 0;
|
2009-02-13 17:41:47 +01:00
|
|
|
size_t temp_len, user_len;
|
2007-02-23 12:13:55 +01:00
|
|
|
char temp_user[USER_HOST_BUFF_SIZE];
|
|
|
|
struct user_conn *uc;
|
|
|
|
|
|
|
|
DBUG_ASSERT(user != 0);
|
|
|
|
DBUG_ASSERT(host != 0);
|
|
|
|
|
|
|
|
user_len= strlen(user);
|
|
|
|
temp_len= (strmov(strmov(temp_user, user)+1, host) - temp_user)+1;
|
|
|
|
(void) pthread_mutex_lock(&LOCK_user_conn);
|
|
|
|
if (!(uc = (struct user_conn *) hash_search(&hash_user_connections,
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
(uchar*) temp_user, temp_len)))
|
2007-02-23 12:13:55 +01:00
|
|
|
{
|
|
|
|
/* First connection for user; Create a user connection object */
|
|
|
|
if (!(uc= ((struct user_conn*)
|
|
|
|
my_malloc(sizeof(struct user_conn) + temp_len+1,
|
|
|
|
MYF(MY_WME)))))
|
|
|
|
{
|
2007-10-31 22:10:58 +01:00
|
|
|
/* MY_WME ensures an error is set in THD. */
|
2007-02-23 12:13:55 +01:00
|
|
|
return_val= 1;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
uc->user=(char*) (uc+1);
|
|
|
|
memcpy(uc->user,temp_user,temp_len+1);
|
|
|
|
uc->host= uc->user + user_len + 1;
|
|
|
|
uc->len= temp_len;
|
|
|
|
uc->connections= uc->questions= uc->updates= uc->conn_per_hour= 0;
|
|
|
|
uc->user_resources= *mqh;
|
2007-07-30 10:33:50 +02:00
|
|
|
uc->reset_utime= thd->thr_create_utime;
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
if (my_hash_insert(&hash_user_connections, (uchar*) uc))
|
2007-02-23 12:13:55 +01:00
|
|
|
{
|
2007-10-31 22:10:58 +01:00
|
|
|
/* The only possible error is out of memory, MY_WME sets an error. */
|
2007-02-23 12:13:55 +01:00
|
|
|
my_free((char*) uc,0);
|
|
|
|
return_val= 1;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
thd->user_connect=uc;
|
|
|
|
uc->connections++;
|
|
|
|
end:
|
|
|
|
(void) pthread_mutex_unlock(&LOCK_user_conn);
|
|
|
|
return return_val;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
check if user has already too many connections
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
check_for_max_user_connections()
|
|
|
|
thd Thread handle
|
|
|
|
uc User connect object
|
|
|
|
|
|
|
|
NOTES
|
|
|
|
If check fails, we decrease user connection count, which means one
|
|
|
|
shouldn't call decrease_user_connections() after this function.
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 ok
|
|
|
|
1 error
|
|
|
|
*/
|
|
|
|
|
2007-10-31 22:10:58 +01:00
|
|
|
static
|
2007-02-23 12:13:55 +01:00
|
|
|
int check_for_max_user_connections(THD *thd, USER_CONN *uc)
|
|
|
|
{
|
|
|
|
int error=0;
|
|
|
|
DBUG_ENTER("check_for_max_user_connections");
|
|
|
|
|
|
|
|
(void) pthread_mutex_lock(&LOCK_user_conn);
|
|
|
|
if (max_user_connections && !uc->user_resources.user_conn &&
|
|
|
|
max_user_connections < (uint) uc->connections)
|
|
|
|
{
|
2007-10-31 22:10:58 +01:00
|
|
|
my_error(ER_TOO_MANY_USER_CONNECTIONS, MYF(0), uc->user);
|
2007-02-23 12:13:55 +01:00
|
|
|
error=1;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
time_out_user_resource_limits(thd, uc);
|
|
|
|
if (uc->user_resources.user_conn &&
|
|
|
|
uc->user_resources.user_conn < uc->connections)
|
|
|
|
{
|
2007-10-31 22:10:58 +01:00
|
|
|
my_error(ER_USER_LIMIT_REACHED, MYF(0), uc->user,
|
|
|
|
"max_user_connections",
|
|
|
|
(long) uc->user_resources.user_conn);
|
2007-02-23 12:13:55 +01:00
|
|
|
error= 1;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
if (uc->user_resources.conn_per_hour &&
|
|
|
|
uc->user_resources.conn_per_hour <= uc->conn_per_hour)
|
|
|
|
{
|
2007-10-31 22:10:58 +01:00
|
|
|
my_error(ER_USER_LIMIT_REACHED, MYF(0), uc->user,
|
|
|
|
"max_connections_per_hour",
|
|
|
|
(long) uc->user_resources.conn_per_hour);
|
2007-02-23 12:13:55 +01:00
|
|
|
error=1;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
uc->conn_per_hour++;
|
|
|
|
|
2007-10-31 22:10:58 +01:00
|
|
|
end:
|
2007-02-23 12:13:55 +01:00
|
|
|
if (error)
|
|
|
|
uc->connections--; // no need for decrease_user_connections() here
|
|
|
|
(void) pthread_mutex_unlock(&LOCK_user_conn);
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Decrease user connection count
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
decrease_user_connections()
|
|
|
|
uc User connection object
|
|
|
|
|
|
|
|
NOTES
|
|
|
|
If there is a n user connection object for a connection
|
|
|
|
(which only happens if 'max_user_connections' is defined or
|
|
|
|
if someone has created a resource grant for a user), then
|
|
|
|
the connection count is always incremented on connect.
|
|
|
|
|
|
|
|
The user connect object is not freed if some users has
|
|
|
|
'max connections per hour' defined as we need to be able to hold
|
|
|
|
count over the lifetime of the connection.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void decrease_user_connections(USER_CONN *uc)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("decrease_user_connections");
|
|
|
|
(void) pthread_mutex_lock(&LOCK_user_conn);
|
|
|
|
DBUG_ASSERT(uc->connections);
|
|
|
|
if (!--uc->connections && !mqh_used)
|
|
|
|
{
|
|
|
|
/* Last connection for user; Delete it */
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
(void) hash_delete(&hash_user_connections,(uchar*) uc);
|
2007-02-23 12:13:55 +01:00
|
|
|
}
|
|
|
|
(void) pthread_mutex_unlock(&LOCK_user_conn);
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Reset per-hour user resource limits when it has been more than
|
|
|
|
an hour since they were last checked
|
|
|
|
|
|
|
|
SYNOPSIS:
|
|
|
|
time_out_user_resource_limits()
|
|
|
|
thd Thread handler
|
|
|
|
uc User connection details
|
|
|
|
|
|
|
|
NOTE:
|
|
|
|
This assumes that the LOCK_user_conn mutex has been acquired, so it is
|
|
|
|
safe to test and modify members of the USER_CONN structure.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void time_out_user_resource_limits(THD *thd, USER_CONN *uc)
|
|
|
|
{
|
2007-07-30 10:33:50 +02:00
|
|
|
ulonglong check_time= thd->start_utime;
|
2007-02-23 12:13:55 +01:00
|
|
|
DBUG_ENTER("time_out_user_resource_limits");
|
|
|
|
|
|
|
|
/* If more than a hour since last check, reset resource checking */
|
2007-07-30 10:33:50 +02:00
|
|
|
if (check_time - uc->reset_utime >= LL(3600000000))
|
2007-02-23 12:13:55 +01:00
|
|
|
{
|
|
|
|
uc->questions=1;
|
|
|
|
uc->updates=0;
|
|
|
|
uc->conn_per_hour=0;
|
2007-07-30 10:33:50 +02:00
|
|
|
uc->reset_utime= check_time;
|
2007-02-23 12:13:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Check if maximum queries per hour limit has been reached
|
|
|
|
returns 0 if OK.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool check_mqh(THD *thd, uint check_command)
|
|
|
|
{
|
|
|
|
bool error= 0;
|
|
|
|
USER_CONN *uc=thd->user_connect;
|
|
|
|
DBUG_ENTER("check_mqh");
|
|
|
|
DBUG_ASSERT(uc != 0);
|
|
|
|
|
|
|
|
(void) pthread_mutex_lock(&LOCK_user_conn);
|
|
|
|
|
|
|
|
time_out_user_resource_limits(thd, uc);
|
|
|
|
|
|
|
|
/* Check that we have not done too many questions / hour */
|
|
|
|
if (uc->user_resources.questions &&
|
|
|
|
uc->questions++ >= uc->user_resources.questions)
|
|
|
|
{
|
2007-10-31 22:10:58 +01:00
|
|
|
my_error(ER_USER_LIMIT_REACHED, MYF(0), uc->user, "max_questions",
|
|
|
|
(long) uc->user_resources.questions);
|
2007-02-23 12:13:55 +01:00
|
|
|
error=1;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
if (check_command < (uint) SQLCOM_END)
|
|
|
|
{
|
|
|
|
/* Check that we have not done too many updates / hour */
|
|
|
|
if (uc->user_resources.updates &&
|
|
|
|
(sql_command_flags[check_command] & CF_CHANGES_DATA) &&
|
|
|
|
uc->updates++ >= uc->user_resources.updates)
|
|
|
|
{
|
2007-10-31 22:10:58 +01:00
|
|
|
my_error(ER_USER_LIMIT_REACHED, MYF(0), uc->user, "max_updates",
|
|
|
|
(long) uc->user_resources.updates);
|
2007-02-23 12:13:55 +01:00
|
|
|
error=1;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end:
|
|
|
|
(void) pthread_mutex_unlock(&LOCK_user_conn);
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* NO_EMBEDDED_ACCESS_CHECKS */
|
|
|
|
|
|
|
|
|
2007-10-31 22:10:58 +01:00
|
|
|
/**
|
|
|
|
Check if user exist and password supplied is correct.
|
|
|
|
|
|
|
|
@param thd thread handle, thd->security_ctx->{host,user,ip} are used
|
|
|
|
@param command originator of the check: now check_user is called
|
|
|
|
during connect and change user procedures; used for
|
|
|
|
logging.
|
|
|
|
@param passwd scrambled password received from client
|
|
|
|
@param passwd_len length of scrambled password
|
|
|
|
@param db database name to connect to, may be NULL
|
|
|
|
@param check_count TRUE if establishing a new connection. In this case
|
|
|
|
check that we have not exceeded the global
|
|
|
|
max_connections limist
|
|
|
|
|
|
|
|
@note Host, user and passwd may point to communication buffer.
|
|
|
|
Current implementation does not depend on that, but future changes
|
|
|
|
should be done with this in mind; 'thd' is INOUT, all other params
|
|
|
|
are 'IN'.
|
|
|
|
|
|
|
|
@retval 0 OK; thd->security_ctx->user/master_access/priv_user/db_access and
|
|
|
|
thd->db are updated; OK is sent to the client.
|
|
|
|
@retval 1 error, e.g. access denied or handshake error, not sent to
|
|
|
|
the client. A message is pushed into the error stack.
|
2007-02-23 12:13:55 +01:00
|
|
|
*/
|
|
|
|
|
2007-10-31 22:10:58 +01:00
|
|
|
int
|
|
|
|
check_user(THD *thd, enum enum_server_command command,
|
2007-02-23 12:13:55 +01:00
|
|
|
const char *passwd, uint passwd_len, const char *db,
|
|
|
|
bool check_count)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("check_user");
|
2007-03-29 20:11:17 +02:00
|
|
|
LEX_STRING db_str= { (char *) db, db ? strlen(db) : 0 };
|
2007-11-01 20:29:20 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Clear thd->db as it points to something, that will be freed when
|
|
|
|
connection is closed. We don't want to accidentally free a wrong
|
|
|
|
pointer if connect failed. Also in case of 'CHANGE USER' failure,
|
|
|
|
current database will be switched to 'no database selected'.
|
|
|
|
*/
|
|
|
|
thd->reset_db(NULL, 0);
|
|
|
|
|
2007-02-23 12:13:55 +01:00
|
|
|
#ifdef NO_EMBEDDED_ACCESS_CHECKS
|
|
|
|
thd->main_security_ctx.master_access= GLOBAL_ACLS; // Full rights
|
|
|
|
/* Change database if necessary */
|
|
|
|
if (db && db[0])
|
|
|
|
{
|
2007-03-29 20:11:17 +02:00
|
|
|
if (mysql_change_db(thd, &db_str, FALSE))
|
2007-10-31 22:10:58 +01:00
|
|
|
DBUG_RETURN(1);
|
2007-02-23 12:13:55 +01:00
|
|
|
}
|
2008-02-19 13:45:21 +01:00
|
|
|
my_ok(thd);
|
2007-02-23 12:13:55 +01:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
#else
|
|
|
|
|
|
|
|
my_bool opt_secure_auth_local;
|
|
|
|
pthread_mutex_lock(&LOCK_global_system_variables);
|
|
|
|
opt_secure_auth_local= opt_secure_auth;
|
|
|
|
pthread_mutex_unlock(&LOCK_global_system_variables);
|
|
|
|
|
|
|
|
/*
|
|
|
|
If the server is running in secure auth mode, short scrambles are
|
|
|
|
forbidden.
|
|
|
|
*/
|
|
|
|
if (opt_secure_auth_local && passwd_len == SCRAMBLE_LENGTH_323)
|
|
|
|
{
|
2007-10-31 22:10:58 +01:00
|
|
|
my_error(ER_NOT_SUPPORTED_AUTH_MODE, MYF(0));
|
2007-02-23 12:13:55 +01:00
|
|
|
general_log_print(thd, COM_CONNECT, ER(ER_NOT_SUPPORTED_AUTH_MODE));
|
2007-10-31 22:10:58 +01:00
|
|
|
DBUG_RETURN(1);
|
2007-02-23 12:13:55 +01:00
|
|
|
}
|
|
|
|
if (passwd_len != 0 &&
|
|
|
|
passwd_len != SCRAMBLE_LENGTH &&
|
|
|
|
passwd_len != SCRAMBLE_LENGTH_323)
|
2007-10-31 22:10:58 +01:00
|
|
|
{
|
Fix for BUG#11755168 '46895: test "outfile_loaddata" fails (reproducible)'.
In sql_class.cc, 'row_count', of type 'ha_rows', was used as last argument for
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD which is
"Incorrect %-.32s value: '%-.128s' for column '%.192s' at row %ld".
So 'ha_rows' was used as 'long'.
On SPARC32 Solaris builds, 'long' is 4 bytes and 'ha_rows' is 'longlong' i.e. 8 bytes.
So the printf-like code was reading only the first 4 bytes.
Because the CPU is big-endian, 1LL is 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x01
so the first four bytes yield 0. So the warning message had "row 0" instead of
"row 1" in test outfile_loaddata.test:
-Warning 1366 Incorrect string value: '\xE1\xE2\xF7' for column 'b' at row 1
+Warning 1366 Incorrect string value: '\xE1\xE2\xF7' for column 'b' at row 0
All error-messaging functions which internally invoke some printf-life function
are potential candidate for such mistakes.
One apparently easy way to catch such mistakes is to use
ATTRIBUTE_FORMAT (from my_attribute.h).
But this works only when call site has both:
a) the format as a string literal
b) the types of arguments.
So:
func(ER(ER_BLAH), 10);
will silently not be checked, because ER(ER_BLAH) is not known at
compile time (it is known at run-time, and depends on the chosen
language).
And
func("%s", a va_list argument);
has the same problem, as the *real* type of arguments is not
known at this site at compile time (it's known in some caller).
Moreover,
func(ER(ER_BLAH));
though possibly correct (if ER(ER_BLAH) has no '%' markers), will not
compile (gcc says "error: format not a string literal and no format
arguments").
Consequences:
1) ATTRIBUTE_FORMAT is here added only to functions which in practice
take "string literal" formats: "my_error_reporter" and "print_admin_msg".
2) it cannot be added to the other functions: my_error(),
push_warning_printf(), Table_check_intact::report_error(),
general_log_print().
To do a one-time check of functions listed in (2), the following
"static code analysis" has been done:
1) replace
my_error(ER_xxx, arguments for substitution in format)
with the equivalent
my_printf_error(ER_xxx,ER(ER_xxx), arguments for substitution in
format),
so that we have ER(ER_xxx) and the arguments *in the same call site*
2) add ATTRIBUTE_FORMAT to push_warning_printf(),
Table_check_intact::report_error(), general_log_print()
3) replace ER(xxx) with the hard-coded English text found in
errmsg.txt (like: ER(ER_UNKNOWN_ERROR) is replaced with
"Unknown error"), so that a call site has the format as string literal
4) this way, ATTRIBUTE_FORMAT can effectively do its job
5) compile, fix errors detected by ATTRIBUTE_FORMAT
6) revert steps 1-2-3.
The present patch has no compiler error when submitted again to the
static code analysis above.
It cannot catch all problems though: see Field::set_warning(), in
which a call to push_warning_printf() has a variable error
(thus, not replacable by a string literal); I checked set_warning() calls
by hand though.
See also WL 5883 for one proposal to avoid such bugs from appearing
again in the future.
The issues fixed in the patch are:
a) mismatch in types (like 'int' passed to '%ld')
b) more arguments passed than specified in the format.
This patch resolves mismatches by changing the type/number of arguments,
not by changing error messages of sql/share/errmsg.txt. The latter would be wrong,
per the following old rule: errmsg.txt must be as stable as possible; no insertions
or deletions of messages, no changes of type or number of printf-like format specifiers,
are allowed, as long as the change impacts a message already released in a GA version.
If this rule is not followed:
- Connectors, which use error message numbers, will be confused (by insertions/deletions
of messages)
- using errmsg.sys of MySQL 5.1.n with mysqld of MySQL 5.1.(n+1)
could produce wrong messages or crash; such usage can easily happen if
installing 5.1.(n+1) while /etc/my.cnf still has --language=/path/to/5.1.n/xxx;
or if copying mysqld from 5.1.(n+1) into a 5.1.n installation.
When fixing b), I have verified that the superfluous arguments were not used in the format
in the first 5.1 GA (5.1.30 'bteam@astra04-20081114162938-z8mctjp6st27uobm').
Had they been used, then passing them today, even if the message doesn't use them
anymore, would have been necessary, as explained above.
2011-05-16 22:04:01 +02:00
|
|
|
my_error(ER_HANDSHAKE_ERROR, MYF(0));
|
2007-10-31 22:10:58 +01:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
2007-02-23 12:13:55 +01:00
|
|
|
|
|
|
|
USER_RESOURCES ur;
|
|
|
|
int res= acl_getroot(thd, &ur, passwd, passwd_len);
|
|
|
|
#ifndef EMBEDDED_LIBRARY
|
|
|
|
if (res == -1)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
This happens when client (new) sends password scrambled with
|
|
|
|
scramble(), but database holds old value (scrambled with
|
|
|
|
scramble_323()). Here we please client to send scrambled_password
|
|
|
|
in old format.
|
|
|
|
*/
|
|
|
|
NET *net= &thd->net;
|
|
|
|
if (opt_secure_auth_local)
|
|
|
|
{
|
2007-10-31 22:10:58 +01:00
|
|
|
my_error(ER_SERVER_IS_IN_SECURE_AUTH_MODE, MYF(0),
|
|
|
|
thd->main_security_ctx.user,
|
|
|
|
thd->main_security_ctx.host_or_ip);
|
2007-02-23 12:13:55 +01:00
|
|
|
general_log_print(thd, COM_CONNECT, ER(ER_SERVER_IS_IN_SECURE_AUTH_MODE),
|
|
|
|
thd->main_security_ctx.user,
|
|
|
|
thd->main_security_ctx.host_or_ip);
|
2007-10-31 22:10:58 +01:00
|
|
|
DBUG_RETURN(1);
|
2007-02-23 12:13:55 +01:00
|
|
|
}
|
|
|
|
/* We have to read very specific packet size */
|
|
|
|
if (send_old_password_request(thd) ||
|
|
|
|
my_net_read(net) != SCRAMBLE_LENGTH_323 + 1)
|
|
|
|
{
|
|
|
|
inc_host_errors(&thd->remote.sin_addr);
|
Fix for BUG#11755168 '46895: test "outfile_loaddata" fails (reproducible)'.
In sql_class.cc, 'row_count', of type 'ha_rows', was used as last argument for
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD which is
"Incorrect %-.32s value: '%-.128s' for column '%.192s' at row %ld".
So 'ha_rows' was used as 'long'.
On SPARC32 Solaris builds, 'long' is 4 bytes and 'ha_rows' is 'longlong' i.e. 8 bytes.
So the printf-like code was reading only the first 4 bytes.
Because the CPU is big-endian, 1LL is 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x01
so the first four bytes yield 0. So the warning message had "row 0" instead of
"row 1" in test outfile_loaddata.test:
-Warning 1366 Incorrect string value: '\xE1\xE2\xF7' for column 'b' at row 1
+Warning 1366 Incorrect string value: '\xE1\xE2\xF7' for column 'b' at row 0
All error-messaging functions which internally invoke some printf-life function
are potential candidate for such mistakes.
One apparently easy way to catch such mistakes is to use
ATTRIBUTE_FORMAT (from my_attribute.h).
But this works only when call site has both:
a) the format as a string literal
b) the types of arguments.
So:
func(ER(ER_BLAH), 10);
will silently not be checked, because ER(ER_BLAH) is not known at
compile time (it is known at run-time, and depends on the chosen
language).
And
func("%s", a va_list argument);
has the same problem, as the *real* type of arguments is not
known at this site at compile time (it's known in some caller).
Moreover,
func(ER(ER_BLAH));
though possibly correct (if ER(ER_BLAH) has no '%' markers), will not
compile (gcc says "error: format not a string literal and no format
arguments").
Consequences:
1) ATTRIBUTE_FORMAT is here added only to functions which in practice
take "string literal" formats: "my_error_reporter" and "print_admin_msg".
2) it cannot be added to the other functions: my_error(),
push_warning_printf(), Table_check_intact::report_error(),
general_log_print().
To do a one-time check of functions listed in (2), the following
"static code analysis" has been done:
1) replace
my_error(ER_xxx, arguments for substitution in format)
with the equivalent
my_printf_error(ER_xxx,ER(ER_xxx), arguments for substitution in
format),
so that we have ER(ER_xxx) and the arguments *in the same call site*
2) add ATTRIBUTE_FORMAT to push_warning_printf(),
Table_check_intact::report_error(), general_log_print()
3) replace ER(xxx) with the hard-coded English text found in
errmsg.txt (like: ER(ER_UNKNOWN_ERROR) is replaced with
"Unknown error"), so that a call site has the format as string literal
4) this way, ATTRIBUTE_FORMAT can effectively do its job
5) compile, fix errors detected by ATTRIBUTE_FORMAT
6) revert steps 1-2-3.
The present patch has no compiler error when submitted again to the
static code analysis above.
It cannot catch all problems though: see Field::set_warning(), in
which a call to push_warning_printf() has a variable error
(thus, not replacable by a string literal); I checked set_warning() calls
by hand though.
See also WL 5883 for one proposal to avoid such bugs from appearing
again in the future.
The issues fixed in the patch are:
a) mismatch in types (like 'int' passed to '%ld')
b) more arguments passed than specified in the format.
This patch resolves mismatches by changing the type/number of arguments,
not by changing error messages of sql/share/errmsg.txt. The latter would be wrong,
per the following old rule: errmsg.txt must be as stable as possible; no insertions
or deletions of messages, no changes of type or number of printf-like format specifiers,
are allowed, as long as the change impacts a message already released in a GA version.
If this rule is not followed:
- Connectors, which use error message numbers, will be confused (by insertions/deletions
of messages)
- using errmsg.sys of MySQL 5.1.n with mysqld of MySQL 5.1.(n+1)
could produce wrong messages or crash; such usage can easily happen if
installing 5.1.(n+1) while /etc/my.cnf still has --language=/path/to/5.1.n/xxx;
or if copying mysqld from 5.1.(n+1) into a 5.1.n installation.
When fixing b), I have verified that the superfluous arguments were not used in the format
in the first 5.1 GA (5.1.30 'bteam@astra04-20081114162938-z8mctjp6st27uobm').
Had they been used, then passing them today, even if the message doesn't use them
anymore, would have been necessary, as explained above.
2011-05-16 22:04:01 +02:00
|
|
|
my_error(ER_HANDSHAKE_ERROR, MYF(0));
|
2007-10-31 22:10:58 +01:00
|
|
|
DBUG_RETURN(1);
|
2007-02-23 12:13:55 +01:00
|
|
|
}
|
|
|
|
/* Final attempt to check the user based on reply */
|
|
|
|
/* So as passwd is short, errcode is always >= 0 */
|
|
|
|
res= acl_getroot(thd, &ur, (char *) net->read_pos, SCRAMBLE_LENGTH_323);
|
|
|
|
}
|
|
|
|
#endif /*EMBEDDED_LIBRARY*/
|
|
|
|
/* here res is always >= 0 */
|
|
|
|
if (res == 0)
|
|
|
|
{
|
|
|
|
if (!(thd->main_security_ctx.master_access &
|
|
|
|
NO_ACCESS)) // authentication is OK
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info",
|
|
|
|
("Capabilities: %lu packet_length: %ld Host: '%s' "
|
|
|
|
"Login user: '%s' Priv_user: '%s' Using password: %s "
|
|
|
|
"Access: %lu db: '%s'",
|
|
|
|
thd->client_capabilities,
|
|
|
|
thd->max_client_packet_length,
|
|
|
|
thd->main_security_ctx.host_or_ip,
|
|
|
|
thd->main_security_ctx.user,
|
|
|
|
thd->main_security_ctx.priv_user,
|
|
|
|
passwd_len ? "yes": "no",
|
|
|
|
thd->main_security_ctx.master_access,
|
|
|
|
(thd->db ? thd->db : "*none*")));
|
|
|
|
|
|
|
|
if (check_count)
|
|
|
|
{
|
2008-03-12 15:44:40 +01:00
|
|
|
pthread_mutex_lock(&LOCK_connection_count);
|
|
|
|
bool count_ok= connection_count <= max_connections ||
|
|
|
|
(thd->main_security_ctx.master_access & SUPER_ACL);
|
|
|
|
VOID(pthread_mutex_unlock(&LOCK_connection_count));
|
|
|
|
|
2007-02-23 12:13:55 +01:00
|
|
|
if (!count_ok)
|
|
|
|
{ // too many connections
|
2007-10-31 22:10:58 +01:00
|
|
|
my_error(ER_CON_COUNT_ERROR, MYF(0));
|
|
|
|
DBUG_RETURN(1);
|
2007-02-23 12:13:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Log the command before authentication checks, so that the user can
|
|
|
|
check the log for the tried login tried and also to detect
|
|
|
|
break-in attempts.
|
|
|
|
*/
|
|
|
|
general_log_print(thd, command,
|
|
|
|
(thd->main_security_ctx.priv_user ==
|
|
|
|
thd->main_security_ctx.user ?
|
|
|
|
(char*) "%s@%s on %s" :
|
|
|
|
(char*) "%s@%s as anonymous on %s"),
|
|
|
|
thd->main_security_ctx.user,
|
|
|
|
thd->main_security_ctx.host_or_ip,
|
|
|
|
db ? db : (char*) "");
|
|
|
|
|
|
|
|
/*
|
|
|
|
This is the default access rights for the current database. It's
|
|
|
|
set to 0 here because we don't have an active database yet (and we
|
|
|
|
may not have an active database to set.
|
|
|
|
*/
|
|
|
|
thd->main_security_ctx.db_access=0;
|
|
|
|
|
|
|
|
/* Don't allow user to connect if he has done too many queries */
|
|
|
|
if ((ur.questions || ur.updates || ur.conn_per_hour || ur.user_conn ||
|
|
|
|
max_user_connections) &&
|
|
|
|
get_or_create_user_conn(thd,
|
|
|
|
(opt_old_style_user_limits ? thd->main_security_ctx.user :
|
|
|
|
thd->main_security_ctx.priv_user),
|
|
|
|
(opt_old_style_user_limits ? thd->main_security_ctx.host_or_ip :
|
|
|
|
thd->main_security_ctx.priv_host),
|
|
|
|
&ur))
|
2007-10-31 22:10:58 +01:00
|
|
|
{
|
|
|
|
/* The error is set by get_or_create_user_conn(). */
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
2007-02-23 12:13:55 +01:00
|
|
|
if (thd->user_connect &&
|
|
|
|
(thd->user_connect->user_resources.conn_per_hour ||
|
|
|
|
thd->user_connect->user_resources.user_conn ||
|
|
|
|
max_user_connections) &&
|
|
|
|
check_for_max_user_connections(thd, thd->user_connect))
|
2007-10-31 22:10:58 +01:00
|
|
|
{
|
|
|
|
/* The error is set in check_for_max_user_connections(). */
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
2007-02-23 12:13:55 +01:00
|
|
|
|
|
|
|
/* Change database if necessary */
|
|
|
|
if (db && db[0])
|
|
|
|
{
|
2007-03-29 20:11:17 +02:00
|
|
|
if (mysql_change_db(thd, &db_str, FALSE))
|
2007-02-23 12:13:55 +01:00
|
|
|
{
|
2007-10-31 22:10:58 +01:00
|
|
|
/* mysql_change_db() has pushed the error message. */
|
2007-02-23 12:13:55 +01:00
|
|
|
if (thd->user_connect)
|
|
|
|
decrease_user_connections(thd->user_connect);
|
2007-10-31 22:10:58 +01:00
|
|
|
DBUG_RETURN(1);
|
2007-02-23 12:13:55 +01:00
|
|
|
}
|
|
|
|
}
|
2008-02-19 13:45:21 +01:00
|
|
|
my_ok(thd);
|
2007-02-23 12:13:55 +01:00
|
|
|
thd->password= test(passwd_len); // remember for error messages
|
2010-06-04 19:58:41 +02:00
|
|
|
#ifndef EMBEDDED_LIBRARY
|
2010-04-30 01:18:19 +02:00
|
|
|
/*
|
|
|
|
Allow the network layer to skip big packets. Although a malicious
|
|
|
|
authenticated session might use this to trick the server to read
|
|
|
|
big packets indefinitely, this is a previously established behavior
|
|
|
|
that needs to be preserved as to not break backwards compatibility.
|
|
|
|
*/
|
|
|
|
thd->net.skip_big_packet= TRUE;
|
2010-06-04 19:58:41 +02:00
|
|
|
#endif
|
2007-02-23 12:13:55 +01:00
|
|
|
/* Ready to handle queries */
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (res == 2) // client gave short hash, server has long hash
|
|
|
|
{
|
2007-10-31 22:10:58 +01:00
|
|
|
my_error(ER_NOT_SUPPORTED_AUTH_MODE, MYF(0));
|
2007-02-23 12:13:55 +01:00
|
|
|
general_log_print(thd, COM_CONNECT, ER(ER_NOT_SUPPORTED_AUTH_MODE));
|
2007-10-31 22:10:58 +01:00
|
|
|
DBUG_RETURN(1);
|
2007-02-23 12:13:55 +01:00
|
|
|
}
|
2007-10-31 22:10:58 +01:00
|
|
|
my_error(ER_ACCESS_DENIED_ERROR, MYF(0),
|
|
|
|
thd->main_security_ctx.user,
|
|
|
|
thd->main_security_ctx.host_or_ip,
|
|
|
|
passwd_len ? ER(ER_YES) : ER(ER_NO));
|
2007-02-23 12:13:55 +01:00
|
|
|
general_log_print(thd, COM_CONNECT, ER(ER_ACCESS_DENIED_ERROR),
|
|
|
|
thd->main_security_ctx.user,
|
|
|
|
thd->main_security_ctx.host_or_ip,
|
|
|
|
passwd_len ? ER(ER_YES) : ER(ER_NO));
|
2007-10-31 22:10:58 +01:00
|
|
|
DBUG_RETURN(1);
|
2007-02-23 12:13:55 +01:00
|
|
|
#endif /* NO_EMBEDDED_ACCESS_CHECKS */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Check for maximum allowable user connections, if the mysqld server is
|
|
|
|
started with corresponding variable that is greater then 0.
|
|
|
|
*/
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
extern "C" uchar *get_key_conn(user_conn *buff, size_t *length,
|
2007-02-23 12:13:55 +01:00
|
|
|
my_bool not_used __attribute__((unused)))
|
|
|
|
{
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
*length= buff->len;
|
|
|
|
return (uchar*) buff->user;
|
2007-02-23 12:13:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern "C" void free_user(struct user_conn *uc)
|
|
|
|
{
|
|
|
|
my_free((char*) uc,MYF(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void init_max_user_conn(void)
|
|
|
|
{
|
|
|
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
|
|
|
(void) hash_init(&hash_user_connections,system_charset_info,max_connections,
|
|
|
|
0,0,
|
|
|
|
(hash_get_key) get_key_conn, (hash_free_key) free_user,
|
|
|
|
0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void free_max_user_conn(void)
|
|
|
|
{
|
|
|
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
|
|
|
hash_free(&hash_user_connections);
|
|
|
|
#endif /* NO_EMBEDDED_ACCESS_CHECKS */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void reset_mqh(LEX_USER *lu, bool get_them= 0)
|
|
|
|
{
|
|
|
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
|
|
|
(void) pthread_mutex_lock(&LOCK_user_conn);
|
|
|
|
if (lu) // for GRANT
|
|
|
|
{
|
|
|
|
USER_CONN *uc;
|
|
|
|
uint temp_len=lu->user.length+lu->host.length+2;
|
|
|
|
char temp_user[USER_HOST_BUFF_SIZE];
|
|
|
|
|
|
|
|
memcpy(temp_user,lu->user.str,lu->user.length);
|
|
|
|
memcpy(temp_user+lu->user.length+1,lu->host.str,lu->host.length);
|
|
|
|
temp_user[lu->user.length]='\0'; temp_user[temp_len-1]=0;
|
|
|
|
if ((uc = (struct user_conn *) hash_search(&hash_user_connections,
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
(uchar*) temp_user, temp_len)))
|
2007-02-23 12:13:55 +01:00
|
|
|
{
|
|
|
|
uc->questions=0;
|
|
|
|
get_mqh(temp_user,&temp_user[lu->user.length+1],uc);
|
|
|
|
uc->updates=0;
|
|
|
|
uc->conn_per_hour=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* for FLUSH PRIVILEGES and FLUSH USER_RESOURCES */
|
|
|
|
for (uint idx=0;idx < hash_user_connections.records; idx++)
|
|
|
|
{
|
|
|
|
USER_CONN *uc=(struct user_conn *) hash_element(&hash_user_connections,
|
|
|
|
idx);
|
|
|
|
if (get_them)
|
|
|
|
get_mqh(uc->user,uc->host,uc);
|
|
|
|
uc->questions=0;
|
|
|
|
uc->updates=0;
|
|
|
|
uc->conn_per_hour=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(void) pthread_mutex_unlock(&LOCK_user_conn);
|
|
|
|
#endif /* NO_EMBEDDED_ACCESS_CHECKS */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-18 14:12:36 +01:00
|
|
|
/**
|
|
|
|
Set thread character set variables from the given ID
|
|
|
|
|
|
|
|
@param thd thread handle
|
|
|
|
@param cs_number character set and collation ID
|
|
|
|
|
|
|
|
@retval 0 OK; character_set_client, collation_connection and
|
|
|
|
character_set_results are set to the new value,
|
|
|
|
or to the default global values.
|
|
|
|
|
|
|
|
@retval 1 error, e.g. the given ID is not supported by parser.
|
|
|
|
Corresponding SQL error is sent.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool thd_init_client_charset(THD *thd, uint cs_number)
|
2007-02-23 12:13:55 +01:00
|
|
|
{
|
2011-02-18 14:12:36 +01:00
|
|
|
CHARSET_INFO *cs;
|
2007-02-23 12:13:55 +01:00
|
|
|
/*
|
|
|
|
Use server character set and collation if
|
|
|
|
- opt_character_set_client_handshake is not set
|
|
|
|
- client has not specified a character set
|
|
|
|
- client character set is the same as the servers
|
|
|
|
- client character set doesn't exists in server
|
|
|
|
*/
|
|
|
|
if (!opt_character_set_client_handshake ||
|
2011-02-18 14:12:36 +01:00
|
|
|
!(cs= get_charset(cs_number, MYF(0))) ||
|
2007-02-23 12:13:55 +01:00
|
|
|
!my_strcasecmp(&my_charset_latin1,
|
|
|
|
global_system_variables.character_set_client->name,
|
2011-02-18 14:12:36 +01:00
|
|
|
cs->name))
|
2007-02-23 12:13:55 +01:00
|
|
|
{
|
|
|
|
thd->variables.character_set_client=
|
|
|
|
global_system_variables.character_set_client;
|
|
|
|
thd->variables.collation_connection=
|
|
|
|
global_system_variables.collation_connection;
|
|
|
|
thd->variables.character_set_results=
|
|
|
|
global_system_variables.character_set_results;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-02-18 14:12:36 +01:00
|
|
|
if (!is_supported_parser_charset(cs))
|
|
|
|
{
|
|
|
|
/* Disallow non-supported parser character sets: UCS2, UTF16, UTF32 */
|
|
|
|
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), "character_set_client",
|
|
|
|
cs->csname);
|
|
|
|
return true;
|
|
|
|
}
|
2007-02-23 12:13:55 +01:00
|
|
|
thd->variables.character_set_results=
|
|
|
|
thd->variables.collation_connection=
|
2011-02-18 14:12:36 +01:00
|
|
|
thd->variables.character_set_client= cs;
|
2007-02-23 12:13:55 +01:00
|
|
|
}
|
2011-02-18 14:12:36 +01:00
|
|
|
return false;
|
2007-02-23 12:13:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Initialize connection threads
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool init_new_connection_handler_thread()
|
|
|
|
{
|
|
|
|
pthread_detach_this_thread();
|
|
|
|
#if defined(__WIN__)
|
2008-02-19 14:25:26 +01:00
|
|
|
win_install_sigabrt_handler();
|
2007-02-23 12:13:55 +01:00
|
|
|
#else
|
|
|
|
/* Win32 calls this in pthread_create */
|
|
|
|
if (my_thread_init())
|
|
|
|
return 1;
|
|
|
|
#endif /* __WIN__ */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-11 15:10:15 +01:00
|
|
|
#ifndef EMBEDDED_LIBRARY
|
2011-05-30 12:42:30 +02:00
|
|
|
|
|
|
|
/** Get a string according to the protocol of the underlying buffer. */
|
|
|
|
typedef char * (*get_proto_string_func_t) (char **, size_t *, size_t *);
|
|
|
|
|
2011-03-11 15:10:15 +01:00
|
|
|
/**
|
2011-05-30 12:42:30 +02:00
|
|
|
Get a string formatted according to the 4.1 version of the MySQL protocol.
|
2011-03-11 15:10:15 +01:00
|
|
|
|
2011-05-30 12:42:30 +02:00
|
|
|
@param buffer[in, out] Pointer to the user-supplied buffer to be scanned.
|
2011-03-11 15:10:15 +01:00
|
|
|
@param max_bytes_available[in, out] Limit the bytes to scan.
|
|
|
|
@param string_length[out] The number of characters scanned not including
|
|
|
|
the null character.
|
|
|
|
|
2011-05-30 12:42:30 +02:00
|
|
|
@remark Strings are always null character terminated in this version of the
|
|
|
|
protocol.
|
|
|
|
|
2011-03-11 15:10:15 +01:00
|
|
|
@remark The string_length does not include the terminating null character.
|
|
|
|
However, after the call, the buffer is increased by string_length+1
|
|
|
|
bytes, beyond the null character if there still available bytes to
|
|
|
|
scan.
|
|
|
|
|
|
|
|
@return pointer to beginning of the string scanned.
|
|
|
|
@retval NULL The buffer content is malformed
|
|
|
|
*/
|
|
|
|
|
|
|
|
static
|
2011-05-30 12:42:30 +02:00
|
|
|
char *get_41_protocol_string(char **buffer,
|
|
|
|
size_t *max_bytes_available,
|
|
|
|
size_t *string_length)
|
2011-03-11 15:10:15 +01:00
|
|
|
{
|
|
|
|
char *str= (char *)memchr(*buffer, '\0', *max_bytes_available);
|
|
|
|
|
|
|
|
if (str == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
*string_length= (size_t)(str - *buffer);
|
|
|
|
*max_bytes_available-= *string_length + 1;
|
|
|
|
str= *buffer;
|
2011-05-30 12:42:30 +02:00
|
|
|
*buffer += *string_length + 1;
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Get a string formatted according to the 4.0 version of the MySQL protocol.
|
|
|
|
|
|
|
|
@param buffer[in, out] Pointer to the user-supplied buffer to be scanned.
|
|
|
|
@param max_bytes_available[in, out] Limit the bytes to scan.
|
|
|
|
@param string_length[out] The number of characters scanned not including
|
|
|
|
the null character.
|
|
|
|
|
|
|
|
@remark If there are not enough bytes left after the current position of
|
|
|
|
the buffer to satisfy the current string, the string is considered
|
|
|
|
to be empty and a pointer to empty_c_string is returned.
|
|
|
|
|
|
|
|
@remark A string at the end of the packet is not null terminated.
|
|
|
|
|
|
|
|
@return Pointer to beginning of the string scanned, or a pointer to a empty
|
|
|
|
string.
|
|
|
|
*/
|
|
|
|
static
|
|
|
|
char *get_40_protocol_string(char **buffer,
|
|
|
|
size_t *max_bytes_available,
|
|
|
|
size_t *string_length)
|
|
|
|
{
|
|
|
|
char *str;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
/* No bytes to scan left, treat string as empty. */
|
|
|
|
if ((*max_bytes_available) == 0)
|
|
|
|
{
|
|
|
|
*string_length= 0;
|
|
|
|
return empty_c_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
str= (char *) memchr(*buffer, '\0', *max_bytes_available);
|
|
|
|
|
|
|
|
/*
|
|
|
|
If the string was not null terminated by the client,
|
|
|
|
the remainder of the packet is the string. Otherwise,
|
|
|
|
advance the buffer past the end of the null terminated
|
|
|
|
string.
|
|
|
|
*/
|
|
|
|
if (str == NULL)
|
|
|
|
len= *string_length= *max_bytes_available;
|
|
|
|
else
|
|
|
|
len= (*string_length= (size_t)(str - *buffer)) + 1;
|
|
|
|
|
|
|
|
str= *buffer;
|
|
|
|
*buffer+= len;
|
|
|
|
*max_bytes_available-= len;
|
2011-03-11 15:10:15 +01:00
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Get a length encoded string from a user-supplied buffer.
|
|
|
|
|
|
|
|
@param buffer[in, out] The buffer to scan; updates position after scan.
|
|
|
|
@param max_bytes_available[in, out] Limit the number of bytes to scan
|
|
|
|
@param string_length[out] Number of characters scanned
|
2011-05-30 12:42:30 +02:00
|
|
|
|
2011-03-11 15:10:15 +01:00
|
|
|
@remark In case the length is zero, then the total size of the string is
|
|
|
|
considered to be 1 byte; the size byte.
|
|
|
|
|
|
|
|
@return pointer to first byte after the header in buffer.
|
|
|
|
@retval NULL The buffer content is malformed
|
|
|
|
*/
|
|
|
|
|
|
|
|
static
|
|
|
|
char *get_length_encoded_string(char **buffer,
|
|
|
|
size_t *max_bytes_available,
|
|
|
|
size_t *string_length)
|
|
|
|
{
|
|
|
|
if (*max_bytes_available == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Do double cast to prevent overflow from signed / unsigned conversion */
|
|
|
|
size_t str_len= (size_t)(unsigned char)**buffer;
|
|
|
|
|
|
|
|
/*
|
|
|
|
If the length encoded string has the length 0
|
|
|
|
the total size of the string is only one byte long (the size byte)
|
|
|
|
*/
|
|
|
|
if (str_len == 0)
|
|
|
|
{
|
|
|
|
++*buffer;
|
|
|
|
*string_length= 0;
|
|
|
|
/*
|
|
|
|
Return a pointer to the 0 character so the return value will be
|
|
|
|
an empty string.
|
|
|
|
*/
|
|
|
|
return *buffer-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (str_len >= *max_bytes_available)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
char *str= *buffer+1;
|
|
|
|
*string_length= str_len;
|
|
|
|
*max_bytes_available-= *string_length + 1;
|
|
|
|
*buffer+= *string_length + 1;
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-23 12:13:55 +01:00
|
|
|
/*
|
|
|
|
Perform handshake, authorize client and update thd ACL variables.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
check_connection()
|
|
|
|
thd thread handle
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 success, OK is sent to user, thd is updated.
|
|
|
|
-1 error, which is sent to user
|
|
|
|
> 0 error code (not sent to user)
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int check_connection(THD *thd)
|
|
|
|
{
|
|
|
|
uint connect_errors= 0;
|
|
|
|
NET *net= &thd->net;
|
|
|
|
ulong pkt_len= 0;
|
|
|
|
char *end;
|
|
|
|
|
2011-05-09 12:57:17 +02:00
|
|
|
bool packet_has_required_size= false;
|
|
|
|
char *db;
|
|
|
|
size_t db_len;
|
|
|
|
char *passwd;
|
|
|
|
size_t passwd_len;
|
|
|
|
char *user;
|
|
|
|
size_t user_len;
|
|
|
|
|
2007-02-23 12:13:55 +01:00
|
|
|
DBUG_PRINT("info",
|
|
|
|
("New connection received on %s", vio_description(net->vio)));
|
|
|
|
#ifdef SIGNAL_WITH_VIO_CLOSE
|
|
|
|
thd->set_active_vio(net->vio);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!thd->main_security_ctx.host) // If TCP/IP connection
|
|
|
|
{
|
|
|
|
char ip[30];
|
|
|
|
|
|
|
|
if (vio_peer_addr(net->vio, ip, &thd->peer_port))
|
2007-10-31 22:10:58 +01:00
|
|
|
{
|
Fix for BUG#11755168 '46895: test "outfile_loaddata" fails (reproducible)'.
In sql_class.cc, 'row_count', of type 'ha_rows', was used as last argument for
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD which is
"Incorrect %-.32s value: '%-.128s' for column '%.192s' at row %ld".
So 'ha_rows' was used as 'long'.
On SPARC32 Solaris builds, 'long' is 4 bytes and 'ha_rows' is 'longlong' i.e. 8 bytes.
So the printf-like code was reading only the first 4 bytes.
Because the CPU is big-endian, 1LL is 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x01
so the first four bytes yield 0. So the warning message had "row 0" instead of
"row 1" in test outfile_loaddata.test:
-Warning 1366 Incorrect string value: '\xE1\xE2\xF7' for column 'b' at row 1
+Warning 1366 Incorrect string value: '\xE1\xE2\xF7' for column 'b' at row 0
All error-messaging functions which internally invoke some printf-life function
are potential candidate for such mistakes.
One apparently easy way to catch such mistakes is to use
ATTRIBUTE_FORMAT (from my_attribute.h).
But this works only when call site has both:
a) the format as a string literal
b) the types of arguments.
So:
func(ER(ER_BLAH), 10);
will silently not be checked, because ER(ER_BLAH) is not known at
compile time (it is known at run-time, and depends on the chosen
language).
And
func("%s", a va_list argument);
has the same problem, as the *real* type of arguments is not
known at this site at compile time (it's known in some caller).
Moreover,
func(ER(ER_BLAH));
though possibly correct (if ER(ER_BLAH) has no '%' markers), will not
compile (gcc says "error: format not a string literal and no format
arguments").
Consequences:
1) ATTRIBUTE_FORMAT is here added only to functions which in practice
take "string literal" formats: "my_error_reporter" and "print_admin_msg".
2) it cannot be added to the other functions: my_error(),
push_warning_printf(), Table_check_intact::report_error(),
general_log_print().
To do a one-time check of functions listed in (2), the following
"static code analysis" has been done:
1) replace
my_error(ER_xxx, arguments for substitution in format)
with the equivalent
my_printf_error(ER_xxx,ER(ER_xxx), arguments for substitution in
format),
so that we have ER(ER_xxx) and the arguments *in the same call site*
2) add ATTRIBUTE_FORMAT to push_warning_printf(),
Table_check_intact::report_error(), general_log_print()
3) replace ER(xxx) with the hard-coded English text found in
errmsg.txt (like: ER(ER_UNKNOWN_ERROR) is replaced with
"Unknown error"), so that a call site has the format as string literal
4) this way, ATTRIBUTE_FORMAT can effectively do its job
5) compile, fix errors detected by ATTRIBUTE_FORMAT
6) revert steps 1-2-3.
The present patch has no compiler error when submitted again to the
static code analysis above.
It cannot catch all problems though: see Field::set_warning(), in
which a call to push_warning_printf() has a variable error
(thus, not replacable by a string literal); I checked set_warning() calls
by hand though.
See also WL 5883 for one proposal to avoid such bugs from appearing
again in the future.
The issues fixed in the patch are:
a) mismatch in types (like 'int' passed to '%ld')
b) more arguments passed than specified in the format.
This patch resolves mismatches by changing the type/number of arguments,
not by changing error messages of sql/share/errmsg.txt. The latter would be wrong,
per the following old rule: errmsg.txt must be as stable as possible; no insertions
or deletions of messages, no changes of type or number of printf-like format specifiers,
are allowed, as long as the change impacts a message already released in a GA version.
If this rule is not followed:
- Connectors, which use error message numbers, will be confused (by insertions/deletions
of messages)
- using errmsg.sys of MySQL 5.1.n with mysqld of MySQL 5.1.(n+1)
could produce wrong messages or crash; such usage can easily happen if
installing 5.1.(n+1) while /etc/my.cnf still has --language=/path/to/5.1.n/xxx;
or if copying mysqld from 5.1.(n+1) into a 5.1.n installation.
When fixing b), I have verified that the superfluous arguments were not used in the format
in the first 5.1 GA (5.1.30 'bteam@astra04-20081114162938-z8mctjp6st27uobm').
Had they been used, then passing them today, even if the message doesn't use them
anymore, would have been necessary, as explained above.
2011-05-16 22:04:01 +02:00
|
|
|
my_error(ER_BAD_HOST_ERROR, MYF(0));
|
2007-10-31 22:10:58 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (!(thd->main_security_ctx.ip= my_strdup(ip,MYF(MY_WME))))
|
|
|
|
return 1; /* The error is set by my_strdup(). */
|
2007-02-23 12:13:55 +01:00
|
|
|
thd->main_security_ctx.host_or_ip= thd->main_security_ctx.ip;
|
|
|
|
vio_in_addr(net->vio,&thd->remote.sin_addr);
|
|
|
|
if (!(specialflag & SPECIAL_NO_RESOLVE))
|
|
|
|
{
|
|
|
|
vio_in_addr(net->vio,&thd->remote.sin_addr);
|
|
|
|
thd->main_security_ctx.host=
|
|
|
|
ip_to_hostname(&thd->remote.sin_addr, &connect_errors);
|
|
|
|
/* Cut very long hostnames to avoid possible overflows */
|
|
|
|
if (thd->main_security_ctx.host)
|
|
|
|
{
|
|
|
|
if (thd->main_security_ctx.host != my_localhost)
|
|
|
|
thd->main_security_ctx.host[min(strlen(thd->main_security_ctx.host),
|
|
|
|
HOSTNAME_LENGTH)]= 0;
|
|
|
|
thd->main_security_ctx.host_or_ip= thd->main_security_ctx.host;
|
|
|
|
}
|
|
|
|
if (connect_errors > max_connect_errors)
|
2007-10-31 22:10:58 +01:00
|
|
|
{
|
|
|
|
my_error(ER_HOST_IS_BLOCKED, MYF(0), thd->main_security_ctx.host_or_ip);
|
|
|
|
return 1;
|
|
|
|
}
|
2007-02-23 12:13:55 +01:00
|
|
|
}
|
|
|
|
DBUG_PRINT("info",("Host: %s ip: %s",
|
|
|
|
(thd->main_security_ctx.host ?
|
|
|
|
thd->main_security_ctx.host : "unknown host"),
|
|
|
|
(thd->main_security_ctx.ip ?
|
|
|
|
thd->main_security_ctx.ip : "unknown ip")));
|
|
|
|
if (acl_check_host(thd->main_security_ctx.host, thd->main_security_ctx.ip))
|
2007-10-31 22:10:58 +01:00
|
|
|
{
|
|
|
|
my_error(ER_HOST_NOT_PRIVILEGED, MYF(0),
|
|
|
|
thd->main_security_ctx.host_or_ip);
|
|
|
|
return 1;
|
|
|
|
}
|
2007-02-23 12:13:55 +01:00
|
|
|
}
|
|
|
|
else /* Hostname given means that the connection was on a socket */
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info",("Host: %s", thd->main_security_ctx.host));
|
|
|
|
thd->main_security_ctx.host_or_ip= thd->main_security_ctx.host;
|
|
|
|
thd->main_security_ctx.ip= 0;
|
|
|
|
/* Reset sin_addr */
|
|
|
|
bzero((char*) &thd->remote, sizeof(thd->remote));
|
|
|
|
}
|
|
|
|
vio_keepalive(net->vio, TRUE);
|
2008-03-25 17:18:58 +01:00
|
|
|
|
|
|
|
ulong server_capabilites;
|
2007-02-23 12:13:55 +01:00
|
|
|
{
|
|
|
|
/* buff[] needs to big enough to hold the server_version variable */
|
2009-12-18 19:44:24 +01:00
|
|
|
char buff[SERVER_VERSION_LENGTH + 1 + SCRAMBLE_LENGTH + 1 + 64];
|
2008-03-25 17:18:58 +01:00
|
|
|
server_capabilites= CLIENT_BASIC_FLAGS;
|
2007-02-23 12:13:55 +01:00
|
|
|
|
|
|
|
if (opt_using_transactions)
|
2008-03-25 17:18:58 +01:00
|
|
|
server_capabilites|= CLIENT_TRANSACTIONS;
|
2007-02-23 12:13:55 +01:00
|
|
|
#ifdef HAVE_COMPRESS
|
2008-03-25 17:18:58 +01:00
|
|
|
server_capabilites|= CLIENT_COMPRESS;
|
2007-02-23 12:13:55 +01:00
|
|
|
#endif /* HAVE_COMPRESS */
|
|
|
|
#ifdef HAVE_OPENSSL
|
|
|
|
if (ssl_acceptor_fd)
|
2008-03-25 17:18:58 +01:00
|
|
|
{
|
|
|
|
server_capabilites |= CLIENT_SSL; /* Wow, SSL is available! */
|
|
|
|
server_capabilites |= CLIENT_SSL_VERIFY_SERVER_CERT;
|
|
|
|
}
|
2007-02-23 12:13:55 +01:00
|
|
|
#endif /* HAVE_OPENSSL */
|
|
|
|
|
|
|
|
end= strnmov(buff, server_version, SERVER_VERSION_LENGTH) + 1;
|
|
|
|
int4store((uchar*) end, thd->thread_id);
|
|
|
|
end+= 4;
|
|
|
|
/*
|
|
|
|
So as check_connection is the only entry point to authorization
|
|
|
|
procedure, scramble is set here. This gives us new scramble for
|
|
|
|
each handshake.
|
|
|
|
*/
|
|
|
|
create_random_string(thd->scramble, SCRAMBLE_LENGTH, &thd->rand);
|
|
|
|
/*
|
|
|
|
Old clients does not understand long scrambles, but can ignore packet
|
|
|
|
tail: that's why first part of the scramble is placed here, and second
|
|
|
|
part at the end of packet.
|
|
|
|
*/
|
|
|
|
end= strmake(end, thd->scramble, SCRAMBLE_LENGTH_323) + 1;
|
2011-05-30 12:42:30 +02:00
|
|
|
|
2008-03-25 17:18:58 +01:00
|
|
|
int2store(end, server_capabilites);
|
2007-02-23 12:13:55 +01:00
|
|
|
/* write server characteristics: up to 16 bytes allowed */
|
|
|
|
end[2]=(char) default_charset_info->number;
|
|
|
|
int2store(end+3, thd->server_status);
|
|
|
|
bzero(end+5, 13);
|
|
|
|
end+= 18;
|
|
|
|
/* write scramble tail */
|
|
|
|
end= strmake(end, thd->scramble + SCRAMBLE_LENGTH_323,
|
|
|
|
SCRAMBLE_LENGTH - SCRAMBLE_LENGTH_323) + 1;
|
|
|
|
|
|
|
|
/* At this point we write connection message and read reply */
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
if (net_write_command(net, (uchar) protocol_version, (uchar*) "", 0,
|
|
|
|
(uchar*) buff, (size_t) (end-buff)) ||
|
2011-05-09 12:57:17 +02:00
|
|
|
(pkt_len= my_net_read(net)) == packet_error)
|
2007-02-23 12:13:55 +01:00
|
|
|
{
|
|
|
|
inc_host_errors(&thd->remote.sin_addr);
|
Fix for BUG#11755168 '46895: test "outfile_loaddata" fails (reproducible)'.
In sql_class.cc, 'row_count', of type 'ha_rows', was used as last argument for
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD which is
"Incorrect %-.32s value: '%-.128s' for column '%.192s' at row %ld".
So 'ha_rows' was used as 'long'.
On SPARC32 Solaris builds, 'long' is 4 bytes and 'ha_rows' is 'longlong' i.e. 8 bytes.
So the printf-like code was reading only the first 4 bytes.
Because the CPU is big-endian, 1LL is 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x01
so the first four bytes yield 0. So the warning message had "row 0" instead of
"row 1" in test outfile_loaddata.test:
-Warning 1366 Incorrect string value: '\xE1\xE2\xF7' for column 'b' at row 1
+Warning 1366 Incorrect string value: '\xE1\xE2\xF7' for column 'b' at row 0
All error-messaging functions which internally invoke some printf-life function
are potential candidate for such mistakes.
One apparently easy way to catch such mistakes is to use
ATTRIBUTE_FORMAT (from my_attribute.h).
But this works only when call site has both:
a) the format as a string literal
b) the types of arguments.
So:
func(ER(ER_BLAH), 10);
will silently not be checked, because ER(ER_BLAH) is not known at
compile time (it is known at run-time, and depends on the chosen
language).
And
func("%s", a va_list argument);
has the same problem, as the *real* type of arguments is not
known at this site at compile time (it's known in some caller).
Moreover,
func(ER(ER_BLAH));
though possibly correct (if ER(ER_BLAH) has no '%' markers), will not
compile (gcc says "error: format not a string literal and no format
arguments").
Consequences:
1) ATTRIBUTE_FORMAT is here added only to functions which in practice
take "string literal" formats: "my_error_reporter" and "print_admin_msg".
2) it cannot be added to the other functions: my_error(),
push_warning_printf(), Table_check_intact::report_error(),
general_log_print().
To do a one-time check of functions listed in (2), the following
"static code analysis" has been done:
1) replace
my_error(ER_xxx, arguments for substitution in format)
with the equivalent
my_printf_error(ER_xxx,ER(ER_xxx), arguments for substitution in
format),
so that we have ER(ER_xxx) and the arguments *in the same call site*
2) add ATTRIBUTE_FORMAT to push_warning_printf(),
Table_check_intact::report_error(), general_log_print()
3) replace ER(xxx) with the hard-coded English text found in
errmsg.txt (like: ER(ER_UNKNOWN_ERROR) is replaced with
"Unknown error"), so that a call site has the format as string literal
4) this way, ATTRIBUTE_FORMAT can effectively do its job
5) compile, fix errors detected by ATTRIBUTE_FORMAT
6) revert steps 1-2-3.
The present patch has no compiler error when submitted again to the
static code analysis above.
It cannot catch all problems though: see Field::set_warning(), in
which a call to push_warning_printf() has a variable error
(thus, not replacable by a string literal); I checked set_warning() calls
by hand though.
See also WL 5883 for one proposal to avoid such bugs from appearing
again in the future.
The issues fixed in the patch are:
a) mismatch in types (like 'int' passed to '%ld')
b) more arguments passed than specified in the format.
This patch resolves mismatches by changing the type/number of arguments,
not by changing error messages of sql/share/errmsg.txt. The latter would be wrong,
per the following old rule: errmsg.txt must be as stable as possible; no insertions
or deletions of messages, no changes of type or number of printf-like format specifiers,
are allowed, as long as the change impacts a message already released in a GA version.
If this rule is not followed:
- Connectors, which use error message numbers, will be confused (by insertions/deletions
of messages)
- using errmsg.sys of MySQL 5.1.n with mysqld of MySQL 5.1.(n+1)
could produce wrong messages or crash; such usage can easily happen if
installing 5.1.(n+1) while /etc/my.cnf still has --language=/path/to/5.1.n/xxx;
or if copying mysqld from 5.1.(n+1) into a 5.1.n installation.
When fixing b), I have verified that the superfluous arguments were not used in the format
in the first 5.1 GA (5.1.30 'bteam@astra04-20081114162938-z8mctjp6st27uobm').
Had they been used, then passing them today, even if the message doesn't use them
anymore, would have been necessary, as explained above.
2011-05-16 22:04:01 +02:00
|
|
|
my_error(ER_HANDSHAKE_ERROR, MYF(0));
|
2007-10-31 22:10:58 +01:00
|
|
|
return 1;
|
2007-02-23 12:13:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef _CUSTOMCONFIG_
|
|
|
|
#include "_cust_sql_parse.h"
|
|
|
|
#endif
|
|
|
|
if (connect_errors)
|
|
|
|
reset_host_errors(&thd->remote.sin_addr);
|
|
|
|
if (thd->packet.alloc(thd->variables.net_buffer_length))
|
2007-10-31 22:10:58 +01:00
|
|
|
return 1; /* The error is set by alloc(). */
|
2007-02-23 12:13:55 +01:00
|
|
|
|
2011-05-09 12:57:17 +02:00
|
|
|
uint charset_code= 0;
|
|
|
|
end= (char *)net->read_pos;
|
|
|
|
/*
|
|
|
|
In order to safely scan a head for '\0' string terminators
|
|
|
|
we must keep track of how many bytes remain in the allocated
|
|
|
|
buffer or we might read past the end of the buffer.
|
|
|
|
*/
|
|
|
|
size_t bytes_remaining_in_packet= pkt_len;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Peek ahead on the client capability packet and determine which version of
|
|
|
|
the protocol should be used.
|
|
|
|
*/
|
|
|
|
if (bytes_remaining_in_packet < 2)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
thd->client_capabilities= uint2korr(end);
|
|
|
|
|
2011-07-01 16:15:50 +02:00
|
|
|
/*
|
2011-07-01 17:18:27 +02:00
|
|
|
Connector/J only sends client capabilities (4 bytes) before starting SSL
|
2011-07-01 16:15:50 +02:00
|
|
|
negotiation so we don't have char_set and other information for client in
|
|
|
|
packet read. In that case, skip reading those information. The below code
|
|
|
|
is patch for this.
|
|
|
|
*/
|
|
|
|
if(bytes_remaining_in_packet == AUTH_PACKET_HEADER_SIZE_CONNJ_SSL &&
|
2011-07-01 17:18:27 +02:00
|
|
|
(thd->client_capabilities & CLIENT_SSL))
|
2011-07-01 16:15:50 +02:00
|
|
|
{
|
|
|
|
thd->client_capabilities= uint4korr(end);
|
2011-07-01 17:18:27 +02:00
|
|
|
thd->max_client_packet_length= global_system_variables.max_allowed_packet;
|
2011-07-01 16:15:50 +02:00
|
|
|
charset_code= default_charset_info->number;
|
|
|
|
end+= AUTH_PACKET_HEADER_SIZE_CONNJ_SSL;
|
|
|
|
bytes_remaining_in_packet-= AUTH_PACKET_HEADER_SIZE_CONNJ_SSL;
|
|
|
|
goto skip_to_ssl;
|
|
|
|
}
|
|
|
|
|
2011-05-09 12:57:17 +02:00
|
|
|
if (thd->client_capabilities & CLIENT_PROTOCOL_41)
|
|
|
|
packet_has_required_size= bytes_remaining_in_packet >=
|
|
|
|
AUTH_PACKET_HEADER_SIZE_PROTO_41;
|
|
|
|
else
|
|
|
|
packet_has_required_size= bytes_remaining_in_packet >=
|
|
|
|
AUTH_PACKET_HEADER_SIZE_PROTO_40;
|
|
|
|
|
|
|
|
if (!packet_has_required_size)
|
|
|
|
goto error;
|
|
|
|
|
2007-02-23 12:13:55 +01:00
|
|
|
if (thd->client_capabilities & CLIENT_PROTOCOL_41)
|
|
|
|
{
|
2011-05-09 12:57:17 +02:00
|
|
|
thd->client_capabilities= uint4korr(end);
|
|
|
|
thd->max_client_packet_length= uint4korr(end + 4);
|
|
|
|
charset_code= (uint)(uchar)*(end + 8);
|
|
|
|
/*
|
|
|
|
Skip 23 remaining filler bytes which have no particular meaning.
|
|
|
|
*/
|
|
|
|
end+= AUTH_PACKET_HEADER_SIZE_PROTO_41;
|
|
|
|
bytes_remaining_in_packet-= AUTH_PACKET_HEADER_SIZE_PROTO_41;
|
2007-02-23 12:13:55 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-05-09 12:57:17 +02:00
|
|
|
thd->client_capabilities= uint2korr(end);
|
|
|
|
thd->max_client_packet_length= uint3korr(end + 2);
|
|
|
|
end+= AUTH_PACKET_HEADER_SIZE_PROTO_40;
|
|
|
|
bytes_remaining_in_packet-= AUTH_PACKET_HEADER_SIZE_PROTO_40;
|
|
|
|
/**
|
|
|
|
Old clients didn't have their own charset. Instead the assumption
|
|
|
|
was that they used what ever the server used.
|
|
|
|
*/
|
|
|
|
charset_code= default_charset_info->number;
|
2007-02-23 12:13:55 +01:00
|
|
|
}
|
2011-05-09 12:57:17 +02:00
|
|
|
|
2011-07-01 16:15:50 +02:00
|
|
|
skip_to_ssl:
|
|
|
|
|
2011-05-09 12:57:17 +02:00
|
|
|
DBUG_PRINT("info", ("client_character_set: %u", charset_code));
|
|
|
|
if (thd_init_client_charset(thd, charset_code))
|
|
|
|
goto error;
|
|
|
|
thd->update_charset();
|
|
|
|
|
2008-03-25 17:18:58 +01:00
|
|
|
/*
|
|
|
|
Disable those bits which are not supported by the server.
|
|
|
|
This is a precautionary measure, if the client lies. See Bug#27944.
|
|
|
|
*/
|
|
|
|
thd->client_capabilities&= server_capabilites;
|
2007-02-23 12:13:55 +01:00
|
|
|
|
|
|
|
if (thd->client_capabilities & CLIENT_IGNORE_SPACE)
|
|
|
|
thd->variables.sql_mode|= MODE_IGNORE_SPACE;
|
|
|
|
#ifdef HAVE_OPENSSL
|
|
|
|
DBUG_PRINT("info", ("client capabilities: %lu", thd->client_capabilities));
|
2011-05-09 12:57:17 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
If client requested SSL then we must stop parsing, try to switch to SSL,
|
|
|
|
and wait for the client to send a new handshake packet.
|
|
|
|
The client isn't expected to send any more bytes until SSL is initialized.
|
|
|
|
*/
|
2007-02-23 12:13:55 +01:00
|
|
|
if (thd->client_capabilities & CLIENT_SSL)
|
|
|
|
{
|
|
|
|
/* Do the SSL layering. */
|
|
|
|
if (!ssl_acceptor_fd)
|
2011-05-09 12:57:17 +02:00
|
|
|
goto error;
|
|
|
|
|
2007-02-23 12:13:55 +01:00
|
|
|
DBUG_PRINT("info", ("IO layer change in progress..."));
|
|
|
|
if (sslaccept(ssl_acceptor_fd, net->vio, net->read_timeout))
|
|
|
|
{
|
|
|
|
DBUG_PRINT("error", ("Failed to accept new SSL connection"));
|
2011-05-09 12:57:17 +02:00
|
|
|
goto error;
|
2007-02-23 12:13:55 +01:00
|
|
|
}
|
2011-05-09 12:57:17 +02:00
|
|
|
|
2007-02-23 12:13:55 +01:00
|
|
|
DBUG_PRINT("info", ("Reading user information over SSL layer"));
|
2011-05-09 12:57:17 +02:00
|
|
|
if ((pkt_len= my_net_read(net)) == packet_error)
|
2007-02-23 12:13:55 +01:00
|
|
|
{
|
|
|
|
DBUG_PRINT("error", ("Failed to read user information (pkt_len= %lu)",
|
|
|
|
pkt_len));
|
2011-05-09 12:57:17 +02:00
|
|
|
goto error;
|
2007-02-23 12:13:55 +01:00
|
|
|
}
|
2011-05-09 12:57:17 +02:00
|
|
|
/*
|
|
|
|
A new packet was read and the statistics reflecting the remaining bytes
|
|
|
|
in the packet must be updated.
|
|
|
|
*/
|
|
|
|
bytes_remaining_in_packet= pkt_len;
|
2007-02-23 12:13:55 +01:00
|
|
|
|
2011-05-09 12:57:17 +02:00
|
|
|
/*
|
|
|
|
After the SSL handshake is performed the client resends the handshake
|
|
|
|
packet but because of legacy reasons we chose not to parse the packet
|
|
|
|
fields a second time and instead only assert the length of the packet.
|
|
|
|
*/
|
|
|
|
if (thd->client_capabilities & CLIENT_PROTOCOL_41)
|
|
|
|
{
|
|
|
|
|
|
|
|
packet_has_required_size= bytes_remaining_in_packet >=
|
|
|
|
AUTH_PACKET_HEADER_SIZE_PROTO_41;
|
|
|
|
end= (char *)net->read_pos + AUTH_PACKET_HEADER_SIZE_PROTO_41;
|
|
|
|
bytes_remaining_in_packet -= AUTH_PACKET_HEADER_SIZE_PROTO_41;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
packet_has_required_size= bytes_remaining_in_packet >=
|
|
|
|
AUTH_PACKET_HEADER_SIZE_PROTO_40;
|
|
|
|
end= (char *)net->read_pos + AUTH_PACKET_HEADER_SIZE_PROTO_40;
|
|
|
|
bytes_remaining_in_packet -= AUTH_PACKET_HEADER_SIZE_PROTO_40;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!packet_has_required_size)
|
|
|
|
goto error;
|
2007-02-23 12:13:55 +01:00
|
|
|
}
|
2011-05-09 12:57:17 +02:00
|
|
|
#endif /* HAVE_OPENSSL */
|
2007-02-23 12:13:55 +01:00
|
|
|
|
|
|
|
if (thd->client_capabilities & CLIENT_INTERACTIVE)
|
|
|
|
thd->variables.net_wait_timeout= thd->variables.net_interactive_timeout;
|
|
|
|
if ((thd->client_capabilities & CLIENT_TRANSACTIONS) &&
|
|
|
|
opt_using_transactions)
|
|
|
|
net->return_status= &thd->server_status;
|
|
|
|
|
2011-05-30 12:42:30 +02:00
|
|
|
/*
|
|
|
|
The 4.0 and 4.1 versions of the protocol differ on how strings
|
|
|
|
are terminated. In the 4.0 version, if a string is at the end
|
|
|
|
of the packet, the string is not null terminated. Do not assume
|
|
|
|
that the returned string is always null terminated.
|
|
|
|
*/
|
|
|
|
get_proto_string_func_t get_string;
|
|
|
|
|
|
|
|
if (thd->client_capabilities & CLIENT_PROTOCOL_41)
|
|
|
|
get_string= get_41_protocol_string;
|
|
|
|
else
|
|
|
|
get_string= get_40_protocol_string;
|
2007-02-23 12:13:55 +01:00
|
|
|
|
2011-06-06 15:53:46 +02:00
|
|
|
user= get_string(&end, &bytes_remaining_in_packet, &user_len);
|
2011-03-11 15:10:15 +01:00
|
|
|
if (user == NULL)
|
2011-05-09 12:57:17 +02:00
|
|
|
goto error;
|
2007-06-11 22:03:05 +02:00
|
|
|
|
2007-02-23 12:13:55 +01:00
|
|
|
/*
|
2011-03-11 15:10:15 +01:00
|
|
|
Old clients send a null-terminated string as password; new clients send
|
2007-02-23 12:13:55 +01:00
|
|
|
the size (1 byte) + string (not null-terminated). Hence in case of empty
|
|
|
|
password both send '\0'.
|
|
|
|
*/
|
2011-05-09 12:57:17 +02:00
|
|
|
passwd_len= 0;
|
|
|
|
passwd= NULL;
|
2011-03-11 15:10:15 +01:00
|
|
|
|
|
|
|
if (thd->client_capabilities & CLIENT_SECURE_CONNECTION)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
4.1+ password. First byte is password length.
|
|
|
|
*/
|
|
|
|
passwd= get_length_encoded_string(&end, &bytes_remaining_in_packet,
|
|
|
|
&passwd_len);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Old passwords are zero terminated strings.
|
|
|
|
*/
|
2011-05-30 12:42:30 +02:00
|
|
|
passwd= get_string(&end, &bytes_remaining_in_packet, &passwd_len);
|
2011-03-11 15:10:15 +01:00
|
|
|
}
|
2007-02-23 12:13:55 +01:00
|
|
|
|
2011-03-11 15:10:15 +01:00
|
|
|
if (passwd == NULL)
|
2011-05-09 12:57:17 +02:00
|
|
|
goto error;
|
2007-02-23 12:13:55 +01:00
|
|
|
|
2011-05-09 12:57:17 +02:00
|
|
|
db_len= 0;
|
|
|
|
db= NULL;
|
2011-03-11 15:10:15 +01:00
|
|
|
|
|
|
|
if (thd->client_capabilities & CLIENT_CONNECT_WITH_DB)
|
|
|
|
{
|
2011-05-30 12:42:30 +02:00
|
|
|
db= get_string(&end, &bytes_remaining_in_packet, &db_len);
|
2011-03-11 15:10:15 +01:00
|
|
|
if (db == NULL)
|
2011-05-09 12:57:17 +02:00
|
|
|
goto error;
|
2011-03-11 15:10:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
char db_buff[NAME_LEN + 1]; // buffer to store db in utf8
|
|
|
|
char user_buff[USERNAME_LENGTH + 1]; // buffer to store user in utf8
|
|
|
|
uint dummy_errors;
|
|
|
|
|
2011-05-30 12:42:30 +02:00
|
|
|
/*
|
|
|
|
Copy and convert the user and database names to the character set used
|
|
|
|
by the server. Since 4.1 all database names are stored in UTF-8. Also,
|
|
|
|
ensure that the names are properly null-terminated as this is relied
|
|
|
|
upon later.
|
|
|
|
*/
|
2007-02-23 12:13:55 +01:00
|
|
|
if (db)
|
|
|
|
{
|
2011-05-30 12:42:30 +02:00
|
|
|
db_len= copy_and_convert(db_buff, sizeof(db_buff)-1, system_charset_info,
|
|
|
|
db, db_len, thd->charset(), &dummy_errors);
|
|
|
|
db_buff[db_len]= '\0';
|
2007-02-23 12:13:55 +01:00
|
|
|
db= db_buff;
|
|
|
|
}
|
|
|
|
|
2011-05-30 12:42:30 +02:00
|
|
|
user_len= copy_and_convert(user_buff, sizeof(user_buff)-1,
|
|
|
|
system_charset_info, user, user_len,
|
|
|
|
thd->charset(), &dummy_errors);
|
|
|
|
user_buff[user_len]= '\0';
|
2007-02-23 12:13:55 +01:00
|
|
|
user= user_buff;
|
|
|
|
|
|
|
|
/* If username starts and ends in "'", chop them off */
|
|
|
|
if (user_len > 1 && user[0] == '\'' && user[user_len - 1] == '\'')
|
|
|
|
{
|
|
|
|
user[user_len-1]= 0;
|
|
|
|
user++;
|
|
|
|
user_len-= 2;
|
|
|
|
}
|
|
|
|
|
2010-11-11 08:34:14 +01:00
|
|
|
/*
|
|
|
|
Clip username to allowed length in characters (not bytes). This is
|
|
|
|
mostly for backward compatibility.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
CHARSET_INFO *cs= system_charset_info;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
user_len= (uint) cs->cset->well_formed_len(cs, user, user + user_len,
|
|
|
|
USERNAME_CHAR_LENGTH, &err);
|
|
|
|
user[user_len]= '\0';
|
|
|
|
}
|
|
|
|
|
2007-10-31 22:10:58 +01:00
|
|
|
if (!(thd->main_security_ctx.user= my_strdup(user, MYF(MY_WME))))
|
|
|
|
return 1; /* The error is set by my_strdup(). */
|
2007-02-23 12:13:55 +01:00
|
|
|
return check_user(thd, COM_CONNECT, passwd, passwd_len, db, TRUE);
|
2011-05-09 12:57:17 +02:00
|
|
|
|
|
|
|
error:
|
|
|
|
inc_host_errors(&thd->remote.sin_addr);
|
2011-06-06 15:53:46 +02:00
|
|
|
my_error(ER_HANDSHAKE_ERROR, MYF(0));
|
2011-05-09 12:57:17 +02:00
|
|
|
return 1;
|
2007-02-23 12:13:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Setup thread to be used with the current thread
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
bool setup_connection_thread_globals()
|
|
|
|
thd Thread/connection handler
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 ok
|
|
|
|
1 Error (out of memory)
|
|
|
|
In this case we will close the connection and increment status
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool setup_connection_thread_globals(THD *thd)
|
|
|
|
{
|
|
|
|
if (thd->store_globals())
|
|
|
|
{
|
|
|
|
close_connection(thd, ER_OUT_OF_RESOURCES, 1);
|
|
|
|
statistic_increment(aborted_connects,&LOCK_status);
|
|
|
|
thread_scheduler.end_thread(thd, 0);
|
|
|
|
return 1; // Error
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Autenticate user, with error reporting
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
login_connection()
|
|
|
|
thd Thread handler
|
|
|
|
|
|
|
|
NOTES
|
|
|
|
Connection is not closed in case of errors
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 ok
|
|
|
|
1 error
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2008-03-12 15:44:40 +01:00
|
|
|
static bool login_connection(THD *thd)
|
2007-02-23 12:13:55 +01:00
|
|
|
{
|
|
|
|
NET *net= &thd->net;
|
2007-12-12 16:21:01 +01:00
|
|
|
int error;
|
2007-02-23 12:13:55 +01:00
|
|
|
DBUG_ENTER("login_connection");
|
2007-10-10 15:57:01 +02:00
|
|
|
DBUG_PRINT("info", ("login_connection called by thread %lu",
|
2007-02-23 12:13:55 +01:00
|
|
|
thd->thread_id));
|
|
|
|
|
|
|
|
/* Use "connect_timeout" value during connection phase */
|
2007-05-24 20:57:10 +02:00
|
|
|
my_net_set_read_timeout(net, connect_timeout);
|
|
|
|
my_net_set_write_timeout(net, connect_timeout);
|
2007-02-23 12:13:55 +01:00
|
|
|
|
2007-12-12 16:21:01 +01:00
|
|
|
error= check_connection(thd);
|
|
|
|
net_end_statement(thd);
|
|
|
|
|
|
|
|
if (error)
|
2007-02-23 12:13:55 +01:00
|
|
|
{ // Wrong permissions
|
|
|
|
#ifdef __NT__
|
|
|
|
if (vio_type(net->vio) == VIO_TYPE_NAMEDPIPE)
|
|
|
|
my_sleep(1000); /* must wait after eof() */
|
|
|
|
#endif
|
|
|
|
statistic_increment(aborted_connects,&LOCK_status);
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
/* Connect completed, set read/write timeouts back to default */
|
2007-05-24 20:57:10 +02:00
|
|
|
my_net_set_read_timeout(net, thd->variables.net_read_timeout);
|
|
|
|
my_net_set_write_timeout(net, thd->variables.net_write_timeout);
|
2007-02-23 12:13:55 +01:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Close an established connection
|
|
|
|
|
|
|
|
NOTES
|
|
|
|
This mainly updates status variables
|
|
|
|
*/
|
|
|
|
|
2008-03-12 15:44:40 +01:00
|
|
|
static void end_connection(THD *thd)
|
2007-02-23 12:13:55 +01:00
|
|
|
{
|
|
|
|
NET *net= &thd->net;
|
2007-03-02 17:43:45 +01:00
|
|
|
plugin_thdvar_cleanup(thd);
|
2007-02-23 12:13:55 +01:00
|
|
|
if (thd->user_connect)
|
|
|
|
decrease_user_connections(thd->user_connect);
|
2007-10-09 12:53:15 +02:00
|
|
|
|
2009-09-23 15:21:29 +02:00
|
|
|
if (thd->killed || (net->error && net->vio != 0))
|
2007-10-09 12:53:15 +02:00
|
|
|
{
|
|
|
|
statistic_increment(aborted_threads,&LOCK_status);
|
|
|
|
}
|
|
|
|
|
2007-12-12 16:21:01 +01:00
|
|
|
if (net->error && net->vio != 0)
|
2007-02-23 12:13:55 +01:00
|
|
|
{
|
|
|
|
if (!thd->killed && thd->variables.log_warnings > 1)
|
2007-10-09 12:53:15 +02:00
|
|
|
{
|
|
|
|
Security_context *sctx= thd->security_ctx;
|
|
|
|
|
2007-02-23 12:13:55 +01:00
|
|
|
sql_print_warning(ER(ER_NEW_ABORTING_CONNECTION),
|
|
|
|
thd->thread_id,(thd->db ? thd->db : "unconnected"),
|
|
|
|
sctx->user ? sctx->user : "unauthenticated",
|
|
|
|
sctx->host_or_ip,
|
2007-12-12 16:21:01 +01:00
|
|
|
(thd->main_da.is_error() ? thd->main_da.message() :
|
2007-02-23 12:13:55 +01:00
|
|
|
ER(ER_UNKNOWN_ERROR)));
|
2007-10-09 12:53:15 +02:00
|
|
|
}
|
2007-02-23 12:13:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Initialize THD to handle queries
|
|
|
|
*/
|
|
|
|
|
2007-10-10 15:57:01 +02:00
|
|
|
static void prepare_new_connection_state(THD* thd)
|
2007-02-23 12:13:55 +01:00
|
|
|
{
|
|
|
|
Security_context *sctx= thd->security_ctx;
|
|
|
|
|
|
|
|
#ifdef __NETWARE__
|
|
|
|
netware_reg_user(sctx->ip, sctx->user, "MySQL");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (thd->variables.max_join_size == HA_POS_ERROR)
|
|
|
|
thd->options |= OPTION_BIG_SELECTS;
|
|
|
|
if (thd->client_capabilities & CLIENT_COMPRESS)
|
|
|
|
thd->net.compress=1; // Use compression
|
|
|
|
|
2007-08-27 22:31:27 +02:00
|
|
|
/*
|
|
|
|
Much of this is duplicated in create_embedded_thd() for the
|
|
|
|
embedded server library.
|
|
|
|
TODO: refactor this to avoid code duplication there
|
|
|
|
*/
|
2007-02-23 12:13:55 +01:00
|
|
|
thd->version= refresh_version;
|
|
|
|
thd->proc_info= 0;
|
|
|
|
thd->command= COM_SLEEP;
|
|
|
|
thd->set_time();
|
|
|
|
thd->init_for_queries();
|
|
|
|
|
|
|
|
if (sys_init_connect.value_length && !(sctx->master_access & SUPER_ACL))
|
|
|
|
{
|
|
|
|
execute_init_command(thd, &sys_init_connect, &LOCK_sys_init_connect);
|
2007-12-12 16:21:01 +01:00
|
|
|
if (thd->is_error())
|
2007-02-23 12:13:55 +01:00
|
|
|
{
|
|
|
|
thd->killed= THD::KILL_CONNECTION;
|
|
|
|
sql_print_warning(ER(ER_NEW_ABORTING_CONNECTION),
|
|
|
|
thd->thread_id,(thd->db ? thd->db : "unconnected"),
|
|
|
|
sctx->user ? sctx->user : "unauthenticated",
|
|
|
|
sctx->host_or_ip, "init_connect command failed");
|
2007-12-12 16:21:01 +01:00
|
|
|
sql_print_warning("%s", thd->main_da.message());
|
2007-02-23 12:13:55 +01:00
|
|
|
}
|
|
|
|
thd->proc_info=0;
|
|
|
|
thd->set_time();
|
|
|
|
thd->init_for_queries();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Thread handler for a connection
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
handle_one_connection()
|
|
|
|
arg Connection object (THD)
|
|
|
|
|
|
|
|
IMPLEMENTATION
|
|
|
|
This function (normally) does the following:
|
|
|
|
- Initialize thread
|
|
|
|
- Initialize THD to be used with this thread
|
|
|
|
- Authenticate user
|
|
|
|
- Execute all queries sent on the connection
|
|
|
|
- Take connection down
|
|
|
|
- End thread / Handle next connection using thread from thread cache
|
|
|
|
*/
|
|
|
|
|
|
|
|
pthread_handler_t handle_one_connection(void *arg)
|
|
|
|
{
|
|
|
|
THD *thd= (THD*) arg;
|
2009-06-09 00:05:24 +02:00
|
|
|
|
|
|
|
thd->thr_create_utime= my_micro_time();
|
2007-02-23 12:13:55 +01:00
|
|
|
|
|
|
|
if (thread_scheduler.init_new_connection_thread())
|
|
|
|
{
|
|
|
|
close_connection(thd, ER_OUT_OF_RESOURCES, 1);
|
|
|
|
statistic_increment(aborted_connects,&LOCK_status);
|
|
|
|
thread_scheduler.end_thread(thd,0);
|
|
|
|
return 0;
|
|
|
|
}
|
2009-06-09 00:05:24 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
If a thread was created to handle this connection:
|
|
|
|
increment slow_launch_threads counter if it took more than
|
|
|
|
slow_launch_time seconds to create the thread.
|
|
|
|
*/
|
|
|
|
if (thd->prior_thr_create_utime)
|
|
|
|
{
|
|
|
|
ulong launch_time= (ulong) (thd->thr_create_utime -
|
|
|
|
thd->prior_thr_create_utime);
|
|
|
|
if (launch_time >= slow_launch_time*1000000L)
|
|
|
|
statistic_increment(slow_launch_threads, &LOCK_status);
|
|
|
|
thd->prior_thr_create_utime= 0;
|
|
|
|
}
|
2007-02-23 12:13:55 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
handle_one_connection() is normally the only way a thread would
|
|
|
|
start and would always be on the very high end of the stack ,
|
|
|
|
therefore, the thread stack always starts at the address of the
|
|
|
|
first local variable of handle_one_connection, which is thd. We
|
|
|
|
need to know the start of the stack so that we could check for
|
|
|
|
stack overruns.
|
|
|
|
*/
|
|
|
|
thd->thread_stack= (char*) &thd;
|
|
|
|
if (setup_connection_thread_globals(thd))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
NET *net= &thd->net;
|
|
|
|
|
2007-11-05 16:25:40 +01:00
|
|
|
lex_start(thd);
|
2007-02-23 12:13:55 +01:00
|
|
|
if (login_connection(thd))
|
|
|
|
goto end_thread;
|
|
|
|
|
|
|
|
prepare_new_connection_state(thd);
|
|
|
|
|
|
|
|
while (!net->error && net->vio != 0 &&
|
|
|
|
!(thd->killed == THD::KILL_CONNECTION))
|
|
|
|
{
|
|
|
|
if (do_command(thd))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
end_connection(thd);
|
|
|
|
|
|
|
|
end_thread:
|
|
|
|
close_connection(thd, 0, 1);
|
|
|
|
if (thread_scheduler.end_thread(thd,1))
|
|
|
|
return 0; // Probably no-threads
|
|
|
|
|
|
|
|
/*
|
|
|
|
If end_thread() returns, we are either running with
|
|
|
|
thread-handler=no-threads or this thread has been schedule to
|
|
|
|
handle the next connection.
|
|
|
|
*/
|
|
|
|
thd= current_thd;
|
|
|
|
thd->thread_stack= (char*) &thd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* EMBEDDED_LIBRARY */
|
2011-05-09 12:57:17 +02:00
|
|
|
|