1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

Intermediate commit - just to make new files visible to bk in the new

tree


server-tools/instance-manager/Makefile.am:
  Fixed IM linking to avoid using both mysys and libmysql as the define the
  same symbols and therefore conflict
server-tools/instance-manager/listener.cc:
  Added ability to listen network ports
server-tools/instance-manager/listener.h:
  Various additions to the Listener_thread_args
server-tools/instance-manager/log.cc:
  merge
server-tools/instance-manager/log.h:
  merge
server-tools/instance-manager/manager.cc:
  Fixes and additions to enable guardian functionality
server-tools/instance-manager/manager.h:
  Changed manager() signature
server-tools/instance-manager/mysqlmanager.cc:
  Various fixes
server-tools/instance-manager/options.cc:
  Added handling of default values for new options in the Options struct. (such
  as default_user, default_password, monitoring_interval e.t.c)
server-tools/instance-manager/options.h:
  Added new options to the Options struct
sql/net_serv.cc:
  Added MYSQL_INSTANCE_MANAGER defines to enable alarm handling in the IM
server-tools/instance-manager/buffer.cc:
  Simple implementation of variable-length buffer
server-tools/instance-manager/command.cc:
  Abstract command. All commands are derived from Command class
server-tools/instance-manager/commands.h:
  Interfaces for all commands we have
server-tools/instance-manager/factory.cc:
  Commands factory. This class hides command instantiation. The idea is to
  handle various protocols this way. (different commands for different
  protocols
server-tools/instance-manager/guardian.cc:
  Guardian thread implementation (monitor and restart instances in case of a
  failure
server-tools/instance-manager/guardian.h:
  Guardian_thread and Guardian_thread_args class interface. The
  Guardian_thread is responsible for monitoring and restarting instances
server-tools/instance-manager/instance.cc:
  Instance class contains methods and data to manage a single instance
server-tools/instance-manager/instance.h:
  This file contains class an instance class interface. The class is
  responsible for starting/stopping an instance
server-tools/instance-manager/instance_map.cc:
  The instance repository. This class is also responsible for initialization
  of Instance class objects.
server-tools/instance-manager/instance_options.cc:
  The Instance_options class contains all methods to get and  handle options
  of an instance
server-tools/instance-manager/mysql_connection.cc:
  The class responsible for handling MySQL client/server protocol connections
server-tools/instance-manager/mysql_manager_error.h:
  The list of Instance Manger-specific errors
server-tools/instance-manager/parse.cc:
  Simple query parser
server-tools/instance-manager/parse.h:
  Parser interface
server-tools/instance-manager/protocol.cc:
  Here implemented functions used to handle mysql client/server protocol
server-tools/instance-manager/protocol.h:
  Interface for MySQL client/server protocol
server-tools/instance-manager/thread_registry.cc:
  Thread registry stores information about every thread. It's main function is
  to provide graceful shutdown for all threads.
server-tools/instance-manager/user_map.h:
  User map contains hash with user names and passwords
This commit is contained in:
unknown
2004-10-23 11:32:52 +04:00
parent 746e6e53e7
commit a5435ea78a
42 changed files with 4261 additions and 148 deletions

View File

@ -0,0 +1,172 @@
/* Copyright (C) 2003 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
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; either version 2 of the License, or
(at your option) any later version.
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 */
#ifdef __GNUC__
#pragma interface
#endif
#include "user_map.h"
#include <mysql_com.h>
#include <m_string.h>
#include "log.h"
struct User
{
char user[USERNAME_LENGTH + 1];
uint8 user_length;
uint8 salt[SCRAMBLE_LENGTH];
int init(const char *line);
};
int User::init(const char *line)
{
const char *name_begin, *name_end, *password;
if (line[0] == '\'' || line[0] == '"')
{
name_begin= line + 1;
name_end= strchr(name_begin, line[0]);
if (name_end == 0 || name_end[1] != ':')
goto err;
password= name_end + 2;
}
else
{
name_begin= line;
name_end= strchr(name_begin, ':');
if (name_end == 0)
goto err;
password= name_end + 1;
}
user_length= name_end - name_begin;
if (user_length > USERNAME_LENGTH)
goto err;
/* assume that newline characater is present */
if (strlen(password) != SCRAMBLED_PASSWORD_CHAR_LENGTH + 1)
goto err;
memcpy(user, name_begin, user_length);
user[user_length]= 0;
get_salt_from_password(salt, password);
log_info("loaded user %s", user);
return 0;
err:
log_error("error parsing user and password at line %d", line);
return 1;
}
C_MODE_START
static byte* get_user_key(const byte* u, uint* len,
my_bool __attribute__((unused)) t)
{
const User *user= (const User *) u;
*len= user->user_length;
return (byte *) user->user;
}
static void delete_user(void *u)
{
User *user= (User *) u;
delete user;
}
C_MODE_END
User_map::User_map()
{
enum { START_HASH_SIZE = 16 };
hash_init(&hash, default_charset_info, START_HASH_SIZE, 0, 0,
get_user_key, delete_user, 0);
}
User_map::~User_map()
{
hash_free(&hash);
}
/*
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 1
*/
int User_map::load(const char *password_file_name)
{
FILE *file;
char line[USERNAME_LENGTH + SCRAMBLED_PASSWORD_CHAR_LENGTH +
2 + /* for possible quotes */
1 + /* for ':' */
1 + /* for newline */
1]; /* for trailing zero */
uint line_length;
User *user;
int rc= 1;
if ((file= my_fopen(password_file_name, O_RDONLY | O_BINARY, MYF(0))) == 0)
{
log_error("can't open password file %s: errno=%d, %s", password_file_name,
errno, strerror(errno));
return 1;
}
while (fgets(line, sizeof(line), file))
{
/* skip comments and empty lines */
if (line[0] == '#' || line[0] == '\n' && line[1] == '\0')
continue;
if ((user= new User) == 0)
goto done;
if (user->init(line) || my_hash_insert(&hash, (byte *) user))
goto err_init_user;
}
if (feof(file))
rc= 0;
goto done;
err_init_user:
delete user;
done:
my_fclose(file, MYF(0));
return rc;
}
/*
Check if user exists and password is correct
RETURN VALUE
0 - user found and password OK
1 - password mismatch
2 - user not found
*/
int User_map::authenticate(const char *user_name, uint length,
const char *scrambled_password,
const char *scramble) const
{
const User *user= (const User *) hash_search((HASH *) &hash,
(byte *) user_name, length);
if (user)
return check_scramble(scrambled_password, scramble, user->salt);
return 2;
}