comparison packaging/safer_run_as.c @ 1010:1c1964c27b39 runafterinstall

(issue54) commit work in progress on start after installation
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 02 Sep 2014 14:25:40 +0200
parents
children
comparison
equal deleted inserted replaced
1004:7dff5c0c569c 1010:1c1964c27b39
1 #include <windows.h>
2 #include "exdll.h"
3 #include "util.h"
4 #include "logging.h"
5
6 static HINSTANCE g_hInstance; /* Our Instance. */
7 static HWND g_hwndParent; /* Handle of parent window or NULL. */
8
9 #define UNUSED(x) (void)(x)
10
11 /* Standard entry point for DLLs. */
12 int WINAPI
13 DllMain (HANDLE hinst, DWORD reason, LPVOID reserved)
14 {
15 UNUSED(reserved);
16 if (reason == DLL_PROCESS_ATTACH)
17 g_hInstance = hinst;
18 return TRUE;
19 }
20
21 void __declspec(dllexport) __cdecl Exec(HWND hwndParent,
22 int string_size,
23 char *variables,
24 stack_t **stacktop)
25 {
26 HANDLE restricted_token = NULL;
27 STARTUPINFO si;
28 PROCESS_INFORMATION pi;
29
30 EXDLL_INIT();
31
32 UNUSED(hwndParent);
33 UNUSED(g_hwndParent);
34
35 memset(&si, 0, sizeof(STARTUPINFO));
36
37 if (!stacktop || !*stacktop || !(*stacktop)->text)
38 {
39 ERRORPRINTF ("Invalid call to exec\n");
40 return;
41 }
42
43 restricted_token = get_normal_token();
44
45 if (restricted_token == NULL || restricted_token == INVALID_HANDLE_VALUE)
46 {
47 ERRORPRINTF ("Failed to obtain restricted token.\n");
48 return;
49 }
50
51 if (CreateProcessAsUser(restricted_token,
52 0,
53 (*stacktop)->text,
54 0,
55 0,
56 FALSE,
57 CREATE_NEW_CONSOLE,
58 0,
59 0,
60 &si,
61 &pi))
62 {
63 CloseHandle(pi.hProcess);
64 CloseHandle(pi.hThread);
65 }
66 }
67

http://wald.intevation.org/projects/trustbridge/