@@ -185,6 +185,7 @@ static const char *default_timezone = NULL;
185185"# allows any local user to connect as any PostgreSQL user, including\n" \
186186"# the database superuser. If you do not trust all your local users,\n" \
187187"# use another authentication method.\n"
188+ static bool authwarning = false;
188189
189190/*
190191 * Centralized knowledge of switches to pass to backend
@@ -2390,6 +2391,16 @@ usage(const char *progname)
23902391 printf (_ ("\nReport bugs to <pgsql-bugs@lists.postgresql.org>.\n" ));
23912392}
23922393
2394+ static void
2395+ check_authmethod_unspecified (const char * * authmethod )
2396+ {
2397+ if (* authmethod == NULL )
2398+ {
2399+ authwarning = true;
2400+ * authmethod = "trust" ;
2401+ }
2402+ }
2403+
23932404static void
23942405check_authmethod_valid (const char * authmethod , const char * const * valid_methods , const char * conntype )
23952406{
@@ -3237,16 +3248,8 @@ main(int argc, char *argv[])
32373248 exit (1 );
32383249 }
32393250
3240- if (authmethodlocal == NULL )
3241- {
3242- #ifdef HAVE_AUTH_PEER
3243- authmethodlocal = "peer" ;
3244- #else
3245- authmethodlocal = "md5" ;
3246- #endif
3247- }
3248- if (authmethodhost == NULL )
3249- authmethodhost = "md5" ;
3251+ check_authmethod_unspecified (& authmethodlocal );
3252+ check_authmethod_unspecified (& authmethodhost );
32503253
32513254 check_authmethod_valid (authmethodlocal , auth_methods_local , "local" );
32523255 check_authmethod_valid (authmethodhost , auth_methods_host , "host" );
@@ -3329,6 +3332,14 @@ main(int argc, char *argv[])
33293332 else
33303333 printf (_ ("\nSync to disk skipped.\nThe data directory might become corrupt if the operating system crashes.\n" ));
33313334
3335+ if (authwarning )
3336+ {
3337+ printf ("\n" );
3338+ pg_log_warning ("enabling \"trust\" authentication for local connections" );
3339+ fprintf (stderr , _ ("You can change this by editing pg_hba.conf or using the option -A, or\n"
3340+ "--auth-local and --auth-host, the next time you run initdb.\n" ));
3341+ }
3342+
33323343 /*
33333344 * Build up a shell command to tell the user how to start the server
33343345 */
0 commit comments