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.

1429 lines
40 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997-2001.
  5. //
  6. // File: N C P E R M S . C P P
  7. //
  8. // Contents: Common routines for dealing with permissions.
  9. //
  10. // Notes: Pollute this under penalty of death.
  11. //
  12. // Author: shaunco 20 Sep 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #include <pch.h>
  16. #pragma hdrstop
  17. #include <ntseapi.h>
  18. #include "ncbase.h"
  19. #include "ncdebug.h"
  20. #include "ncperms.h"
  21. #include "netconp.h"
  22. #include "ncreg.h"
  23. #include "lm.h"
  24. CGroupPolicyBase* g_pNetmanGPNLA = NULL;
  25. #define INITGUID
  26. #include <nmclsid.h>
  27. //+---------------------------------------------------------------------------
  28. //
  29. // Function: FCheckGroupMembership
  30. //
  31. // Purpose: Returns TRUE if the logged on user is a member of the
  32. // specified group.
  33. //
  34. // Arguments:
  35. // dwRID [in] Group RID to check against.
  36. //
  37. // Returns: TRUE if the logged on user is a member of the specified group
  38. //
  39. // Author: scottbri 14 Sept 1998
  40. //
  41. // Notes:
  42. //
  43. BOOL FCheckGroupMembership(IN DWORD dwRID)
  44. {
  45. SID_IDENTIFIER_AUTHORITY SidAuth = SECURITY_NT_AUTHORITY;
  46. PSID psid;
  47. BOOL fIsMember = FALSE;
  48. // Allocate a SID for the Administrators group and check to see
  49. // if the user is a member.
  50. //
  51. if (AllocateAndInitializeSid (&SidAuth, 2,
  52. SECURITY_BUILTIN_DOMAIN_RID,
  53. dwRID,
  54. 0, 0, 0, 0, 0, 0,
  55. &psid))
  56. {
  57. if (!CheckTokenMembership (NULL, psid, &fIsMember))
  58. {
  59. fIsMember = FALSE;
  60. TraceLastWin32Error ("FCheckGroupMembership - CheckTokenMemberShip failed.");
  61. }
  62. FreeSid (psid);
  63. }
  64. else
  65. {
  66. TraceLastWin32Error ("FCheckGroupMembership - AllocateAndInitializeSid failed.");
  67. }
  68. return fIsMember;
  69. }
  70. //+---------------------------------------------------------------------------
  71. //
  72. // Function: FIsUserAdmin
  73. //
  74. // Purpose: Returns TRUE if the logged on user is a member of the
  75. // Administrators local group.
  76. //
  77. // Arguments:
  78. // (none)
  79. //
  80. // Returns: TRUE if the logged on user is a member of the
  81. // Administrators local group. False otherwise.
  82. //
  83. // Author: shaunco 19 Mar 1998
  84. //
  85. // Notes:
  86. //
  87. BOOL
  88. FIsUserAdmin()
  89. {
  90. BOOL fIsMember;
  91. // Check the administrators group
  92. //
  93. fIsMember = FCheckGroupMembership(DOMAIN_ALIAS_RID_ADMINS);
  94. return fIsMember;
  95. }
  96. //#define ALIGN_DWORD(_size) (((_size) + 3) & ~3)
  97. //#define ALIGN_QWORD(_size) (((_size) + 7) & ~7)
  98. #define SIZE_ALIGNED_FOR_TYPE(_size, _type) \
  99. (((_size) + sizeof(_type)-1) & ~(sizeof(_type)-1))
  100. //+---------------------------------------------------------------------------
  101. //
  102. // Function: HrAllocateSecurityDescriptorAllowAccessToWorld
  103. //
  104. // Purpose: Allocate a security descriptor and initialize it to
  105. // allow access to everyone.
  106. //
  107. // Arguments:
  108. // ppSd [out] Returned security descriptor.
  109. //
  110. // Returns: S_OK or an error code.
  111. //
  112. // Author: shaunco 10 Nov 1998
  113. //
  114. // Notes: Free *ppSd with MemFree.
  115. //
  116. HRESULT
  117. HrAllocateSecurityDescriptorAllowAccessToWorld (
  118. OUT PSECURITY_DESCRIPTOR* ppSd)
  119. {
  120. PSECURITY_DESCRIPTOR pSd = NULL;
  121. PSID pSid = NULL;
  122. PACL pDacl = NULL;
  123. DWORD dwErr = NOERROR;
  124. DWORD dwAlignSdSize;
  125. DWORD dwAlignDaclSize;
  126. DWORD dwSidSize;
  127. PVOID pvBuffer = NULL;
  128. // Here is the buffer we are building.
  129. //
  130. // |<- a ->|<- b ->|<- c ->|
  131. // +-------+--------+------+
  132. // | p| p| |
  133. // | SD a| DACL a| SID |
  134. // | d| d| |
  135. // +-------+-------+-------+
  136. // ^ ^ ^
  137. // | | |
  138. // | | +--pSid
  139. // | |
  140. // | +--pDacl
  141. // |
  142. // +--pSd (this is returned via *ppSd)
  143. //
  144. // pad is so that pDacl and pSid are aligned properly.
  145. //
  146. // a = dwAlignSdSize
  147. // b = dwAlignDaclSize
  148. // c = dwSidSize
  149. //
  150. // Initialize output parameter.
  151. //
  152. *ppSd = NULL;
  153. // Compute the size of the SID. The SID is the well-known SID for World
  154. // (S-1-1-0).
  155. //
  156. dwSidSize = GetSidLengthRequired(1);
  157. // Compute the size of the DACL. It has an inherent copy of SID within
  158. // it so add enough room for it. It also must sized properly so that
  159. // a pointer to a SID structure can come after it. Hence, we use
  160. // SIZE_ALIGNED_FOR_TYPE.
  161. //
  162. dwAlignDaclSize = SIZE_ALIGNED_FOR_TYPE(
  163. sizeof(ACCESS_ALLOWED_ACE) + sizeof(ACL) + dwSidSize,
  164. PSID);
  165. // Compute the size of the SD. It must be sized propertly so that a
  166. // pointer to a DACL structure can come after it. Hence, we use
  167. // SIZE_ALIGNED_FOR_TYPE.
  168. //
  169. dwAlignSdSize = SIZE_ALIGNED_FOR_TYPE(
  170. sizeof(SECURITY_DESCRIPTOR),
  171. PACL);
  172. // Allocate the buffer big enough for all.
  173. //
  174. dwErr = ERROR_OUTOFMEMORY;
  175. pvBuffer = MemAlloc(dwSidSize + dwAlignDaclSize + dwAlignSdSize);
  176. if (pvBuffer)
  177. {
  178. SID_IDENTIFIER_AUTHORITY SidIdentifierWorldAuth
  179. = SECURITY_WORLD_SID_AUTHORITY;
  180. PULONG pSubAuthority;
  181. dwErr = NOERROR;
  182. // Setup the pointers into the buffer.
  183. //
  184. pSd = pvBuffer;
  185. pDacl = (PACL)((PBYTE)pvBuffer + dwAlignSdSize);
  186. pSid = (PSID)((PBYTE)pDacl + dwAlignDaclSize);
  187. // Initialize pSid as S-1-1-0.
  188. //
  189. if (!InitializeSid(
  190. pSid,
  191. &SidIdentifierWorldAuth,
  192. 1)) // 1 sub-authority
  193. {
  194. dwErr = GetLastError();
  195. goto finish;
  196. }
  197. pSubAuthority = GetSidSubAuthority(pSid, 0);
  198. *pSubAuthority = SECURITY_WORLD_RID;
  199. // Initialize pDacl.
  200. //
  201. if (!InitializeAcl(
  202. pDacl,
  203. dwAlignDaclSize,
  204. ACL_REVISION))
  205. {
  206. dwErr = GetLastError();
  207. goto finish;
  208. }
  209. // Add an access-allowed ACE for S-1-1-0 to pDacl.
  210. //
  211. if (!AddAccessAllowedAce(
  212. pDacl,
  213. ACL_REVISION,
  214. STANDARD_RIGHTS_ALL | SPECIFIC_RIGHTS_ALL,
  215. pSid))
  216. {
  217. dwErr = GetLastError();
  218. goto finish;
  219. }
  220. // Initialize pSd.
  221. //
  222. if (!InitializeSecurityDescriptor(
  223. pSd,
  224. SECURITY_DESCRIPTOR_REVISION))
  225. {
  226. dwErr = GetLastError();
  227. goto finish;
  228. }
  229. // Set pSd to use pDacl.
  230. //
  231. if (!SetSecurityDescriptorDacl(
  232. pSd,
  233. TRUE,
  234. pDacl,
  235. FALSE))
  236. {
  237. dwErr = GetLastError();
  238. goto finish;
  239. }
  240. // Set the owner for pSd.
  241. //
  242. if (!SetSecurityDescriptorOwner(
  243. pSd,
  244. NULL,
  245. FALSE))
  246. {
  247. dwErr = GetLastError();
  248. goto finish;
  249. }
  250. // Set the group for pSd.
  251. //
  252. if (!SetSecurityDescriptorGroup(
  253. pSd,
  254. NULL,
  255. FALSE))
  256. {
  257. dwErr = GetLastError();
  258. goto finish;
  259. }
  260. finish:
  261. if (!dwErr)
  262. {
  263. *ppSd = pSd;
  264. }
  265. else
  266. {
  267. MemFree(pvBuffer);
  268. }
  269. }
  270. return HRESULT_FROM_WIN32(dwErr);
  271. }
  272. //+--------------------------------------------------------------------------
  273. //
  274. // Function: HrEnablePrivilege
  275. //
  276. // Purpose: Enables the specified privilege for the current process
  277. //
  278. // Arguments:
  279. // pszPrivilegeName [in] The name of the privilege
  280. //
  281. // Returns: HRESULT. S_OK if successful,
  282. // a converted Win32 error code otherwise
  283. //
  284. // Author: billbe 13 Dec 1997
  285. //
  286. // Notes:
  287. //
  288. HRESULT
  289. HrEnablePrivilege (
  290. IN PCWSTR pszPrivilegeName)
  291. {
  292. HANDLE hToken;
  293. // Open the thread token in case it is impersonating
  294. BOOL fWin32Success = OpenThreadToken (GetCurrentThread(),
  295. TOKEN_ADJUST_PRIVILEGES, TRUE, &hToken);
  296. // If there was no token for the thread, open the process token
  297. //
  298. if (!fWin32Success && (ERROR_NO_TOKEN == GetLastError ()))
  299. {
  300. // Get token to adjust privileges for this process
  301. fWin32Success = OpenProcessToken (GetCurrentProcess(),
  302. TOKEN_ADJUST_PRIVILEGES, &hToken);
  303. }
  304. if (fWin32Success)
  305. {
  306. // get the luid that represents the privilege name
  307. LUID luid;
  308. fWin32Success = LookupPrivilegeValue(NULL, pszPrivilegeName, &luid);
  309. if (fWin32Success)
  310. {
  311. // set up the privilege structure
  312. TOKEN_PRIVILEGES tpNewPrivileges;
  313. tpNewPrivileges.PrivilegeCount = 1;
  314. tpNewPrivileges.Privileges[0].Luid = luid;
  315. tpNewPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  316. // turn on the privilege
  317. AdjustTokenPrivileges (hToken, FALSE, &tpNewPrivileges, 0,
  318. NULL, NULL);
  319. if (ERROR_SUCCESS != GetLastError())
  320. {
  321. fWin32Success = FALSE;
  322. }
  323. }
  324. CloseHandle(hToken);
  325. }
  326. HRESULT hr;
  327. // Convert any errors to an HRESULT
  328. if (!fWin32Success)
  329. {
  330. hr = HrFromLastWin32Error();
  331. }
  332. else
  333. {
  334. hr = S_OK;
  335. }
  336. TraceError ("HrEnablePrivilege", hr);
  337. return hr;
  338. }
  339. //+---------------------------------------------------------------------------
  340. //
  341. // Function: HrEnableAllPrivileges
  342. //
  343. // Purpose: Enables all privileges for the current process.
  344. //
  345. // Arguments:
  346. // pptpOld [out] Returns the previous state of privileges so that they can
  347. // be restored.
  348. //
  349. // Returns: S_OK if successful, Win32 Error otherwise
  350. //
  351. // Author: danielwe 11 Aug 1997
  352. //
  353. // Notes: The pptpOld parameter should be freed with delete [].
  354. //
  355. HRESULT
  356. HrEnableAllPrivileges (
  357. OUT TOKEN_PRIVILEGES** pptpOld)
  358. {
  359. Assert(pptpOld);
  360. HRESULT hr = S_OK;
  361. HANDLE hTok;
  362. ULONG cbTok = 4096;
  363. BOOL fres;
  364. // Try opening the thread token first in case of impersonation
  365. fres = OpenThreadToken(GetCurrentThread(),
  366. TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, TRUE, &hTok);
  367. if (!fres && (ERROR_NO_TOKEN == GetLastError()))
  368. {
  369. // If there was no thread token open the process token
  370. fres = OpenProcessToken(GetCurrentProcess(),
  371. TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
  372. &hTok);
  373. }
  374. if (fres)
  375. {
  376. PTOKEN_PRIVILEGES ptpNew;
  377. hr = E_OUTOFMEMORY;
  378. ptpNew = (PTOKEN_PRIVILEGES)MemAlloc(cbTok);
  379. if (ptpNew)
  380. {
  381. hr = S_OK;
  382. fres = GetTokenInformation(hTok, TokenPrivileges,
  383. ptpNew, cbTok, &cbTok);
  384. if (fres)
  385. {
  386. //
  387. // Set the state settings so that all privileges are enabled...
  388. //
  389. if (ptpNew->PrivilegeCount > 0)
  390. {
  391. for (ULONG iPriv = 0; iPriv < ptpNew->PrivilegeCount; iPriv++)
  392. {
  393. ptpNew->Privileges[iPriv].Attributes = SE_PRIVILEGE_ENABLED;
  394. }
  395. }
  396. *pptpOld = reinterpret_cast<PTOKEN_PRIVILEGES>(new BYTE[cbTok]);
  397. fres = AdjustTokenPrivileges(hTok, FALSE, ptpNew, cbTok, *pptpOld,
  398. &cbTok);
  399. }
  400. MemFree(ptpNew);
  401. }
  402. CloseHandle(hTok);
  403. }
  404. if (!fres)
  405. {
  406. hr = HrFromLastWin32Error();
  407. }
  408. TraceError("HrEnableAllPrivileges", hr);
  409. return hr;
  410. }
  411. //+---------------------------------------------------------------------------
  412. //
  413. // Function: HrRestorePrivileges
  414. //
  415. // Purpose: Restores the privileges for the current process after they have
  416. // have been modified by HrEnableAllPrivileges().
  417. //
  418. // Arguments:
  419. // ptpRestore [in] Previous state of privileges as returned by
  420. // HrEnableAllPrivileges().
  421. //
  422. // Returns: S_OK if successful, Win32 Error otherwise
  423. //
  424. // Author: danielwe 11 Aug 1997
  425. //
  426. // Notes:
  427. //
  428. HRESULT
  429. HrRestorePrivileges (
  430. IN TOKEN_PRIVILEGES* ptpRestore)
  431. {
  432. HRESULT hr = S_OK;
  433. HANDLE hTok = NULL ;
  434. BOOL fres = FALSE;
  435. Assert(ptpRestore);
  436. if (OpenProcessToken(GetCurrentProcess(),
  437. TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
  438. &hTok))
  439. {
  440. if (AdjustTokenPrivileges(hTok, FALSE, ptpRestore, 0, NULL, NULL))
  441. {
  442. fres = TRUE;
  443. }
  444. CloseHandle(hTok);
  445. }
  446. if (!fres)
  447. {
  448. hr = HrFromLastWin32Error();
  449. }
  450. TraceError("HrRestorePrivileges", hr);
  451. return hr;
  452. }
  453. extern const DECLSPEC_SELECTANY WCHAR c_szConnectionsPolicies[] =
  454. L"Software\\Policies\\Microsoft\\Windows\\Network Connections";
  455. // User types
  456. const DWORD USER_TYPE_ADMIN = 0x00000001;
  457. const DWORD USER_TYPE_NETCONFIGOPS = 0x00000002;
  458. const DWORD USER_TYPE_POWERUSER = 0x00000004;
  459. const DWORD USER_TYPE_USER = 0x00000008;
  460. const DWORD USER_TYPE_GUEST = 0x00000010;
  461. typedef struct
  462. {
  463. DWORD dwShift;
  464. PCWSTR pszValue;
  465. DWORD dwApplyMask;
  466. } PERM_MAP_STRUCT;
  467. extern const DECLSPEC_SELECTANY PERM_MAP_STRUCT USER_PERM_MAP[] =
  468. {
  469. {NCPERM_NewConnectionWizard, L"NC_NewConnectionWizard", APPLY_TO_ALL_USERS},
  470. {NCPERM_Statistics, L"NC_Statistics", APPLY_TO_ALL_USERS},
  471. {NCPERM_AddRemoveComponents, L"NC_AddRemoveComponents", APPLY_TO_ADMIN},
  472. {NCPERM_RasConnect, L"NC_RasConnect", APPLY_TO_ALL_USERS},
  473. {NCPERM_LanConnect, L"NC_LanConnect", APPLY_TO_ALL_USERS},
  474. {NCPERM_DeleteConnection, L"NC_DeleteConnection", APPLY_TO_ALL_USERS},
  475. {NCPERM_DeleteAllUserConnection, L"NC_DeleteAllUserConnection", APPLY_TO_ALL_USERS},
  476. {NCPERM_RenameConnection, L"NC_RenameConnection", APPLY_TO_ALL_USERS},
  477. {NCPERM_RenameMyRasConnection, L"NC_RenameMyRasConnection", APPLY_TO_ALL_USERS},
  478. {NCPERM_ChangeBindState, L"NC_ChangeBindState", APPLY_TO_ADMIN},
  479. {NCPERM_AdvancedSettings, L"NC_AdvancedSettings", APPLY_TO_ADMIN},
  480. {NCPERM_DialupPrefs, L"NC_DialupPrefs", APPLY_TO_ALL_USERS},
  481. {NCPERM_LanChangeProperties, L"NC_LanChangeProperties", APPLY_TO_OPS_OR_ADMIN},
  482. {NCPERM_RasChangeProperties, L"NC_RasChangeProperties", APPLY_TO_ALL_USERS},
  483. {NCPERM_LanProperties, L"NC_LanProperties", APPLY_TO_ALL_USERS},
  484. {NCPERM_RasMyProperties, L"NC_RasMyProperties", APPLY_TO_ALL_USERS},
  485. {NCPERM_RasAllUserProperties, L"NC_RasAllUserProperties", APPLY_TO_ALL_USERS},
  486. {NCPERM_ShowSharedAccessUi, L"NC_ShowSharedAccessUi", APPLY_TO_LOCATION},
  487. {NCPERM_AllowAdvancedTCPIPConfig, L"NC_AllowAdvancedTCPIPConfig", APPLY_TO_ALL_USERS},
  488. {NCPERM_PersonalFirewallConfig, L"NC_PersonalFirewallConfig", APPLY_TO_LOCATION},
  489. {NCPERM_AllowNetBridge_NLA, L"NC_AllowNetBridge_NLA", APPLY_TO_LOCATION},
  490. {NCPERM_ICSClientApp, L"NC_ICSClientApp", APPLY_TO_LOCATION},
  491. {NCPERM_EnDisComponentsAllUserRas, L"NC_EnDisComponentsAllUserRas", APPLY_TO_NON_ADMINS},
  492. {NCPERM_EnDisComponentsMyRas, L"NC_EnDisComponentsMyRas", APPLY_TO_NON_ADMINS},
  493. {NCPERM_ChangeMyRasProperties, L"NC_ChangeMyRasProperties", APPLY_TO_NON_ADMINS},
  494. {NCPERM_ChangeAllUserRasProperties, L"NC_ChangeAllUserRasProperties", APPLY_TO_NON_ADMINS},
  495. {NCPERM_RenameLanConnection, L"NC_RenameLanConnection", APPLY_TO_NON_ADMINS},
  496. {NCPERM_RenameAllUserRasConnection, L"NC_RenameAllUserRasConnection", APPLY_TO_NON_ADMINS},
  497. {NCPERM_IpcfgOperation, L"NC_IPConfigOperation", APPLY_TO_ALL_USERS},
  498. {NCPERM_Repair, L"NC_Repair", APPLY_TO_ALL_USERS},
  499. };
  500. extern const DECLSPEC_SELECTANY PERM_MAP_STRUCT MACHINE_PERM_MAP[] =
  501. {
  502. {NCPERM_ShowSharedAccessUi, L"NC_ShowSharedAccessUi", APPLY_TO_LOCATION},
  503. {NCPERM_PersonalFirewallConfig, L"NC_PersonalFirewallConfig", APPLY_TO_LOCATION},
  504. {NCPERM_ICSClientApp, L"NC_ICSClientApp", APPLY_TO_LOCATION},
  505. {NCPERM_AllowNetBridge_NLA, L"NC_AllowNetBridge_NLA", APPLY_TO_LOCATION}
  506. };
  507. extern const LONG NCPERM_Min = NCPERM_NewConnectionWizard;
  508. extern const LONG NCPERM_Max = NCPERM_Repair;
  509. // External policies (for now, only explorer has polices that affect our processing
  510. //
  511. extern const WCHAR c_szExplorerPolicies[] =
  512. L"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer";
  513. extern const WCHAR c_szNCPolicyForAdministrators[] =
  514. L"NC_EnableAdminProhibits";
  515. extern const WCHAR c_szNoNetworkConnectionPolicy[] =
  516. L"NoNetworkConnections";
  517. static DWORD g_dwPermMask;
  518. static BOOL g_fPermsInited = FALSE;
  519. inline
  520. VOID NCPERM_SETBIT(IN DWORD dw, IN DWORD dwVal)
  521. {
  522. DWORD dwBit = (1 << dw);
  523. g_dwPermMask = (g_dwPermMask & ~dwBit) | ((0==dwVal) ? 0 : dwBit);
  524. }
  525. inline
  526. BOOL NCPERM_CHECKBIT(IN DWORD dw)
  527. {
  528. #ifdef DBG
  529. if (!FIsPolicyConfigured(dw))
  530. {
  531. if (0xFFFFFFFF != g_dwDbgPermissionsFail)
  532. {
  533. if (FProhibitFromAdmins() || !FIsUserAdmin())
  534. {
  535. if ( (1 << dw) & g_dwDbgPermissionsFail)
  536. {
  537. TraceTag(ttidDefault, "Failing permissions check due to g_dwDbgPermissionsFail set");
  538. return FALSE;
  539. }
  540. }
  541. }
  542. }
  543. #endif // DBG
  544. return !!(g_dwPermMask & (1 << dw));
  545. }
  546. inline
  547. BOOL NCPERM_USER_IS_ADMIN(IN DWORD dwUserType)
  548. {
  549. return (dwUserType & USER_TYPE_ADMIN);
  550. }
  551. inline
  552. BOOL NCPERM_USER_IS_NETCONFIGOPS(IN DWORD dwUserType)
  553. {
  554. return (dwUserType & USER_TYPE_NETCONFIGOPS);
  555. }
  556. inline
  557. BOOL NCPERM_USER_IS_POWERUSER(IN DWORD dwUserType)
  558. {
  559. return (dwUserType & USER_TYPE_POWERUSER);
  560. }
  561. inline
  562. BOOL NCPERM_USER_IS_USER(IN DWORD dwUserType)
  563. {
  564. return (dwUserType & USER_TYPE_USER);
  565. }
  566. inline
  567. BOOL NCPERM_USER_IS_GUEST(IN DWORD dwUserType)
  568. {
  569. return (dwUserType & USER_TYPE_GUEST);
  570. }
  571. inline
  572. BOOL NCPERM_APPLIES_TO_CURRENT_USER(IN DWORD dwUserType, IN DWORD dwApplyMask)
  573. {
  574. return (dwUserType & dwApplyMask);
  575. }
  576. inline
  577. int NCPERM_FIND_MAP_ENTRY(IN ULONG ulPerm)
  578. {
  579. for (int i = 0; i < celems(USER_PERM_MAP); i++)
  580. {
  581. if (USER_PERM_MAP[i].dwShift == ulPerm)
  582. {
  583. return i;
  584. }
  585. }
  586. return -1;
  587. }
  588. inline
  589. BOOL NCPERM_APPLIES_TO_LOCATION(IN ULONG ulPerm)
  590. {
  591. BOOL bAppliesToLocation = FALSE;
  592. int nIdx = NCPERM_FIND_MAP_ENTRY(ulPerm);
  593. if (nIdx != -1)
  594. {
  595. bAppliesToLocation = (USER_PERM_MAP[nIdx].dwApplyMask & APPLY_TO_LOCATION);
  596. }
  597. else
  598. {
  599. bAppliesToLocation = FALSE;
  600. }
  601. return bAppliesToLocation;
  602. }
  603. inline
  604. BOOL NCPERM_APPLY_BASED_ON_LOCATION(IN ULONG ulPerm, IN DWORD dwPermission)
  605. {
  606. DWORD fSameNetwork = FALSE;
  607. if (g_pNetmanGPNLA)
  608. {
  609. fSameNetwork = g_pNetmanGPNLA->IsSameNetworkAsGroupPolicies();
  610. }
  611. if (!fSameNetwork && NCPERM_APPLIES_TO_LOCATION(ulPerm))
  612. {
  613. dwPermission = TRUE;
  614. }
  615. return dwPermission;
  616. }
  617. inline
  618. DWORD NCPERM_USER_TYPE()
  619. {
  620. if (FIsUserAdmin())
  621. {
  622. return USER_TYPE_ADMIN;
  623. }
  624. else if (FIsUserNetworkConfigOps())
  625. {
  626. return USER_TYPE_NETCONFIGOPS;
  627. }
  628. else if (FIsUserPowerUser())
  629. {
  630. return USER_TYPE_POWERUSER;
  631. }
  632. else if (FIsUserGuest())
  633. {
  634. return USER_TYPE_GUEST;
  635. }
  636. return USER_TYPE_USER;
  637. }
  638. inline
  639. BOOL IsOsLikePersonal()
  640. {
  641. OSVERSIONINFOEXW verInfo = {0};
  642. ULONGLONG ConditionMask = 0;
  643. static BOOL fChecked = FALSE;
  644. static BOOL fOsLikePersonal = FALSE;
  645. // Optimization, since OS can't change on the fly. Even a domain join requires a reboot.
  646. // If that ever changes then this logic needs to be revisited.
  647. // ISSUE: Revisit frequently. This may change.
  648. if (fChecked)
  649. {
  650. return fOsLikePersonal;
  651. }
  652. verInfo.dwOSVersionInfoSize = sizeof(verInfo);
  653. verInfo.wProductType = VER_NT_WORKSTATION;
  654. VER_SET_CONDITION(ConditionMask, VER_PRODUCT_TYPE, VER_LESS_EQUAL);
  655. if(VerifyVersionInfo(&verInfo, VER_PRODUCT_TYPE, ConditionMask))
  656. {
  657. LPWSTR pszDomain;
  658. NETSETUP_JOIN_STATUS njs = NetSetupUnknownStatus;
  659. if (NERR_Success == NetGetJoinInformation(NULL, &pszDomain, &njs))
  660. {
  661. NetApiBufferFree(pszDomain);
  662. }
  663. if (NetSetupDomainName == njs)
  664. {
  665. fOsLikePersonal = FALSE; // connected to domain
  666. }
  667. else
  668. {
  669. fOsLikePersonal = TRUE; // Professional, but not a domain member
  670. }
  671. }
  672. else
  673. {
  674. fOsLikePersonal = FALSE;
  675. }
  676. fChecked = TRUE;
  677. return fOsLikePersonal;
  678. }
  679. const ULONG c_arrayHomenetPerms[] =
  680. {
  681. NCPERM_PersonalFirewallConfig,
  682. NCPERM_ICSClientApp,
  683. NCPERM_ShowSharedAccessUi
  684. };
  685. #ifdef DBG
  686. ULONG g_dwDbgPermissionsFail = 0xFFFFFFFF;
  687. ULONG g_dwDbgWin2kPoliciesSet = 0xFFFFFFFF;
  688. #endif // DBG
  689. //+---------------------------------------------------------------------------
  690. //
  691. // Function: FHasPermission
  692. //
  693. // Purpose: Called to determine if the requested permissions are available
  694. //
  695. // Arguments:
  696. // ulPerm [in] Permission flags (E.g. NCPERM_xxxx)
  697. // pGPBase [in] CGroupPolicyBase - the netman Group Policy Engine. In
  698. // order to check a location aware policy, this must be
  699. // passed in.
  700. //
  701. // Returns: BOOL, TRUE if the requested permission is granted to the user
  702. //
  703. BOOL
  704. FHasPermission(IN ULONG ulPerm, IN CGroupPolicyBase* pGPBase)
  705. {
  706. TraceFileFunc(ttidDefault);
  707. DWORD dwCurrentUserType;
  708. Assert(static_cast<LONG>(ulPerm) >= NCPERM_Min);
  709. Assert(static_cast<LONG>(ulPerm) <= NCPERM_Max);
  710. g_pNetmanGPNLA = pGPBase;
  711. //if we are using DataCenter, Back Office,
  712. //Small Business Center, or Blade, then don't grant the permission
  713. for (int i = 0; i < celems(c_arrayHomenetPerms); i++)
  714. {
  715. if (c_arrayHomenetPerms[i] == ulPerm)
  716. {
  717. // On IA64, all homenet technologies are unavailable.
  718. #ifndef _WIN64
  719. // Look for the enterprise SKUs
  720. OSVERSIONINFOEXW verInfo = {0};
  721. ULONGLONG ConditionMask = 0;
  722. verInfo.dwOSVersionInfoSize = sizeof(verInfo);
  723. verInfo.wSuiteMask = VER_SUITE_DATACENTER |
  724. VER_SUITE_BACKOFFICE |
  725. VER_SUITE_SMALLBUSINESS_RESTRICTED |
  726. VER_SUITE_SMALLBUSINESS |
  727. VER_SUITE_BLADE;
  728. VER_SET_CONDITION(ConditionMask, VER_SUITENAME, VER_OR);
  729. if(VerifyVersionInfo(&verInfo, VER_SUITENAME, ConditionMask))
  730. #endif
  731. {
  732. return FALSE;
  733. }
  734. }
  735. }
  736. dwCurrentUserType = NCPERM_USER_TYPE();
  737. if (NCPERM_USER_IS_ADMIN(dwCurrentUserType) && !FProhibitFromAdmins() && !NCPERM_APPLIES_TO_LOCATION(ulPerm))
  738. {
  739. // If user is admin and we're not supposed to revoke
  740. // anything from admins and this is not a location aware policy
  741. // then just return TRUE
  742. return TRUE;
  743. }
  744. if (!g_fPermsInited)
  745. {
  746. TraceTag(ttidDefault, "Initializing permissions");
  747. RefreshAllPermission();
  748. g_fPermsInited = TRUE;
  749. }
  750. else
  751. {
  752. // update the requested permission only
  753. HRESULT hr = S_OK;
  754. HKEY hkey = NULL;
  755. DWORD dw = 0;
  756. switch(ulPerm)
  757. {
  758. case NCPERM_OpenConnectionsFolder:
  759. TraceTag(ttidDefault, "Reading OpenConnectionsFolder permissions");
  760. hr = HrRegOpenKeyEx(HKEY_CURRENT_USER, c_szExplorerPolicies,
  761. KEY_READ, &hkey);
  762. if (S_OK == hr)
  763. {
  764. TraceTag(ttidDefault, "Opened explorer policies");
  765. hr = HrRegQueryDword(hkey, c_szNoNetworkConnectionPolicy, &dw);
  766. if (SUCCEEDED(hr) && dw)
  767. {
  768. TraceTag(ttidDefault,
  769. "Explorer 'No open connections folder' policy: %d", dw);
  770. NCPERM_SETBIT(NCPERM_OpenConnectionsFolder, 0);
  771. }
  772. RegCloseKey(hkey);
  773. hkey = NULL;
  774. }
  775. break;
  776. default:
  777. hr = HrRegOpenKeyEx(HKEY_CURRENT_USER, c_szConnectionsPolicies,
  778. KEY_READ, &hkey);
  779. if (S_OK == hr)
  780. {
  781. DWORD dw;
  782. // Read the User Policy
  783. for (UINT nIdx=0; nIdx<celems(USER_PERM_MAP); nIdx++)
  784. {
  785. if (ulPerm == USER_PERM_MAP[nIdx].dwShift && NCPERM_APPLIES_TO_CURRENT_USER(dwCurrentUserType, USER_PERM_MAP[nIdx].dwApplyMask))
  786. {
  787. hr = HrRegQueryDword(hkey, USER_PERM_MAP[nIdx].pszValue, &dw);
  788. if (SUCCEEDED(hr))
  789. {
  790. NCPERM_SETBIT(USER_PERM_MAP[nIdx].dwShift, dw);
  791. }
  792. }
  793. }
  794. RegCloseKey(hkey);
  795. }
  796. // Read the machine policy
  797. //
  798. hr = HrRegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szConnectionsPolicies,
  799. KEY_READ, &hkey);
  800. if (S_OK == hr)
  801. {
  802. DWORD dw;
  803. for (UINT nIdx=0; nIdx<celems(MACHINE_PERM_MAP); nIdx++)
  804. {
  805. if (ulPerm == MACHINE_PERM_MAP[nIdx].dwShift)
  806. {
  807. hr = HrRegQueryDword(hkey, MACHINE_PERM_MAP[nIdx].pszValue, &dw);
  808. if (S_OK == hr)
  809. {
  810. NCPERM_SETBIT(MACHINE_PERM_MAP[nIdx].dwShift, NCPERM_APPLY_BASED_ON_LOCATION(ulPerm, dw));
  811. }
  812. }
  813. }
  814. RegCloseKey(hkey);
  815. }
  816. break;
  817. }
  818. }
  819. return NCPERM_CHECKBIT(ulPerm);
  820. }
  821. //+---------------------------------------------------------------------------
  822. //
  823. // Function: FHasPermissionFromCache
  824. //
  825. // Purpose: Fast call to determine if the requested permissions are available
  826. //
  827. // Arguments:
  828. // ulPerm [in] Permission flags (E.g. NCPERM_xxxx)
  829. //
  830. // Returns: BOOL, TRUE if the requested permission is granted to the user
  831. //
  832. // NOTE: Cannot be used to check a location aware policy!
  833. //
  834. BOOL
  835. FHasPermissionFromCache(IN ULONG ulPerm)
  836. {
  837. Assert(static_cast<LONG>(ulPerm) >= NCPERM_Min);
  838. Assert(static_cast<LONG>(ulPerm) <= NCPERM_Max);
  839. if (!g_fPermsInited)
  840. {
  841. RefreshAllPermission();
  842. g_fPermsInited = TRUE;
  843. }
  844. return NCPERM_CHECKBIT(ulPerm);
  845. }
  846. //+---------------------------------------------------------------------------
  847. //
  848. // Function: FProhibitFromAdmins
  849. //
  850. // Purpose: See if group policies should apply to the administrator
  851. //
  852. // Arguments:
  853. //
  854. // Returns: TRUE if it should apply, otherwise false
  855. //
  856. // Author: ckotze 11 Aug 2000
  857. //
  858. // Notes:
  859. //
  860. BOOL FProhibitFromAdmins()
  861. {
  862. HRESULT hr = S_OK;
  863. HKEY hKey;
  864. DWORD dw;
  865. BOOL bEnabled = FALSE;
  866. #ifdef DBG
  867. if (0xFFFFFFFF != g_dwDbgWin2kPoliciesSet)
  868. {
  869. return g_dwDbgWin2kPoliciesSet;
  870. }
  871. #endif // DBG
  872. hr = HrRegOpenKeyEx(HKEY_CURRENT_USER, c_szConnectionsPolicies,
  873. KEY_READ, &hKey);
  874. if (S_OK == hr)
  875. {
  876. hr = HrRegQueryDword(hKey, c_szNCPolicyForAdministrators, &dw);
  877. if (SUCCEEDED(hr))
  878. {
  879. bEnabled = (dw) ? TRUE : FALSE;
  880. }
  881. RegCloseKey(hKey);
  882. }
  883. TraceErrorOptional("FProhibitFromAdmins", hr, (HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == hr));
  884. return bEnabled;
  885. }
  886. //+---------------------------------------------------------------------------
  887. //
  888. // Function: RefreshAllPermission
  889. //
  890. // Purpose: Initializes all permission to the settings from the registry,
  891. // and the ACL list below. Stores these to be used by
  892. // FHasPermissionFromCache
  893. //
  894. // Arguments:
  895. // none
  896. //
  897. // Returns: None
  898. //
  899. VOID RefreshAllPermission()
  900. {
  901. DWORD dwCurrentUserType;
  902. HKEY hkey;
  903. HRESULT hr;
  904. DWORD dw;
  905. dwCurrentUserType = NCPERM_USER_TYPE();
  906. g_dwPermMask = 0;
  907. // If Admin assume all rights
  908. //
  909. if (NCPERM_USER_IS_ADMIN(dwCurrentUserType))
  910. {
  911. // Cheat a little by setting all bits to one
  912. //
  913. g_dwPermMask = 0xFFFFFFFF;
  914. // If this policy is not set, then we don't need to worry about reading the regkeys
  915. // since we can never take anything away from Admins.
  916. }
  917. else if (NCPERM_USER_IS_NETCONFIGOPS(dwCurrentUserType))
  918. {
  919. NCPERM_SETBIT(NCPERM_NewConnectionWizard, 1);
  920. NCPERM_SETBIT(NCPERM_Statistics, 1);
  921. NCPERM_SETBIT(NCPERM_RasConnect, 1);
  922. NCPERM_SETBIT(NCPERM_DeleteConnection, 1);
  923. NCPERM_SETBIT(NCPERM_DeleteAllUserConnection, 1);
  924. NCPERM_SETBIT(NCPERM_RenameConnection, 1);
  925. NCPERM_SETBIT(NCPERM_RenameMyRasConnection, 1);
  926. NCPERM_SETBIT(NCPERM_RenameAllUserRasConnection, 1);
  927. NCPERM_SETBIT(NCPERM_RenameLanConnection, 1);
  928. NCPERM_SETBIT(NCPERM_DialupPrefs, 1);
  929. NCPERM_SETBIT(NCPERM_RasChangeProperties, 1);
  930. NCPERM_SETBIT(NCPERM_RasMyProperties, 1);
  931. NCPERM_SETBIT(NCPERM_RasAllUserProperties, 1);
  932. NCPERM_SETBIT(NCPERM_ChangeAllUserRasProperties, 1);
  933. NCPERM_SETBIT(NCPERM_LanProperties, 1);
  934. NCPERM_SETBIT(NCPERM_LanChangeProperties, 1);
  935. NCPERM_SETBIT(NCPERM_AllowAdvancedTCPIPConfig, 1);
  936. NCPERM_SETBIT(NCPERM_OpenConnectionsFolder, 1);
  937. NCPERM_SETBIT(NCPERM_LanConnect, 1);
  938. NCPERM_SETBIT(NCPERM_EnDisComponentsAllUserRas, 1);
  939. NCPERM_SETBIT(NCPERM_EnDisComponentsMyRas, 1);
  940. NCPERM_SETBIT(NCPERM_IpcfgOperation, 1);
  941. NCPERM_SETBIT(NCPERM_Repair, 1);
  942. }
  943. else if (NCPERM_USER_IS_POWERUSER(dwCurrentUserType))
  944. {
  945. NCPERM_SETBIT(NCPERM_Repair, 1);
  946. // Rest should be like NCPERM_USER_IS_USER
  947. NCPERM_SETBIT(NCPERM_NewConnectionWizard, 1);
  948. NCPERM_SETBIT(NCPERM_Statistics, 1);
  949. NCPERM_SETBIT(NCPERM_RasConnect, 1);
  950. NCPERM_SETBIT(NCPERM_DeleteConnection, 1);
  951. NCPERM_SETBIT(NCPERM_RenameMyRasConnection, 1);
  952. NCPERM_SETBIT(NCPERM_DialupPrefs, 1);
  953. NCPERM_SETBIT(NCPERM_RasChangeProperties, 1);
  954. NCPERM_SETBIT(NCPERM_RasMyProperties, 1);
  955. NCPERM_SETBIT(NCPERM_AllowAdvancedTCPIPConfig, 1);
  956. NCPERM_SETBIT(NCPERM_LanProperties, 1);
  957. NCPERM_SETBIT(NCPERM_OpenConnectionsFolder, 1);
  958. if (IsOsLikePersonal())
  959. {
  960. NCPERM_SETBIT(NCPERM_RasAllUserProperties, 1);
  961. NCPERM_SETBIT(NCPERM_ChangeAllUserRasProperties, 1);
  962. }
  963. }
  964. else if (NCPERM_USER_IS_USER(dwCurrentUserType))
  965. {
  966. NCPERM_SETBIT(NCPERM_NewConnectionWizard, 1);
  967. NCPERM_SETBIT(NCPERM_Statistics, 1);
  968. NCPERM_SETBIT(NCPERM_RasConnect, 1);
  969. NCPERM_SETBIT(NCPERM_DeleteConnection, 1);
  970. NCPERM_SETBIT(NCPERM_RenameMyRasConnection, 1);
  971. NCPERM_SETBIT(NCPERM_DialupPrefs, 1);
  972. NCPERM_SETBIT(NCPERM_RasChangeProperties, 1);
  973. NCPERM_SETBIT(NCPERM_RasMyProperties, 1);
  974. NCPERM_SETBIT(NCPERM_AllowAdvancedTCPIPConfig, 1);
  975. NCPERM_SETBIT(NCPERM_LanProperties, 1);
  976. NCPERM_SETBIT(NCPERM_OpenConnectionsFolder, 1);
  977. if (IsOsLikePersonal())
  978. {
  979. NCPERM_SETBIT(NCPERM_RasAllUserProperties, 1);
  980. NCPERM_SETBIT(NCPERM_ChangeAllUserRasProperties, 1);
  981. }
  982. }
  983. else if (NCPERM_USER_IS_GUEST(dwCurrentUserType))
  984. {
  985. NCPERM_SETBIT(NCPERM_Statistics, 1);
  986. NCPERM_SETBIT(NCPERM_OpenConnectionsFolder, 1);
  987. }
  988. if (FProhibitFromAdmins() || !NCPERM_USER_IS_ADMIN(dwCurrentUserType))
  989. {
  990. // Read folder policy
  991. hr = HrRegOpenKeyEx(HKEY_CURRENT_USER, c_szExplorerPolicies,
  992. KEY_READ, &hkey);
  993. if (S_OK == hr)
  994. {
  995. TraceTag(ttidDefault, "Opened Explorer Policy reg key");
  996. hr = HrRegQueryDword(hkey, c_szNoNetworkConnectionPolicy, &dw);
  997. if (SUCCEEDED(hr) && dw)
  998. {
  999. TraceTag(ttidDefault, "Explorer 'No open connections folder' policy: %d", dw);
  1000. NCPERM_SETBIT(NCPERM_OpenConnectionsFolder, 0);
  1001. }
  1002. RegCloseKey(hkey);
  1003. hkey = NULL;
  1004. }
  1005. // Read the user policy
  1006. //
  1007. hr = HrRegOpenKeyEx(HKEY_CURRENT_USER, c_szConnectionsPolicies,
  1008. KEY_READ, &hkey);
  1009. if (S_OK == hr)
  1010. {
  1011. for (UINT nIdx=0; nIdx<celems(USER_PERM_MAP); nIdx++)
  1012. {
  1013. if (NCPERM_APPLIES_TO_CURRENT_USER(dwCurrentUserType, USER_PERM_MAP[nIdx].dwApplyMask))
  1014. {
  1015. hr = HrRegQueryDword(hkey, USER_PERM_MAP[nIdx].pszValue, &dw);
  1016. if (SUCCEEDED(hr))
  1017. {
  1018. NCPERM_SETBIT(USER_PERM_MAP[nIdx].dwShift, dw);
  1019. }
  1020. }
  1021. }
  1022. RegCloseKey(hkey);
  1023. }
  1024. }
  1025. // Read the machine policy
  1026. //
  1027. hr = HrRegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szConnectionsPolicies,
  1028. KEY_READ, &hkey);
  1029. if (S_OK == hr)
  1030. {
  1031. DWORD dw;
  1032. for (UINT nIdx=0; nIdx<celems(MACHINE_PERM_MAP); nIdx++)
  1033. {
  1034. hr = HrRegQueryDword(hkey, MACHINE_PERM_MAP[nIdx].pszValue, &dw);
  1035. if (S_OK == hr)
  1036. {
  1037. NCPERM_SETBIT(MACHINE_PERM_MAP[nIdx].dwShift, NCPERM_APPLY_BASED_ON_LOCATION(MACHINE_PERM_MAP[nIdx].dwShift, dw));
  1038. }
  1039. }
  1040. RegCloseKey(hkey);
  1041. }
  1042. }
  1043. //+---------------------------------------------------------------------------
  1044. //
  1045. // Function: IsHNetAllowed
  1046. //
  1047. // Purpose: Verify the permission to use/enable (ICS/Firewall and create bridge network)
  1048. //
  1049. // Arguments: dwPerm [in] Group policy check to make for permission checking
  1050. //
  1051. // Notes: Checks the following:
  1052. //
  1053. // Does the architecture / SKU permit the use of homenet technologies?
  1054. // Does group policy allow the particular technology?
  1055. // Is the user an Admin and are admins allowed access to this technology?
  1056. //
  1057. // Example scenario. The user is a Admin but ITG disables the right to create bridge this function would return FALSE
  1058. //
  1059. BOOL
  1060. IsHNetAllowed(
  1061. IN DWORD dwPerm
  1062. )
  1063. {
  1064. #ifndef _WIN64
  1065. BOOL fPermission = false;
  1066. OSVERSIONINFOEXW verInfo = {0};
  1067. ULONGLONG ConditionMask = 0;
  1068. // Look for the enterprise SKUs
  1069. verInfo.dwOSVersionInfoSize = sizeof(verInfo);
  1070. verInfo.wSuiteMask = VER_SUITE_DATACENTER |
  1071. VER_SUITE_BACKOFFICE |
  1072. VER_SUITE_SMALLBUSINESS_RESTRICTED |
  1073. VER_SUITE_SMALLBUSINESS |
  1074. VER_SUITE_BLADE;
  1075. VER_SET_CONDITION(ConditionMask, VER_SUITENAME, VER_AND);
  1076. if ( VerifyVersionInfo(&verInfo, VER_SUITENAME, ConditionMask) )
  1077. {
  1078. // Homenet technologies are not available on enterprise SKUs
  1079. return FALSE;
  1080. }
  1081. if ( FIsUserAdmin() && !FProhibitFromAdmins() )
  1082. {
  1083. HRESULT hr;
  1084. INetMachinePolicies* pMachinePolicy;
  1085. hr = CoCreateInstance(
  1086. CLSID_NetGroupPolicies,
  1087. NULL,
  1088. CLSCTX_SERVER,
  1089. IID_INetMachinePolicies,
  1090. reinterpret_cast<void **>(&pMachinePolicy)
  1091. );
  1092. if ( SUCCEEDED(hr) )
  1093. {
  1094. hr = pMachinePolicy->VerifyPermission(dwPerm, &fPermission);
  1095. pMachinePolicy->Release();
  1096. }
  1097. }
  1098. return fPermission;
  1099. #else // #ifndef _WIN64
  1100. // On IA64, homenet technologies are not available at all.
  1101. return FALSE;
  1102. #endif
  1103. }
  1104. //+---------------------------------------------------------------------------
  1105. //
  1106. // Function: FIsUserNetworkConfigOps
  1107. //
  1108. // Purpose: Checks to see if the current user is a NetConfig Operator
  1109. //
  1110. //
  1111. // Arguments:
  1112. // none.
  1113. //
  1114. //
  1115. // Returns: BOOL.
  1116. //
  1117. // Author: ckotze 12 Jun 2000
  1118. //
  1119. // Notes:
  1120. //
  1121. BOOL FIsUserNetworkConfigOps()
  1122. {
  1123. BOOL fIsMember;
  1124. fIsMember = FCheckGroupMembership(DOMAIN_ALIAS_RID_NETWORK_CONFIGURATION_OPS);
  1125. return fIsMember;
  1126. }
  1127. //+---------------------------------------------------------------------------
  1128. //
  1129. // Function: FIsUserPowerUser
  1130. //
  1131. // Purpose: Checks to see if the current user is a Power User
  1132. //
  1133. //
  1134. // Arguments:
  1135. // none.
  1136. //
  1137. //
  1138. // Returns: BOOL.
  1139. //
  1140. // Author: deonb 9 May 2001
  1141. //
  1142. // Notes:
  1143. //
  1144. BOOL FIsUserPowerUser()
  1145. {
  1146. BOOL fIsMember;
  1147. fIsMember = FCheckGroupMembership(DOMAIN_ALIAS_RID_POWER_USERS);
  1148. return fIsMember;
  1149. }
  1150. //+---------------------------------------------------------------------------
  1151. //
  1152. // Function: FIsUserGuest
  1153. //
  1154. // Purpose: Checks to see if the current user is a Guest
  1155. //
  1156. //
  1157. // Arguments:
  1158. // none.
  1159. //
  1160. //
  1161. // Returns: BOOL.
  1162. //
  1163. // Author: ckotze 12 Jun 2000
  1164. //
  1165. // Notes:
  1166. //
  1167. BOOL FIsUserGuest()
  1168. {
  1169. BOOL fIsMember;
  1170. fIsMember = FCheckGroupMembership(DOMAIN_ALIAS_RID_GUESTS);
  1171. return fIsMember;
  1172. }
  1173. //+---------------------------------------------------------------------------
  1174. //
  1175. // Function: FIsPolicyConfigured
  1176. //
  1177. // Purpose: Checks to see if the specific policy is configured
  1178. //
  1179. //
  1180. // Arguments: ulPerm [in] Group policy number from the USER_PERM_MAP
  1181. //
  1182. //
  1183. // Returns: BOOL.
  1184. //
  1185. // Author: ckotze 12 Jun 2000
  1186. //
  1187. // Notes:
  1188. //
  1189. BOOL FIsPolicyConfigured(IN DWORD ulPerm)
  1190. {
  1191. HRESULT hr;
  1192. HKEY hkey;
  1193. BOOL bConfigured = FALSE;
  1194. hr = HrRegOpenKeyEx(HKEY_CURRENT_USER, c_szConnectionsPolicies, KEY_READ, &hkey);
  1195. if (S_OK == hr)
  1196. {
  1197. DWORD dw;
  1198. if (ulPerm == USER_PERM_MAP[ulPerm].dwShift)
  1199. {
  1200. DWORD dw;
  1201. hr = HrRegQueryDword(hkey, USER_PERM_MAP[static_cast<DWORD>(ulPerm)].pszValue, &dw);
  1202. if (SUCCEEDED(hr))
  1203. {
  1204. bConfigured = TRUE;
  1205. }
  1206. }
  1207. RegCloseKey(hkey);
  1208. }
  1209. return bConfigured;
  1210. }
  1211. //+---------------------------------------------------------------------------
  1212. //
  1213. // Function: IsSameNetworkAsGroupPolicies
  1214. //
  1215. // Purpose: Checks to see if the current network is the same as where the
  1216. // Group Policies were assigned from.
  1217. //
  1218. // Arguments:
  1219. // none.
  1220. //
  1221. //
  1222. // Returns: BOOL
  1223. //
  1224. // Author: ckotze 05 Jan 2001
  1225. //
  1226. // Notes:
  1227. //
  1228. BOOL IsSameNetworkAsGroupPolicies()
  1229. {
  1230. return g_pNetmanGPNLA->IsSameNetworkAsGroupPolicies();
  1231. }