2 Unix SMB/CIFS implementation.
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/>.
23 #include "libcli/composite/composite.h"
24 #include "winbind/wb_server.h"
25 #include "smbd/service_task.h"
27 struct cmd_getgrgid_state
{
28 struct composite_context
*ctx
;
29 struct wbsrv_service
*service
;
33 struct wbsrv_domain
*domain
;
35 struct winbindd_gr
*result
;
38 static void cmd_getgrgid_recv_sid(struct composite_context
*ctx
);
39 static void cmd_getgrgid_recv_domain(struct composite_context
*ctx
);
40 static void cmd_getgrgid_recv_group_info(struct composite_context
*ctx
);
42 /* Get the SID using the gid */
44 struct composite_context
*wb_cmd_getgrgid_send(TALLOC_CTX
*mem_ctx
,
45 struct wbsrv_service
*service
,
48 struct composite_context
*ctx
, *result
;
49 struct cmd_getgrgid_state
*state
;
51 DEBUG(5, ("wb_cmd_getgrgid_send called\n"));
53 result
= composite_create(mem_ctx
, service
->task
->event_ctx
);
54 if (!result
) return NULL
;
56 state
= talloc(result
, struct cmd_getgrgid_state
);
57 if (composite_nomem(state
, result
)) return result
;
59 result
->private_data
= state
;
60 state
->service
= service
;
63 ctx
= wb_gid2sid_send(state
, service
, gid
);
64 if (composite_nomem(ctx
, state
->ctx
)) return result
;
66 composite_continue(result
, ctx
, cmd_getgrgid_recv_sid
, state
);
71 /* Receive the sid and get the domain structure with it */
73 static void cmd_getgrgid_recv_sid(struct composite_context
*ctx
)
75 struct cmd_getgrgid_state
*state
=
76 talloc_get_type(ctx
->async
.private_data
,
77 struct cmd_getgrgid_state
);
79 DEBUG(5, ("cmd_getgrgid_recv_sid called %p\n", ctx
->private_data
));
81 state
->ctx
->status
= wb_gid2sid_recv(ctx
, state
, &state
->sid
);
82 if (!composite_is_ok(state
->ctx
)) return;
84 ctx
= wb_sid2domain_send(state
, state
->service
, state
->sid
);
86 composite_continue(state
->ctx
, ctx
, cmd_getgrgid_recv_domain
, state
);
89 /* Receive the domain struct and call libnet to get the user info struct */
91 static void cmd_getgrgid_recv_domain(struct composite_context
*ctx
)
93 struct cmd_getgrgid_state
*state
=
94 talloc_get_type(ctx
->async
.private_data
,
95 struct cmd_getgrgid_state
);
96 struct libnet_GroupInfo
*group_info
;
98 DEBUG(5, ("cmd_getgrgid_recv_domain called\n"));
100 state
->ctx
->status
= wb_sid2domain_recv(ctx
, &state
->domain
);
101 if (!composite_is_ok(state
->ctx
)) return;
103 group_info
= talloc(state
, struct libnet_GroupInfo
);
104 if (composite_nomem(group_info
, state
->ctx
)) return;
106 group_info
->in
.level
= GROUP_INFO_BY_SID
;
107 group_info
->in
.data
.group_sid
= state
->sid
;
108 group_info
->in
.domain_name
= state
->domain
->libnet_ctx
->samr
.name
;
110 /* We need the workgroup later, so copy it */
111 state
->workgroup
= talloc_strdup(state
,
112 state
->domain
->libnet_ctx
->samr
.name
);
113 if (composite_nomem(state
->workgroup
, state
->ctx
)) return;
115 ctx
= libnet_GroupInfo_send(state
->domain
->libnet_ctx
, state
,group_info
,
118 composite_continue(state
->ctx
, ctx
, cmd_getgrgid_recv_group_info
,state
);
121 /* Receive the group info struct */
123 static void cmd_getgrgid_recv_group_info(struct composite_context
*ctx
)
125 struct cmd_getgrgid_state
*state
=
126 talloc_get_type(ctx
->async
.private_data
,
127 struct cmd_getgrgid_state
);
128 struct libnet_GroupInfo
*group_info
;
129 struct winbindd_gr
*gr
;
131 DEBUG(5, ("cmd_getgrgid_recv_group_info called\n"));
133 gr
= talloc(state
, struct winbindd_gr
);
134 if (composite_nomem(gr
, state
->ctx
)) return;
136 group_info
= talloc(state
, struct libnet_GroupInfo
);
137 if(composite_nomem(group_info
, state
->ctx
)) return;
139 state
->ctx
->status
= libnet_GroupInfo_recv(ctx
, state
, group_info
);
140 if (!composite_is_ok(state
->ctx
)) return;
142 WBSRV_SAMBA3_SET_STRING(gr
->gr_name
, group_info
->out
.group_name
);
143 WBSRV_SAMBA3_SET_STRING(gr
->gr_passwd
, "*");
145 gr
->gr_gid
= state
->gid
;
149 composite_done(state
->ctx
);
152 NTSTATUS
wb_cmd_getgrgid_recv(struct composite_context
*ctx
,
153 TALLOC_CTX
*mem_ctx
, struct winbindd_gr
**gr
)
155 NTSTATUS status
= composite_wait(ctx
);
157 DEBUG(5, ("wb_cmd_getgrgid_recv called\n"));
159 DEBUG(5, ("status is %s\n", nt_errstr(status
)));
161 if (NT_STATUS_IS_OK(status
)) {
162 struct cmd_getgrgid_state
*state
=
163 talloc_get_type(ctx
->private_data
,
164 struct cmd_getgrgid_state
);
165 *gr
= talloc_steal(mem_ctx
, state
->result
);