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

« back to all changes in this revision

Viewing changes to server/providers/ldap/ldap_id.c

  • 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 Identity Backend Module
5
 
 
6
 
    Authors:
7
 
        Simo Sorce <ssorce@redhat.com>
8
 
 
9
 
    Copyright (C) 2008 Red Hat
10
 
 
11
 
    This program is free software; you can redistribute it and/or modify
12
 
    it under the terms of the GNU General Public License as published by
13
 
    the Free Software Foundation; either version 3 of the License, or
14
 
    (at your option) any later version.
15
 
 
16
 
    This program is distributed in the hope that it will be useful,
17
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 
    GNU General Public License for more details.
20
 
 
21
 
    You should have received a copy of the GNU General Public License
22
 
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 
*/
24
 
 
25
 
#include <errno.h>
26
 
#include <time.h>
27
 
#include <sys/time.h>
28
 
 
29
 
#include "util/util.h"
30
 
#include "db/sysdb.h"
31
 
#include "providers/ldap/ldap_common.h"
32
 
#include "providers/ldap/sdap_async.h"
33
 
 
34
 
/* =Users-Related-Functions-(by-name,by-uid)============================== */
35
 
 
36
 
struct users_get_state {
37
 
    struct tevent_context *ev;
38
 
    struct sdap_id_ctx *ctx;
39
 
    struct sysdb_ctx *sysdb;
40
 
    struct sss_domain_info *domain;
41
 
 
42
 
    const char *name;
43
 
    int filter_type;
44
 
 
45
 
    char *filter;
46
 
    const char **attrs;
47
 
};
48
 
 
49
 
static void users_get_connect_done(struct tevent_req *subreq);
50
 
static void users_get_done(struct tevent_req *subreq);
51
 
static void users_get_delete(struct tevent_req *subreq);
52
 
 
53
 
struct tevent_req *users_get_send(TALLOC_CTX *memctx,
54
 
                                  struct tevent_context *ev,
55
 
                                  struct sdap_id_ctx *ctx,
56
 
                                  const char *name,
57
 
                                  int filter_type,
58
 
                                  int attrs_type)
59
 
{
60
 
    struct tevent_req *req, *subreq;
61
 
    struct users_get_state *state;
62
 
    const char *attr_name;
63
 
    int ret;
64
 
 
65
 
    req = tevent_req_create(memctx, &state, struct users_get_state);
66
 
    if (!req) return NULL;
67
 
 
68
 
    state->ev = ev;
69
 
    state->ctx = ctx;
70
 
    state->sysdb = ctx->be->sysdb;
71
 
    state->domain = state->ctx->be->domain;
72
 
    state->name = name;
73
 
    state->filter_type = filter_type;
74
 
 
75
 
    switch (filter_type) {
76
 
    case BE_FILTER_NAME:
77
 
        attr_name = ctx->opts->user_map[SDAP_AT_USER_NAME].name;
78
 
        break;
79
 
    case BE_FILTER_IDNUM:
80
 
        attr_name = ctx->opts->user_map[SDAP_AT_USER_UID].name;
81
 
        break;
82
 
    default:
83
 
        ret = EINVAL;
84
 
        goto fail;
85
 
    }
86
 
 
87
 
    state->filter = talloc_asprintf(state, "(&(%s=%s)(objectclass=%s))",
88
 
                                    attr_name, name,
89
 
                                    ctx->opts->user_map[SDAP_OC_USER].name);
90
 
    if (!state->filter) {
91
 
        DEBUG(2, ("Failed to build filter\n"));
92
 
        ret = ENOMEM;
93
 
        goto fail;
94
 
    }
95
 
 
96
 
    /* TODO: handle attrs_type */
97
 
    ret = build_attrs_from_map(state, ctx->opts->user_map,
98
 
                               SDAP_OPTS_USER, &state->attrs);
99
 
    if (ret != EOK) goto fail;
100
 
 
101
 
    if (!sdap_connected(ctx)) {
102
 
 
103
 
        if (ctx->gsh) talloc_zfree(ctx->gsh);
104
 
 
105
 
        /* FIXME: add option to decide if tls should be used
106
 
         * or SASL/GSSAPI, etc ... */
107
 
        subreq = sdap_cli_connect_send(state, ev, ctx->opts,
108
 
                                       ctx->be, ctx->service,
109
 
                                       &ctx->rootDSE);
110
 
        if (!subreq) {
111
 
            ret = ENOMEM;
112
 
            goto fail;
113
 
        }
114
 
 
115
 
        tevent_req_set_callback(subreq, users_get_connect_done, req);
116
 
 
117
 
        return req;
118
 
    }
119
 
 
120
 
    subreq = sdap_get_users_send(state, state->ev,
121
 
                                 state->domain, state->sysdb,
122
 
                                 state->ctx->opts, state->ctx->gsh,
123
 
                                 state->attrs, state->filter);
124
 
    if (!subreq) {
125
 
        ret = ENOMEM;
126
 
        goto fail;
127
 
    }
128
 
    tevent_req_set_callback(subreq, users_get_done, req);
129
 
 
130
 
    return req;
131
 
 
132
 
fail:
133
 
    tevent_req_error(req, ret);
134
 
    tevent_req_post(req, ev);
135
 
    return req;
136
 
}
137
 
 
138
 
static void users_get_connect_done(struct tevent_req *subreq)
139
 
{
140
 
    struct tevent_req *req = tevent_req_callback_data(subreq,
141
 
                                                      struct tevent_req);
142
 
    struct users_get_state *state = tevent_req_data(req,
143
 
                                                     struct users_get_state);
144
 
    int ret;
145
 
 
146
 
    ret = sdap_cli_connect_recv(subreq, state->ctx,
147
 
                                &state->ctx->gsh, &state->ctx->rootDSE);
148
 
    talloc_zfree(subreq);
149
 
    if (ret) {
150
 
        if (ret == ENOTSUP) {
151
 
            DEBUG(0, ("Authentication mechanism not Supported by server"));
152
 
        }
153
 
        tevent_req_error(req, ret);
154
 
        return;
155
 
    }
156
 
 
157
 
    subreq = sdap_get_users_send(state, state->ev,
158
 
                                 state->domain, state->sysdb,
159
 
                                 state->ctx->opts, state->ctx->gsh,
160
 
                                 state->attrs, state->filter);
161
 
    if (!subreq) {
162
 
        tevent_req_error(req, ENOMEM);
163
 
        return;
164
 
    }
165
 
    tevent_req_set_callback(subreq, users_get_done, req);
166
 
}
167
 
 
168
 
static void users_get_done(struct tevent_req *subreq)
169
 
{
170
 
    struct tevent_req *req = tevent_req_callback_data(subreq,
171
 
                                                      struct tevent_req);
172
 
    struct users_get_state *state = tevent_req_data(req,
173
 
                                                     struct users_get_state);
174
 
    char *endptr;
175
 
    uid_t uid;
176
 
    int ret;
177
 
 
178
 
    ret = sdap_get_users_recv(subreq, NULL, NULL);
179
 
    talloc_zfree(subreq);
180
 
    if (ret && ret != ENOENT) {
181
 
        tevent_req_error(req, ret);
182
 
        return;
183
 
    }
184
 
 
185
 
    if (ret == ENOENT) {
186
 
        if (strchr(state->name, '*')) {
187
 
            /* it was an enumeration */
188
 
            tevent_req_error(req, ret);
189
 
            return;
190
 
        }
191
 
 
192
 
        switch (state->filter_type) {
193
 
        case BE_FILTER_NAME:
194
 
            subreq = sysdb_delete_user_send(state, state->ev,
195
 
                                            state->sysdb, NULL,
196
 
                                            state->domain, state->name, 0);
197
 
            if (!subreq) {
198
 
                tevent_req_error(req, ENOMEM);
199
 
                return;
200
 
            }
201
 
            tevent_req_set_callback(subreq, users_get_delete, req);
202
 
            return;
203
 
 
204
 
        case BE_FILTER_IDNUM:
205
 
            errno = 0;
206
 
            uid = (uid_t)strtol(state->name, &endptr, 0);
207
 
            if (errno || *endptr || (state->name == endptr)) {
208
 
                tevent_req_error(req, errno);
209
 
                return;
210
 
            }
211
 
 
212
 
            subreq = sysdb_delete_user_send(state, state->ev,
213
 
                                            state->sysdb, NULL,
214
 
                                            state->domain, NULL, uid);
215
 
            if (!subreq) {
216
 
                tevent_req_error(req, ENOMEM);
217
 
                return;
218
 
            }
219
 
            tevent_req_set_callback(subreq, users_get_delete, req);
220
 
            return;
221
 
 
222
 
        default:
223
 
            tevent_req_error(req, EINVAL);
224
 
            return;
225
 
        }
226
 
    }
227
 
 
228
 
    tevent_req_done(req);
229
 
}
230
 
 
231
 
static void users_get_delete(struct tevent_req *subreq)
232
 
{
233
 
    struct tevent_req *req = tevent_req_callback_data(subreq,
234
 
                                                      struct tevent_req);
235
 
    struct users_get_state *state = tevent_req_data(req,
236
 
                                                     struct users_get_state);
237
 
    int ret;
238
 
 
239
 
    ret = sysdb_delete_user_recv(subreq);
240
 
    talloc_zfree(subreq);
241
 
    if (ret) {
242
 
        DEBUG(2, ("User (%s) delete returned %d (%s)\n",
243
 
                  state->name, ret, strerror(ret)));
244
 
    }
245
 
 
246
 
    tevent_req_done(req);
247
 
}
248
 
 
249
 
int users_get_recv(struct tevent_req *req)
250
 
{
251
 
    TEVENT_REQ_RETURN_ON_ERROR(req);
252
 
 
253
 
    return EOK;
254
 
}
255
 
 
256
 
 
257
 
/* =Groups-Related-Functions-(by-name,by-uid)============================= */
258
 
 
259
 
struct groups_get_state {
260
 
    struct tevent_context *ev;
261
 
    struct sdap_id_ctx *ctx;
262
 
    struct sysdb_ctx *sysdb;
263
 
    struct sss_domain_info *domain;
264
 
 
265
 
    const char *name;
266
 
    int filter_type;
267
 
 
268
 
    char *filter;
269
 
    const char **attrs;
270
 
};
271
 
 
272
 
static void groups_get_connect_done(struct tevent_req *subreq);
273
 
static void groups_get_done(struct tevent_req *subreq);
274
 
static void groups_get_delete(struct tevent_req *subreq);
275
 
 
276
 
struct tevent_req *groups_get_send(TALLOC_CTX *memctx,
277
 
                                   struct tevent_context *ev,
278
 
                                   struct sdap_id_ctx *ctx,
279
 
                                   const char *name,
280
 
                                   int filter_type,
281
 
                                   int attrs_type)
282
 
{
283
 
    struct tevent_req *req, *subreq;
284
 
    struct groups_get_state *state;
285
 
    const char *attr_name;
286
 
    int ret;
287
 
 
288
 
    req = tevent_req_create(memctx, &state, struct groups_get_state);
289
 
    if (!req) return NULL;
290
 
 
291
 
    state->ev = ev;
292
 
    state->ctx = ctx;
293
 
    state->sysdb = ctx->be->sysdb;
294
 
    state->domain = state->ctx->be->domain;
295
 
    state->name = name;
296
 
    state->filter_type = filter_type;
297
 
 
298
 
    switch(filter_type) {
299
 
    case BE_FILTER_NAME:
300
 
        attr_name = ctx->opts->group_map[SDAP_AT_GROUP_NAME].name;
301
 
        break;
302
 
    case BE_FILTER_IDNUM:
303
 
        attr_name = ctx->opts->group_map[SDAP_AT_GROUP_GID].name;
304
 
        break;
305
 
    default:
306
 
        ret = EINVAL;
307
 
        goto fail;
308
 
    }
309
 
 
310
 
    state->filter = talloc_asprintf(state, "(&(%s=%s)(objectclass=%s))",
311
 
                                    attr_name, name,
312
 
                                    ctx->opts->group_map[SDAP_OC_GROUP].name);
313
 
    if (!state->filter) {
314
 
        DEBUG(2, ("Failed to build filter\n"));
315
 
        ret = ENOMEM;
316
 
        goto fail;
317
 
    }
318
 
 
319
 
    /* TODO: handle attrs_type */
320
 
    ret = build_attrs_from_map(state, ctx->opts->group_map,
321
 
                               SDAP_OPTS_GROUP, &state->attrs);
322
 
    if (ret != EOK) goto fail;
323
 
 
324
 
    if (!sdap_connected(ctx)) {
325
 
 
326
 
        if (ctx->gsh) talloc_zfree(ctx->gsh);
327
 
 
328
 
        /* FIXME: add option to decide if tls should be used
329
 
         * or SASL/GSSAPI, etc ... */
330
 
        subreq = sdap_cli_connect_send(state, ev, ctx->opts,
331
 
                                       ctx->be, ctx->service,
332
 
                                       &ctx->rootDSE);
333
 
        if (!subreq) {
334
 
            ret = ENOMEM;
335
 
            goto fail;
336
 
        }
337
 
 
338
 
        tevent_req_set_callback(subreq, groups_get_connect_done, req);
339
 
 
340
 
        return req;
341
 
    }
342
 
 
343
 
    subreq = sdap_get_groups_send(state, state->ev,
344
 
                                  state->domain, state->sysdb,
345
 
                                  state->ctx->opts, state->ctx->gsh,
346
 
                                  state->attrs, state->filter);
347
 
    if (!subreq) {
348
 
        ret = ENOMEM;
349
 
        goto fail;
350
 
    }
351
 
    tevent_req_set_callback(subreq, groups_get_done, req);
352
 
 
353
 
    return req;
354
 
 
355
 
fail:
356
 
    tevent_req_error(req, ret);
357
 
    tevent_req_post(req, ev);
358
 
    return req;
359
 
}
360
 
 
361
 
static void groups_get_connect_done(struct tevent_req *subreq)
362
 
{
363
 
    struct tevent_req *req = tevent_req_callback_data(subreq,
364
 
                                                      struct tevent_req);
365
 
    struct groups_get_state *state = tevent_req_data(req,
366
 
                                                     struct groups_get_state);
367
 
    int ret;
368
 
 
369
 
    ret = sdap_cli_connect_recv(subreq, state->ctx,
370
 
                                &state->ctx->gsh, &state->ctx->rootDSE);
371
 
    talloc_zfree(subreq);
372
 
    if (ret) {
373
 
        if (ret == ENOTSUP) {
374
 
            DEBUG(0, ("Authentication mechanism not Supported by server"));
375
 
        }
376
 
        tevent_req_error(req, ret);
377
 
        return;
378
 
    }
379
 
 
380
 
    subreq = sdap_get_groups_send(state, state->ev,
381
 
                                  state->domain, state->sysdb,
382
 
                                  state->ctx->opts, state->ctx->gsh,
383
 
                                  state->attrs, state->filter);
384
 
    if (!subreq) {
385
 
        tevent_req_error(req, ENOMEM);
386
 
        return;
387
 
    }
388
 
    tevent_req_set_callback(subreq, groups_get_done, req);
389
 
}
390
 
 
391
 
static void groups_get_done(struct tevent_req *subreq)
392
 
