24static const char restrict_chars[] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
27 const char *
name,
const char *
subname,
int remoteVersion,
62 for (s = result; *s !=
'\0'; s++)
64 if (*s ==
'\n' || *s ==
'\r')
105 const char *
type,
const char *acls,
const char *baseacls,
106 const char *owner,
const char *prefix,
int remoteVersion,
110 char **aclitems = NULL;
111 char **baseitems = NULL;
112 char **grantitems = NULL;
113 char **revokeitems = NULL;
117 int nrevokeitems = 0;
131 if (acls == NULL || *acls ==
'\0')
135 if (owner && *owner ==
'\0')
163 grantitems = (
char **)
pg_malloc(naclitems *
sizeof(
char *));
164 for (
i = 0;
i < naclitems;
i++)
168 for (
int j = 0;
j < nbaseitems;
j++)
170 if (strcmp(aclitems[
i], baseitems[
j]) == 0)
177 grantitems[ngrantitems++] = aclitems[
i];
179 revokeitems = (
char **)
pg_malloc(nbaseitems *
sizeof(
char *));
180 for (
i = 0;
i < nbaseitems;
i++)
184 for (
int j = 0;
j < naclitems;
j++)
186 if (strcmp(baseitems[
i], aclitems[
j]) == 0)
193 revokeitems[nrevokeitems++] = baseitems[
i];
211 for (
i = 0;
i < nrevokeitems;
i++)
215 grantee, grantor, privs, NULL))
225 if (nspname && *nspname)
230 if (grantee->
len == 0)
261 for (
i = 0;
i < ngrantitems;
i++)
264 grantee, grantor, privs, privswgo))
271 if (privs->
len > 0 || privswgo->
len > 0)
276 if (grantor->
len == 0 && owner)
281 strcmp(grantee->
data, owner) == 0 &&
282 strcmp(grantor->
data, owner) == 0)
288 && (!owner || strcmp(owner, grantor->
data) != 0))
296 if (nspname && *nspname)
301 if (grantee->
len == 0)
306 if (privswgo->
len > 0)
310 if (nspname && *nspname)
315 if (grantee->
len == 0)
323 && (!owner || strcmp(owner, grantor->
data) != 0))
393 prefix->
data, remoteVersion, sql))
424 const char *
name,
const char *
subname,
int remoteVersion,
429 bool all_with_go =
true;
430 bool all_without_go =
true;
446 slpos = strchr(eqpos + 1,
'/');
464#define CONVERT_PRIV(code, keywd) \
466 if ((pos = strchr(eqpos + 1, code))) \
468 if (*(pos + 1) == '*' && privswgo != NULL) \
470 AddAcl(privswgo, keywd, subname); \
471 all_without_go = false; \
475 AddAcl(privs, keywd, subname); \
476 all_with_go = false; \
480 all_with_go = all_without_go = false; \
486 if (strcmp(
type,
"TABLE") == 0 || strcmp(
type,
"SEQUENCE") == 0 ||
487 strcmp(
type,
"TABLES") == 0 || strcmp(
type,
"SEQUENCES") == 0)
491 if (strcmp(
type,
"SEQUENCE") == 0 ||
492 strcmp(
type,
"SEQUENCES") == 0)
513 else if (strcmp(
type,
"FUNCTION") == 0 ||
514 strcmp(
type,
"FUNCTIONS") == 0)
516 else if (strcmp(
type,
"PROCEDURE") == 0 ||
517 strcmp(
type,
"PROCEDURES") == 0)
519 else if (strcmp(
type,
"LANGUAGE") == 0)
521 else if (strcmp(
type,
"SCHEMA") == 0 ||
522 strcmp(
type,
"SCHEMAS") == 0)
527 else if (strcmp(
type,
"DATABASE") == 0)
533 else if (strcmp(
type,
"TABLESPACE") == 0)
535 else if (strcmp(
type,
"TYPE") == 0 ||
536 strcmp(
type,
"TYPES") == 0)
538 else if (strcmp(
type,
"FOREIGN DATA WRAPPER") == 0)
540 else if (strcmp(
type,
"FOREIGN SERVER") == 0)
542 else if (strcmp(
type,
"FOREIGN TABLE") == 0)
544 else if (strcmp(
type,
"PARAMETER") == 0)
549 else if (strcmp(
type,
"LARGE OBJECT") == 0 ||
550 strcmp(
type,
"LARGE OBJECTS") == 0)
567 else if (all_without_go)
590 for (src =
input; *src; src++)
593 if (!isalnum((
unsigned char) *src) && *src !=
'_')
601 for (src =
input; *src; src++)
635 while (!(*
input ==
'"' && *(
input + 1) !=
'"'))
682 "SELECT provider, label FROM pg_catalog.pg_shseclabel "
683 "WHERE classoid = 'pg_catalog.%s'::pg_catalog.regclass "
684 "AND objoid = '%u'", catalog_name, objectId);
697 const char *objtype,
const char *objname)
708 "SECURITY LABEL FOR %s ON %s",
767 char *nextp = rawstring;
776 *namelist = nextptr = (
char **)
777 pg_malloc((strlen(rawstring) / 2 + 2) *
sizeof(
char *));
780 while (isspace((
unsigned char) *nextp))
798 endp = strchr(nextp + 1,
'"');
804 memmove(endp, endp + 1, strlen(endp));
815 !isspace((
unsigned char) *nextp))
818 if (curname == nextp)
822 while (isspace((
unsigned char) *nextp))
828 while (isspace((
unsigned char) *nextp))
832 else if (*nextp ==
'\0')
843 *nextptr++ = curname;
866 const char *type2,
const char *name2,
874 pos = strchr(mine,
'=');
884 if (type2 != NULL && name2 != NULL)
913 if (*namelist == NULL)
915 for (nameptr = namelist; *nameptr; nameptr++)
917 if (nameptr != namelist)
947 pg_fatal(
"could not open directory \"%s\": %m", dirname);
952 pg_fatal(
"could not create directory \"%s\": %m", dirname);
957 pg_fatal(
"could not change permissions of directory \"%s\": %m",
962 pg_fatal(
"directory \"%s\" is not empty", dirname);
980 for (
int i = 0;
i <
sizeof(
buf) - 1;
i++)
986 ret[
sizeof(
buf) - 1] =
'\0';
Datum idx(PG_FUNCTION_ARGS)
Acl * acldefault(ObjectType objtype, Oid ownerId)
char * generate_restrict_key(void)
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)
bool valid_restrict_key(const char *restrict_key)
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)
char * sanitize_line(const char *str, bool want_hyphen)
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)
static const char restrict_chars[]
bool SplitGUCList(char *rawstring, char separator, char ***namelist)
#define CONVERT_PRIV(code, keywd)
void * pg_malloc(size_t size)
char * pg_strdup(const char *in)
static char * restrict_key
bool pg_strong_random(void *buf, size_t len)
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)