idl: rebuild drsuapi.idl
[Samba/aatanasov.git] / source4 / winbind / wb_cmd_getgrgid.c
blob80f4e9cfc32df4682d42b4c9a013a6856d62f667
1 /*
2 Unix SMB/CIFS implementation.
4 Backend for getgrgid
6 Copyright (C) Kai Blin 2007
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 "winbind/wb_server.h"
25 #include "winbind/wb_async_helpers.h"
26 #include "winbind/wb_helper.h"
27 #include "smbd/service_task.h"
28 #include "libnet/libnet_proto.h"
29 #include "param/param.h"
30 #include "libcli/security/proto.h"
31 #include "auth/credentials/credentials.h"
33 struct cmd_getgrgid_state {
34 struct composite_context *ctx;
35 struct wbsrv_service *service;
36 gid_t gid;
37 struct dom_sid *sid;
38 char *workgroup;
39 struct wbsrv_domain *domain;
41 struct winbindd_gr *result;
44 static void cmd_getgrgid_recv_sid(struct composite_context *ctx);
45 static void cmd_getgrgid_recv_domain(struct composite_context *ctx);
46 static void cmd_getgrgid_recv_group_info(struct composite_context *ctx);
48 /* Get the SID using the gid */
50 struct composite_context *wb_cmd_getgrgid_send(TALLOC_CTX *mem_ctx,
51 struct wbsrv_service *service,
52 gid_t gid)
54 struct composite_context *ctx, *result;
55 struct cmd_getgrgid_state *state;
57 DEBUG(5, ("wb_cmd_getgrgid_send called\n"));
59 result = composite_create(mem_ctx, service->task->event_ctx);
60 if (!result) return NULL;
62 state = talloc(result, struct cmd_getgrgid_state);
63 if (composite_nomem(state, result)) return result;
64 state->ctx = result;
65 result->private_data = state;
66 state->service = service;
67 state->gid = gid;
69 ctx = wb_gid2sid_send(state, service, gid);
70 if (composite_nomem(ctx, state->ctx)) return result;
72 composite_continue(result, ctx, cmd_getgrgid_recv_sid, state);
73 return result;
77 /* Receive the sid and get the domain structure with it */
79 static void cmd_getgrgid_recv_sid(struct composite_context *ctx)
81 struct cmd_getgrgid_state *state =
82 talloc_get_type(ctx->async.private_data,
83 struct cmd_getgrgid_state);
85 DEBUG(5, ("cmd_getgrgid_recv_sid called %p\n", ctx->private_data));
87 state->ctx->status = wb_gid2sid_recv(ctx, state, &state->sid);
88 if (!composite_is_ok(state->ctx)) return;
90 ctx = wb_sid2domain_send(state, state->service, state->sid);
92 composite_continue(state->ctx, ctx, cmd_getgrgid_recv_domain, state);
95 /* Receive the domain struct and call libnet to get the user info struct */
97 static void cmd_getgrgid_recv_domain(struct composite_context *ctx)
99 struct cmd_getgrgid_state *state =
100 talloc_get_type(ctx->async.private_data,
101 struct cmd_getgrgid_state);
102 struct libnet_GroupInfo *group_info;
104 DEBUG(5, ("cmd_getgrgid_recv_domain called\n"));
106 state->ctx->status = wb_sid2domain_recv(ctx, &state->domain);
107 if (!composite_is_ok(state->ctx)) return;
109 group_info = talloc(state, struct libnet_GroupInfo);
110 if (composite_nomem(group_info, state->ctx)) return;
112 group_info->in.level = GROUP_INFO_BY_SID;
113 group_info->in.data.group_sid = state->sid;
114 group_info->in.domain_name = state->domain->libnet_ctx->samr.name;
116 /* We need the workgroup later, so copy it */
117 state->workgroup = talloc_strdup(state,
118 state->domain->libnet_ctx->samr.name);
119 if (composite_nomem(state->workgroup, state->ctx)) return;
121 ctx = libnet_GroupInfo_send(state->domain->libnet_ctx, state,group_info,
122 NULL);
124 composite_continue(state->ctx, ctx, cmd_getgrgid_recv_group_info,state);
127 /* Receive the group info struct */
129 static void cmd_getgrgid_recv_group_info(struct composite_context *ctx)
131 struct cmd_getgrgid_state *state =
132 talloc_get_type(ctx->async.private_data,
133 struct cmd_getgrgid_state);
134 struct libnet_GroupInfo *group_info;
135 struct winbindd_gr *gr;
137 DEBUG(5, ("cmd_getgrgid_recv_group_info called\n"));
139 gr = talloc(state, struct winbindd_gr);
140 if (composite_nomem(gr, state->ctx)) return;
142 group_info = talloc(state, struct libnet_GroupInfo);
143 if(composite_nomem(group_info, state->ctx)) return;
145 state->ctx->status = libnet_GroupInfo_recv(ctx, state, group_info);
146 if (!composite_is_ok(state->ctx)) return;
148 WBSRV_SAMBA3_SET_STRING(gr->gr_name, group_info->out.group_name);
149 WBSRV_SAMBA3_SET_STRING(gr->gr_passwd, "*");
151 gr->gr_gid = state->gid;
153 state->result = gr;
155 composite_done(state->ctx);
158 NTSTATUS wb_cmd_getgrgid_recv(struct composite_context *ctx,
159 TALLOC_CTX *mem_ctx, struct winbindd_gr **gr)
161 NTSTATUS status = composite_wait(ctx);
163 DEBUG(5, ("wb_cmd_getgrgid_recv called\n"));
165 DEBUG(5, ("status is %s\n", nt_errstr(status)));
167 if (NT_STATUS_IS_OK(status)) {
168 struct cmd_getgrgid_state *state =
169 talloc_get_type(ctx->private_data,
170 struct cmd_getgrgid_state);
171 *gr = talloc_steal(mem_ctx, state->result);
173 talloc_free(ctx);
174 return status;