PostgreSQL Source Code  git master
restricted_token.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void get_restricted_token (void)
 

Function Documentation

◆ get_restricted_token()

void get_restricted_token ( void  )

Definition at line 129 of file restricted_token.c.

130 {
131 #ifdef WIN32
132  HANDLE restrictedToken;
133 
134  /*
135  * Before we execute another program, make sure that we are running with a
136  * restricted token. If not, re-execute ourselves with one.
137  */
138 
139  if ((restrict_env = getenv("PG_RESTRICT_EXEC")) == NULL
140  || strcmp(restrict_env, "1") != 0)
141  {
142  PROCESS_INFORMATION pi;
143  char *cmdline;
144 
145  ZeroMemory(&pi, sizeof(pi));
146 
147  cmdline = pg_strdup(GetCommandLine());
148 
149  setenv("PG_RESTRICT_EXEC", "1", 1);
150 
151  if ((restrictedToken = CreateRestrictedProcess(cmdline, &pi)) == 0)
152  {
153  pg_log_error("could not re-execute with restricted token: error code %lu", GetLastError());
154  }
155  else
156  {
157  /*
158  * Successfully re-executed. Now wait for child process to capture
159  * the exit code.
160  */
161  DWORD x;
162 
163  CloseHandle(restrictedToken);
164  CloseHandle(pi.hThread);
165  WaitForSingleObject(pi.hProcess, INFINITE);
166 
167  if (!GetExitCodeProcess(pi.hProcess, &x))
168  pg_fatal("could not get exit code from subprocess: error code %lu", GetLastError());
169  exit(x);
170  }
171  pg_free(cmdline);
172  }
173 #endif
174 }
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
void pg_free(void *ptr)
Definition: fe_memutils.c:105
int x
Definition: isn.c:71
exit(1)
#define pg_log_error(...)
Definition: logging.h:106
#define pg_fatal(...)
#define setenv(x, y, z)
Definition: win32_port.h:534

References exit(), pg_fatal, pg_free(), pg_log_error, pg_strdup(), setenv, and x.

Referenced by main(), and regression_main().