7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.40 1999/07/17 20:17:52 momjian Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.41 1999/10/18 03:32:29 tgl Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
14
14
#include <ctype.h>
15
+
15
16
#include "postgres.h"
16
17
17
18
#include "catalog/catalog.h"
18
19
#include "catalog/pg_shadow.h"
19
20
#include "catalog/pg_type.h"
20
- #include "miscadmin .h"
21
+ #include "lib/stringinfo .h"
21
22
#include "utils/acl.h"
22
23
#include "utils/memutils.h"
23
24
#include "utils/syscache.h"
@@ -41,7 +42,7 @@ static char *aclparse(char *s, AclItem *aip, unsigned *modechg);
41
42
* the string position in 's' that points to the next non-space character
42
43
* in 's', after any quotes. Also:
43
44
* - loads the identifier into 'name'. (If no identifier is found, 'name'
44
- * contains an empty string) .
45
+ * contains an empty string.) name must be NAMEDATALEN bytes .
45
46
*/
46
47
static char *
47
48
getid (char * s , char * n )
@@ -69,9 +70,9 @@ getid(char *s, char *n)
69
70
in_quotes = 0 ;
70
71
}
71
72
}
72
- if (len > sizeof ( NameData ) )
73
- elog (ERROR , "getid: identifier cannot be > %d characters" ,
74
- sizeof ( NameData ) );
73
+ if (len >= NAMEDATALEN )
74
+ elog (ERROR , "getid: identifier must be < %d characters" ,
75
+ NAMEDATALEN );
75
76
if (len > 0 )
76
77
memmove (n , id , len );
77
78
n [len ] = '\0' ;
@@ -205,10 +206,10 @@ makeacl(int n)
205
206
Size size ;
206
207
207
208
if (n < 0 )
208
- elog (ERROR , "makeacl: invalid size: %d\n " , n );
209
+ elog (ERROR , "makeacl: invalid size: %d" , n );
209
210
size = ACL_N_SIZE (n );
210
211
if (!(new_acl = (Acl * ) palloc (size )))
211
- elog (ERROR , "makeacl: palloc failed on %d\n " , size );
212
+ elog (ERROR , "makeacl: palloc failed on %d" , size );
212
213
MemSet ((char * ) new_acl , 0 , size );
213
214
new_acl -> size = size ;
214
215
new_acl -> ndim = 1 ;
@@ -679,34 +680,37 @@ ChangeACLStmt *
679
680
makeAclStmt (char * privileges , List * rel_list , char * grantee ,
680
681
char grant_or_revoke )
681
682
{
682
- ChangeACLStmt * n = makeNode (ChangeACLStmt );
683
- char str [MAX_PARSE_BUFFER ];
683
+ ChangeACLStmt * n = makeNode (ChangeACLStmt );
684
+ StringInfoData str ;
685
+
686
+ initStringInfo (& str );
684
687
685
688
/* see comment in pg_type.h */
686
689
Assert (ACLITEMSIZE == sizeof (AclItem ));
687
690
688
691
n -> aclitem = (AclItem * ) palloc (sizeof (AclItem ));
689
692
690
- /* the grantee string is "G <group_name>", "U <user_name>", or "ALL" */
693
+ /* the grantee string is "G <group_name>", "U <user_name>", or "ALL" */
691
694
if (grantee [0 ] == 'G' ) /* group permissions */
692
695
{
693
- sprintf ( str , "%s %c%s%c %c%s" ,
694
- ACL_IDTYPE_GID_KEYWORD ,
695
- '"' , grantee + 2 , '"' , grant_or_revoke , privileges );
696
+ appendStringInfo ( & str , "%s \"%s\" %c%s" ,
697
+ ACL_IDTYPE_GID_KEYWORD ,
698
+ grantee + 2 , grant_or_revoke , privileges );
696
699
}
697
700
else if (grantee [0 ] == 'U' ) /* user permission */
698
701
{
699
- sprintf ( str , "%s %c%s%c %c%s" ,
700
- ACL_IDTYPE_UID_KEYWORD ,
701
- '"' , grantee + 2 , '"' , grant_or_revoke , privileges );
702
+ appendStringInfo ( & str , "%s \"%s\" %c%s" ,
703
+ ACL_IDTYPE_UID_KEYWORD ,
704
+ grantee + 2 , grant_or_revoke , privileges );
702
705
}
703
706
else
704
- /* all permission */
705
707
{
706
- sprintf (str , "%c%s" ,
707
- grant_or_revoke , privileges );
708
+ /* all permission */
709
+ appendStringInfo (& str , "%c%s" ,
710
+ grant_or_revoke , privileges );
708
711
}
709
712
n -> relNames = rel_list ;
710
- aclparse (str , n -> aclitem , (unsigned * ) & n -> modechg );
713
+ aclparse (str .data , n -> aclitem , (unsigned * ) & n -> modechg );
714
+ pfree (str .data );
711
715
return n ;
712
716
}
0 commit comments