2 * winsecur.c: implementation of winsecur.h.
10 #if !defined NO_SECURITY
12 #define WINSECUR_GLOBAL
17 static int attempted = FALSE;
18 static int successful;
19 static HMODULE advapi;
23 advapi = load_system32_dll("advapi32.dll");
24 successful = advapi &&
25 GET_WINDOWS_FUNCTION(advapi, GetSecurityInfo) &&
26 GET_WINDOWS_FUNCTION(advapi, OpenProcessToken) &&
27 GET_WINDOWS_FUNCTION(advapi, GetTokenInformation) &&
28 GET_WINDOWS_FUNCTION(advapi, InitializeSecurityDescriptor) &&
29 GET_WINDOWS_FUNCTION(advapi, SetSecurityDescriptorOwner);
34 PSID get_user_sid(void)
36 HANDLE proc = NULL, tok = NULL;
37 TOKEN_USER *user = NULL;
39 PSID sid = NULL, ret = NULL;
44 if ((proc = OpenProcess(MAXIMUM_ALLOWED, FALSE,
45 GetCurrentProcessId())) == NULL)
48 if (!p_OpenProcessToken(proc, TOKEN_QUERY, &tok))
51 if (!p_GetTokenInformation(tok, TokenUser, NULL, 0, &toklen) &&
52 GetLastError() != ERROR_INSUFFICIENT_BUFFER)
55 if ((user = (TOKEN_USER *)LocalAlloc(LPTR, toklen)) == NULL)
58 if (!p_GetTokenInformation(tok, TokenUser, user, toklen, &toklen))
61 sidlen = GetLengthSid(user->User.Sid);
63 sid = (PSID)smalloc(sidlen);
65 if (!CopySid(sidlen, sid, user->User.Sid))
68 /* Success. Move sid into the return value slot, and null it out
69 * to stop the cleanup code freeing it. */
86 #endif /* !defined NO_SECURITY */