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.

474 lines
10 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. aBound.lLbound = 0;
  156. aBound.cElements = lpIISSrcObject->IISValue.value_5.Length;;
  157. if (bReturnBinaryAsVT_VARIANT)
  158. {
  159. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  160. }
  161. else
  162. {
  163. aList = SafeArrayCreate( VT_UI1, 1, &aBound );
  164. }
  165. if ( aList == NULL )
  166. {
  167. hr = E_OUTOFMEMORY;
  168. BAIL_ON_FAILURE(hr);
  169. }
  170. hr = SafeArrayAccessData( aList, (void HUGEP * FAR *) &pArray );
  171. BAIL_ON_FAILURE(hr);
  172. memcpy( pArray, lpIISSrcObject->IISValue.value_5.Binary, aBound.cElements );
  173. SafeArrayUnaccessData( aList );
  174. if (bReturnBinaryAsVT_VARIANT)
  175. {
  176. V_VT(lpVarDestObject) = VT_ARRAY | VT_VARIANT;
  177. }
  178. else
  179. {
  180. V_VT(lpVarDestObject) = VT_ARRAY | VT_UI1;
  181. }
  182. V_ARRAY(lpVarDestObject) = aList;
  183. RRETURN(hr);
  184. error:
  185. if ( aList )
  186. SafeArrayDestroy( aList );
  187. RRETURN(hr);
  188. }
  189. HRESULT
  190. IISTypeToVarTypeCopyIISSynIdNTACL(
  191. PIISOBJECT lpIISSrcObject,
  192. PVARIANT lpVarDestObject
  193. )
  194. {
  195. HRESULT hr = S_OK;
  196. lpVarDestObject->vt = VT_DISPATCH;
  197. hr = ConvertSecDescriptorToVariant(
  198. (PSECURITY_DESCRIPTOR)lpIISSrcObject->IISValue.value_5.Binary,
  199. lpVarDestObject
  200. );
  201. RRETURN(hr);
  202. }
  203. HRESULT
  204. IISTypeToVarTypeCopyIISSynIdIPSECLIST(
  205. PIISOBJECT lpIISSrcObject,
  206. PVARIANT lpVarDestObject
  207. )
  208. {
  209. HRESULT hr = S_OK;
  210. IISIPSecurity * pIPSec = NULL;
  211. hr = CIPSecurity::CreateIPSecurity(
  212. IID_IISIPSecurity,
  213. (VOID**) &pIPSec
  214. );
  215. BAIL_ON_FAILURE(hr);
  216. hr = ((CIPSecurity*)pIPSec)->InitFromBinaryBlob(
  217. lpIISSrcObject->IISValue.value_5.Binary,
  218. lpIISSrcObject->IISValue.value_5.Length);
  219. lpVarDestObject->vt = VT_DISPATCH;
  220. lpVarDestObject->pdispVal = pIPSec;
  221. error:
  222. RRETURN(hr);
  223. }
  224. HRESULT
  225. IISTypeToVarTypeCopy(
  226. IIsSchema *pSchema,
  227. LPWSTR pszPropertyName,
  228. PIISOBJECT lpIISSrcObject,
  229. PVARIANT lpVarDestObject,
  230. BOOL bReturnBinaryAsVT_VARIANT
  231. )
  232. {
  233. HRESULT hr = S_OK;
  234. switch (lpIISSrcObject->IISType) {
  235. case IIS_SYNTAX_ID_DWORD:
  236. hr = IISTypeToVarTypeCopyIISSynIdDWORD(
  237. pSchema,
  238. lpIISSrcObject,
  239. lpVarDestObject
  240. );
  241. break;
  242. case IIS_SYNTAX_ID_STRING:
  243. hr = IISTypeToVarTypeCopyIISSynIdSTRING(
  244. pSchema,
  245. lpIISSrcObject,
  246. lpVarDestObject
  247. );
  248. break;
  249. case IIS_SYNTAX_ID_EXPANDSZ:
  250. hr = IISTypeToVarTypeCopyIISSynIdEXPANDSZ(
  251. pSchema,
  252. lpIISSrcObject,
  253. lpVarDestObject
  254. );
  255. break;
  256. case IIS_SYNTAX_ID_MULTISZ:
  257. hr = IISTypeToVarTypeCopyIISSynIdMULTISZ(
  258. pSchema,
  259. lpIISSrcObject,
  260. lpVarDestObject
  261. );
  262. break;
  263. case IIS_SYNTAX_ID_BOOL:
  264. hr = IISTypeToVarTypeCopyIISSynIdBOOL(
  265. pSchema,
  266. lpIISSrcObject,
  267. lpVarDestObject
  268. );
  269. break;
  270. case IIS_SYNTAX_ID_BOOL_BITMASK:
  271. hr = IISTypeToVarTypeCopyIISSynIdBOOLBITMASK(
  272. pSchema,
  273. pszPropertyName,
  274. lpIISSrcObject,
  275. lpVarDestObject
  276. );
  277. break;
  278. case IIS_SYNTAX_ID_MIMEMAP:
  279. hr = IISTypeToVarTypeCopyIISSynIdMIMEMAP(
  280. pSchema,
  281. lpIISSrcObject,
  282. lpVarDestObject
  283. );
  284. break;
  285. case IIS_SYNTAX_ID_NTACL:
  286. hr = IISTypeToVarTypeCopyIISSynIdNTACL(
  287. lpIISSrcObject,
  288. lpVarDestObject
  289. );
  290. break;
  291. case IIS_SYNTAX_ID_BINARY:
  292. hr = IISTypeToVarTypeCopyIISSynIdBinary(
  293. lpIISSrcObject,
  294. lpVarDestObject,
  295. bReturnBinaryAsVT_VARIANT
  296. );
  297. break;
  298. case IIS_SYNTAX_ID_IPSECLIST:
  299. hr = IISTypeToVarTypeCopyIISSynIdIPSECLIST(
  300. lpIISSrcObject,
  301. lpVarDestObject
  302. );
  303. break;
  304. default:
  305. hr = E_FAIL;
  306. break;
  307. }
  308. RRETURN(hr);
  309. }
  310. HRESULT
  311. IISTypeToVarTypeCopyConstruct(
  312. IIsSchema *pSchema,
  313. LPWSTR pszPropertyName,
  314. LPIISOBJECT pIISSrcObjects,
  315. DWORD dwNumObjects,
  316. PVARIANT pVarDestObjects,
  317. BOOL bReturnBinaryAsVT_VARIANT
  318. )
  319. {
  320. long i = 0;
  321. HRESULT hr = S_OK;
  322. DWORD dwSyntaxId;
  323. dwSyntaxId = pIISSrcObjects->IISType;
  324. if (dwSyntaxId == IIS_SYNTAX_ID_BINARY ||
  325. dwSyntaxId == IIS_SYNTAX_ID_IPSECLIST ||
  326. dwSyntaxId == IIS_SYNTAX_ID_NTACL) {
  327. hr = IISTypeToVarTypeCopy( pSchema,
  328. pszPropertyName,
  329. pIISSrcObjects,
  330. pVarDestObjects,
  331. bReturnBinaryAsVT_VARIANT);
  332. RRETURN(hr);
  333. }
  334. VariantInit(pVarDestObjects);
  335. //
  336. // Check to see if IISType is a Multi-sz w/ only 1 empty string element
  337. //
  338. if (dwNumObjects == 1 &&
  339. (pIISSrcObjects->IISType == IIS_SYNTAX_ID_MULTISZ ||
  340. pIISSrcObjects->IISType == IIS_SYNTAX_ID_MIMEMAP )) {
  341. if (*pIISSrcObjects->IISValue.value_4.MultiSz == L'\0') {
  342. dwNumObjects = 0;
  343. }
  344. }
  345. // The following are for handling are multi-value properties
  346. //
  347. SAFEARRAY *aList = NULL;
  348. SAFEARRAYBOUND aBound;
  349. aBound.lLbound = 0;
  350. aBound.cElements = dwNumObjects;
  351. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  352. if ( aList == NULL )
  353. {
  354. hr = E_OUTOFMEMORY;
  355. BAIL_ON_FAILURE(hr);
  356. }
  357. for ( i = 0; i < (long) dwNumObjects; i++ )
  358. {
  359. VARIANT v;
  360. VariantInit(&v);
  361. hr = IISTypeToVarTypeCopy( pSchema,
  362. pszPropertyName,
  363. pIISSrcObjects + i,
  364. &v,
  365. bReturnBinaryAsVT_VARIANT);
  366. BAIL_ON_FAILURE(hr);
  367. hr = SafeArrayPutElement( aList, &i, &v );
  368. VariantClear(&v);
  369. BAIL_ON_FAILURE(hr);
  370. }
  371. V_VT(pVarDestObjects) = VT_ARRAY | VT_VARIANT;
  372. V_ARRAY(pVarDestObjects) = aList;
  373. RRETURN(S_OK);
  374. error:
  375. if ( aList )
  376. SafeArrayDestroy( aList );
  377. RRETURN(hr);
  378. }