source: trunk/server/source3/winbindd/winbindd_getgrent.c@ 898

Last change on this file since 898 was 596, checked in by Herwig Bauernfeind, 14 years ago

Samba 3.5: Update trunk to 3.5.8

File size: 5.9 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3 async implementation of WINBINDD_GETGRENT
4 Copyright (C) Volker Lendecke 2009
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#include "includes.h"
21#include "winbindd.h"
22
23struct winbindd_getgrent_state {
24 struct tevent_context *ev;
25 struct winbindd_cli_state *cli;
26 int max_groups;
27 int num_groups;
28 struct winbindd_gr *groups;
29 struct talloc_dict **members;
30};
31
32static void winbindd_getgrent_done(struct tevent_req *subreq);
33
34struct tevent_req *winbindd_getgrent_send(TALLOC_CTX *mem_ctx,
35 struct tevent_context *ev,
36 struct winbindd_cli_state *cli,
37 struct winbindd_request *request)
38{
39 struct tevent_req *req, *subreq;
40 struct winbindd_getgrent_state *state;
41
42 req = tevent_req_create(mem_ctx, &state,
43 struct winbindd_getgrent_state);
44 if (req == NULL) {
45 return NULL;
46 }
47 state->ev = ev;
48 state->num_groups = 0;
49 state->cli = cli;
50
51 DEBUG(3, ("[%5lu]: getgrent\n", (unsigned long)cli->pid));
52
53 if (!lp_winbind_enum_groups()) {
54 tevent_req_nterror(req, NT_STATUS_NO_MORE_ENTRIES);
55 return tevent_req_post(req, ev);
56 }
57
58 if (cli->grent_state == NULL) {
59 tevent_req_nterror(req, NT_STATUS_NO_MORE_ENTRIES);
60 return tevent_req_post(req, ev);
61 }
62
63 state->max_groups = MIN(500, request->data.num_entries);
64 if (state->max_groups == 0) {
65 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
66 return tevent_req_post(req, ev);
67 }
68
69 state->groups = talloc_zero_array(state, struct winbindd_gr,
70 state->max_groups);
71 if (tevent_req_nomem(state->groups, req)) {
72 return tevent_req_post(req, ev);
73 }
74
75 state->members = talloc_array(state, struct talloc_dict *,
76 state->max_groups);
77 if (tevent_req_nomem(state->members, req)) {
78 TALLOC_FREE(state->groups);
79 return tevent_req_post(req, ev);
80 }
81
82 subreq = wb_next_grent_send(state, ev, lp_winbind_expand_groups(),
83 cli->grent_state,
84 &state->groups[state->num_groups]);
85 if (tevent_req_nomem(subreq, req)) {
86 return tevent_req_post(req, ev);
87 }
88 tevent_req_set_callback(subreq, winbindd_getgrent_done, req);
89 return req;
90}
91