@@ -24,6 +24,7 @@ main(int argc, char *argv[])
24
24
{"host" , required_argument , NULL , 'h' },
25
25
{"port" , required_argument , NULL , 'p' },
26
26
{"username" , required_argument , NULL , 'U' },
27
+ {"role" , required_argument , NULL , 'g' },
27
28
{"no-password" , no_argument , NULL , 'w' },
28
29
{"password" , no_argument , NULL , 'W' },
29
30
{"echo" , no_argument , NULL , 'e' },
@@ -57,6 +58,7 @@ main(int argc, char *argv[])
57
58
char * host = NULL ;
58
59
char * port = NULL ;
59
60
char * username = NULL ;
61
+ SimpleStringList roles = {NULL , NULL };
60
62
enum trivalue prompt_password = TRI_DEFAULT ;
61
63
bool echo = false;
62
64
bool interactive = false;
@@ -83,7 +85,7 @@ main(int argc, char *argv[])
83
85
84
86
handle_help_version_opts (argc , argv , "createuser" , help );
85
87
86
- while ((c = getopt_long (argc , argv , "h:p:U:wWedDsSaArRiIlLc:PEN" ,
88
+ while ((c = getopt_long (argc , argv , "h:p:U:g: wWedDsSaArRiIlLc:PEN" ,
87
89
long_options , & optindex )) != -1 )
88
90
{
89
91
switch (c )
@@ -97,6 +99,9 @@ main(int argc, char *argv[])
97
99
case 'U' :
98
100
username = pg_strdup (optarg );
99
101
break ;
102
+ case 'g' :
103
+ simple_string_list_append (& roles , optarg );
104
+ break ;
100
105
case 'w' :
101
106
prompt_password = TRI_NO ;
102
107
break ;
@@ -302,6 +307,19 @@ main(int argc, char *argv[])
302
307
appendPQExpBufferStr (& sql , " NOREPLICATION" );
303
308
if (conn_limit != NULL )
304
309
appendPQExpBuffer (& sql , " CONNECTION LIMIT %s" , conn_limit );
310
+ if (roles .head != NULL )
311
+ {
312
+ SimpleStringListCell * cell ;
313
+ appendPQExpBufferStr (& sql , " IN ROLE " );
314
+
315
+ for (cell = roles .head ; cell ; cell = cell -> next )
316
+ {
317
+ if (cell -> next )
318
+ appendPQExpBuffer (& sql , "%s," , fmtId (cell -> val ));
319
+ else
320
+ appendPQExpBuffer (& sql , "%s" , fmtId (cell -> val ));
321
+ }
322
+ }
305
323
appendPQExpBufferStr (& sql , ";\n" );
306
324
307
325
if (echo )
@@ -334,6 +352,7 @@ help(const char *progname)
334
352
printf (_ (" -D, --no-createdb role cannot create databases (default)\n" ));
335
353
printf (_ (" -e, --echo show the commands being sent to the server\n" ));
336
354
printf (_ (" -E, --encrypted encrypt stored password\n" ));
355
+ printf (_ (" -g, --role=ROLE new role will be a member of this role\n" ));
337
356
printf (_ (" -i, --inherit role inherits privileges of roles it is a\n"
338
357
" member of (default)\n" ));
339
358
printf (_ (" -I, --no-inherit role does not inherit privileges\n" ));
0 commit comments