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