r11422: Remove unused args
[kai/samba.git] / source4 / winbind / wb_cmd_lookupname.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    Command backend for wbinfo -n
5
6    Copyright (C) Volker Lendecke 2005
7    
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.
12    
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.
17    
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.
21 */
22
23 #include "includes.h"
24 #include "libcli/composite/composite.h"
25 #include "winbind/wb_server.h"
26 #include "smbd/service_stream.h"
27 #include "smbd/service_task.h"
28
29 struct cmd_lookupname_state {
30         struct composite_context *ctx;
31         const char *name;
32         struct wb_sid_object *result;
33 };
34
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);
37
38 struct composite_context *wb_cmd_lookupname_send(struct wbsrv_service *service,
39                                                  const char *dom_name,
40                                                  const char *name)
41 {
42         struct cmd_lookupname_state *state;
43
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,
48                                             service->primary_sid,
49                                             lookupname_send_req,
50                                             lookupname_recv_req,
51                                             state);
52         if (state->ctx == NULL) goto failed;
53         state->ctx->private_data = state;
54         return state->ctx;
55
56  failed:
57         talloc_free(state);
58         return NULL;
59 }
60
61 static struct composite_context *lookupname_send_req(struct wbsrv_domain *domain,
62                                                      void *p)
63 {
64         struct cmd_lookupname_state *state =
65                 talloc_get_type(p, struct cmd_lookupname_state);
66
67         return wb_lsa_lookupnames_send(domain->lsa_pipe,
68                                        domain->lsa_policy,
69                                        1, &state->name);
70 }
71
72 static NTSTATUS lookupname_recv_req(struct composite_context *ctx, void *p)
73 {
74         struct cmd_lookupname_state *state =
75                 talloc_get_type(p, struct cmd_lookupname_state);
76         struct wb_sid_object **sids;
77         NTSTATUS status;
78
79         status = wb_lsa_lookupnames_recv(ctx, state, &sids);
80         if (NT_STATUS_IS_OK(status)) {
81                 state->result = sids[0];
82         }
83         return status;
84 }
85
86 NTSTATUS wb_cmd_lookupname_recv(struct composite_context *c,
87                                 TALLOC_CTX *mem_ctx,
88                                 struct wb_sid_object **sid)
89 {
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);
95         }
96         talloc_free(state);
97         return status;
98 }
99
100 NTSTATUS wb_cmd_lookupname(struct wbsrv_service *service,
101                            const char *dom_name,
102                            const char *name,
103                            TALLOC_CTX *mem_ctx, struct wb_sid_object **sid)
104 {
105         struct composite_context *c =
106                 wb_cmd_lookupname_send(service, dom_name, name);
107         return wb_cmd_lookupname_recv(c, mem_ctx, sid);
108 }