{
393
 
    struct tevent_req *req = tevent_req_callback_data(subreq,
394
 
                                                      struct tevent_req);
395
 
    struct groups_get_state *state = tevent_req_data(req,
396
 
                                                     struct groups_get_state);
397
 
    char *endptr;
398
 
    gid_t gid;
399
 
    int ret;
400
 
 
401
 
    ret = sdap_get_groups_recv(subreq, NULL, NULL);
402
 
    talloc_zfree(subreq);
403
 
    if (ret && ret != ENOENT) {
404
 
        tevent_req_error(req, ret);
405
 
        return;
406
 
    }
407
 
 
408
 
    if (ret == ENOENT) {
409
 
        if (strchr(state->name, '*')) {
410
 
            /* it was an enumeration */
411
 
            tevent_req_error(req, ret);
412
 
            return;
413
 
        }
414
 
 
415
 
        switch (state->filter_type) {
416
 
        case BE_FILTER_NAME:
417
 
            subreq = sysdb_delete_group_send(state, state->ev,
418
 
                                            state->sysdb, NULL,
419
 
                                            state->domain, state->name, 0);
420
 
            if (!subreq) {
421
 
                tevent_req_error(req, ENOMEM);
422
 
                return;
423
 
            }
424
 
            tevent_req_set_callback(subreq, groups_get_delete, req);
425
 
            return;
426
 
 
427
 
        case BE_FILTER_IDNUM:
428
 
            errno = 0;
429
 
            gid = (gid_t)strtol(state->name, &endptr, 0);
430
 
            if (errno || *endptr || (state->name == endptr)) {
431
 
                tevent_req_error(req, errno);
432
 
                return;
433
 
            }
434
 
 
435
 
            subreq = sysdb_delete_group_send(state, state->ev,
436
 
                                            state->sysdb, NULL,
437
 
                                            state->domain, NULL, gid);
438
 
            if (!subreq) {
439
 
                tevent_req_error(req, ENOMEM);
440
 
                return;
441
 
            }
442
 
            tevent_req_set_callback(subreq, groups_get_delete, req);
443
 
            return;
444
 
 
445
 
        default:
446
 
            tevent_req_error(req, EINVAL);
447
 
            return;
448
 
        }
449
 
    }
450
 
 
451
 
    tevent_req_done(req);
452
 
}
453
 
 
454
 
static void groups_get_delete(struct tevent_req *subreq)
455
 
{
456
 
    struct tevent_req *req = tevent_req_callback_data(subreq,
457
 
                                                      struct tevent_req);
458
 
    struct groups_get_state *state = tevent_req_data(req,
459
 
                                                     struct groups_get_state);
460
 
    int ret;
461
 
 
462
 
    ret = sysdb_delete_group_recv(subreq);
463
 
    talloc_zfree(subreq);
464
 
    if (ret) {
465
 
        DEBUG(2, ("Group (%s) delete returned %d (%s)\n",
466
 
                  state->name, ret, strerror(ret)));
467
 
    }
468
 
 
469
 
    tevent_req_done(req);
470
 
}
471
 
 
472
 
int groups_get_recv(struct tevent_req *req)
473
 
{
474
 
    TEVENT_REQ_RETURN_ON_ERROR(req);
475
 
 
476
 
    return EOK;
477
 
}
478
 
 
479
 
 
480
 
/* =Get-Groups-for-User================================================== */
481
 
 
482
 
struct groups_by_user_state {
483
 
    struct tevent_context *ev;
484
 
    struct sdap_id_ctx *ctx;
485
 
    const char *name;
486
 
    const char **attrs;
487
 
};
488
 
 
489
 
static void groups_by_user_connect_done(struct tevent_req *subreq);
490
 
static void groups_by_user_done(struct tevent_req *subreq);
491
 
 
492
 
static struct tevent_req *groups_by_user_send(TALLOC_CTX *memctx,
493
 
                                              struct tevent_context *ev,
494
 
                                              struct sdap_id_ctx *ctx,
495
 
                                              const char *name)
496
 
