s3:loadparm: add reload_registry_shares() - reload only those shares already loaded...
[Samba.git] / source4 / winbind / wb_name2domain.c
blob9da3d43ebcf90587e5603670d32187183bfc91f1
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"
28 struct name2domain_state {
29 struct composite_context *ctx;
30 struct wbsrv_service *service;
32 struct wbsrv_domain *domain;
35 static void name2domain_recv_sid(struct composite_context *ctx);
36 static void name2domain_recv_domain(struct composite_context *ctx);
38 struct composite_context *wb_name2domain_send(TALLOC_CTX *mem_ctx,
39 struct wbsrv_service *service, const char* name)
41 struct composite_context *result, *ctx;
42 struct name2domain_state *state;
43 char *user_dom, *user_name;
44 bool ok;
46 DEBUG(5, ("wb_name2domain_send called\n"));
48 result = composite_create(mem_ctx, service->task->event_ctx);
49 if (!result) return NULL;
51 state = talloc(result, struct name2domain_state);
52 if (composite_nomem(state, result)) return result;
53 state->ctx = result;
54 result->private_data = state;
55 state->service = service;
57 ok = wb_samba3_split_username(state, service->task->lp_ctx, name, &user_dom, &user_name);
58 if(!ok) {
59 composite_error(state->ctx, NT_STATUS_OBJECT_NAME_INVALID);
60 return result;
63 ctx = wb_cmd_lookupname_send(state, service, user_dom, user_name);
64 if (composite_nomem(ctx, state->ctx)) return result;
66 composite_continue(result, ctx, name2domain_recv_sid, state);
67 return result;
70 static void name2domain_recv_sid(struct composite_context *ctx)
72 struct name2domain_state *state =
73 talloc_get_type(ctx->async.private_data,
74 struct name2domain_state);
75 struct wb_sid_object *sid;
77 DEBUG(5, ("name2domain_recv_sid called\n"));
79 state->ctx->status = wb_cmd_lookupname_recv(ctx, state, &sid);
80 if(!composite_is_ok(state->ctx)) return;
82 ctx = wb_sid2domain_send(state, state->service, sid->sid);
84 composite_continue(state->ctx, ctx, name2domain_recv_domain, state);
87 static void name2domain_recv_domain(struct composite_context *ctx)
89 struct name2domain_state *state =
90 talloc_get_type(ctx->async.private_data,
91 struct name2domain_state);
92 struct wbsrv_domain *domain;
94 DEBUG(5, ("name2domain_recv_domain called\n"));
96 state->ctx->status = wb_sid2domain_recv(ctx, &domain);
97 if(!composite_is_ok(state->ctx)) return;
99 state->domain = domain;
101 composite_done(state->ctx);
104 NTSTATUS wb_name2domain_recv(struct composite_context *ctx,
105 struct wbsrv_domain **result)
107 NTSTATUS status = composite_wait(ctx);
109 DEBUG(5, ("wb_name2domain_recv called\n"));
111 if (NT_STATUS_IS_OK(status)) {
112 struct name2domain_state *state =
113 talloc_get_type(ctx->private_data,
114 struct name2domain_state);
115 *result = state->domain;
117 talloc_free(ctx);
118 return status;