Commit f8d944a6 authored by Vicențiu Ciorbaru's avatar Vicențiu Ciorbaru Committed by Sergei Golubchik

Added a init_role_mapping function to be used for later

parent 573c7322
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment