ldap.h revision 157001
190792Sgshapiro/*
2157001Sgshapiro * Copyright (c) 2001-2003, 2005 Sendmail, 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 *
9157001Sgshapiro *	$Id: ldap.h,v 1.28 2005/06/23 23:11:21 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_*
2094334Sgshapiro**        in the next major release (8.13) 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
3590792Sgshapiro/* Attribute types */
36132943Sgshapiro#  define SM_LDAP_ATTR_NONE		(-1)
37132943Sgshapiro#  define SM_LDAP_ATTR_OBJCLASS	0
38132943Sgshapiro#  define SM_LDAP_ATTR_NORMAL		1
39132943Sgshapiro#  define SM_LDAP_ATTR_DN		2
40132943Sgshapiro#  define SM_LDAP_ATTR_FILTER		3
41132943Sgshapiro#  define SM_LDAP_ATTR_URL		4
4290792Sgshapiro
4390792Sgshapiro/* sm_ldap_results() flags */
44132943Sgshapiro#  define SM_LDAP_SINGLEMATCH	0x0001
45132943Sgshapiro#  define SM_LDAP_MATCHONLY	0x0002
46132943Sgshapiro#  define SM_LDAP_USE_ALLATTR	0x0004
47157001Sgshapiro#  define SM_LDAP_SINGLEDN	0x0008
4894334Sgshapiro
4990792Sgshapirostruct sm_ldap_struct
5090792Sgshapiro{
5190792Sgshapiro	/* needed for ldap_open or ldap_init */
52132943Sgshapiro	char		*ldap_uri;
53132943Sgshapiro	char		*ldap_host;
5490792Sgshapiro	int		ldap_port;
5594334Sgshapiro	int		ldap_version;
5690792Sgshapiro	pid_t		ldap_pid;
5790792Sgshapiro
5890792Sgshapiro	/* options set in ld struct before ldap_bind_s */
5990792Sgshapiro	int		ldap_deref;
6090792Sgshapiro	time_t		ldap_timelimit;
6190792Sgshapiro	int		ldap_sizelimit;
6290792Sgshapiro	int		ldap_options;
6390792Sgshapiro
6490792Sgshapiro	/* args for ldap_bind_s */
6590792Sgshapiro	LDAP		*ldap_ld;
6690792Sgshapiro	char		*ldap_binddn;
6790792Sgshapiro	char		*ldap_secret;
6890792Sgshapiro	int		ldap_method;
6990792Sgshapiro
7090792Sgshapiro	/* args for ldap_search */
7190792Sgshapiro	char		*ldap_base;
7290792Sgshapiro	int		ldap_scope;
7390792Sgshapiro	char		*ldap_filter;
7490792Sgshapiro	char		*ldap_attr[LDAPMAP_MAX_ATTR + 1];
7590792Sgshapiro	int		ldap_attr_type[LDAPMAP_MAX_ATTR + 1];
7694334Sgshapiro	char		*ldap_attr_needobjclass[LDAPMAP_MAX_ATTR + 1];
7790792Sgshapiro	bool		ldap_attrsonly;
7890792Sgshapiro
7990792Sgshapiro	/* args for ldap_result */
8090792Sgshapiro	struct timeval	ldap_timeout;
8190792Sgshapiro	LDAPMessage	*ldap_res;
8290792Sgshapiro
8390792Sgshapiro	/* ldapmap_lookup options */
8490792Sgshapiro	char		ldap_attrsep;
8590792Sgshapiro
8690792Sgshapiro	/* Linked list of maps sharing the same LDAP binding */
8790792Sgshapiro	void		*ldap_next;
8890792Sgshapiro};
8990792Sgshapiro
9090792Sgshapirotypedef struct sm_ldap_struct		SM_LDAP_STRUCT;
9190792Sgshapiro
9294334Sgshapirostruct sm_ldap_recurse_entry
9390792Sgshapiro{
9490792Sgshapiro	char *lr_search;
9590792Sgshapiro	int lr_type;
96132943Sgshapiro	LDAPURLDesc *lr_ludp;
97132943Sgshapiro	char **lr_attrs;
9894334Sgshapiro	bool lr_done;
9990792Sgshapiro};
10090792Sgshapiro
10194334Sgshapirostruct sm_ldap_recurse_list
10294334Sgshapiro{
10394334Sgshapiro	int lr_size;
10494334Sgshapiro	int lr_cnt;
10594334Sgshapiro	struct sm_ldap_recurse_entry **lr_data;
10694334Sgshapiro};
10794334Sgshapiro
10894334Sgshapirotypedef struct sm_ldap_recurse_entry	SM_LDAP_RECURSE_ENTRY;
10990792Sgshapirotypedef struct sm_ldap_recurse_list	SM_LDAP_RECURSE_LIST;
11090792Sgshapiro
11190792Sgshapiro/* functions */
11290792Sgshapiroextern void	sm_ldap_clear __P((SM_LDAP_STRUCT *));
11390792Sgshapiroextern bool	sm_ldap_start __P((char *, SM_LDAP_STRUCT *));
11490792Sgshapiroextern int	sm_ldap_search __P((SM_LDAP_STRUCT *, char *));
11594334Sgshapiroextern int	sm_ldap_results __P((SM_LDAP_STRUCT *, int, int, int,
11694334Sgshapiro				     SM_RPOOL_T *, char **, int *, int *,
11790792Sgshapiro				     SM_LDAP_RECURSE_LIST *));
11890792Sgshapiroextern void	sm_ldap_setopts __P((LDAP *, SM_LDAP_STRUCT *));
11990792Sgshapiroextern int	sm_ldap_geterrno __P((LDAP *));
12090792Sgshapiroextern void	sm_ldap_close __P((SM_LDAP_STRUCT *));
12194334Sgshapiro
12294334Sgshapiro/* Portability defines */
12394334Sgshapiro#  if !SM_CONF_LDAP_MEMFREE
12494334Sgshapiro#   define ldap_memfree(x)	((void) 0)
12594334Sgshapiro#  endif /* !SM_CONF_LDAP_MEMFREE */
12694334Sgshapiro
12790792Sgshapiro# endif /* LDAPMAP */
12890792Sgshapiro#endif /* ! SM_LDAP_H */
129