24 const char *
name,
const char *
subname,
int remoteVersion,
65 const char *
type,
const char *acls,
const char *baseacls,
66 const char *owner,
const char *prefix,
int remoteVersion,
70 char **aclitems = NULL;
71 char **baseitems = NULL;
72 char **grantitems = NULL;
73 char **revokeitems = NULL;
91 if (acls == NULL || *acls ==
'\0')
95 if (owner && *owner ==
'\0')
123 grantitems = (
char **)
pg_malloc(naclitems *
sizeof(
char *));
124 for (
i = 0;
i < naclitems;
i++)
128 for (
int j = 0;
j < nbaseitems;
j++)
130 if (strcmp(aclitems[
i], baseitems[
j]) == 0)
137 grantitems[ngrantitems++] = aclitems[
i];
139 revokeitems = (
char **)
pg_malloc(nbaseitems *
sizeof(
char *));
140 for (
i = 0;
i < nbaseitems;
i++)
144 for (
int j = 0;
j < naclitems;
j++)
146 if (strcmp(baseitems[
i], aclitems[
j]) == 0)
153 revokeitems[nrevokeitems++] = baseitems[
i];
171 for (
i = 0;
i < nrevokeitems;
i++)
175 grantee, grantor, privs, NULL))
185 if (nspname && *nspname)
190 if (grantee->
len == 0)
221 for (
i = 0;
i < ngrantitems;
i++)
224 grantee, grantor, privs, privswgo))
231 if (privs->
len > 0 || privswgo->
len > 0)
236 if (grantor->
len == 0 && owner)
241 strcmp(grantee->
data, owner) == 0 &&
242 strcmp(grantor->
data, owner) == 0)
248 && (!owner || strcmp(owner, grantor->
data) != 0))
256 if (nspname && *nspname)
261 if (grantee->
len == 0)
266 if (privswgo->
len > 0)
270 if (nspname && *nspname)
275 if (grantee->
len == 0)
283 && (!owner || strcmp(owner, grantor->
data) != 0))
353 prefix->
data, remoteVersion, sql))
384 const char *
name,
const char *
subname,
int remoteVersion,
389 bool all_with_go =
true;
390 bool all_without_go =
true;
406 slpos = strchr(eqpos + 1,
'/');
424#define CONVERT_PRIV(code, keywd) \
426 if ((pos = strchr(eqpos + 1, code))) \
428 if (*(pos + 1) == '*' && privswgo != NULL) \
430 AddAcl(privswgo, keywd, subname); \
431 all_without_go = false; \
435 AddAcl(privs, keywd, subname); \
436 all_with_go = false; \
440 all_with_go = all_without_go = false; \
446 if (strcmp(
type,
"TABLE") == 0 || strcmp(
type,
"SEQUENCE") == 0 ||
447 strcmp(
type,
"TABLES") == 0 || strcmp(
type,
"SEQUENCES") == 0)
451 if (strcmp(
type,
"SEQUENCE") == 0 ||
452 strcmp(
type,
"SEQUENCES") == 0)
473 else if (strcmp(
type,
"FUNCTION") == 0 ||
474 strcmp(
type,
"FUNCTIONS") == 0)
476 else if (strcmp(
type,
"PROCEDURE") == 0 ||
477 strcmp(
type,
"PROCEDURES") == 0)
479 else if (strcmp(
type,
"LANGUAGE") == 0)
481 else if (strcmp(
type,
"SCHEMA") == 0 ||
482 strcmp(
type,
"SCHEMAS") == 0)
487 else if (strcmp(
type,
"DATABASE") == 0)
493 else if (strcmp(
type,
"TABLESPACE") == 0)
495 else if (strcmp(
type,
"TYPE") == 0 ||
496 strcmp(
type,
"TYPES") == 0)
498 else if (strcmp(
type,
"FOREIGN DATA WRAPPER") == 0)
500 else if (strcmp(
type,
"FOREIGN SERVER") == 0)
502 else if (strcmp(
type,
"FOREIGN TABLE") == 0)
504 else if (strcmp(
type,
"PARAMETER") == 0)
509 else if (strcmp(
type,
"LARGE OBJECT") == 0)
526 else if (all_without_go)
549 for (src =
input; *src; src++)
552 if (!isalnum((
unsigned char) *src) && *src !=
'_')
560 for (src =
input; *src; src++)
594 while (!(*
input ==
'"' && *(
input + 1) !=
'"'))
641 "SELECT provider, label FROM pg_catalog.pg_shseclabel "
642 "WHERE classoid = 'pg_catalog.%s'::pg_catalog.regclass "
643 "AND objoid = '%u'", catalog_name, objectId);
656 const char *objtype,
const char *objname)
667 "SECURITY LABEL FOR %s ON %s",
726 char *nextp = rawstring;
735 *namelist = nextptr = (
char **)
736 pg_malloc((strlen(rawstring) / 2 + 2) *
sizeof(
char *));
739 while (isspace((
unsigned char) *nextp))
757 endp = strchr(nextp + 1,
'"');
763 memmove(endp, endp + 1, strlen(endp));
774 !isspace((
unsigned char) *nextp))
777 if (curname == nextp)
781 while (isspace((
unsigned char) *nextp))
787 while (isspace((
unsigned char) *nextp))
791 else if (*nextp ==
'\0')
802 *nextptr++ = curname;
825 const char *type2,
const char *name2,
833 pos = strchr(mine,
'=');
843 if (type2 != NULL && name2 != NULL)
870 for (nameptr = namelist; *nameptr; nameptr++)
872 if (nameptr != namelist)
Acl * acldefault(ObjectType objtype, Oid ownerId)
bool buildACLCommands(const char *name, const char *subname, const char *nspname, const char *type, const char *acls, const char *baseacls, const char *owner, const char *prefix, int remoteVersion, PQExpBuffer sql)
static char * dequoteAclUserName(PQExpBuffer output, char *input)
void buildShSecLabelQuery(const char *catalog_name, Oid objectId, PQExpBuffer sql)
void makeAlterConfigCommand(PGconn *conn, const char *configitem, const char *type, const char *name, const char *type2, const char *name2, PQExpBuffer buf)
bool buildDefaultACLCommands(const char *type, const char *nspname, const char *acls, const char *acldefault, const char *owner, int remoteVersion, PQExpBuffer sql)
bool variable_is_guc_list_quote(const char *name)
void quoteAclUserName(PQExpBuffer output, const char *input)
static bool parseAclItem(const char *item, const char *type, const char *name, const char *subname, int remoteVersion, PQExpBuffer grantee, PQExpBuffer grantor, PQExpBuffer privs, PQExpBuffer privswgo)
static void AddAcl(PQExpBuffer aclbuf, const char *keyword, const char *subname)
void emitShSecLabels(PGconn *conn, PGresult *res, PQExpBuffer buffer, const char *objtype, const char *objname)
bool SplitGUCList(char *rawstring, char separator, char ***namelist)
#define CONVERT_PRIV(code, keywd)
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
int PQntuples(const PGresult *res)
void * pg_malloc(size_t size)
char * pg_strdup(const char *in)
int pg_strcasecmp(const char *s1, const char *s2)
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
PQExpBuffer createPQExpBuffer(void)
void resetPQExpBuffer(PQExpBuffer str)
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void destroyPQExpBuffer(PQExpBuffer str)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
const char * fmtId(const char *rawid)
void appendStringLiteralConn(PQExpBuffer buf, const char *str, PGconn *conn)
bool parsePGArray(const char *atext, char ***itemarray, int *nitems)