Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d3406d8

Browse files
Fix handling of default option values in createuser
Add description of which one is the default between two complementary options of --bypassrls and --replication in the help text and docs. In correspondence let the command always include the tokens corresponding to every options of that kind in the SQL command sent to server. Tests are updated accordingly. Also fix the checks of some trivalue vars which were using literal zero for checking default value instead of the enum label TRI_DEFAULT. While not a bug, since TRI_DEFAULT is defined as zero, fixing improves read- ability improved readability (and avoid bugs if the enum is changed). Author: Kyotaro Horiguchi <horikyota.ntt@gmail.com> Discussion: https://postgr.es/m/20220810.151243.1073197628358749087.horikyota.ntt@gmail.com
1 parent 4211fbd commit d3406d8

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

doc/src/sgml/ref/createuser.sgml

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ PostgreSQL documentation
348348
<para>
349349
The new user will not have the <literal>REPLICATION</literal>
350350
privilege, which is described more fully in the documentation for <xref
351-
linkend="sql-createrole"/>.
351+
linkend="sql-createrole"/>. This is the default.
352352
</para>
353353
</listitem>
354354
</varlistentry>

src/bin/scripts/createuser.c

+14-7
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ main(int argc, char *argv[])
239239
free(pw2);
240240
}
241241

242-
if (superuser == 0)
242+
if (superuser == TRI_DEFAULT)
243243
{
244244
if (interactive && yesno_prompt("Shall the new role be a superuser?"))
245245
superuser = TRI_YES;
@@ -254,26 +254,32 @@ main(int argc, char *argv[])
254254
createrole = TRI_YES;
255255
}
256256

257-
if (createdb == 0)
257+
if (createdb == TRI_DEFAULT)
258258
{
259259
if (interactive && yesno_prompt("Shall the new role be allowed to create databases?"))
260260
createdb = TRI_YES;
261261
else
262262
createdb = TRI_NO;
263263
}
264264

265-
if (createrole == 0)
265+
if (createrole == TRI_DEFAULT)
266266
{
267267
if (interactive && yesno_prompt("Shall the new role be allowed to create more new roles?"))
268268
createrole = TRI_YES;
269269
else
270270
createrole = TRI_NO;
271271
}
272272

273-
if (inherit == 0)
273+
if (bypassrls == TRI_DEFAULT)
274+
bypassrls = TRI_NO;
275+
276+
if (replication == TRI_DEFAULT)
277+
replication = TRI_NO;
278+
279+
if (inherit == TRI_DEFAULT)
274280
inherit = TRI_YES;
275281

276-
if (login == 0)
282+
if (login == TRI_DEFAULT)
277283
login = TRI_YES;
278284

279285
cparams.dbname = NULL; /* this program lacks any dbname option... */
@@ -432,9 +438,10 @@ help(const char *progname)
432438
printf(_(" --interactive prompt for missing role name and attributes rather\n"
433439
" than using defaults\n"));
434440
printf(_(" --bypassrls role can bypass row-level security (RLS) policy\n"));
435-
printf(_(" --no-bypassrls role cannot bypass row-level security (RLS) policy\n"));
441+
printf(_(" --no-bypassrls role cannot bypass row-level security (RLS) policy\n"
442+
" (default)\n"));
436443
printf(_(" --replication role can initiate replication\n"));
437-
printf(_(" --no-replication role cannot initiate replication\n"));
444+
printf(_(" --no-replication role cannot initiate replication (default)\n"));
438445
printf(_(" -?, --help show this help, then exit\n"));
439446
printf(_("\nConnection options:\n"));
440447
printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));

src/bin/scripts/t/040_createuser.pl

+9-9
Original file line numberDiff line numberDiff line change
@@ -18,47 +18,47 @@
1818

1919
$node->issues_sql_like(
2020
[ 'createuser', 'regress_user1' ],
21-
qr/statement: CREATE ROLE regress_user1 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN;/,
21+
qr/statement: CREATE ROLE regress_user1 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN NOREPLICATION NOBYPASSRLS;/,
2222
'SQL CREATE USER run');
2323
$node->issues_sql_like(
2424
[ 'createuser', '-L', 'regress_role1' ],
25-
qr/statement: CREATE ROLE regress_role1 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT NOLOGIN;/,
25+
qr/statement: CREATE ROLE regress_role1 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT NOLOGIN NOREPLICATION NOBYPASSRLS;/,
2626
'create a non-login role');
2727
$node->issues_sql_like(
2828
[ 'createuser', '-r', 'regress user2' ],
29-
qr/statement: CREATE ROLE "regress user2" NOSUPERUSER NOCREATEDB CREATEROLE INHERIT LOGIN;/,
29+
qr/statement: CREATE ROLE "regress user2" NOSUPERUSER NOCREATEDB CREATEROLE INHERIT LOGIN NOREPLICATION NOBYPASSRLS;/,
3030
'create a CREATEROLE user');
3131
$node->issues_sql_like(
3232
[ 'createuser', '-s', 'regress_user3' ],
33-
qr/statement: CREATE ROLE regress_user3 SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;/,
33+
qr/statement: CREATE ROLE regress_user3 SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN NOREPLICATION NOBYPASSRLS;/,
3434
'create a superuser');
3535
$node->issues_sql_like(
3636
[
3737
'createuser', '-a',
3838
'regress_user1', '-a',
3939
'regress user2', 'regress user #4'
4040
],
41-
qr/statement: CREATE ROLE "regress user #4" NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN ADMIN regress_user1,"regress user2";/,
41+
qr/statement: CREATE ROLE "regress user #4" NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN NOREPLICATION NOBYPASSRLS ADMIN regress_user1,"regress user2";/,
4242
'add a role as a member with admin option of the newly created role');
4343
$node->issues_sql_like(
4444
[
4545
'createuser', '-m',
4646
'regress_user3', '-m',
4747
'regress user #4', 'REGRESS_USER5'
4848
],
49-
qr/statement: CREATE ROLE "REGRESS_USER5" NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN ROLE regress_user3,"regress user #4";/,
49+
qr/statement: CREATE ROLE "REGRESS_USER5" NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN NOREPLICATION NOBYPASSRLS ROLE regress_user3,"regress user #4";/,
5050
'add a role as a member of the newly created role');
5151
$node->issues_sql_like(
5252
[ 'createuser', '-v', '2029 12 31', 'regress_user6' ],
53-
qr/statement: CREATE ROLE regress_user6 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN VALID UNTIL \'2029 12 31\';/,
53+
qr/statement: CREATE ROLE regress_user6 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN NOREPLICATION NOBYPASSRLS VALID UNTIL \'2029 12 31\';/,
5454
'create a role with a password expiration date');
5555
$node->issues_sql_like(
5656
[ 'createuser', '--bypassrls', 'regress_user7' ],
57-
qr/statement: CREATE ROLE regress_user7 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN BYPASSRLS;/,
57+
qr/statement: CREATE ROLE regress_user7 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN NOREPLICATION BYPASSRLS;/,
5858
'create a BYPASSRLS role');
5959
$node->issues_sql_like(
6060
[ 'createuser', '--no-bypassrls', 'regress_user8' ],
61-
qr/statement: CREATE ROLE regress_user8 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN NOBYPASSRLS;/,
61+
qr/statement: CREATE ROLE regress_user8 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN NOREPLICATION NOBYPASSRLS;/,
6262
'create a role without BYPASSRLS');
6363

6464
$node->command_fails([ 'createuser', 'regress_user1' ],

0 commit comments

Comments
 (0)