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/ndr_winbind_c.h"
23 #include "../libcli/security/security.h"
25 struct wb_getpwsid_state {
26 struct tevent_context *ev;
28 struct wbint_userinfo *userinfo;
29 struct winbindd_pw *pw;
32 static void wb_getpwsid_queryuser_done(struct tevent_req *subreq);
34 struct tevent_req *wb_getpwsid_send(TALLOC_CTX *mem_ctx,
35 struct tevent_context *ev,
36 const struct dom_sid *user_sid,
37 struct winbindd_pw *pw)
39 struct tevent_req *req, *subreq;
40 struct wb_getpwsid_state *state;
42 req = tevent_req_create(mem_ctx, &state, struct wb_getpwsid_state);
46 sid_copy(&state->sid, user_sid);
50 subreq = wb_queryuser_send(state, ev, &state->sid);
51 if (tevent_req_nomem(subreq, req)) {
52 return tevent_req_post(req, ev);
54 tevent_req_set_callback(subreq, wb_getpwsid_queryuser_done, req);
58 static void wb_getpwsid_queryuser_done(struct tevent_req *subreq)
60 struct tevent_req *req = tevent_req_callback_data(
61 subreq, struct tevent_req);
62 struct wb_getpwsid_state *state = tevent_req_data(
63 req, struct wb_getpwsid_state);
64 struct winbindd_pw *pw = state->pw;
65 struct wbint_userinfo *info;
66 fstring acct_name, output_username;
70 status = wb_queryuser_recv(subreq, state, &state->userinfo);
72 if (tevent_req_nterror(req, status)) {
75 info = state->userinfo;
77 pw->pw_uid = info->uid;
78 pw->pw_gid = info->primary_gid;
80 fstrcpy(acct_name, info->acct_name);
81 if (!strlower_m(acct_name)) {
82 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
86 fill_domain_username(output_username, info->domain_name,
88 strlcpy(pw->pw_name, output_username, sizeof(pw->pw_name));
90 strlcpy(pw->pw_gecos, info->full_name ? info->full_name : "",
91 sizeof(pw->pw_gecos));
93 tmp = talloc_sub_specified(
94 state, info->homedir, acct_name,
95 info->primary_group_name, info->domain_name,
96 pw->pw_uid, pw->pw_gid);
97 if (tevent_req_nomem(tmp, req)) {
100 strlcpy(pw->pw_dir, tmp, sizeof(pw->pw_dir));
103 tmp = talloc_sub_specified(
104 state, info->shell, info->acct_name,
105 info->primary_group_name, info->domain_name,
106 pw->pw_uid, pw->pw_gid);
107 if (tevent_req_nomem(tmp, req)) {
110 strlcpy(pw->pw_shell, tmp, sizeof(pw->pw_shell));
113 strlcpy(pw->pw_passwd, "*", sizeof(pw->pw_passwd));
115 tevent_req_done(req);
118 NTSTATUS wb_getpwsid_recv(struct tevent_req *req)
120 return tevent_req_simple_recv_ntstatus(req);