{
497
 
    struct tevent_req *req, *subreq;
498
 
    struct groups_by_user_state *state;
499
 
    int ret;
500
 
 
501
 
    req = tevent_req_create(memctx, &state, struct groups_by_user_state);
502
 
    if (!req) return NULL;
503
 
 
504
 
    state->ev = ev;
505
 
    state->ctx = ctx;
506
 
    state->name = name;
507
 
 
508
 
    ret = build_attrs_from_map(state, ctx->opts->group_map,
509
 
                               SDAP_OPTS_GROUP, &state->attrs);
510
 
    if (ret != EOK) goto fail;
511
 
 
512
 
    if (!sdap_connected(ctx)) {
513
 
 
514
 
        if (ctx->gsh) talloc_zfree(ctx->gsh);
515
 
 
516
 
        /* FIXME: add option to decide if tls should be used
517
 
         * or SASL/GSSAPI, etc ... */
518
 
        subreq = sdap_cli_connect_send(state, ev, ctx->opts,
519
 
                                       ctx->be, ctx->service,
520
 
                                       &ctx->rootDSE);
521
 
        if (!subreq) {
522
 
            ret = ENOMEM;
523
 
            goto fail;
524
 
        }
525
 
 
526
 
        tevent_req_set_callback(subreq, groups_by_user_connect_done, req);
527
 
 
528
 
        return req;
529
 
    }
530
 
 
531
 
    subreq = sdap_get_initgr_send(state, state->ev,
532
 
                                  state->ctx->be->domain,
533
 
                                  state->ctx->be->sysdb,
534
 
                                  state->ctx->opts, state->ctx->gsh,
535
 
                                  state->name, state->attrs);
536
 
    if (!subreq) {
537
 
        ret = ENOMEM;
538
 
        goto fail;
539
 
    }
540
 
    tevent_req_set_callback(subreq, groups_by_user_done, req);
541
 
 
542
 
    return req;
543
 
 
544
 
fail:
545
 
    tevent_req_error(req, ret);
546
 
    tevent_req_post(req, ev);
547
 
    return req;
548
 
}
549
 
 
550
 
static void groups_by_user_connect_done(struct tevent_req *subreq)
551
 
{
552
 
    struct tevent_req *req = tevent_req_callback_data(subreq,
553
 
                                                      struct tevent_req);
554
 
    struct groups_by_user_state *state = tevent_req_data(req,
555
 
                                                     struct groups_by_user_state);
556
 
    int ret;
557
 
 
558
 
    ret = sdap_cli_connect_recv(subreq, state->ctx,
559
 
                                &state->ctx->gsh, &state->ctx->rootDSE);
560
 
    talloc_zfree(subreq);
561
 
    if (ret) {
562
 
        if (ret == ENOTSUP) {
563
 
            DEBUG(0, ("Authentication mechanism not Supported by server"));
564
 
        }
565
 
        tevent_req_error(req, ret);
566
 
        return;
567
 
    }
568
 
 
569
 
    subreq = sdap_get_initgr_send(state, state->ev,
570
 
                                  state->ctx->be->domain,
571
 
                                  state->ctx->be->sysdb,
572
 
                                  state->ctx->opts, state->ctx->gsh,
573
 
                                  state->name, state->attrs);
574
 
    if (!subreq) {
575
 
        tevent_req_error(req, ENOMEM);
576
 
        return;
577
 
    }
578
 
    tevent_req_set_callback(subreq, groups_by_user_done, req);
579
 
}
580
 
 
581
 
static void groups_by_user_done(struct tevent_req *subreq)
582
 
{
583
 
    struct tevent_req *req = tevent_req_callback_data(subreq,
584
 
                                                      struct tevent_req);
585
 
    int ret;
586
 
 
587
 
    ret = sdap_get_initgr_recv(subreq);
588
 
    talloc_zfree(subreq);
589
 
    if (ret) {
590
 
        tevent_req_error(req, ret);
591
 
        return;
592
 
    }
593
 
 
594
 
    tevent_req_done(req);
595
 
}
596
 
 
597
 
int groups_by_user_recv(struct tevent_req *req)
598
 
{
599
 
    TEVENT_REQ_RETURN_ON_ERROR(req);
600
 
 
601
 
    return EOK;
602
 
}
603
 
 
604
 
 
605
 
 
606
 
/* =Get-Account-Info-Call================================================= */
607
 
 
608
 
/* FIXME: embed this function in sssd_be and only call out
609
 
 * specific functions from modules ? */
610
 
 
611
 
static void sdap_account_info_users_done(struct tevent_req *req);
612
 
