~ubuntu-branches/ubuntu/saucy/sssd/saucy

« back to all changes in this revision

Viewing changes to src/providers/ldap/sdap.h

  • Committer: Stéphane Graber
  • Date: 2011-06-15 16:23:14 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: stgraber@ubuntu.com-20110615162314-rbhoppnpaxfqo5q7
Merge 1.5.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    SSSD
 
3
 
 
4
    LDAP Helper routines
 
5
 
 
6
    Copyright (C) Simo Sorce <ssorce@redhat.com>
 
7
 
 
8
    This program is free software; you can redistribute it and/or modify
 
9
    it under the terms of the GNU General Public License as published by
 
10
    the Free Software Foundation; either version 3 of the License, or
 
11
    (at your option) any later version.
 
12
 
 
13
    This program is distributed in the hope that it will be useful,
 
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
    GNU General Public License for more details.
 
17
 
 
18
    You should have received a copy of the GNU General Public License
 
19
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
*/
 
21
 
 
22
#ifndef _SDAP_H_
 
23
#define _SDAP_H_
 
24
 
 
25
#include "providers/dp_backend.h"
 
26
#include <ldap.h>
 
27
#include "util/sss_ldap.h"
 
28
 
 
29
#ifdef LDAP_OPT_DIAGNOSTIC_MESSAGE
 
30
#define SDAP_DIAGNOSTIC_MESSAGE LDAP_OPT_DIAGNOSTIC_MESSAGE
 
31
#else
 
32
#ifdef LDAP_OPT_ERROR_STRING
 
33
#define SDAP_DIAGNOSTIC_MESSAGE LDAP_OPT_ERROR_STRING
 
34
#else
 
35
#error No extended diagnostic message available
 
36
#endif
 
37
#endif
 
38
 
 
39
struct sdap_msg {
 
40
    struct sdap_msg *next;
 
41
    LDAPMessage *msg;
 
42
};
 
43
 
 
44
struct sdap_op;
 
45
 
 
46
typedef void (sdap_op_callback_t)(struct sdap_op *op,
 
47
                                  struct sdap_msg *, int, void *);
 
48
 
 
49
struct sdap_handle;
 
50
 
 
51
struct sdap_op {
 
52
    struct sdap_op *prev, *next;
 
53
    struct sdap_handle *sh;
 
54
 
 
55
    int msgid;
 
56
    bool done;
 
57
 
 
58
    sdap_op_callback_t *callback;
 
59
    void *data;
 
60
 
 
61
    struct tevent_context *ev;
 
62
    struct sdap_msg *list;
 
63
    struct sdap_msg *last;
 
64
};
 
65
 
 
66
struct fd_event_item {
 
67
    struct fd_event_item *prev;
 
68
    struct fd_event_item *next;
 
69
 
 
70
    int fd;
 
71
    struct tevent_fd *fde;
 
72
};
 
73
 
 
74
struct ldap_cb_data {
 
75
    struct sdap_handle *sh;
 
76
    struct tevent_context *ev;
 
77
    struct fd_event_item *fd_list;
 
78
};
 
79
 
 
80
struct sup_list {
 
81
    int num_vals;
 
82
    char **vals;
 
83
};
 
84
 
 
85
struct sdap_handle {
 
86
    LDAP *ldap;
 
87
    bool connected;
 
88
    /* Authentication ticket expiration time (if any) */
 
89
    time_t expire_time;
 
90
    ber_int_t page_size;
 
91
 
 
92
    struct sdap_fd_events *sdap_fd_events;
 
93
 
 
94
    struct sup_list supported_saslmechs;
 
95
    struct sup_list supported_controls;
 
96
    struct sup_list supported_extensions;
 
97
 
 
98
    struct sdap_op *ops;
 
99
 
 
100
    /* during release we need to lock access to the handler
 
101
     * from the destructor to avoid recursion */
 
102
    bool destructor_lock;
 
103
    /* mark when it is safe to finally release the handler memory */
 
104
    bool release_memory;
 
105
};
 
106
 
 
107
struct sdap_service {
 
108
    char *name;
 
109
    char *uri;
 
110
    char *kinit_service_name;
 
111
};
 
112
 
 
113
struct sdap_ppolicy_data {
 
114
    int grace;
 
115
    int expire;
 
116
};
 
117
 
 
118
#define SYSDB_SHADOWPW_LASTCHANGE "shadowLastChange"
 
119
#define SYSDB_SHADOWPW_MIN "shadowMin"
 
120
#define SYSDB_SHADOWPW_MAX "shadowMax"
 
121
#define SYSDB_SHADOWPW_WARNING "shadowWarning"
 
122
#define SYSDB_SHADOWPW_INACTIVE "shadowInactive"
 
123
#define SYSDB_SHADOWPW_EXPIRE "shadowExpire"
 
124
#define SYSDB_SHADOWPW_FLAG "shadowFlag"
 
125
 
 
126
#define SYSDB_NS_ACCOUNT_LOCK "nsAccountLock"
 
127
 
 
128
#define SYSDB_KRBPW_LASTCHANGE "krbLastPwdChange"
 
129
#define SYSDB_KRBPW_EXPIRATION "krbPasswordExpiration"
 
130
 
 
131
#define SYSDB_PWD_ATTRIBUTE "pwdAttribute"
 
132
 
 
133
#define SYSDB_AD_ACCOUNT_EXPIRES "adAccountExpires"
 
134
#define SYSDB_AD_USER_ACCOUNT_CONTROL "adUserAccountControl"
 
135
 
 
136
#define SDAP_ROOTDSE_ATTR_NAMING_CONTEXTS "namingContexts"
 
137
#define SDAP_ROOTDSE_ATTR_DEFAULT_NAMING_CONTEXT "defaultNamingContext"
 
138
 
 
139
#define SDAP_IPA_USN "entryUSN"
 
140
#define SDAP_IPA_LAST_USN "lastUSN"
 
141
#define SDAP_AD_USN "uSNChanged"
 
142
#define SDAP_AD_LAST_USN "highestCommittedUSN"
 
143
 
 
144
enum sdap_result {
 
145
    SDAP_SUCCESS,
 
146
    SDAP_NOT_FOUND,
 
147
    SDAP_UNAVAIL,
 
148
    SDAP_RETRY,
 
149
    SDAP_ERROR,
 
150
    SDAP_AUTH_SUCCESS,
 
151
    SDAP_AUTH_FAILED,
 
152
    SDAP_AUTH_PW_EXPIRED,
 
153
    SDAP_ACCT_EXPIRED
 
154
};
 
155
 
 
156
enum sdap_basic_opt {
 
157
    SDAP_URI = 0,
 
158
    SDAP_SEARCH_BASE,
 
159
    SDAP_DEFAULT_BIND_DN,
 
160
    SDAP_DEFAULT_AUTHTOK_TYPE,
 
161
    SDAP_DEFAULT_AUTHTOK,
 
162
    SDAP_SEARCH_TIMEOUT,
 
163
    SDAP_NETWORK_TIMEOUT,
 
164
    SDAP_OPT_TIMEOUT,
 
165
    SDAP_TLS_REQCERT,
 
166
    SDAP_USER_SEARCH_BASE,
 
167
    SDAP_USER_SEARCH_SCOPE,
 
168
    SDAP_USER_SEARCH_FILTER,
 
169
    SDAP_GROUP_SEARCH_BASE,
 
170
    SDAP_GROUP_SEARCH_SCOPE,
 
171
    SDAP_GROUP_SEARCH_FILTER,
 
172
    SDAP_SCHEMA,
 
173
    SDAP_OFFLINE_TIMEOUT,
 
174
    SDAP_FORCE_UPPER_CASE_REALM,
 
175
    SDAP_ENUM_REFRESH_TIMEOUT,
 
176
    SDAP_CACHE_PURGE_TIMEOUT,
 
177
    SDAP_ENTRY_CACHE_TIMEOUT,
 
178
    SDAP_TLS_CACERT,
 
179
    SDAP_TLS_CACERTDIR,
 
180
    SDAP_TLS_CERT,
 
181
    SDAP_TLS_KEY,
 
182
    SDAP_TLS_CIPHER_SUITE,
 
183
    SDAP_ID_TLS,
 
184
    SDAP_SASL_MECH,
 
185
    SDAP_SASL_AUTHID,
 
186
    SDAP_KRB5_KEYTAB,
 
187
    SDAP_KRB5_KINIT,
 
188
    SDAP_KRB5_KDC,
 
189
    SDAP_KRB5_REALM,
 
190
    SDAP_PWD_POLICY,
 
191
    SDAP_REFERRALS,
 
192
    SDAP_ACCOUNT_CACHE_EXPIRATION,
 
193
    SDAP_DNS_SERVICE_NAME,
 
194
    SDAP_KRB5_TICKET_LIFETIME,
 
195
    SDAP_ACCESS_FILTER,
 
196
    SDAP_NETGROUP_SEARCH_BASE,
 
197
    SDAP_NESTING_LEVEL,
 
198
    SDAP_DEREF,
 
199
    SDAP_ACCOUNT_EXPIRE_POLICY,
 
200
    SDAP_ACCESS_ORDER,
 
201
    SDAP_CHPASS_URI,
 
202
    SDAP_CHPASS_DNS_SERVICE_NAME,
 
203
    SDAP_ENUM_SEARCH_TIMEOUT,
 
204
    SDAP_DISABLE_AUTH_TLS,
 
205
    SDAP_PAGE_SIZE,
 
206
 
 
207
    SDAP_OPTS_BASIC /* opts counter */
 
208
};
 
