2 Unix SMB/CIFS implementation.
3 async implementation of WINBINDD_GETPWNAM
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 "passdb/lookup_sid.h" /* only for LOOKUP_NAME_NO_NSS flag */
24 struct winbindd_getpwnam_state
{
25 struct tevent_context
*ev
;
29 enum lsa_SidType type
;
30 struct winbindd_pw pw
;
33 static void winbindd_getpwnam_lookupname_done(struct tevent_req
*subreq
);
34 static void winbindd_getpwnam_done(struct tevent_req
*subreq
);
36 struct tevent_req
*winbindd_getpwnam_send(TALLOC_CTX
*mem_ctx
,
37 struct tevent_context
*ev
,
38 struct winbindd_cli_state
*cli
,
39 struct winbindd_request
*request
)
41 struct tevent_req
*req
, *subreq
;
42 struct winbindd_getpwnam_state
*state
;
43 char *domuser
, *mapped_user
;
46 req
= tevent_req_create(mem_ctx
, &state
,
47 struct winbindd_getpwnam_state
);
53 /* Ensure null termination */
54 request
->data
.username
[sizeof(request
->data
.username
)-1]='\0';
56 DEBUG(3, ("getpwnam %s\n", request
->data
.username
));
58 domuser
= request
->data
.username
;
60 status
= normalize_name_unmap(state
, domuser
, &mapped_user
);
62 if (NT_STATUS_IS_OK(status
)
63 || NT_STATUS_EQUAL(status
, NT_STATUS_FILE_RENAMED
)) {
64 /* normalize_name_unmapped did something */
65 domuser
= mapped_user
;
68 if (!parse_domain_user(domuser
, state
->domname
, state
->username
)) {
69 DEBUG(5, ("Could not parse domain user: %s\n", domuser
));
70 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
71 return tevent_req_post(req
, ev
);
74 if (lp_winbind_trusted_domains_only()
75 && strequal(state
->domname
, lp_workgroup())) {
76 DEBUG(7,("winbindd_getpwnam: My domain -- "
77 "rejecting getpwnam() for %s\\%s.\n",
78 state
->domname
, state
->username
));
79 tevent_req_nterror(req
, NT_STATUS_NO_SUCH_USER
);
80 return tevent_req_post(req
, ev
);
83 subreq
= wb_lookupname_send(state
, ev
, state
->domname
, state
->username
,
85 if (tevent_req_nomem(subreq
, req
)) {
86 return tevent_req_post(req
, ev
);
88 tevent_req_set_callback(subreq
, winbindd_getpwnam_lookupname_done
,
93 static void winbindd_getpwnam_lookupname_done(struct tevent_req
*subreq
)
95 struct tevent_req
*req
= tevent_req_callback_data(
96 subreq
, struct tevent_req
);
97 struct winbindd_getpwnam_state
*state
= tevent_req_data(
98 req
, struct winbindd_getpwnam_state
);
101 status
= wb_lookupname_recv(subreq
, &state
->sid
, &state
->type
);
103 if (tevent_req_nterror(req
, status
)) {
107 subreq
= wb_getpwsid_send(state
, state
->ev
, &state
->sid
, &state
->pw
);
108 if (tevent_req_nomem(subreq
, req
)) {
111 tevent_req_set_callback(subreq
, winbindd_getpwnam_done
, req
);
114 static void winbindd_getpwnam_done(struct tevent_req
*subreq
)
116 struct tevent_req
*req
= tevent_req_callback_data(
117 subreq
, struct tevent_req
);
120 status
= wb_getpwsid_recv(subreq
);
122 if (tevent_req_nterror(req
, status
)) {
125 tevent_req_done(req
);
128 NTSTATUS
winbindd_getpwnam_recv(struct tevent_req
*req
,
129 struct winbindd_response
*response
)
131 struct winbindd_getpwnam_state
*state
= tevent_req_data(
132 req
, struct winbindd_getpwnam_state
);
135 if (tevent_req_is_nterror(req
, &status
)) {
136 DEBUG(5, ("Could not convert sid %s: %s\n",
137 sid_string_dbg(&state
->sid
), nt_errstr(status
)));
140 response
->data
.pw
= state
->pw
;