|
39 | 39 | * Portions Copyright (c) 1994, Regents of the University of California
|
40 | 40 | * Portions taken from FreeBSD.
|
41 | 41 | *
|
42 |
| - * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.44 2004/07/19 02:47:12 tgl Exp $ |
| 42 | + * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.45 2004/08/01 05:59:13 momjian Exp $ |
43 | 43 | *
|
44 | 44 | *-------------------------------------------------------------------------
|
45 | 45 | */
|
@@ -88,6 +88,7 @@ char *lc_messages = "";
|
88 | 88 | char *username = "";
|
89 | 89 | bool pwprompt = false;
|
90 | 90 | char *pwfilename = NULL;
|
| 91 | +char *authmethod = ""; |
91 | 92 | bool debug = false;
|
92 | 93 | bool noclean = false;
|
93 | 94 | bool show_setting = false;
|
@@ -118,6 +119,16 @@ bool output_failed = false;
|
118 | 119 | int n_connections = 10;
|
119 | 120 | int n_buffers = 50;
|
120 | 121 |
|
| 122 | +/* |
| 123 | + * Warning messages for authentication methods |
| 124 | + */ |
| 125 | +char *authtrust_warning = \ |
| 126 | + "# CAUTION: Configuring the system for local \"trust\" authentication allows\n" |
| 127 | + "# any local user to connect as any PostgreSQL user, including the database\n" |
| 128 | + "# superuser. If you do not trust all your local users, use another\n" |
| 129 | + "# authenication method.\n"; |
| 130 | +char *authwarning = NULL; |
| 131 | + |
121 | 132 | /*
|
122 | 133 | * Centralized knowledge of switches to pass to backend
|
123 | 134 | *
|
@@ -1114,7 +1125,16 @@ setup_config(void)
|
1114 | 1125 | "host all all ::1",
|
1115 | 1126 | "#host all all ::1");
|
1116 | 1127 | #endif
|
1117 |
| - |
| 1128 | + |
| 1129 | + /* Replace default authentication methods */ |
| 1130 | + conflines = replace_token(conflines, |
| 1131 | + "@authmethod@", |
| 1132 | + authmethod); |
| 1133 | + |
| 1134 | + conflines = replace_token(conflines, |
| 1135 | + "@authcomment@", |
| 1136 | + strcmp(authmethod,"trust") ? "" : authtrust_warning); |
| 1137 | + |
1118 | 1138 | snprintf(path, sizeof(path), "%s/pg_hba.conf", pg_data);
|
1119 | 1139 |
|
1120 | 1140 | writefile(path, conflines);
|
@@ -1971,6 +1991,7 @@ usage(const char *progname)
|
1971 | 1991 | " in the respective category (default taken from\n"
|
1972 | 1992 | " environment)\n"));
|
1973 | 1993 | printf(_(" --no-locale equivalent to --locale=C\n"));
|
| 1994 | + printf(_(" -A, --auth=method default authentication method for local connections\n")); |
1974 | 1995 | printf(_(" -U, --username=NAME database superuser name\n"));
|
1975 | 1996 | printf(_(" -W, --pwprompt prompt for a password for the new superuser\n"));
|
1976 | 1997 | printf(_(" --pwfile=filename read password for the new superuser from file\n"));
|
@@ -2004,6 +2025,7 @@ main(int argc, char *argv[])
|
2004 | 2025 | {"lc-time", required_argument, NULL, 6},
|
2005 | 2026 | {"lc-messages", required_argument, NULL, 7},
|
2006 | 2027 | {"no-locale", no_argument, NULL, 8},
|
| 2028 | + {"auth", required_argument, NULL, 'A'}, |
2007 | 2029 | {"pwprompt", no_argument, NULL, 'W'},
|
2008 | 2030 | {"pwfile", required_argument, NULL, 9},
|
2009 | 2031 | {"username", required_argument, NULL, 'U'},
|
@@ -2052,10 +2074,13 @@ main(int argc, char *argv[])
|
2052 | 2074 |
|
2053 | 2075 | /* process command-line options */
|
2054 | 2076 |
|
2055 |
| - while ((c = getopt_long(argc, argv, "dD:E:L:nU:W", long_options, &option_index)) != -1) |
| 2077 | + while ((c = getopt_long(argc, argv, "dD:E:L:nU:WA:", long_options, &option_index)) != -1) |
2056 | 2078 | {
|
2057 | 2079 | switch (c)
|
2058 | 2080 | {
|
| 2081 | + case 'A': |
| 2082 | + authmethod = xstrdup(optarg); |
| 2083 | + break; |
2059 | 2084 | case 'D':
|
2060 | 2085 | pg_data = xstrdup(optarg);
|
2061 | 2086 | break;
|
@@ -2136,6 +2161,43 @@ main(int argc, char *argv[])
|
2136 | 2161 | fprintf(stderr, _("%s: you cannot specify both password prompt and password file\n"), progname);
|
2137 | 2162 | exit(1);
|
2138 | 2163 | }
|
| 2164 | + |
| 2165 | + if (authmethod == NULL || !strlen(authmethod)) |
| 2166 | + { |
| 2167 | + authwarning = _("\nWARNING: enabling \"trust\" authentication for local connections.\n" |
| 2168 | + "You can change this by editing pg_hba.conf or using the -A flag the\n" |
| 2169 | + "next time you run initdb.\n"); |
| 2170 | + authmethod="trust"; |
| 2171 | + } |
| 2172 | + |
| 2173 | + if (strcmp(authmethod,"md5") && |
| 2174 | + strcmp(authmethod,"ident") && |
| 2175 | + strncmp(authmethod,"ident ",6) && /* ident with space = param */ |
| 2176 | + strcmp(authmethod,"trust") && |
| 2177 | +#ifdef USE_PAM |
| 2178 | + strcmp(authmethod,"pam") && |
| 2179 | + strncmp(authmethod,"pam ",4) && /* pam with space = param */ |
| 2180 | +#endif |
| 2181 | + strcmp(authmethod,"crypt") && |
| 2182 | + strcmp(authmethod,"password") |
| 2183 | + ) |
| 2184 | + /* |
| 2185 | + * Kerberos methods not listed because they are not supported |
| 2186 | + * over local connections and are rejected in hba.c |
| 2187 | + */ |
| 2188 | + { |
| 2189 | + fprintf(stderr, _("%s: unknown authentication method \"%s\".\n"), progname, authmethod); |
| 2190 | + exit(1); |
| 2191 | + } |
| 2192 | + |
| 2193 | + if ((!strcmp(authmethod,"md5") || |
| 2194 | + !strcmp(authmethod,"crypt") || |
| 2195 | + !strcmp(authmethod,"password")) && |
| 2196 | + !(pwprompt || pwfilename)) |
| 2197 | + { |
| 2198 | + fprintf(stderr, _("%s: you need to specify a password for the superuser to enable %s authentication.\n"), progname, authmethod); |
| 2199 | + exit(1); |
| 2200 | + } |
2139 | 2201 |
|
2140 | 2202 | if (strlen(pg_data) == 0)
|
2141 | 2203 | {
|
@@ -2449,6 +2511,9 @@ main(int argc, char *argv[])
|
2449 | 2511 |
|
2450 | 2512 | make_template0();
|
2451 | 2513 |
|
| 2514 | + if (authwarning != NULL) |
| 2515 | + fprintf(stderr, authwarning); |
| 2516 | + |
2452 | 2517 | printf(_("\nSuccess. You can now start the database server using:\n\n"
|
2453 | 2518 | " %s%s%s/postmaster -D %s%s%s\n"
|
2454 | 2519 | "or\n"
|
|
0 commit comments