ReactOS  0.4.15-dev-976-g0f66c66
resman.c File Reference
#include "precomp.h"
#include <debug.h>
Include dependency graph for resman.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

static BOOL AuthzpQueryToken (IN OUT PAUTHZ_RESMAN ResMan, IN HANDLE hToken)
 
static BOOL AuthzpInitUnderImpersonation (IN OUT PAUTHZ_RESMAN ResMan)
 
static BOOL AuthzpInitSelf (IN OUT PAUTHZ_RESMAN ResMan)
 
AUTHZAPI BOOL WINAPI AuthzInitializeResourceManager (IN DWORD flags, IN PFN_AUTHZ_DYNAMIC_ACCESS_CHECK pfnAccessCheck OPTIONAL, IN PFN_AUTHZ_COMPUTE_DYNAMIC_GROUPS pfnComputeDynamicGroups OPTIONAL, IN PFN_AUTHZ_FREE_DYNAMIC_GROUPS pfnFreeDynamicGroups OPTIONAL, IN PCWSTR ResourceManagerName OPTIONAL, IN PAUTHZ_RESOURCE_MANAGER_HANDLE pAuthzResourceManager)
 
AUTHZAPI BOOL WINAPI AuthzFreeResourceManager (IN AUTHZ_RESOURCE_MANAGER_HANDLE AuthzResourceManager)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 31 of file resman.c.

Function Documentation

◆ AuthzFreeResourceManager()

AUTHZAPI BOOL WINAPI AuthzFreeResourceManager ( IN AUTHZ_RESOURCE_MANAGER_HANDLE  AuthzResourceManager)

Definition at line 229 of file resman.c.

