4242 * Portions Copyright (c) 1994, Regents of the University of California
4343 * Portions taken from FreeBSD.
4444 *
45- * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.111 2006/02/2400:55:49 adunstan Exp $
45+ * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.112 2006/02/2402:02:41 adunstan Exp $
4646 *
4747 *-------------------------------------------------------------------------
4848 */
@@ -95,9 +95,6 @@ static char *authmethod = "";
9595static bool debug = false;
9696static bool noclean = false;
9797static bool show_setting = false;
98- #ifdef WIN32
99- static bool restricted_exec = false;
100- #endif
10198
10299
103100/* internal vars */
@@ -2426,11 +2423,8 @@ main(int argc, char *argv[])
24262423{"lc-messages" ,required_argument ,NULL ,7 },
24272424{"no-locale" ,no_argument ,NULL ,8 },
24282425{"auth" ,required_argument ,NULL ,'A' },
2429- {"pwprompt" ,no_argument ,NULL ,'W' },
2426+ {"pwprompt" ,no_argument ,NULL ,'W' },
24302427{"pwfile" ,required_argument ,NULL ,9 },
2431- #ifdef WIN32
2432- {"restrictedexec" ,no_argument ,NULL ,10 },
2433- #endif
24342428{"username" ,required_argument ,NULL ,'U' },
24352429{"help" ,no_argument ,NULL ,'?' },
24362430{"version" ,no_argument ,NULL ,'V' },
@@ -2450,6 +2444,9 @@ main(int argc, char *argv[])
24502444 * environment */
24512445char bin_dir [MAXPGPATH ];
24522446char * pg_data_native ;
2447+ #ifdef WIN32
2448+ char * restrict_env ;
2449+ #endif
24532450static const char * subdirs []= {
24542451"global" ,
24552452"pg_xlog" ,
@@ -2540,11 +2537,6 @@ main(int argc, char *argv[])
25402537case 9 :
25412538pwfilename = xstrdup (optarg );
25422539break ;
2543- #ifdef WIN32
2544- case 10 :
2545- restricted_exec = true;
2546- break ;
2547- #endif
25482540case 's' :
25492541show_setting = true;
25502542break ;
@@ -2556,6 +2548,7 @@ main(int argc, char *argv[])
25562548}
25572549}
25582550
2551+
25592552/* Non-option argument specifies data directory */
25602553if (optind < argc )
25612554{
@@ -2644,16 +2637,18 @@ main(int argc, char *argv[])
26442637 * Before we execute another program, make sure that we are running with a
26452638 * restricted token. If not, re-execute ourselves with one.
26462639 */
2647- if (!restricted_exec )
2640+
2641+ if ((restrict_env = getenv ("PG_RESTRICT_EXEC" ))== NULL
2642+ || strcmp (restrict_env ,"1" )!= 0 )
26482643 {
26492644PROCESS_INFORMATION pi ;
26502645char * cmdline ;
26512646
26522647ZeroMemory (& pi ,sizeof (pi ));
26532648
2654- cmdline = pg_malloc ( strlen ( GetCommandLine ()) + 19 );
2655- strcpy ( cmdline , GetCommandLine ());
2656- strcat ( cmdline , " --restrictedexec " );
2649+ cmdline = xstrdup ( GetCommandLine ());
2650+
2651+ putenv ( "PG_RESTRICT_EXEC=1 " );
26572652
26582653if (!CreateRestrictedProcess (cmdline ,& pi ))
26592654 {