Skip to content

Commit 8b0fec9

Browse files
committed
initdb: Fix for mixed-case superuser names
The previous coding did not properly quote the user name before casting it to regrole. To avoid all that, just pass in BOOTSTRAP_SUPERUSERID numerically. Also fix one place where the BOOTSTRAP_SUPERUSERID was hardcoded as 10.
1 parent c397814 commit 8b0fec9

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/bin/initdb/initdb.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#endif
6262

6363
#include "catalog/catalog.h"
64+
#include "catalog/pg_authid.h"
6465
#include "common/file_utils.h"
6566
#include "common/restricted_token.h"
6667
#include "common/username.h"
@@ -1617,7 +1618,7 @@ setup_collation(FILE *cmdfd)
16171618
PG_CMD_PUTS("SELECT pg_import_system_collations(if_not_exists => false, schema => 'pg_catalog');\n\n");
16181619

16191620
/* Add an SQL-standard name */
1620-
PG_CMD_PRINTF2("INSERT INTO pg_collation (collname, collnamespace, collowner, collencoding, collcollate, collctype) VALUES ('ucs_basic', 'pg_catalog'::regnamespace, '%s'::regrole, %d, 'C', 'C');\n\n", escape_quotes(username), PG_UTF8);
1621+
PG_CMD_PRINTF2("INSERT INTO pg_collation (collname, collnamespace, collowner, collencoding, collcollate, collctype) VALUES ('ucs_basic', 'pg_catalog'::regnamespace, %u, %d, 'C', 'C');\n\n", BOOTSTRAP_SUPERUSERID, PG_UTF8);
16211622
}
16221623

16231624
/*
@@ -1688,7 +1689,7 @@ setup_privileges(FILE *cmdfd)
16881689
" SET relacl = (SELECT array_agg(a.acl) FROM "
16891690
" (SELECT E'=r/\"$POSTGRES_SUPERUSERNAME\"' as acl "
16901691
" UNION SELECT unnest(pg_catalog.acldefault("
1691-
" CASE WHEN relkind = 'S' THEN 's' ELSE 'r' END::\"char\",10::oid))"
1692+
" CASE WHEN relkind = 'S' THEN 's' ELSE 'r' END::\"char\"," CppAsString2(BOOTSTRAP_SUPERUSERID) "::oid))"
16921693
" ) as a) "
16931694
" WHERE relkind IN ('r', 'v', 'm', 'S') AND relacl IS NULL;\n\n",
16941695
"GRANT USAGE ON SCHEMA pg_catalog TO PUBLIC;\n\n",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy