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