209
 
 
210
enum sdap_gen_attrs {
 
211
    SDAP_AT_ENTRY_USN = 0,
 
212
    SDAP_AT_LAST_USN,
 
213
 
 
214
    SDAP_AT_GENERAL /* attrs counter */
 
215
};
 
216
 
 
217
/* the objectclass must be the first attribute.
 
218
 * Functions depend on this */
 
219
enum sdap_user_attrs {
 
220
    SDAP_OC_USER = 0,
 
221
    SDAP_AT_USER_NAME,
 
222
    SDAP_AT_USER_PWD,
 
223
    SDAP_AT_USER_UID,
 
224
    SDAP_AT_USER_GID,
 
225
    SDAP_AT_USER_GECOS,
 
226
    SDAP_AT_USER_HOME,
 
227
    SDAP_AT_USER_SHELL,
 
228
    SDAP_AT_USER_PRINC,
 
229
    SDAP_AT_USER_FULLNAME,
 
230
    SDAP_AT_USER_MEMBEROF,
 
231
    SDAP_AT_USER_UUID,
 
232
    SDAP_AT_USER_MODSTAMP,
 
233
    SDAP_AT_USER_USN,
 
234
    SDAP_AT_SP_LSTCHG,
 
235
    SDAP_AT_SP_MIN,
 
236
    SDAP_AT_SP_MAX,
 
237
    SDAP_AT_SP_WARN,
 
238
    SDAP_AT_SP_INACT,
 
239
    SDAP_AT_SP_EXPIRE,
 
240
    SDAP_AT_SP_FLAG,
 
241
    SDAP_AT_KP_LASTCHANGE,
 
242
    SDAP_AT_KP_EXPIRATION,
 
243
    SDAP_AT_PWD_ATTRIBUTE,
 
244
    SDAP_AT_AUTH_SVC,
 
245
    SDAP_AT_AD_ACCOUNT_EXPIRES,
 
246
    SDAP_AT_AD_USER_ACCOUNT_CONTROL,
 
247
    SDAP_AT_NS_ACCOUNT_LOCK,
 
248
 
 
249
    SDAP_OPTS_USER /* attrs counter */
 
250
};
 
251
 
 
252
#define SDAP_FIRST_EXTRA_USER_AT SDAP_AT_SP_LSTCHG
 
253
 
 
254
/* the objectclass must be the first attribute.
 
255
 * Functions depend on this */
 
256
enum sdap_group_attrs {
 
257
    SDAP_OC_GROUP = 0,
 
258
    SDAP_AT_GROUP_NAME,
 
259
    SDAP_AT_GROUP_PWD,
 
260
    SDAP_AT_GROUP_GID,
 
261
    SDAP_AT_GROUP_MEMBER,
 
262
    SDAP_AT_GROUP_UUID,
 
263
    SDAP_AT_GROUP_MODSTAMP,
 
264
    SDAP_AT_GROUP_USN,
 
265
 
 
266
    SDAP_OPTS_GROUP /* attrs counter */
 
267
};
 
268
 
 
269
enum sdap_netgroup_attrs {
 
270
    SDAP_OC_NETGROUP = 0,
 
271
    SDAP_AT_NETGROUP_NAME,
 
272
    SDAP_AT_NETGROUP_MEMBER,
 
273
    SDAP_AT_NETGROUP_TRIPLE,
 
274
    SDAP_AT_NETGROUP_UUID,
 
275
    SDAP_AT_NETGROUP_MODSTAMP,
 
276
 
 
277
    SDAP_OPTS_NETGROUP /* attrs counter */
 
278
};
 
279
 
 
280
struct sdap_attr_map {
 
281
    const char *opt_name;
 
282
    const char *def_name;
 
283
    const char *sys_name;
 
284
    char *name;
 
285
};
 
