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"
24 #include "lib/util/string_wrappers.h"
25 #include "source3/lib/substitute.h"
27 struct wb_getpwsid_state
{
28 struct tevent_context
*ev
;
30 struct wbint_userinfo
*userinfo
;
31 struct winbindd_pw
*pw
;
34 static void wb_getpwsid_queryuser_done(struct tevent_req
*subreq
);
36 struct tevent_req
*wb_getpwsid_send(TALLOC_CTX
*mem_ctx
,
37 struct tevent_context
*ev
,
38 const struct dom_sid
*user_sid
,
39 struct winbindd_pw
*pw
)
41 struct tevent_req
*req
, *subreq
;
42 struct wb_getpwsid_state
*state
;
43 struct dom_sid_buf buf
;
45 req
= tevent_req_create(mem_ctx
, &state
, struct wb_getpwsid_state
);
49 D_INFO("WB command getpwsid start.\nQuery user SID %s.\n", dom_sid_str_buf(user_sid
, &buf
));
50 sid_copy(&state
->sid
, user_sid
);
54 if (dom_sid_in_domain(&global_sid_Unix_Users
, user_sid
)) {
55 /* unmapped Unix users must be resolved locally */
56 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
57 return tevent_req_post(req
, ev
);
60 subreq
= wb_queryuser_send(state
, ev
, &state
->sid
);
61 if (tevent_req_nomem(subreq
, req
)) {
62 return tevent_req_post(req
, ev
);
64 tevent_req_set_callback(subreq
, wb_getpwsid_queryuser_done
, req
);
68 static void wb_getpwsid_queryuser_done(struct tevent_req
*subreq
)
70 struct tevent_req
*req
= tevent_req_callback_data(
71 subreq
, struct tevent_req
);
72 struct wb_getpwsid_state
*state
= tevent_req_data(
73 req
, struct wb_getpwsid_state
);
74 struct winbindd_pw
*pw
= state
->pw
;
75 struct wbint_userinfo
*info
;
77 const char *output_username
= NULL
;
78 char *mapped_name
= NULL
;
82 status
= wb_queryuser_recv(subreq
, state
, &state
->userinfo
);
84 if (tevent_req_nterror(req
, status
)) {
87 info
= state
->userinfo
;
89 pw
->pw_uid
= info
->uid
;
90 pw
->pw_gid
= info
->primary_gid
;
92 fstrcpy(acct_name
, info
->acct_name
);
93 if (!strlower_m(acct_name
)) {
94 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
100 * This function should be called in 'idmap winbind child'. It shouldn't
101 * be a blocking call, but for this we need to add a new function for
102 * winbind.idl. This is a fix which can be backported for now.
104 status
= normalize_name_map(state
,
108 if (NT_STATUS_IS_OK(status
) ||
109 NT_STATUS_EQUAL(status
, NT_STATUS_FILE_RENAMED
)) {
110 fstrcpy(acct_name
, mapped_name
);
112 output_username
= fill_domain_username_talloc(state
,
116 if (output_username
== NULL
) {
117 tevent_req_nterror(req
, NT_STATUS_NO_MEMORY
);
121 strlcpy(pw
->pw_name
, output_username
, sizeof(pw
->pw_name
));
123 strlcpy(pw
->pw_gecos
, info
->full_name
? info
->full_name
: "",
124 sizeof(pw
->pw_gecos
));
126 tmp
= talloc_sub_specified(
127 state
, info
->homedir
, acct_name
,
128 info
->primary_group_name
, info
->domain_name
,
129 pw
->pw_uid
, pw
->pw_gid
);
130 if (tevent_req_nomem(tmp
, req
)) {
133 strlcpy(pw
->pw_dir
, tmp
, sizeof(pw
->pw_dir
));
136 tmp
= talloc_sub_specified(
137 state
, info
->shell
, acct_name
,
138 info
->primary_group_name
, info
->domain_name
,
139 pw
->pw_uid
, pw
->pw_gid
);
140 if (tevent_req_nomem(tmp
, req
)) {
143 strlcpy(pw
->pw_shell
, tmp
, sizeof(pw
->pw_shell
));
146 strlcpy(pw
->pw_passwd
, "*", sizeof(pw
->pw_passwd
));
148 tevent_req_done(req
);
151 NTSTATUS
wb_getpwsid_recv(struct tevent_req
*req
)
153 NTSTATUS status
= tevent_req_simple_recv_ntstatus(req
);
154 D_INFO("WB command getpwsid end.\nReturn status %s.\n", nt_errstr(status
));