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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
66f0c2e3
Commit
66f0c2e3
authored
Oct 18, 2013
by
Sergei Golubchik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
small cleanup
parent
0c303b52
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
53 deletions
+66
-53
sql/sql_acl.cc
sql/sql_acl.cc
+66
-53
No files found.
sql/sql_acl.cc
View file @
66f0c2e3
...
@@ -574,13 +574,16 @@ static uchar* acl_role_get_key(ACL_ROLE *entry, size_t *length,
...
@@ -574,13 +574,16 @@ static uchar* acl_role_get_key(ACL_ROLE *entry, size_t *length,
return
(
uchar
*
)
entry
->
user
.
str
;
return
(
uchar
*
)
entry
->
user
.
str
;
}
}
typedef
struct
st_role_grant
struct
ROLE_GRANT_PAIR
:
public
Sql_alloc
{
{
char
*
u_uname
;
char
*
u_uname
;
char
*
u_hname
;
char
*
u_hname
;
char
*
r_uname
;
char
*
r_uname
;
LEX_STRING
hashkey
;
LEX_STRING
hashkey
;
}
ROLE_GRANT_PAIR
;
bool
init
(
MEM_ROOT
*
mem
,
char
*
username
,
char
*
hostname
,
char
*
rolename
);
};
/*
/*
Struct to hold the state of a node during a Depth First Search exploration
Struct to hold the state of a node during a Depth First Search exploration
*/
*/
...
@@ -598,9 +601,12 @@ static uchar* acl_role_map_get_key(ROLE_GRANT_PAIR *entry, size_t *length,
...
@@ -598,9 +601,12 @@ static uchar* acl_role_map_get_key(ROLE_GRANT_PAIR *entry, size_t *length,
return
(
uchar
*
)
entry
->
hashkey
.
str
;
return
(
uchar
*
)
entry
->
hashkey
.
str
;
}
}
static
void
init_role_grant_pair
(
MEM_ROOT
*
mem
,
ROLE_GRANT_PAIR
*
entry
,
bool
ROLE_GRANT_PAIR
::
init
(
MEM_ROOT
*
mem
,
char
*
username
,
char
*
username
,
char
*
hostname
,
char
*
rolename
)
char
*
hostname
,
char
*
rolename
)
{
{
if
(
!
this
)
return
true
;
size_t
uname_l
=
username
?
strlen
(
username
)
:
0
;
size_t
uname_l
=
username
?
strlen
(
username
)
:
0
;
size_t
hname_l
=
hostname
?
strlen
(
hostname
)
:
0
;
size_t
hname_l
=
hostname
?
strlen
(
hostname
)
:
0
;
size_t
rname_l
=
rolename
?
strlen
(
rolename
)
:
0
;
size_t
rname_l
=
rolename
?
strlen
(
rolename
)
:
0
;
...
@@ -610,6 +616,9 @@ static void init_role_grant_pair(MEM_ROOT *mem, ROLE_GRANT_PAIR *entry,
...
@@ -610,6 +616,9 @@ static void init_role_grant_pair(MEM_ROOT *mem, ROLE_GRANT_PAIR *entry,
*/
*/
size_t
bufflen
=
uname_l
+
hname_l
+
rname_l
+
3
;
//add the '\0' aswell
size_t
bufflen
=
uname_l
+
hname_l
+
rname_l
+
3
;
//add the '\0' aswell
char
*
buff
=
(
char
*
)
alloc_root
(
mem
,
bufflen
);
char
*
buff
=
(
char
*
)
alloc_root
(
mem
,
bufflen
);
if
(
!
buff
)
return
true
;
/*
/*
Offsets in the buffer for all 3 strings
Offsets in the buffer for all 3 strings
*/
*/
...
@@ -620,20 +629,22 @@ static void init_role_grant_pair(MEM_ROOT *mem, ROLE_GRANT_PAIR *entry,
...
@@ -620,20 +629,22 @@ static void init_role_grant_pair(MEM_ROOT *mem, ROLE_GRANT_PAIR *entry,
if
(
username
)
//prevent undefined behaviour
if
(
username
)
//prevent undefined behaviour
memcpy
(
username_pos
,
username
,
uname_l
);
memcpy
(
username_pos
,
username
,
uname_l
);
username_pos
[
uname_l
]
=
'\0'
;
//#1 string terminator
username_pos
[
uname_l
]
=
'\0'
;
//#1 string terminator
entry
->
u_uname
=
username_pos
;
u_uname
=
username_pos
;
if
(
hostname
)
//prevent undefined behaviour
if
(
hostname
)
//prevent undefined behaviour
memcpy
(
hostname_pos
,
hostname
,
hname_l
);
memcpy
(
hostname_pos
,
hostname
,
hname_l
);
hostname_pos
[
hname_l
]
=
'\0'
;
//#2 string terminator
hostname_pos
[
hname_l
]
=
'\0'
;
//#2 string terminator
entry
->
u_hname
=
hostname_pos
;
u_hname
=
hostname_pos
;
if
(
rolename
)
//prevent undefined behaviour
if
(
rolename
)
//prevent undefined behaviour
memcpy
(
rolename_pos
,
rolename
,
rname_l
);
memcpy
(
rolename_pos
,
rolename
,
rname_l
);
rolename_pos
[
rname_l
]
=
'\0'
;
//#3 string terminator
rolename_pos
[
rname_l
]
=
'\0'
;
//#3 string terminator
entry
->
r_uname
=
rolename_pos
;
r_uname
=
rolename_pos
;
entry
->
hashkey
.
str
=
buff
;
hashkey
.
str
=
buff
;
entry
->
hashkey
.
length
=
bufflen
;
hashkey
.
length
=
bufflen
;
return
false
;
}
}
#define IP_ADDR_STRLEN (3 + 1 + 3 + 1 + 3 + 1 + 3)
#define IP_ADDR_STRLEN (3 + 1 + 3 + 1 + 3 + 1 + 3)
...
@@ -1388,13 +1399,14 @@ static my_bool acl_load(THD *thd, TABLE_LIST *tables)
...
@@ -1388,13 +1399,14 @@ static my_bool acl_load(THD *thd, TABLE_LIST *tables)
init_alloc_root
(
&
temp_root
,
ACL_ALLOC_BLOCK_SIZE
,
0
,
MYF
(
0
));
init_alloc_root
(
&
temp_root
,
ACL_ALLOC_BLOCK_SIZE
,
0
,
MYF
(
0
));
while
(
!
(
read_record_info
.
read_record
(
&
read_record_info
)))
while
(
!
(
read_record_info
.
read_record
(
&
read_record_info
)))
{
{
ROLE_GRANT_PAIR
*
mapping
=
(
ROLE_GRANT_PAIR
*
)
alloc_root
(
ROLE_GRANT_PAIR
*
mapping
=
new
(
&
mem
)
ROLE_GRANT_PAIR
;
&
mem
,
sizeof
(
ROLE_GRANT_PAIR
));
char
*
hostname
=
get_field
(
&
temp_root
,
table
->
field
[
0
]);
char
*
hostname
=
get_field
(
&
temp_root
,
table
->
field
[
0
]);
char
*
username
=
get_field
(
&
temp_root
,
table
->
field
[
1
]);
char
*
username
=
get_field
(
&
temp_root
,
table
->
field
[
1
]);
char
*
rolename
=
get_field
(
&
temp_root
,
table
->
field
[
2
]);
char
*
rolename
=
get_field
(
&
temp_root
,
table
->
field
[
2
]);
init_role_grant_pair
(
&
mem
,
mapping
,
username
,
hostname
,
rolename
);
if
(
mapping
->
init
(
&
mem
,
username
,
hostname
,
rolename
))
continue
;
if
(
add_role_user_mapping
(
mapping
)
==
-
1
)
{
if
(
add_role_user_mapping
(
mapping
)
==
-
1
)
{
sql_print_error
(
"Invalid roles_mapping table entry user:'%s@%s', rolename:'%s'"
,
sql_print_error
(
"Invalid roles_mapping table entry user:'%s@%s', rolename:'%s'"
,
mapping
->
u_uname
?
mapping
->
u_uname
:
""
,
mapping
->
u_uname
?
mapping
->
u_uname
:
""
,
...
@@ -3811,9 +3823,9 @@ replace_roles_mapping_table(TABLE *table, ROLE_GRANT_PAIR *pair,
...
@@ -3811,9 +3823,9 @@ replace_roles_mapping_table(TABLE *table, ROLE_GRANT_PAIR *pair,
pair
->
hashkey
.
length
))
pair
->
hashkey
.
length
))
{
{
/* allocate a new entry that will go in the hash */
/* allocate a new entry that will go in the hash */
hash_entry
=
(
ROLE_GRANT_PAIR
*
)
alloc_root
(
&
mem
,
sizeof
(
ROLE_GRANT_PAIR
))
;
hash_entry
=
new
(
&
mem
)
ROLE_GRANT_PAIR
;
i
nit_role_grant_pair
(
&
mem
,
hash_entry
,
i
f
(
hash_entry
->
init
(
&
mem
,
pair
->
u_uname
,
pair
->
u_hname
,
pair
->
r_uname
))
pair
->
u_uname
,
pair
->
u_hname
,
pair
->
r_uname
);
DBUG_RETURN
(
1
);
my_hash_insert
(
&
acl_roles_mappings
,
(
uchar
*
)
hash_entry
);
my_hash_insert
(
&
acl_roles_mappings
,
(
uchar
*
)
hash_entry
);
}
}
else
else
...
@@ -5408,12 +5420,11 @@ bool mysql_grant_role(THD *thd, List <LEX_USER> &list, bool revoke)
...
@@ -5408,12 +5420,11 @@ bool mysql_grant_role(THD *thd, List <LEX_USER> &list, bool revoke)
username
=
user
->
user
.
str
;
username
=
user
->
user
.
str
;
}
}
ROLE_GRANT_PAIR
*
mapping
,
*
hash_entry
;
ROLE_GRANT_PAIR
*
mapping
=
new
(
&
temp_root
)
ROLE_GRANT_PAIR
,
*
hash_entry
;
mapping
=
(
ROLE_GRANT_PAIR
*
)
alloc_root
(
&
temp_root
,
sizeof
(
ROLE_GRANT_PAIR
));
if
(
mapping
->
init
(
&
temp_root
,
username
,
hostname
,
rolename
))
continue
;
init_role_grant_pair
(
&
temp_root
,
mapping
,
username
,
hostname
,
rolename
);
if
(
!
revoke
)
if
(
!
revoke
)
{
{
int
res
=
add_role_user_mapping
(
mapping
);
int
res
=
add_role_user_mapping
(
mapping
);
...
@@ -8432,7 +8443,7 @@ static int handle_grant_struct(enum enum_acl_lists struct_no, bool drop,
...
@@ -8432,7 +8443,7 @@ static int handle_grant_struct(enum enum_acl_lists struct_no, bool drop,
break
;
break
;
default:
default:
DBUG_ASSERT
(
0
);
DBUG_ASSERT
(
0
);
return
-
1
;
DBUG_RETURN
(
-
1
)
;
}
}
#ifdef EXTRA_DEBUG
#ifdef EXTRA_DEBUG
...
@@ -8616,16 +8627,18 @@ static int handle_grant_struct(enum enum_acl_lists struct_no, bool drop,
...
@@ -8616,16 +8627,18 @@ static int handle_grant_struct(enum enum_acl_lists struct_no, bool drop,
*/
*/
char
*
old_key
=
role_grant_pair
->
hashkey
.
str
;
char
*
old_key
=
role_grant_pair
->
hashkey
.
str
;
size_t
old_key_length
=
role_grant_pair
->
hashkey
.
length
;
size_t
old_key_length
=
role_grant_pair
->
hashkey
.
length
;
bool
oom
;
if
(
role_not_matched
)
if
(
role_not_matched
)
init_role_grant_pair
(
&
mem
,
role_grant_pai
r
,
oom
=
role_grant_pair
->
init
(
&
mem
,
user_to
->
user
.
st
r
,
user_to
->
user
.
str
,
user_to
->
host
.
str
,
user_to
->
host
.
str
,
role_grant_pair
->
r_uname
);
role_grant_pair
->
r_uname
);
else
else
init_role_grant_pair
(
&
mem
,
role_grant_pair
,
oom
=
role_grant_pair
->
init
(
&
mem
,
role_grant_pair
->
u_uname
,
role_grant_pair
->
u_uname
,
role_grant_pair
->
u_hname
,
role_grant_pair
->
u_hname
,
user_to
->
user
.
str
);
user_to
->
user
.
str
);
if
(
oom
)
DBUG_RETURN
(
-
1
);
my_hash_update
(
roles_mappings_hash
,
(
uchar
*
)
role_grant_pair
,
my_hash_update
(
roles_mappings_hash
,
(
uchar
*
)
role_grant_pair
,
(
uchar
*
)
old_key
,
old_key_length
);
(
uchar
*
)
old_key
,
old_key_length
);
...
...
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