Index: doc/src/sgml/runtime.sgml =================================================================== RCS file: /projects/cvsroot/pgsql-server/doc/src/sgml/runtime.sgml,v retrieving revision 1.266 diff -c -c -r1.266 runtime.sgml *** doc/src/sgml/runtime.sgml 10 Jun 2004 22:26:17 -0000 1.266 --- doc/src/sgml/runtime.sgml 20 Jun 2004 17:07:00 -0000 *************** *** 121,129 **** However, while the directory contents are secure, the default client authentication setup allows any local user to connect to the database and even become the database superuser. If you do not ! trust other local users, we recommend you use ! initdb's or ! option to assign a password to the database superuser.passwordof the superuser After initdb, modify the pg_hba.conf file to use md5 or --- 121,129 ---- However, while the directory contents are secure, the default client authentication setup allows any local user to connect to the database and even become the database superuser. If you do not ! trust other local users, we recommend you use one of ! initdb's , ! or option to assign a password to the database superuser.passwordof the superuser After initdb, modify the pg_hba.conf file to use md5 or Index: doc/src/sgml/ref/initdb.sgml =================================================================== RCS file: /projects/cvsroot/pgsql-server/doc/src/sgml/ref/initdb.sgml,v retrieving revision 1.29 diff -c -c -r1.29 initdb.sgml *** doc/src/sgml/ref/initdb.sgml 23 Mar 2004 02:47:35 -0000 1.29 --- doc/src/sgml/ref/initdb.sgml 20 Jun 2004 17:08:36 -0000 *************** *** 185,190 **** --- 185,199 ---- + + + + + + Makes initdb read the password to give the + database superuser from a file. + + Index: src/bin/initdb/initdb.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/bin/initdb/initdb.c,v retrieving revision 1.38 diff -c -c -r1.38 initdb.c *** src/bin/initdb/initdb.c 18 Jun 2004 06:13:58 -0000 1.38 --- src/bin/initdb/initdb.c 20 Jun 2004 16:51:37 -0000 *************** *** 84,89 **** --- 84,90 ---- char *lc_messages = ""; char *username = ""; bool pwprompt = false; + char *pwfilename = NULL; bool debug = false; bool noclean = false; bool show_setting = false; *************** *** 1076,1090 **** char pwdpath[MAXPGPATH]; struct stat statbuf; ! pwd1 = simple_prompt("Enter new superuser password: ", 100, false); ! pwd2 = simple_prompt("Enter it again: ", 100, false); ! if (strcmp(pwd1, pwd2) != 0) { ! fprintf(stderr, _("Passwords didn't match.\n")); ! exit_nicely(); } ! free(pwd2); printf(_("setting password ... ")); fflush(stdout); --- 1077,1116 ---- char pwdpath[MAXPGPATH]; struct stat statbuf; ! if (pwprompt) { ! pwd1 = simple_prompt("Enter new superuser password: ", 100, false); ! pwd2 = simple_prompt("Enter it again: ", 100, false); ! if (strcmp(pwd1, pwd2) != 0) ! { ! fprintf(stderr, _("Passwords didn't match.\n")); ! exit_nicely(); ! } ! free(pwd2); } ! else ! { ! FILE *pwf = fopen(pwfilename,"r"); ! char pwdbuf[MAXPGPATH]; + if (!pwf) + { + fprintf(stderr, _("Failed to open '%s' to read superuser password: %i\n"), pwfilename, errno); + exit_nicely(); + } + if (!fgets(pwdbuf, sizeof(pwdbuf), pwf)) + { + fprintf(stderr, _("Failed to read superuser password from '%s': %i\n"), pwfilename, errno); + fclose(pwf); + exit_nicely(); + } + fclose(pwf); + while (pwdbuf[strlen(pwdbuf)-1] == '\r' || pwdbuf[strlen(pwdbuf)-1] == '\n') + pwdbuf[strlen(pwdbuf)-1] = 0; + + pwd1 = xstrdup(pwdbuf); + + } printf(_("setting password ... ")); fflush(stdout); *************** *** 1737,1742 **** --- 1763,1769 ---- printf(_(" --no-locale equivalent to --locale=C\n")); printf(_(" -U, --username=NAME database superuser name\n")); printf(_(" -W, --pwprompt prompt for a password for the new superuser\n")); + printf(_(" --pwfile=filename read password for the new superuser from file\n")); printf(_(" -?, --help show this help, then exit\n")); printf(_(" -V, --version output version information, then exit\n")); printf(_("\nLess commonly used options:\n")); *************** *** 1768,1773 **** --- 1795,1801 ---- {"lc-messages", required_argument, NULL, 7}, {"no-locale", no_argument, NULL, 8}, {"pwprompt", no_argument, NULL, 'W'}, + {"pwfile", required_argument, NULL, 9}, {"username", required_argument, NULL, 'U'}, {"help", no_argument, NULL, '?'}, {"version", no_argument, NULL, 'V'}, *************** *** 1857,1862 **** --- 1885,1893 ---- case 8: locale = "C"; break; + case 9: + pwfilename = xstrdup(optarg); + break; case 's': show_setting = true; break; *************** *** 1882,1887 **** --- 1913,1924 ---- progname); } + if (pwprompt && pwfilename) + { + fprintf(stderr, _("%s: you cannot specify both password prompt and password file\n"), progname); + exit(1); + } + if (strlen(pg_data) == 0) { pgdenv = getenv("PGDATA"); *************** *** 2147,2153 **** /* Create the stuff we don't need to use bootstrap mode for */ setup_shadow(); ! if (pwprompt) get_set_pwd(); unlimit_systables(); --- 2184,2190 ---- /* Create the stuff we don't need to use bootstrap mode for */ setup_shadow(); ! if (pwprompt || pwfilename) get_set_pwd(); unlimit_systables();