aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backend/commands/user.c36
1 files changed, 24 insertions, 12 deletions
diff --git a/src/backend/commands/user.c b/src/backend/commands/user.c
index 71c5caa41b9..1cdd2bf542c 100644
--- a/src/backend/commands/user.c
+++ b/src/backend/commands/user.c
@@ -455,19 +455,31 @@ CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
/*
* Add the new role to the specified existing roles.
*/
- foreach(item, addroleto)
+ if (addroleto)
{
- RoleSpec *oldrole = lfirst(item);
- HeapTuple oldroletup = get_rolespec_tuple(oldrole);
- Oid oldroleid = HeapTupleGetOid(oldroletup);
- char *oldrolename = NameStr(((Form_pg_authid) GETSTRUCT(oldroletup))->rolname);
-
- AddRoleMems(oldrolename, oldroleid,
- list_make1(makeString(stmt->role)),
- list_make1_oid(roleid),
- GetUserId(), false);
+ RoleSpec *thisrole = makeNode(RoleSpec);
+ List *thisrole_list = list_make1(thisrole);
+ List *thisrole_oidlist = list_make1_oid(roleid);
+
+ thisrole->roletype = ROLESPEC_CSTRING;
+ thisrole->rolename = stmt->role;
+ thisrole->location = -1;
- ReleaseSysCache(oldroletup);
+ foreach(item, addroleto)
+ {
+ RoleSpec *oldrole = lfirst(item);
+ HeapTuple oldroletup = get_rolespec_tuple(oldrole);
+ Form_pg_authid oldroleform = (Form_pg_authid) GETSTRUCT(oldroletup);
+ Oid oldroleid = HeapTupleGetOid(oldroletup);
+ char *oldrolename = NameStr(oldroleform->rolname);
+
+ AddRoleMems(oldrolename, oldroleid,
+ thisrole_list,
+ thisrole_oidlist,
+ GetUserId(), false);
+
+ ReleaseSysCache(oldroletup);
+ }
}
/*
@@ -1478,7 +1490,7 @@ AddRoleMems(const char *rolename, Oid roleid,
forboth(specitem, memberSpecs, iditem, memberIds)
{
- RoleSpec *memberRole = lfirst(specitem);
+ RoleSpec *memberRole = lfirst_node(RoleSpec, specitem);
Oid memberid = lfirst_oid(iditem);
HeapTuple authmem_tuple;
HeapTuple tuple;