⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dumputils.c

📁 PostgreSQL7.4.6 for Linux
💻 C
📖 第 1 页 / 共 2 页
字号:
									  privswgo->data, type, name);					if (grantee->len == 0)						appendPQExpBuffer(secondsql, "PUBLIC");					else if (strncmp(grantee->data, "group ",									 strlen("group ")) == 0)						appendPQExpBuffer(secondsql, "GROUP %s",								fmtId(grantee->data + strlen("group ")));					else						appendPQExpBuffer(secondsql, "%s", fmtId(grantee->data));					appendPQExpBuffer(secondsql, " WITH GRANT OPTION;\n");				}				if (grantor->len > 0					&& (!owner || strcmp(owner, grantor->data) != 0))					appendPQExpBuffer(secondsql, "RESET SESSION AUTHORIZATION;\n");			}		}	}	/*	 * If we didn't find any owner privs, the owner must have revoked 'em	 * all	 */	if (!found_owner_privs && owner)	{		appendPQExpBuffer(firstsql, "REVOKE ALL ON %s %s FROM %s;\n",						  type, name, fmtId(owner));	}	destroyPQExpBuffer(grantee);	destroyPQExpBuffer(grantor);	destroyPQExpBuffer(privs);	destroyPQExpBuffer(privswgo);	appendPQExpBuffer(sql, "%s%s", firstsql->data, secondsql->data);	destroyPQExpBuffer(firstsql);	destroyPQExpBuffer(secondsql);	free(aclitems);	return true;}/* * Deconstruct an ACL array (or actually any 1-dimensional Postgres array) * into individual items. * * On success, returns true and sets *itemarray and *nitems to describe * an array of individual strings.	On parse failure, returns false; * *itemarray may exist or be NULL. * * NOTE: free'ing itemarray is sufficient to deallocate the working storage. */static boolparseAclArray(const char *acls, char ***itemarray, int *nitems){	int			inputlen;	char	  **items;	char	   *strings;	int			curitem;	/*	 * We expect input in the form of "{item,item,item}" where any item is	 * either raw data, or surrounded by double quotes (in which case	 * embedded characters including backslashes and quotes are	 * backslashed).	 *	 * We build the result as an array of pointers followed by the actual	 * string data, all in one malloc block for convenience of	 * deallocation. The worst-case storage need is not more than one	 * pointer and one character for each input character (consider	 * "{,,,,,,,,,,}").	 */	*itemarray = NULL;	*nitems = 0;	inputlen = strlen(acls);	if (inputlen < 2 || acls[0] != '{' || acls[inputlen - 1] != '}')		return false;			/* bad input */	items = (char **) malloc(inputlen * (sizeof(char *) + sizeof(char)));	if (items == NULL)		return false;			/* out of memory */	*itemarray = items;	strings = (char *) (items + inputlen);	acls++;						/* advance over initial '{' */	curitem = 0;	while (*acls != '}')	{		if (*acls == '\0')			return false;		/* premature end of string */		items[curitem] = strings;		while (*acls != '}' && *acls != ',')		{			if (*acls == '\0')				return false;	/* premature end of string */			if (*acls != '"')				*strings++ = *acls++;	/* copy unquoted data */			else			{				/* process quoted substring */				acls++;				while (*acls != '"')				{					if (*acls == '\0')						return false;	/* premature end of string */					if (*acls == '\\')					{						acls++;						if (*acls == '\0')							return false;		/* premature end of string */					}					*strings++ = *acls++;		/* copy quoted data */				}				acls++;			}		}		*strings++ = '\0';		if (*acls == ',')			acls++;		curitem++;	}	if (acls[1] != '\0')		return false;			/* bogus syntax (embedded '}') */	*nitems = curitem;	return true;}/* * This will parse an aclitem string, having the general form *		username=privilegecodes/grantor * or *		group groupname=privilegecodes/grantor * (the /grantor part will not be present if pre-7.4 database). * * The returned grantee string will be the dequoted username or groupname * (preceded with "group " in the latter case).  The returned grantor is * the dequoted grantor name or empty.	Privilege characters are decoded * and split between privileges with grant option (privswgo) and without * (privs). * * Note: for cross-version compatibility, it's important to use ALL when * appropriate. */static boolparseAclItem(const char *item, const char *type, const char *name,			 int remoteVersion,			 PQExpBuffer grantee, PQExpBuffer grantor,			 PQExpBuffer privs, PQExpBuffer privswgo){	char	   *buf;	bool		all_with_go = true;	bool		all_without_go = true;	char	   *eqpos;	char	   *slpos;	char	   *pos;	buf = strdup(item);	/* user or group name is string up to = */	eqpos = copyAclUserName(grantee, buf);	if (*eqpos != '=')		return false;	/* grantor may be listed after / */	slpos = strchr(eqpos + 1, '/');	if (slpos)	{		*slpos++ = '\0';		slpos = copyAclUserName(grantor, slpos);		if (*slpos != '\0')			return false;	}	else		resetPQExpBuffer(grantor);	/* privilege codes */#define CONVERT_PRIV(code, keywd) \	if ((pos = strchr(eqpos + 1, code))) \	{ \		if (*(pos + 1) == '*') \		{ \			AddAcl(privswgo, keywd); \			all_without_go = false; \		} \		else \		{ \			AddAcl(privs, keywd); \			all_with_go = false; \		} \	} \	else \		all_with_go = all_without_go = false	resetPQExpBuffer(privs);	resetPQExpBuffer(privswgo);	if (strcmp(type, "TABLE") == 0)	{		CONVERT_PRIV('a', "INSERT");		CONVERT_PRIV('r', "SELECT");		CONVERT_PRIV('R', "RULE");		if (remoteVersion >= 70200)		{			CONVERT_PRIV('w', "UPDATE");			CONVERT_PRIV('d', "DELETE");			CONVERT_PRIV('x', "REFERENCES");			CONVERT_PRIV('t', "TRIGGER");		}		else		{			/* 7.0 and 7.1 have a simpler worldview */			CONVERT_PRIV('w', "UPDATE,DELETE");		}	}	else if (strcmp(type, "FUNCTION") == 0)		CONVERT_PRIV('X', "EXECUTE");	else if (strcmp(type, "LANGUAGE") == 0)		CONVERT_PRIV('U', "USAGE");	else if (strcmp(type, "SCHEMA") == 0)	{		CONVERT_PRIV('C', "CREATE");		CONVERT_PRIV('U', "USAGE");	}	else if (strcmp(type, "DATABASE") == 0)	{		CONVERT_PRIV('C', "CREATE");		CONVERT_PRIV('T', "TEMPORARY");	}	else		abort();#undef CONVERT_PRIV	if (all_with_go)	{		resetPQExpBuffer(privs);		printfPQExpBuffer(privswgo, "ALL");	}	else if (all_without_go)	{		resetPQExpBuffer(privswgo);		printfPQExpBuffer(privs, "ALL");	}	free(buf);	return true;}/* * Transfer a user or group name starting at *input into the output buffer, * dequoting if needed.  Returns a pointer to just past the input name. * The name is taken to end at an unquoted '=' or end of string. */static char *copyAclUserName(PQExpBuffer output, char *input){	resetPQExpBuffer(output);	while (*input && *input != '=')	{		/* If user name isn't quoted, then just add it to the output buffer */		if (*input != '"')			appendPQExpBufferChar(output, *input++);		else		{			/* Otherwise, it's a quoted username */ 			input++;			/* Loop until we come across an unescaped quote */			while (!(*input == '"' && *(input + 1) != '"'))			{				if (*input == '\0')					return input;		/* really a syntax error... */				/*				 * Quoting convention is to escape " as "".  Keep this				 * code in sync with putid() in backend's acl.c.				 */				if (*input == '"' && *(input + 1) == '"')					input++;				appendPQExpBufferChar(output, *input++);			}			input++;		}	}	return input;}/* * Append a privilege keyword to a keyword list, inserting comma if needed. */static voidAddAcl(PQExpBuffer aclbuf, const char *keyword){	if (aclbuf->len > 0)		appendPQExpBufferChar(aclbuf, ',');	appendPQExpBuffer(aclbuf, "%s", keyword);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -