Skip to content

Commit 2b69571

Browse files
committed
Make restricted_exec feature for Windows more robust by using the environment to pass the flag instead of the command line - some implementations of getopt fail if getopt arguments are present after non-getopt arguments.
1 parent b5fe16d commit 2b69571

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

src/bin/initdb/initdb.c

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
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/24 00:55:49 adunstan Exp $
45+
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.112 2006/02/24 02:02:41 adunstan Exp $
4646
*
4747
*-------------------------------------------------------------------------
4848
*/
@@ -95,9 +95,6 @@ static char *authmethod = "";
9595
static bool debug = false;
9696
static bool noclean = false;
9797
static 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 */
24512445
char bin_dir[MAXPGPATH];
24522446
char *pg_data_native;
2447+
#ifdef WIN32
2448+
char *restrict_env;
2449+
#endif
24532450
static const char *subdirs[] = {
24542451
"global",
24552452
"pg_xlog",
@@ -2540,11 +2537,6 @@ main(int argc, char *argv[])
25402537
case 9:
25412538
pwfilename = xstrdup(optarg);
25422539
break;
2543-
#ifdef WIN32
2544-
case 10:
2545-
restricted_exec = true;
2546-
break;
2547-
#endif
25482540
case 's':
25492541
show_setting = true;
25502542
break;
@@ -2556,6 +2548,7 @@ main(int argc, char *argv[])
25562548
}
25572549
}
25582550

2551+
25592552
/* Non-option argument specifies data directory */
25602553
if (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
{
26492644
PROCESS_INFORMATION pi;
26502645
char *cmdline;
26512646

26522647
ZeroMemory(&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

26582653
if (!CreateRestrictedProcess(cmdline, &pi))
26592654
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy