s3:popt_common: Fix password processing.
[Samba.git] / source4 / winbind / wb_cmd_lookupname.c
blob5178187ea8bfb9efca0b605ea66f5cec2504005a
1 /*
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 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_helper.h"
26 #include "smbd/service_task.h"
28 struct cmd_lookupname_state {
29 struct composite_context *ctx;
30 const char *name;
31 struct wb_sid_object *result;
34 static void lookupname_recv_domain(struct composite_context *ctx);
35 static void lookupname_recv_sids(struct composite_context *ctx);
37 struct composite_context *wb_cmd_lookupname_send(TALLOC_CTX *mem_ctx,
38 struct wbsrv_service *service,
39 const char *dom_name,
40 const char *name)
42 struct composite_context *result, *ctx;
43 struct cmd_lookupname_state *state;
45 result = composite_create(mem_ctx, service->task->event_ctx);
46 if (result == NULL) goto failed;
48 state = talloc(result, struct cmd_lookupname_state);
49 if (state == NULL) goto failed;
50 state->ctx = result;
51 result->private_data = state;
53 state->name = talloc_asprintf(state, "%s\\%s", dom_name, name);
54 if (state->name == NULL) goto failed;
56 ctx = wb_sid2domain_send(state, service, service->primary_sid);
57 if (ctx == NULL) goto failed;
59 ctx->async.fn = lookupname_recv_domain;
60 ctx->async.private_data = state;
61 return result;
63 failed:
64 talloc_free(result);
65 return NULL;
68 static void lookupname_recv_domain(struct composite_context *ctx)
70 struct cmd_lookupname_state *state =
71 talloc_get_type(ctx->async.private_data,
72 struct cmd_lookupname_state);
73 struct wbsrv_domain *domain;
75 state->ctx->status = wb_sid2domain_recv(ctx, &domain);
76 if (!composite_is_ok(state->ctx)) return;
78 ctx = wb_lsa_lookupnames_send(state, domain->libnet_ctx->lsa.pipe,
79 &domain->libnet_ctx->lsa.handle, 1, &state->name);
80 composite_continue(state->ctx, ctx, lookupname_recv_sids, state);
83 static void lookupname_recv_sids(struct composite_context *ctx)
85 struct cmd_lookupname_state *state =
86 talloc_get_type(ctx->async.private_data,
87 struct cmd_lookupname_state);
88 struct wb_sid_object **sids;
90 state->ctx->status = wb_lsa_lookupnames_recv(ctx, state, &sids);
91 if (!composite_is_ok(state->ctx)) return;
93 state->result = sids[0];
94 composite_done(state->ctx);
97 NTSTATUS wb_cmd_lookupname_recv(struct composite_context *c,
98 TALLOC_CTX *mem_ctx,
99 struct wb_sid_object **sid)
101 struct cmd_lookupname_state *state =
102 talloc_get_type(c->private_data, struct cmd_lookupname_state);
103 NTSTATUS status = composite_wait(c);
104 if (NT_STATUS_IS_OK(status)) {
105 *sid = talloc_steal(mem_ctx, state->result);
107 talloc_free(state);
108 return status;
111 NTSTATUS wb_cmd_lookupname(TALLOC_CTX *mem_ctx,
112 struct wbsrv_service *service,
113 const char *dom_name,
114 const char *name,
115 struct wb_sid_object **sid)
117 struct composite_context *c =
118 wb_cmd_lookupname_send(mem_ctx, service, dom_name, name);
119 return wb_cmd_lookupname_recv(c, mem_ctx, sid);