2 Unix SMB/CIFS implementation.
4 Copyright (C) Volker Lendecke 2009
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "librpc/gen_ndr/cli_wbint.h"
24 struct wb_queryuser_state {
26 struct wbint_userinfo info;
29 static void wb_queryuser_done(struct tevent_req *subreq);
31 struct tevent_req *wb_queryuser_send(TALLOC_CTX *mem_ctx,
32 struct tevent_context *ev,
33 const struct dom_sid *user_sid)
35 struct tevent_req *req, *subreq;
36 struct wb_queryuser_state *state;
37 struct winbindd_domain *domain;
38 struct winbind_userinfo info;
41 req = tevent_req_create(mem_ctx, &state, struct wb_queryuser_state);
45 sid_copy(&state->sid, user_sid);
47 domain = find_domain_from_sid_noinit(user_sid);
49 tevent_req_nterror(req, NT_STATUS_NO_SUCH_USER);
50 return tevent_req_post(req, ev);
53 status = wcache_query_user(domain, state, &state->sid, &info);
54 if (NT_STATUS_IS_OK(status)) {
55 state->info.acct_name = info.acct_name;
56 state->info.full_name = info.full_name;
57 state->info.homedir = info.homedir;
58 state->info.shell = info.shell;
59 state->info.primary_gid = info.primary_gid;
60 sid_copy(&state->info.user_sid, &info.user_sid);
61 sid_copy(&state->info.group_sid, &info.group_sid);
63 return tevent_req_post(req, ev);
66 subreq = rpccli_wbint_QueryUser_send(state, ev, domain->child.rpccli,
67 &state->sid, &state->info);
68 if (tevent_req_nomem(subreq, req)) {
69 return tevent_req_post(req, ev);
71 tevent_req_set_callback(subreq, wb_queryuser_done, req);
75 static void wb_queryuser_done(struct tevent_req *subreq)
77 struct tevent_req *req = tevent_req_callback_data(
78 subreq, struct tevent_req);
79 struct wb_queryuser_state *state = tevent_req_data(
80 req, struct wb_queryuser_state);
81 NTSTATUS status, result;
83 status = rpccli_wbint_QueryUser_recv(subreq, state, &result);
85 if (!NT_STATUS_IS_OK(status)) {
86 tevent_req_nterror(req, status);
89 if (!NT_STATUS_IS_OK(result)) {
90 tevent_req_nterror(req, result);
96 NTSTATUS wb_queryuser_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
97 struct winbind_userinfo **pinfo)
99 struct wb_queryuser_state *state = tevent_req_data(
100 req, struct wb_queryuser_state);
101 struct winbind_userinfo *info;
104 if (tevent_req_is_nterror(req, &status)) {
108 info = talloc(mem_ctx, struct winbind_userinfo);
110 return NT_STATUS_NO_MEMORY;
112 info->acct_name = talloc_move(info, &state->info.acct_name);
113 info->full_name = talloc_move(info, &state->info.full_name);
114 info->homedir = talloc_move(info, &state->info.homedir);
115 info->shell = talloc_move(info, &state->info.shell);
116 info->primary_gid = state->info.primary_gid;
117 sid_copy(&info->user_sid, &state->info.user_sid);
118 sid_copy(&info->group_sid, &state->info.group_sid);