2 Unix SMB/CIFS implementation.
4 In-Child server implementation of the routines defined in wbint.idl
6 Copyright (C) Volker Lendecke 2009
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "winbindd/winbindd.h"
24 #include "winbindd/winbindd_proto.h"
25 #include "librpc/gen_ndr/srv_wbint.h"
27 void _wbint_Ping(pipes_struct *p, struct wbint_Ping *r)
29 *r->out.out_data = r->in.in_data;
32 NTSTATUS _wbint_LookupSid(pipes_struct *p, struct wbint_LookupSid *r)
34 struct winbindd_domain *domain = wb_child_domain();
37 enum lsa_SidType type;
41 return NT_STATUS_REQUEST_NOT_ACCEPTED;
44 status = domain->methods->sid_to_name(domain, p->mem_ctx, r->in.sid,
45 &dom_name, &name, &type);
46 if (!NT_STATUS_IS_OK(status)) {
50 *r->out.domain = dom_name;
56 NTSTATUS _wbint_LookupName(pipes_struct *p, struct wbint_LookupName *r)
58 struct winbindd_domain *domain = wb_child_domain();
61 return NT_STATUS_REQUEST_NOT_ACCEPTED;
64 return domain->methods->name_to_sid(
65 domain, p->mem_ctx, r->in.domain, r->in.name, r->in.flags,
66 r->out.sid, r->out.type);
69 NTSTATUS _wbint_Sid2Uid(pipes_struct *p, struct wbint_Sid2Uid *r)
74 status = idmap_sid_to_uid(r->in.dom_name ? r->in.dom_name : "",
76 if (!NT_STATUS_IS_OK(status)) {
83 NTSTATUS _wbint_Sid2Gid(pipes_struct *p, struct wbint_Sid2Gid *r)
88 status = idmap_sid_to_gid(r->in.dom_name ? r->in.dom_name : "",
90 if (!NT_STATUS_IS_OK(status)) {
97 NTSTATUS _wbint_Uid2Sid(pipes_struct *p, struct wbint_Uid2Sid *r)
99 return idmap_uid_to_sid(r->in.dom_name ? r->in.dom_name : "",
100 r->out.sid, r->in.uid);
103 NTSTATUS _wbint_Gid2Sid(pipes_struct *p, struct wbint_Gid2Sid *r)
105 return idmap_gid_to_sid(r->in.dom_name ? r->in.dom_name : "",
106 r->out.sid, r->in.gid);
109 NTSTATUS _wbint_QueryUser(pipes_struct *p, struct wbint_QueryUser *r)
111 struct winbindd_domain *domain = wb_child_domain();
113 if (domain == NULL) {
114 return NT_STATUS_REQUEST_NOT_ACCEPTED;
117 return domain->methods->query_user(domain, p->mem_ctx, r->in.sid,
121 NTSTATUS _wbint_LookupUserAliases(pipes_struct *p,
122 struct wbint_LookupUserAliases *r)
124 struct winbindd_domain *domain = wb_child_domain();
126 if (domain == NULL) {
127 return NT_STATUS_REQUEST_NOT_ACCEPTED;
130 return domain->methods->lookup_useraliases(
131 domain, p->mem_ctx, r->in.sids->num_sids, r->in.sids->sids,
132 &r->out.rids->num_rids, &r->out.rids->rids);
135 NTSTATUS _wbint_LookupUserGroups(pipes_struct *p,
136 struct wbint_LookupUserGroups *r)
138 struct winbindd_domain *domain = wb_child_domain();
140 if (domain == NULL) {
141 return NT_STATUS_REQUEST_NOT_ACCEPTED;
144 return domain->methods->lookup_usergroups(
145 domain, p->mem_ctx, r->in.sid,
146 &r->out.sids->num_sids, &r->out.sids->sids);
149 NTSTATUS _wbint_QuerySequenceNumber(pipes_struct *p,
150 struct wbint_QuerySequenceNumber *r)
152 struct winbindd_domain *domain = wb_child_domain();
154 if (domain == NULL) {
155 return NT_STATUS_REQUEST_NOT_ACCEPTED;
158 return domain->methods->sequence_number(domain, r->out.sequence);
161 NTSTATUS _wbint_LookupGroupMembers(pipes_struct *p,
162 struct wbint_LookupGroupMembers *r)
164 struct winbindd_domain *domain = wb_child_domain();
165 uint32_t i, num_names;
166 struct dom_sid *sid_mem;
168 uint32_t *name_types;
171 if (domain == NULL) {
172 return NT_STATUS_REQUEST_NOT_ACCEPTED;
175 status = domain->methods->lookup_groupmem(
176 domain, p->mem_ctx, r->in.sid, r->in.type,
177 &num_names, &sid_mem, &names, &name_types);
178 if (!NT_STATUS_IS_OK(status)) {
182 r->out.members->num_principals = num_names;
183 r->out.members->principals = talloc_array(
184 r->out.members, struct wbint_Principal, num_names);
185 if (r->out.members->principals == NULL) {
186 return NT_STATUS_NO_MEMORY;
189 for (i=0; i<num_names; i++) {
190 struct wbint_Principal *m = &r->out.members->principals[i];
191 sid_copy(&m->sid, &sid_mem[i]);
192 m->name = talloc_move(r->out.members->principals, &names[i]);
193 m->type = (enum lsa_SidType)name_types[i];
199 NTSTATUS _wbint_QueryUserList(pipes_struct *p, struct wbint_QueryUserList *r)
201 struct winbindd_domain *domain = wb_child_domain();
203 if (domain == NULL) {
204 return NT_STATUS_REQUEST_NOT_ACCEPTED;
207 return domain->methods->query_user_list(
208 domain, p->mem_ctx, &r->out.users->num_userinfos,
209 &r->out.users->userinfos);
212 NTSTATUS _wbint_DsGetDcName(pipes_struct *p, struct wbint_DsGetDcName *r)
214 struct winbindd_domain *domain = wb_child_domain();
215 struct rpc_pipe_client *netlogon_pipe;
216 struct netr_DsRGetDCNameInfo *dc_info;
219 unsigned int orig_timeout;
221 if (domain == NULL) {
222 return dsgetdcname(p->mem_ctx, winbind_messaging_context(),
223 r->in.domain_name, r->in.domain_guid,
224 r->in.site_name ? r->in.site_name : "",
229 status = cm_connect_netlogon(domain, &netlogon_pipe);
231 if (!NT_STATUS_IS_OK(status)) {
232 DEBUG(10, ("Can't contact the NETLOGON pipe\n"));
236 /* This call can take a long time - allow the server to time out.
237 35 seconds should do it. */
239 orig_timeout = rpccli_set_timeout(netlogon_pipe, 35000);
241 if (domain->active_directory) {
242 status = rpccli_netr_DsRGetDCName(
243 netlogon_pipe, p->mem_ctx, domain->dcname,
244 r->in.domain_name, NULL, r->in.domain_guid,
245 r->in.flags, r->out.dc_info, &werr);
246 if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(werr)) {
252 * Fallback to less capable methods
255 dc_info = talloc_zero(r->out.dc_info, struct netr_DsRGetDCNameInfo);
256 if (dc_info == NULL) {
257 status = NT_STATUS_NO_MEMORY;
261 if (r->in.flags & DS_PDC_REQUIRED) {
262 status = rpccli_netr_GetDcName(
263 netlogon_pipe, p->mem_ctx, domain->dcname,
264 r->in.domain_name, &dc_info->dc_unc, &werr);
266 status = rpccli_netr_GetAnyDCName(
267 netlogon_pipe, p->mem_ctx, domain->dcname,
268 r->in.domain_name, &dc_info->dc_unc, &werr);
271 if (!NT_STATUS_IS_OK(status)) {
272 DEBUG(10, ("rpccli_netr_Get[Any]DCName failed: %s\n",
276 if (!W_ERROR_IS_OK(werr)) {
277 DEBUG(10, ("rpccli_netr_Get[Any]DCName failed: %s\n",
279 status = werror_to_ntstatus(werr);
283 *r->out.dc_info = dc_info;
284 status = NT_STATUS_OK;
287 /* And restore our original timeout. */
288 rpccli_set_timeout(netlogon_pipe, orig_timeout);
293 NTSTATUS _wbint_LookupRids(pipes_struct *p, struct wbint_LookupRids *r)
295 struct winbindd_domain *domain = wb_child_domain();
298 enum lsa_SidType *types;
299 struct wbint_Principal *result;
303 if (domain == NULL) {
304 return NT_STATUS_REQUEST_NOT_ACCEPTED;
307 status = domain->methods->rids_to_names(
308 domain, talloc_tos(), &domain->sid, r->in.rids->rids,
309 r->in.rids->num_rids, &domain_name, &names, &types);
310 if (!NT_STATUS_IS_OK(status)) {
314 result = talloc_array(p->mem_ctx, struct wbint_Principal,
315 r->in.rids->num_rids);
316 if (result == NULL) {
317 return NT_STATUS_NO_MEMORY;
320 for (i=0; i<r->in.rids->num_rids; i++) {
321 sid_compose(&result[i].sid, &domain->sid, r->in.rids->rids[i]);
322 result[i].type = types[i];
323 result[i].name = talloc_move(result, &names[i]);
328 r->out.names->num_principals = r->in.rids->num_rids;
329 r->out.names->principals = result;