PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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 (const char *progname)
 

Function Documentation

void get_restricted_token ( const char *  progname)

Definition at line 146 of file restricted_token.c.

References _, NULL, pg_strdup(), and putenv.

Referenced by main().

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