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.

259 lines
5.5 KiB

  1. #include "pch.h"
  2. #pragma hdrstop
  3. #include "compat.h"
  4. DEFINE_MODULE( "RIPREP" )
  5. BOOL
  6. pIsDomainController(
  7. IN PWSTR Server,
  8. OUT PBOOL DomainControllerFlag
  9. )
  10. /*++
  11. Routine Description:
  12. Queries if the machine is a server or workstation via
  13. the NetServerGetInfo API.
  14. Arguments:
  15. Server - The machine to query, or NULL for the local machine
  16. DomainControllerFlag - Receives TRUE if the machine is a
  17. domain controller, or FALSE if the
  18. machine is a workstation.
  19. Return value:
  20. TRUE if the API was successful, or FALSE if not. GetLastError
  21. gives failure code.
  22. --*/
  23. {
  24. PSERVER_INFO_101 si101;
  25. NET_API_STATUS nas;
  26. nas = NetServerGetInfo(
  27. Server,
  28. 101, // info-level
  29. (PBYTE *) &si101
  30. );
  31. if (nas != NO_ERROR) {
  32. SetLastError (nas);
  33. return FALSE;
  34. }
  35. if ((si101->sv101_type & SV_TYPE_DOMAIN_CTRL) ||
  36. (si101->sv101_type & SV_TYPE_DOMAIN_BAKCTRL)) {
  37. //
  38. // We are dealing with a DC
  39. //
  40. *DomainControllerFlag = TRUE;
  41. } else {
  42. *DomainControllerFlag = FALSE;
  43. }
  44. NetApiBufferFree (si101);
  45. return TRUE;
  46. }
  47. BOOL
  48. DCCheck(
  49. PCOMPATIBILITYCALLBACK CompatibilityCallback,
  50. LPVOID Context
  51. )
  52. /*++
  53. Routine Description:
  54. Check if the machine is a DC. If so, then we add a compatibility
  55. entry. DC's currently cannot be duplicated by RIPREP.
  56. Arguments:
  57. CompatibilityCallback - pointer to call back function
  58. Context - context pointer
  59. Return Value:
  60. Returns always TRUE.
  61. --*/
  62. {
  63. BOOL IsDC;
  64. if (!pIsDomainController(NULL, &IsDC) || (IsDC == TRUE)) {
  65. RIPREP_COMPATIBILITY_ENTRY CompEntry;
  66. WCHAR Text[100];
  67. LoadString(g_hinstance, IDS_CANT_BE_DC_TITLE, Text, ARRAYSIZE(Text));
  68. ZeroMemory(&CompEntry, sizeof(CompEntry));
  69. CompEntry.SizeOfStruct= sizeof(RIPREP_COMPATIBILITY_ENTRY);
  70. CompEntry.Description = Text;
  71. CompEntry.TextName = L"dummy.txt";
  72. CompEntry.MsgResourceId = IDS_CANT_BE_DC_TEXT;
  73. CompatibilityCallback(&CompEntry,Context);
  74. }
  75. return(TRUE);
  76. }
  77. BOOL
  78. GetProfileDirectory(
  79. OUT PWSTR OutputBuffer
  80. )
  81. /*++
  82. Routine Description:
  83. Retrieves the local profiles directory.
  84. We query the registry to retreive this.
  85. Arguments:
  86. OutputBuffer - buffer to receive the profiles directory. Assumed to be
  87. MAX_PATH elements large.
  88. Return Value:
  89. Returns TRUE on success.
  90. --*/
  91. {
  92. HKEY hKey;
  93. WCHAR Buffer[MAX_PATH],ProfilePath[MAX_PATH];
  94. DWORD Type,Size;
  95. LONG rslt;
  96. BOOL retval = FALSE;
  97. *OutputBuffer = NULL;
  98. rslt = RegOpenKeyEx(
  99. HKEY_LOCAL_MACHINE,
  100. L"Software\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
  101. 0,
  102. KEY_QUERY_VALUE,
  103. &hKey);
  104. if (rslt == NO_ERROR) {
  105. Size = sizeof(Buffer);
  106. rslt = RegQueryValueEx(
  107. hKey,
  108. L"ProfilesDirectory",
  109. NULL,
  110. &Type,
  111. (LPBYTE)Buffer,
  112. &Size);
  113. RegCloseKey(hKey);
  114. if (rslt == NO_ERROR) {
  115. if (ExpandEnvironmentStrings(Buffer,ProfilePath,ARRAYSIZE(ProfilePath))) {
  116. wcscpy( OutputBuffer, ProfilePath );
  117. retval = TRUE;
  118. }
  119. }
  120. }
  121. return(retval);
  122. }
  123. BOOL
  124. MultipleProfileCheck(
  125. PCOMPATIBILITYCALLBACK CompatibilityCallback,
  126. LPVOID Context
  127. )
  128. /*++
  129. Routine Description:
  130. Check if the machine has multiple user profiles. If so, add a
  131. compatibility entry.
  132. If the machine has multiple user profiles, we want to warn the user as
  133. there may be sensitive data under the profiles that may make it
  134. onto a public server.
  135. Arguments:
  136. CompatibilityCallback - pointer to call back function
  137. Context - context pointer
  138. Return Value:
  139. Returns TRUE.
  140. --*/
  141. {
  142. WCHAR ProfilePath[MAX_PATH];
  143. WIN32_FIND_DATA FindData;
  144. DWORD DirectoryCount = 0;
  145. BOOL DoWarning = TRUE;
  146. if (GetProfileDirectory( ProfilePath )) {
  147. HANDLE hFind;
  148. wcscat( ProfilePath, L"\\*.*" );
  149. hFind =FindFirstFile(ProfilePath,&FindData);
  150. if (hFind != INVALID_HANDLE_VALUE) {
  151. do {
  152. if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  153. DirectoryCount += 1;
  154. }
  155. } while ( FindNextFile( hFind, &FindData));
  156. FindClose( hFind );
  157. }
  158. }
  159. //
  160. // if there are more than 5 directories, make a warning. These directories
  161. // are:
  162. // "."
  163. // ".."
  164. // "Administrator"
  165. // "All Users"
  166. // "Default User"
  167. // "LocalService"
  168. // "NetworkService"
  169. //
  170. if (DirectoryCount <= 7 && DirectoryCount != 0) {
  171. DoWarning = FALSE;
  172. }
  173. if (DoWarning) {
  174. RIPREP_COMPATIBILITY_ENTRY CompEntry;
  175. WCHAR Text[100];
  176. LoadString(g_hinstance, IDS_MULTIPLE_PROFILES, Text, ARRAYSIZE(Text));
  177. ZeroMemory(&CompEntry, sizeof(CompEntry));
  178. CompEntry.SizeOfStruct= sizeof(RIPREP_COMPATIBILITY_ENTRY);
  179. CompEntry.Description = Text;
  180. CompEntry.MsgResourceId = IDS_MULTIPLE_PROFILES_DESC;
  181. CompEntry.TextName = L"dummy.txt";
  182. CompatibilityCallback(&CompEntry,Context);
  183. }
  184. return(TRUE);
  185. }