2006-12-31 01:02:27 +01:00
|
|
|
/* Copyright (C) 2004-2006 MySQL AB
|
2004-10-23 11:32:52 +04: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
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2004-10-23 11:32:52 +04:00
|
|
|
|
|
|
|
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
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
|
2005-09-23 21:28:56 +03:00
|
|
|
#if defined(__GNUC__) && defined(USE_PRAGMA_IMPLEMENTATION)
|
2005-10-07 20:25:51 +04:00
|
|
|
#pragma implementation
|
2004-10-23 11:32:52 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "user_map.h"
|
2006-05-18 18:57:50 +04:00
|
|
|
#include "exit_codes.h"
|
2004-10-23 11:32:52 +04:00
|
|
|
#include "log.h"
|
2006-05-19 04:51:23 +04:00
|
|
|
#include "portability.h"
|
2004-10-23 11:32:52 +04:00
|
|
|
|
2006-05-18 18:57:50 +04:00
|
|
|
User::User(const LEX_STRING *user_name_arg, const char *password)
|
2004-10-23 11:32:52 +04:00
|
|
|
{
|
2007-02-27 19:31:49 +02:00
|
|
|
user_length= (uint8) (strmake(user, user_name_arg->str,
|
|
|
|
USERNAME_LENGTH + 1) - user);
|
2006-05-18 18:57:50 +04:00
|
|
|
set_password(password);
|
|
|
|
}
|
2004-10-23 11:32:52 +04:00
|
|
|
|
|
|
|
int User::init(const char *line)
|
|
|
|
{
|
2005-08-05 17:02:06 +04:00
|
|
|
const char *name_begin, *name_end, *password;
|
2006-05-18 18:57:50 +04:00
|
|
|
int password_length;
|
2004-10-23 11:32:52 +04:00
|
|
|
|
|
|
|
if (line[0] == '\'' || line[0] == '"')
|
|
|
|
{
|
|
|
|
name_begin= line + 1;
|
|
|
|
name_end= strchr(name_begin, line[0]);
|
|
|
|
if (name_end == 0 || name_end[1] != ':')
|
2006-05-18 18:57:50 +04:00
|
|
|
{
|
2006-11-21 17:47:14 +03:00
|
|
|
log_error("Invalid format (unmatched quote) of user line (%s).",
|
2006-11-30 12:23:55 +03:00
|
|
|
(const char *) line);
|
2006-05-18 18:57:50 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2005-08-05 17:02:06 +04:00
|
|
|
password= name_end + 2;
|
2004-10-23 11:32:52 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
name_begin= line;
|
|
|
|
name_end= strchr(name_begin, ':');
|
|
|
|
if (name_end == 0)
|
2006-05-18 18:57:50 +04:00
|
|
|
{
|
2006-11-21 17:47:14 +03:00
|
|
|
log_error("Invalid format (no delimiter) of user line (%s).",
|
2006-11-30 12:23:55 +03:00
|
|
|
(const char *) line);
|
2006-05-18 18:57:50 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2005-08-05 17:02:06 +04:00
|
|
|
password= name_end + 1;
|
2004-10-23 11:32:52 +04:00
|
|
|
}
|
2006-05-18 18:57:50 +04:00
|
|
|
|
2007-02-27 19:31:49 +02:00
|
|
|
user_length= (uint8) (name_end - name_begin);
|
2004-10-23 11:32:52 +04:00
|
|
|
if (user_length > USERNAME_LENGTH)
|
2006-05-18 18:57:50 +04:00
|
|
|
{
|
2006-11-21 17:47:14 +03:00
|
|
|
log_error("User name is too long (%d). Max length: %d. "
|
2006-11-30 12:23:55 +03:00
|
|
|
"User line: '%s'.",
|
|
|
|
(int) user_length,
|
|
|
|
(int) USERNAME_LENGTH,
|
|
|
|
(const char *) line);
|
2006-05-18 18:57:50 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-02-27 19:31:49 +02:00
|
|
|
password_length= (int) strlen(password);
|
2006-05-18 18:57:50 +04:00
|
|
|
if (password_length > SCRAMBLED_PASSWORD_CHAR_LENGTH)
|
|
|
|
{
|
2006-11-21 17:47:14 +03:00
|
|
|
log_error("Password is too long (%d). Max length: %d."
|
2006-11-30 12:23:55 +03:00
|
|
|
"User line: '%s'.",
|
|
|
|
(int) password_length,
|
|
|
|
(int) SCRAMBLED_PASSWORD_CHAR_LENGTH,
|
|
|
|
(const char *) line);
|
2006-05-18 18:57:50 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2004-10-23 11:32:52 +04:00
|
|
|
|
|
|
|
memcpy(user, name_begin, user_length);
|
|
|
|
user[user_length]= 0;
|
2006-05-18 18:57:50 +04:00
|
|
|
|
|
|
|
memcpy(scrambled_password, password, password_length);
|
|
|
|
scrambled_password[password_length]= 0;
|
|
|
|
|
2004-10-23 11:32:52 +04:00
|
|
|
get_salt_from_password(salt, password);
|
2006-05-18 18:57:50 +04:00
|
|
|
|
2006-11-21 17:47:14 +03:00
|
|
|
log_info("Loaded user '%s'.", (const char *) user);
|
2004-10-23 11:32:52 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
C_MODE_START
|
|
|
|
|
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 12:59:39 +03:00
|
|
|
static uchar* get_user_key(const uchar* u, size_t* len,
|
|
|
|
my_bool __attribute__((unused)) t)
|
2004-10-23 11:32:52 +04:00
|
|
|
{
|
|
|
|
const User *user= (const User *) u;
|
|
|
|
*len= user->user_length;
|
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 12:59:39 +03:00
|
|
|
return (uchar *) user->user;
|
2004-10-23 11:32:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void delete_user(void *u)
|
|
|
|
{
|
|
|
|
User *user= (User *) u;
|
|
|
|
delete user;
|
|
|
|
}
|
|
|
|
|
|
|
|
C_MODE_END
|
|
|
|
|
|
|
|
|
2006-05-18 18:57:50 +04:00
|
|
|
void User_map::Iterator::reset()
|
|
|
|
{
|
|
|
|
cur_idx= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
User *User_map::Iterator::next()
|
|
|
|
{
|
|
|
|
if (cur_idx < user_map->hash.records)
|
|
|
|
return (User *) hash_element(&user_map->hash, cur_idx++);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-02 10:11:03 +03:00
|
|
|
int User_map::init()
|
2004-10-23 11:32:52 +04:00
|
|
|
{
|
2005-08-05 17:02:06 +04:00
|
|
|
enum { START_HASH_SIZE= 16 };
|
2004-11-02 10:11:03 +03:00
|
|
|
if (hash_init(&hash, default_charset_info, START_HASH_SIZE, 0, 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 12:59:39 +03:00
|
|
|
get_user_key, delete_user, 0))
|
2004-11-02 10:11:03 +03:00
|
|
|
return 1;
|
2006-05-18 18:57:50 +04:00
|
|
|
|
|
|
|
initialized= TRUE;
|
|
|
|
|
2004-11-02 10:11:03 +03:00
|
|
|
return 0;
|
2004-10-23 11:32:52 +04:00
|
|
|
}
|
|
|
|
|
2004-11-02 10:11:03 +03:00
|
|
|
|
2006-05-18 18:57:50 +04:00
|
|
|
User_map::User_map()
|
|
|
|
:initialized(FALSE)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-23 11:32:52 +04:00
|
|
|
User_map::~User_map()
|
|
|
|
{
|
2006-05-18 18:57:50 +04:00
|
|
|
if (initialized)
|
|
|
|
hash_free(&hash);
|
2004-10-23 11:32:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-05-18 18:57:50 +04:00
|
|
|
Load password database.
|
|
|
|
|
2006-11-18 01:34:44 +03:00
|
|
|
SYNOPSIS
|
2006-05-18 18:57:50 +04:00
|
|
|
load()
|
|
|
|
password_file_name [IN] password file path
|
|
|
|
err_msg [OUT] error message
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
Load all users from the password file. Must be called once right after
|
|
|
|
construction. In case of failure, puts error message to the log file and
|
|
|
|
returns specific error code.
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 on success
|
|
|
|
!0 on error
|
2004-10-23 11:32:52 +04:00
|
|
|
*/
|
|
|
|
|
2006-05-18 18:57:50 +04:00
|
|
|
int User_map::load(const char *password_file_name, const char **err_msg)
|
2004-10-23 11:32:52 +04:00
|
|
|
{
|
2006-05-18 18:57:50 +04:00
|
|
|
static const int ERR_MSG_BUF_SIZE = 255;
|
|
|
|
static char err_msg_buf[ERR_MSG_BUF_SIZE];
|
|
|
|
|
2004-10-23 11:32:52 +04:00
|
|
|
FILE *file;
|
|
|
|
char line[USERNAME_LENGTH + SCRAMBLED_PASSWORD_CHAR_LENGTH +
|
|
|
|
2 + /* for possible quotes */
|
|
|
|
1 + /* for ':' */
|
2005-08-29 23:29:35 +04:00
|
|
|
2 + /* for newline */
|
2004-10-23 11:32:52 +04:00
|
|
|
1]; /* for trailing zero */
|
|
|
|
User *user;
|
|
|
|
|
2006-05-18 18:57:50 +04:00
|
|
|
if (my_access(password_file_name, F_OK) != 0)
|
|
|
|
{
|
|
|
|
if (err_msg)
|
|
|
|
{
|
|
|
|
snprintf(err_msg_buf, ERR_MSG_BUF_SIZE,
|
|
|
|
"password file (%s) does not exist",
|
|
|
|
(const char *) password_file_name);
|
|
|
|
*err_msg= err_msg_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERR_PASSWORD_FILE_DOES_NOT_EXIST;
|
|
|
|
}
|
|
|
|
|
2004-10-23 11:32:52 +04:00
|
|
|
if ((file= my_fopen(password_file_name, O_RDONLY | O_BINARY, MYF(0))) == 0)
|
|
|
|
{
|
2006-05-18 18:57:50 +04:00
|
|
|
if (err_msg)
|
|
|
|
{
|
|
|
|
snprintf(err_msg_buf, ERR_MSG_BUF_SIZE,
|
|
|
|
"can not open password file (%s): %s",
|
|
|
|
(const char *) password_file_name,
|
|
|
|
(const char *) strerror(errno));
|
|
|
|
*err_msg= err_msg_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERR_IO_ERROR;
|
2004-10-23 11:32:52 +04:00
|
|
|
}
|
|
|
|
|
2006-11-21 17:47:14 +03:00
|
|
|
log_info("Loading the password database...");
|
2006-05-18 18:57:50 +04:00
|
|
|
|
2004-10-23 11:32:52 +04:00
|
|
|
while (fgets(line, sizeof(line), file))
|
|
|
|
{
|
2006-05-18 18:57:50 +04:00
|
|
|
char *user_line= line;
|
|
|
|
|
|
|
|
/*
|
|
|
|
We need to skip EOL-symbols also from the beginning of the line, because
|
|
|
|
if the previous line was ended by \n\r sequence, we get \r in our line.
|
|
|
|
*/
|
|
|
|
|
|
|
|
while (user_line[0] == '\r' || user_line[0] == '\n')
|
|
|
|
++user_line;
|
|
|
|
|
|
|
|
/* Skip EOL-symbols in the end of the line. */
|
|
|
|
|
|
|
|
{
|
|
|
|
char *ptr;
|
|
|
|
|
|
|
|
if ((ptr= strchr(user_line, '\n')))
|
|
|
|
*ptr= 0;
|
|
|
|
|
|
|
|
if ((ptr= strchr(user_line, '\r')))
|
|
|
|
*ptr= 0;
|
|
|
|
}
|
|
|
|
|
2004-10-23 11:32:52 +04:00
|
|
|
/* skip comments and empty lines */
|
2006-05-18 18:57:50 +04:00
|
|
|
if (!user_line[0] || user_line[0] == '#')
|
2004-10-23 11:32:52 +04:00
|
|
|
continue;
|
2006-05-18 18:57:50 +04:00
|
|
|
|
2004-10-23 11:32:52 +04:00
|
|
|
if ((user= new User) == 0)
|
2006-05-18 18:57:50 +04:00
|
|
|
{
|
|
|
|
my_fclose(file, MYF(0));
|
|
|
|
|
|
|
|
if (err_msg)
|
|
|
|
{
|
|
|
|
snprintf(err_msg_buf, ERR_MSG_BUF_SIZE,
|
|
|
|
"out of memory while parsing password file (%s)",
|
|
|
|
(const char *) password_file_name);
|
|
|
|
*err_msg= err_msg_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (user->init(user_line))
|
|
|
|
{
|
|
|
|
delete user;
|
|
|
|
my_fclose(file, MYF(0));
|
|
|
|
|
|
|
|
if (err_msg)
|
|
|
|
{
|
|
|
|
snprintf(err_msg_buf, ERR_MSG_BUF_SIZE,
|
|
|
|
"password file (%s) corrupted",
|
|
|
|
(const char *) password_file_name);
|
|
|
|
*err_msg= err_msg_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERR_PASSWORD_FILE_CORRUPTED;
|
|
|
|
}
|
|
|
|
|
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 12:59:39 +03:00
|
|
|
if (my_hash_insert(&hash, (uchar *) user))
|
2006-05-18 18:57:50 +04:00
|
|
|
{
|
|
|
|
delete user;
|
|
|
|
my_fclose(file, MYF(0));
|
|
|
|
|
|
|
|
if (err_msg)
|
|
|
|
{
|
|
|
|
snprintf(err_msg_buf, ERR_MSG_BUF_SIZE,
|
|
|
|
"out of memory while parsing password file (%s)",
|
|
|
|
(const char *) password_file_name);
|
|
|
|
*err_msg= err_msg_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERR_OUT_OF_MEMORY;
|
|
|
|
}
|
2004-10-23 11:32:52 +04:00
|
|
|
}
|
2006-05-18 18:57:50 +04:00
|
|
|
|
2006-11-21 17:47:14 +03:00
|
|
|
log_info("The password database loaded successfully.");
|
2006-05-18 18:57:50 +04:00
|
|
|
|
2004-10-23 11:32:52 +04:00
|
|
|
my_fclose(file, MYF(0));
|
2006-05-18 18:57:50 +04:00
|
|
|
|
|
|
|
if (err_msg)
|
|
|
|
*err_msg= NULL;
|
|
|
|
|
|
|
|
return ERR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int User_map::save(const char *password_file_name, const char **err_msg)
|
|
|
|
{
|
|
|
|
static const int ERR_MSG_BUF_SIZE = 255;
|
|
|
|
static char err_msg_buf[ERR_MSG_BUF_SIZE];
|
|
|
|
|
|
|
|
FILE *file;
|
|
|
|
|
|
|
|
if ((file= my_fopen(password_file_name, O_WRONLY | O_TRUNC | O_BINARY,
|
|
|
|
MYF(0))) == 0)
|
|
|
|
{
|
|
|
|
if (err_msg)
|
|
|
|
{
|
|
|
|
snprintf(err_msg_buf, ERR_MSG_BUF_SIZE,
|
|
|
|
"can not open password file (%s) for writing: %s",
|
|
|
|
(const char *) password_file_name,
|
|
|
|
(const char *) strerror(errno));
|
|
|
|
*err_msg= err_msg_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERR_IO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
User_map::Iterator it(this);
|
|
|
|
User *user;
|
|
|
|
|
|
|
|
while ((user= it.next()))
|
|
|
|
{
|
|
|
|
if (fprintf(file, "%s:%s\n", (const char *) user->user,
|
|
|
|
(const char *) user->scrambled_password) < 0)
|
|
|
|
{
|
|
|
|
if (err_msg)
|
|
|
|
{
|
|
|
|
snprintf(err_msg_buf, ERR_MSG_BUF_SIZE,
|
|
|
|
"can not write to password file (%s): %s",
|
|
|
|
(const char *) password_file_name,
|
|
|
|
(const char *) strerror(errno));
|
|
|
|
*err_msg= err_msg_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
my_fclose(file, MYF(0));
|
|
|
|
|
|
|
|
return ERR_IO_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
my_fclose(file, MYF(0));
|
|
|
|
|
|
|
|
return ERR_OK;
|
2004-10-23 11:32:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Check if user exists and password is correct
|
|
|
|
RETURN VALUE
|
|
|
|
0 - user found and password OK
|
|
|
|
1 - password mismatch
|
|
|
|
2 - user not found
|
|
|
|
*/
|
|
|
|
|
2006-05-18 18:57:50 +04:00
|
|
|
int User_map::authenticate(const LEX_STRING *user_name,
|
2004-10-23 11:32:52 +04:00
|
|
|
const char *scrambled_password,
|
|
|
|
const char *scramble) const
|
|
|
|
{
|
2006-05-18 18:57:50 +04:00
|
|
|
const User *user= find_user(user_name);
|
|
|
|
return user ? check_scramble(scrambled_password, scramble, user->salt) : 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
User *User_map::find_user(const LEX_STRING *user_name)
|
|
|
|
{
|
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 12:59:39 +03:00
|
|
|
return (User*) hash_search(&hash, (uchar*) user_name->str, user_name->length);
|
2006-05-18 18:57:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
const User *User_map::find_user(const LEX_STRING *user_name) const
|
|
|
|
{
|
|
|
|
return const_cast<User_map *> (this)->find_user(user_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool User_map::add_user(User *user)
|
|
|
|
{
|
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 12:59:39 +03:00
|
|
|
return my_hash_insert(&hash, (uchar*) user) == 0 ? FALSE : TRUE;
|
2006-05-18 18:57:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool User_map::remove_user(User *user)
|
|
|
|
{
|
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 12:59:39 +03:00
|
|
|
return hash_delete(&hash, (uchar*) user) == 0 ? FALSE : TRUE;
|
2004-10-23 11:32:52 +04:00
|
|
|
}
|