230 {
231  BOOL Ret = FALSE;
232 
233  if (AuthzResourceManager != NULL)
234  {
235  PAUTHZ_RESMAN ResMan = (PAUTHZ_RESMAN)AuthzResourceManager;
236 
237  VALIDATE_RESMAN_HANDLE(AuthzResourceManager);
238 
239  if (!(ResMan->flags & AUTHZ_RM_FLAG_NO_AUDIT))
240  {
241  /* FIXME - cleanup auditing */
242  }
243 
244  if (ResMan->UserSid != NULL)
245  {
246  LocalFree((HLOCAL)ResMan->UserSid);
247  }
248 
249  LocalFree((HLOCAL)AuthzResourceManager);
250  Ret = TRUE;
251  }
252  else
254 
255  return Ret;
256 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define TRUE
Definition: types.h:120
DWORD flags
Definition: precomp.h:41
PSID UserSid
Definition: precomp.h:42
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
#define VALIDATE_RESMAN_HANDLE(handle)
Definition: precomp.h:26
#define SetLastError(x)
Definition: compat.h:500
struct _AUTHZ_RESMAN * PAUTHZ_RESMAN
#define AUTHZ_RM_FLAG_NO_AUDIT
Definition: authz.h:42
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577

◆ AuthzInitializeResourceManager()

AUTHZAPI BOOL WINAPI AuthzInitializeResourceManager ( IN DWORD  flags,
IN PFN_AUTHZ_DYNAMIC_ACCESS_CHECK pfnAccessCheck  OPTIONAL,
IN PFN_AUTHZ_COMPUTE_DYNAMIC_GROUPS pfnComputeDynamicGroups  OPTIONAL,
IN PFN_AUTHZ_FREE_DYNAMIC_GROUPS pfnFreeDynamicGroups  OPTIONAL,
IN PCWSTR ResourceManagerName  OPTIONAL,
IN PAUTHZ_RESOURCE_MANAGER_HANDLE  pAuthzResourceManager 
)

Definition at line 145 of file resman.c.

151 {
152  BOOL Ret = FALSE;
153 
154  if (pAuthzResourceManager != NULL &&
156  {
157  PAUTHZ_RESMAN ResMan;
158  SIZE_T RequiredSize = sizeof(AUTHZ_RESMAN);
159 
160  if (ResourceManagerName != NULL)
161  {
162  RequiredSize += wcslen(ResourceManagerName) * sizeof(WCHAR);
163  }
164 
166  RequiredSize);
167  if (ResMan != NULL)
168  {
169  /* initialize the resource manager structure */
170 #if DBG
171  ResMan->Tag = RESMAN_TAG;
172 #endif
173 
174  ResMan->flags = flags;
175  ResMan->UserSid = NULL;
176 
177  if (ResourceManagerName != NULL)
178  {
179  wcscpy(ResMan->ResourceManagerName,
180  ResourceManagerName);
181  }
182  else
183  ResMan->ResourceManagerName[0] = UNICODE_NULL;
184 
185  ResMan->pfnAccessCheck = pfnAccessCheck;
186  ResMan->pfnComputeDynamicGroups = pfnComputeDynamicGroups;
187  ResMan->pfnFreeDynamicGroups = pfnFreeDynamicGroups;
188 
189  if (!(flags & AUTHZ_RM_FLAG_NO_AUDIT))
190  {
191  /* FIXME - initialize auditing */
192  DPRINT1("Auditing not implemented!\n");
193  }
194 
196  {
197  Ret = AuthzpInitUnderImpersonation(ResMan);
198  }
199  else
200  {
201  Ret = AuthzpInitSelf(ResMan);
202  }
203 
204  if (Ret)
205  {
206  /* finally return the handle */
207  *pAuthzResourceManager = (AUTHZ_RESOURCE_MANAGER_HANDLE)ResMan;
208  }
209  else
210  {
211  DPRINT1("Querying the token failed!\n");
212  LocalFree((HLOCAL)ResMan);
213  }
214  }
215  }
216  else
218 
219  return Ret;
220 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
PFN_AUTHZ_FREE_DYNAMIC_GROUPS pfnFreeDynamicGroups
Definition: precomp.h:39
DWORD flags
Definition: precomp.h:41
_Inout_ PRTL_BUFFER _In_ SIZE_T RequiredSize
struct _AUTHZ_RESMAN AUTHZ_RESMAN
PSID UserSid
Definition: precomp.h:42
WCHAR ResourceManagerName[1]
Definition: precomp.h:45
#define FALSE
Definition: types.h:117
#define UNICODE_NULL
unsigned int BOOL
Definition: ntddk_ex.h:94
HANDLE AUTHZ_RESOURCE_MANAGER_HANDLE
Definition: authz.h:50
smooth NULL
Definition: ftsmooth.c:416
static BOOL AuthzpInitSelf(IN OUT PAUTHZ_RESMAN ResMan)
Definition: resman.c:120
PFN_AUTHZ_DYNAMIC_ACCESS_CHECK pfnAccessCheck
Definition: precomp.h:37
#define LMEM_FIXED
Definition: winbase.h:349
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define SetLastError(x)
Definition: compat.h:500
GLbitfield flags
Definition: glext.h:7161
struct _AUTHZ_RESMAN * PAUTHZ_RESMAN
#define AUTHZ_RM_FLAG_INITIALIZE_UNDER_IMPERSONATION
Definition: authz.h:43
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
PFN_AUTHZ_COMPUTE_DYNAMIC_GROUPS pfnComputeDynamicGroups
Definition: precomp.h:38
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define AUTHZ_RM_FLAG_NO_AUDIT
Definition: authz.h:42
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
static BOOL AuthzpInitUnderImpersonation(IN OUT PAUTHZ_RESMAN ResMan)
Definition: resman.c:100
#define DPRINT1
Definition: precomp.h:8
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

◆ AuthzpInitSelf()

static BOOL AuthzpInitSelf ( IN OUT PAUTHZ_RESMAN  ResMan)
static

Definition at line 120 of file resman.c.

121 {
122  HANDLE hToken;
123  BOOL Ret;
124 
126  TOKEN_QUERY,
127  &hToken);
128  if (Ret)
129  {
130  Ret = AuthzpQueryToken(ResMan,
131  hToken);
132  CloseHandle(hToken);
133  }
134 
135  return Ret;
136 }
#define CloseHandle
Definition: compat.h:487
unsigned int BOOL
Definition: ntddk_ex.h:94
#define TOKEN_QUERY
Definition: setypes.h:874
#define GetCurrentProcess()
Definition: compat.h:507
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:296
static BOOL AuthzpQueryToken(IN OUT PAUTHZ_RESMAN ResMan, IN HANDLE hToken)
Definition: resman.c:35

Referenced by AuthzInitializeResourceManager().

◆ AuthzpInitUnderImpersonation()

static BOOL AuthzpInitUnderImpersonation ( IN OUT PAUTHZ_RESMAN  ResMan)
static

Definition at line 100 of file resman.c.

101 {
102  HANDLE hToken;
103  BOOL Ret;
104 
106  TOKEN_QUERY,
107  TRUE,
108  &hToken);
109  if (Ret)
110  {
111  Ret = AuthzpQueryToken(ResMan,
112  hToken);
113  CloseHandle(hToken);
114  }
115 
116  return Ret;
117 }
#define CloseHandle
Definition: compat.h:487
#define TRUE
Definition: types.h:120
HANDLE WINAPI GetCurrentThread(VOID)
Definition: proc.c:1148
unsigned int BOOL
Definition: ntddk_ex.h:94
#define TOKEN_QUERY
Definition: setypes.h:874
BOOL WINAPI OpenThreadToken(HANDLE ThreadHandle, DWORD DesiredAccess, BOOL OpenAsSelf, HANDLE *TokenHandle)
Definition: security.c:338
static BOOL AuthzpQueryToken(IN OUT PAUTHZ_RESMAN ResMan, IN HANDLE hToken)
Definition: resman.c:35

