* Update to version 2.19.5
[alpine.git] / pith / ldap.h
blob80409d5311bd825d88f82b1d1bd451fc12e58c53
1 /*
2 * $Id: ldap.h 1012 2008-03-26 00:44:22Z hubert@u.washington.edu $
4 * ========================================================================
5 * Copyright 2006-2008 University of Washington
6 * Copyright 2013-2014 Eduardo Chappa
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 type, /* Search type (surname...) */
52 srch, /* Search rule (contains...) */
53 scope; /* Scope of search (base...) */
54 } LDAP_SERV_S;
58 * Structures to control the LDAP address selection screen
60 * We may run into the problem of LDAP databases containing non-UTF-8 data
61 * because they are old. They should have all UTF-8 data and that is what
62 * we are assuming. If we wanted to accomodate these servers we could
63 * translate the data when we use it. LDAP data is only used in a few
64 * places so it might not be too hard to fix it. There are four calls
65 * into the LDAP library that produce character strings which are
66 * supposed to be UTF-8. They are
67 * ldap_get_dn
68 * ldap_first_attribute
69 * ldap_next_attribute
70 * ldap_get_values
71 * We call those from a half dozen functions. We could fix it by
72 * having a directory-character-set per server and passing that around
73 * in the LDAP_SERV_RES_S structure, I think. For now, let's go with
74 * the assumption that everything is already UTF-8.
76 typedef struct ldap_serv_results {
77 LDAP *ld; /* LDAP handle */
78 LDAPMessage *res; /* LDAP search result */
79 LDAP_SERV_S *info_used;
80 char *serv;
81 struct ldap_serv_results *next;
82 } LDAP_SERV_RES_S;
85 typedef struct addr_choose {
86 LDAP_SERV_RES_S *res_head;
87 char *title;
88 LDAP *selected_ld; /* from which ld was entry selected */
89 LDAPMessage *selected_entry; /* which entry was selected */
90 LDAP_SERV_S *info_used;
91 char *selected_serv;
92 } ADDR_CHOOSE_S;
96 * This is very similar to LDAP_SERV_RES_S, but selected_entry
97 * is a single entry instead of a result list.
99 typedef struct ldap_choose_results {
100 LDAP *ld; /* LDAP handle */
101 LDAPMessage *selected_entry;
102 LDAP_SERV_S *info_used;
103 char *serv;
104 } LDAP_CHOOSE_S;
108 * How the LDAP lookup should work.
110 typedef enum {AlwaysDisplay,
111 AlwaysDisplayAndMailRequired,
112 DisplayIfTwo,
113 DisplayIfOne,
114 DisplayForURL
115 } LDAPLookupStyle;
118 #define LDAP_TYPE_CN 0
119 #define LDAP_TYPE_SUR 1
120 #define LDAP_TYPE_GIVEN 2
121 #define LDAP_TYPE_EMAIL 3
122 #define LDAP_TYPE_CN_EMAIL 4
123 #define LDAP_TYPE_SUR_GIVEN 5
124 #define LDAP_TYPE_SEVERAL 6
126 #define LDAP_SRCH_CONTAINS 0
127 #define LDAP_SRCH_EQUALS 1
128 #define LDAP_SRCH_BEGINS 2
129 #define LDAP_SRCH_ENDS 3
131 #define DEF_LDAP_TYPE 6
132 #define DEF_LDAP_SRCH 2
133 #define DEF_LDAP_TIME 30
134 #define DEF_LDAP_SIZE 0
135 #define DEF_LDAP_SCOPE LDAP_SCOPE_SUBTREE
136 #define DEF_LDAP_MAILATTR "mail"
137 #define DEF_LDAP_SNATTR "sn"
138 #define DEF_LDAP_GNATTR "givenname"
139 #define DEF_LDAP_CNATTR "cn"
141 #endif /* ENABLE_LDAP */
145 * Error handling argument for white pages lookups.
147 typedef struct wp_err {
148 char *error;
149 int wp_err_occurred;
150 int *mangled;
151 int ldap_errno;
152 } WP_ERR_S;
155 extern int wp_exit;
156 extern int wp_nobail;
159 /* exported protoypes */
160 ADDRESS *wp_lookups(char *, WP_ERR_S *, int);
161 #ifdef ENABLE_LDAP
162 int ldap_lookup_all(char *, int, int, LDAPLookupStyle, CUSTOM_FILT_S *,
163 LDAP_CHOOSE_S **, WP_ERR_S *, LDAP_SERV_RES_S **);
164 char *ldap_translate(char *, LDAP_SERV_S *);
165 ADDRESS *address_from_ldap(LDAP_CHOOSE_S *);
166 LDAP_SERV_S *break_up_ldap_server(char *);
167 void free_ldap_server_info(LDAP_SERV_S **);
168 void free_ldap_result_list(LDAP_SERV_RES_S **);
169 void our_ldap_memfree(void *);
170 void our_ldap_dn_memfree(void *);
171 int our_ldap_set_option(LDAP *, int, void *);
172 int ldap_v3_is_supported(LDAP *);
173 int ask_user_which_entry(LDAP_SERV_RES_S *, char *,
174 LDAP_CHOOSE_S **, WP_ERR_S *, LDAPLookupStyle);
175 LDAP_SERV_RES_S *ldap_lookup_all_work(char *, int, int, CUSTOM_FILT_S *, WP_ERR_S *);
179 * This must be defined in the application
181 int ldap_addr_select(struct pine *, ADDR_CHOOSE_S *, LDAP_CHOOSE_S **,
182 LDAPLookupStyle, WP_ERR_S *, char *);
183 #endif /* ENABLE_LDAP */
186 #endif /* PITH_LDAP_INCLUDED */