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.

250 lines
4.6 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. #define INC_OLE2
  10. #include "precomp.h"
  11. #pragma hdrstop
  12. #include "varconv.hxx"
  13. #include "property.hxx"
  14. #include "client.h"
  15. #define VALIDATE_PTR(pPtr) \
  16. if (!pPtr) { \
  17. hr = E_ADS_BAD_PARAMETER;\
  18. }\
  19. BAIL_ON_FAILURE(hr);
  20. HRESULT
  21. put_BSTR_Property(
  22. IADs * pADsObject,
  23. BSTR bstrPropertyName,
  24. BSTR pSrcStringProperty
  25. )
  26. {
  27. HRESULT hr;
  28. VARIANT varInputData;
  29. hr = PackString2Variant(
  30. pSrcStringProperty,
  31. &varInputData
  32. );
  33. BAIL_ON_FAILURE(hr);
  34. if (!pSrcStringProperty || !*pSrcStringProperty) {
  35. hr = pADsObject->PutEx(
  36. ADS_PROPERTY_CLEAR,
  37. bstrPropertyName,
  38. varInputData
  39. );
  40. BAIL_ON_FAILURE(hr);
  41. } else {
  42. hr = pADsObject->Put(
  43. bstrPropertyName,
  44. varInputData
  45. );
  46. BAIL_ON_FAILURE(hr);
  47. }
  48. error:
  49. VariantClear(&varInputData);
  50. return hr;
  51. }
  52. HRESULT
  53. put_DWORD_Property(
  54. IADs *pADsObject,
  55. BSTR bstrPropertyName,
  56. DWORD *pdwSrcProperty
  57. )
  58. {
  59. HRESULT hr = S_OK;
  60. VARIANT varInputData;
  61. if (!pdwSrcProperty)
  62. return S_OK;
  63. hr = PackDWORD2Variant(
  64. *pdwSrcProperty,
  65. &varInputData
  66. );
  67. BAIL_ON_FAILURE(hr);
  68. hr = pADsObject->Put(
  69. bstrPropertyName,
  70. varInputData
  71. );
  72. BAIL_ON_FAILURE(hr);
  73. error:
  74. return hr;
  75. }
  76. HRESULT
  77. put_MULTISZ_Property(
  78. IADs *pADsObject,
  79. BSTR bstrPropertyName,
  80. BSTR pSrcStringProperty
  81. )
  82. {
  83. HRESULT hr = S_OK;
  84. VARIANT var;
  85. VARIANT varInputData;
  86. BSTR pStr;
  87. BSTR *pStrArray;
  88. DWORD i;
  89. BSTR pMultiString;
  90. if (!pSrcStringProperty || !*pSrcStringProperty)
  91. pMultiString = L"";
  92. else
  93. pMultiString = pSrcStringProperty;
  94. VariantInit(&var);
  95. //
  96. // Convert MULTI_SZ to string array (last element of array must be NULL)
  97. //
  98. for (i = 0, pStr = pMultiString ; *pStr ; ++i, pStr += wcslen(pStr) + 1)
  99. ;
  100. if (!(pStrArray = (BSTR *) AllocSplMem((i + 1)*sizeof(BSTR)))) {
  101. hr = MAKE_HRESULT( SEVERITY_ERROR, FACILITY_WIN32, GetLastError());
  102. BAIL_ON_FAILURE(hr);
  103. }
  104. for (i = 0, pStr = pMultiString ; *pStr ; ++i, pStr += wcslen(pStr) + 1)
  105. pStrArray[i] = pStr;
  106. pStrArray[i] = NULL;
  107. MakeVariantFromStringArray(pStrArray, &var);
  108. FreeSplMem(pStrArray);
  109. hr = PackVARIANTinVariant(
  110. var,
  111. &varInputData
  112. );
  113. BAIL_ON_FAILURE(hr);
  114. if (!pSrcStringProperty || !*pSrcStringProperty) {
  115. hr = pADsObject->PutEx(
  116. ADS_PROPERTY_CLEAR,
  117. bstrPropertyName,
  118. varInputData
  119. );
  120. BAIL_ON_FAILURE(hr);
  121. } else {
  122. hr = pADsObject->Put(
  123. bstrPropertyName,
  124. varInputData
  125. );
  126. BAIL_ON_FAILURE(hr);
  127. }
  128. error:
  129. VariantClear(&var);
  130. VariantClear(&varInputData);
  131. return hr;
  132. }
  133. HRESULT
  134. put_BOOL_Property(
  135. IADs *pADsObject,
  136. BSTR bstrPropertyName,
  137. BOOL *bSrcProperty
  138. )
  139. {
  140. HRESULT hr = S_OK;
  141. VARIANT varInputData;
  142. BOOL bVal;
  143. bVal = bSrcProperty ? *bSrcProperty : 0;
  144. hr = PackBOOL2Variant(
  145. bVal,
  146. &varInputData
  147. );
  148. BAIL_ON_FAILURE(hr);
  149. if (!bSrcProperty) {
  150. hr = pADsObject->PutEx(
  151. ADS_PROPERTY_CLEAR,
  152. bstrPropertyName,
  153. varInputData
  154. );
  155. BAIL_ON_FAILURE(hr);
  156. } else {
  157. hr = pADsObject->Put(
  158. bstrPropertyName,
  159. varInputData
  160. );
  161. BAIL_ON_FAILURE(hr);
  162. }
  163. error:
  164. return hr;
  165. }
  166. HRESULT
  167. get_BSTR_Property(
  168. IADs *pADsObject,
  169. BSTR bstrPropertyName,
  170. BSTR *ppDestStringProperty
  171. )
  172. {
  173. HRESULT hr = S_OK;
  174. VARIANT varOutputData;
  175. VariantInit( &varOutputData );
  176. hr = pADsObject->Get(
  177. bstrPropertyName,
  178. &varOutputData
  179. );
  180. BAIL_ON_FAILURE(hr);
  181. hr = UnpackStringfromVariant(
  182. varOutputData,
  183. ppDestStringProperty
  184. );
  185. BAIL_ON_FAILURE(hr);
  186. error:
  187. return hr;
  188. }