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.

408 lines
7.1 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Abstract:
  4. Adds properties to ds
  5. Author:
  6. Steve Wilson (NT) December 1996
  7. Revision History:
  8. --*/
  9. #include <precomp.h>
  10. #pragma hdrstop
  11. #define VALIDATE_PTR(pPtr) \
  12. if (!pPtr) { \
  13. hr = E_ADS_BAD_PARAMETER;\
  14. }\
  15. BAIL_ON_FAILURE(hr);
  16. HRESULT
  17. put_BSTR_Property(
  18. IADs * pADsObject,
  19. BSTR bstrPropertyName,
  20. BSTR pSrcStringProperty
  21. )
  22. {
  23. HRESULT hr;
  24. VARIANT varInputData;
  25. hr = PackString2Variant(
  26. pSrcStringProperty,
  27. &varInputData
  28. );
  29. BAIL_ON_FAILURE(hr);
  30. if (!pSrcStringProperty || !*pSrcStringProperty) {
  31. hr = pADsObject->PutEx(
  32. ADS_PROPERTY_CLEAR,
  33. bstrPropertyName,
  34. varInputData
  35. );
  36. BAIL_ON_FAILURE(hr);
  37. } else {
  38. hr = pADsObject->Put(
  39. bstrPropertyName,
  40. varInputData
  41. );
  42. BAIL_ON_FAILURE(hr);
  43. }
  44. error:
  45. VariantClear(&varInputData);
  46. return hr;
  47. }
  48. HRESULT
  49. get_BSTR_Property(
  50. IADs *pADsObject,
  51. BSTR bstrPropertyName,
  52. BSTR *ppDestStringProperty
  53. )
  54. {
  55. HRESULT hr = S_OK;
  56. VARIANT varOutputData;
  57. VALIDATE_PTR( ppDestStringProperty );
  58. VariantInit( &varOutputData );
  59. hr = pADsObject->Get(
  60. bstrPropertyName,
  61. &varOutputData
  62. );
  63. BAIL_ON_FAILURE(hr);
  64. hr = UnpackStringfromVariant(
  65. varOutputData,
  66. ppDestStringProperty
  67. );
  68. BAIL_ON_FAILURE(hr);
  69. error:
  70. return hr;
  71. }
  72. HRESULT
  73. put_DWORD_Property(
  74. IADs *pADsObject,
  75. BSTR bstrPropertyName,
  76. DWORD *pdwSrcProperty
  77. )
  78. {
  79. HRESULT hr = S_OK;
  80. VARIANT varInputData;
  81. if (!pdwSrcProperty)
  82. return S_OK;
  83. hr = PackDWORD2Variant(
  84. *pdwSrcProperty,
  85. &varInputData
  86. );
  87. BAIL_ON_FAILURE(hr);
  88. hr = pADsObject->Put(
  89. bstrPropertyName,
  90. varInputData
  91. );
  92. BAIL_ON_FAILURE(hr);
  93. error:
  94. return hr;
  95. }
  96. HRESULT
  97. get_DWORD_Property(
  98. IADs *pADsObject,
  99. BSTR bstrPropertyName,
  100. PDWORD pdwDestProperty
  101. )
  102. {
  103. HRESULT hr = S_OK;
  104. VARIANT varOutputData;
  105. VALIDATE_PTR( pdwDestProperty );
  106. VariantInit( &varOutputData );
  107. hr = pADsObject->Get(
  108. bstrPropertyName,
  109. &varOutputData
  110. );
  111. BAIL_ON_FAILURE(hr);
  112. hr = UnpackDWORDfromVariant(
  113. varOutputData,
  114. pdwDestProperty
  115. );
  116. BAIL_ON_FAILURE(hr);
  117. error:
  118. return hr;
  119. }
  120. HRESULT
  121. put_Dispatch_Property(
  122. IADs *pADsObject,
  123. BSTR bstrPropertyName,
  124. IDispatch *pdwSrcProperty
  125. )
  126. {
  127. HRESULT hr = S_OK;
  128. VARIANT varInputData;
  129. if (!pdwSrcProperty)
  130. return S_OK;
  131. hr = PackDispatch2Variant(
  132. pdwSrcProperty,
  133. &varInputData
  134. );
  135. BAIL_ON_FAILURE(hr);
  136. hr = pADsObject->Put(
  137. bstrPropertyName,
  138. varInputData
  139. );
  140. BAIL_ON_FAILURE(hr);
  141. error:
  142. return hr;
  143. }
  144. HRESULT
  145. get_Dispatch_Property(
  146. IADs *pADsObject,
  147. BSTR bstrPropertyName,
  148. IDispatch **ppDispatch
  149. )
  150. {
  151. HRESULT hr = S_OK;
  152. VARIANT varOutputData;
  153. VariantInit( &varOutputData );
  154. hr = pADsObject->Get(
  155. bstrPropertyName,
  156. &varOutputData
  157. );
  158. BAIL_ON_FAILURE(hr);
  159. hr = UnpackDispatchfromVariant(
  160. varOutputData,
  161. ppDispatch
  162. );
  163. BAIL_ON_FAILURE(hr);
  164. error:
  165. return hr;
  166. }
  167. HRESULT
  168. put_MULTISZ_Property(
  169. IADs *pADsObject,
  170. BSTR bstrPropertyName,
  171. BSTR pSrcStringProperty
  172. )
  173. {
  174. HRESULT hr = S_OK;
  175. VARIANT var;
  176. VARIANT varInputData;
  177. BSTR pStr;
  178. BSTR *pStrArray;
  179. DWORD i;
  180. BSTR pMultiString;
  181. if (!pSrcStringProperty || !*pSrcStringProperty)
  182. pMultiString = L"";
  183. else
  184. pMultiString = pSrcStringProperty;
  185. VariantInit(&var);
  186. // Convert MULTI_SZ to string array (last element of array must be NULL)
  187. for (i = 0, pStr = pMultiString ; *pStr ; ++i, pStr += wcslen(pStr) + 1)
  188. ;
  189. if (!(pStrArray = (BSTR *) AllocSplMem((i + 1)*sizeof(BSTR)))) {
  190. hr = MAKE_HRESULT( SEVERITY_ERROR, FACILITY_WIN32, GetLastError());
  191. BAIL_ON_FAILURE(hr);
  192. }
  193. for (i = 0, pStr = pMultiString ; *pStr ; ++i, pStr += wcslen(pStr) + 1)
  194. pStrArray[i] = pStr;
  195. pStrArray[i] = NULL;
  196. MakeVariantFromStringArray(pStrArray, &var);
  197. FreeSplMem(pStrArray);
  198. hr = PackVARIANTinVariant(
  199. var,
  200. &varInputData
  201. );
  202. BAIL_ON_FAILURE(hr);
  203. if (!pSrcStringProperty || !*pSrcStringProperty) {
  204. hr = pADsObject->PutEx(
  205. ADS_PROPERTY_CLEAR,
  206. bstrPropertyName,
  207. varInputData
  208. );
  209. BAIL_ON_FAILURE(hr);
  210. } else {
  211. hr = pADsObject->Put(
  212. bstrPropertyName,
  213. varInputData
  214. );
  215. BAIL_ON_FAILURE(hr);
  216. }
  217. error:
  218. VariantClear(&var);
  219. VariantClear(&varInputData);
  220. return hr;
  221. }
  222. HRESULT
  223. put_BOOL_Property(
  224. IADs *pADsObject,
  225. BSTR bstrPropertyName,
  226. BOOL *bSrcProperty
  227. )
  228. {
  229. HRESULT hr = S_OK;
  230. VARIANT varInputData;
  231. BOOL bVal;
  232. bVal = bSrcProperty ? *bSrcProperty : 0;
  233. hr = PackBOOL2Variant(
  234. bVal,
  235. &varInputData
  236. );
  237. BAIL_ON_FAILURE(hr);
  238. if (!bSrcProperty) {
  239. hr = pADsObject->PutEx(
  240. ADS_PROPERTY_CLEAR,
  241. bstrPropertyName,
  242. varInputData
  243. );
  244. BAIL_ON_FAILURE(hr);
  245. } else {
  246. hr = pADsObject->Put(
  247. bstrPropertyName,
  248. varInputData
  249. );
  250. BAIL_ON_FAILURE(hr);
  251. }
  252. error:
  253. return hr;
  254. }
  255. HRESULT
  256. get_UI1Array_Property(
  257. IADs *pADsObject,
  258. BSTR bstrPropertyName,
  259. IID *pIID
  260. )
  261. {
  262. HRESULT hr = S_OK;
  263. VARIANT varOutputData;
  264. VariantInit( &varOutputData );
  265. hr = pADsObject->Get(
  266. bstrPropertyName,
  267. &varOutputData
  268. );
  269. BAIL_ON_FAILURE(hr);
  270. hr = UI1Array2IID(
  271. varOutputData,
  272. pIID
  273. );
  274. BAIL_ON_FAILURE(hr);
  275. error:
  276. VariantClear(&varOutputData);
  277. return hr;
  278. }
  279. HRESULT
  280. get_SID_Property(
  281. IADs *pADsObject,
  282. BSTR bstrPropertyName,
  283. LPWSTR *ppszSID
  284. )
  285. {
  286. HRESULT hr = S_OK;
  287. VARIANT varOutputData;
  288. VariantInit( &varOutputData );
  289. hr = pADsObject->Get(
  290. bstrPropertyName,
  291. &varOutputData
  292. );
  293. BAIL_ON_FAILURE(hr);
  294. hr = UI1Array2SID(
  295. varOutputData,
  296. ppszSID
  297. );
  298. BAIL_ON_FAILURE(hr);
  299. error:
  300. VariantClear(&varOutputData);
  301. return hr;
  302. }