static void sdap_account_info_groups_done(struct tevent_req *req);
613
 
static void sdap_account_info_initgr_done(struct tevent_req *req);
614
 
 
615
 
void sdap_account_info_handler(struct be_req *breq)
616
 
{
617
 
    struct sdap_id_ctx *ctx;
618
 
    struct be_acct_req *ar;
619
 
    struct tevent_req *req;
620
 
    const char *err = "Unknown Error";
621
 
    int ret = EOK;
622
 
 
623
 
    ctx = talloc_get_type(breq->be_ctx->bet_info[BET_ID].pvt_bet_data, struct sdap_id_ctx);
624
 
 
625
 
    if (be_is_offline(ctx->be)) {
626
 
        return sdap_handler_done(breq, DP_ERR_OFFLINE, EAGAIN, "Offline");
627
 
    }
628
 
 
629
 
    ar = talloc_get_type(breq->req_data, struct be_acct_req);
630
 
 
631
 
    switch (ar->entry_type & 0xFFF) {
632
 
    case BE_REQ_USER: /* user */
633
 
 
634
 
        /* skip enumerations on demand */
635
 
        if (strcmp(ar->filter_value, "*") == 0) {
636
 
            return sdap_handler_done(breq, DP_ERR_OK, EOK, "Success");
637
 
        }
638
 
 
639
 
        req = users_get_send(breq, breq->be_ctx->ev, ctx,
640
 
                             ar->filter_value,
641
 
                             ar->filter_type,
642
 
                             ar->attr_type);
643
 
        if (!req) {
644
 
            return sdap_handler_done(breq, DP_ERR_FATAL, ENOMEM, "Out of memory");
645
 
        }
646
 
 
647
 
        tevent_req_set_callback(req, sdap_account_info_users_done, breq);
648
 
 
649
 
        break;
650
 
 
651
 
    case BE_REQ_GROUP: /* group */
652
 
 
653
 
        if (strcmp(ar->filter_value, "*") == 0) {
654
 
            return sdap_handler_done(breq, DP_ERR_OK, EOK, "Success");
655
 
        }
656
 
 
657
 
        /* skip enumerations on demand */
658
 
        req = groups_get_send(breq, breq->be_ctx->ev, ctx,
659
 
                              ar->filter_value,
660
 
                              ar->filter_type,
661
 
                              ar->attr_type);
662
 
        if (!req) {
663
 
            return sdap_handler_done(breq, DP_ERR_FATAL, ENOMEM, "Out of memory");
664
 
        }
665
 
 
666
 
        tevent_req_set_callback(req, sdap_account_info_groups_done, breq);
667
 
 
668
 
        break;
669
 
 
670
 
    case BE_REQ_INITGROUPS: /* init groups for user */
671
 
        if (ar->filter_type != BE_FILTER_NAME) {
672
 
            ret = EINVAL;
673
 
            err = "Invalid filter type";
674
 
            break;
675
 
        }
676
 
        if (ar->attr_type != BE_ATTR_CORE) {
677
 
            ret = EINVAL;
678
 
            err = "Invalid attr type";
679
 
            break;
680
 
        }
681
 
        if (strchr(ar->filter_value, '*')) {
682
 
            ret = EINVAL;
683
 
            err = "Invalid filter value";
684
 
            break;
685
 
        }
686
 
        req = groups_by_user_send(breq, breq->be_ctx->ev, ctx,
687
 
                                  ar->filter_value);
688
 
        if (!req) ret = ENOMEM;
689
 
        /* tevent_req_set_callback(req, groups_by_user_done, breq); */
690
 
 
691
 
        tevent_req_set_callback(req, sdap_account_info_initgr_done, breq);
692
 
 
693
 
        break;
694
 
 
695
 
    default: /*fail*/
696
 
        ret = EINVAL;
697
 
        err = "Invalid request type";
698
 
    }
699
 
 
700
 
    if (ret != EOK) return sdap_handler_done(breq, DP_ERR_FATAL, ret, err);
701
 
}
702
 
 
703
 
