xref: /freebsd/contrib/sendmail/include/sm/ldap.h (revision eacee0ff7ec955b32e09515246bd97b6edcd2b0f)
1 /*
2  * Copyright (c) 2001-2002 Sendmail, Inc. and its suppliers.
3  *      All rights reserved.
4  *
5  * By using this file, you agree to the terms and conditions set
6  * forth in the LICENSE file which can be found at the top level of
7  * the sendmail distribution.
8  *
9  *	$Id: ldap.h,v 1.9 2002/01/11 22:06:50 gshapiro Exp $
10  */
11 
12 #ifndef	SM_LDAP_H
13 # define SM_LDAP_H
14 
15 # include <sm/conf.h>
16 # include <sm/rpool.h>
17 
18 # ifndef LDAPMAP_MAX_ATTR
19 #  define LDAPMAP_MAX_ATTR	64
20 # endif /* ! LDAPMAP_MAX_ATTR */
21 # ifndef LDAPMAP_MAX_FILTER
22 #  define LDAPMAP_MAX_FILTER	1024
23 # endif /* ! LDAPMAP_MAX_FILTER */
24 # ifndef LDAPMAP_MAX_PASSWD
25 #  define LDAPMAP_MAX_PASSWD	256
26 # endif /* ! LDAPMAP_MAX_PASSWD */
27 
28 # if LDAPMAP
29 
30 #  if _FFR_LDAP_RECURSION
31 
32 /* Attribute types */
33 #   define LDAPMAP_ATTR_NORMAL	0
34 #   define LDAPMAP_ATTR_DN	1
35 #   define LDAPMAP_ATTR_FILTER	2
36 #   define LDAPMAP_ATTR_URL	3
37 #   define LDAPMAP_ATTR_FINAL	4
38 
39 /* sm_ldap_results() flags */
40 #   define SM_LDAP_SINGLEMATCH	0x0001
41 #   define SM_LDAP_MATCHONLY	0x0002
42 #  endif /* _FFR_LDAP_RECURSION */
43 
44 struct sm_ldap_struct
45 {
46 	/* needed for ldap_open or ldap_init */
47 	char		*ldap_host;
48 	int		ldap_port;
49 	pid_t		ldap_pid;
50 
51 	/* options set in ld struct before ldap_bind_s */
52 	int		ldap_deref;
53 	time_t		ldap_timelimit;
54 	int		ldap_sizelimit;
55 	int		ldap_options;
56 
57 	/* args for ldap_bind_s */
58 	LDAP		*ldap_ld;
59 	char		*ldap_binddn;
60 	char		*ldap_secret;
61 	int		ldap_method;
62 
63 	/* args for ldap_search */
64 	char		*ldap_base;
65 	int		ldap_scope;
66 	char		*ldap_filter;
67 	char		*ldap_attr[LDAPMAP_MAX_ATTR + 1];
68 #  if _FFR_LDAP_RECURSION
69 	int		ldap_attr_type[LDAPMAP_MAX_ATTR + 1];
70 	char		*ldap_attr_final[LDAPMAP_MAX_ATTR + 1];
71 #  endif /* _FFR_LDAP_RECURSION */
72 	bool		ldap_attrsonly;
73 
74 	/* args for ldap_result */
75 	struct timeval	ldap_timeout;
76 	LDAPMessage	*ldap_res;
77 
78 	/* ldapmap_lookup options */
79 	char		ldap_attrsep;
80 
81 	/* Linked list of maps sharing the same LDAP binding */
82 	void		*ldap_next;
83 };
84 
85 typedef struct sm_ldap_struct		SM_LDAP_STRUCT;
86 
87 #  if _FFR_LDAP_RECURSION
88 struct sm_ldap_recurse_list
89 {
90 	char *lr_search;
91 	int lr_type;
92 	struct sm_ldap_recurse_list *lr_next;
93 };
94 
95 typedef struct sm_ldap_recurse_list	SM_LDAP_RECURSE_LIST;
96 #  endif /* _FFR_LDAP_RECURSION */
97 
98 /* functions */
99 extern void	sm_ldap_clear __P((SM_LDAP_STRUCT *));
100 extern bool	sm_ldap_start __P((char *, SM_LDAP_STRUCT *));
101 extern int	sm_ldap_search __P((SM_LDAP_STRUCT *, char *));
102 #  if _FFR_LDAP_RECURSION
103 extern int	sm_ldap_results __P((SM_LDAP_STRUCT *, int, int, char,
104 				     SM_RPOOL_T *, char **,
105 				     SM_LDAP_RECURSE_LIST *));
106 #  endif /* _FFR_LDAP_RECURSION */
107 extern void	sm_ldap_setopts __P((LDAP *, SM_LDAP_STRUCT *));
108 extern int	sm_ldap_geterrno __P((LDAP *));
109 extern void	sm_ldap_close __P((SM_LDAP_STRUCT *));
110 # endif /* LDAPMAP */
111 
112 #endif /* ! SM_LDAP_H */
113