xref: /titanic_50/usr/src/cmd/sendmail/include/sm/ldap.h (revision 3c112a2b34403220c06c3e2fcac403358cfba168)
1 /*
2  * Copyright (c) 2001-2003, 2005-2007 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.34 2008/11/17 21:02:54 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.x+1) 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 /* maximum number of arguments in a map lookup, see sendmail.h: MAX_MAP_ARGS */
36 #  define SM_LDAP_ARGS		10
37 
38 /* error codes from sm_ldap_search*() */
39 #  define SM_LDAP_ERR		(-1)	/* generic error: ldap_search(3) */
40 #  define SM_LDAP_ERR_ARG_MISS	(-2)	/* an argument is missing */
41 
42 /* Attribute types */
43 #  define SM_LDAP_ATTR_NONE		(-1)
44 #  define SM_LDAP_ATTR_OBJCLASS	0
45 #  define SM_LDAP_ATTR_NORMAL		1
46 #  define SM_LDAP_ATTR_DN		2
47 #  define SM_LDAP_ATTR_FILTER		3
48 #  define SM_LDAP_ATTR_URL		4
49 
50 /* sm_ldap_results() flags */
51 #  define SM_LDAP_SINGLEMATCH	0x0001
52 #  define SM_LDAP_MATCHONLY	0x0002
53 #  define SM_LDAP_USE_ALLATTR	0x0004
54 #  define SM_LDAP_SINGLEDN	0x0008
55 
56 struct sm_ldap_struct
57 {
58 	/* needed for ldap_open or ldap_init */
59 	char		*ldap_uri;
60 	char		*ldap_host;
61 	int		ldap_port;
62 	int		ldap_version;
63 	pid_t		ldap_pid;
64 
65 	/* options set in ld struct before ldap_bind_s */
66 	int		ldap_deref;
67 	time_t		ldap_timelimit;
68 	int		ldap_sizelimit;
69 	int		ldap_options;
70 
71 	/* args for ldap_bind_s */
72 	LDAP		*ldap_ld;
73 	char		*ldap_binddn;
74 	char		*ldap_secret;
75 	int		ldap_method;
76 
77 	/* args for ldap_search */
78 	char		*ldap_base;
79 	int		ldap_scope;
80 	char		*ldap_filter;
81 	char		*ldap_attr[LDAPMAP_MAX_ATTR + 1];
82 	int		ldap_attr_type[LDAPMAP_MAX_ATTR + 1];
83 	char		*ldap_attr_needobjclass[LDAPMAP_MAX_ATTR + 1];
84 	bool		ldap_attrsonly;
85 	bool		ldap_multi_args;
86 
87 	/* args for ldap_result */
88 	struct timeval	ldap_timeout;
89 	LDAPMessage	*ldap_res;
90 
91 	/* ldapmap_lookup options */
92 	char		ldap_attrsep;
93 
94 # if _FFR_LDAP_NETWORK_TIMEOUT
95 	int		ldap_networktmo;
96 # endif /* _FFR_LDAP_NETWORK_TIMEOUT */
97 
98 	/* Linked list of maps sharing the same LDAP binding */
99 	void		*ldap_next;
100 };
101 
102 typedef struct sm_ldap_struct		SM_LDAP_STRUCT;
103 
104 struct sm_ldap_recurse_entry
105 {
106 	char		*lr_search;
107 	int		lr_type;
108 	LDAPURLDesc	*lr_ludp;
109 	char		**lr_attrs;
110 	bool		lr_done;
111 };
112 
113 struct sm_ldap_recurse_list
114 {
115 	int				lrl_size;
116 	int				lrl_cnt;
117 	struct sm_ldap_recurse_entry	**lrl_data;
118 };
119 
120 typedef struct sm_ldap_recurse_entry	SM_LDAP_RECURSE_ENTRY;
121 typedef struct sm_ldap_recurse_list	SM_LDAP_RECURSE_LIST;
122 
123 /* functions */
124 extern void	sm_ldap_clear __P((SM_LDAP_STRUCT *));
125 extern bool	sm_ldap_start __P((char *, SM_LDAP_STRUCT *));
126 extern int	sm_ldap_search __P((SM_LDAP_STRUCT *, char *));
127 extern int	sm_ldap_search_m __P((SM_LDAP_STRUCT *, char **));
128 extern int	sm_ldap_results __P((SM_LDAP_STRUCT *, int, int, int,
129 				     SM_RPOOL_T *, char **, int *, int *,
130 				     SM_LDAP_RECURSE_LIST *));
131 extern void	sm_ldap_setopts __P((LDAP *, SM_LDAP_STRUCT *));
132 extern int	sm_ldap_geterrno __P((LDAP *));
133 extern void	sm_ldap_close __P((SM_LDAP_STRUCT *));
134 
135 /* Portability defines */
136 #  if !SM_CONF_LDAP_MEMFREE
137 #   define ldap_memfree(x)	((void) 0)
138 #  endif /* !SM_CONF_LDAP_MEMFREE */
139 
140 # endif /* LDAPMAP */
141 #endif /* ! SM_LDAP_H */
142