26 const char *
name,
const char *
subname,
int remoteVersion,
67 const char *
type,
const char *acls,
const char *baseacls,
68 const char *owner,
const char *prefix,
int remoteVersion,
72 char **aclitems = NULL;
73 char **baseitems = NULL;
74 char **grantitems = NULL;
75 char **revokeitems = NULL;
93 if (acls == NULL || *acls ==
'\0')
97 if (owner && *owner ==
'\0')
125 grantitems = (
char **)
pg_malloc(naclitems *
sizeof(
char *));
126 for (
i = 0;
i < naclitems;
i++)
130 for (
int j = 0;
j < nbaseitems;
j++)
132 if (strcmp(aclitems[
i], baseitems[
j]) == 0)
139 grantitems[ngrantitems++] = aclitems[
i];
141 revokeitems = (
char **)
pg_malloc(nbaseitems *
sizeof(
char *));
142 for (
i = 0;
i < nbaseitems;
i++)
146 for (
int j = 0;
j < naclitems;
j++)
148 if (strcmp(baseitems[
i], aclitems[
j]) == 0)
155 revokeitems[nrevokeitems++] = baseitems[
i];
173 for (
i = 0;
i < nrevokeitems;
i++)
177 grantee, grantor, privs, NULL))
187 if (nspname && *nspname)
192 if (grantee->
len == 0)
223 for (
i = 0;
i < ngrantitems;
i++)
226 grantee, grantor, privs, privswgo))
233 if (privs->
len > 0 || privswgo->
len > 0)
238 if (grantor->
len == 0 && owner)
243 strcmp(grantee->
data, owner) == 0 &&
244 strcmp(grantor->
data, owner) == 0)
250 && (!owner || strcmp(owner, grantor->
data) != 0))
258 if (nspname && *nspname)
263 if (grantee->
len == 0)
268 if (privswgo->
len > 0)
272 if (nspname && *nspname)
277 if (grantee->
len == 0)
285 && (!owner || strcmp(owner, grantor->
data) != 0))
355 prefix->
data, remoteVersion, sql))
386 const char *
name,
const char *
subname,
int remoteVersion,
391 bool all_with_go =
true;
392 bool all_without_go =
true;
408 slpos = strchr(eqpos + 1,
'/');
426#define CONVERT_PRIV(code, keywd) \
428 if ((pos = strchr(eqpos + 1, code))) \
430 if (*(pos + 1) == '*' && privswgo != NULL) \
432 AddAcl(privswgo, keywd, subname); \
433 all_without_go = false; \
437 AddAcl(privs, keywd, subname); \
438 all_with_go = false; \
442 all_with_go = all_without_go = false; \
448 if (strcmp(
type,
"TABLE") == 0 || strcmp(
type,
"SEQUENCE") == 0 ||
449 strcmp(
type,
"TABLES") == 0 || strcmp(
type,
"SEQUENCES") == 0)
453 if (strcmp(
type,
"SEQUENCE") == 0 ||
454 strcmp(
type,
"SEQUENCES") == 0)
475 else if (strcmp(
type,
"FUNCTION") == 0 ||
476 strcmp(
type,
"FUNCTIONS") == 0)
478 else if (strcmp(
type,
"PROCEDURE") == 0 ||
479 strcmp(
type,
"PROCEDURES") == 0)
481 else if (strcmp(
type,
"LANGUAGE") == 0)
483 else if (strcmp(
type,
"SCHEMA") == 0 ||
484 strcmp(
type,
"SCHEMAS") == 0)
489 else if (strcmp(
type,
"DATABASE") == 0)
495 else if (strcmp(
type,
"TABLESPACE") == 0)
497 else if (strcmp(
type,
"TYPE") == 0 ||
498 strcmp(
type,
"TYPES") == 0)
500 else if (strcmp(
type,
"FOREIGN DATA WRAPPER") == 0)
502 else if (strcmp(
type,
"FOREIGN SERVER") == 0)
504 else if (strcmp(
type,
"FOREIGN TABLE") == 0)
506 else if (strcmp(
type,
"PARAMETER") == 0)
511 else if (strcmp(
type,
"LARGE OBJECT") == 0 ||
512 strcmp(
type,
"LARGE OBJECTS") == 0)
529 else if (all_without_go)
552 for (src =
input; *src; src++)
555 if (!isalnum((
unsigned char) *src) && *src !=
'_')
563 for (src =
input; *src; src++)
597 while (!(*
input ==
'"' && *(
input + 1) !=
'"'))
644 "SELECT provider, label FROM pg_catalog.pg_shseclabel "
645 "WHERE classoid = 'pg_catalog.%s'::pg_catalog.regclass "
646 "AND objoid = '%u'", catalog_name, objectId);
659 const char *objtype,
const char *objname)
670 "SECURITY LABEL FOR %s ON %s",
729 char *nextp = rawstring;
738 *namelist = nextptr = (
char **)
739 pg_malloc((strlen(rawstring) / 2 + 2) *
sizeof(
char *));
742 while (isspace((
unsigned char) *nextp))
760 endp = strchr(nextp + 1,
'"');
766 memmove(endp, endp + 1, strlen(endp));
777 !isspace((
unsigned char) *nextp))
780 if (curname == nextp)
784 while (isspace((
unsigned char) *nextp))
790 while (isspace((
unsigned char) *nextp))
794 else if (*nextp ==
'\0')
805 *nextptr++ = curname;
828 const char *type2,
const char *name2,
836 pos = strchr(mine,
'=');
846 if (type2 != NULL && name2 != NULL)
873 for (nameptr = namelist; *nameptr; nameptr++)
875 if (nameptr != namelist)
905 pg_fatal(
"could not open directory \"%s\": %m", dirname);
910 pg_fatal(
"could not create directory \"%s\": %m", dirname);
915 pg_fatal(
"could not change permissions of directory \"%s\": %m",
920 pg_fatal(
"directory \"%s\" is not empty", dirname);
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)
void create_or_open_dir(const char *dirname)
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)
int pg_check_dir(const char *dir)
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)