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

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