2 Unix SMB/CIFS implementation.
4 Command backend for wbinfo -n
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 "smbd/service_stream.h"
27 #include "smbd/service_task.h"
29 struct cmd_lookupname_state
{
30 struct composite_context
*ctx
;
32 struct wb_sid_object
*result
;
35 static struct composite_context
*lookupname_send_req(struct wbsrv_domain
*domain
, void *p
);
36 static NTSTATUS
lookupname_recv_req(struct composite_context
*ctx
, void *p
);
38 struct composite_context
*wb_cmd_lookupname_send(struct wbsrv_service
*service
,
42 struct cmd_lookupname_state
*state
;
44 state
= talloc(NULL
, struct cmd_lookupname_state
);
45 state
->name
= talloc_asprintf(state
, "%s\\%s", dom_name
, name
);
46 if (state
->name
== NULL
) goto failed
;
47 state
->ctx
= wb_domain_request_send(state
, service
,
52 if (state
->ctx
== NULL
) goto failed
;
53 state
->ctx
->private_data
= state
;
61 static struct composite_context
*lookupname_send_req(struct wbsrv_domain
*domain
,
64 struct cmd_lookupname_state
*state
=
65 talloc_get_type(p
, struct cmd_lookupname_state
);
67 return wb_lsa_lookupnames_send(domain
->lsa_pipe
,
72 static NTSTATUS
lookupname_recv_req(struct composite_context
*ctx
, void *p
)
74 struct cmd_lookupname_state
*state
=
75 talloc_get_type(p
, struct cmd_lookupname_state
);
76 struct wb_sid_object
**sids
;
79 status
= wb_lsa_lookupnames_recv(ctx
, state
, &sids
);
80 if (NT_STATUS_IS_OK(status
)) {
81 state
->result
= sids
[0];
86 NTSTATUS
wb_cmd_lookupname_recv(struct composite_context
*c
,
88 struct wb_sid_object
**sid
)
90 struct cmd_lookupname_state
*state
=
91 talloc_get_type(c
->private_data
, struct cmd_lookupname_state
);
92 NTSTATUS status
= composite_wait(c
);
93 if (NT_STATUS_IS_OK(status
)) {
94 *sid
= talloc_steal(mem_ctx
, state
->result
);
100 NTSTATUS
wb_cmd_lookupname(struct wbsrv_service
*service
,
101 const char *dom_name
,
103 TALLOC_CTX
*mem_ctx
, struct wb_sid_object
**sid
)
105 struct composite_context
*c
=
106 wb_cmd_lookupname_send(service
, dom_name
, name
);
107 return wb_cmd_lookupname_recv(c
, mem_ctx
, sid
);