2 Unix SMB/CIFS implementation.
4 Command backend for wbinfo -s
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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "libcli/composite/composite.h"
25 #include "winbind/wb_server.h"
26 #include "winbind/wb_helper.h"
27 #include "smbd/service_task.h"
28 #include "libcli/security/security.h"
30 struct cmd_lookupsid_state
{
31 struct composite_context
*ctx
;
32 const struct dom_sid
*sid
;
33 struct wb_sid_object
*result
;
36 static void lookupsid_recv_domain(struct composite_context
*ctx
);
37 static void lookupsid_recv_names(struct composite_context
*ctx
);
39 struct composite_context
*wb_cmd_lookupsid_send(TALLOC_CTX
*mem_ctx
,
40 struct wbsrv_service
*service
,
41 const struct dom_sid
*sid
)
43 struct composite_context
*result
, *ctx
;
44 struct cmd_lookupsid_state
*state
;
47 result
= composite_create(mem_ctx
, service
->task
->event_ctx
);
48 if (result
== NULL
) goto failed
;
50 state
= talloc(result
, struct cmd_lookupsid_state
);
51 if (state
== NULL
) goto failed
;
53 result
->private_data
= state
;
55 state
->sid
= dom_sid_dup(state
, sid
);
56 if (state
->sid
== NULL
) goto failed
;
58 ctx
= wb_sid2domain_send(state
, service
, service
->primary_sid
);
59 if (ctx
== NULL
) goto failed
;
61 ctx
->async
.fn
= lookupsid_recv_domain
;
62 ctx
->async
.private_data
= state
;
70 static void lookupsid_recv_domain(struct composite_context
*ctx
)
72 struct cmd_lookupsid_state
*state
=
73 talloc_get_type(ctx
->async
.private_data
,
74 struct cmd_lookupsid_state
);
75 struct wbsrv_domain
*domain
;
77 state
->ctx
->status
= wb_sid2domain_recv(ctx
, &domain
);
78 if (!composite_is_ok(state
->ctx
)) return;
80 ctx
= wb_lsa_lookupsids_send(state
, domain
->lsa_pipe
,
81 domain
->lsa_policy
, 1, &state
->sid
);
82 composite_continue(state
->ctx
, ctx
, lookupsid_recv_names
, state
);
85 static void lookupsid_recv_names(struct composite_context
*ctx
)
87 struct cmd_lookupsid_state
*state
=
88 talloc_get_type(ctx
->async
.private_data
,
89 struct cmd_lookupsid_state
);
90 struct wb_sid_object
**names
;
92 state
->ctx
->status
= wb_lsa_lookupsids_recv(ctx
, state
, &names
);
93 if (!composite_is_ok(state
->ctx
)) return;
95 state
->result
= names
[0];
96 composite_done(state
->ctx
);
99 NTSTATUS
wb_cmd_lookupsid_recv(struct composite_context
*c
,
101 struct wb_sid_object
**sid
)
103 struct cmd_lookupsid_state
*state
=
104 talloc_get_type(c
->private_data
, struct cmd_lookupsid_state
);
105 NTSTATUS status
= composite_wait(c
);
106 if (NT_STATUS_IS_OK(status
)) {
107 *sid
= talloc_steal(mem_ctx
, state
->result
);
113 NTSTATUS
wb_cmd_lookupsid(TALLOC_CTX
*mem_ctx
, struct wbsrv_service
*service
,
114 const struct dom_sid
*sid
,
115 struct wb_sid_object
**name
)
117 struct composite_context
*c
=
118 wb_cmd_lookupsid_send(mem_ctx
, service
, sid
);
119 return wb_cmd_lookupsid_recv(c
, mem_ctx
, name
);