Add support for tab-completion when selecting by rule
[alpine.git] / pith / ldap.h
blob04aa5c3e9768bc5d6765a884be7a2d9eef272684
1 /*
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"
25 #ifdef ENABLE_LDAP
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 */
36 *nick, /* Nickname */
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...) */
55 } LDAP_SERV_S;
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
68 * ldap_get_dn
69 * ldap_first_attribute
70 * ldap_next_attribute
71 * ldap_get_values_len
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;
81 char *serv;
82 struct ldap_serv_results *next;
83 } LDAP_SERV_RES_S;
86 typedef struct addr_choose {
87 LDAP_SERV_RES_S *res_head;
88 char *title;
89 LDAP *selected_ld; /* from which ld was entry selected */
90 LDAPMessage *selected_entry; /* which entry was selected */
91 LDAP_SERV_S *info_used;
92 char *selected_serv;
93 } ADDR_CHOOSE_S;
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;
104 char *serv;
105 } LDAP_CHOOSE_S;
109 * How the LDAP lookup should work.
111 typedef enum {AlwaysDisplay,
112 AlwaysDisplayAndMailRequired,
113 DisplayIfTwo,
114 DisplayIfOne,
115 DisplayForURL
116 } LDAPLookupStyle;
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 {
157 char *error;
158 int wp_err_occurred;
159 int *mangled;
160 int ldap_errno;
161 } WP_ERR_S;
164 extern int wp_exit;
165 extern int wp_nobail;
168 /* exported prototypes */
169 ADDRESS *wp_lookups(char *, WP_ERR_S *, int);
170 #ifdef ENABLE_LDAP
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 */