mirror of
https://github.com/MariaDB/server.git
synced 2025-01-18 04:53:01 +01:00
Added a init_role_mapping function to be used for later
This commit is contained in:
parent
573c73225e
commit
f8d944a6a0
1 changed files with 38 additions and 0 deletions
|
@ -549,6 +549,44 @@ static uchar* acl_role_map_get_key(ROLE_GRANT_PAIR *entry, size_t *length,
|
|||
return (uchar*) entry->hashkey.str;
|
||||
}
|
||||
|
||||
static void init_role_grant_pair(MEM_ROOT *mem, ROLE_GRANT_PAIR *entry,
|
||||
char *username, char *hostname, char *rolename)
|
||||
{
|
||||
size_t len[3] = {username ? strlen(username) : 0,
|
||||
hostname ? strlen(hostname) : 0,
|
||||
rolename ? strlen(rolename) : 0};
|
||||
/*
|
||||
Create a buffer that holds all 3 NULL terminated strings in succession
|
||||
To save memory space, the same buffer is used as the hashkey
|
||||
*/
|
||||
size_t bufflen = len[0] + len[1] + len[2] + 3; //add the '\0' aswell
|
||||
char *buff= (char *)alloc_root(mem, bufflen);
|
||||
/*
|
||||
Offsets in the buffer for all 3 strings
|
||||
*/
|
||||
char *username_pos= buff;
|
||||
char *hostname_pos= buff + len[0] + 1;
|
||||
char *rolename_pos= buff + len[0] + len[1] + 2;
|
||||
|
||||
if (username)
|
||||
memcpy(username_pos, username, len[0]);
|
||||
username_pos[len[0]]= '\0'; //#1 string terminator
|
||||
entry->u_uname= username_pos;
|
||||
|
||||
if (hostname)
|
||||
memcpy(hostname_pos, hostname, len[1]);
|
||||
hostname_pos[len[1]]= '\0'; //#2 string terminator
|
||||
entry->u_hname= hostname_pos;
|
||||
|
||||
if (rolename)
|
||||
memcpy(rolename_pos, rolename, len[2]);
|
||||
rolename_pos[len[2]]= '\0'; //#3 string terminator
|
||||
entry->r_uname= rolename_pos;
|
||||
|
||||
entry->hashkey.str = buff;
|
||||
entry->hashkey.length = bufflen;
|
||||
}
|
||||
|
||||
#define IP_ADDR_STRLEN (3 + 1 + 3 + 1 + 3 + 1 + 3)
|
||||
#define ACL_KEY_LENGTH (IP_ADDR_STRLEN + 1 + NAME_LEN + \
|
||||
1 + USERNAME_LENGTH + 1)
|
||||
|
|
Loading…
Reference in a new issue