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.

201 lines
8.4 KiB

  1. //
  2. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  3. //
  4. // ***************************************************************************
  5. //
  6. // Original Author: Rajesh Rao
  7. //
  8. // $Author: rajeshr $
  9. // $Date: 6/11/98 4:43p $
  10. // $Workfile:ldaphelp.h $
  11. //
  12. // $Modtime: 6/11/98 11:21a $
  13. // $Revision: 1 $
  14. // $Nokeywords: $
  15. //
  16. //
  17. // Description: Contains the declaration for the CLDAPHelper class. This is
  18. // a class that has many static helper functions pertaining to ADSI LDAP Provider
  19. //***************************************************************************
  20. /////////////////////////////////////////////////////////////////////////
  21. #ifndef LDAP_HELPER_H
  22. #define LDAP_HELPER_H
  23. class CLDAPHelper
  24. {
  25. public:
  26. //***************************************************************************
  27. //
  28. // CLDAPHelper :: GetLDAPClassFromLDAPName
  29. //
  30. // Purpose : To fill in a CADSIClass object on a class/property provided by the LDAP Provider
  31. // Parameters:
  32. // pDirectorySearchSchemaContainer : The IDirectorySearch interface where the schema object should be looked for
  33. // lpszSchemaContainerSuffix : The suffix to be used. The actual object fetched will be:
  34. // LDAP://CN=<lpszCommonName>,<lpszSchemaContainerSuffix>, where lpszCommonName is the
  35. // 'cn' attribute of the object having the ldapdisplayname attribute as lpszLDAPObjectName
  36. // pSearchInfo: An array of ADS_SEARCHPREF_INFO to be used in the search
  37. // dwSearchInfoCount : The number of elements in the above array
  38. // lpszLDAPObjectName : The LDAPDisplayName of the LDAP class or property to be fetched.
  39. // ppLDAPObject : The address where the pointer to IDirectoryObject will be stored
  40. // It is the caller's responsibility to delete the object when done with it
  41. //
  42. // Return Value: The COM status value indicating the status of the request.
  43. //***************************************************************************
  44. static HRESULT GetLDAPClassFromLDAPName(
  45. IDirectorySearch *pDirectorySearchSchemaContainer,
  46. LPCWSTR lpszSchemaContainerSuffix,
  47. PADS_SEARCHPREF_INFO pSearchInfo,
  48. DWORD dwSearchInfoCount,
  49. CADSIClass *pADSIClass);
  50. //***************************************************************************
  51. //
  52. // CLDAPHelper :: GetLDAPSchemaObjectFromCommonName
  53. //
  54. // Purpose : To fetch the IDirectoryObject interface on a class/property provided by the LDAP Provider
  55. // Parameters:
  56. // lpszSchemaContainerSuffix : The suffix to be used. The actual object fetced will be:
  57. // LDAP://CN=<lpszCommonName>,<lpszSchemaContainerSuffix>
  58. // lpszCommonName : The 'cn' attribute of the LDAP class or property to be fetched.
  59. // ppLDAPObject : The address where the pointer to IDirectoryObject will be stored
  60. // It is the caller's responsibility to delete the object when done with it
  61. //
  62. // Return Value: The COM status value indicating the status of the request.
  63. //***************************************************************************
  64. static HRESULT GetLDAPSchemaObjectFromCommonName(
  65. LPCWSTR lpszSchemaContainerSuffix,
  66. LPCWSTR lpszCommonName,
  67. IDirectoryObject **ppLDAPObject);
  68. //***************************************************************************
  69. //
  70. // CLDAPHelper :: GetLDAPClassNameFromCN
  71. //
  72. // Purpose : To fetch the LDAPDisplayNAme of a class from its path
  73. // Parameters:
  74. //
  75. // Return Value: The COM status value indicating the status of the request. The user should delete the
  76. // name returned, when done
  77. //***************************************************************************
  78. static HRESULT GetLDAPClassNameFromCN(LPCWSTR lpszLDAPClassPath,
  79. LPWSTR *lppszLDAPName);
  80. //***************************************************************************
  81. //
  82. // CLDAPHelper :: EnumerateClasses
  83. //
  84. // Purpose : To fetch the list of names of subclasses (immediate) of an LDAP class
  85. // Parameters:
  86. // pDirectorySearchSchemaContainer : The IDirectorySearch interface where the schema object should be looked for
  87. // lpszSchemaContainerSuffix : The suffix to be used. The actual object fetced will be:
  88. // LDAP://CN=<lpszObjectName>,<lpszSchemaContainerSuffix>
  89. // pSearchInfo: An array of ADS_SEARCHPREF_INFO to be used in the search
  90. // dwSearchInfoCount : The number of elements in the above array
  91. // lppszLDAPSuperClass : The immediate superclass of the classes to be retreived. This is optional
  92. // and is ignored if NULL
  93. // bDeep : Indicates whether a deep enumeration is required. Otherwise a shallow enumeration is done
  94. // pppszClassNames : The address of the array of LPWSTR pointers where the resulting objects will be
  95. // placed. The user should deallocate this array as well as its contents when done with them.
  96. // pdwNumRows : The number of elements in the above array returned
  97. //
  98. // Return Value: The COM status value indicating the status of the request.
  99. //***************************************************************************
  100. static HRESULT EnumerateClasses(
  101. IDirectorySearch *pDirectorySearchSchemaContainer,
  102. LPCWSTR lpszSchemaContainerSuffix,
  103. PADS_SEARCHPREF_INFO pSearchInfo,
  104. DWORD dwSearchInfoCount,
  105. LPCWSTR lpszSuperClass,
  106. BOOLEAN bDeep,
  107. LPWSTR **pppszClassNames,
  108. DWORD *pdwNumRows,
  109. BOOLEAN bArtificialClass);
  110. // Gets the IDIrectoryObject interface on an ADSI instance
  111. static HRESULT GetADSIInstance(LPCWSTR szADSIPath, CADSIInstance **ppADSIInstance, ProvDebugLog *pLogObject);
  112. //***************************************************************************
  113. //
  114. // CLDAPHelper :: ExecuteQuery
  115. //
  116. // Purpose : To fetch the IDirectoryObject interface on a class/property provided by the LDAP Provider
  117. // Parameters:
  118. // pszPathToRoot : The ADSI path to the node from which the search should start
  119. // pSearchInfo: A pointer to a ADS_SEARCHPREF_INFO to be used in the search
  120. // dwSearchInfoCount: The number of elements in pSearchInfo array
  121. // pszLDAPQuery : The LDAP query to be executed
  122. // pppADSIInstances : The address of the array of CADSIInstance pointers where the resulting objects will be
  123. // placed. The user should deallocate this array as well as its contents when done with them.
  124. // pdwNumRows : The number of elements in the above array returned
  125. //
  126. // Return Value: The COM status value indicating the status of the request.
  127. //***************************************************************************
  128. static HRESULT ExecuteQuery(
  129. LPCWSTR pszPathToRoot,
  130. PADS_SEARCHPREF_INFO pSearchInfo,
  131. DWORD dwSearchInfoCount,
  132. LPCWSTR pszLDAPQuery,
  133. CADSIInstance ***pppADSIInstances,
  134. DWORD *pdwNumRows,
  135. ProvDebugLog *pLogObject);
  136. // Helper functions to delete a ADS_ATTR_INFO structure
  137. static void DeleteAttributeContents(PADS_ATTR_INFO pAttribute);
  138. static void DeleteADsValueContents(PADSVALUE pValue);
  139. //***************************************************************************
  140. //
  141. // CLDAPHelper :: UnmangleWBEMNameToLDAP
  142. //
  143. // Purpose : Converts a mangled WBEM name to LDAP
  144. // An underscore in LDAP maps to two underscores in WBEM
  145. // An hyphen in LDAP maps to one underscore in WBEM
  146. //
  147. // Parameters:
  148. // lpszWBEMName : The WBEM class or property name
  149. //
  150. // Return Value: The LDAP name to the class or property object. This has to
  151. // be deallocated by the user
  152. //***************************************************************************
  153. static LPWSTR UnmangleWBEMNameToLDAP(LPCWSTR lpszWBEMName);
  154. //***************************************************************************
  155. //
  156. // CLDAPHelper :: MangleLDAPNameToWBEM
  157. //
  158. // Purpose : Converts a LDAP name to WBEM by mangling it
  159. // An underscore in LDAP maps to two underscores in WBEM
  160. // An hyphen in LDAP maps to one underscore in WBEM
  161. //
  162. // Parameters:
  163. // lpszLDAPName : The LDAP class or property name
  164. //
  165. // Return Value: The LDAP name to the class or property object. This has to
  166. // be deallocated by the user
  167. //***************************************************************************
  168. static LPWSTR MangleLDAPNameToWBEM(LPCWSTR lpszLDAPName, BOOLEAN bArtificalName = FALSE);
  169. private:
  170. // Forms the ADSI path from a class or property name
  171. static LPWSTR CreateADSIPath(LPCWSTR lpszLDAPSchemaObjectName, LPCWSTR lpszSchemaContainerSuffix);
  172. // Some literals
  173. static LPCWSTR LDAP_CN_EQUALS;
  174. static LPCWSTR LDAP_DISP_NAME_EQUALS;
  175. static LPCWSTR OBJECT_CATEGORY_EQUALS_CLASS_SCHEMA;
  176. static LPCWSTR SUB_CLASS_OF_EQUALS;
  177. static LPCWSTR NOT_LDAP_NAME_EQUALS;
  178. static LPCWSTR LEFT_BRACKET_AND;
  179. static LPCWSTR GOVERNS_ID_EQUALS;
  180. static LPCWSTR CLASS_SCHEMA;
  181. static LPCWSTR CN_EQUALS;
  182. };
  183. #endif /* LDAP_HELPER_H */