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.

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