extcmap.h 27 KB

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