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.

526 lines
12 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1997.
  5. //
  6. // File: var2IIS.cxx
  7. //
  8. // Contents: IIS Object to Variant Copy Routines
  9. //
  10. // Functions:
  11. //
  12. // History: 01-Mar-97 SophiaC Created.
  13. //
  14. // Issues: Check null ptrs for AllocADsMem and AllocADsStr
  15. //
  16. //----------------------------------------------------------------------------
  17. #include "iis.hxx"
  18. //
  19. // IISType objects copy code
  20. //
  21. HRESULT
  22. VarTypeToIISTypeCopyIISSynIdDWORD(
  23. PVARIANT lpVarSrcObject,
  24. PIISOBJECT lpIISDestObject
  25. )
  26. {
  27. HRESULT hr = S_OK;
  28. hr = VariantChangeType(lpVarSrcObject,
  29. lpVarSrcObject,
  30. 0,
  31. VT_UI4);
  32. if (FAILED(hr)) {
  33. if (hr == E_OUTOFMEMORY) {
  34. RRETURN(hr);
  35. }
  36. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  37. }
  38. lpIISDestObject->IISType = IIS_SYNTAX_ID_DWORD;
  39. lpIISDestObject->IISValue.value_1.dwDWORD =
  40. lpVarSrcObject->lVal;
  41. RRETURN(hr);
  42. }
  43. HRESULT
  44. VarTypeToIISTypeCopyIISSynIdSTRING(
  45. PVARIANT lpVarSrcObject,
  46. PIISOBJECT lpIISDestObject
  47. )
  48. {
  49. HRESULT hr = S_OK;
  50. hr = VariantChangeType(lpVarSrcObject,
  51. lpVarSrcObject,
  52. 0,
  53. VT_BSTR);
  54. if (FAILED(hr)) {
  55. if (hr == E_OUTOFMEMORY) {
  56. RRETURN(hr);
  57. }
  58. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  59. }
  60. lpIISDestObject->IISType = IIS_SYNTAX_ID_STRING;
  61. lpIISDestObject->IISValue.value_2.String =
  62. AllocADsStr(
  63. lpVarSrcObject->bstrVal
  64. );
  65. RRETURN(hr);
  66. }
  67. HRESULT
  68. VarTypeToIISTypeCopyIISSynIdEXPANDSZ(
  69. PVARIANT lpVarSrcObject,
  70. PIISOBJECT lpIISDestObject
  71. )
  72. {
  73. HRESULT hr = S_OK;
  74. hr = VariantChangeType(lpVarSrcObject,
  75. lpVarSrcObject,
  76. 0,
  77. VT_BSTR);
  78. if (FAILED(hr)) {
  79. if (hr == E_OUTOFMEMORY) {
  80. RRETURN(hr);
  81. }
  82. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  83. }
  84. lpIISDestObject->IISType = IIS_SYNTAX_ID_EXPANDSZ;
  85. lpIISDestObject->IISValue.value_3.ExpandSz =
  86. AllocADsStr(
  87. lpVarSrcObject->bstrVal
  88. );
  89. RRETURN(hr);
  90. }
  91. HRESULT
  92. VarTypeToIISTypeCopyIISSynIdMULTISZ(
  93. PVARIANT lpVarSrcObject,
  94. PIISOBJECT lpIISDestObject
  95. )
  96. {
  97. HRESULT hr = S_OK;
  98. hr = VariantChangeType(lpVarSrcObject,
  99. lpVarSrcObject,
  100. 0,
  101. VT_BSTR);
  102. if (FAILED(hr)) {
  103. if (hr == E_OUTOFMEMORY) {
  104. RRETURN(hr);
  105. }
  106. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  107. }
  108. lpIISDestObject->IISType = IIS_SYNTAX_ID_MULTISZ;
  109. lpIISDestObject->IISValue.value_4.MultiSz =
  110. AllocADsStr(
  111. lpVarSrcObject->bstrVal
  112. );
  113. RRETURN(hr);
  114. }
  115. HRESULT
  116. VarTypeToIISTypeCopyIISSynIdMIMEMAP(
  117. PVARIANT lpVarSrcObject,
  118. PIISOBJECT lpIISDestObject
  119. )
  120. {
  121. HRESULT hr = S_OK;
  122. LPWSTR pszStr;
  123. IISMimeType * pMimeType = NULL;
  124. if(lpVarSrcObject->vt != VT_DISPATCH){
  125. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  126. }
  127. lpIISDestObject->IISType = IIS_SYNTAX_ID_MIMEMAP;
  128. pMimeType = (IISMimeType *)lpVarSrcObject->pdispVal;
  129. hr = ((CMimeType*) pMimeType)->CopyMimeType(
  130. &pszStr
  131. );
  132. BAIL_ON_FAILURE(hr);
  133. lpIISDestObject->IISValue.value_6.MimeMap = pszStr;
  134. error:
  135. RRETURN(hr);
  136. }
  137. HRESULT
  138. VarTypeToIISTypeCopyIISSynIdBinary(
  139. PVARIANT lpVarSrcObject,
  140. PIISOBJECT lpIISDestObject,
  141. BOOL bReturnBinaryAsVT_VARIANT
  142. )
  143. {
  144. HRESULT hr = S_OK;
  145. LONG dwSLBound = 0;
  146. LONG dwSUBound = 0;
  147. CHAR HUGEP *pArray = NULL;
  148. if (bReturnBinaryAsVT_VARIANT)
  149. {
  150. hr = VariantChangeType(lpVarSrcObject,lpVarSrcObject,0,VT_ARRAY | VT_VARIANT);
  151. }
  152. else
  153. {
  154. hr = VariantChangeType(lpVarSrcObject,lpVarSrcObject,0,VT_ARRAY | VT_UI1);
  155. }
  156. if (FAILED(hr)) {
  157. if (hr == E_OUTOFMEMORY) {
  158. RRETURN(hr);
  159. }
  160. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  161. }
  162. if (bReturnBinaryAsVT_VARIANT)
  163. {
  164. if( lpVarSrcObject->vt != (VT_ARRAY | VT_VARIANT)) {
  165. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  166. }
  167. }
  168. else
  169. {
  170. if( lpVarSrcObject->vt != (VT_ARRAY | VT_UI1)) {
  171. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  172. }
  173. }
  174. hr = SafeArrayGetLBound(V_ARRAY(lpVarSrcObject),1,(long FAR *) &dwSLBound );
  175. BAIL_ON_FAILURE(hr);
  176. hr = SafeArrayGetUBound(V_ARRAY(lpVarSrcObject),1,(long FAR *) &dwSUBound );
  177. BAIL_ON_FAILURE(hr);
  178. lpIISDestObject->IISValue.value_5.Binary = (LPBYTE) AllocADsMem(dwSUBound - dwSLBound + 1);
  179. if (lpIISDestObject->IISValue.value_5.Binary == NULL)
  180. {
  181. hr = E_OUTOFMEMORY;
  182. BAIL_ON_FAILURE(hr);
  183. }
  184. lpIISDestObject->IISType = IIS_SYNTAX_ID_BINARY;
  185. lpIISDestObject->IISValue.value_5.Length = dwSUBound - dwSLBound + 1;
  186. hr = SafeArrayAccessData( V_ARRAY(lpVarSrcObject),(void HUGEP * FAR *) &pArray );
  187. BAIL_ON_FAILURE(hr);
  188. memcpy( lpIISDestObject->IISValue.value_5.Binary,pArray,dwSUBound-dwSLBound+1);
  189. SafeArrayUnaccessData( V_ARRAY(lpVarSrcObject) );
  190. error:
  191. RRETURN(hr);
  192. }
  193. HRESULT
  194. VarTypeToIISTypeCopyIISSynIdNTACL(
  195. PVARIANT lpVarSrcObject,
  196. PIISOBJECT lpIISDestObject
  197. )
  198. {
  199. HRESULT hr = S_OK;
  200. IADsSecurityDescriptor FAR * pSecDes = NULL;
  201. PSECURITY_DESCRIPTOR pSecurityDescriptor = NULL;
  202. DWORD Length = 0;
  203. IDispatch FAR * pDispatch = NULL;
  204. if(lpVarSrcObject->vt != VT_DISPATCH){
  205. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  206. }
  207. lpIISDestObject->IISType = IIS_SYNTAX_ID_BINARY;
  208. pDispatch = V_DISPATCH(lpVarSrcObject);
  209. hr = pDispatch->QueryInterface(
  210. IID_IADsSecurityDescriptor,
  211. (void **)&pSecDes
  212. );
  213. BAIL_ON_FAILURE(hr);
  214. hr = ConvertSecurityDescriptorToSecDes(
  215. pSecDes,
  216. &pSecurityDescriptor,
  217. &Length
  218. );
  219. BAIL_ON_FAILURE(hr);
  220. lpIISDestObject->IISValue.value_5.Binary = (LPBYTE)AllocADsMem(Length);
  221. if ((lpIISDestObject->IISValue.value_5.Binary) == NULL) {
  222. hr = E_OUTOFMEMORY;
  223. BAIL_ON_FAILURE(hr);
  224. }
  225. lpIISDestObject->IISValue.value_5.Length = Length;
  226. memcpy(lpIISDestObject->IISValue.value_5.Binary, pSecurityDescriptor,
  227. Length);
  228. error:
  229. if (pSecDes) {
  230. pSecDes->Release();
  231. }
  232. RRETURN(hr);
  233. }
  234. HRESULT
  235. VarTypeToIISTypeCopyIISSynIdIPSECLIST(
  236. PVARIANT lpVarSrcObject,
  237. PIISOBJECT lpIISDestObject
  238. )
  239. {
  240. HRESULT hr = S_OK;
  241. LPBYTE pBuffer;
  242. DWORD Length = 0;
  243. IISIPSecurity * pIPSec = NULL;
  244. if(lpVarSrcObject->vt != VT_DISPATCH){
  245. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  246. }
  247. lpIISDestObject->IISType = IIS_SYNTAX_ID_IPSECLIST;
  248. pIPSec = (IISIPSecurity*)lpVarSrcObject->pdispVal;
  249. hr = ((CIPSecurity*) pIPSec)->CopyIPSecurity(
  250. &pBuffer,
  251. &Length
  252. );
  253. if (pBuffer == NULL) {
  254. RRETURN(E_OUTOFMEMORY);
  255. }
  256. lpIISDestObject->IISValue.value_5.Length = Length;
  257. lpIISDestObject->IISValue.value_5.Binary = (LPBYTE)AllocADsMem(Length);
  258. memcpy(lpIISDestObject->IISValue.value_5.Binary, pBuffer, Length);
  259. RRETURN(hr);
  260. }
  261. HRESULT
  262. VarTypeToIISTypeCopyIISSynIdBOOL(
  263. PVARIANT lpVarSrcObject,
  264. PIISOBJECT lpIISDestObject
  265. )
  266. {
  267. HRESULT hr = S_OK;
  268. hr = VariantChangeType(lpVarSrcObject,
  269. lpVarSrcObject,
  270. 0,
  271. VT_BOOL);
  272. if (FAILED(hr)) {
  273. if (hr == E_OUTOFMEMORY) {
  274. RRETURN(hr);
  275. }
  276. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  277. }
  278. lpIISDestObject->IISType = IIS_SYNTAX_ID_BOOL;
  279. lpIISDestObject->IISValue.value_1.dwDWORD =
  280. (lpVarSrcObject->boolVal) ? 1 : 0;
  281. RRETURN(hr);
  282. }
  283. HRESULT
  284. VarTypeToIISTypeCopyIISSynIdBOOLBITMASK(
  285. PVARIANT lpVarSrcObject,
  286. PIISOBJECT lpIISDestObject
  287. )
  288. {
  289. HRESULT hr = S_OK;
  290. hr = VariantChangeType(lpVarSrcObject,
  291. lpVarSrcObject,
  292. 0,
  293. VT_BOOL);
  294. if (FAILED(hr)) {
  295. if (hr == E_OUTOFMEMORY) {
  296. RRETURN(hr);
  297. }
  298. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  299. }
  300. lpIISDestObject->IISType = IIS_SYNTAX_ID_BOOL_BITMASK;
  301. lpIISDestObject->IISValue.value_1.dwDWORD =
  302. (lpVarSrcObject->boolVal) ? 1 : 0;
  303. RRETURN(hr);
  304. }
  305. HRESULT
  306. VarTypeToIISTypeCopy(
  307. DWORD dwIISType,
  308. PVARIANT lpVarSrcObject,
  309. PIISOBJECT lpIISDestObject,
  310. BOOL bReturnBinaryAsVT_VARIANT
  311. )
  312. {
  313. HRESULT hr = S_OK;
  314. switch (dwIISType){
  315. case IIS_SYNTAX_ID_DWORD:
  316. hr = VarTypeToIISTypeCopyIISSynIdDWORD(
  317. lpVarSrcObject,
  318. lpIISDestObject
  319. );
  320. break;
  321. case IIS_SYNTAX_ID_STRING:
  322. hr = VarTypeToIISTypeCopyIISSynIdSTRING(
  323. lpVarSrcObject,
  324. lpIISDestObject
  325. );
  326. break;
  327. case IIS_SYNTAX_ID_EXPANDSZ:
  328. hr = VarTypeToIISTypeCopyIISSynIdEXPANDSZ(
  329. lpVarSrcObject,
  330. lpIISDestObject
  331. );
  332. break;
  333. case IIS_SYNTAX_ID_MULTISZ:
  334. hr = VarTypeToIISTypeCopyIISSynIdMULTISZ(
  335. lpVarSrcObject,
  336. lpIISDestObject
  337. );
  338. break;
  339. case IIS_SYNTAX_ID_MIMEMAP:
  340. hr = VarTypeToIISTypeCopyIISSynIdMIMEMAP(
  341. lpVarSrcObject,
  342. lpIISDestObject
  343. );
  344. break;
  345. case IIS_SYNTAX_ID_NTACL:
  346. hr = VarTypeToIISTypeCopyIISSynIdNTACL(
  347. lpVarSrcObject,
  348. lpIISDestObject
  349. );
  350. break;
  351. case IIS_SYNTAX_ID_BINARY:
  352. hr = VarTypeToIISTypeCopyIISSynIdBinary(
  353. lpVarSrcObject,
  354. lpIISDestObject,
  355. bReturnBinaryAsVT_VARIANT
  356. );
  357. break;
  358. case IIS_SYNTAX_ID_IPSECLIST:
  359. hr = VarTypeToIISTypeCopyIISSynIdIPSECLIST(
  360. lpVarSrcObject,
  361. lpIISDestObject
  362. );
  363. break;
  364. case IIS_SYNTAX_ID_BOOL:
  365. hr = VarTypeToIISTypeCopyIISSynIdBOOL(
  366. lpVarSrcObject,
  367. lpIISDestObject
  368. );
  369. break;
  370. case IIS_SYNTAX_ID_BOOL_BITMASK:
  371. hr = VarTypeToIISTypeCopyIISSynIdBOOLBITMASK(
  372. lpVarSrcObject,
  373. lpIISDestObject
  374. );
  375. break;
  376. default:
  377. hr = E_FAIL;
  378. break;
  379. }
  380. RRETURN(hr);
  381. }
  382. HRESULT
  383. VarTypeToIISTypeCopyConstruct(
  384. DWORD dwIISType,
  385. LPVARIANT pVarSrcObjects,
  386. DWORD dwNumObjects,
  387. LPIISOBJECT * ppIISDestObjects,
  388. BOOL bReturnBinaryAsVT_VARIANT
  389. )
  390. {
  391. DWORD i = 0;
  392. LPIISOBJECT pIISDestObjects = NULL;
  393. HRESULT hr = S_OK;
  394. pIISDestObjects = (LPIISOBJECT)AllocADsMem(
  395. dwNumObjects * sizeof(IISOBJECT)
  396. );
  397. if (!pIISDestObjects) {
  398. RRETURN(E_FAIL);
  399. }
  400. for (i = 0; i < dwNumObjects; i++ ) {
  401. hr = VarTypeToIISTypeCopy(
  402. dwIISType,
  403. pVarSrcObjects + i,
  404. pIISDestObjects + i,
  405. bReturnBinaryAsVT_VARIANT
  406. );
  407. BAIL_ON_FAILURE(hr);
  408. }
  409. *ppIISDestObjects = pIISDestObjects;
  410. RRETURN(S_OK);
  411. error:
  412. if (pIISDestObjects) {
  413. IISTypeFreeIISObjects(
  414. pIISDestObjects,
  415. dwNumObjects
  416. );
  417. }
  418. *ppIISDestObjects = NULL;
  419. RRETURN(hr);
  420. }