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.

388 lines
9.1 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1997
  5. //
  6. // File: cenumobj.cxx
  7. //
  8. // Contents: IIS Object Enumeration Code
  9. //
  10. // CIISGenObjectEnum::CIISGenObjectEnum()
  11. // CIISGenObjectEnum::CIISGenObjectEnum
  12. // CIISGenObjectEnum::Create
  13. // CIISGenObjectEnum::GetGenObjects
  14. // CIISGenObjectEnum::EnumGenericObjects
  15. // CIISGenObjectEnum::Next
  16. //
  17. // History: 28-Feb-97 SophiaC Created.
  18. //----------------------------------------------------------------------------
  19. #include "iis.hxx"
  20. #pragma hdrstop
  21. //+---------------------------------------------------------------------------
  22. //
  23. // Function: CIISEnumVariant::Create
  24. //
  25. // Synopsis:
  26. //
  27. // Arguments: [pCollection]
  28. // [ppEnumVariant]
  29. //
  30. // Returns: HRESULT
  31. //
  32. // Modifies:
  33. //
  34. // History:
  35. //
  36. //----------------------------------------------------------------------------
  37. /* INTRINSA suppress=null_pointers, uninitialized */
  38. HRESULT
  39. CIISGenObjectEnum::Create(
  40. CIISGenObjectEnum FAR* FAR* ppenumvariant,
  41. BSTR ADsPath,
  42. VARIANT var,
  43. CCredentials& Credentials
  44. )
  45. {
  46. HRESULT hr = NOERROR;
  47. CIISGenObjectEnum FAR* penumvariant = NULL;
  48. LPWSTR pszIISPathName = NULL;
  49. DWORD dwStatus = 0;
  50. OBJECTINFO ObjectInfo;
  51. POBJECTINFO pObjectInfo = NULL;
  52. CLexer Lexer(ADsPath);
  53. *ppenumvariant = NULL;
  54. penumvariant = new CIISGenObjectEnum();
  55. if (!penumvariant) {
  56. hr = E_OUTOFMEMORY;
  57. BAIL_ON_FAILURE(hr);
  58. }
  59. hr = ADsAllocString( ADsPath, &penumvariant->_ADsPath);
  60. BAIL_ON_FAILURE(hr);
  61. //
  62. // Parse the pathname
  63. //
  64. pObjectInfo = &ObjectInfo;
  65. memset(pObjectInfo, 0, sizeof(OBJECTINFO));
  66. hr = ADsObject(&Lexer, pObjectInfo);
  67. BAIL_ON_FAILURE(hr);
  68. penumvariant->_Credentials = Credentials;
  69. *ppenumvariant = penumvariant;
  70. //
  71. // Store ServerName
  72. //
  73. penumvariant->_pszServerName = AllocADsStr(pObjectInfo->TreeName);
  74. if (!(penumvariant->_pszServerName)) {
  75. hr = E_OUTOFMEMORY;
  76. BAIL_ON_FAILURE(hr);
  77. }
  78. hr = InitServerInfo(Credentials,
  79. penumvariant->_pszServerName,
  80. &(penumvariant->_pAdminBase),
  81. &(penumvariant->_pSchema));
  82. BAIL_ON_FAILURE(hr);
  83. pszIISPathName = AllocADsStr(ADsPath);
  84. if (!pszIISPathName) {
  85. hr = E_OUTOFMEMORY;
  86. BAIL_ON_FAILURE(hr);
  87. }
  88. memset(pszIISPathName, 0, sizeof(pszIISPathName));
  89. hr = BuildIISPathFromADsPath(
  90. pObjectInfo,
  91. pszIISPathName
  92. );
  93. BAIL_ON_FAILURE(hr);
  94. penumvariant->_pszMetaBasePath = AllocADsStr(pszIISPathName);
  95. if (!(penumvariant->_pszMetaBasePath)) {
  96. hr = E_OUTOFMEMORY;
  97. BAIL_ON_FAILURE(hr);
  98. }
  99. error:
  100. if (FAILED(hr)) {
  101. if (penumvariant) {
  102. delete penumvariant;
  103. *ppenumvariant = NULL;
  104. }
  105. }
  106. if (pszIISPathName) {
  107. FreeADsStr(pszIISPathName);
  108. }
  109. FreeObjectInfo(pObjectInfo);
  110. RRETURN(hr);
  111. }
  112. CIISGenObjectEnum::CIISGenObjectEnum():
  113. _ADsPath(NULL),
  114. _pszServerName(NULL),
  115. _pSchema(NULL),
  116. _pAdminBase(NULL),
  117. _pszMetaBasePath(NULL)
  118. {
  119. _dwObjectCurrentEntry = 0;
  120. }
  121. CIISGenObjectEnum::~CIISGenObjectEnum()
  122. {
  123. if (_ADsPath) {
  124. ADsFreeString(_ADsPath);
  125. }
  126. if (_pszServerName) {
  127. FreeADsStr(_pszServerName);
  128. }
  129. if (_pszMetaBasePath){
  130. FreeADsStr(_pszMetaBasePath);
  131. }
  132. //
  133. // Release everything
  134. //
  135. }
  136. HRESULT
  137. CIISGenObjectEnum::EnumGenericObjects(
  138. ULONG cElements,
  139. VARIANT FAR* pvar,
  140. ULONG FAR* pcElementFetched
  141. )
  142. {
  143. HRESULT hr = S_OK;
  144. IDispatch *pDispatch = NULL;
  145. DWORD i = 0;
  146. while (i < cElements ) {
  147. hr = GetGenObject(&pDispatch);
  148. if (FAILED(hr)) {
  149. continue;
  150. }
  151. if (hr == S_FALSE) {
  152. break;
  153. }
  154. VariantInit(&pvar[i]);
  155. pvar[i].vt = VT_DISPATCH;
  156. pvar[i].pdispVal = pDispatch;
  157. (*pcElementFetched)++;
  158. i++;
  159. }
  160. return(hr);
  161. }
  162. /* #pragma INTRINSA suppress=all */
  163. HRESULT
  164. CIISGenObjectEnum::GetGenObject(
  165. IDispatch ** ppDispatch
  166. )
  167. {
  168. HRESULT hr = S_OK;
  169. WCHAR NameBuf[MAX_PATH];
  170. WCHAR DataBuf[MAX_PATH];
  171. DWORD dwStatus = 0;
  172. DWORD dwReqdBufferLen;
  173. METADATA_HANDLE hObjHandle = NULL;
  174. METADATA_RECORD mdrData;
  175. IADs * pADs = NULL;
  176. *ppDispatch = NULL;
  177. if (!_pAdminBase)
  178. {
  179. hr = InitServerInfo(_Credentials, _pszServerName, &_pAdminBase, &_pSchema);
  180. BAIL_ON_FAILURE(hr);
  181. }
  182. hr = OpenAdminBaseKey(
  183. _Credentials,
  184. _pszServerName,
  185. _pszMetaBasePath,
  186. METADATA_PERMISSION_READ,
  187. &_pAdminBase,
  188. &hObjHandle
  189. );
  190. BAIL_ON_FAILURE(hr);
  191. hr = _pAdminBase->EnumKeys(
  192. hObjHandle,
  193. L"",
  194. (LPWSTR)NameBuf,
  195. _dwObjectCurrentEntry
  196. );
  197. BAIL_ON_FAILURE(hr);
  198. //
  199. // Find out Class Name
  200. //
  201. mdrData.dwMDIdentifier = MD_KEY_TYPE;
  202. mdrData.dwMDDataType = STRING_METADATA;
  203. mdrData.dwMDUserType = ALL_METADATA;
  204. mdrData.dwMDAttributes = METADATA_INHERIT;
  205. mdrData.dwMDDataLen = MAX_PATH;
  206. mdrData.pbMDData = (PBYTE)DataBuf;
  207. hr = _pAdminBase->GetData(
  208. hObjHandle,
  209. (LPWSTR)NameBuf,
  210. &mdrData,
  211. &dwReqdBufferLen
  212. );
  213. if (FAILED(hr)) {
  214. if (hr == MD_ERROR_DATA_NOT_FOUND) {
  215. LPWSTR pszIISPath;
  216. pszIISPath = _wcsupr((LPWSTR)_pszMetaBasePath);
  217. if (wcsstr(pszIISPath, L"W3SVC") != NULL) {
  218. memcpy((LPWSTR)DataBuf, WEBDIR_CLASS_W,
  219. SIZEOF_WEBDIR_CLASS_W);
  220. }
  221. else if (wcsstr(pszIISPath, L"MSFTPSVC") != NULL) {
  222. memcpy((LPWSTR)DataBuf, FTPVDIR_CLASS_W,
  223. SIZEOF_FTPVDIR_CLASS_W);
  224. }
  225. else {
  226. memcpy((LPWSTR)DataBuf, DEFAULT_SCHEMA_CLASS_W,
  227. SIZEOF_DEFAULT_CLASS_W);
  228. }
  229. }
  230. else {
  231. BAIL_ON_FAILURE(hr);
  232. }
  233. }
  234. else {
  235. hr = _pSchema->ValidateClassName((LPWSTR)DataBuf);
  236. if (hr == E_ADS_SCHEMA_VIOLATION) {
  237. memcpy((LPWSTR)DataBuf, DEFAULT_SCHEMA_CLASS_W,
  238. SIZEOF_DEFAULT_CLASS_W);
  239. }
  240. }
  241. //
  242. // Bump up the object count. The instantiation of this object
  243. // may fail; if we come into this function again, we do not want
  244. // to pick up the same object.
  245. //
  246. _dwObjectCurrentEntry++;
  247. hr = CIISGenObject::CreateGenericObject(
  248. _ADsPath,
  249. (LPWSTR)NameBuf,
  250. (LPWSTR)DataBuf,
  251. _Credentials,
  252. ADS_OBJECT_BOUND,
  253. IID_IDispatch,
  254. (void **)&pADs
  255. );
  256. BAIL_ON_FAILURE(hr);
  257. hr = pADs->QueryInterface(
  258. IID_IDispatch,
  259. (void**)ppDispatch
  260. );
  261. error:
  262. if (_pAdminBase && hObjHandle) {
  263. CloseAdminBaseKey(_pAdminBase, hObjHandle);
  264. }
  265. if (pADs) {
  266. pADs->Release();
  267. }
  268. //
  269. // GetGenObject returns only S_FALSE
  270. //
  271. if (FAILED(hr)) {
  272. hr = S_FALSE;
  273. }
  274. RRETURN(hr);
  275. }
  276. //+---------------------------------------------------------------------------
  277. //
  278. // Function: CIISGenObjectEnum::Next
  279. //
  280. // Synopsis: Returns cElements number of requested NetOle objects in the
  281. // array supplied in pvar.
  282. //
  283. // Arguments: [cElements] -- The number of elements requested by client
  284. // [pvar] -- ptr to array of VARIANTs to for return objects
  285. // [pcElementFetched] -- if non-NULL, then number of elements
  286. // -- actually returned is placed here
  287. //
  288. // Returns: HRESULT -- S_OK if number of elements requested are returned
  289. // -- S_FALSE if number of elements is < requested
  290. //
  291. // Modifies:
  292. //
  293. // History: 11-3-95 krishnag Created.
  294. //
  295. //----------------------------------------------------------------------------
  296. STDMETHODIMP
  297. CIISGenObjectEnum::Next(
  298. ULONG cElements,
  299. VARIANT FAR* pvar,
  300. ULONG FAR* pcElementFetched
  301. )
  302. {
  303. ULONG cElementFetched = 0;
  304. HRESULT hr = S_OK;
  305. hr = EnumGenericObjects(
  306. cElements,
  307. pvar,
  308. &cElementFetched
  309. );
  310. if (pcElementFetched) {
  311. *pcElementFetched = cElementFetched;
  312. }
  313. RRETURN(hr);
  314. }