190792Sgshapiro/* 2261363Sgshapiro * Copyright (c) 2001-2003, 2005-2007 Proofpoint, Inc. and its suppliers. 390792Sgshapiro * All rights reserved. 490792Sgshapiro * 590792Sgshapiro * By using this file, you agree to the terms and conditions set 690792Sgshapiro * forth in the LICENSE file which can be found at the top level of 790792Sgshapiro * the sendmail distribution. 890792Sgshapiro * 9266692Sgshapiro * $Id: ldap.h,v 1.35 2013-11-22 20:51:31 ca Exp $ 1090792Sgshapiro */ 1190792Sgshapiro 1290792Sgshapiro#ifndef SM_LDAP_H 1390792Sgshapiro# define SM_LDAP_H 1490792Sgshapiro 1590792Sgshapiro# include <sm/conf.h> 1690792Sgshapiro# include <sm/rpool.h> 1790792Sgshapiro 1894334Sgshapiro/* 1994334Sgshapiro** NOTE: These should be changed from LDAPMAP_* to SM_LDAP_* 20168515Sgshapiro** in the next major release (8.x+1) of sendmail. 2194334Sgshapiro*/ 2294334Sgshapiro 2390792Sgshapiro# ifndef LDAPMAP_MAX_ATTR 2490792Sgshapiro# define LDAPMAP_MAX_ATTR 64 2590792Sgshapiro# endif /* ! LDAPMAP_MAX_ATTR */ 2690792Sgshapiro# ifndef LDAPMAP_MAX_FILTER 2790792Sgshapiro# define LDAPMAP_MAX_FILTER 1024 2890792Sgshapiro# endif /* ! LDAPMAP_MAX_FILTER */ 2990792Sgshapiro# ifndef LDAPMAP_MAX_PASSWD 3090792Sgshapiro# define LDAPMAP_MAX_PASSWD 256 3190792Sgshapiro# endif /* ! LDAPMAP_MAX_PASSWD */ 3290792Sgshapiro 3390792Sgshapiro# if LDAPMAP 3490792Sgshapiro 35168515Sgshapiro/* maximum number of arguments in a map lookup, see sendmail.h: MAX_MAP_ARGS */ 36168515Sgshapiro# define SM_LDAP_ARGS 10 37168515Sgshapiro 38168515Sgshapiro/* error codes from sm_ldap_search*() */ 39168515Sgshapiro# define SM_LDAP_ERR (-1) /* generic error: ldap_search(3) */ 40168515Sgshapiro# define SM_LDAP_ERR_ARG_MISS (-2) /* an argument is missing */ 41168515Sgshapiro 4290792Sgshapiro/* Attribute types */ 43132943Sgshapiro# define SM_LDAP_ATTR_NONE (-1) 44132943Sgshapiro# define SM_LDAP_ATTR_OBJCLASS 0 45132943Sgshapiro# define SM_LDAP_ATTR_NORMAL 1 46132943Sgshapiro# define SM_LDAP_ATTR_DN 2 47132943Sgshapiro# define SM_LDAP_ATTR_FILTER 3 48132943Sgshapiro# define SM_LDAP_ATTR_URL 4 4990792Sgshapiro 5090792Sgshapiro/* sm_ldap_results() flags */ 51132943Sgshapiro# define SM_LDAP_SINGLEMATCH 0x0001 52132943Sgshapiro# define SM_LDAP_MATCHONLY 0x0002 53132943Sgshapiro# define SM_LDAP_USE_ALLATTR 0x0004 54157001Sgshapiro# define SM_LDAP_SINGLEDN 0x0008 5594334Sgshapiro 5690792Sgshapirostruct sm_ldap_struct 5790792Sgshapiro{ 5890792Sgshapiro /* needed for ldap_open or ldap_init */ 59132943Sgshapiro char *ldap_uri; 60132943Sgshapiro char *ldap_host; 6190792Sgshapiro int ldap_port; 6294334Sgshapiro int ldap_version; 6390792Sgshapiro pid_t ldap_pid; 6490792Sgshapiro 6590792Sgshapiro /* options set in ld struct before ldap_bind_s */ 6690792Sgshapiro int ldap_deref; 6790792Sgshapiro time_t ldap_timelimit; 6890792Sgshapiro int ldap_sizelimit; 6990792Sgshapiro int ldap_options; 7090792Sgshapiro 7190792Sgshapiro /* args for ldap_bind_s */ 7290792Sgshapiro LDAP *ldap_ld; 7390792Sgshapiro char *ldap_binddn; 7490792Sgshapiro char *ldap_secret; 7590792Sgshapiro int ldap_method; 7690792Sgshapiro 7790792Sgshapiro /* args for ldap_search */ 7890792Sgshapiro char *ldap_base; 7990792Sgshapiro int ldap_scope; 8090792Sgshapiro char *ldap_filter; 8190792Sgshapiro char *ldap_attr[LDAPMAP_MAX_ATTR + 1]; 8290792Sgshapiro int ldap_attr_type[LDAPMAP_MAX_ATTR + 1]; 8394334Sgshapiro char *ldap_attr_needobjclass[LDAPMAP_MAX_ATTR + 1]; 8490792Sgshapiro bool ldap_attrsonly; 85168515Sgshapiro bool ldap_multi_args; 8690792Sgshapiro 8790792Sgshapiro /* args for ldap_result */ 8890792Sgshapiro struct timeval ldap_timeout; 8990792Sgshapiro LDAPMessage *ldap_res; 9090792Sgshapiro 9190792Sgshapiro /* ldapmap_lookup options */ 9290792Sgshapiro char ldap_attrsep; 9390792Sgshapiro 94173340Sgshapiro# if _FFR_LDAP_NETWORK_TIMEOUT 95203004Sgshapiro int ldap_networktmo; 96173340Sgshapiro# endif /* _FFR_LDAP_NETWORK_TIMEOUT */ 97173340Sgshapiro 9890792Sgshapiro /* Linked list of maps sharing the same LDAP binding */ 9990792Sgshapiro void *ldap_next; 10090792Sgshapiro}; 10190792Sgshapiro 10290792Sgshapirotypedef struct sm_ldap_struct SM_LDAP_STRUCT; 10390792Sgshapiro 10494334Sgshapirostruct sm_ldap_recurse_entry 10590792Sgshapiro{ 106168515Sgshapiro char *lr_search; 107168515Sgshapiro int lr_type; 108168515Sgshapiro LDAPURLDesc *lr_ludp; 109168515Sgshapiro char **lr_attrs; 110168515Sgshapiro bool lr_done; 11190792Sgshapiro}; 11290792Sgshapiro 11394334Sgshapirostruct sm_ldap_recurse_list 11494334Sgshapiro{ 115168515Sgshapiro int lrl_size; 116168515Sgshapiro int lrl_cnt; 117168515Sgshapiro struct sm_ldap_recurse_entry **lrl_data; 11894334Sgshapiro}; 11994334Sgshapiro 12094334Sgshapirotypedef struct sm_ldap_recurse_entry SM_LDAP_RECURSE_ENTRY; 12190792Sgshapirotypedef struct sm_ldap_recurse_list SM_LDAP_RECURSE_LIST; 12290792Sgshapiro 12390792Sgshapiro/* functions */ 12490792Sgshapiroextern void sm_ldap_clear __P((SM_LDAP_STRUCT *)); 12590792Sgshapiroextern bool sm_ldap_start __P((char *, SM_LDAP_STRUCT *)); 12690792Sgshapiroextern int sm_ldap_search __P((SM_LDAP_STRUCT *, char *)); 127168515Sgshapiroextern int sm_ldap_search_m __P((SM_LDAP_STRUCT *, char **)); 12894334Sgshapiroextern int sm_ldap_results __P((SM_LDAP_STRUCT *, int, int, int, 12994334Sgshapiro SM_RPOOL_T *, char **, int *, int *, 13090792Sgshapiro SM_LDAP_RECURSE_LIST *)); 13190792Sgshapiroextern void sm_ldap_setopts __P((LDAP *, SM_LDAP_STRUCT *)); 13290792Sgshapiroextern int sm_ldap_geterrno __P((LDAP *)); 13390792Sgshapiroextern void sm_ldap_close __P((SM_LDAP_STRUCT *)); 13494334Sgshapiro 13594334Sgshapiro/* Portability defines */ 13694334Sgshapiro# if !SM_CONF_LDAP_MEMFREE 13794334Sgshapiro# define ldap_memfree(x) ((void) 0) 13894334Sgshapiro# endif /* !SM_CONF_LDAP_MEMFREE */ 13994334Sgshapiro 14090792Sgshapiro# endif /* LDAPMAP */ 14190792Sgshapiro#endif /* ! SM_LDAP_H */ 142