Source code of Windows XP (NT5)
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.

400 lines
15 KiB

  1. //*************************************************************
  2. //
  3. // Policy specific headers
  4. //
  5. // Microsoft Confidential
  6. // Copyright (c) Microsoft Corporation 1997-1998
  7. // All rights reserved
  8. //
  9. //*************************************************************
  10. #include "uenv.h"
  11. #include "reghash.h"
  12. #include "rsop.h"
  13. #include "chkacc.h"
  14. #include "collect.h"
  15. #include "Indicate.h"
  16. #include "rsopsec.h"
  17. #include "gpfilter.h"
  18. #include "locator.h"
  19. #include "rsopinc.h"
  20. #define GPO_LPARAM_FLAG_DELETE 0x00000001
  21. //
  22. // Structures
  23. //
  24. typedef struct _GPINFOHANDLE
  25. {
  26. LPGPOINFO pGPOInfo;
  27. } GPINFOHANDLE, *LPGPINFOHANDLE;
  28. typedef struct _DNENTRY {
  29. LPTSTR pwszDN; // Distinguished name
  30. union {
  31. PGROUP_POLICY_OBJECT pDeferredGPO; // GPO corresponding to this DN
  32. struct _DNENTRY * pDeferredOU; // OU correspdonding to this DN
  33. };
  34. PLDAPMessage pOUMsg; // Message for evaluating deferred OU
  35. GPO_LINK gpoLink; // Type of GPO
  36. struct _DNENTRY * pNext; // Singly linked list pointer
  37. } DNENTRY;
  38. typedef struct _LDAPQUERY {
  39. LPTSTR pwszDomain; // Domain of subtree search
  40. LPTSTR pwszFilter; // Ldap filter for search
  41. DWORD cbAllocLen; // Allocated size of pwszFilter in bytes
  42. DWORD cbLen; // Size of pwszFilter currently used in bytes
  43. PLDAP pLdapHandle; // Ldap bind handle
  44. BOOL bOwnLdapHandle; // Does this struct own pLdapHandle ?
  45. PLDAPMessage pMessage; // Ldap message handle
  46. DNENTRY * pDnEntry; // Distinguished name entry
  47. struct _LDAPQUERY * pNext; // Singly linked list pointer
  48. } LDAPQUERY;
  49. typedef struct _POLICYCHANGEDINFO {
  50. HANDLE hToken;
  51. BOOL bMachine;
  52. } POLICYCHANGEDINFO, *LPPOLICYCHANGEDINFO;
  53. //
  54. // Verison number for the registry file format
  55. //
  56. #define REGISTRY_FILE_VERSION 1
  57. //
  58. // File signature
  59. //
  60. #define REGFILE_SIGNATURE 0x67655250
  61. //
  62. // Default refresh rate (minutes)
  63. //
  64. // Client machines will refresh every 90 minutes
  65. // Domain controllers will refresh every 5 minutes
  66. //
  67. #define GP_DEFAULT_REFRESH_RATE 90
  68. #define GP_DEFAULT_REFRESH_RATE_DC 5
  69. //
  70. // Default refresh rate max offset
  71. //
  72. // To prevent many clients from querying policy at the exact same
  73. // time, a random amount is added to the refresh rate. In the
  74. // default case, a number between 0 and 30 will be added to
  75. // 180 to determine when the next background refresh will occur
  76. //
  77. #define GP_DEFAULT_REFRESH_RATE_OFFSET 30
  78. #define GP_DEFAULT_REFRESH_RATE_OFFSET_DC 0
  79. //
  80. // Max keyname size
  81. //
  82. #define MAX_KEYNAME_SIZE 2048
  83. #define MAX_VALUENAME_SIZE 512
  84. //
  85. // Max time to wait for the network to start (in ms)
  86. //
  87. #define MAX_WAIT_TIME 120000
  88. //
  89. // Extension registry path
  90. //
  91. #define GP_EXTENSIONS TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\GPExtensions")
  92. //
  93. // Path for extension preference policies
  94. //
  95. #define GP_EXTENSIONS_POLICIES TEXT("Software\\Policies\\Microsoft\\Windows\\Group Policy\\%s")
  96. //
  97. // Group Policy Object option flags
  98. //
  99. // Note, this was taken from sdk\inc\gpedit.h
  100. //
  101. #define GPO_OPTION_DISABLE_USER 0x00000001 // The user portion of this GPO is disabled
  102. #define GPO_OPTION_DISABLE_MACHINE 0x00000002 // The machine portion of this GPO is disabled
  103. //
  104. // DS Object class types
  105. //
  106. extern TCHAR szDSClassAny[];
  107. extern TCHAR szDSClassGPO[];
  108. extern TCHAR szDSClassSite[];
  109. extern TCHAR szDSClassDomain[];
  110. extern TCHAR szDSClassOU[];
  111. extern TCHAR szObjectClass[];
  112. //
  113. // Extension name properties
  114. //
  115. #define GPO_MACHEXTENSION_NAMES L"gPCMachineExtensionNames"
  116. #define GPO_USEREXTENSION_NAMES L"gPCUserExtensionNames"
  117. #define GPO_FUNCTIONALITY_VERSION L"gPCFunctionalityVersion"
  118. #define MACHPOLICY_DENY_USERS L"DenyUsersFromMachGP"
  119. extern TCHAR wszKerberos[];
  120. #define POLICY_GUID_PATH TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\PolicyGuid")
  121. //
  122. // Global flags for Gpo shutdown processing. These are accessed outside
  123. // the lock because its value is either 0 or 1. Even if there is a race,
  124. // all it means is that shutdown will start one iteration later.
  125. //
  126. extern BOOL g_bStopMachGPOProcessing;
  127. extern BOOL g_bStopUserGPOProcessing;
  128. //
  129. // Critical section for handling concurrent, asynchronous completion
  130. //
  131. extern CRITICAL_SECTION g_GPOCS;
  132. //
  133. // Global pointers for maintaining asynchronous completion context
  134. //
  135. extern LPGPINFOHANDLE g_pMachGPInfo;
  136. extern LPGPINFOHANDLE g_pUserGPInfo;
  137. //
  138. // Status UI critical section, callback, and proto-types
  139. //
  140. extern CRITICAL_SECTION g_StatusCallbackCS;
  141. extern PFNSTATUSMESSAGECALLBACK g_pStatusMessageCallback;
  142. DWORD UserPolicyCallback (BOOL bVerbose, LPWSTR lpMessage);
  143. DWORD MachinePolicyCallback (BOOL bVerbose, LPWSTR lpMessage);
  144. //
  145. // Function proto-types
  146. //
  147. DWORD WINAPI GPOThread (LPGPOINFO lpGPOInfo);
  148. extern "C" BOOL ProcessGPOs (LPGPOINFO lpGPOInfo);
  149. DWORD WINAPI PolicyChangedThread (LPPOLICYCHANGEDINFO lpPolicyChangedInfo);
  150. BOOL ResetPolicies (LPGPOINFO lpGPOInfo, LPTSTR lpArchive);
  151. BOOL SetupGPOFilter (LPGPOINFO lpGPOInfo );
  152. void FilterGPOs( LPGPEXT lpExt, LPGPOINFO lpGPOInfo );
  153. void FreeLists( LPGPOINFO lpGPOInfo );
  154. void FreeExtList(LPEXTLIST pExtList );
  155. BOOL CheckGPOs (LPGPEXT lpExt, LPGPOINFO lpGPOInfo, DWORD dwTime, BOOL *pbProcessGPOs,
  156. BOOL *pbNoChanges, PGROUP_POLICY_OBJECT *ppDeletedGPOList);
  157. BOOL CheckForChangedSid( LPGPOINFO lpGPOInfo, CLocator *plocator );
  158. BOOL CheckForSkippedExtensions( LPGPOINFO lpGPOInfo, BOOL bRsopPlanningMode );
  159. BOOL ReadGPExtensions( LPGPOINFO lpGPOInfo );
  160. BOOL LoadGPExtension (LPGPEXT lpExt, BOOL bRsopPlanningMode );
  161. BOOL UnloadGPExtensions (LPGPOINFO lpGPOInfo);
  162. BOOL WriteStatus( TCHAR *lpExtName, LPGPOINFO lpGPOInfo, LPTSTR lpwszSidUser, LPGPEXTSTATUS lpExtStatus );
  163. void ReadStatus ( TCHAR *lpExtName, LPGPOINFO lpGPOInfo, LPTSTR lpwszSidUser, LPGPEXTSTATUS lpExtStatus );
  164. DWORD ProcessGPOList (LPGPEXT lpExt, LPGPOINFO lpGPOInfo, PGROUP_POLICY_OBJECT pDeletedGPOList,
  165. PGROUP_POLICY_OBJECT pChangedGPOList, BOOL bNoChanges,
  166. ASYNCCOMPLETIONHANDLE pAsyncHandle, HRESULT *phrCSERsopStatus );
  167. BOOL ProcessGPORegistryPolicy (LPGPOINFO lpGPOInfo, PGROUP_POLICY_OBJECT pChangedGPOList, HRESULT *phrRsopLogging);
  168. BOOL SaveGPOList (TCHAR *pszExtName, LPGPOINFO lpGPOInfo,
  169. HKEY hKeyRootMach, LPTSTR lpwszSidUser, BOOL bShadow, PGROUP_POLICY_OBJECT lpGPOList);
  170. BOOL AddGPO (PGROUP_POLICY_OBJECT * lpGPOList,
  171. DWORD dwFlags, BOOL bFound, BOOL bAccessGranted, BOOL bDisabled, DWORD dwOptions,
  172. DWORD dwVersion, LPTSTR lpDSPath, LPTSTR lpFileSysPath,
  173. LPTSTR lpDisplayName, LPTSTR lpGPOName, LPTSTR lpExtensions,
  174. PSECURITY_DESCRIPTOR pSD, DWORD cbSDLen,
  175. GPO_LINK GPOLink, LPTSTR lpLink,
  176. LPARAM lParam, BOOL bFront, BOOL bBlock, BOOL bVerbose, BOOL bProcessGPO);
  177. BOOL RefreshDisplay (LPGPOINFO lpGPOInfo);
  178. extern "C" DWORD IsSlowLink (HKEY hKeyRoot, LPTSTR lpDCAddress, BOOL *bSlow, DWORD* pdwAdapterIndex );
  179. BOOL GetGPOInfo (DWORD dwFlags, LPTSTR lpHostName, LPTSTR lpDNName,
  180. LPCTSTR lpComputerName, PGROUP_POLICY_OBJECT *lpGPOList,
  181. LPSCOPEOFMGMT *ppSOMList, LPGPCONTAINER *ppGpContainerList,
  182. PNETAPI32_API pNetAPI32, BOOL bMachineTokenOk, PRSOPTOKEN pRsopToken, WCHAR *pwszSiteName,
  183. CGpoFilter *pGpoFilter, CLocator *pLocator );
  184. void WINAPI ShutdownGPOProcessing( BOOL bMachine );
  185. void DebugPrintGPOList( LPGPOINFO lpGPOInfo );
  186. typedef BOOL (*PFNREGFILECALLBACK)(LPGPOINFO lpGPOInfo, LPTSTR lpKeyName,
  187. LPTSTR lpValueName, DWORD dwType,
  188. DWORD dwDataLength, LPBYTE lpData,
  189. WCHAR *pwszGPO,
  190. WCHAR *pwszSOM, REGHASHTABLE *pHashTable);
  191. BOOL ParseRegistryFile (LPGPOINFO lpGPOInfo, LPTSTR lpRegistry,
  192. PFNREGFILECALLBACK pfnRegFileCallback,
  193. HANDLE hArchive, WCHAR *pwszGPO,
  194. WCHAR *pwszSOM, REGHASHTABLE *pHashTable,
  195. BOOL bRsopPlanningMode);
  196. BOOL ExtensionHasPerUserLocalSetting( LPTSTR pszExtension, HKEY hKeyRoot );
  197. void CheckGroupMembership( LPGPOINFO lpGPOInfo, HANDLE hToken, BOOL *pbMemChanged, BOOL *pbUserLocalMemChanged, PTOKEN_GROUPS *pTokenGroups );
  198. BOOL ReadMembershipList( LPGPOINFO lpGPOInfo, LPTSTR lpwszSidUser, PTOKEN_GROUPS pGroups );
  199. void SaveMembershipList( LPGPOINFO lpGPOInfo, LPTSTR lpwszSidUser, PTOKEN_GROUPS pGroups );
  200. BOOL GroupInList( LPTSTR lpSid, PTOKEN_GROUPS pGroups );
  201. DWORD GetCurTime();
  202. extern "C" DWORD GetDomainControllerInfo( PNETAPI32_API pNetAPI32, LPTSTR szDomainName,
  203. ULONG ulFlags, HKEY hKeyRoot, PDOMAIN_CONTROLLER_INFO* ppInfo,
  204. BOOL* pfSlow,
  205. DWORD* pdwAdapterIndex );
  206. PLDAP GetMachineDomainDS( PNETAPI32_API pNetApi32, PLDAP_API pLdapApi );
  207. extern "C" HANDLE GetMachineToken();
  208. NTSTATUS CallDFS(LPWSTR lpDomainName, LPWSTR lpDCName);
  209. BOOL AddLocalGPO( LPSCOPEOFMGMT *ppSOMList );
  210. BOOL AddGPOToRsopList( LPGPCONTAINER *ppGpContainerList,
  211. DWORD dwFlags,
  212. BOOL bFound,
  213. BOOL bAccessGranted,
  214. BOOL bDisabled,
  215. DWORD dwVersion,
  216. LPTSTR lpDSPath,
  217. LPTSTR lpFileSysPath,
  218. LPTSTR lpDisplayName,
  219. LPTSTR lpGPOName,
  220. PSECURITY_DESCRIPTOR pSD,
  221. DWORD cbSDLen,
  222. BOOL bFilterAllowed,
  223. WCHAR *pwszFilterId,
  224. LPWSTR szSOM,
  225. DWORD dwGPOOptions );
  226. SCOPEOFMGMT *AllocSOM( LPWSTR pwszSOMId );
  227. void FreeSOM( SCOPEOFMGMT *pSOM );
  228. GPLINK *AllocGpLink( LPWSTR pwszGPO, DWORD dwOptions );
  229. void FreeGpLink( GPLINK *pGpLink );
  230. GPCONTAINER *AllocGpContainer( DWORD dwFlags,
  231. BOOL bFound,
  232. BOOL bAccessGranted,
  233. BOOL bDisabled,
  234. DWORD dwVersion,
  235. LPTSTR lpDSPath,
  236. LPTSTR lpFileSysPath,
  237. LPTSTR lpDisplayName,
  238. LPTSTR lpGpoName,
  239. PSECURITY_DESCRIPTOR pSD,
  240. DWORD cbSDLen,
  241. BOOL bFilterAllowed,
  242. WCHAR *pwszFilterId,
  243. LPWSTR szSOM,
  244. DWORD dwOptions );
  245. void FreeGpContainer( GPCONTAINER *pGpContainer );
  246. void FreeSOMList( SCOPEOFMGMT *pSOMList );
  247. void FreeGpContainerList( GPCONTAINER *pGpContainerList );
  248. LONG GPOExceptionFilter( PEXCEPTION_POINTERS pExceptionPtrs );
  249. BOOL FreeGpoInfo( LPGPOINFO pGpoInfo );
  250. BOOL ReadExtStatus(LPGPOINFO lpGPOInfo);
  251. BOOL ReadGPOList ( TCHAR * pszExtName, HKEY hKeyRoot,
  252. HKEY hKeyRootMach, LPTSTR lpwszSidUser, BOOL bShadow,
  253. PGROUP_POLICY_OBJECT * lpGPOList);
  254. BOOL GetDeletedGPOList (PGROUP_POLICY_OBJECT lpGPOList,
  255. PGROUP_POLICY_OBJECT *ppDeletedGPOList);
  256. BOOL HistoryPresent( LPGPOINFO lpGPOInfo, LPGPEXT lpExt );
  257. extern "C" BOOL InitializePolicyProcessing(BOOL bMachine);
  258. BOOL FilterCheck( PLDAP pld, PLDAP_API pLDAP,
  259. PLDAPMessage pMessage,
  260. PRSOPTOKEN pRsopToken,
  261. LPTSTR szWmiFilter,
  262. CGpoFilter *pGpoFilter,
  263. CLocator *pLocator,
  264. BOOL *pbFilterAllowed,
  265. WCHAR **ppwszFilterId );
  266. BOOL CheckGPOAccess (PLDAP pld, PLDAP_API pLDAP, HANDLE hToken, PLDAPMessage pMessage,
  267. LPTSTR lpSDProperty, DWORD dwFlags,
  268. PSECURITY_DESCRIPTOR *ppSD, DWORD *pcbSDLen,
  269. BOOL *pbAccessGranted,
  270. PRSOPTOKEN pRsopToken );
  271. BOOL AddOU( DNENTRY **ppOUList, LPTSTR pwszOU, GPO_LINK gpoLink );
  272. BOOL EvaluateDeferredGPOs (PLDAP pldBound,
  273. PLDAP_API pLDAP,
  274. LPTSTR pwszDomainBound,
  275. DWORD dwFlags,
  276. HANDLE hToken,
  277. BOOL bVerbose,
  278. PGROUP_POLICY_OBJECT pDeferredForcedList,
  279. PGROUP_POLICY_OBJECT pDeferredNonForcedList,
  280. PGROUP_POLICY_OBJECT *ppForcedList,
  281. PGROUP_POLICY_OBJECT *ppNonForcedList,
  282. LPGPCONTAINER *ppGpContainerList,
  283. PRSOPTOKEN pRsopToken,
  284. CGpoFilter *pGpoFilter,
  285. CLocator *pLocator );
  286. BOOL SearchDSObject (LPTSTR lpDSObject, DWORD dwFlags, HANDLE hToken, PGROUP_POLICY_OBJECT *pGPOForcedList,
  287. PGROUP_POLICY_OBJECT *pGPONonForcedList,
  288. LPSCOPEOFMGMT *ppSOMList, LPGPCONTAINER *ppGpContainerList,
  289. BOOL bVerbose,
  290. GPO_LINK GPOLink, PLDAP pld, PLDAP_API pLDAP, PLDAPMessage pLDAPMsg,BOOL *bBlock, PRSOPTOKEN pRsopToken );
  291. BOOL EvaluateDeferredOUs( DNENTRY *pOUList,
  292. DWORD dwFlags,
  293. HANDLE hToken,
  294. PGROUP_POLICY_OBJECT *ppDeferredForcedList,
  295. PGROUP_POLICY_OBJECT *ppDeferredNonForcedList,
  296. LPSCOPEOFMGMT *ppSOMList,
  297. LPGPCONTAINER *ppGpContainerList,
  298. BOOL bVerbose,
  299. PLDAP pld,
  300. PLDAP_API pLDAP,
  301. BOOL *pbBlock,
  302. PRSOPTOKEN pRsopToken);
  303. void FreeDnEntry( DNENTRY *pDnEntry );
  304. BOOL CheckOUAccess( PLDAP_API pLDAP,
  305. PLDAP pld,
  306. PLDAPMessage pMessage,
  307. PRSOPTOKEN pRsopToken,
  308. BOOL *pbAccessGranted );
  309. BOOL AddAdmFile( WCHAR *pwszFile, WCHAR *pwszGPO, FILETIME *pftWrite, LPTSTR szComputer, ADMFILEINFO **ppAdmFileCache );
  310. void FreeAdmFileCache( ADMFILEINFO *pAdmFileCache );
  311. ADMFILEINFO * AllocAdmFileInfo( WCHAR *pwszFile, WCHAR *pwszGPO, FILETIME *pftWrite );
  312. void FreeAdmFileInfo( ADMFILEINFO *pAdmFileInfo );
  313. DWORD
  314. SavePolicyState( LPGPOINFO pInfo );
  315. DWORD
  316. SaveLinkState( LPGPOINFO pInfo );
  317. DWORD
  318. ComparePolicyState( LPGPOINFO pInfo, BOOL* pbLinkChanged, BOOL* pbStateChanged, BOOL *pbNoState );
  319. DWORD
  320. DeletePolicyState( LPCWSTR szSid );
  321. LPTSTR GetSomPath( LPTSTR szContainer );
  322. HRESULT RsopSidsFromToken(PRSOPTOKEN pRsopToken,
  323. PTOKEN_GROUPS* ppGroups);