Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

183 lines
4.4 KiB

  1. //
  2. // Copyright (C) 2000-2002, Microsoft Corporation
  3. //
  4. // File: Authzsecurity.c
  5. //
  6. // Contents: miscellaneous dfs functions.
  7. //
  8. // History: April 16 2002, Author: Rohanp
  9. //
  10. //-----------------------------------------------------------------------------
  11. #include <nt.h>
  12. #include <ntrtl.h>
  13. #include <nturtl.h>
  14. #include <windows.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <malloc.h>
  18. #include <dsgetdc.h>
  19. #include <lm.h>
  20. #include <dfsheader.h>
  21. #include <dfsmisc.h>
  22. #include <shellapi.h>
  23. #include <Aclapi.h>
  24. #include <authz.h>
  25. #include "securitylogmacros.hxx"
  26. AUTHZ_RESOURCE_MANAGER_HANDLE g_DfsAuthzResourceManager = NULL;
  27. BOOL
  28. DfsInitializeAuthz(void)
  29. {
  30. BOOL RetVal = FALSE;
  31. RetVal = AuthzInitializeResourceManager(AUTHZ_RM_FLAG_NO_AUDIT, NULL, NULL,
  32. NULL, L"DFSSECURITY",
  33. &g_DfsAuthzResourceManager);
  34. return RetVal;
  35. }
  36. BOOL
  37. DfsTerminateAuthz(void)
  38. {
  39. BOOL RetVal = FALSE;
  40. if(g_DfsAuthzResourceManager)
  41. {
  42. RetVal = AuthzFreeResourceManager(g_DfsAuthzResourceManager);
  43. g_DfsAuthzResourceManager = NULL;
  44. }
  45. return RetVal;
  46. }
  47. DWORD
  48. DfsIsAccessGrantedBySid(DWORD dwDesiredAccess,
  49. PSECURITY_DESCRIPTOR pSD,
  50. PSID TheSID,
  51. GENERIC_MAPPING * DfsGenericMapping)
  52. {
  53. DWORD Status = 0;
  54. DWORD dwError = 0;
  55. BOOL RetVal = FALSE;
  56. ACCESS_MASK GrantedMask = 0;;
  57. AUTHZ_CLIENT_CONTEXT_HANDLE AuthzCC = NULL;
  58. LUID Luid = {0, 0};
  59. AUTHZ_ACCESS_REQUEST AuthzRequest;
  60. AUTHZ_ACCESS_REPLY AuthzReply;
  61. if(g_DfsAuthzResourceManager == NULL)
  62. {
  63. Status = ERROR_INVALID_PARAMETER;
  64. goto Exit;
  65. }
  66. RetVal = AuthzInitializeContextFromSid(AUTHZ_SKIP_TOKEN_GROUPS,
  67. TheSID, g_DfsAuthzResourceManager,
  68. NULL, Luid, NULL, &AuthzCC);
  69. if(RetVal == FALSE)
  70. {
  71. Status = GetLastError();
  72. goto Exit;
  73. }
  74. MapGenericMask(&dwDesiredAccess, DfsGenericMapping);
  75. ZeroMemory((void *) &AuthzRequest, sizeof(AuthzRequest));
  76. AuthzRequest.DesiredAccess = dwDesiredAccess;
  77. ZeroMemory((void *) &AuthzReply, sizeof(AuthzReply));
  78. AuthzReply.ResultListLength = 1;
  79. AuthzReply.GrantedAccessMask = &GrantedMask;
  80. AuthzReply.Error = &dwError;
  81. RetVal = AuthzAccessCheck (0, AuthzCC, &AuthzRequest, NULL,
  82. pSD, NULL, 0, &AuthzReply, 0);
  83. if(RetVal == FALSE)
  84. {
  85. Status = GetLastError();
  86. goto Exit;
  87. }
  88. Status = dwError;
  89. Exit:
  90. if(AuthzCC)
  91. {
  92. AuthzFreeContext(AuthzCC);
  93. }
  94. return Status;
  95. }
  96. DWORD
  97. DfsIsAccessGrantedByToken(DWORD dwDesiredAccess,
  98. PSECURITY_DESCRIPTOR pSD,
  99. HANDLE TheToken,
  100. GENERIC_MAPPING * DfsGenericMapping)
  101. {
  102. DWORD Status = 0;
  103. DWORD dwError = 0;
  104. BOOL RetVal = FALSE;
  105. ACCESS_MASK GrantedMask = 0;;
  106. AUTHZ_CLIENT_CONTEXT_HANDLE AuthzCC = NULL;
  107. LUID Luid = {0, 0};
  108. AUTHZ_ACCESS_REQUEST AuthzRequest;
  109. AUTHZ_ACCESS_REPLY AuthzReply;
  110. if(g_DfsAuthzResourceManager == NULL)
  111. {
  112. Status = ERROR_INVALID_PARAMETER;
  113. goto Exit;
  114. }
  115. RetVal = AuthzInitializeContextFromToken(AUTHZ_SKIP_TOKEN_GROUPS,
  116. TheToken, g_DfsAuthzResourceManager,
  117. NULL, Luid, NULL, &AuthzCC);
  118. if(RetVal == FALSE)
  119. {
  120. Status = GetLastError();
  121. goto Exit;
  122. }
  123. MapGenericMask(&dwDesiredAccess, DfsGenericMapping);
  124. ZeroMemory((void *) &AuthzRequest, sizeof(AuthzRequest));
  125. AuthzRequest.DesiredAccess = dwDesiredAccess;
  126. ZeroMemory((void *) &AuthzReply, sizeof(AuthzReply));
  127. AuthzReply.ResultListLength = 1;
  128. AuthzReply.GrantedAccessMask = &GrantedMask;
  129. AuthzReply.Error = &dwError;
  130. RetVal = AuthzAccessCheck (0, AuthzCC, &AuthzRequest, NULL,
  131. pSD, NULL, 0, &AuthzReply, 0);
  132. if(RetVal == FALSE)
  133. {
  134. Status = GetLastError();
  135. goto Exit;
  136. }
  137. Status = dwError;
  138. Exit:
  139. if(AuthzCC)
  140. {
  141. AuthzFreeContext(AuthzCC);
  142. }
  143. return Status;
  144. }