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.

345 lines
8.1 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // attrdef.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // Defines the class AttributeDefinition.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 03/01/1999 Original version.
  16. // 01/27/2000 Add support for proxy policies.
  17. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #include <stdafx.h>
  20. #include <memory>
  21. #include <attrdef.h>
  22. inline AttributeDefinition::AttributeDefinition() throw ()
  23. {
  24. memset(this, 0, sizeof(*this));
  25. }
  26. inline AttributeDefinition::~AttributeDefinition() throw ()
  27. {
  28. SysFreeString(name);
  29. SysFreeString(description);
  30. SysFreeString(ldapName);
  31. SafeArrayDestroy(enumNames);
  32. SafeArrayDestroy(enumValues);
  33. }
  34. void AttributeDefinition::Release() const throw ()
  35. {
  36. if (InterlockedDecrement(&refCount) == 0)
  37. {
  38. delete const_cast<AttributeDefinition*>(this);
  39. }
  40. }
  41. HRESULT AttributeDefinition::getInfo(
  42. ATTRIBUTEINFO infoId,
  43. VARIANT* pVal
  44. ) const throw ()
  45. {
  46. if (pVal == NULL) { return E_INVALIDARG; }
  47. VariantInit(pVal);
  48. HRESULT hr = S_OK;
  49. switch (infoId)
  50. {
  51. case NAME:
  52. {
  53. if (V_BSTR(pVal) = SysAllocString(name))
  54. {
  55. V_VT(pVal) = VT_BSTR;
  56. }
  57. else
  58. {
  59. hr = E_OUTOFMEMORY;
  60. }
  61. break;
  62. }
  63. case SYNTAX:
  64. {
  65. V_I4(pVal) = (LONG)syntax;
  66. V_VT(pVal) = VT_I4;
  67. break;
  68. }
  69. case RESTRICTIONS:
  70. {
  71. V_I4(pVal) = (LONG)restrictions;
  72. V_VT(pVal) = VT_I4;
  73. break;
  74. }
  75. case DESCRIPTION:
  76. {
  77. // Description is optional, so it may be NULL.
  78. if (description)
  79. {
  80. if (V_BSTR(pVal) = SysAllocString(description))
  81. {
  82. V_VT(pVal) = VT_BSTR;
  83. }
  84. else
  85. {
  86. hr = E_OUTOFMEMORY;
  87. }
  88. }
  89. break;
  90. }
  91. case VENDORID:
  92. {
  93. V_I4(pVal) = (LONG)vendor;
  94. V_VT(pVal) = VT_I4;
  95. break;
  96. }
  97. case LDAPNAME:
  98. {
  99. if (V_BSTR(pVal) = SysAllocString(ldapName))
  100. {
  101. V_VT(pVal) = VT_BSTR;
  102. }
  103. else
  104. {
  105. hr = E_OUTOFMEMORY;
  106. }
  107. break;
  108. }
  109. default:
  110. hr = E_INVALIDARG;
  111. }
  112. return hr;
  113. }
  114. HRESULT AttributeDefinition::getProperty(
  115. LONG propId,
  116. VARIANT* pVal
  117. ) const throw ()
  118. {
  119. if (pVal == NULL) { return E_INVALIDARG; }
  120. VariantInit(pVal);
  121. HRESULT hr = S_OK;
  122. switch (propId)
  123. {
  124. case PROPERTY_SDO_NAME:
  125. {
  126. if (V_BSTR(pVal) = SysAllocString(name))
  127. {
  128. V_VT(pVal) = VT_BSTR;
  129. }
  130. else
  131. {
  132. hr = E_OUTOFMEMORY;
  133. }
  134. break;
  135. }
  136. case PROPERTY_ATTRIBUTE_ID:
  137. {
  138. V_VT(pVal) = VT_I4;
  139. V_I4(pVal) = id;
  140. break;
  141. }
  142. case PROPERTY_ATTRIBUTE_VENDOR_ID:
  143. {
  144. V_VT(pVal) = VT_I4;
  145. V_I4(pVal) = vendor;
  146. break;
  147. }
  148. case PROPERTY_ATTRIBUTE_IS_ENUMERABLE:
  149. {
  150. V_VT(pVal) = VT_BOOL;
  151. V_BOOL(pVal) = enumNames ? VARIANT_TRUE : VARIANT_FALSE;
  152. break;
  153. }
  154. case PROPERTY_ATTRIBUTE_ENUM_NAMES:
  155. {
  156. if (enumNames)
  157. {
  158. hr = SafeArrayCopy(enumNames, &V_ARRAY(pVal));
  159. if (SUCCEEDED(hr)) { V_VT(pVal) = VT_ARRAY; }
  160. }
  161. break;
  162. }
  163. case PROPERTY_ATTRIBUTE_ENUM_VALUES:
  164. {
  165. if (enumValues)
  166. {
  167. hr = SafeArrayCopy(enumValues, &V_ARRAY(pVal));
  168. if (SUCCEEDED(hr)) { V_VT(pVal) = VT_ARRAY; }
  169. }
  170. break;
  171. }
  172. case PROPERTY_ATTRIBUTE_SYNTAX:
  173. {
  174. V_VT(pVal) = VT_I4;
  175. V_I4(pVal) = syntax;
  176. break;
  177. }
  178. case PROPERTY_ATTRIBUTE_ALLOW_MULTIPLE:
  179. {
  180. V_VT(pVal) = VT_BOOL;
  181. V_BOOL(pVal) = (restrictions & MULTIVALUED)
  182. ? VARIANT_TRUE : VARIANT_FALSE;
  183. break;
  184. }
  185. case PROPERTY_ATTRIBUTE_ALLOW_IN_PROFILE:
  186. {
  187. V_VT(pVal) = VT_BOOL;
  188. V_BOOL(pVal) = (restrictions & ALLOWEDINPROFILE)
  189. ? VARIANT_TRUE : VARIANT_FALSE;
  190. break;
  191. }
  192. case PROPERTY_ATTRIBUTE_ALLOW_IN_CONDITION:
  193. {
  194. V_VT(pVal) = VT_BOOL;
  195. V_BOOL(pVal) = (restrictions & ALLOWEDINCONDITION)
  196. ? VARIANT_TRUE : VARIANT_FALSE;
  197. break;
  198. }
  199. case PROPERTY_ATTRIBUTE_DISPLAY_NAME:
  200. {
  201. if (V_BSTR(pVal) = SysAllocString(ldapName))
  202. {
  203. V_VT(pVal) = VT_BSTR;
  204. }
  205. else
  206. {
  207. hr = E_OUTOFMEMORY;
  208. }
  209. break;
  210. }
  211. case PROPERTY_ATTRIBUTE_ALLOW_IN_PROXY_PROFILE:
  212. {
  213. V_VT(pVal) = VT_BOOL;
  214. V_BOOL(pVal) = (restrictions & ALLOWEDINPROXYPROFILE)
  215. ? VARIANT_TRUE : VARIANT_FALSE;
  216. break;
  217. }
  218. case PROPERTY_ATTRIBUTE_ALLOW_IN_PROXY_CONDITION:
  219. {
  220. V_VT(pVal) = VT_BOOL;
  221. V_BOOL(pVal) = (restrictions & ALLOWEDINPROXYCONDITION)
  222. ? VARIANT_TRUE : VARIANT_FALSE;
  223. break;
  224. }
  225. default:
  226. hr = E_INVALIDARG;
  227. }
  228. return hr;
  229. }
  230. HRESULT AttributeDefinition::createInstance(
  231. AttributeDefinition** newDef
  232. ) throw ()
  233. {
  234. // Check the arguments.
  235. if (newDef == NULL) { return E_INVALIDARG; }
  236. // Create a new AttributeDefinition.
  237. *newDef = new (std::nothrow) AttributeDefinition();
  238. if (*newDef == NULL) { return E_OUTOFMEMORY; }
  239. // Set the refCount to one.
  240. (*newDef)->refCount = 1;
  241. return S_OK;
  242. }
  243. int __cdecl AttributeDefinition::searchById(
  244. const ULONG* key,
  245. const AttributeDefinition* const* def
  246. ) throw ()
  247. {
  248. if (*key > (*def)->id)
  249. {
  250. return 1;
  251. }
  252. else if (*key < (*def)->id)
  253. {
  254. return -1;
  255. }
  256. return 0;
  257. }
  258. int __cdecl AttributeDefinition::sortById(
  259. const AttributeDefinition* const* def1,
  260. const AttributeDefinition* const* def2
  261. ) throw ()
  262. {
  263. if ((*def1)->id > (*def2)->id)
  264. {
  265. return 1;
  266. }
  267. else if ((*def1)->id < (*def2)->id)
  268. {
  269. return -1;
  270. }
  271. return 0;
  272. }
  273. int __cdecl AttributeDefinition::searchByName(
  274. PCWSTR key,
  275. const AttributeDefinition* const* def
  276. ) throw ()
  277. {
  278. return _wcsicmp(key, (*def)->name);
  279. }
  280. int __cdecl AttributeDefinition::sortByName(
  281. const AttributeDefinition* const* def1,
  282. const AttributeDefinition* const* def2
  283. ) throw ()
  284. {
  285. return _wcsicmp((*def1)->name, (*def2)->name);
  286. }
  287. int __cdecl AttributeDefinition::searchByLdapName(
  288. PCWSTR key,
  289. const AttributeDefinition* const* def
  290. ) throw ()
  291. {
  292. return _wcsicmp(key, (*def)->ldapName);
  293. }
  294. int __cdecl AttributeDefinition::sortByLdapName(
  295. const AttributeDefinition* const* def1,
  296. const AttributeDefinition* const* def2
  297. ) throw ()
  298. {
  299. return _wcsicmp((*def1)->ldapName, (*def2)->ldapName);
  300. }