Referenced by AuthzInitializeResourceManager().

◆ AuthzpQueryToken()

static BOOL AuthzpQueryToken ( IN OUT PAUTHZ_RESMAN  ResMan,
IN HANDLE  hToken 
)
static

Definition at line 35 of file resman.c.

37 {
38  TOKEN_USER User;
39  TOKEN_STATISTICS Statistics;
40  DWORD BufLen;
41  PSID UserSid = NULL;
42  BOOL Ret = FALSE;
43 
44  /* query information about the user */
45  BufLen = sizeof(User);
46  Ret = GetTokenInformation(hToken,
47  TokenUser,
48  &User,
49  BufLen,
50  &BufLen);
51  if (Ret)
52  {
53  BufLen = GetLengthSid(User.User.Sid);
54  if (BufLen != 0)
55  {
56  UserSid = (PSID)LocalAlloc(LMEM_FIXED,
57  BufLen);
58  if (UserSid != NULL)
59  {
60  CopyMemory(UserSid,
61  User.User.Sid,
62  BufLen);
63  }
64  else
65  Ret = FALSE;
66  }
67  else
68  Ret = FALSE;
69  }
70 
71  if (Ret)
72  {
73  /* query general information */
74  BufLen = sizeof(Statistics);
75  Ret = GetTokenInformation(hToken,
76  TokenUser,
77  &Statistics,
78  BufLen,
79  &BufLen);
80  }
81 
82  if (Ret)
83  {
84  ResMan->UserSid = UserSid;
85  ResMan->AuthenticationId = Statistics.AuthenticationId;
86  Ret = TRUE;
87  }
88  else
89  {
90  if (UserSid != NULL)
91  {
92  LocalFree((HLOCAL)UserSid);
93  }
94  }
95 
96  return Ret;
97 }
LUID AuthenticationId
Definition: setypes.h:1033
#define BufLen
Definition: fatfs.h:167
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
#define LMEM_FIXED
Definition: winbase.h:349
DWORD WINAPI GetLengthSid(PSID pSid)
Definition: security.c:798
#define CopyMemory
Definition: winbase.h:1646
unsigned long DWORD
Definition: ntddk_ex.h:95
struct _SID * PSID
Definition: eventlog.c:35
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
BOOL WINAPI GetTokenInformation(HANDLE TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass, LPVOID TokenInformation, DWORD TokenInformationLength, PDWORD ReturnLength)
Definition: security.c:413
SID_AND_ATTRIBUTES User
Definition: setypes.h:956
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373

Referenced by AuthzpInitSelf(), and AuthzpInitUnderImpersonation().