6
6
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
7
7
* Portions Copyright (c) 1994, Regents of the University of California
8
8
*
9
- * $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.157 2005/07/25 22:12:31 tgl Exp $
9
+ * $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.158 2005/07/26 16:38:26 tgl Exp $
10
10
*
11
11
*-------------------------------------------------------------------------
12
12
*/
@@ -82,6 +82,7 @@ CreateRole(CreateRoleStmt *stmt)
82
82
bool encrypt_password = Password_encryption ; /* encrypt password? */
83
83
char encrypted_password [MD5_PASSWD_LEN + 1 ];
84
84
bool issuper = false; /* Make the user a superuser? */
85
+ bool inherit = true; /* Auto inherit privileges? */
85
86
bool createrole = false; /* Can this user create roles? */
86
87
bool createdb = false; /* Can the user create databases? */
87
88
bool canlogin = false; /* Can this user login? */
@@ -91,6 +92,7 @@ CreateRole(CreateRoleStmt *stmt)
91
92
char * validUntil = NULL ; /* time the login is valid until */
92
93
DefElem * dpassword = NULL ;
93
94
DefElem * dissuper = NULL ;
95
+ DefElem * dinherit = NULL ;
94
96
DefElem * dcreaterole = NULL ;
95
97
DefElem * dcreatedb = NULL ;
96
98
DefElem * dcanlogin = NULL ;
@@ -99,6 +101,19 @@ CreateRole(CreateRoleStmt *stmt)
99
101
DefElem * dadminmembers = NULL ;
100
102
DefElem * dvalidUntil = NULL ;
101
103
104
+ /* The defaults can vary depending on the original statement type */
105
+ switch (stmt -> stmt_type )
106
+ {
107
+ case ROLESTMT_ROLE :
108
+ break ;
109
+ case ROLESTMT_USER :
110
+ canlogin = true;
111
+ /* may eventually want inherit to default to false here */
112
+ break ;
113
+ case ROLESTMT_GROUP :
114
+ break ;
115
+ }
116
+
102
117
/* Extract options from the statement node tree */
103
118
foreach (option , stmt -> options )
104
119
{
@@ -120,7 +135,7 @@ CreateRole(CreateRoleStmt *stmt)
120
135
}
121
136
else if (strcmp (defel -> defname , "sysid" ) == 0 )
122
137
{
123
- ereport (WARNING ,
138
+ ereport (NOTICE ,
124
139
(errmsg ("SYSID can no longer be specified" )));
125
140
}
126
141
else if (strcmp (defel -> defname , "superuser" ) == 0 )
@@ -131,6 +146,14 @@ CreateRole(CreateRoleStmt *stmt)
131
146
errmsg ("conflicting or redundant options" )));
132
147
dissuper = defel ;
133
148
}
149
+ else if (strcmp (defel -> defname , "inherit" ) == 0 )
150
+ {
151
+ if (dinherit )
152
+ ereport (ERROR ,
153
+ (errcode (ERRCODE_SYNTAX_ERROR ),
154
+ errmsg ("conflicting or redundant options" )));
155
+ dinherit = defel ;
156
+ }
134
157
else if (strcmp (defel -> defname , "createrole" ) == 0 )
135
158
{
136
159
if (dcreaterole )
@@ -196,6 +219,8 @@ CreateRole(CreateRoleStmt *stmt)
196
219
password = strVal (dpassword -> arg );
197
220
if (dissuper )
198
221
issuper = intVal (dissuper -> arg ) != 0 ;
222
+ if (dinherit )
223
+ inherit = intVal (dinherit -> arg ) != 0 ;
199
224
if (dcreaterole )
200
225
createrole = intVal (dcreaterole -> arg ) != 0 ;
201
226
if (dcreatedb )
@@ -261,6 +286,7 @@ CreateRole(CreateRoleStmt *stmt)
261
286
DirectFunctionCall1 (namein , CStringGetDatum (stmt -> role ));
262
287
263
288
new_record [Anum_pg_authid_rolsuper - 1 ] = BoolGetDatum (issuper );
289
+ new_record [Anum_pg_authid_rolinherit - 1 ] = BoolGetDatum (inherit );
264
290
new_record [Anum_pg_authid_rolcreaterole - 1 ] = BoolGetDatum (createrole );
265
291
new_record [Anum_pg_authid_rolcreatedb - 1 ] = BoolGetDatum (createdb );
266
292
/* superuser gets catupdate right by default */
@@ -367,13 +393,15 @@ AlterRole(AlterRoleStmt *stmt)
367
393
bool encrypt_password = Password_encryption ; /* encrypt password? */
368
394
char encrypted_password [MD5_PASSWD_LEN + 1 ];
369
395
int issuper = -1 ; /* Make the user a superuser? */
396
+ int inherit = -1 ; /* Auto inherit privileges? */
370
397
int createrole = -1 ; /* Can this user create roles? */
371
398
int createdb = -1 ; /* Can the user create databases? */
372
399
int canlogin = -1 ; /* Can this user login? */
373
400
List * rolemembers = NIL ; /* roles to be added/removed */
374
401
char * validUntil = NULL ; /* time the login is valid until */
375
402
DefElem * dpassword = NULL ;
376
403
DefElem * dissuper = NULL ;
404
+ DefElem * dinherit = NULL ;
377
405
DefElem * dcreaterole = NULL ;
378
406
DefElem * dcreatedb = NULL ;
379
407
DefElem * dcanlogin = NULL ;
@@ -408,6 +436,14 @@ AlterRole(AlterRoleStmt *stmt)
408
436
errmsg ("conflicting or redundant options" )));
409
437
dissuper = defel ;
410
438
}
439
+ else if (strcmp (defel -> defname , "inherit" ) == 0 )
440
+ {
441
+ if (dinherit )
442
+ ereport (ERROR ,
443
+ (errcode (ERRCODE_SYNTAX_ERROR ),
444
+ errmsg ("conflicting or redundant options" )));
445
+ dinherit = defel ;
446
+ }
411
447
else if (strcmp (defel -> defname , "createrole" ) == 0 )
412
448
{
413
449
if (dcreaterole )
@@ -458,6 +494,8 @@ AlterRole(AlterRoleStmt *stmt)
458
494
password = strVal (dpassword -> arg );
459
495
if (dissuper )
460
496
issuper = intVal (dissuper -> arg );
497
+ if (dinherit )
498
+ inherit = intVal (dinherit -> arg );
461
499
if (dcreaterole )
462
500
createrole = intVal (dcreaterole -> arg );
463
501
if (dcreatedb )
@@ -497,10 +535,10 @@ AlterRole(AlterRoleStmt *stmt)
497
535
(errcode (ERRCODE_INSUFFICIENT_PRIVILEGE ),
498
536
errmsg ("must be superuser to alter superusers" )));
499
537
}
500
- else
538
+ else if (! have_createrole_privilege ())
501
539
{
502
- if (!have_createrole_privilege () &&
503
- !( createrole < 0 &&
540
+ if (!( inherit < 0 &&
541
+ createrole < 0 &&
504
542
createdb < 0 &&
505
543
canlogin < 0 &&
506
544
!rolemembers &&
@@ -536,6 +574,12 @@ AlterRole(AlterRoleStmt *stmt)
536
574
new_record_repl [Anum_pg_authid_rolcatupdate - 1 ] = 'r' ;
537
575
}
538
576
577
+ if (inherit >= 0 )
578
+ {
579
+ new_record [Anum_pg_authid_rolinherit - 1 ] = BoolGetDatum (inherit > 0 );
580
+ new_record_repl [Anum_pg_authid_rolinherit - 1 ] = 'r' ;
581
+ }
582
+
539
583
if (createrole >= 0 )
540
584
{
541
585
new_record [Anum_pg_authid_rolcreaterole - 1 ] = BoolGetDatum (createrole > 0 );
0 commit comments