77 *
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.33 1999/02/13 23:18:58 momjian Exp $
10+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.34 1999/03/21 06:31:59 momjian Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
@@ -34,11 +34,12 @@ static char *aclparse(char *s, AclItem *aip, unsigned *modechg);
3434/*
3535 * getid
3636 *Consumes the first alphanumeric string (identifier) found in string
37- *'s', ignoring any leading white space.
37+ *'s', ignoring any leading white space. If it finds a double quote
38+ *it returns the word inside the quotes.
3839 *
3940 * RETURNS:
4041 *the string position in 's' that points to the next non-space character
41- *in 's'. Also:
42+ *in 's', after any quotes . Also:
4243 *- loads the identifier into 'name'. (If no identifier is found, 'name'
4344 * contains an empty string).
4445 */
@@ -47,13 +48,27 @@ getid(char *s, char *n)
4748{
4849unsigned len ;
4950char * id ;
51+ int in_quotes = 0 ;
5052
5153Assert (s && n );
5254
5355while (isspace (* s ))
5456++ s ;
55- for (id = s ,len = 0 ;isalnum (* s )|| * s == '_' ;++ len ,++ s )
56- ;
57+
58+ if (* s == '"' )
59+ {
60+ in_quotes = 1 ;
61+ s ++ ;
62+ }
63+
64+ for (id = s ,len = 0 ;isalnum (* s )|| * s == '_' || in_quotes ;++ len ,++ s )
65+ {
66+ if (in_quotes && * s == '"' )
67+ {
68+ len -- ;
69+ in_quotes = 0 ;
70+ }
71+ }
5772if (len > sizeof (NameData ))
5873elog (ERROR ,"getid: identifier cannot be >%d characters" ,
5974sizeof (NameData ));
@@ -91,12 +106,16 @@ aclparse(char *s, AclItem *aip, unsigned *modechg)
91106
92107Assert (s && aip && modechg );
93108
109+ #ifdef ACLDEBUG_TRACE
110+ printf ("aclparse: input = '%s'\n" ,s );
111+ #endif ACLDEBUG_TRACE
94112aip -> ai_idtype = ACL_IDTYPE_UID ;
95113s = getid (s ,name );
96114if (* s != ACL_MODECHG_ADD_CHR &&
97115* s != ACL_MODECHG_DEL_CHR &&
98116* s != ACL_MODECHG_EQL_CHR )
99- {/* we just read a keyword, not a name */
117+ {
118+ /* we just read a keyword, not a name */
100119if (!strcmp (name ,ACL_IDTYPE_GID_KEYWORD ))
101120aip -> ai_idtype = ACL_IDTYPE_GID ;
102121else if (strcmp (name ,ACL_IDTYPE_UID_KEYWORD ))
@@ -668,15 +687,15 @@ makeAclStmt(char *privileges, List *rel_list, char *grantee,
668687/* the grantee string is "G <group_name>", "U <user_name>", or "ALL" */
669688if (grantee [0 ]== 'G' )/* group permissions */
670689{
671- sprintf (str ,"%s %s %c%s" ,
690+ sprintf (str ,"%s %c%s%c %c%s" ,
672691ACL_IDTYPE_GID_KEYWORD ,
673- grantee + 2 ,grant_or_revoke ,privileges );
692+ '"' , grantee + 2 , '"' ,grant_or_revoke ,privileges );
674693}
675694else if (grantee [0 ]== 'U' )/* user permission */
676695{
677- sprintf (str ,"%s %s %c%s" ,
696+ sprintf (str ,"%s %c%s%c %c%s" ,
678697ACL_IDTYPE_UID_KEYWORD ,
679- grantee + 2 ,grant_or_revoke ,privileges );
698+ '"' , grantee + 2 , '"' ,grant_or_revoke ,privileges );
680699}
681700else
682701/* all permission */