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 */
23 #include "libcli/security/dom_sid.h"
25 struct winbindd_getpwnam_state
{
26 struct tevent_context
*ev
;
31 enum lsa_SidType type
;
32 struct winbindd_pw pw
;
35 static void winbindd_getpwnam_lookupname_done(struct tevent_req
*subreq
);
36 static void winbindd_getpwnam_done(struct tevent_req
*subreq
);
38 struct tevent_req
*winbindd_getpwnam_send(TALLOC_CTX
*mem_ctx
,
39 struct tevent_context
*ev
,
40 struct winbindd_cli_state
*cli
,
41 struct winbindd_request
*request
)
43 struct tevent_req
*req
, *subreq
;
44 struct winbindd_getpwnam_state
*state
;
45 char *domuser
, *mapped_user
;
49 req
= tevent_req_create(mem_ctx
, &state
,
50 struct winbindd_getpwnam_state
);
56 /* Ensure null termination */
57 request
->data
.username
[sizeof(request
->data
.username
)-1]='\0';
59 D_NOTICE("[%s (%u)] Winbind external command GETPWNAM start.\n"
60 "Query username '%s'.\n",
62 (unsigned int)cli
->pid
,
63 request
->data
.username
);
65 domuser
= request
->data
.username
;
67 status
= normalize_name_unmap(state
, domuser
, &mapped_user
);
69 if (NT_STATUS_IS_OK(status
)
70 || NT_STATUS_EQUAL(status
, NT_STATUS_FILE_RENAMED
)) {
71 /* normalize_name_unmapped did something */
72 domuser
= mapped_user
;
75 ok
= parse_domain_user(state
,
81 D_WARNING("Could not parse domain user: %s\n", domuser
);
82 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
83 return tevent_req_post(req
, ev
);
86 subreq
= wb_lookupname_send(state
, ev
,
91 if (tevent_req_nomem(subreq
, req
)) {
92 return tevent_req_post(req
, ev
);
94 tevent_req_set_callback(subreq
, winbindd_getpwnam_lookupname_done
,
99 static void winbindd_getpwnam_lookupname_done(struct tevent_req
*subreq
)
101 struct tevent_req
*req
= tevent_req_callback_data(
102 subreq
, struct tevent_req
);
103 struct winbindd_getpwnam_state
*state
= tevent_req_data(
104 req
, struct winbindd_getpwnam_state
);
107 status
= wb_lookupname_recv(subreq
, &state
->sid
, &state
->type
);
109 if (NT_STATUS_IS_OK(status
) && state
->type
== SID_NAME_UNKNOWN
) {
110 status
= NT_STATUS_NONE_MAPPED
;
112 if (tevent_req_nterror(req
, status
)) {
116 subreq
= wb_getpwsid_send(state
, state
->ev
, &state
->sid
, &state
->pw
);
117 if (tevent_req_nomem(subreq
, req
)) {
120 tevent_req_set_callback(subreq
, winbindd_getpwnam_done
, req
);
123 static void winbindd_getpwnam_done(struct tevent_req
*subreq
)
125 struct tevent_req
*req
= tevent_req_callback_data(
126 subreq
, struct tevent_req
);
129 status
= wb_getpwsid_recv(subreq
);
131 if (tevent_req_nterror(req
, status
)) {
134 tevent_req_done(req
);
137 NTSTATUS
winbindd_getpwnam_recv(struct tevent_req
*req
,
138 struct winbindd_response
*response
)
140 struct winbindd_getpwnam_state
*state
= tevent_req_data(
141 req
, struct winbindd_getpwnam_state
);
144 if (tevent_req_is_nterror(req
, &status
)) {
145 struct dom_sid_buf buf
;
146 D_WARNING("Could not convert sid %s: %s\n",
147 dom_sid_str_buf(&state
->sid
, &buf
),
151 response
->data
.pw
= state
->pw
;
153 D_NOTICE("Winbind external command GETPWNAM end.\n"
154 "(name:passwd:uid:gid:gecos:dir:shell)\n"
155 "%s:%s:%u:%u:%s:%s:%s\n",
158 (unsigned int)state
->pw
.pw_uid
,
159 (unsigned int)state
->pw
.pw_gid
,