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.

270 lines
5.9 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. //
  4. // Microsoft Windows
  5. // Copyright (C) Microsoft Corporation, 1992 - 1995
  6. //
  7. // File: schmgmt.cxx
  8. //
  9. // Contents: Microsoft ADs LDAP Provider Generic Object
  10. //
  11. //
  12. // History: 03-02-97 ShankSh Created.
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "ldapc.hxx"
  16. #pragma hdrstop
  17. HRESULT
  18. ADsEnumAttributes(
  19. LPWSTR pszLdapServer,
  20. LPWSTR pszLdapDn,
  21. CCredentials Credentials,
  22. DWORD dwPort,
  23. LPWSTR * ppszAttrNames,
  24. DWORD dwNumAttributes,
  25. PADS_ATTR_DEF * ppAttrDefinition,
  26. DWORD * pdwNumAttributes
  27. )
  28. {
  29. HRESULT hr = S_OK;
  30. LDAP_SCHEMA_HANDLE hSchema = NULL;
  31. DWORD cAttributes, cClasses;
  32. PROPERTYINFO *pPropertyInfo;
  33. DWORD dwMemSize = 0, dwStrBufSize = 0;
  34. DWORD dwLdapSyntax;
  35. LPBYTE pBuffer = NULL;
  36. LPWSTR pszNameEntry = NULL;
  37. PADS_ATTR_DEF pAttrDefEntry = NULL;
  38. ULONG i;
  39. if ( !ppAttrDefinition || !pdwNumAttributes ||
  40. (((LONG)dwNumAttributes) < 0 && ((LONG)dwNumAttributes) != -1) ) {
  41. RRETURN (E_INVALIDARG);
  42. }
  43. *ppAttrDefinition = NULL;
  44. *pdwNumAttributes = NULL;
  45. hr = SchemaOpen(
  46. pszLdapServer,
  47. &hSchema,
  48. Credentials,
  49. dwPort
  50. );
  51. BAIL_ON_FAILURE(hr);
  52. if (dwNumAttributes != (DWORD)-1) {
  53. //
  54. // List of attributes specified;
  55. //
  56. cAttributes = 0;
  57. for (i=0; i < dwNumAttributes; i++) {
  58. hr = SchemaGetPropertyInfo(
  59. hSchema,
  60. ppszAttrNames[i],
  61. &pPropertyInfo);
  62. BAIL_ON_FAILURE(hr);
  63. if (pPropertyInfo != NULL) {
  64. cAttributes++;
  65. dwStrBufSize += (wcslen(ppszAttrNames[i]) + 1) * sizeof (WCHAR);
  66. }
  67. }
  68. dwMemSize = sizeof(ADS_ATTR_DEF) * cAttributes + dwStrBufSize;
  69. pBuffer = (LPBYTE) AllocADsMem(dwMemSize);
  70. if (!pBuffer)
  71. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  72. pAttrDefEntry = (PADS_ATTR_DEF) pBuffer;
  73. pszNameEntry = (LPWSTR) (pBuffer + cAttributes * sizeof(ADS_ATTR_DEF));
  74. for (i=0; i < dwNumAttributes; i++) {
  75. hr = SchemaGetPropertyInfo(
  76. hSchema,
  77. ppszAttrNames[i],
  78. &pPropertyInfo);
  79. BAIL_ON_FAILURE(hr);
  80. if (pPropertyInfo == NULL)
  81. continue;
  82. dwLdapSyntax = LdapGetSyntaxIdFromName(
  83. pPropertyInfo->pszSyntax);
  84. pAttrDefEntry->dwADsType = MapLDAPTypeToADSType(dwLdapSyntax);
  85. pAttrDefEntry->dwMinRange = pPropertyInfo->lMinRange;
  86. pAttrDefEntry->dwMaxRange = pPropertyInfo->lMaxRange;
  87. pAttrDefEntry->fMultiValued = !(pPropertyInfo->fSingleValued);
  88. wcscpy(pszNameEntry, ppszAttrNames[i]);
  89. pAttrDefEntry->pszAttrName = pszNameEntry;
  90. pszNameEntry += wcslen(ppszAttrNames[i]) + 1;
  91. pAttrDefEntry ++;
  92. }
  93. }
  94. else {
  95. //
  96. // Get all the attribute definitions
  97. //
  98. hr = SchemaGetObjectCount(
  99. hSchema,
  100. &cClasses,
  101. &cAttributes);
  102. BAIL_ON_FAILURE(hr);
  103. dwMemSize = sizeof(ADS_ATTR_DEF) * cAttributes;
  104. //
  105. // Calculate the size of the buffer
  106. //
  107. for (i=0; i < cAttributes; i++) {
  108. hr = SchemaGetPropertyInfoByIndex(
  109. hSchema,
  110. i,
  111. &pPropertyInfo);
  112. BAIL_ON_FAILURE(hr);
  113. dwMemSize += (wcslen(pPropertyInfo->pszPropertyName) + 1) * sizeof (WCHAR);
  114. }
  115. pBuffer = (LPBYTE) AllocADsMem(dwMemSize);
  116. if (!pBuffer)
  117. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  118. pAttrDefEntry = (PADS_ATTR_DEF) pBuffer;
  119. pszNameEntry = (LPWSTR) (pBuffer + cAttributes * sizeof(ADS_ATTR_DEF));
  120. for (i=0; i < cAttributes; i++) {
  121. hr = SchemaGetPropertyInfoByIndex(
  122. hSchema,
  123. i,
  124. &pPropertyInfo);
  125. BAIL_ON_FAILURE(hr);
  126. dwLdapSyntax = LdapGetSyntaxIdFromName(
  127. pPropertyInfo->pszSyntax);
  128. pAttrDefEntry->dwADsType = MapLDAPTypeToADSType(dwLdapSyntax);
  129. pAttrDefEntry->dwMinRange = pPropertyInfo->lMinRange;
  130. pAttrDefEntry->dwMaxRange = pPropertyInfo->lMaxRange;
  131. pAttrDefEntry->fMultiValued = !(pPropertyInfo->fSingleValued);
  132. wcscpy(pszNameEntry, pPropertyInfo->pszPropertyName);
  133. pAttrDefEntry->pszAttrName = pszNameEntry;
  134. pszNameEntry += wcslen(pPropertyInfo->pszPropertyName) + 1;
  135. pAttrDefEntry ++;
  136. }
  137. }
  138. *ppAttrDefinition = (PADS_ATTR_DEF) pBuffer;
  139. *pdwNumAttributes = cAttributes;
  140. error:
  141. if ( hSchema )
  142. SchemaClose( &hSchema );
  143. RRETURN(hr);
  144. }
  145. HRESULT
  146. ADsCreateAttributeDefinition(
  147. LPWSTR pszAttributeName,
  148. PADS_ATTR_DEF pAttributeDefinition
  149. )
  150. {
  151. RRETURN (E_NOTIMPL);
  152. }
  153. HRESULT
  154. ADsWriteAttributeDefinition(
  155. LPWSTR pszAttributeName,
  156. PADS_ATTR_DEF pAttributeDefinition
  157. )
  158. {
  159. RRETURN (E_NOTIMPL);
  160. }
  161. HRESULT
  162. ADsDeleteAttributeDefinition(
  163. LPWSTR pszAttributeName
  164. )
  165. {
  166. RRETURN (E_NOTIMPL);
  167. }
  168. HRESULT
  169. ADsEnumClasses(
  170. LPWSTR * ppszAttrNames,
  171. DWORD dwNumClasses,
  172. PADS_CLASS_DEF * ppAttrDefinition,
  173. DWORD * pdwNumClasses
  174. )
  175. {
  176. RRETURN (E_NOTIMPL);
  177. }
  178. HRESULT
  179. ADsCreateClassDefinition(
  180. LPWSTR pszClassName,
  181. PADS_CLASS_DEF pClassDefinition
  182. )
  183. {
  184. RRETURN (E_NOTIMPL);
  185. }
  186. HRESULT
  187. ADsWriteClassDefinition(
  188. LPWSTR pszClassName,
  189. PADS_CLASS_DEF pClassDefinition
  190. )
  191. {
  192. RRETURN (E_NOTIMPL);
  193. }
  194. HRESULT
  195. ADsDeleteClassDefinition(
  196. LPWSTR pszClassName
  197. )
  198. {
  199. RRETURN (E_NOTIMPL);
  200. }