dsdb-acl: fix the order of special and system checks
[Samba/gebeck_regimport.git] / source4 / winbind / wb_cmd_userdomgroups.c
blobc1258a94d2729355238157e8a54f4f40614f7e6e
1 /*
2 Unix SMB/CIFS implementation.
4 Command backend for wbinfo --user-domgroups
6 Copyright (C) Volker Lendecke 2005
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.
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.
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/>.
22 #include "includes.h"
23 #include "libcli/composite/composite.h"
24 #include "libcli/security/security.h"
25 #include "winbind/wb_server.h"
26 #include "winbind/wb_helper.h"
27 #include "smbd/service_task.h"
29 struct cmd_userdomgroups_state {
30 struct composite_context *ctx;
31 struct dom_sid *dom_sid;
32 uint32_t user_rid;
33 uint32_t num_rids;
34 uint32_t *rids;
37 static void userdomgroups_recv_domain(struct composite_context *ctx);
38 static void userdomgroups_recv_rids(struct composite_context *ctx);
40 struct composite_context *wb_cmd_userdomgroups_send(TALLOC_CTX *mem_ctx,
41 struct wbsrv_service *service,
42 const struct dom_sid *sid)
44 struct composite_context *result, *ctx;
45 struct cmd_userdomgroups_state *state;
47 result = composite_create(mem_ctx, service->task->event_ctx);
48 if (result == NULL) goto failed;
50 state = talloc(result, struct cmd_userdomgroups_state);
51 if (state == NULL) goto failed;
52 state->ctx = result;
53 result->private_data = state;
55 state->dom_sid = dom_sid_dup(state, sid);
56 if (state->dom_sid == NULL) goto failed;
57 state->dom_sid->num_auths -= 1;
59 state->user_rid = sid->sub_auths[sid->num_auths-1];
61 ctx = wb_sid2domain_send(state, service, sid);
63 composite_continue(state->ctx, ctx, userdomgroups_recv_domain, state);
65 if (ctx) {
66 return result;
69 failed:
70 talloc_free(result);
71 return NULL;
74 static void userdomgroups_recv_domain(struct composite_context *ctx)
76 struct cmd_userdomgroups_state *state =
77 talloc_get_type(ctx->async.private_data,
78 struct cmd_userdomgroups_state);
79 struct wbsrv_domain *domain;
81 state->ctx->status = wb_sid2domain_recv(ctx, &domain);
82 if (!composite_is_ok(state->ctx)) return;
84 ctx = wb_samr_userdomgroups_send(state, domain->libnet_ctx->samr.pipe,
85 &domain->libnet_ctx->samr.handle,
86 state->user_rid);
87 composite_continue(state->ctx, ctx, userdomgroups_recv_rids, state);
91 static void userdomgroups_recv_rids(struct composite_context *ctx)
93 struct cmd_userdomgroups_state *state =
94 talloc_get_type(ctx->async.private_data,
95 struct cmd_userdomgroups_state);
97 state->ctx->status = wb_samr_userdomgroups_recv(ctx, state,
98 &state->num_rids,
99 &state->rids);
100 if (!composite_is_ok(state->ctx)) return;
102 composite_done(state->ctx);
105 NTSTATUS wb_cmd_userdomgroups_recv(struct composite_context *c,
106 TALLOC_CTX *mem_ctx,
107 uint32_t *num_sids, struct dom_sid ***sids)
109 struct cmd_userdomgroups_state *state =
110 talloc_get_type(c->private_data,
111 struct cmd_userdomgroups_state);
112 uint32_t i;
113 NTSTATUS status;
115 status = composite_wait(c);
116 if (!NT_STATUS_IS_OK(status)) goto done;
118 *num_sids = state->num_rids;
119 *sids = talloc_array(mem_ctx, struct dom_sid *, state->num_rids);
120 if (*sids == NULL) {
121 status = NT_STATUS_NO_MEMORY;
122 goto done;
125 for (i=0; i<state->num_rids; i++) {
126 (*sids)[i] = dom_sid_add_rid((*sids), state->dom_sid,
127 state->rids[i]);
128 if ((*sids)[i] == NULL) {
129 status = NT_STATUS_NO_MEMORY;
130 goto done;
134 done:
135 talloc_free(c);
136 return status;
139 NTSTATUS wb_cmd_userdomgroups(TALLOC_CTX *mem_ctx,
140 struct wbsrv_service *service,
141 const struct dom_sid *sid,
142 uint32_t *num_sids, struct dom_sid ***sids)
144 struct composite_context *c =
145 wb_cmd_userdomgroups_send(mem_ctx, service, sid);
146 return wb_cmd_userdomgroups_recv(c, mem_ctx, num_sids, sids);