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"
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 type
, /* Search type (surname...) */
52 srch
, /* Search rule (contains...) */
53 scope
; /* Scope of search (base...) */
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
68 * ldap_first_attribute
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
;
81 struct ldap_serv_results
*next
;
85 typedef struct addr_choose
{
86 LDAP_SERV_RES_S
*res_head
;
88 LDAP
*selected_ld
; /* from which ld was entry selected */
89 LDAPMessage
*selected_entry
; /* which entry was selected */
90 LDAP_SERV_S
*info_used
;
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
;
108 * How the LDAP lookup should work.
110 typedef enum {AlwaysDisplay
,
111 AlwaysDisplayAndMailRequired
,
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
{
156 extern int wp_nobail
;
159 /* exported protoypes */
160 ADDRESS
*wp_lookups(char *, WP_ERR_S
*, int);
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 */