WHATSNEW: Update release notes.
[Samba.git] / source4 / winbind / wb_name2domain.c
blobe19703b1e59245eadeb60899ce6dd9b6b482b9d3
1 /*
2 Unix SMB/CIFS implementation.
4 Find and init a domain struct for a name
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/>.
22 #include "includes.h"
23 #include "libcli/composite/composite.h"
24 #include "winbind/wb_server.h"
25 #include "smbd/service_task.h"
26 #include "winbind/wb_helper.h"
27 #include "param/param.h"
29 struct name2domain_state {
30 struct composite_context *ctx;
31 struct wbsrv_service *service;
33 struct wbsrv_domain *domain;
36 static void name2domain_recv_sid(struct composite_context *ctx);
37 static void name2domain_recv_domain(struct composite_context *ctx);
39 struct composite_context *wb_name2domain_send(TALLOC_CTX *mem_ctx,
40 struct wbsrv_service *service, const char* name)
42 struct composite_context *result, *ctx;
43 struct name2domain_state *state;
44 char *user_dom, *user_name;
45 bool ok;
47 DEBUG(5, ("wb_name2domain_send called\n"));
49 result = composite_create(mem_ctx, service->task->event_ctx);
50 if (!result) return NULL;
52 state = talloc(result, struct name2domain_state);
53 if (composite_nomem(state, result)) return result;
54 state->ctx = result;
55 result->private_data = state;
56 state->service = service;
58 ok = wb_samba3_split_username(state, service->task->lp_ctx, name, &user_dom, &user_name);
59 if(!ok) {
60 composite_error(state->ctx, NT_STATUS_OBJECT_NAME_INVALID);
61 return result;
64 ctx = wb_cmd_lookupname_send(state, service, user_dom, user_name);
65 if (composite_nomem(ctx, state->ctx)) return result;
67 composite_continue(result, ctx, name2domain_recv_sid, state);
68 return result;
71 static void name2domain_recv_sid(struct composite_context *ctx)
73 struct name2domain_state *state =
74 talloc_get_type(ctx->async.private_data,
75 struct name2domain_state);
76 struct wb_sid_object *sid;
78 DEBUG(5, ("name2domain_recv_sid called\n"));
80 state->ctx->status = wb_cmd_lookupname_recv(ctx, state, &sid);
81 if(!composite_is_ok(state->ctx)) return;
83 ctx = wb_sid2domain_send(state, state->service, sid->sid);
85 composite_continue(state->ctx, ctx, name2domain_recv_domain, state);
88 static void name2domain_recv_domain(struct composite_context *ctx)
90 struct name2domain_state *state =
91 talloc_get_type(ctx->async.private_data,
92 struct name2domain_state);
93 struct wbsrv_domain *domain;
95 DEBUG(5, ("name2domain_recv_domain called\n"));
97 state->ctx->status = wb_sid2domain_recv(ctx, &domain);
98 if(!composite_is_ok(state->ctx)) return;
100 state->domain = domain;
102 composite_done(state->ctx);
105 NTSTATUS wb_name2domain_recv(struct composite_context *ctx,
106 struct wbsrv_domain **result)
108 NTSTATUS status = composite_wait(ctx);
110 DEBUG(5, ("wb_name2domain_recv called\n"));
112 if (NT_STATUS_IS_OK(status)) {
113 struct name2domain_state *state =
114 talloc_get_type(ctx->private_data,
115 struct name2domain_state);
116 *result = state->domain;
118 talloc_free(ctx);
119 return status;