xref: /freebsd/contrib/sendmail/include/sm/ldap.h (revision f0a75d274af375d15b97b830966b99a02b7db911)
1 /*
2  * Copyright (c) 2001-2003, 2005 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.28 2005/06/23 23:11:21 ca 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 #  define SM_LDAP_SINGLEDN	0x0008
48 
49 struct sm_ldap_struct
50 {
51 	/* needed for ldap_open or ldap_init */
52 	char		*ldap_uri;
53 	char		*ldap_host;
54 	int		ldap_port;
55 	int		ldap_version;
56 	pid_t		ldap_pid;
57 
58 	/* options set in ld struct before ldap_bind_s */
59 	int		ldap_deref;
60 	time_t		ldap_timelimit;
61 	int		ldap_sizelimit;
62 	int		ldap_options;
63 
64 	/* args for ldap_bind_s */
65 	LDAP		*ldap_ld;
66 	char		*ldap_binddn;
67 	char		*ldap_secret;
68 	int		ldap_method;
69 
70 	/* args for ldap_search */
71 	char		*ldap_base;
72 	int		ldap_scope;
73 	char		*ldap_filter;
74 	char		*ldap_attr[LDAPMAP_MAX_ATTR + 1];
75 	int		ldap_attr_type[LDAPMAP_MAX_ATTR + 1];
76 	char		*ldap_attr_needobjclass[LDAPMAP_MAX_ATTR + 1];
77 	bool		ldap_attrsonly;
78 
79 	/* args for ldap_result */
80 	struct timeval	ldap_timeout;
81 	LDAPMessage	*ldap_res;
82 
83 	/* ldapmap_lookup options */
84 	char		ldap_attrsep;
85 
86 	/* Linked list of maps sharing the same LDAP binding */
87 	void		*ldap_next;
88 };
89 
90 typedef struct sm_ldap_struct		SM_LDAP_STRUCT;
91 
92 struct sm_ldap_recurse_entry
93 {
94 	char *lr_search;
95 	int lr_type;
96 	LDAPURLDesc *lr_ludp;
97 	char **lr_attrs;
98 	bool lr_done;
99 };
100 
101 struct sm_ldap_recurse_list
102 {
103 	int lr_size;
104 	int lr_cnt;
105 	struct sm_ldap_recurse_entry **lr_data;
106 };
107 
108 typedef struct sm_ldap_recurse_entry	SM_LDAP_RECURSE_ENTRY;
109 typedef struct sm_ldap_recurse_list	SM_LDAP_RECURSE_LIST;
110 
111 /* functions */
112 extern void	sm_ldap_clear __P((SM_LDAP_STRUCT *));
113 extern bool	sm_ldap_start __P((char *, SM_LDAP_STRUCT *));
114 extern int	sm_ldap_search __P((SM_LDAP_STRUCT *, char *));
115 extern int	sm_ldap_results __P((SM_LDAP_STRUCT *, int, int, int,
116 				     SM_RPOOL_T *, char **, int *, int *,
117 				     SM_LDAP_RECURSE_LIST *));
118 extern void	sm_ldap_setopts __P((LDAP *, SM_LDAP_STRUCT *));
119 extern int	sm_ldap_geterrno __P((LDAP *));
120 extern void	sm_ldap_close __P((SM_LDAP_STRUCT *));
121 
122 /* Portability defines */
123 #  if !SM_CONF_LDAP_MEMFREE
124 #   define ldap_memfree(x)	((void) 0)
125 #  endif /* !SM_CONF_LDAP_MEMFREE */
126 
127 # endif /* LDAPMAP */
128 #endif /* ! SM_LDAP_H */
129