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.

379 lines
9.4 KiB

  1. /*++
  2. Copyright (c) 1992-1996 Microsoft Corporation
  3. Module Name:
  4. iisutil.h
  5. Abstract:
  6. IIS Resource utility routine DLL
  7. Author:
  8. Pete Benoit (v-pbenoi) 12-SEP-1996
  9. Revision History:
  10. --*/
  11. #ifndef IISUTIL_H
  12. #define IISUTIL_H
  13. #define UNICODE 1
  14. #if defined(__cplusplus)
  15. extern "C" {
  16. #endif
  17. #include "clusres.h"
  18. #include "wtypes.h"
  19. #include "iiscnfg.h"
  20. #include "iiscnfgp.h"
  21. #include "iiscl.h"
  22. #if defined(__cplusplus)
  23. } // extern "C"
  24. #endif
  25. #include <winsock2.h>
  26. #include <ole2.h>
  27. #include <iadm.h>
  28. extern PLOG_EVENT_ROUTINE g_IISLogEvent;
  29. //#define IISLogEvent ClusResLogEvent
  30. //#define IISSetResourceStatus ClusResSetResourceStatus
  31. #if DBG
  32. //#define DBG_CANT_VERIFY
  33. //extern BOOL g_fDbgCantVerify;
  34. #endif
  35. #if 1
  36. #define _DEBUG_SUPPORT
  37. extern char debug_buffer[];
  38. extern FILE* debug_file;
  39. extern void InitDebug();
  40. #define DEBUG_BUFFER debug_buffer
  41. #define DECLARE_DEBUG_BUFFER char debug_buffer[256]; FILE *debug_file=NULL
  42. #define INIT_DEBUG InitDebug()
  43. #define TERMINATE_DEBUG if ( debug_file ) fclose(debug_file)
  44. extern void TimeStamp( FILE* );
  45. #define TR(a) { if ( debug_file ) {TimeStamp(debug_file); wsprintfA a; fputs(debug_buffer,debug_file); fflush(debug_file);} }
  46. #else
  47. #define DEBUG_BUFFER
  48. #define DECLARE_DEBUG_BUFFER
  49. #define INIT_DEBUG
  50. #define TERMINATE_DEBUG
  51. #define TR(a)
  52. #endif
  53. extern DWORD g_dwTlsCoInit;
  54. extern HANDLE g_hEventLog;
  55. #define SetCoInit( a ) TlsSetValue( g_dwTlsCoInit, (LPVOID)a )
  56. #define GetCoInit() (BOOL)(!!PtrToUlong(TlsGetValue( g_dwTlsCoInit )))
  57. // Define the Service Identifiers
  58. #define IIS_SERVICE_TYPE_W3 0
  59. #define IIS_SERVICE_TYPE_FTP 1
  60. #define IIS_SERVICE_TYPE_SMTP 2
  61. #define IIS_SERVICE_TYPE_NNTP 3
  62. #define MAX_SERVICE IIS_SERVICE_TYPE_NNTP + 1
  63. // Define the default ports for services
  64. const USHORT DEFAULT_PORT[MAX_SERVICE] =
  65. {
  66. 80, // W3
  67. 21, // FTP
  68. 25, // SMTP
  69. 119 // NNTP
  70. };
  71. // Define the resource type identifiers
  72. #define IIS_RESOURCE_TYPE 0
  73. #define SMTP_RESOURCE_TYPE 1
  74. #define NNTP_RESOURCE_TYPE 2
  75. #define MAX_RESOURCE_TYPE NNTP_RESOURCE_TYPE + 1
  76. // Define the resource type names
  77. const WCHAR RESOURCE_TYPE[MAX_RESOURCE_TYPE][MAX_PATH] =
  78. {
  79. L"IIS Server Instance",
  80. L"SMTP Server Instance",
  81. L"NNTP Server Instance"
  82. };
  83. // Define some max values
  84. #define SERVER_START_DELAY 1000 // 1 Second
  85. #define MAX_DEFAULT_WSTRING_SIZE 512 // Default string size
  86. #define MAX_RETRY 4 // 4 Retries
  87. #define MAX_MUTEX_WAIT 10*1000 // 10 seconds
  88. #define IP_ADDRESS_RESOURCE_NAME L"IP Address"
  89. #define CHECK_IS_ALIVE_CONNECT_TIMEOUT 10
  90. #define CHECK_IS_ALIVE_SEND_TIMEOUT 10
  91. #define CHECK_IS_ALIVE_SEND_TIMEOUT 10
  92. #define IIS_RESOURCE_SIGNATURE 0x75fc983b
  93. #define MB_TIMEOUT 5000
  94. #define SERVICE_START_MAX_POLL 30
  95. #define SERVICE_START_POLL_DELAY 1000
  96. #define IISCLUS_ONLINE_TIMEOUT 30 // 30 s
  97. #define IISCLUS_OFFLINE_TIMEOUT (60*3) // 3 minutes
  98. // Define parameters structure
  99. typedef struct _IIS_PARAMS {
  100. LPWSTR ServiceName;
  101. LPWSTR InstanceId;
  102. LPWSTR MDPath;
  103. DWORD ServiceType;
  104. } IIS_PARAMS, *PIIS_PARAMS;
  105. // Define the resource data structure
  106. typedef struct _IIS_RESOURCE {
  107. DWORD Signature;
  108. DWORD dwPort;
  109. SOCKADDR saServer;
  110. BOOL bAlive;
  111. LIST_ENTRY ListEntry;
  112. LPWSTR ResourceName;
  113. IIS_PARAMS Params;
  114. RESOURCE_HANDLE ResourceHandle;
  115. HKEY ParametersKey;
  116. CLUS_WORKER OnlineThread;
  117. CLUS_WORKER OfflineThread;
  118. CLUSTER_RESOURCE_STATE State;
  119. } IIS_RESOURCE, *LPIIS_RESOURCE;
  120. DWORD
  121. SetInstanceState(
  122. IN PCLUS_WORKER pWorker,
  123. IN LPIIS_RESOURCE ResourceEntry,
  124. IN RESOURCE_STATUS* presourceStatus,
  125. IN CLUSTER_RESOURCE_STATE TargetState,
  126. IN LPWSTR TargetStateString,
  127. IN DWORD dwMdPropControl,
  128. IN DWORD dwMdPropTarget
  129. );
  130. DWORD
  131. InstanceEnableCluster(
  132. LPWSTR pwszServiceName,
  133. LPWSTR pwszInstanceId
  134. );
  135. DWORD
  136. InstanceDisableCluster(
  137. LPWSTR pwszServiceName,
  138. LPWSTR pwszInstanceId
  139. );
  140. VOID
  141. DestructIISResource(
  142. IN LPIIS_RESOURCE ResourceEntry
  143. );
  144. VOID
  145. FreeIISResource(
  146. IN LPIIS_RESOURCE ResourceEntry
  147. );
  148. DWORD
  149. VerifyIISService(
  150. IN LPWSTR MDPath,
  151. IN DWORD ServiceType,
  152. IN DWORD dwPort,
  153. IN SOCKADDR saServer,
  154. IN PLOG_EVENT_ROUTINE LogEvent
  155. );
  156. DWORD
  157. GetServerBindings(
  158. LPWSTR MDPath,
  159. DWORD dwServiceType,
  160. SOCKADDR* psaServer,
  161. LPDWORD pdwPort
  162. );
  163. HRESOURCE
  164. ClusterGetResourceDependency(
  165. IN LPCWSTR ResourceName,
  166. IN LPCWSTR ResourceType,
  167. IN LPIIS_RESOURCE ResourceEntry,
  168. IN PLOG_EVENT_ROUTINE LogEvent
  169. );
  170. DWORD
  171. ResUtilSetSzProperty(
  172. IN HKEY RegistryKey,
  173. IN LPCWSTR PropName,
  174. IN LPCWSTR NewValue,
  175. IN OUT PWSTR * OutValue
  176. );
  177. DWORD
  178. WINAPI
  179. ResUtilReadProperties(
  180. IN HKEY RegistryKey,
  181. IN const PRESUTIL_PROPERTY_ITEM PropertyTable,
  182. IN OUT LPBYTE OutParams,
  183. IN RESOURCE_HANDLE ResourceHandle,
  184. IN PLOG_EVENT_ROUTINE LogEvent
  185. );
  186. class CMetaData {
  187. public:
  188. CMetaData() { m_hMB = NULL; }
  189. ~CMetaData() { Close(); }
  190. BOOL Open( LPWSTR pszPath,
  191. BOOL fReconnect = FALSE,
  192. DWORD dwFlags = METADATA_PERMISSION_READ );
  193. BOOL Close( VOID );
  194. BOOL SetData( LPWSTR pszPath,
  195. DWORD dwPropID,
  196. DWORD dwUserType,
  197. DWORD dwDataType,
  198. VOID * pvData,
  199. DWORD cbData,
  200. DWORD dwFlags = METADATA_INHERIT );
  201. BOOL GetData( LPWSTR pszPath,
  202. DWORD dwPropID,
  203. DWORD dwUserType,
  204. DWORD dwDataType,
  205. VOID * pvData,
  206. DWORD * cbData,
  207. DWORD dwFlags = METADATA_INHERIT );
  208. BOOL SetDword( LPWSTR pszPath,
  209. DWORD dwPropID,
  210. DWORD dwUserType,
  211. DWORD dwValue,
  212. DWORD dwFlags = METADATA_INHERIT )
  213. {
  214. return SetData( pszPath,
  215. dwPropID,
  216. dwUserType,
  217. DWORD_METADATA,
  218. (PVOID) &dwValue,
  219. sizeof( DWORD ),
  220. dwFlags );
  221. }
  222. BOOL GetDword( LPWSTR pszPath,
  223. DWORD dwPropID,
  224. DWORD dwUserType,
  225. DWORD * pdwValue,
  226. DWORD dwFlags = METADATA_INHERIT )
  227. {
  228. DWORD cb = sizeof(DWORD);
  229. return GetData( pszPath,
  230. dwPropID,
  231. dwUserType,
  232. DWORD_METADATA,
  233. pdwValue,
  234. &cb,
  235. dwFlags );
  236. }
  237. BOOL GetString( LPWSTR pszPath,
  238. DWORD dwPropID,
  239. DWORD dwUserType,
  240. WCHAR * pszValue,
  241. DWORD * pcbValue,
  242. DWORD dwFlags = METADATA_INHERIT )
  243. {
  244. return GetData( pszPath,
  245. dwPropID,
  246. dwUserType,
  247. STRING_METADATA,
  248. pszValue,
  249. pcbValue,
  250. dwFlags );
  251. }
  252. BOOL GetMultisz( LPWSTR pszPath,
  253. DWORD dwPropID,
  254. DWORD dwUserType,
  255. LPWSTR pszValue,
  256. DWORD* pcbValue,
  257. DWORD dwFlags = METADATA_INHERIT )
  258. {
  259. return GetData( pszPath,
  260. dwPropID,
  261. dwUserType,
  262. MULTISZ_METADATA,
  263. (LPVOID)pszValue,
  264. pcbValue,
  265. dwFlags );
  266. }
  267. static BOOL Init();
  268. static BOOL Terminate();
  269. BOOL GetMD();
  270. BOOL ReleaseMD();
  271. private:
  272. METADATA_HANDLE m_hMB;
  273. static IMSAdminBase* g_pMBCom;
  274. static CRITICAL_SECTION g_cs;
  275. } ;
  276. BOOL
  277. TcpSockSend(
  278. IN SOCKET sock,
  279. IN LPVOID pBuffer,
  280. IN DWORD cbBuffer,
  281. OUT PDWORD pcbTotalSent,
  282. IN DWORD nTimeout
  283. );
  284. BOOL
  285. TcpSockRecv(
  286. IN SOCKET sock,
  287. IN LPVOID pBuffer,
  288. IN DWORD cbBuffer,
  289. OUT LPDWORD pbReceived,
  290. IN DWORD nTimeout
  291. );
  292. INT
  293. WaitForSocketWorker(
  294. IN SOCKET sockRead,
  295. IN SOCKET sockWrite,
  296. IN LPBOOL pfRead,
  297. IN LPBOOL pfWrite,
  298. IN DWORD nTimeout
  299. );
  300. SOCKET
  301. TcpSockConnectToHost(
  302. SOCKADDR* psaServer,
  303. DWORD dwPort,
  304. DWORD dwTimeOut
  305. );
  306. VOID
  307. TcpSockClose(
  308. SOCKET hSocket
  309. );
  310. #endif