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_fill_pwent_state
{
25 struct tevent_context
*ev
;
26 struct wbint_userinfo
*info
;
27 struct winbindd_pw
*pw
;
30 static void wb_fill_pwent_sid2uid_done(struct tevent_req
*subreq
);
31 static void wb_fill_pwent_sid2gid_done(struct tevent_req
*subreq
);
33 struct tevent_req
*wb_fill_pwent_send(TALLOC_CTX
*mem_ctx
,
34 struct tevent_context
*ev
,
35 struct wbint_userinfo
*info
,
36 struct winbindd_pw
*pw
)
38 struct tevent_req
*req
, *subreq
;
39 struct wb_fill_pwent_state
*state
;
41 req
= tevent_req_create(mem_ctx
, &state
, struct wb_fill_pwent_state
);
49 subreq
= wb_sid2uid_send(state
, state
->ev
, &state
->info
->user_sid
);
50 if (tevent_req_nomem(subreq
, req
)) {
51 return tevent_req_post(req
, ev
);
53 tevent_req_set_callback(subreq
, wb_fill_pwent_sid2uid_done
, req
);
57 static void wb_fill_pwent_sid2uid_done(struct tevent_req
*subreq
)
59 struct tevent_req
*req
= tevent_req_callback_data(
60 subreq
, struct tevent_req
);
61 struct wb_fill_pwent_state
*state
= tevent_req_data(
62 req
, struct wb_fill_pwent_state
);
65 status
= wb_sid2uid_recv(subreq
, &state
->pw
->pw_uid
);
67 if (!NT_STATUS_IS_OK(status
)) {
68 tevent_req_nterror(req
, status
);
72 subreq
= wb_sid2gid_send(state
, state
->ev
, &state
->info
->group_sid
);
73 if (tevent_req_nomem(subreq
, req
)) {
76 tevent_req_set_callback(subreq
, wb_fill_pwent_sid2gid_done
, req
);
79 static void wb_fill_pwent_sid2gid_done(struct tevent_req
*subreq
)
81 struct tevent_req
*req
= tevent_req_callback_data(
82 subreq
, struct tevent_req
);
83 struct wb_fill_pwent_state
*state
= tevent_req_data(
84 req
, struct wb_fill_pwent_state
);
85 struct winbindd_domain
*domain
;
87 fstring user_name
, output_username
;
88 char *mapped_name
= NULL
;
91 status
= wb_sid2gid_recv(subreq
, &state
->pw
->pw_gid
);
93 if (!NT_STATUS_IS_OK(status
)) {
94 tevent_req_nterror(req
, status
);
98 domain
= find_domain_from_sid_noinit(&state
->info
->user_sid
);
100 tevent_req_nterror(req
, NT_STATUS_NO_SUCH_USER
);
103 dom_name
= domain
->name
;
107 fstrcpy(user_name
, state
->info
->acct_name
);
108 strlower_m(user_name
);
109 status
= normalize_name_map(state
, domain
, user_name
, &mapped_name
);
111 /* Basic removal of whitespace */
112 if (NT_STATUS_IS_OK(status
)) {
113 fill_domain_username(output_username
, dom_name
, mapped_name
,
116 /* Complete name replacement */
117 else if (NT_STATUS_EQUAL(status
, NT_STATUS_FILE_RENAMED
)) {
118 fstrcpy(output_username
, mapped_name
);
120 /* No change at all */
122 fill_domain_username(output_username
, dom_name
, user_name
,
126 fstrcpy(state
->pw
->pw_name
, output_username
);
127 fstrcpy(state
->pw
->pw_gecos
, state
->info
->full_name
);
129 /* Home directory and shell */
131 if (!fillup_pw_field(lp_template_homedir(), user_name
, dom_name
,
132 state
->pw
->pw_uid
, state
->pw
->pw_gid
,
133 state
->info
->homedir
, state
->pw
->pw_dir
)) {
134 tevent_req_nterror(req
, NT_STATUS_NO_SUCH_USER
);
138 if (!fillup_pw_field(lp_template_shell(), user_name
, dom_name
,
139 state
->pw
->pw_uid
, state
->pw
->pw_gid
,
140 state
->info
->shell
, state
->pw
->pw_shell
)) {
141 tevent_req_nterror(req
, NT_STATUS_NO_SUCH_USER
);
145 /* Password - set to "*" as we can't generate anything useful here.
146 Authentication can be done using the pam_winbind module. */
148 fstrcpy(state
->pw
->pw_passwd
, "*");
149 tevent_req_done(req
);
152 NTSTATUS
wb_fill_pwent_recv(struct tevent_req
*req
)
154 return tevent_req_simple_recv_ntstatus(req
);