286
 
 
287
struct sdap_options {
 
288
    struct dp_option *basic;
 
289
    struct sdap_attr_map *gen_map;
 
290
    struct sdap_attr_map *user_map;
 
291
    struct sdap_attr_map *group_map;
 
292
    struct sdap_attr_map *netgroup_map;
 
293
 
 
294
    /* supported schema types */
 
295
    enum schema_type {
 
296
        SDAP_SCHEMA_RFC2307 = 1,    /* memberUid = uid */
 
297
        SDAP_SCHEMA_RFC2307BIS = 2, /* member = dn */
 
298
        SDAP_SCHEMA_IPA_V1 = 3,     /* member/memberof */
 
299
        SDAP_SCHEMA_AD = 4          /* AD's member/memberof */
 
300
    } schema_type;
 
301
 
 
302
    struct ldb_dn *users_base;
 
303
    struct ldb_dn *groups_base;
 
304
};
 
305
 
 
306
struct sdap_server_opts {
 
307
    char *server_id;
 
308
    bool supports_usn;
 
309
    char *max_user_value;
 
310
    char *max_group_value;
 
311
};
 
312
 
 
313
struct sdap_id_ctx;
 
314
 
 
315
int sdap_get_map(TALLOC_CTX *memctx,
 
316
                 struct confdb_ctx *cdb,
 
317
                 const char *conf_path,
 
318
                 struct sdap_attr_map *def_map,
 
319
                 int num_entries,
 
320
                 struct sdap_attr_map **_map);
 
321
 
 
322
int sdap_parse_entry(TALLOC_CTX *memctx,
 
323
                     struct sdap_handle *sh, struct sdap_msg *sm,
 
324
                     struct sdap_attr_map *map, int attrs_num,
 
325
                     struct sysdb_attrs **_attrs, char **_dn);
 
326
 
 
327
int sdap_parse_user(TALLOC_CTX *memctx, struct sdap_options *opts,
 
328
                    struct sdap_handle *sh, struct sdap_msg *sm,
 
329
                    struct sysdb_attrs **_attrs, char **_dn);
 
330
 
 
331
int sdap_parse_group(TALLOC_CTX *memctx, struct sdap_options *opts,
 
332
                     struct sdap_handle *sh, struct sdap_msg *sm,
 
333
                     struct sysdb_attrs **_attrs, char **_dn);
 
334
 
 
335
int sdap_get_msg_dn(TALLOC_CTX *memctx, struct sdap_handle *sh,
 
336
                    struct sdap_msg *sm, char **_dn);
 
337
 
 
338
errno_t setup_tls_config(struct dp_option *basic_opts);
 
339
 
 
340
int sdap_set_rootdse_supported_lists(struct sysdb_attrs *rootdse,
 
341
                                     struct sdap_handle *sh);
 
342
bool sdap_check_sup_list(struct sup_list *l, const char *val);
 
343
 
 
344
#define sdap_is_sasl_mech_supported(sh, sasl_mech) \
 
345
    sdap_check_sup_list(&((sh)->supported_saslmechs), sasl_mech)
 
346
 
 
347
#define sdap_is_control_supported(sh, ctrl_oid) \
 
348
    sdap_check_sup_list(&((sh)->supported_controls), ctrl_oid)
 
349
 
 
350
#define sdap_is_extension_supported(sh, ext_oid) \
 
351
    sdap_check_sup_list(&((sh)->supported_extensions), ext_oid)
 
352
 
 
353
int build_attrs_from_map(TALLOC_CTX *memctx,
 
354
                         struct sdap_attr_map *map,
 
355
                         size_t size, const char ***_attrs);
 
356
int append_attrs_to_array(const char **attrs, size_t size, const char *attr);
 
357
 
 
358
int sdap_control_create(struct sdap_handle *sh, const char *oid, int iscritical,
 
359
                        struct berval *value, int dupval, LDAPControl **ctrlp);
 
360
 
 
361
errno_t sdap_set_config_options_with_rootdse(struct sysdb_attrs *rootdse,
 
362
                                             struct sdap_handle *sh,
 
363
                                             struct sdap_options *opts);
 
364
int sdap_get_server_opts_from_rootdse(TALLOC_CTX *memctx,
 
365
                                      const char *server,
 
366
                                      struct sysdb_attrs *rootdse,
 
367
                                      struct sdap_options *opts,
 
368
                                      struct sdap_server_opts **srv_opts);
 
369
void sdap_steal_server_opts(struct sdap_id_ctx *id_ctx,
 
370
                            struct sdap_server_opts **srv_opts);
 
371
#endif /* _SDAP_H_ */