Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2b69571

Browse files
committed
Make restricted_exec feature for Windows more robust by using the environmentto pass the flag instead of the command line - some implementations ofgetopt fail if getopt arguments are present after non-getopt arguments.
1 parentb5fe16d commit2b69571

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/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 = "";
9595
staticbooldebug= false;
9696
staticboolnoclean= false;
9797
staticboolshow_setting= false;
98-
#ifdefWIN32
99-
staticboolrestricted_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-
#ifdefWIN32
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
charbin_dir[MAXPGPATH];
24522446
char*pg_data_native;
2447+
#ifdefWIN32
2448+
char*restrict_env;
2449+
#endif
24532450
staticconstchar*subdirs[]= {
24542451
"global",
24552452
"pg_xlog",
@@ -2540,11 +2537,6 @@ main(int argc, char *argv[])
25402537
case9:
25412538
pwfilename=xstrdup(optarg);
25422539
break;
2543-
#ifdefWIN32
2544-
case10:
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_INFORMATIONpi;
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)

[8]ページ先頭

©2009-2025 Movatter.jp