initdb check_need_password fix

Started by Peter Eisentrautover 13 years ago2 messages
#1Peter Eisentraut
peter_e@gmx.net
1 attachment(s)

If you run initdb -A md5, you get an error

initdb: must specify a password for the superuser to enable md5 authentication

In 9.2, when you run something like initdb --auth-local=peer
--auth-host=md5, you still get that error, which I think is a mistake.
The error should only be shown if both authentication choices are
password-like. Hence I propose the attached patch.

Attachments:

pg-initdb-auth-error-fix.patchtext/x-patch; charset=UTF-8; name=pg-initdb-auth-error-fix.patchDownload
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index bac8385..edd5d71 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -2574,13 +2574,19 @@ struct tsearch_config_match
 }
 
 static void
-check_need_password(const char *authmethod)
+check_need_password(const char *authmethodlocal, const char *authmethodhost)
 {
-	if ((strcmp(authmethod, "md5") == 0 ||
-		 strcmp(authmethod, "password") == 0) &&
+	if ((strcmp(authmethodlocal, "md5") == 0 ||
+		 strcmp(authmethodlocal, "password") == 0) &&
+		(strcmp(authmethodhost, "md5") == 0 ||
+		 strcmp(authmethodhost, "password") == 0) &&
 		!(pwprompt || pwfilename))
 	{
-		fprintf(stderr, _("%s: must specify a password for the superuser to enable %s authentication\n"), progname, authmethod);
+		fprintf(stderr, _("%s: must specify a password for the superuser to enable %s authentication\n"), progname,
+				(strcmp(authmethodlocal, "md5") == 0 ||
+				 strcmp(authmethodlocal, "password") == 0)
+				? authmethodlocal
+				: authmethodhost);
 		exit(1);
 	}
 }
@@ -2792,8 +2798,7 @@ struct tsearch_config_match
 	check_authmethod_valid(authmethodlocal, auth_methods_local, "local");
 	check_authmethod_valid(authmethodhost, auth_methods_host, "host");
 
-	check_need_password(authmethodlocal);
-	check_need_password(authmethodhost);
+	check_need_password(authmethodlocal, authmethodhost);
 
 	if (strlen(pg_data) == 0)
 	{
#2Robert Haas
robertmhaas@gmail.com
In reply to: Peter Eisentraut (#1)
Re: initdb check_need_password fix

On Thu, Jun 28, 2012 at 3:48 PM, Peter Eisentraut <peter_e@gmx.net> wrote:

If you run initdb -A md5, you get an error

initdb: must specify a password for the superuser to enable md5 authentication

In 9.2, when you run something like initdb --auth-local=peer
--auth-host=md5, you still get that error, which I think is a mistake.
The error should only be shown if both authentication choices are
password-like.  Hence I propose the attached patch.

Looks right to me.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company