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.

502 lines
11 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1997.
  5. //
  6. // File: iis2var.cxx
  7. //
  8. // Contents: IIS Object to Variant Copy Routines
  9. //
  10. // Functions:
  11. //
  12. // History: 05-Mar-97 SophiaC Created.
  13. //
  14. //
  15. // Issues: Check null ptrs for AllocADsMem and AllocADsStr
  16. //
  17. //
  18. //----------------------------------------------------------------------------
  19. #include "iis.hxx"
  20. //
  21. // IISType objects copy code
  22. //
  23. void
  24. VarTypeFreeVarObjects(
  25. PVARIANT pVarObject,
  26. DWORD dwNumValues
  27. )
  28. {
  29. DWORD i = 0;
  30. for (i = 0; i < dwNumValues; i++ ) {
  31. VariantClear(pVarObject + i);
  32. }
  33. FreeADsMem(pVarObject);
  34. return;
  35. }
  36. HRESULT
  37. IISTypeToVarTypeCopyIISSynIdDWORD(
  38. IIsSchema *pSchema,
  39. PIISOBJECT lpIISSrcObject,
  40. PVARIANT lpVarDestObject
  41. )
  42. {
  43. HRESULT hr = S_OK;
  44. lpVarDestObject->vt = VT_I4;
  45. lpVarDestObject->lVal = lpIISSrcObject->IISValue.value_1.dwDWORD;
  46. RRETURN(hr);
  47. }
  48. HRESULT
  49. IISTypeToVarTypeCopyIISSynIdSTRING(
  50. IIsSchema *pSchema,
  51. PIISOBJECT lpIISSrcObject,
  52. PVARIANT lpVarDestObject
  53. )
  54. {
  55. HRESULT hr = S_OK;
  56. lpVarDestObject->vt = VT_BSTR;
  57. hr = ADsAllocString(
  58. lpIISSrcObject->IISValue.value_2.String,
  59. &(lpVarDestObject->bstrVal)
  60. );
  61. RRETURN(hr);
  62. }
  63. HRESULT
  64. IISTypeToVarTypeCopyIISSynIdEXPANDSZ(
  65. IIsSchema *pSchema,
  66. PIISOBJECT lpIISSrcObject,
  67. PVARIANT lpVarDestObject
  68. )
  69. {
  70. HRESULT hr = S_OK;
  71. lpVarDestObject->vt = VT_BSTR;
  72. hr = ADsAllocString(
  73. lpIISSrcObject->IISValue.value_3.ExpandSz,
  74. &(lpVarDestObject->bstrVal)
  75. );
  76. RRETURN(hr);
  77. }
  78. HRESULT
  79. IISTypeToVarTypeCopyIISSynIdMULTISZ(
  80. IIsSchema *pSchema,
  81. PIISOBJECT lpIISSrcObject,
  82. PVARIANT lpVarDestObject
  83. )
  84. {
  85. HRESULT hr = S_OK;
  86. lpVarDestObject->vt = VT_BSTR;
  87. hr = ADsAllocString(
  88. lpIISSrcObject->IISValue.value_4.MultiSz,
  89. &(lpVarDestObject->bstrVal)
  90. );
  91. RRETURN(hr);
  92. }
  93. HRESULT
  94. IISTypeToVarTypeCopyIISSynIdBOOL(
  95. IIsSchema *pSchema,
  96. PIISOBJECT lpIISSrcObject,
  97. PVARIANT lpVarDestObject
  98. )
  99. {
  100. HRESULT hr = S_OK;
  101. lpVarDestObject->vt = VT_BOOL;
  102. lpVarDestObject->boolVal = lpIISSrcObject->IISValue.value_1.dwDWORD ?
  103. VARIANT_TRUE : VARIANT_FALSE;
  104. RRETURN(hr);
  105. }
  106. HRESULT
  107. IISTypeToVarTypeCopyIISSynIdBOOLBITMASK(
  108. IIsSchema *pSchema,
  109. LPWSTR pszPropertyName,
  110. PIISOBJECT lpIISSrcObject,
  111. PVARIANT lpVarDestObject
  112. )
  113. {
  114. HRESULT hr = S_OK;
  115. DWORD dwFlag = 0;
  116. pSchema->LookupBitMask(pszPropertyName, &dwFlag);
  117. lpVarDestObject->vt = VT_BOOL;
  118. lpVarDestObject->boolVal =
  119. (lpIISSrcObject->IISValue.value_1.dwDWORD) & dwFlag ?
  120. VARIANT_TRUE : VARIANT_FALSE;
  121. RRETURN(hr);
  122. }
  123. HRESULT
  124. IISTypeToVarTypeCopyIISSynIdMIMEMAP(
  125. IIsSchema *pSchema,
  126. PIISOBJECT lpIISSrcObject,
  127. PVARIANT lpVarDestObject
  128. )
  129. {
  130. HRESULT hr = S_OK;
  131. IISMimeType * pMimeType = NULL;
  132. hr = CMimeType::CreateMimeType(
  133. IID_IISMimeType,
  134. (VOID**) &pMimeType
  135. );
  136. BAIL_ON_FAILURE(hr);
  137. hr = ((CMimeType*)pMimeType)->InitFromIISString(
  138. lpIISSrcObject->IISValue.value_4.MultiSz);
  139. lpVarDestObject->vt = VT_DISPATCH;
  140. lpVarDestObject->pdispVal = pMimeType;
  141. error:
  142. RRETURN(hr);
  143. }
  144. HRESULT
  145. IISTypeToVarTypeCopyIISSynIdBinary(
  146. PIISOBJECT lpIISSrcObject,
  147. PVARIANT lpVarDestObject,
  148. BOOL bReturnBinaryAsVT_VARIANT
  149. )
  150. {
  151. HRESULT hr = S_OK;
  152. SAFEARRAY *aList = NULL;
  153. SAFEARRAYBOUND aBound;
  154. CHAR HUGEP *pArray = NULL;
  155. long i = 0;
  156. aBound.lLbound = 0;
  157. aBound.cElements = lpIISSrcObject->IISValue.value_5.Length;;
  158. if (bReturnBinaryAsVT_VARIANT)
  159. {
  160. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  161. }
  162. else
  163. {
  164. aList = SafeArrayCreate( VT_UI1, 1, &aBound );
  165. }
  166. if ( aList == NULL )
  167. {
  168. hr = E_OUTOFMEMORY;
  169. BAIL_ON_FAILURE(hr);
  170. }
  171. hr = SafeArrayAccessData( aList, (void HUGEP * FAR *) &pArray );
  172. BAIL_ON_FAILURE(hr);
  173. if (!bReturnBinaryAsVT_VARIANT)
  174. {
  175. memcpy( pArray, lpIISSrcObject->IISValue.value_5.Binary, aBound.cElements );
  176. }
  177. else
  178. {
  179. for (i = 0; (DWORD)i < aBound.cElements; i++ )
  180. {
  181. VARIANT v;
  182. WCHAR wVal[20];
  183. VariantInit(&v);
  184. V_VT(&v) = VT_BSTR;
  185. _itow(lpIISSrcObject->IISValue.value_5.Binary[i], wVal, 16);
  186. hr = ADsAllocString( wVal, &(V_BSTR(&v)));
  187. BAIL_ON_FAILURE(hr);
  188. hr = SafeArrayPutElement( aList, &i, &v );
  189. VariantClear(&v);
  190. BAIL_ON_FAILURE(hr);
  191. }
  192. }
  193. SafeArrayUnaccessData( aList );
  194. if (bReturnBinaryAsVT_VARIANT)
  195. {
  196. V_VT(lpVarDestObject) = VT_ARRAY | VT_VARIANT;
  197. }
  198. else
  199. {
  200. V_VT(lpVarDestObject) = VT_ARRAY | VT_UI1;
  201. }
  202. V_ARRAY(lpVarDestObject) = aList;
  203. RRETURN(hr);
  204. error:
  205. if ( aList )
  206. SafeArrayDestroy( aList );
  207. RRETURN(hr);
  208. }
  209. HRESULT
  210. IISTypeToVarTypeCopyIISSynIdNTACL(
  211. PIISOBJECT lpIISSrcObject,
  212. PVARIANT lpVarDestObject
  213. )
  214. {
  215. HRESULT hr = S_OK;
  216. lpVarDestObject->vt = VT_DISPATCH;
  217. hr = ConvertSecDescriptorToVariant(
  218. (PSECURITY_DESCRIPTOR)lpIISSrcObject->IISValue.value_5.Binary,
  219. lpVarDestObject
  220. );
  221. RRETURN(hr);
  222. }
  223. HRESULT
  224. IISTypeToVarTypeCopyIISSynIdIPSECLIST(
  225. PIISOBJECT lpIISSrcObject,
  226. PVARIANT lpVarDestObject
  227. )
  228. {
  229. HRESULT hr = S_OK;
  230. IISIPSecurity * pIPSec = NULL;
  231. hr = CIPSecurity::CreateIPSecurity(
  232. IID_IISIPSecurity,
  233. (VOID**) &pIPSec
  234. );
  235. BAIL_ON_FAILURE(hr);
  236. hr = ((CIPSecurity*)pIPSec)->InitFromBinaryBlob(
  237. lpIISSrcObject->IISValue.value_5.Binary,
  238. lpIISSrcObject->IISValue.value_5.Length);
  239. lpVarDestObject->vt = VT_DISPATCH;
  240. lpVarDestObject->pdispVal = pIPSec;
  241. error:
  242. RRETURN(hr);
  243. }
  244. HRESULT
  245. IISTypeToVarTypeCopy(
  246. IIsSchema *pSchema,
  247. LPWSTR pszPropertyName,
  248. PIISOBJECT lpIISSrcObject,
  249. PVARIANT lpVarDestObject,
  250. BOOL bReturnBinaryAsVT_VARIANT
  251. )
  252. {
  253. HRESULT hr = S_OK;
  254. switch (lpIISSrcObject->IISType) {
  255. case IIS_SYNTAX_ID_DWORD:
  256. hr = IISTypeToVarTypeCopyIISSynIdDWORD(
  257. pSchema,
  258. lpIISSrcObject,
  259. lpVarDestObject
  260. );
  261. break;
  262. case IIS_SYNTAX_ID_STRING:
  263. hr = IISTypeToVarTypeCopyIISSynIdSTRING(
  264. pSchema,
  265. lpIISSrcObject,
  266. lpVarDestObject
  267. );
  268. break;
  269. case IIS_SYNTAX_ID_EXPANDSZ:
  270. hr = IISTypeToVarTypeCopyIISSynIdEXPANDSZ(
  271. pSchema,
  272. lpIISSrcObject,
  273. lpVarDestObject
  274. );
  275. break;
  276. case IIS_SYNTAX_ID_MULTISZ:
  277. hr = IISTypeToVarTypeCopyIISSynIdMULTISZ(
  278. pSchema,
  279. lpIISSrcObject,
  280. lpVarDestObject
  281. );
  282. break;
  283. case IIS_SYNTAX_ID_BOOL:
  284. hr = IISTypeToVarTypeCopyIISSynIdBOOL(
  285. pSchema,
  286. lpIISSrcObject,
  287. lpVarDestObject
  288. );
  289. break;
  290. case IIS_SYNTAX_ID_BOOL_BITMASK:
  291. hr = IISTypeToVarTypeCopyIISSynIdBOOLBITMASK(
  292. pSchema,
  293. pszPropertyName,
  294. lpIISSrcObject,
  295. lpVarDestObject
  296. );
  297. break;
  298. case IIS_SYNTAX_ID_MIMEMAP:
  299. hr = IISTypeToVarTypeCopyIISSynIdMIMEMAP(
  300. pSchema,
  301. lpIISSrcObject,
  302. lpVarDestObject
  303. );
  304. break;
  305. case IIS_SYNTAX_ID_NTACL:
  306. hr = IISTypeToVarTypeCopyIISSynIdNTACL(
  307. lpIISSrcObject,
  308. lpVarDestObject
  309. );
  310. break;
  311. case IIS_SYNTAX_ID_BINARY:
  312. hr = IISTypeToVarTypeCopyIISSynIdBinary(
  313. lpIISSrcObject,
  314. lpVarDestObject,
  315. bReturnBinaryAsVT_VARIANT
  316. );
  317. break;
  318. case IIS_SYNTAX_ID_IPSECLIST:
  319. hr = IISTypeToVarTypeCopyIISSynIdIPSECLIST(
  320. lpIISSrcObject,
  321. lpVarDestObject
  322. );
  323. break;
  324. default:
  325. hr = E_FAIL;
  326. break;
  327. }
  328. RRETURN(hr);
  329. }
  330. HRESULT
  331. IISTypeToVarTypeCopyConstruct(
  332. IIsSchema *pSchema,
  333. LPWSTR pszPropertyName,
  334. LPIISOBJECT pIISSrcObjects,
  335. DWORD dwNumObjects,
  336. PVARIANT pVarDestObjects,
  337. BOOL bReturnBinaryAsVT_VARIANT
  338. )
  339. {
  340. long i = 0;
  341. HRESULT hr = S_OK;
  342. DWORD dwSyntaxId;
  343. dwSyntaxId = pIISSrcObjects->IISType;
  344. if (dwSyntaxId == IIS_SYNTAX_ID_BINARY ||
  345. dwSyntaxId == IIS_SYNTAX_ID_IPSECLIST ||
  346. dwSyntaxId == IIS_SYNTAX_ID_NTACL) {
  347. hr = IISTypeToVarTypeCopy( pSchema,
  348. pszPropertyName,
  349. pIISSrcObjects,
  350. pVarDestObjects,
  351. bReturnBinaryAsVT_VARIANT);
  352. RRETURN(hr);
  353. }
  354. VariantInit(pVarDestObjects);
  355. //
  356. // Check to see if IISType is a Multi-sz w/ only 1 empty string element
  357. //
  358. if (dwNumObjects == 1 &&
  359. (pIISSrcObjects->IISType == IIS_SYNTAX_ID_MULTISZ ||
  360. pIISSrcObjects->IISType == IIS_SYNTAX_ID_MIMEMAP )) {
  361. if (*pIISSrcObjects->IISValue.value_4.MultiSz == L'\0') {
  362. dwNumObjects = 0;
  363. }
  364. }
  365. // The following are for handling are multi-value properties
  366. //
  367. SAFEARRAY *aList = NULL;
  368. SAFEARRAYBOUND aBound;
  369. aBound.lLbound = 0;
  370. aBound.cElements = dwNumObjects;
  371. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  372. if ( aList == NULL )
  373. {
  374. hr = E_OUTOFMEMORY;
  375. BAIL_ON_FAILURE(hr);
  376. }
  377. for ( i = 0; i < (long) dwNumObjects; i++ )
  378. {
  379. VARIANT v;
  380. VariantInit(&v);
  381. hr = IISTypeToVarTypeCopy( pSchema,
  382. pszPropertyName,
  383. pIISSrcObjects + i,
  384. &v,
  385. bReturnBinaryAsVT_VARIANT);
  386. BAIL_ON_FAILURE(hr);
  387. hr = SafeArrayPutElement( aList, &i, &v );
  388. VariantClear(&v);
  389. BAIL_ON_FAILURE(hr);
  390. }
  391. V_VT(pVarDestObjects) = VT_ARRAY | VT_VARIANT;
  392. V_ARRAY(pVarDestObjects) = aList;
  393. RRETURN(S_OK);
  394. error:
  395. if ( aList )
  396. SafeArrayDestroy( aList );
  397. RRETURN(hr);
  398. }