static void sdap_account_info_users_done(struct tevent_req *req)
704
 
{
705
 
    struct be_req *breq = tevent_req_callback_data(req, struct be_req);
706
 
    struct sdap_id_ctx *ctx;
707
 
    int dp_err = DP_ERR_OK;
708
 
    const char *error = NULL;
709
 
    int ret;
710
 
 
711
 
    ret = users_get_recv(req);
712
 
    talloc_zfree(req);
713
 
 
714
 
    if (ret) {
715
 
        dp_err = DP_ERR_FATAL;
716
 
        error = "Enum Users Failed";
717
 
 
718
 
        if (ret == ETIMEDOUT || ret == EFAULT || ret == EIO) {
719
 
            dp_err = DP_ERR_OFFLINE;
720
 
            ctx = talloc_get_type(breq->be_ctx->bet_info[BET_ID].pvt_bet_data,
721
 
                                  struct sdap_id_ctx);
722
 
            if (sdap_check_gssapi_reconnect(ctx)) {
723
 
                talloc_zfree(ctx->gsh);
724
 
                sdap_account_info_handler(breq);
725
 
                return;
726
 
            }
727
 
            sdap_mark_offline(ctx);
728
 
        }
729
 
    }
730
 
 
731
 
    sdap_handler_done(breq, dp_err, ret, error);
732
 
}
733
 
 
734
 
static void sdap_account_info_groups_done(struct tevent_req *req)
735
 
{
736
 
    struct be_req *breq = tevent_req_callback_data(req, struct be_req);
737
 
    struct sdap_id_ctx *ctx;
738
 
    int dp_err = DP_ERR_OK;
739
 
    const char *error = NULL;
740
 
    int ret;
741
 
 
742
 
    ret = groups_get_recv(req);
743
 
    talloc_zfree(req);
744
 
 
745
 
    if (ret) {
746
 
        dp_err = DP_ERR_FATAL;
747
 
        error = "Enum Groups Failed";
748
 
 
749
 
        if (ret == ETIMEDOUT || ret == EFAULT || ret == EIO) {
750
 
            dp_err = DP_ERR_OFFLINE;
751
 
            ctx = talloc_get_type(breq->be_ctx->bet_info[BET_ID].pvt_bet_data,
752
 
                                  struct sdap_id_ctx);
753
 
            if (sdap_check_gssapi_reconnect(ctx)) {
754
 
                talloc_zfree(ctx->gsh);
755
 
                sdap_account_info_handler(breq);
756
 
                return;
757
 
            }
758
 
            sdap_mark_offline(ctx);
759
 
        }
760
 
    }
761
 
 
762
 
    return sdap_handler_done(breq, dp_err, ret, error);
763
 
}
764
 
 
765
 
static void sdap_account_info_initgr_done(struct tevent_req *req)
766
 
{
767
 
    struct be_req *breq = tevent_req_callback_data(req, struct be_req);
768
 
    struct sdap_id_ctx *ctx;
769
 
    int dp_err = DP_ERR_OK;
770
 
    const char *error = NULL;
771
 
    int ret;
772
 
 
773
 
    ret = groups_by_user_recv(req);
774
 
    talloc_zfree(req);
775
 
 
776
 
    if (ret) {
777
 
        dp_err = DP_ERR_FATAL;
778
 
        error = "Init Groups Failed";
779
 
 
780
 
        if (ret == ETIMEDOUT || ret == EFAULT || ret == EIO) {
781
 
            dp_err = DP_ERR_OFFLINE;
782
 
            ctx = talloc_get_type(breq->be_ctx->bet_info[BET_ID].pvt_bet_data,
783
 
                                  struct sdap_id_ctx);
784
 
            if (sdap_check_gssapi_reconnect(ctx)) {
785
 
                talloc_zfree(ctx->gsh);
786
 
                sdap_account_info_handler(breq);
787
 
                return;
788
 
            }
789
 
            sdap_mark_offline(ctx);
790
 
        }
791
 
    }
792
 
 
793
 
    return sdap_handler_done(breq, dp_err, ret, error);
794
 
}
795