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.

201 lines
4.5 KiB

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