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.

359 lines
8.2 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997
  5. //
  6. // File: cenumns.cxx
  7. //
  8. // Contents: Windows NT 4.0 Enumerator Code
  9. //
  10. // CIISNamespaceEnum::Create
  11. // CIISNamespaceEnum::CIISNamespaceEnum
  12. // CIISNamespaceEnum::~CIISNamespaceEnum
  13. // CIISNamespaceEnum::Next
  14. // CIISNamespaceEnum::GetServerObject
  15. // CIISNamespaceEnum::EnumServerObjects
  16. //
  17. // History: 21-Feb-97 SophiaC Created.
  18. //----------------------------------------------------------------------------
  19. #include "iis.hxx"
  20. #include "charset.hxx"
  21. #pragma hdrstop
  22. #define ENUM_BUFFER_SIZE (1024 * 16)
  23. #define DEFAULT_ADMIN_SERVER_KEY \
  24. L"SOFTWARE\\Microsoft\\ADs\\Providers\\IIS\\"
  25. #define DEFAULT_ADMIN_SERVER_VALUE_KEY L"DefaultAdminServer"
  26. //+---------------------------------------------------------------------------
  27. //
  28. // Function: CIISNamespaceEnum::Create
  29. //
  30. // Synopsis:
  31. //
  32. // Arguments: [pCollection]
  33. // [ppEnumVariant]
  34. //
  35. // Returns: HRESULT
  36. //
  37. // Modifies:
  38. //
  39. // History:
  40. //
  41. //----------------------------------------------------------------------------
  42. HRESULT
  43. CIISNamespaceEnum::Create(
  44. CIISNamespaceEnum FAR* FAR* ppenumvariant,
  45. VARIANT var,
  46. CCredentials& Credentials
  47. )
  48. {
  49. HRESULT hr = S_OK;
  50. CIISNamespaceEnum FAR* penumvariant = NULL;
  51. penumvariant = new CIISNamespaceEnum();
  52. if (penumvariant == NULL){
  53. hr = E_OUTOFMEMORY;
  54. BAIL_ON_FAILURE(hr);
  55. }
  56. hr = ObjectTypeList::CreateObjectTypeList(
  57. var,
  58. &penumvariant->_pObjList
  59. );
  60. BAIL_ON_FAILURE(hr);
  61. penumvariant->_Credentials = Credentials;
  62. *ppenumvariant = penumvariant;
  63. RRETURN(hr);
  64. error:
  65. if (penumvariant) {
  66. delete penumvariant;
  67. }
  68. RRETURN(hr);
  69. }
  70. //+---------------------------------------------------------------------------
  71. //
  72. // Function: CIISNamespaceEnum::CIISNamespaceEnum
  73. //
  74. // Synopsis:
  75. //
  76. //
  77. // Arguments:
  78. //
  79. //
  80. // Returns:
  81. //
  82. // Modifies:
  83. //
  84. // History:
  85. //
  86. //----------------------------------------------------------------------------
  87. CIISNamespaceEnum::CIISNamespaceEnum()
  88. {
  89. _pObjList = NULL;
  90. _fRegistryRead = FALSE;
  91. bDone = false;
  92. //_lpServerList = NULL;
  93. //_iCurrentServer = 0;
  94. }
  95. //+---------------------------------------------------------------------------
  96. //
  97. // Function: CIISNamespaceEnum::~CIISNamespaceEnum
  98. //
  99. // Synopsis:
  100. //
  101. //
  102. // Arguments:
  103. //
  104. // Returns:
  105. //
  106. // Modifies:
  107. //
  108. // History:
  109. //
  110. //----------------------------------------------------------------------------
  111. CIISNamespaceEnum::~CIISNamespaceEnum()
  112. {
  113. if ( _pObjList )
  114. delete _pObjList;
  115. // FreeServerList();
  116. }
  117. //+---------------------------------------------------------------------------
  118. //
  119. // Function: CIISNamespaceEnum::Next
  120. //
  121. // Synopsis: Returns cElements number of requested ADs objects in the
  122. // array supplied in pvar.
  123. //
  124. // Arguments: [cElements] -- The number of elements requested by client
  125. // [pvar] -- ptr to array of VARIANTs to for return objects
  126. // [pcElementFetched] -- if non-NULL, then number of elements
  127. // -- actually returned is placed here
  128. //
  129. // Returns: HRESULT -- S_OK if number of elements requested are returned
  130. // -- S_FALSE if number of elements is < requested
  131. //
  132. // Modifies:
  133. //
  134. // History:
  135. //
  136. //----------------------------------------------------------------------------
  137. STDMETHODIMP
  138. CIISNamespaceEnum::Next(
  139. ULONG cElements,
  140. VARIANT FAR* pvar,
  141. ULONG FAR* pcElementFetched
  142. )
  143. {
  144. ULONG cElementFetched = 0;
  145. HRESULT hr = S_OK;
  146. hr = EnumServerObjects(
  147. cElements,
  148. pvar,
  149. &cElementFetched
  150. );
  151. if (pcElementFetched) {
  152. *pcElementFetched = cElementFetched;
  153. }
  154. RRETURN(hr);
  155. }
  156. //+---------------------------------------------------------------------------
  157. //
  158. // Function: CIISNamespaceEnum::Reset
  159. //
  160. // Synopsis: Resets the enumerator so that a new server list will
  161. // be generated on the next call to Next.
  162. //
  163. // Arguments: None.
  164. //
  165. // Returns: HRESULT -- S_OK if there was a previous server list
  166. // -- S_FALSE if there was not a previous server list
  167. //
  168. // Modifies:
  169. //
  170. // History:
  171. //
  172. //----------------------------------------------------------------------------
  173. STDMETHODIMP
  174. CIISNamespaceEnum::Reset(
  175. )
  176. {
  177. bDone = true;
  178. return (S_OK);
  179. }
  180. // Generate the server list and set flags
  181. HRESULT
  182. CIISNamespaceEnum::GenerateServerList()
  183. {
  184. RRETURN(E_NOTIMPL);
  185. // DWORD Error;
  186. //
  187. // ADsAssert(_lpServerList==NULL);
  188. //
  189. // Error = INetDiscoverServers(
  190. // INET_ALL_SERVICES_ID,
  191. // SVC_DEFAULT_WAIT_TIME,
  192. // &_lpServerList);
  193. //
  194. // if (Error != ERROR_SUCCESS) {
  195. // return HRESULT_FROM_WIN32(Error);
  196. // }
  197. //
  198. // // Set the current server to the first
  199. // _iCurrentServer = 0;
  200. //
  201. //
  202. // return S_OK;
  203. //
  204. }
  205. // Free the server list and set flags
  206. HRESULT
  207. CIISNamespaceEnum::FreeServerList(
  208. )
  209. {
  210. RRETURN(E_NOTIMPL);
  211. // if ( _lpServerList ) {
  212. // // _lpServerList is set to NULL
  213. // INetFreeDiscoverServersList(&_lpServerList); // void return
  214. // }
  215. // ADsAssert(_lpServerList==NULL);
  216. // return S_OK;
  217. }
  218. HRESULT
  219. CIISNamespaceEnum::EnumServerObjects(
  220. ULONG cElements,
  221. VARIANT FAR* pvar,
  222. ULONG FAR* pcElementFetched
  223. )
  224. {
  225. HRESULT hr = S_OK;
  226. IDispatch *pDispatch = NULL;
  227. DWORD i = 0;
  228. // perform this check once per call
  229. // if (!_lpServerList) { // generate server list
  230. // GenerateServerList();
  231. // }
  232. // we're only going to return a single element - localhost
  233. cElements = 1;
  234. while (i < cElements) {
  235. hr = GetServerObject(&pDispatch);
  236. BAIL_ON_FAILURE(hr);
  237. if (hr == S_FALSE) {
  238. break;
  239. }
  240. VariantInit(&pvar[i]);
  241. pvar[i].vt = VT_DISPATCH;
  242. pvar[i].pdispVal = pDispatch;
  243. (*pcElementFetched)++;
  244. i++;
  245. }
  246. // we've received the entire block or we have
  247. // reached the end of the list
  248. RRETURN(hr);
  249. error:
  250. // there was an error retrieving the current object
  251. RRETURN(hr);
  252. }
  253. /* #pragma INTRINSA suppress=all */
  254. HRESULT
  255. CIISNamespaceEnum::GetServerObject(
  256. IDispatch ** ppDispatch
  257. )
  258. {
  259. // HKEY hKey = NULL;
  260. // #if 0
  261. // WCHAR szServerName[MAX_PATH];
  262. // #endif
  263. WCHAR *lpwszServerName;
  264. HRESULT hr;
  265. char szServerName[10] = "localhost";
  266. UINT err;
  267. if (true == bDone)
  268. {
  269. RRETURN(S_FALSE);
  270. }
  271. // // while there are still more servers
  272. // if (_iCurrentServer < (_lpServerList->NumServers)) {
  273. // // get the next server name
  274. // lpszServerName = _lpServerList->Servers[_iCurrentServer]->ServerName;
  275. //
  276. // // convert the server name to unicode
  277. // #if 0
  278. // AnsiToUnicodeString(
  279. // lpszServerName,
  280. // szServerName,
  281. // strlen(lpszServerName));
  282. // #else
  283. err = AllocUnicode(szServerName, &lpwszServerName);
  284. if (err) {
  285. RRETURN( HRESULT_FROM_WIN32(err) );
  286. }
  287. // #endif
  288. //
  289. // // increment the current server index
  290. // ++_iCurrentServer;
  291. //
  292. // } else {
  293. // RRETURN(S_FALSE);
  294. // }
  295. //
  296. *ppDispatch = NULL;
  297. //
  298. // Now create and send back the current object
  299. //
  300. hr = CIISTree::CreateServerObject(
  301. L"IIS:",
  302. lpwszServerName,
  303. COMPUTER_CLASS_W,
  304. _Credentials,
  305. ADS_OBJECT_BOUND,
  306. IID_IDispatch,
  307. (void **)ppDispatch
  308. );
  309. BAIL_ON_FAILURE(hr);
  310. bDone = true;
  311. error:
  312. RRETURN_ENUM_STATUS(hr);
  313. }