Skip to content

Commit 9e189bc

Browse files
nathan-bossartCommitfest Bot
authored andcommitted
pg_upgrade: Warn about roles with MD5 passwords.
1 parent 73bdcfa commit 9e189bc

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

src/bin/pg_upgrade/check.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ static void check_new_cluster_logical_replication_slots(void);
3131
static void check_new_cluster_subscription_configuration(void);
3232
static void check_old_cluster_for_valid_slots(void);
3333
static void check_old_cluster_subscription_state(void);
34+
static void check_for_md5_passwords(ClusterInfo *cluster);
3435

3536
/*
3637
* DataTypesUsageChecks - definitions of data type checks for the old cluster
@@ -685,6 +686,12 @@ check_and_dump_old_cluster(void)
685686
if (GET_MAJOR_VERSION(old_cluster.major_version) <= 905)
686687
check_for_pg_role_prefix(&old_cluster);
687688

689+
/*
690+
* MD5 password support is deprecated. Warn if any roles have MD5
691+
* passwords.
692+
*/
693+
check_for_md5_passwords(&old_cluster);
694+
688695
/*
689696
* While not a check option, we do this now because this is the only time
690697
* the old server is running.
@@ -2272,3 +2279,62 @@ check_old_cluster_subscription_state(void)
22722279
else
22732280
check_ok();
22742281
}
2282+
2283+
/*
2284+
* check_for_md5_passwords()
2285+
*
2286+
* As of v18, MD5 password support is marked as deprecated and to-be-removed in
2287+
* a future major release.
2288+
*/
2289+
static void
2290+
check_for_md5_passwords(ClusterInfo *cluster)
2291+
{
2292+
PGresult *res;
2293+
PGconn *conn = connectToServer(cluster, "template1");
2294+
int ntups;
2295+
int i_roloid;
2296+
int i_rolname;
2297+
FILE *script = NULL;
2298+
char output_path[MAXPGPATH];
2299+
2300+
prep_status("Checking for roles with MD5 passwords");
2301+
2302+
snprintf(output_path, sizeof(output_path), "%s/%s",
2303+
log_opts.basedir,
2304+
"roles_with_md5_passwords.txt");
2305+
2306+
res = executeQueryOrDie(conn,
2307+
"SELECT oid AS roloid, rolname "
2308+
"FROM pg_catalog.pg_authid "
2309+
"WHERE rolpassword ~ '^md5'");
2310+
2311+
ntups = PQntuples(res);
2312+
i_roloid = PQfnumber(res, "roloid");
2313+
i_rolname = PQfnumber(res, "rolname");
2314+
for (int rowno = 0; rowno < ntups; rowno++)
2315+
{
2316+
if (script == NULL && (script = fopen_priv(output_path, "w")) == NULL)
2317+
pg_fatal("could not open file \"%s\": %m", output_path);
2318+
fprintf(script, "%s (oid=%s)\n",
2319+
PQgetvalue(res, rowno, i_rolname),
2320+
PQgetvalue(res, rowno, i_roloid));
2321+
}
2322+
2323+
PQclear(res);
2324+
2325+
PQfinish(conn);
2326+
2327+
if (script)
2328+
{
2329+
fclose(script);
2330+
report_status(PG_WARNING, "warning");
2331+
pg_log(PG_WARNING,
2332+
"Your installation contains roles with MD5 passwords.\n"
2333+
"Support for MD5-encrypted passwords is deprecated and will be\n"
2334+
"removed in a future release of PostgreSQL. A list of roles\n"
2335+
"with MD5 passwords is in the file:\n"
2336+
" %s", output_path);
2337+
}
2338+
else
2339+
check_ok();
2340+
}

0 commit comments

Comments
 (0)