28
28
main (int argc , char * argv [])
29
29
{
30
30
static struct option long_options [] = {
31
+ {"admin" , required_argument , NULL , 'a' },
31
32
{"connection-limit" , required_argument , NULL , 'c' },
32
33
{"createdb" , no_argument , NULL , 'd' },
33
34
{"no-createdb" , no_argument , NULL , 'D' },
@@ -39,18 +40,22 @@ main(int argc, char *argv[])
39
40
{"no-inherit" , no_argument , NULL , 'I' },
40
41
{"login" , no_argument , NULL , 'l' },
41
42
{"no-login" , no_argument , NULL , 'L' },
43
+ {"member" , required_argument , NULL , 'm' },
42
44
{"port" , required_argument , NULL , 'p' },
43
45
{"pwprompt" , no_argument , NULL , 'P' },
44
46
{"createrole" , no_argument , NULL , 'r' },
45
47
{"no-createrole" , no_argument , NULL , 'R' },
46
48
{"superuser" , no_argument , NULL , 's' },
47
49
{"no-superuser" , no_argument , NULL , 'S' },
48
50
{"username" , required_argument , NULL , 'U' },
51
+ {"valid-until" , required_argument , NULL , 'v' },
49
52
{"no-password" , no_argument , NULL , 'w' },
50
53
{"password" , no_argument , NULL , 'W' },
51
54
{"replication" , no_argument , NULL , 1 },
52
55
{"no-replication" , no_argument , NULL , 2 },
53
56
{"interactive" , no_argument , NULL , 3 },
57
+ {"bypassrls" , no_argument , NULL , 4 },
58
+ {"no-bypassrls" , no_argument , NULL , 5 },
54
59
{NULL , 0 , NULL , 0 }
55
60
};
56
61
@@ -62,21 +67,25 @@ main(int argc, char *argv[])
62
67
char * port = NULL ;
63
68
char * username = NULL ;
64
69
SimpleStringList roles = {NULL , NULL };
70
+ SimpleStringList members = {NULL , NULL };
71
+ SimpleStringList admins = {NULL , NULL };
65
72
enum trivalue prompt_password = TRI_DEFAULT ;
66
73
ConnParams cparams ;
67
74
bool echo = false;
68
75
bool interactive = false;
69
76
int conn_limit = -2 ; /* less than minimum valid value */
70
77
bool pwprompt = false;
71
78
char * newpassword = NULL ;
79
+ char * pwexpiry = NULL ;
72
80
73
81
/* Tri-valued variables. */
74
82
enum trivalue createdb = TRI_DEFAULT ,
75
83
superuser = TRI_DEFAULT ,
76
84
createrole = TRI_DEFAULT ,
77
85
inherit = TRI_DEFAULT ,
78
86
login = TRI_DEFAULT ,
79
- replication = TRI_DEFAULT ;
87
+ replication = TRI_DEFAULT ,
88
+ bypassrls = TRI_DEFAULT ;
80
89
81
90
PQExpBufferData sql ;
82
91
@@ -89,11 +98,14 @@ main(int argc, char *argv[])
89
98
90
99
handle_help_version_opts (argc , argv , "createuser" , help );
91
100
92
- while ((c = getopt_long (argc , argv , "c:dDeEg:h:iIlLp: PrRsSU:wW" ,
101
+ while ((c = getopt_long (argc , argv , "a: c:dDeEg:h:iIlLm:p: PrRsSU:v :wW" ,
93
102
long_options , & optindex )) != -1 )
94
103
{
95
104
switch (c )
96
105
{
106
+ case 'a' :
107
+ simple_string_list_append (& admins , optarg );
108
+ break ;
97
109
case 'c' :
98
110
if (!option_parse_int (optarg , "-c/--connection-limit" ,
99
111
-1 , INT_MAX , & conn_limit ))
@@ -129,6 +141,9 @@ main(int argc, char *argv[])
129
141
case 'L' :
130
142
login = TRI_NO ;
131
143
break ;
144
+ case 'm' :
145
+ simple_string_list_append (& members , optarg );
146
+ break ;
132
147
case 'p' :
133
148
port = pg_strdup (optarg );
134
149
break ;
@@ -150,6 +165,9 @@ main(int argc, char *argv[])
150
165
case 'U' :
151
166
username = pg_strdup (optarg );
152
167
break ;
168
+ case 'v' :
169
+ pwexpiry = pg_strdup (optarg );
170
+ break ;
153
171
case 'w' :
154
172
prompt_password = TRI_NO ;
155
173
break ;
@@ -165,6 +183,12 @@ main(int argc, char *argv[])
165
183
case 3 :
166
184
interactive = true;
167
185
break ;
186
+ case 4 :
187
+ bypassrls = TRI_YES ;
188
+ break ;
189
+ case 5 :
190
+ bypassrls = TRI_NO ;
191
+ break ;
168
192
default :
169
193
/* getopt_long already emitted a complaint */
170
194
pg_log_error_hint ("Try \"%s --help\" for more information." , progname );
@@ -304,8 +328,17 @@ main(int argc, char *argv[])
304
328
appendPQExpBufferStr (& sql , " REPLICATION" );
305
329
if (replication == TRI_NO )
306
330
appendPQExpBufferStr (& sql , " NOREPLICATION" );
331
+ if (bypassrls == TRI_YES )
332
+ appendPQExpBufferStr (& sql , " BYPASSRLS" );
333
+ if (bypassrls == TRI_NO )
334
+ appendPQExpBufferStr (& sql , " NOBYPASSRLS" );
307
335
if (conn_limit >= -1 )
308
336
appendPQExpBuffer (& sql , " CONNECTION LIMIT %d" , conn_limit );
337
+ if (pwexpiry != NULL )
338
+ {
339
+ appendPQExpBufferStr (& sql , " VALID UNTIL " );
340
+ appendStringLiteralConn (& sql , pwexpiry , conn );
341
+ }
309
342
if (roles .head != NULL )
310
343
{
311
344
SimpleStringListCell * cell ;
@@ -320,6 +353,35 @@ main(int argc, char *argv[])
320
353
appendPQExpBufferStr (& sql , fmtId (cell -> val ));
321
354
}
322
355
}
356
+ if (members .head != NULL )
357
+ {
358
+ SimpleStringListCell * cell ;
359
+
360
+ appendPQExpBufferStr (& sql , " ROLE " );
361
+
362
+ for (cell = members .head ; cell ; cell = cell -> next )
363
+ {
364
+ if (cell -> next )
365
+ appendPQExpBuffer (& sql , "%s," , fmtId (cell -> val ));
366
+ else
367
+ appendPQExpBufferStr (& sql , fmtId (cell -> val ));
368
+ }
369
+ }
370
+ if (admins .head != NULL )
371
+ {
372
+ SimpleStringListCell * cell ;
373
+
374
+ appendPQExpBufferStr (& sql , " ADMIN " );
375
+
376
+ for (cell = admins .head ; cell ; cell = cell -> next )
377
+ {
378
+ if (cell -> next )
379
+ appendPQExpBuffer (& sql , "%s," , fmtId (cell -> val ));
380
+ else
381
+ appendPQExpBufferStr (& sql , fmtId (cell -> val ));
382
+ }
383
+ }
384
+
323
385
appendPQExpBufferChar (& sql , ';' );
324
386
325
387
if (echo )
@@ -346,6 +408,8 @@ help(const char *progname)
346
408
printf (_ ("Usage:\n" ));
347
409
printf (_ (" %s [OPTION]... [ROLENAME]\n" ), progname );
348
410
printf (_ ("\nOptions:\n" ));
411
+ printf (_ (" -a, --admin=ROLE this role will be a member of new role with admin\n"
412
+ " option\n" ));
349
413
printf (_ (" -c, --connection-limit=N connection limit for role (default: no limit)\n" ));
350
414
printf (_ (" -d, --createdb role can create new databases\n" ));
351
415
printf (_ (" -D, --no-createdb role cannot create databases (default)\n" ));
@@ -356,14 +420,18 @@ help(const char *progname)
356
420
printf (_ (" -I, --no-inherit role does not inherit privileges\n" ));
357
421
printf (_ (" -l, --login role can login (default)\n" ));
358
422
printf (_ (" -L, --no-login role cannot login\n" ));
423
+ printf (_ (" -m, --member=ROLE this role will be a member of new role\n" ));
359
424
printf (_ (" -P, --pwprompt assign a password to new role\n" ));
360
425
printf (_ (" -r, --createrole role can create new roles\n" ));
361
426
printf (_ (" -R, --no-createrole role cannot create roles (default)\n" ));
362
427
printf (_ (" -s, --superuser role will be superuser\n" ));
363
428
printf (_ (" -S, --no-superuser role will not be superuser (default)\n" ));
429
+ printf (_ (" -v, --valid-until password expiration date for role\n" ));
364
430
printf (_ (" -V, --version output version information, then exit\n" ));
365
431
printf (_ (" --interactive prompt for missing role name and attributes rather\n"
366
432
" than using defaults\n" ));
433
+ printf (_ (" --bypassrls role can bypass row-level security (RLS) policy\n" ));
434
+ printf (_ (" --no-bypassrls role cannot bypass row-level security (RLS) policy\n" ));
367
435
printf (_ (" --replication role can initiate replication\n" ));
368
436
printf (_ (" --no-replication role cannot initiate replication\n" ));
369
437
printf (_ (" -?, --help show this help, then exit\n" ));
0 commit comments