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.

275 lines
6.2 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. if(FAILED(hr) && pBuffer)
  144. {
  145. FreeADsMem(pBuffer);
  146. }
  147. RRETURN(hr);
  148. }
  149. HRESULT
  150. ADsCreateAttributeDefinition(
  151. LPWSTR pszAttributeName,
  152. PADS_ATTR_DEF pAttributeDefinition
  153. )
  154. {
  155. RRETURN (E_NOTIMPL);
  156. }
  157. HRESULT
  158. ADsWriteAttributeDefinition(
  159. LPWSTR pszAttributeName,
  160. PADS_ATTR_DEF pAttributeDefinition
  161. )
  162. {
  163. RRETURN (E_NOTIMPL);
  164. }
  165. HRESULT
  166. ADsDeleteAttributeDefinition(
  167. LPWSTR pszAttributeName
  168. )
  169. {
  170. RRETURN (E_NOTIMPL);
  171. }
  172. HRESULT
  173. ADsEnumClasses(
  174. LPWSTR * ppszAttrNames,
  175. DWORD dwNumClasses,
  176. PADS_CLASS_DEF * ppAttrDefinition,
  177. DWORD * pdwNumClasses
  178. )
  179. {
  180. RRETURN (E_NOTIMPL);
  181. }
  182. HRESULT
  183. ADsCreateClassDefinition(
  184. LPWSTR pszClassName,
  185. PADS_CLASS_DEF pClassDefinition
  186. )
  187. {
  188. RRETURN (E_NOTIMPL);
  189. }
  190. HRESULT
  191. ADsWriteClassDefinition(
  192. LPWSTR pszClassName,
  193. PADS_CLASS_DEF pClassDefinition
  194. )
  195. {
  196. RRETURN (E_NOTIMPL);
  197. }
  198. HRESULT
  199. ADsDeleteClassDefinition(
  200. LPWSTR pszClassName
  201. )
  202. {
  203. RRETURN (E_NOTIMPL);
  204. }