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 145 of file restricted_token.c.

References pg_log_error, pg_strdup(), and putenv.

Referenced by main(), and regression_main().

146 {
147 #ifdef WIN32
148  HANDLE restrictedToken;
149 
150  /*
151  * Before we execute another program, make sure that we are running with a
152  * restricted token. If not, re-execute ourselves with one.
153  */
154 
155  if ((restrict_env = getenv("PG_RESTRICT_EXEC")) == NULL
156  || strcmp(restrict_env, "1") != 0)
157  {
158  PROCESS_INFORMATION pi;
159  char *cmdline;
160 
161  ZeroMemory(&pi, sizeof(pi));
162 
163  cmdline = pg_strdup(GetCommandLine());
164 
165  putenv("PG_RESTRICT_EXEC=1");
166 
167  if ((restrictedToken = CreateRestrictedProcess(cmdline, &pi)) == 0)
168  {
169  pg_log_error("could not re-execute with restricted token: error code %lu", GetLastError());
170  }
171  else
172  {
173  /*
174  * Successfully re-execed. Now wait for child process to capture
175  * exitcode.
176  */
177  DWORD x;
178 
179  CloseHandle(restrictedToken);
180  CloseHandle(pi.hThread);
181  WaitForSingleObject(pi.hProcess, INFINITE);
182 
183  if (!GetExitCodeProcess(pi.hProcess, &x))
184  {
185  pg_log_error("could not get exit code from subprocess: error code %lu", GetLastError());
186  exit(1);
187  }
188  exit(x);
189  }
190  }
191 #endif
192 }
#define pg_log_error(...)
Definition: logging.h:79
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define putenv(x)
Definition: win32_port.h:474