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.

213 lines
5.8 KiB

  1. #include <windows.h>
  2. #include <lm.h> // for NetGetJoinInformation
  3. #include <Lmjoin.h>
  4. #include <safeboot.h> // SAFEBOOT_* flags
  5. #include "faxutil.h"
  6. // Copy from: shell\shlwapi\apithk.c
  7. //
  8. // checks to see if this machine is a member of a domain or not
  9. // NOTE: this will always return FALSE for older that win XP!
  10. BOOL
  11. IsMachineDomainMember()
  12. {
  13. static BOOL s_bIsDomainMember = FALSE;
  14. static BOOL s_bDomainCached = FALSE;
  15. if (IsWinXPOS() && !s_bDomainCached)
  16. {
  17. LPWSTR pwszDomain;
  18. NETSETUP_JOIN_STATUS njs;
  19. NET_API_STATUS nas;
  20. HMODULE hNetapi32 = NULL;
  21. NET_API_STATUS (*pfNetGetJoinInformation)(LPCWSTR, LPWSTR*, PNETSETUP_JOIN_STATUS) = NULL;
  22. DEBUG_FUNCTION_NAME(TEXT("IsMachineDomainMember"));
  23. //
  24. // NetGetJoinInformation() requires Windows 2000 or later
  25. //
  26. hNetapi32 = LoadLibrary(TEXT("netapi32.dll"));
  27. if(!hNetapi32)
  28. {
  29. DebugPrintEx(DEBUG_ERR,TEXT("LoadLibrary(netapi32.dll) failed with %ld."),GetLastError());
  30. goto exit;
  31. }
  32. (FARPROC&)pfNetGetJoinInformation = GetProcAddress(hNetapi32, "NetGetJoinInformation");
  33. if(!pfNetGetJoinInformation)
  34. {
  35. DebugPrintEx(DEBUG_ERR,TEXT("GetProcAddress(NetGetJoinInformation) failed with %ld."),GetLastError());
  36. goto exit;
  37. }
  38. nas = pfNetGetJoinInformation(NULL, &pwszDomain, &njs);
  39. if (nas == NERR_Success)
  40. {
  41. if (pwszDomain)
  42. {
  43. NetApiBufferFree(pwszDomain);
  44. }
  45. if (njs == NetSetupDomainName)
  46. {
  47. // we are joined to a domain!
  48. s_bIsDomainMember = TRUE;
  49. }
  50. }
  51. exit:
  52. if(hNetapi32)
  53. {
  54. FreeLibrary(hNetapi32);
  55. }
  56. s_bDomainCached = TRUE;
  57. }
  58. return s_bIsDomainMember;
  59. }
  60. //+---------------------------------------------------------------------------
  61. //
  62. // Function: IsSafeMode
  63. //
  64. // Synopsis: Checks the registry to see if the system is in safe mode.
  65. //
  66. // History: 06-Oct-00 JeffreyS Created
  67. //
  68. // Copy from: shell\osshell\security\rshx32\util.cpp
  69. //----------------------------------------------------------------------------
  70. BOOL
  71. IsSafeMode(void)
  72. {
  73. BOOL fIsSafeMode = FALSE;
  74. LONG ec;
  75. HKEY hkey;
  76. ec = RegOpenKeyEx(
  77. HKEY_LOCAL_MACHINE,
  78. TEXT("SYSTEM\\CurrentControlSet\\Control\\SafeBoot\\Option"),
  79. 0,
  80. KEY_QUERY_VALUE,
  81. &hkey
  82. );
  83. if (ec == NO_ERROR)
  84. {
  85. DWORD dwValue;
  86. DWORD dwValueSize = sizeof(dwValue);
  87. ec = RegQueryValueEx(hkey,
  88. TEXT("OptionValue"),
  89. NULL,
  90. NULL,
  91. (LPBYTE)&dwValue,
  92. &dwValueSize);
  93. if (ec == NO_ERROR)
  94. {
  95. fIsSafeMode = (dwValue == SAFEBOOT_MINIMAL || dwValue == SAFEBOOT_NETWORK);
  96. }
  97. RegCloseKey(hkey);
  98. }
  99. return fIsSafeMode;
  100. }
  101. //+---------------------------------------------------------------------------
  102. //
  103. // Function: IsGuestAccessMode
  104. //
  105. // Synopsis: Checks the registry to see if the system is using the
  106. // Guest-only network access mode.
  107. //
  108. // History: 06-Oct-00 JeffreyS Created
  109. //
  110. // Copy from: shell\osshell\security\rshx32\util.cpp
  111. //----------------------------------------------------------------------------
  112. BOOL
  113. IsGuestAccessMode(void)
  114. {
  115. BOOL fIsGuestAccessMode = FALSE;
  116. PRODUCT_SKU_TYPE skuType = GetProductSKU();
  117. if (PRODUCT_SKU_PERSONAL == skuType)
  118. {
  119. // Guest mode is always on for Personal
  120. fIsGuestAccessMode = TRUE;
  121. }
  122. else if (
  123. ((PRODUCT_SKU_PROFESSIONAL == skuType) || (PRODUCT_SKU_DESKTOP_EMBEDDED == skuType)) &&
  124. !IsMachineDomainMember()
  125. )
  126. {
  127. LONG ec;
  128. HKEY hkey;
  129. // Professional, not in a domain. Check the ForceGuest value.
  130. ec = RegOpenKeyEx(
  131. HKEY_LOCAL_MACHINE,
  132. TEXT("SYSTEM\\CurrentControlSet\\Control\\LSA"),
  133. 0,
  134. KEY_QUERY_VALUE,
  135. &hkey
  136. );
  137. if (ec == NO_ERROR)
  138. {
  139. DWORD dwValue;
  140. DWORD dwValueSize = sizeof(dwValue);
  141. ec = RegQueryValueEx(hkey,
  142. TEXT("ForceGuest"),
  143. NULL,
  144. NULL,
  145. (LPBYTE)&dwValue,
  146. &dwValueSize);
  147. if (ec == NO_ERROR && 1 == dwValue)
  148. {
  149. fIsGuestAccessMode = TRUE;
  150. }
  151. RegCloseKey(hkey);
  152. }
  153. }
  154. return fIsGuestAccessMode;
  155. }
  156. //+---------------------------------------------------------------------------
  157. //
  158. // Function: IsSimpleUI
  159. //
  160. // Synopsis: Checks whether to show the simple version of the UI.
  161. //
  162. // History: 06-Oct-00 JeffreyS Created
  163. // 19-Apr-00 GPease Removed CTRL key check
  164. //
  165. // Copy from: shell\osshell\security\rshx32\util.cpp
  166. //----------------------------------------------------------------------------
  167. BOOL
  168. IsSimpleUI()
  169. {
  170. // Show old UI in safe mode and anytime network access involves
  171. // true user identity (server, pro with GuestMode off).
  172. // Show simple UI anytime network access is done using the Guest
  173. // account (personal, pro with GuestMode on) except in safe mode.
  174. return (!IsSafeMode() && IsGuestAccessMode());
  175. }