summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaiki Ueno <dueno@redhat.com>2017-05-26 12:00:33 +0200
committerDaiki Ueno <ueno@gnu.org>2017-05-26 17:45:17 +0200
commit4de8f7a9c4f8010069402ce943e5d777cd1f3c28 (patch)
tree54d615215fc9ec7d0ed21014dcf46df708a08355
parent95b67e71e19a8415808b5ddf14f253561f11466f (diff)
rpc: Load advapi32.dll on the fly
-rw-r--r--p11-kit/Makefile.am7
-rw-r--r--p11-kit/server.c91
2 files changed, 91 insertions, 7 deletions
diff --git a/p11-kit/Makefile.am b/p11-kit/Makefile.am
index 573bf61..687223e 100644
--- a/p11-kit/Makefile.am
+++ b/p11-kit/Makefile.am
@@ -180,17 +180,10 @@ p11_kit_server_SOURCES = \
p11-kit/server.c \
$(NULL)
-if OS_WIN32
- WIN32_LIBS = -ladvapi32
-else
- WIN32_LIBS =
-endif
-
p11_kit_server_LDADD = \
libp11-tool.la \
libp11-common.la \
libp11-kit.la \
- $(WIN32_LIBS) \
$(NULL)
# Tests ----------------------------------------------------------------
diff --git a/p11-kit/server.c b/p11-kit/server.c
index 5eb5bcd..55bdc9b 100644
--- a/p11-kit/server.c
+++ b/p11-kit/server.c
@@ -694,6 +694,66 @@ main (int argc,
#include <process.h>
#include <windows.h>
+#define DYN_ADVAPI32
+
+typedef DWORD (WINAPI *GetSecurityInfoFunc)
+ (HANDLE handle,
+ SE_OBJECT_TYPE ObjectType,
+ SECURITY_INFORMATION SecurityInfo,
+ PSID *ppsidOwner,
+ PSID *ppsidGroup,
+ PACL *ppDacl,
+ PACL *ppSacl,
+ PSECURITY_DESCRIPTOR *ppSecurityDescriptor);
+typedef DWORD (WINAPI *SetSecurityInfoFunc)
+ (HANDLE handle,
+ SE_OBJECT_TYPE ObjectType,
+ SECURITY_INFORMATION SecurityInfo,
+ PSID psidOwner,
+ PSID psidGroup,
+ PACL pDacl,
+ PACL pSacl);
+typedef WINBOOL (WINAPI *OpenProcessTokenFunc)
+ (HANDLE ProcessHandle,
+ DWORD DesiredAccess,
+ PHANDLE TokenHandle);
+typedef WINBOOL (WINAPI *GetTokenInformationFunc)
+ (HANDLE TokenHandle,
+ TOKEN_INFORMATION_CLASS TokenInformationClass,
+ LPVOID TokenInformation,
+ DWORD TokenInformationLength,
+ PDWORD ReturnLength);
+typedef WINBOOL (WINAPI *InitializeSecurityDescriptorFunc)
+ (PSECURITY_DESCRIPTOR pSecurityDescriptor,
+ DWORD dwRevision);
+typedef WINBOOL (WINAPI *SetSecurityDescriptorOwnerFunc)
+ (PSECURITY_DESCRIPTOR pSecurityDescriptor,
+ PSID pOwner,
+ WINBOOL bOwnerDefaulted);
+typedef DWORD (WINAPI *SetEntriesInAclAFunc)
+ (ULONG cCountOfExplicitEntries,
+ PEXPLICIT_ACCESS_A pListOfExplicitEntries,
+ PACL OldAcl,
+ PACL *NewAcl);
+
+#ifdef DYN_ADVAPI32
+static GetSecurityInfoFunc pGetSecurityInfo;
+static SetSecurityInfoFunc pSetSecurityInfo;
+static OpenProcessTokenFunc pOpenProcessToken;
+static GetTokenInformationFunc pGetTokenInformation;
+static InitializeSecurityDescriptorFunc pInitializeSecurityDescriptor;
+static SetSecurityDescriptorOwnerFunc pSetSecurityDescriptorOwner;
+static SetEntriesInAclAFunc pSetEntriesInAclA;
+#else
+#define pGetSecurityInfo GetSecurityInfo
+#define pSetSecurityInfo SetSecurityInfo
+#define pOpenProcessToken OpenProcessToken
+#define pGetTokenInformation GetTokenInformation
+#define pInitializeSecurityDescriptor InitializeSecurityDescriptor
+#define pSetSecurityDescriptorOwner SetSecurityDescriptorOwner
+#define pSetEntriesInAclA SetEntriesInAclA
+#endif
+
#define BUFSIZE 4096
static bool quiet = false;
@@ -802,6 +862,29 @@ server_loop (Server *server)
return 0;
}
+static HMODULE advapi32_lib;
+
+static bool
+load_windows_functions (void)
+{
+ advapi32_lib = LoadLibraryA ("advapi32.dll");
+ return_val_if_fail (advapi32_lib != NULL, false);
+
+#define GET_WINDOWS_FUNCTION(func) \
+ p ## func = (func ## Func) GetProcAddress (advapi32_lib, # func); \
+ return_val_if_fail (p ## func != NULL, false)
+
+ GET_WINDOWS_FUNCTION (GetSecurityInfo);
+ GET_WINDOWS_FUNCTION (SetSecurityInfo);
+ GET_WINDOWS_FUNCTION (OpenProcessToken);
+ GET_WINDOWS_FUNCTION (GetTokenInformation);
+ GET_WINDOWS_FUNCTION (InitializeSecurityDescriptor);
+ GET_WINDOWS_FUNCTION (SetSecurityDescriptorOwner);
+ GET_WINDOWS_FUNCTION (SetEntriesInAclA);
+
+ return true;
+}
+
int
main (int argc,
char *argv[])
@@ -838,6 +921,11 @@ main (int argc,
{ 0 },
};
+ if (!load_windows_functions ()) {
+ p11_message ("couldn't initialize Windows security functions");
+ return 1;
+ }
+
while ((opt = p11_tool_getopt (argc, argv, options)) != -1) {
switch (opt) {
case opt_verbose:
@@ -894,6 +982,9 @@ main (int argc,
if (pipe_name)
free (pipe_name);
+ if (advapi32_lib)
+ FreeLibrary (advapi32_lib);
+
return ret;
}