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.

274 lines
6.5 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. //
  4. // Microsoft Windows
  5. // Copyright (C) Microsoft Corporation, 1992 - 1995
  6. //
  7. // File: cdssch.cxx
  8. //
  9. // Contents: Microsoft ADs NDS Provider Generic Object
  10. //
  11. //
  12. // History: 03-02-97 ShankSh Created.
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "nds.hxx"
  16. #pragma hdrstop
  17. static WCHAR gszObjClassAttr[] = L"Object Class";
  18. static WCHAR gszNameAttr[] = L"cn";
  19. HRESULT
  20. CNDSGenObject::EnumAttributes(
  21. LPWSTR * ppszAttrNames,
  22. DWORD dwNumAttributes,
  23. PADS_ATTR_DEF * ppAttrDefinition,
  24. DWORD * pdwNumAttributes
  25. )
  26. {
  27. LPWSTR pszNDSPath = NULL;
  28. DWORD dwStatus;
  29. HRESULT hr = S_OK;
  30. DWORD dwNumberOfEntries;
  31. DWORD dwInfoType;
  32. LPNDS_ATTR_DEF lpAttrDefs = NULL;
  33. HANDLE hConnection = NULL, hOperationData = NULL;
  34. DWORD i,j,k;
  35. DWORD dwMemSize = 0;
  36. LPBYTE pBuffer = NULL;
  37. LPWSTR pszNameEntry = NULL;
  38. PADS_ATTR_DEF pAttrDefEntry = NULL;
  39. if ( !ppAttrDefinition || !pdwNumAttributes ||
  40. (((LONG)dwNumAttributes) < 0 && ((LONG)dwNumAttributes) != -1) ) {
  41. RRETURN (E_INVALIDARG);
  42. }
  43. *ppAttrDefinition = NULL;
  44. *pdwNumAttributes = NULL;
  45. //
  46. // Allocate memory for pszNDSPath before calling BuildNDSTreeNameFromADsPath
  47. // Allocating ADsPath is safe as the tree name is always less.
  48. //
  49. pszNDSPath = AllocADsStr(_ADsPath);
  50. if (!pszNDSPath)
  51. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  52. hr = BuildNDSTreeNameFromADsPath(
  53. _ADsPath,
  54. pszNDSPath
  55. );
  56. BAIL_ON_FAILURE(hr);
  57. dwStatus = NwNdsOpenObject(
  58. pszNDSPath,
  59. NULL,
  60. NULL,
  61. &hConnection,
  62. NULL,
  63. NULL,
  64. NULL,
  65. 0,
  66. 0
  67. );
  68. CHECK_AND_SET_EXTENDED_ERROR(dwStatus, hr);
  69. if (dwNumAttributes != (DWORD)-1) {
  70. dwStatus = NwNdsCreateBuffer(
  71. NDS_SCHEMA_READ_ATTR_DEF,
  72. &hOperationData
  73. );
  74. CHECK_AND_SET_EXTENDED_ERROR(dwStatus, hr);
  75. for (i=0; i < dwNumAttributes; i++) {
  76. dwStatus = NwNdsPutInBuffer(
  77. ppszAttrNames[i],
  78. 0,
  79. NULL,
  80. 0,
  81. 0,
  82. hOperationData
  83. );
  84. CHECK_AND_SET_EXTENDED_ERROR(dwStatus, hr);
  85. }
  86. }
  87. else {
  88. //
  89. // Tell the server to give us back all the attributes
  90. //
  91. hOperationData = NULL;
  92. }
  93. dwStatus = NwNdsReadAttrDef(
  94. hConnection,
  95. NDS_INFO_NAMES_DEFS,
  96. &hOperationData
  97. );
  98. CHECK_AND_SET_EXTENDED_ERROR(dwStatus, hr);
  99. dwStatus = NwNdsGetAttrDefListFromBuffer(
  100. hOperationData,
  101. &dwNumberOfEntries,
  102. &dwInfoType,
  103. (LPVOID *) &lpAttrDefs
  104. );
  105. CHECK_AND_SET_EXTENDED_ERROR(dwStatus, hr);
  106. if (dwInfoType != NDS_INFO_NAMES_DEFS )
  107. BAIL_ON_FAILURE( hr = E_FAIL );
  108. //
  109. // Now package this data into a single contiguous buffer
  110. //
  111. hr = ComputeADsAttrDefBufferSize(
  112. lpAttrDefs,
  113. dwNumberOfEntries,
  114. &dwMemSize
  115. );
  116. BAIL_ON_FAILURE(hr);
  117. pBuffer = (LPBYTE) AllocADsMem(dwMemSize);
  118. if (!pBuffer)
  119. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  120. pAttrDefEntry = (PADS_ATTR_DEF) pBuffer;
  121. pszNameEntry = (LPWSTR) (pBuffer + dwNumberOfEntries * sizeof(ADS_ATTR_DEF));
  122. for (j = 0; j < dwNumberOfEntries ; j++ ) {
  123. if (lpAttrDefs[j].dwSyntaxID >= g_cMapNdsTypeToADsType)
  124. pAttrDefEntry->dwADsType = ADSTYPE_INVALID;
  125. else
  126. pAttrDefEntry->dwADsType = g_MapNdsTypeToADsType[lpAttrDefs[j].dwSyntaxID];
  127. pAttrDefEntry->dwMinRange = lpAttrDefs[j].dwLowerLimit;
  128. pAttrDefEntry->dwMaxRange = lpAttrDefs[j].dwUpperLimit;
  129. pAttrDefEntry->fMultiValued = !(lpAttrDefs[j].dwFlags & NDS_SINGLE_VALUED_ATTR);
  130. wcscpy(pszNameEntry, lpAttrDefs[j].szAttributeName);
  131. pAttrDefEntry->pszAttrName = pszNameEntry;
  132. pszNameEntry += wcslen(lpAttrDefs[j].szAttributeName) + 1;
  133. pAttrDefEntry ++;
  134. }
  135. *ppAttrDefinition = (PADS_ATTR_DEF) pBuffer;
  136. *pdwNumAttributes = dwNumberOfEntries;
  137. error:
  138. if (pszNDSPath)
  139. FreeADsStr(pszNDSPath);
  140. if (hOperationData)
  141. NwNdsFreeBuffer( hOperationData );
  142. if (hConnection)
  143. NwNdsCloseObject( hConnection);
  144. RRETURN(hr);
  145. }
  146. HRESULT
  147. CNDSGenObject::CreateAttributeDefinition(
  148. LPWSTR pszAttributeName,
  149. PADS_ATTR_DEF pAttributeDefinition
  150. )
  151. {
  152. RRETURN (E_NOTIMPL);
  153. }
  154. HRESULT
  155. CNDSGenObject::WriteAttributeDefinition(
  156. LPWSTR pszAttributeName,
  157. PADS_ATTR_DEF pAttributeDefinition
  158. )
  159. {
  160. RRETURN (E_NOTIMPL);
  161. }
  162. HRESULT
  163. CNDSGenObject::DeleteAttributeDefinition(
  164. LPWSTR pszAttributeName
  165. )
  166. {
  167. RRETURN (E_NOTIMPL);
  168. }
  169. HRESULT
  170. ComputeADsAttrDefBufferSize(
  171. LPNDS_ATTR_DEF pAttributes,
  172. DWORD dwNumAttributes,
  173. PDWORD pdwSize
  174. )
  175. {
  176. DWORD i = 0;
  177. DWORD dwSize = 0;
  178. dwSize = sizeof(ADS_ATTR_DEF) * dwNumAttributes;
  179. for (i = 0; i < dwNumAttributes; i++)
  180. dwSize += (wcslen(pAttributes[i].szAttributeName) + 1)*sizeof(WCHAR);
  181. *pdwSize = dwSize;
  182. RRETURN(S_OK);
  183. }
  184. HRESULT
  185. CNDSGenObject::DeleteClassDefinition(
  186. LPWSTR pszClassName
  187. )
  188. {
  189. RRETURN(E_NOTIMPL);
  190. }
  191. HRESULT
  192. CNDSGenObject::CreateClassDefinition(
  193. LPWSTR pszClassName,
  194. PADS_CLASS_DEF pClassDefinition
  195. )
  196. {
  197. RRETURN(E_NOTIMPL);
  198. }
  199. HRESULT
  200. CNDSGenObject::WriteClassDefinition(
  201. LPWSTR pszClassName,
  202. PADS_CLASS_DEF pClassDefinition
  203. )
  204. {
  205. RRETURN(E_NOTIMPL);
  206. }
  207. HRESULT
  208. CNDSGenObject::EnumClasses(
  209. LPWSTR *ppszClassNames,
  210. DWORD dwNumClasses,
  211. PADS_CLASS_DEF *ppClassDefinition,
  212. DWORD *pdwNumClasses
  213. )
  214. {
  215. RRETURN(E_NOTIMPL);
  216. }
  217.