xref: /freebsd/contrib/sendmail/include/sm/ldap.h (revision 74bf4e164ba5851606a27d4feff27717452583e5)
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.27 2003/12/20 09:23:47 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 /*
19 **  NOTE: These should be changed from LDAPMAP_* to SM_LDAP_*
20 **        in the next major release (8.13) of sendmail.
21 */
22 
23 # ifndef LDAPMAP_MAX_ATTR
24 #  define LDAPMAP_MAX_ATTR	64
25 # endif /* ! LDAPMAP_MAX_ATTR */
26 # ifndef LDAPMAP_MAX_FILTER
27 #  define LDAPMAP_MAX_FILTER	1024
28 # endif /* ! LDAPMAP_MAX_FILTER */
29 # ifndef LDAPMAP_MAX_PASSWD
30 #  define LDAPMAP_MAX_PASSWD	256
31 # endif /* ! LDAPMAP_MAX_PASSWD */
32 
33 # if LDAPMAP
34 
35 /* Attribute types */
36 #  define SM_LDAP_ATTR_NONE		(-1)
37 #  define SM_LDAP_ATTR_OBJCLASS	0
38 #  define SM_LDAP_ATTR_NORMAL		1
39 #  define SM_LDAP_ATTR_DN		2
40 #  define SM_LDAP_ATTR_FILTER		3
41 #  define SM_LDAP_ATTR_URL		4
42 
43 /* sm_ldap_results() flags */
44 #  define SM_LDAP_SINGLEMATCH	0x0001
45 #  define SM_LDAP_MATCHONLY	0x0002
46 #  define SM_LDAP_USE_ALLATTR	0x0004
47 
48 struct sm_ldap_struct
49 {
50 	/* needed for ldap_open or ldap_init */
51 	char		*ldap_uri;
52 	char		*ldap_host;
53 	int		ldap_port;
54 	int		ldap_version;
55 	pid_t		ldap_pid;
56 
57 	/* options set in ld struct before ldap_bind_s */
58 	int		ldap_deref;
59 	time_t		ldap_timelimit;
60 	int		ldap_sizelimit;
61 	int		ldap_options;
62 
63 	/* args for ldap_bind_s */
64 	LDAP		*ldap_ld;
65 	char		*ldap_binddn;
66 	char		*ldap_secret;
67 	int		ldap_method;
68 
69 	/* args for ldap_search */
70 	char		*ldap_base;
71 	int		ldap_scope;
72 	char		*ldap_filter;
73 	char		*ldap_attr[LDAPMAP_MAX_ATTR + 1];
74 	int		ldap_attr_type[LDAPMAP_MAX_ATTR + 1];
75 	char		*ldap_attr_needobjclass[LDAPMAP_MAX_ATTR + 1];
76 	bool		ldap_attrsonly;
77 
78 	/* args for ldap_result */
79 	struct timeval	ldap_timeout;
80 	LDAPMessage	*ldap_res;
81 
82 	/* ldapmap_lookup options */
83 	char		ldap_attrsep;
84 
85 	/* Linked list of maps sharing the same LDAP binding */
86 	void		*ldap_next;
87 };
88 
89 typedef struct sm_ldap_struct		SM_LDAP_STRUCT;
90 
91 struct sm_ldap_recurse_entry
92 {
93 	char *lr_search;
94 	int lr_type;
95 	LDAPURLDesc *lr_ludp;
96 	char **lr_attrs;
97 	bool lr_done;
98 };
99 
100 struct sm_ldap_recurse_list
101 {
102 	int lr_size;
103 	int lr_cnt;
104 	struct sm_ldap_recurse_entry **lr_data;
105 };
106 
107 typedef struct sm_ldap_recurse_entry	SM_LDAP_RECURSE_ENTRY;
108 typedef struct sm_ldap_recurse_list	SM_LDAP_RECURSE_LIST;
109 
110 /* functions */
111 extern void	sm_ldap_clear __P((SM_LDAP_STRUCT *));
112 extern bool	sm_ldap_start __P((char *, SM_LDAP_STRUCT *));
113 extern int	sm_ldap_search __P((SM_LDAP_STRUCT *, char *));
114 extern int	sm_ldap_results __P((SM_LDAP_STRUCT *, int, int, int,
115 				     SM_RPOOL_T *, char **, int *, int *,
116 				     SM_LDAP_RECURSE_LIST *));
117 extern void	sm_ldap_setopts __P((LDAP *, SM_LDAP_STRUCT *));
118 extern int	sm_ldap_geterrno __P((LDAP *));
119 extern void	sm_ldap_close __P((SM_LDAP_STRUCT *));
120 
121 /* Portability defines */
122 #  if !SM_CONF_LDAP_MEMFREE
123 #   define ldap_memfree(x)	((void) 0)
124 #  endif /* !SM_CONF_LDAP_MEMFREE */
125 
126 # endif /* LDAPMAP */
127 #endif /* ! SM_LDAP_H */
128