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.

299 lines
7.0 KiB

  1. // Copyright (c) 2001 Microsoft Corporation
  2. //
  3. // File: common.h
  4. //
  5. // Synopsis: Defines some commonly used functions
  6. // This is really just a dumping ground for functions
  7. // that don't really belong to a specific class in
  8. // this design. They may be implemented in other
  9. // files besides common.cpp.
  10. //
  11. // History: 02/03/2001 JeffJon Created
  12. #define DNS_DOMAIN_NAME_MAX_LIMIT_DUE_TO_POLICY 64
  13. #define DNS_DOMAIN_NAME_MAX_LIMIT_DUE_TO_POLICY_UTF8 155
  14. #define MAX_NETBIOS_NAME_LENGTH DNLEN
  15. // Service names used for both the OCManager and launching wizards
  16. // DHCP
  17. #define CYS_DHCP_SERVICE_NAME L"DHCPServer"
  18. // DNS
  19. #define CYS_DNS_SERVICE_NAME L"DNS"
  20. // Printer
  21. #define CYS_PRINTER_WIZARD_NAME L"AddPrinter"
  22. #define CYS_PRINTER_DRIVER_WIZARD_NAME L"AddPrinterDriver"
  23. // RRAS
  24. #define CYS_RRAS_SERVICE_NAME L"RRAS"
  25. #define CYS_RRAS_UNINSTALL L"RRASUninstall"
  26. // IIS
  27. #define CYS_WEB_SERVICE_NAME L"w3svc"
  28. #define CYS_IIS_COMMON_COMPONENT L"iis_common"
  29. #define CYS_INETMGR_COMPONENT L"iis_inetmgr"
  30. // WINS
  31. #define CYS_WINS_SERVICE_NAME L"WINS"
  32. // Other needed constants
  33. // Switch provided by explorer.exe when launching CYS
  34. #define EXPLORER_SWITCH L"explorer"
  35. // Special share names that don't have the "special" flag set
  36. #define CYS_SPECIAL_SHARE_SYSVOL L"SYSVOL"
  37. #define CYS_SPECIAL_SHARE_NETLOGON L"NETLOGON"
  38. #define CYS_SPECIAL_SHARE_PRINT L"PRINT$"
  39. extern Popup popup;
  40. // Typedefs for common STL containers
  41. typedef
  42. std::vector<DWORD, Burnslib::Heap::Allocator<DWORD> >
  43. IPAddressList;
  44. bool
  45. IsServiceInstalledHelper(const wchar_t* serviceName);
  46. bool
  47. InstallServiceWithOcManager(
  48. const String& infText,
  49. const String& unattendText,
  50. const String& additionalArgs = String());
  51. DWORD
  52. MyWaitForSendMessageThread(HANDLE hThread, DWORD dwTimeout);
  53. HRESULT
  54. CreateTempFile(const String& name, const String& contents);
  55. HRESULT
  56. CreateAndWaitForProcess(
  57. const String& fullPath,
  58. String& commandline,
  59. DWORD& exitCode,
  60. bool minimize = false);
  61. HRESULT
  62. MyCreateProcess(
  63. const String& fullPath,
  64. String& commandline);
  65. bool
  66. IsKeyValuePresent(RegistryKey& key, const String& value);
  67. bool
  68. GetRegKeyValue(
  69. const String& key,
  70. const String& value,
  71. String& resultString,
  72. HKEY parentKey = HKEY_LOCAL_MACHINE);
  73. bool
  74. GetRegKeyValue(
  75. const String& key,
  76. const String& value,
  77. DWORD& resultValue,
  78. HKEY parentKey = HKEY_LOCAL_MACHINE);
  79. bool
  80. SetRegKeyValue(
  81. const String& key,
  82. const String& value,
  83. const String& newString,
  84. HKEY parentKey = HKEY_LOCAL_MACHINE,
  85. bool create = false);
  86. bool
  87. SetRegKeyValue(
  88. const String& key,
  89. const String& value,
  90. DWORD newValue,
  91. HKEY parentKey = HKEY_LOCAL_MACHINE,
  92. bool create = false);
  93. bool
  94. ExecuteWizard(
  95. HWND parent,
  96. PCWSTR serviceName,
  97. String& resultText,
  98. HRESULT& hr);
  99. // This really comes from Burnslib but it is not provided in a header
  100. // so I am putting the declaration here and we will link to the
  101. // Burnslib definition
  102. HANDLE
  103. AppendLogFile(const String& logBaseName, String& logName);
  104. // Macros to help with the log file operations
  105. #define CYS_APPEND_LOG(text) \
  106. if (logfileHandle) \
  107. FS::Write(logfileHandle, text);
  108. bool
  109. IsDhcpConfigured();
  110. extern "C"
  111. {
  112. DWORD
  113. AnyDHCPServerRunning(
  114. ULONG uClientIp,
  115. ULONG * pServerIp
  116. );
  117. }
  118. // Converts a VARIANT of type VT_ARRAY | VT_BSTR to a list of Strings
  119. HRESULT
  120. VariantArrayToStringVector(VARIANT* variant, StringVector& stringList);
  121. // Will convert a DWORD IP Address into a string
  122. String
  123. IPAddressToString(DWORD ipAddress);
  124. // Will convert a string in the form of an IP address to
  125. // a DWORD. A return value of INADDR_NONE means that we failed
  126. // to do the conversion
  127. DWORD
  128. StringToIPAddress(const String& stringIPAddress);
  129. // Converts a DWORD IP address from Intel processor byte order to
  130. // inorder. For example, an address of 1.2.3.4 would come from inet_addr as
  131. // 04030201 but the UI control returns it as 01020304. This function allows
  132. // for conversion between the two
  133. DWORD
  134. ConvertIPAddressOrder(DWORD address);
  135. // This function allocates an array of DWORDs and fills it with the IP addresses
  136. // from the StringList. The caller must free the returned pointer using
  137. // delete[]
  138. DWORD*
  139. StringIPListToDWORDArray(const StringList& stringIPList, DWORD& count);
  140. // Helper function for creating the INF file for unattended OCM installations
  141. void
  142. CreateInfFileText(
  143. String& infFileText,
  144. unsigned int windowTitleResourceID);
  145. // Helper function for creating the unattend file for unattended OCM installations
  146. void
  147. CreateUnattendFileText(
  148. String& unattendFileText,
  149. PCWSTR serviceName,
  150. bool install = true);
  151. // Opens the favorites folder and creates a favorite for
  152. // the specified URL
  153. HRESULT
  154. AddURLToFavorites(
  155. HWND hwnd,
  156. const String& url,
  157. const String& fileName);
  158. // Launches the specified MMC console
  159. // It assumes the console is in the %windir%\system32 directory
  160. // unless the alternatePath is specified
  161. void
  162. LaunchMMCConsole(
  163. const String& consoleFile,
  164. String& alternatePath = String());
  165. // Launches the Manage Your Server HTA
  166. void
  167. LaunchMYS();
  168. // Retrieves the path to the start menu for All Users
  169. HRESULT
  170. GetAllUsersStartMenu(
  171. String& startMenuPath);
  172. // Retrieves the path to the Administrative Tools menu for All Users
  173. HRESULT
  174. GetAllUsersAdminTools(
  175. String& adminToolsPath);
  176. // Creates a link (shortcut) at the specified location
  177. // with the specified target
  178. HRESULT
  179. CreateShortcut(
  180. const String& shortcutPath,
  181. const String& target,
  182. const String& description);
  183. // Takes a LPARAM from a WM_NOTIFY message from a SysLink control
  184. // and decodes it to return the link index
  185. int
  186. LinkIndexFromNotifyLPARAM(LPARAM lParam);
  187. // Starts the hh.exe process with the given parameter
  188. void
  189. ShowHelp(const String& helpTopic);
  190. // Opens the Configure Your Server logfile
  191. void
  192. OpenLogFile();
  193. // Returns true if the log file is present
  194. bool
  195. IsLogFilePresent();
  196. // Gets the path the "All Users" Administrative Tools
  197. // link in the Start Menu
  198. HRESULT
  199. GetAdminToolsShortcutPath(
  200. String& adminToolsShortcutPath,
  201. const String& linkToAppend);
  202. // Adds the given shortcut with description to the Administrative Tools
  203. // Start Menu with the given link
  204. HRESULT
  205. AddShortcutToAdminTools(
  206. const String& target,
  207. unsigned int descriptionID,
  208. unsigned int linkID);
  209. // Determines if a share should be considered special
  210. // "special" shares are those like C$, SYSVOL$, etc.
  211. bool
  212. IsSpecialShare(const SHARE_INFO_1& shareInfo);
  213. // Determines if there are any shared folders that are not "special"
  214. // "special" shares are those like C$, SYSVOL$, etc.
  215. bool
  216. IsNonSpecialSharePresent();