ldap.h revision 168515
1178476Sjb/*
2178476Sjb * Copyright (c) 2001-2003, 2005, 2006 Sendmail, Inc. and its suppliers.
3178476Sjb *      All rights reserved.
4178476Sjb *
5178476Sjb * By using this file, you agree to the terms and conditions set
6178476Sjb * forth in the LICENSE file which can be found at the top level of
7178476Sjb * the sendmail distribution.
8178476Sjb *
9178476Sjb *	$Id: ldap.h,v 1.32 2006/08/30 22:56:58 ca Exp $
10178476Sjb */
11178476Sjb
12178476Sjb#ifndef	SM_LDAP_H
13178476Sjb# define SM_LDAP_H
14178476Sjb
15178476Sjb# include <sm/conf.h>
16178476Sjb# include <sm/rpool.h>
17178476Sjb
18178476Sjb/*
19178476Sjb**  NOTE: These should be changed from LDAPMAP_* to SM_LDAP_*
20178476Sjb**	in the next major release (8.x+1) of sendmail.
21178476Sjb*/
22178476Sjb
23178476Sjb# ifndef LDAPMAP_MAX_ATTR
24178476Sjb#  define LDAPMAP_MAX_ATTR	64
25178476Sjb# endif /* ! LDAPMAP_MAX_ATTR */
26178476Sjb# ifndef LDAPMAP_MAX_FILTER
27178476Sjb#  define LDAPMAP_MAX_FILTER	1024
28178476Sjb# endif /* ! LDAPMAP_MAX_FILTER */
29178476Sjb# ifndef LDAPMAP_MAX_PASSWD
30178476Sjb#  define LDAPMAP_MAX_PASSWD	256
31178476Sjb# endif /* ! LDAPMAP_MAX_PASSWD */
32178476Sjb
33178476Sjb# if LDAPMAP
34178476Sjb
35178476Sjb/* maximum number of arguments in a map lookup, see sendmail.h: MAX_MAP_ARGS */
36178476Sjb#  define SM_LDAP_ARGS		10
37178476Sjb
38178476Sjb/* error codes from sm_ldap_search*() */
39178476Sjb#  define SM_LDAP_ERR		(-1)	/* generic error: ldap_search(3) */
40178476Sjb#  define SM_LDAP_ERR_ARG_MISS	(-2)	/* an argument is missing */
41178476Sjb
42178476Sjb/* Attribute types */
43178476Sjb#  define SM_LDAP_ATTR_NONE		(-1)
44178476Sjb#  define SM_LDAP_ATTR_OBJCLASS	0
45178476Sjb#  define SM_LDAP_ATTR_NORMAL		1
46178476Sjb#  define SM_LDAP_ATTR_DN		2
47178476Sjb#  define SM_LDAP_ATTR_FILTER		3
48178476Sjb#  define SM_LDAP_ATTR_URL		4
49178476Sjb
50178476Sjb/* sm_ldap_results() flags */
51178476Sjb#  define SM_LDAP_SINGLEMATCH	0x0001
52178476Sjb#  define SM_LDAP_MATCHONLY	0x0002
53178476Sjb#  define SM_LDAP_USE_ALLATTR	0x0004
54178476Sjb#  define SM_LDAP_SINGLEDN	0x0008
55178476Sjb
56178476Sjbstruct sm_ldap_struct
57178476Sjb{
58178476Sjb	/* needed for ldap_open or ldap_init */
59178476Sjb	char		*ldap_uri;
60178476Sjb	char		*ldap_host;
61178476Sjb	int		ldap_port;
62178476Sjb	int		ldap_version;
63178476Sjb	pid_t		ldap_pid;
64178476Sjb
65178476Sjb	/* options set in ld struct before ldap_bind_s */
66178476Sjb	int		ldap_deref;
67178476Sjb	time_t		ldap_timelimit;
68178476Sjb	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	/* Linked list of maps sharing the same LDAP binding */
95	void		*ldap_next;
96};
97
98typedef struct sm_ldap_struct		SM_LDAP_STRUCT;
99
100struct sm_ldap_recurse_entry
101{
102	char		*lr_search;
103	int		lr_type;
104	LDAPURLDesc	*lr_ludp;
105	char		**lr_attrs;
106	bool		lr_done;
107};
108
109struct sm_ldap_recurse_list
110{
111	int				lrl_size;
112	int				lrl_cnt;
113	struct sm_ldap_recurse_entry	**lrl_data;
114};
115
116typedef struct sm_ldap_recurse_entry	SM_LDAP_RECURSE_ENTRY;
117typedef struct sm_ldap_recurse_list	SM_LDAP_RECURSE_LIST;
118
119/* functions */
120extern void	sm_ldap_clear __P((SM_LDAP_STRUCT *));
121extern bool	sm_ldap_start __P((char *, SM_LDAP_STRUCT *));
122extern int	sm_ldap_search __P((SM_LDAP_STRUCT *, char *));
123extern int	sm_ldap_search_m __P((SM_LDAP_STRUCT *, char **));
124extern int	sm_ldap_results __P((SM_LDAP_STRUCT *, int, int, int,
125				     SM_RPOOL_T *, char **, int *, int *,
126				     SM_LDAP_RECURSE_LIST *));
127extern void	sm_ldap_setopts __P((LDAP *, SM_LDAP_STRUCT *));
128extern int	sm_ldap_geterrno __P((LDAP *));
129extern void	sm_ldap_close __P((SM_LDAP_STRUCT *));
130
131/* Portability defines */
132#  if !SM_CONF_LDAP_MEMFREE
133#   define ldap_memfree(x)	((void) 0)
134#  endif /* !SM_CONF_LDAP_MEMFREE */
135
136# endif /* LDAPMAP */
137#endif /* ! SM_LDAP_H */
138