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