Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
1815de7b
Commit
1815de7b
authored
Feb 05, 2005
by
petr@mysql.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--user option added to mysqlmanager
parent
321c53d9
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
92 additions
and
11 deletions
+92
-11
server-tools/instance-manager/mysql_connection.cc
server-tools/instance-manager/mysql_connection.cc
+0
-7
server-tools/instance-manager/mysqlmanager.cc
server-tools/instance-manager/mysqlmanager.cc
+84
-0
server-tools/instance-manager/options.cc
server-tools/instance-manager/options.cc
+7
-2
server-tools/instance-manager/options.h
server-tools/instance-manager/options.h
+1
-2
No files found.
server-tools/instance-manager/mysql_connection.cc
View file @
1815de7b
...
...
@@ -82,7 +82,6 @@ class Mysql_connection_thread: public Mysql_connection_thread_args
private:
/* Names are conventionally the same as in mysqld */
int
check_connection
();
int
check_user
(
const
char
*
user
,
const
char
*
password
);
int
do_command
();
int
dispatch_command
(
enum
enum_server_command
command
,
const
char
*
text
,
uint
len
);
...
...
@@ -287,12 +286,6 @@ int Mysql_connection_thread::check_connection()
}
int
Mysql_connection_thread
::
check_user
(
const
char
*
user
,
const
char
*
password
)
{
return
0
;
}
int
Mysql_connection_thread
::
do_command
()
{
char
*
packet
;
...
...
server-tools/instance-manager/mysqlmanager.cc
View file @
1815de7b
...
...
@@ -22,6 +22,8 @@
#include <my_sys.h>
#include <string.h>
#include <signal.h>
#include <pwd.h>
#include <grp.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/stat.h>
...
...
@@ -54,6 +56,8 @@
static
void
init_environment
(
char
*
progname
);
static
void
daemonize
(
const
char
*
log_file_name
);
static
void
angel
(
const
Options
&
options
);
static
struct
passwd
*
check_user
(
const
char
*
user
);
static
int
set_user
(
const
char
*
user
,
struct
passwd
*
user_info
);
/*
...
...
@@ -68,7 +72,19 @@ int main(int argc, char *argv[])
{
init_environment
(
argv
[
0
]);
Options
options
;
struct
passwd
*
user_info
;
options
.
load
(
argc
,
argv
);
if
((
user_info
=
check_user
(
options
.
user
)))
{
if
(
set_user
(
options
.
user
,
user_info
))
{
options
.
cleanup
();
return
1
;
}
}
if
(
options
.
run_as_service
)
{
/* forks, and returns only in child */
...
...
@@ -84,6 +100,74 @@ int main(int argc, char *argv[])
/******************* Auxilary functions implementation **********************/
/* Change to run as another user if started with --user */
static
struct
passwd
*
check_user
(
const
char
*
user
)
{
#if !defined(__WIN__) && !defined(OS2) && !defined(__NETWARE__)
struct
passwd
*
user_info
;
uid_t
user_id
=
geteuid
();
/* Don't bother if we aren't superuser */
if
(
user_id
)
{
if
(
user
)
{
/* Don't give a warning, if real user is same as given with --user */
user_info
=
getpwnam
(
user
);
if
((
!
user_info
||
user_id
!=
user_info
->
pw_uid
))
log_info
(
"One can only use the --user switch if running as root
\n
"
);
}
return
NULL
;
}
if
(
!
user
)
{
log_info
(
"You are running mysqlmanager as root! This might introduce security problems. It is safer to use --user option istead.
\n
"
);
return
NULL
;
}
if
(
!
strcmp
(
user
,
"root"
))
return
NULL
;
/* Avoid problem with dynamic libraries */
if
(
!
(
user_info
=
getpwnam
(
user
)))
{
/* Allow a numeric uid to be used */
const
char
*
pos
;
for
(
pos
=
user
;
my_isdigit
(
default_charset_info
,
*
pos
);
pos
++
)
;
if
(
*
pos
)
/* Not numeric id */
goto
err
;
if
(
!
(
user_info
=
getpwuid
(
atoi
(
user
))))
goto
err
;
else
return
user_info
;
}
else
return
user_info
;
err:
log_error
(
"Fatal error: Can't change to run as user '%s' ; Please check that the user exists!
\n
"
,
user
);
#endif
return
NULL
;
}
static
int
set_user
(
const
char
*
user
,
struct
passwd
*
user_info
)
{
DBUG_ASSERT
(
user_info
);
#ifdef HAVE_INITGROUPS
initgroups
((
char
*
)
user
,
user_info
->
pw_gid
);
#endif
if
(
setgid
(
user_info
->
pw_gid
)
==
-
1
)
{
log_error
(
"setgid() failed"
);
return
1
;
}
if
(
setuid
(
user_info
->
pw_uid
)
==
-
1
)
{
log_error
(
"setuid() failed"
);
return
1
;
}
return
0
;
}
/*
Init environment, common for daemon and non-daemon
...
...
server-tools/instance-manager/options.cc
View file @
1815de7b
...
...
@@ -36,6 +36,7 @@ const char *Options::socket_file_name= QUOTE(DEFAULT_SOCKET_FILE_NAME);
const
char
*
Options
::
password_file_name
=
QUOTE
(
DEFAULT_PASSWORD_FILE_NAME
);
const
char
*
Options
::
default_mysqld_path
=
QUOTE
(
DEFAULT_MYSQLD_PATH
);
const
char
*
Options
::
bind_address
=
0
;
/* No default value */
const
char
*
Options
::
user
=
0
;
/* No default value */
uint
Options
::
monitoring_interval
=
DEFAULT_MONITORING_INTERVAL
;
uint
Options
::
port_number
=
DEFAULT_PORT
;
/* just to declare */
...
...
@@ -54,7 +55,6 @@ enum options {
OPT_MYSQLD_PATH
,
OPT_RUN_AS_SERVICE
,
OPT_USER
,
OPT_PASSWORD
,
OPT_MONITORING_INTERVAL
,
OPT_PORT
,
OPT_BIND_ADDRESS
...
...
@@ -107,6 +107,11 @@ static struct my_option my_long_options[] =
"Daemonize and start angel process."
,
(
gptr
*
)
&
Options
::
run_as_service
,
0
,
0
,
GET_BOOL
,
NO_ARG
,
0
,
0
,
1
,
0
,
0
,
0
},
{
"user"
,
OPT_USER
,
"Username to start mysqlmanager"
,
(
gptr
*
)
&
Options
::
user
,
(
gptr
*
)
&
Options
::
user
,
0
,
GET_STR
,
REQUIRED_ARG
,
0
,
0
,
0
,
0
,
0
,
0
},
{
"version"
,
'V'
,
"Output version information and exit."
,
0
,
0
,
0
,
GET_NO_ARG
,
NO_ARG
,
0
,
0
,
0
,
0
,
0
,
0
},
...
...
server-tools/instance-manager/options.h
View file @
1815de7b
...
...
@@ -34,8 +34,7 @@ struct Options
static
const
char
*
socket_file_name
;
static
const
char
*
password_file_name
;
static
const
char
*
default_mysqld_path
;
static
const
char
*
default_admin_user
;
static
const
char
*
default_admin_password
;
static
const
char
*
user
;
static
uint
monitoring_interval
;
static
uint
port_number
;
static
const
char
*
bind_address
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment