2 Unix SMB/CIFS implementation.
3 async implementation of WINBINDD_GETGRNAM
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 "libcli/security/dom_sid.h"
24 struct winbindd_getgrnam_state
{
25 struct tevent_context
*ev
;
26 fstring name_namespace
, name_domain
, name_group
;
31 struct db_context
*members
;
34 static void winbindd_getgrnam_lookupname_done(struct tevent_req
*subreq
);
35 static void winbindd_getgrnam_done(struct tevent_req
*subreq
);
37 struct tevent_req
*winbindd_getgrnam_send(TALLOC_CTX
*mem_ctx
,
38 struct tevent_context
*ev
,
39 struct winbindd_cli_state
*cli
,
40 struct winbindd_request
*request
)
42 struct tevent_req
*req
, *subreq
;
43 struct winbindd_getgrnam_state
*state
;
48 req
= tevent_req_create(mem_ctx
, &state
,
49 struct winbindd_getgrnam_state
);
55 /* Ensure null termination */
56 request
->data
.groupname
[sizeof(request
->data
.groupname
)-1]='\0';
58 DBG_NOTICE("[%s (%u)] getgrnam %s\n",
60 (unsigned int)cli
->pid
,
61 request
->data
.groupname
);
63 nt_status
= normalize_name_unmap(state
, request
->data
.groupname
, &tmp
);
64 /* If we didn't map anything in the above call, just reset the
65 tmp pointer to the original string */
66 if (!NT_STATUS_IS_OK(nt_status
) &&
67 !NT_STATUS_EQUAL(nt_status
, NT_STATUS_FILE_RENAMED
))
69 tmp
= request
->data
.groupname
;
72 /* Parse domain and groupname */
74 ok
= parse_domain_user(tmp
,
75 state
->name_namespace
,
79 DBG_INFO("Could not parse domain user: %s\n", tmp
);
80 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
81 return tevent_req_post(req
, ev
);
84 /* if no domain or our local domain and no local tdb group, default to
85 * our local domain for aliases */
87 if ( !*(state
->name_domain
) || strequal(state
->name_domain
,
88 get_global_sam_name()) ) {
89 fstrcpy(state
->name_domain
, get_global_sam_name());
92 subreq
= wb_lookupname_send(state
, ev
,
93 state
->name_namespace
,
97 if (tevent_req_nomem(subreq
, req
)) {
98 return tevent_req_post(req
, ev
);
100 tevent_req_set_callback(subreq
, winbindd_getgrnam_lookupname_done
,
105 static void winbindd_getgrnam_lookupname_done(struct tevent_req
*subreq
)
107 struct tevent_req
*req
= tevent_req_callback_data(
108 subreq
, struct tevent_req
);
109 struct winbindd_getgrnam_state
*state
= tevent_req_data(
110 req
, struct winbindd_getgrnam_state
);
111 enum lsa_SidType type
;
114 status
= wb_lookupname_recv(subreq
, &state
->sid
, &type
);
116 if (tevent_req_nterror(req
, status
)) {
121 case SID_NAME_DOM_GRP
:
123 case SID_NAME_WKN_GRP
:
125 * Also give user types a chance:
126 * These might be user sids mapped to the ID_TYPE_BOTH,
127 * and in that case we should construct a group struct.
130 case SID_NAME_COMPUTER
:
133 tevent_req_nterror(req
, NT_STATUS_NO_SUCH_GROUP
);
137 subreq
= wb_getgrsid_send(state
, state
->ev
, &state
->sid
,
138 lp_winbind_expand_groups());
139 if (tevent_req_nomem(subreq
, req
)) {
142 tevent_req_set_callback(subreq
, winbindd_getgrnam_done
, req
);
145 static void winbindd_getgrnam_done(struct tevent_req
*subreq
)
147 struct tevent_req
*req
= tevent_req_callback_data(
148 subreq
, struct tevent_req
);
149 struct winbindd_getgrnam_state
*state
= tevent_req_data(
150 req
, struct winbindd_getgrnam_state
);
153 status
= wb_getgrsid_recv(subreq
, state
, &state
->domname
, &state
->name
,
154 &state
->gid
, &state
->members
);
156 if (tevent_req_nterror(req
, status
)) {
159 tevent_req_done(req
);
162 NTSTATUS
winbindd_getgrnam_recv(struct tevent_req
*req
,
163 struct winbindd_response
*response
)
165 struct winbindd_getgrnam_state
*state
= tevent_req_data(
166 req
, struct winbindd_getgrnam_state
);
171 if (tevent_req_is_nterror(req
, &status
)) {
172 struct dom_sid_buf sidbuf
;
173 DEBUG(5, ("Could not convert sid %s: %s\n",
174 dom_sid_str_buf(&state
->sid
, &sidbuf
),
179 if (!fill_grent(talloc_tos(), &response
->data
.gr
, state
->domname
,
180 state
->name
, state
->gid
)) {
181 DEBUG(5, ("fill_grent failed\n"));
182 return NT_STATUS_NO_MEMORY
;
185 status
= winbindd_print_groupmembers(state
->members
, response
,
187 if (!NT_STATUS_IS_OK(status
)) {
191 response
->data
.gr
.num_gr_mem
= (uint32_t)num_members
;
193 /* Group membership lives at start of extra data */
195 response
->data
.gr
.gr_mem_ofs
= 0;
196 response
->extra_data
.data
= buf
;
197 response
->length
+= talloc_get_size(response
->extra_data
.data
);