extcmap.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #ifndef _PUBLIC_CERTMAP_H
  39. #define _PUBLIC_CERTMAP_H
  40. #include <ldap.h>
  41. #ifndef NSAPI_PUBLIC
  42. #if defined( _WINDOWS ) || defined( _WIN32 ) || defined( XP_WIN32 )
  43. #define NSAPI_PUBLIC __declspec(dllexport)
  44. #else
  45. #define NSAPI_PUBLIC
  46. #endif
  47. #endif
  48. #define LDAPU_ATTR_INITFN "InitFn"
  49. #define LDAPU_ATTR_LIBRARY "library"
  50. #define LDAPU_ATTR_DNCOMPS "DNComps"
  51. #define LDAPU_ATTR_FILTERCOMPS "FilterComps"
  52. #define LDAPU_ATTR_VERIFYCERT "VerifyCert"
  53. #define LDAPU_ATTR_CERTMAP_LDAP_ATTR "CmapLdapAttr"
  54. /* Error/Success codes */
  55. #define LDAPU_SUCCESS 0
  56. #define LDAPU_FAILED -1
  57. #define LDAPU_CERT_MAP_FUNCTION_FAILED -2
  58. #define LDAPU_CERT_SEARCH_FUNCTION_FAILED -3
  59. #define LDAPU_CERT_VERIFY_FUNCTION_FAILED -4
  60. #define LDAPU_CERT_MAP_INITFN_FAILED -5
  61. /*
  62. * CertMapFn_t -
  63. * This is a typedef for cert mapping function. The mapping function is
  64. * called by the function ldapu_cert_to_ldap_entry.
  65. * Parameters:
  66. * cert - cert to be mapped. You can pass this to
  67. * functions ldapu_get_cert_XYZ.
  68. * ld - Handle to the connection to the directory server.
  69. * certmap_info - This structure contains information about the
  70. * configuration parameters for the cert's issuer (CA).
  71. * This structure can be passed to the function
  72. * ldapu_certmap_info_attrval to get value for a particular
  73. * configuration attribute (or a property).
  74. * ldapdn - The mapping function should allocate memory for ldapdn
  75. * using malloc and set this variable using the 'cert' and
  76. * 'certmap_info'. This DN will be used for ldap lookup.
  77. * filter - The mapping function should allocate memory for filter
  78. * using malloc and set this variable using the 'cert' and
  79. * 'certmap_info'. This will be used as ldap filter for ldap
  80. * lookup of the ldapdn.
  81. *
  82. * Return Value:
  83. * return LDAPU_SUCCESS upon successful completion (cert is mapped)
  84. * return LDAPU_FAILED there is no unexpected error but cert could not
  85. * mapped (probably because ldap entry doesn't exist).
  86. * otherwise return LDAPU_CERT_MAP_FUNCTION_FAILED.
  87. */
  88. typedef int (*CertMapFn_t)(void *cert, LDAP *ld, void *certmap_info,
  89. char **ldapdn, char **filter);
  90. /*
  91. * CertSearchFn_t -
  92. * This is a typedef for cert search function. The search function is
  93. * called by the function ldapu_cert_to_ldap_entry after calling the mapping
  94. * function. The candidate 'dn' and 'filter' returned by the mapping
  95. * function is passed to this function.
  96. * The default search function works as follows:
  97. * 1. If the 'filter' is NULL, default it to 'objectclass=*'.
  98. * 2. If the 'dn' is non-NULL, do a base level search with the 'dn' and
  99. * 'filter'. If it succeeds, we are done. If there is no serious
  100. * error (LDAP_NO_SUCH_OBJECT is not serious error yet), continue.
  101. * 3. If the 'dn' is NULL, default it to 'basedn'.
  102. * 4. Perform a 'subtree' search in LDAP for the 'dn' and the 'filter'.
  103. * 5. Return the results of the last search.
  104. * Parameters:
  105. * cert - cert to be mapped. You can pass this to
  106. * functions ldapu_get_cert_XYZ.
  107. * ld - Handle to the connection to the directory server.
  108. * certmap_info - This structure contains information about the
  109. * configuration parameters for the cert's issuer (CA).
  110. * This structure can be passed to the function
  111. * ldapu_certmap_info_attrval to get value for a particular
  112. * configuration attribute (or a property).
  113. * suffix - If the ldapdn is empty then use this DN to begin the
  114. * search. This is the DN of the root object in LDAP
  115. * Directory.
  116. * ldapdn - candidate 'dn' returned by the mapping function.
  117. * filter - returned by the mapping function.
  118. * attrs - list of attributes to return from the search. If this is
  119. * NULL, all attributes are returned.
  120. * res - result of the search which is passed to the verify
  121. * function.
  122. *
  123. * Return Value:
  124. * return LDAPU_SUCCESS upon successful completion
  125. * return LDAPU_FAILED there is no unexpected error but entries matching the
  126. * 'dn' and 'filter' doesn't exist.
  127. * otherwise return LDAPU_CERT_SEARCH_FUNCTION_FAILED.
  128. */
  129. typedef int (*CertSearchFn_t)(void *cert, LDAP *ld, void *certmap_info,
  130. const char *suffix, const char *ldapdn,
  131. const char *filter, const char **attrs,
  132. LDAPMessage ***res);
  133. /*
  134. * CertVerifyFn_t -
  135. * This is a typedef for cert verify function. The verify function is
  136. * called by the function ldapu_cert_to_ldap_entry after the cert is
  137. * successfully mapped to ldapdn and filter, and an entry matching that
  138. * exists in the directory server. The verify fn may get called for
  139. * multiple matched entries. This function must go through all the entries
  140. * and check which one is appropriate. The pointer to that entry must be
  141. * passed back in the 'LDAPMessage **entry' parameter.
  142. * Parameters:
  143. * cert - Original cert to be mapped. You can pass this to
  144. * functions ldapu_get_cert_XYZ.
  145. * ld - Handle to the connection to the directory server.
  146. * certmap_info - This structure contains information about the
  147. * configuration parameters for the cert's issuer (CA).
  148. * This structure can be passed to the function
  149. * ldapu_certmap_info_attrval to get value for a particular
  150. * configuration attribute (or a property).
  151. * res - cert is first mapped to ldapdn and filter. 'res' is the
  152. * result of ldap search using the ldapdn and filter.
  153. * 'ld' and 'res' can be used in the calls to ldapsdk API.
  154. * entry - pointer to the entry from 'res' which is the correct match
  155. * according to the verify function.
  156. *
  157. * Return Values:
  158. * return LDAPU_SUCCESS upon successful completion (cert is verified)
  159. * return LDAPU_FAILED there is no unexpected error but cert could not
  160. * verified (probably because it was revoked).
  161. * otherwise return LDAPU_CERT_VERIFY_FUNCTION_FAILED.
  162. */
  163. typedef int (*CertVerifyFn_t)(void *cert, LDAP *ld, void *certmap_info,
  164. LDAPMessage *res, LDAPMessage **entry);
  165. /*
  166. * CertmapInitFn_t -
  167. * This is a typedef for user defined init function. An init function can be
  168. * specified in the config file (<ServerRoot>/userdb/certmap.conf) per issuer
  169. * of a certificate. This init function must from the user's library, also
  170. * loaded from the config file using the 'library' property. The init
  171. * function is specified in the config file using the 'InitFn' property.
  172. * When the config file is loaded, any user defined init functions will be
  173. * called with the certmap_info pertaining to the issuer (CA).
  174. * Parameters:
  175. * certmap_info - This structure contains information about the
  176. * configuration parameters for the cert's issuer (CA).
  177. * This structure can be passed to the function
  178. * ldapu_certmap_info_attrval to get value for a particular
  179. * configuration attribute (or a property).
  180. *
  181. * Return Value:
  182. * return LDAPU_SUCCESS upon successful completion
  183. * otherwise return LDAPU_CERT_MAP_INITFN_FAILED. The server startup will be
  184. * aborted if the return value is not LDAPU_SUCCESS.
  185. */
  186. typedef int (*CertMapInitFn_t)(void *certmap_info, const char *issuerName,
  187. const char *issuerDN, const char *libname);
  188. /*
  189. * Refer to the description of the function ldapu_get_cert_ava_val
  190. */
  191. enum {
  192. LDAPU_SUBJECT_DN,
  193. LDAPU_ISSUER_DN
  194. };
  195. /* ldapu_cert_to_ldap_entry */
  196. typedef int (*t_ldapu_cert_to_ldap_entry)(void *cert, LDAP *ld,
  197. const char *suffix,
  198. LDAPMessage **res);
  199. /* ldapu_set_cert_mapfn */
  200. typedef int (*t_ldapu_set_cert_mapfn)(const char *issuerDN,
  201. CertMapFn_t mapfn);
  202. /* ldapu_get_cert_mapfn */
  203. typedef CertMapFn_t (*t_ldapu_get_cert_mapfn) (const char *issuerDN);
  204. /* ldapu_set_cert_searchfn */
  205. typedef int (*t_ldapu_set_cert_searchfn) (const char *issuerDN,
  206. CertSearchFn_t searchfn);
  207. /* ldapu_get_cert_searchfn */
  208. typedef CertSearchFn_t (*t_ldapu_get_cert_searchfn) (const char *issuerDN);
  209. /* ldapu_set_cert_verifyfn */
  210. typedef int (*t_ldapu_set_cert_verifyfn) (const char *issuerDN,
  211. CertVerifyFn_t verifyFn);
  212. /* ldapu_get_cert_verifyfn */
  213. typedef CertVerifyFn_t (*t_ldapu_get_cert_verifyfn) (const char *issuerDN);
  214. /* ldapu_get_cert_subject_dn */
  215. typedef int (*t_ldapu_get_cert_subject_dn) (void *cert, char **subjectDN);
  216. /* ldapu_get_cert_issuer_dn */
  217. typedef int (*t_ldapu_get_cert_issuer_dn) (void *cert, char **issuerDN);
  218. /* ldapu_get_cert_ava_val */
  219. typedef int (*t_ldapu_get_cert_ava_val) (void *cert, int which_dn,
  220. const char *attr, char ***val);
  221. /* ldapu_free_cert_ava_val */
  222. typedef int (*t_ldapu_free_cert_ava_val) (char **val);
  223. /* ldapu_get_cert_der */
  224. typedef int (*t_ldapu_get_cert_der) (void *cert, unsigned char **derCert,
  225. unsigned int *len);
  226. /* ldapu_issuer_certinfo */
  227. typedef int (*t_ldapu_issuer_certinfo) (const char *issuerDN,
  228. void **certmap_info);
  229. /* ldapu_certmap_info_attrval */
  230. typedef int (*t_ldapu_certmap_info_attrval) (void *certmap_info,
  231. const char *attr, char **val);
  232. /* ldapu_err2string */
  233. typedef char * (*t_ldapu_err2string) (int err);
  234. /* ldapu_free */
  235. typedef void (*t_ldapu_free_old) (char *ptr);
  236. typedef void (*t_ldapu_free) (void *ptr);
  237. /* ldapu_malloc */
  238. typedef void *(*t_ldapu_malloc) (int size);
  239. /* ldapu_strdup */
  240. typedef char *(*t_ldapu_strdup) (const char *ptr);
  241. typedef struct LDAPUDispatchVector LDAPUDispatchVector_t;
  242. struct LDAPUDispatchVector {
  243. t_ldapu_cert_to_ldap_entry f_ldapu_cert_to_ldap_entry;
  244. t_ldapu_set_cert_mapfn f_ldapu_set_cert_mapfn;
  245. t_ldapu_get_cert_mapfn f_ldapu_get_cert_mapfn;
  246. t_ldapu_set_cert_searchfn f_ldapu_set_cert_searchfn;
  247. t_ldapu_get_cert_searchfn f_ldapu_get_cert_searchfn;
  248. t_ldapu_set_cert_verifyfn f_ldapu_set_cert_verifyfn;
  249. t_ldapu_get_cert_verifyfn f_ldapu_get_cert_verifyfn;
  250. t_ldapu_get_cert_subject_dn f_ldapu_get_cert_subject_dn;
  251. t_ldapu_get_cert_issuer_dn f_ldapu_get_cert_issuer_dn;
  252. t_ldapu_get_cert_ava_val f_ldapu_get_cert_ava_val;
  253. t_ldapu_free_cert_ava_val f_ldapu_free_cert_ava_val;
  254. t_ldapu_get_cert_der f_ldapu_get_cert_der;
  255. t_ldapu_issuer_certinfo f_ldapu_issuer_certinfo;
  256. t_ldapu_certmap_info_attrval f_ldapu_certmap_info_attrval;
  257. t_ldapu_err2string f_ldapu_err2string;
  258. t_ldapu_free_old f_ldapu_free_old;
  259. t_ldapu_malloc f_ldapu_malloc;
  260. t_ldapu_strdup f_ldapu_strdup;
  261. t_ldapu_free f_ldapu_free;
  262. };
  263. #ifdef INTLDAPU
  264. NSAPI_PUBLIC extern LDAPUDispatchVector_t *__ldapu_table;
  265. #else
  266. typedef int (*CertMapDLLInitFn_t)(LDAPUDispatchVector_t **table);
  267. NSAPI_PUBLIC extern int CertMapDLLInitFn(LDAPUDispatchVector_t **table);
  268. extern LDAPUDispatchVector_t *__ldapu_table;
  269. #if defined( _WINDOWS ) || defined( _WIN32 ) || defined( XP_WIN32 )
  270. #define CertmapDLLInitFnTbl LDAPUDispatchVector_t *__ldapu_table;
  271. #define CertmapDLLInit(rv, libname) \
  272. {\
  273. HANDLE h = LoadLibrary((libname)); \
  274. CertMapDLLInitFn_t init_fn; \
  275. if (!h) return LDAPU_CERT_MAP_INITFN_FAILED; \
  276. init_fn = (CertMapDLLInitFn_t)GetProcAddress(h, "CertMapDLLInitFn"); \
  277. rv = init_fn(&__ldapu_table); \
  278. }
  279. #else
  280. #define CertmapDLLInit(rv, libname)
  281. #define CertmapDLLInitFnTbl
  282. #endif
  283. #endif /* INTLDAPU */
  284. #ifndef INTLDAPU
  285. /*
  286. * ldapu_cert_to_ldap_entry -
  287. * This function is called to map a cert to an ldap entry. It extracts the
  288. * cert issuer information from the given cert. The mapping function set for
  289. * the issuer (if any) or the default mapping function is called to map the
  290. * subject DN from the cert to a candidate ldap DN and filter for ldap
  291. * search. If the mapped ldap DN is NULL, the 'basedn' passed into this
  292. * function is used as a starting place for the search. If the mapped filter
  293. * is NULL, "objectclass=*" is used as a filter. A base level search is
  294. * performed to see if the candidate DN exists in the LDAP database matching
  295. * the filter. If there is no match, a scoped search (sub-tree search) is
  296. * performed. If at least one entry matched the mapped DN and filter, the
  297. * result is passed to the appropriate verify function. The verify function
  298. * is called only if 'VerifyCert' parameter has been set for the cert issuer
  299. * in the certmap.conf file.
  300. * If the verify function succeeds, it must return the pointer to the matched
  301. * 'entry'. If at the end, there is only one matching entry, the mapping is
  302. * successful.
  303. * Parameters:
  304. * cert - cert to be mapped. You can pass this to
  305. * functions ldapu_get_cert_XYZ.
  306. * ld - Handle to the connection to the directory server.
  307. * suffix - If the subject dn is mapped to empty LDAP DN then use this
  308. * DN to begin the search. This is the DN of the root object
  309. * in LDAP Directory.
  310. * res - cert is first mapped to ldapdn and filter. 'res' is the
  311. * result of ldap search using the ldapdn and filter.
  312. * 'ld' and 'res' can be used in the calls to ldapsdk API.
  313. * When done with 'res', free it using ldap_msgfree(res)
  314. *
  315. * Return Value:
  316. * return LDAPU_SUCCESS upon successful completion
  317. * otherwise returns an error code that can be passed to ldapu_err2string.
  318. */
  319. #define ldapu_cert_to_ldap_entry (*__ldapu_table->f_ldapu_cert_to_ldap_entry)
  320. /*
  321. * ldapu_set_cert_mapfn -
  322. * This function can be used to set the cert mapping function for the given
  323. * issuer (CA). If the mapping information doesn't exist for the given
  324. * issuer then a new one will be created and the mapping function will be
  325. * set. When creating the new mapping information, the default mapping
  326. * information is copied.
  327. * Parameters:
  328. * issuerDN - DN of the cert issuer. This mapping function will be used
  329. * for all certs issued by this issuer. If the issuerDN is
  330. * NULL, the given 'mapfn' becomes the default mapping
  331. * function (which is used when no mapping function has been
  332. * set for the cert's issuer).
  333. * mapfn - the mapping function. Look at the desciption of
  334. * CertMapFn_t to find out more about the mapping functions.
  335. *
  336. * Return Value:
  337. * return LDAPU_SUCCESS upon successful completion
  338. * otherwise returns an error code that can be passed to ldapu_err2string.
  339. */
  340. #define ldapu_set_cert_mapfn (*__ldapu_table->f_ldapu_set_cert_mapfn)
  341. /*
  342. * ldapu_get_cert_mapfn -
  343. * This function can be used to get the cert mapping function for the given
  344. * issuer (CA). This will always return a non-NULL function.
  345. * Parameters:
  346. * issuerDN - DN of the cert issuer for which the mapping function is to
  347. * be retrieved. If this is NULL, default mapping function
  348. * is returned.
  349. *
  350. * Return Value:
  351. * The mapping function set for the issuer is returned. If the issuerDN is
  352. * NULL or if no specific mapping function has been set for the issuer, the
  353. * default mapping function is returned.
  354. */
  355. #define ldapu_get_cert_mapfn (*__ldapu_table->f_ldapu_get_cert_mapfn)
  356. /*
  357. * ldapu_set_cert_searchfn -
  358. * This function can be used to set the cert search function for the given
  359. * issuer (CA).
  360. * Parameters:
  361. * issuerDN - DN of the cert issuer. This search function will be used
  362. * for all certs issued by this issuer. If the issuerDN is
  363. * NULL, the given 'searchfn' becomes the default search
  364. * function (which is used when no search function has been
  365. * set for the cert's issuer).
  366. * searchfn - the search function. Look at the desciption of
  367. * CertSearchFn_t to find out more about the search functions.
  368. *
  369. * Return Value:
  370. * return LDAPU_SUCCESS upon successful completion
  371. * otherwise returns an error code that can be passed to ldapu_err2string.
  372. */
  373. #define ldapu_set_cert_searchfn (*__ldapu_table->f_ldapu_set_cert_searchfn)
  374. /*
  375. * ldapu_get_cert_searchfn -
  376. * This function can be used to get the cert search function for the given
  377. * issuer (CA). This will always return a non-NULL function.
  378. * Parameters:
  379. * issuerDN - DN of the cert issuer for which the search function is to
  380. * be retrieved. If this is NULL, the default search
  381. * function is returned.
  382. *
  383. * Return Value:
  384. * The search function set for the issuer is returned. If the issuerDN is
  385. * NULL or if no specific search function has been set for the issuer, the
  386. * default search function is returned.
  387. */
  388. #define ldapu_get_cert_searchfn (*__ldapu_table->f_ldapu_get_cert_searchfn)
  389. /*
  390. * ldapu_set_cert_verifyfn -
  391. * This function can be used to set the cert verify function for the given
  392. * issuer (CA). If the mapping information doesn't exist for the given
  393. * issuer then a new one will be created and the verify function will be
  394. * set. When creating the new mapping information, the default mapping
  395. * information is copied.
  396. * Parameters:
  397. * issuerDN - DN of the cert issuer. This verify function will be used
  398. * for all certs issued by this issuer. If the issuerDN is
  399. * NULL, the given 'verifyFn' becomes the default verify
  400. * function (which is used when no verify function has been
  401. * set for the cert's issuer).
  402. * verifyFn - the verify function. Look at the desciption of
  403. * CertMapFn_t to find out more about the verify functions.
  404. *
  405. * Return Value:
  406. * return LDAPU_SUCCESS upon successful completion
  407. * otherwise returns an error code that can be passed to ldapu_err2string.
  408. */
  409. #define ldapu_set_cert_verifyfn (*__ldapu_table->f_ldapu_set_cert_verifyfn)
  410. /*
  411. * ldapu_get_cert_verifyfn -
  412. * This function can be used to get the cert verify function for the given
  413. * issuer (CA). This function can return NULL when there is no applicable
  414. * verify function.
  415. * Parameters:
  416. * issuerDN - DN of the cert issuer for which the verify function is to
  417. * be retrieved. If this is NULL, default verify function
  418. * is returned.
  419. *
  420. * Return Value:
  421. * The verify function set for the issuer is returned. If the issuerDN is
  422. * NULL or if no specific verify function has been set for the issuer, the
  423. * default verify function is returned. This function can return NULL when
  424. * there is no applicable verify function.
  425. */
  426. #define ldapu_get_cert_verifyfn (*__ldapu_table->f_ldapu_get_cert_verifyfn)
  427. /*
  428. * ldapu_get_cert_subject_dn -
  429. * This function can be used to get the subject DN from the cert. Free the
  430. * subjectDN using 'free' after you are done using it.
  431. * Parameters:
  432. * cert - cert from which the DN is to be extracted.
  433. * subjectDN - subjectDN extracted from the cert. Free it using 'free'
  434. * after it is no longer required.
  435. *
  436. * Return Value:
  437. * return LDAPU_SUCCESS upon successful completion
  438. * otherwise returns an error code that can be passed to ldapu_err2string.
  439. */
  440. #define ldapu_get_cert_subject_dn (*__ldapu_table->f_ldapu_get_cert_subject_dn)
  441. /*
  442. * ldapu_get_cert_issuer_dn -
  443. * This function can be used to get the issuer DN from the cert. Free the
  444. * issuerDN using 'free' after you are done using it.
  445. * Parameters:
  446. * cert - cert from which the DN is to be extracted.
  447. * issuerDN - issuerDN extracted from the cert. Free it using 'free'
  448. * after it is no longer required.
  449. *
  450. * Return Value:
  451. * return LDAPU_SUCCESS upon successful completion
  452. * otherwise returns an error code that can be passed to ldapu_err2string.
  453. */
  454. #define ldapu_get_cert_issuer_dn (*__ldapu_table->f_ldapu_get_cert_issuer_dn)
  455. /*
  456. * ldapu_get_cert_ava_val -
  457. * This function can be used to get value of the given attribute from either
  458. * the subject DN or the issuer DN from the cert.
  459. * Parameters:
  460. * cert - cert from which the values are to be extracted.
  461. * which_dn - Should be either LDAPU_ISSUER_DN or LDAPU_SUBJECT_DN.
  462. * attr - Should be one of "CN", "OU", "O", "C", "UID", "MAIL",
  463. * "E", "L", and "ST".
  464. * val - An array of attribute values extracted from the cert.
  465. * There could be multiple values. The last entry in the
  466. * array is NULL. You must free this array of strings after
  467. * you are done with it (using the function
  468. * ldapu_free_cert_ava_val). 'val' is initialized to NULL if
  469. * there is an error.
  470. *
  471. * Return Value:
  472. * return LDAPU_SUCCESS upon successful completion
  473. * otherwise returns an error code that can be passed to ldapu_err2string.
  474. */
  475. #define ldapu_get_cert_ava_val (*__ldapu_table->f_ldapu_get_cert_ava_val)
  476. /*
  477. * ldapu_free_cert_ava_val -
  478. * This function can be used to free the array returned by the
  479. * ldapu_get_cert_ava_val function.
  480. * Parameters:
  481. * val - An array of attribute values returned by
  482. * ldapu_get_cert_ava_val.
  483. *
  484. * Return Value:
  485. * return LDAPU_SUCCESS upon successful completion
  486. * otherwise returns an error code that can be passed to ldapu_err2string.
  487. */
  488. #define ldapu_free_cert_ava_val (*__ldapu_table->f_ldapu_free_cert_ava_val)
  489. /*
  490. * ldapu_get_cert_der -
  491. * This function can be used to get the original DER encoded cert for the
  492. * given cert.
  493. * Parameters:
  494. * cert - cert from which the original DER is to be extracted.
  495. * derCert - the original DER encoded cert
  496. * len - length of derCert
  497. *
  498. * Return Value:
  499. * return LDAPU_SUCCESS upon successful completion
  500. * otherwise returns an error code that can be passed to ldapu_err2string.
  501. */
  502. #define ldapu_get_cert_der (*__ldapu_table->f_ldapu_get_cert_der)
  503. /*
  504. * ldapu_issuer_certinfo -
  505. * This function can be used to get the handle on the internal structure for
  506. * the given issuer. This handle can be passed to ldapu_certmap_info_attrval
  507. * to get configuration attribute values for the issuer.
  508. * Parameters:
  509. * issuerDN - DN of the issuer for whom the handle on internal structure
  510. * is requested. If issuerDN is NULL, the handle to the
  511. * default configuration information is returned.
  512. * certmap_info - This structure contains information about the
  513. * configuration parameters for the cert's issuer (CA).
  514. * This structure can be passed to the function
  515. * ldapu_certmap_info_attrval to get value for a particular
  516. * configuration attribute (or a property).
  517. *
  518. * Return Value:
  519. * return LDAPU_SUCCESS upon successful completion
  520. * otherwise returns an error code that can be passed to ldapu_err2string.
  521. * CAUTION: DON'T FREE THE 'certmap_info' STRUCTURE.
  522. */
  523. #define ldapu_issuer_certinfo (*__ldapu_table->f_ldapu_issuer_certinfo)
  524. /*
  525. * ldapu_certmap_info_attrval -
  526. * This function can be used to get values for the given attribute/property
  527. * from the given certmap_info. You can get handle on the certmap_info by
  528. * calling the ldapu_issuer_certinfo function. Free the 'val' using 'free'
  529. * after it is no longer required.
  530. * Parameters:
  531. * certmap_info - This structure contains information about the
  532. * configuration parameters for the cert's issuer (CA).
  533. * attr - name of the attribute/property for which the value is to
  534. * be returned. The attribute can be one of the attributes
  535. * listed above (LDAPU_ATTR_XYZ). User defined attributes
  536. * can also be used.
  537. * val - Value of the 'attr' from the 'certmap_info'.
  538. *
  539. * Return Value:
  540. * return LDAPU_SUCCESS upon successful completion
  541. * otherwise returns an error code that can be passed to ldapu_err2string.
  542. */
  543. #define ldapu_certmap_info_attrval (*__ldapu_table->f_ldapu_certmap_info_attrval)
  544. /*
  545. * ldapu_err2string -
  546. * This function can be used to print any of the ldaputil or LDAP error
  547. * code.
  548. * Parameters:
  549. * err - error code to be converted to printable string.
  550. *
  551. * Return Value:
  552. * Printable representation of the given error code.
  553. */
  554. #define ldapu_err2string (*__ldapu_table->f_ldapu_err2string)
  555. /*
  556. * ldapu_free -
  557. * This function should be used to free the memory allocated by
  558. * ldapu_* functions if the ldapu_* function doesn't have a corresponding
  559. * 'free' function. Use this function for free'ing the memory allocated by
  560. * the following functions:
  561. * ldapu_get_cert_subject_dn
  562. * ldapu_get_cert_issuer_dn
  563. * ldapu_get_cert_der
  564. * ldapu_certmap_info_attrval
  565. * To free memory allocated by ldapu_get_cert_ava_val, use
  566. * ldapu_free_cert_ava_val. Do not free the certmap_info pointer returned by
  567. * ldapu_issuer_certinfo.
  568. * Parameters:
  569. * ptr - pointer returned by ldapu_get_cert_* functions.
  570. */
  571. #define ldapu_free (*__ldapu_table->f_ldapu_free)
  572. /*
  573. * ldapu_malloc -
  574. * This function is a cover function for the 'malloc' system call. On NT, it
  575. * is best to alloc & free the memory in the same DLL.
  576. * Parameters:
  577. * size - size of the memory to be allocated
  578. * Return Value:
  579. * same as 'malloc' -- pointer to the allocated memory or NULL on failure.
  580. */
  581. #define ldapu_malloc (*__ldapu_table->f_ldapu_malloc)
  582. /*
  583. * ldapu_strdup -
  584. * This function is a cover function for the 'strdup' system call. On NT, it
  585. * is best to alloc & free the memory in the same DLL.
  586. * Parameters:
  587. * ptr - Pointer to the string to be copied
  588. * Return Value:
  589. * same as 'strdup' -- pointer to the copied string or NULL on failure.
  590. */
  591. #define ldapu_strdup (*__ldapu_table->f_ldapu_strdup)
  592. #endif /* !INTLDAPU */
  593. #endif /* _PUBLIC_CERTMAP_H */