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

155 {
156 #ifdef WIN32
157  HANDLE restrictedToken;
158 
159  /*
160  * Before we execute another program, make sure that we are running with a
161  * restricted token. If not, re-execute ourselves with one.
162  */
163 
164  if ((restrict_env = getenv("PG_RESTRICT_EXEC")) == NULL
165  || strcmp(restrict_env, "1") != 0)
166  {
167  PROCESS_INFORMATION pi;
168  char *cmdline;
169 
170  ZeroMemory(&pi, sizeof(pi));
171 
172  cmdline = pg_strdup(GetCommandLine());
173 
174  setenv("PG_RESTRICT_EXEC", "1", 1);
175 
176  if ((restrictedToken = CreateRestrictedProcess(cmdline, &pi)) == 0)
177  {
178  pg_log_error("could not re-execute with restricted token: error code %lu", GetLastError());
179  }
180  else
181  {
182  /*
183  * Successfully re-executed. Now wait for child process to capture
184  * the exit code.
185  */
186  DWORD x;
187 
188  CloseHandle(restrictedToken);
189  CloseHandle(pi.hThread);
190  WaitForSingleObject(pi.hProcess, INFINITE);
191 
192  if (!GetExitCodeProcess(pi.hProcess, &x))
193  pg_fatal("could not get exit code from subprocess: error code %lu", GetLastError());
194  exit(x);
195  }
196  pg_free(cmdline);
197  }
198 #endif
199 }
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:507

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

Referenced by main(), and regression_main().