Mercurial > trustbridge
view packaging/safer_run_as.c @ 1143:cc7a5c12a429 runafterinstall
Runafterinstall has been merged into master
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Thu, 18 Sep 2014 10:30:27 +0200 |
parents | 1c1964c27b39 |
children |
line wrap: on
line source
#include <windows.h> #include "exdll.h" #include "util.h" #include "logging.h" static HINSTANCE g_hInstance; /* Our Instance. */ static HWND g_hwndParent; /* Handle of parent window or NULL. */ #define UNUSED(x) (void)(x) /* Standard entry point for DLLs. */ int WINAPI DllMain (HANDLE hinst, DWORD reason, LPVOID reserved) { UNUSED(reserved); if (reason == DLL_PROCESS_ATTACH) g_hInstance = hinst; return TRUE; } void __declspec(dllexport) __cdecl Exec(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) { HANDLE restricted_token = NULL; STARTUPINFO si; PROCESS_INFORMATION pi; EXDLL_INIT(); UNUSED(hwndParent); UNUSED(g_hwndParent); memset(&si, 0, sizeof(STARTUPINFO)); if (!stacktop || !*stacktop || !(*stacktop)->text) { ERRORPRINTF ("Invalid call to exec\n"); return; } restricted_token = get_normal_token(); if (restricted_token == NULL || restricted_token == INVALID_HANDLE_VALUE) { ERRORPRINTF ("Failed to obtain restricted token.\n"); return; } if (CreateProcessAsUser(restricted_token, 0, (*stacktop)->text, 0, 0, FALSE, CREATE_NEW_CONSOLE, 0, 0, &si, &pi)) { CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } }