2 * $Id: ldap.h 1012 2008-03-26 00:44:22Z hubert@u.washington.edu $
4 * ========================================================================
5 * Copyright 2013-2022 Eduardo Chappa
6 * Copyright 2006-2008 University of Washington
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * ========================================================================
17 #ifndef PITH_LDAP_INCLUDED
18 #define PITH_LDAP_INCLUDED
21 #include "../pith/state.h"
22 #include "../pith/adrbklib.h"
28 * This is used to consolidate related information about a server. This
29 * information is all stored in the ldap-servers variable, per server.
31 typedef struct ldap_serv
{
32 char *serv
, /* Server name */
33 *base
, /* Search base */
34 *binddn
, /* Bind DN if non-anonymous */
35 *cust
, /* Custom search filter */
37 *mail
, /* Backup email address */
38 *mailattr
, /* "Mail" attribute name */
39 *snattr
, /* "Surname" attribute name */
40 *gnattr
, /* "Givenname" attribute name */
41 *cnattr
; /* "CommonName" attribute name */
42 int port
, /* Port number */
43 time
, /* Time limit */
44 size
, /* Size limit */
45 impl
, /* Use implicitly feature */
46 rhs
, /* Lookup contents feature */
47 ref
, /* Save by reference feature */
48 nosub
, /* Disable space sub feature */
49 tls
, /* Attempt TLS */
50 tlsmust
, /* Require TLS */
51 ldaps
, /* Require LDAPS */
52 type
, /* Search type (surname...) */
53 srch
, /* Search rule (contains...) */
54 scope
; /* Scope of search (base...) */
59 * Structures to control the LDAP address selection screen
61 * We may run into the problem of LDAP databases containing non-UTF-8 data
62 * because they are old. They should have all UTF-8 data and that is what
63 * we are assuming. If we wanted to accommodate these servers we could
64 * translate the data when we use it. LDAP data is only used in a few
65 * places so it might not be too hard to fix it. There are four calls
66 * into the LDAP library that produce character strings which are
67 * supposed to be UTF-8. They are
69 * ldap_first_attribute
72 * We call those from a half dozen functions. We could fix it by
73 * having a directory-character-set per server and passing that around
74 * in the LDAP_SERV_RES_S structure, I think. For now, let's go with
75 * the assumption that everything is already UTF-8.
77 typedef struct ldap_serv_results
{
78 LDAP
*ld
; /* LDAP handle */
79 LDAPMessage
*res
; /* LDAP search result */
80 LDAP_SERV_S
*info_used
;
82 struct ldap_serv_results
*next
;
86 typedef struct addr_choose
{
87 LDAP_SERV_RES_S
*res_head
;
89 LDAP
*selected_ld
; /* from which ld was entry selected */
90 LDAPMessage
*selected_entry
; /* which entry was selected */
91 LDAP_SERV_S
*info_used
;
97 * This is very similar to LDAP_SERV_RES_S, but selected_entry
98 * is a single entry instead of a result list.
100 typedef struct ldap_choose_results
{
101 LDAP
*ld
; /* LDAP handle */
102 LDAPMessage
*selected_entry
;
103 LDAP_SERV_S
*info_used
;
109 * How the LDAP lookup should work.
111 typedef enum {AlwaysDisplay
,
112 AlwaysDisplayAndMailRequired
,
118 #define ALPINE_LDAP_can_use_num(X, Y) \
119 ((X) != NULL && (X)[(Y)] != NULL \
120 && (X)[(Y)]->bv_val != NULL \
121 && (X)[(Y)]->bv_val[0] != '\0')
123 #define ALPINE_LDAP_can_use(X) ALPINE_LDAP_can_use_num((X), 0)
124 #define ALPINE_LDAP_usable(X, Y) ((Y) < ldap_count_values_len((X)) \
125 && ALPINE_LDAP_can_use_num((X), (Y)))
127 #define LDAP_TYPE_CN 0
128 #define LDAP_TYPE_SUR 1
129 #define LDAP_TYPE_GIVEN 2
130 #define LDAP_TYPE_EMAIL 3
131 #define LDAP_TYPE_CN_EMAIL 4
132 #define LDAP_TYPE_SUR_GIVEN 5
133 #define LDAP_TYPE_SEVERAL 6
135 #define LDAP_SRCH_CONTAINS 0
136 #define LDAP_SRCH_EQUALS 1
137 #define LDAP_SRCH_BEGINS 2
138 #define LDAP_SRCH_ENDS 3
140 #define DEF_LDAP_TYPE 6
141 #define DEF_LDAP_SRCH 2
142 #define DEF_LDAP_TIME 30
143 #define DEF_LDAP_SIZE 0
144 #define DEF_LDAP_SCOPE LDAP_SCOPE_SUBTREE
145 #define DEF_LDAP_MAILATTR "mail"
146 #define DEF_LDAP_SNATTR "sn"
147 #define DEF_LDAP_GNATTR "givenname"
148 #define DEF_LDAP_CNATTR "cn"
150 #endif /* ENABLE_LDAP */
154 * Error handling argument for white pages lookups.
156 typedef struct wp_err
{
165 extern int wp_nobail
;
168 /* exported prototypes */
169 ADDRESS
*wp_lookups(char *, WP_ERR_S
*, int);
171 int ldap_lookup_all(char *, int, int, LDAPLookupStyle
, CUSTOM_FILT_S
*,
172 LDAP_CHOOSE_S
**, WP_ERR_S
*, LDAP_SERV_RES_S
**);
173 char *ldap_translate(char *, LDAP_SERV_S
*);
174 char **berval_to_array(struct berval
**);
175 ADDRESS
*address_from_ldap(LDAP_CHOOSE_S
*);
176 LDAP_SERV_S
*break_up_ldap_server(char *);
177 void free_ldap_server_info(LDAP_SERV_S
**);
178 void free_ldap_result_list(LDAP_SERV_RES_S
**);
179 void our_ldap_memfree(void *);
180 void our_ldap_dn_memfree(void *);
181 int our_ldap_set_option(LDAP
*, int, void *);
182 int ldap_v3_is_supported(LDAP
*);
183 int ask_user_which_entry(LDAP_SERV_RES_S
*, char *,
184 LDAP_CHOOSE_S
**, WP_ERR_S
*, LDAPLookupStyle
);
185 LDAP_SERV_RES_S
*ldap_lookup_all_work(char *, int, int, CUSTOM_FILT_S
*, WP_ERR_S
*);
189 * This must be defined in the application
191 int ldap_addr_select(struct pine
*, ADDR_CHOOSE_S
*, LDAP_CHOOSE_S
**,
192 LDAPLookupStyle
, WP_ERR_S
*, char *);
193 #endif /* ENABLE_LDAP */
196 #endif /* PITH_LDAP_INCLUDED */