diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/packaging/safer_run_as.c	Tue Sep 02 14:25:40 2014 +0200
@@ -0,0 +1,67 @@
+#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);
+    }
+}
+

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