xref: /illumos-gate/usr/src/cmd/sendmail/include/sm/ldap.h (revision 058561cb)
1 /*
2  * Copyright (c) 2001-2003, 2005, 2006 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.32 2006/08/30 22:56:58 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 	/* Linked list of maps sharing the same LDAP binding */
97 	void		*ldap_next;
98 };
99 
100 typedef struct sm_ldap_struct		SM_LDAP_STRUCT;
101 
102 struct sm_ldap_recurse_entry
103 {
104 	char		*lr_search;
105 	int		lr_type;
106 	LDAPURLDesc	*lr_ludp;
107 	char		**lr_attrs;
108 	bool		lr_done;
109 };
110 
111 struct sm_ldap_recurse_list
112 {
113 	int				lrl_size;
114 	int				lrl_cnt;
115 	struct sm_ldap_recurse_entry	**lrl_data;
116 };
117 
118 typedef struct sm_ldap_recurse_entry	SM_LDAP_RECURSE_ENTRY;
119 typedef struct sm_ldap_recurse_list	SM_LDAP_RECURSE_LIST;
120 
121 /* functions */
122 extern void	sm_ldap_clear __P((SM_LDAP_STRUCT *));
123 extern bool	sm_ldap_start __P((char *, SM_LDAP_STRUCT *));
124 extern int	sm_ldap_search __P((SM_LDAP_STRUCT *, char *));
125 extern int	sm_ldap_search_m __P((SM_LDAP_STRUCT *, char **));
126 extern int	sm_ldap_results __P((SM_LDAP_STRUCT *, int, int, int,
127 				     SM_RPOOL_T *, char **, int *, int *,
128 				     SM_LDAP_RECURSE_LIST *));
129 extern void	sm_ldap_setopts __P((LDAP *, SM_LDAP_STRUCT *));
130 extern int	sm_ldap_geterrno __P((LDAP *));
131 extern void	sm_ldap_close __P((SM_LDAP_STRUCT *));
132 
133 /* Portability defines */
134 #  if !SM_CONF_LDAP_MEMFREE
135 #   define ldap_memfree(x)	((void) 0)
136 #  endif /* !SM_CONF_LDAP_MEMFREE */
137 
138 # endif /* LDAPMAP */
139 #endif /* ! SM_LDAP_H */
140