1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 |
|
---|
4 | Async helpers for blocking functions
|
---|
5 |
|
---|
6 | Copyright (C) Volker Lendecke 2005
|
---|
7 | Copyright (C) Gerald Carter 2006
|
---|
8 |
|
---|
9 | The helpers always consist of three functions:
|
---|
10 |
|
---|
11 | * A request setup function that takes the necessary parameters together
|
---|
12 | with a continuation function that is to be called upon completion
|
---|
13 |
|
---|
14 | * A private continuation function that is internal only. This is to be
|
---|
15 | called by the lower-level functions in do_async(). Its only task is to
|
---|
16 | properly call the continuation function named above.
|
---|
17 |
|
---|
18 | * A worker function that is called inside the appropriate child process.
|
---|
19 |
|
---|
20 | This program is free software; you can redistribute it and/or modify
|
---|
21 | it under the terms of the GNU General Public License as published by
|
---|
22 | the Free Software Foundation; either version 2 of the License, or
|
---|
23 | (at your option) any later version.
|
---|
24 |
|
---|
25 | This program is distributed in the hope that it will be useful,
|
---|
26 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
27 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
28 | GNU General Public License for more details.
|
---|
29 |
|
---|
30 | You should have received a copy of the GNU General Public License
|
---|
31 | along with this program; if not, write to the Free Software
|
---|
32 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
33 | */
|
---|
34 |
|
---|
35 | #include "includes.h"
|
---|
36 | #include "winbindd.h"
|
---|
37 |
|
---|
38 | #undef DBGC_CLASS
|
---|
39 | #define DBGC_CLASS DBGC_WINBIND
|
---|
40 |
|
---|
41 | struct do_async_state {
|
---|
42 | TALLOC_CTX *mem_ctx;
|
---|
43 | struct winbindd_request request;
|
---|
44 | struct winbindd_response response;
|
---|
45 | void (*cont)(TALLOC_CTX *mem_ctx,
|
---|
46 | BOOL success,
|
---|
47 | struct winbindd_response *response,
|
---|
48 | void *c, void *private_data);
|
---|
49 | void *c, *private_data;
|
---|
50 | };
|
---|
51 |
|
---|
52 | static void do_async_recv(void *private_data, BOOL success)
|
---|
53 | {
|
---|
54 | struct do_async_state *state =
|
---|
55 | talloc_get_type_abort(private_data, struct do_async_state);
|
---|
56 |
|
---|
57 | state->cont(state->mem_ctx, success, &state->response,
|
---|
58 | state->c, state->private_data);
|
---|
59 | }
|
---|
60 |
|
---|
61 | static void do_async(TALLOC_CTX *mem_ctx, struct winbindd_child *child,
|
---|
62 | const struct winbindd_request *request,
|
---|
63 | void (*cont)(TALLOC_CTX *mem_ctx, BOOL success,
|
---|
64 | struct winbindd_response *response,
|
---|
65 | void *c, void *private_data),
|
---|
66 | void *c, void *private_data)
|
---|
67 | {
|
---|
68 | struct do_async_state *state;
|
---|
69 |
|
---|
70 | state = TALLOC_ZERO_P(mem_ctx, struct do_async_state);
|
---|
71 | if (state == NULL) {
|
---|
72 | DEBUG(0, ("talloc failed\n"));
|
---|
73 | cont(mem_ctx, False, NULL, c, private_data);
|
---|
74 | return;
|
---|
75 | }
|
---|
76 |
|
---|
77 | state->mem_ctx = mem_ctx;
|
---|
78 | state->request = *request;
|
---|
79 | state->request.length = sizeof(state->request);
|
---|
80 | state->cont = cont;
|
---|
81 | state->c = c;
|
---|
82 | state->private_data = private_data;
|
---|
83 |
|
---|
84 | async_request(mem_ctx, child, &state->request,
|
---|
85 | &state->response, do_async_recv, state);
|
---|
86 | }
|
---|
87 |
|
---|
88 | void do_async_domain(TALLOC_CTX *mem_ctx, struct winbindd_domain *domain,
|
---|
89 | const struct winbindd_request *request,
|
---|
90 | void (*cont)(TALLOC_CTX *mem_ctx, BOOL success,
|
---|
91 | struct winbindd_response *response,
|
---|
92 | void *c, void *private_data),
|
---|
93 | void *c, void *private_data)
|
---|
94 | {
|
---|
95 | struct do_async_state *state;
|
---|
96 |
|
---|
97 | state = TALLOC_ZERO_P(mem_ctx, struct do_async_state);
|
---|
98 | if (state == NULL) {
|
---|
99 | DEBUG(0, ("talloc failed\n"));
|
---|
100 | cont(mem_ctx, False, NULL, c, private_data);
|
---|
101 | return;
|
---|
102 | }
|
---|
103 |
|
---|
104 | state->mem_ctx = mem_ctx;
|
---|
105 | state->request = *request;
|
---|
106 | state->request.length = sizeof(state->request);
|
---|
107 | state->cont = cont;
|
---|
108 | state->c = c;
|
---|
109 | state->private_data = private_data;
|
---|
110 |
|
---|
111 | async_domain_request(mem_ctx, domain, &state->request,
|
---|
112 | &state->response, do_async_recv, state);
|
---|
113 | }
|
---|
114 |
|
---|
115 | static void winbindd_set_mapping_recv(TALLOC_CTX *mem_ctx, BOOL success,
|
---|
116 | struct winbindd_response *response,
|
---|
117 | void *c, void *private_data)
|
---|
118 | {
|
---|
119 | void (*cont)(void *priv, BOOL succ) = (void (*)(void *, BOOL))c;
|
---|
120 |
|
---|
121 | if (!success) {
|
---|
122 | DEBUG(5, ("Could not trigger idmap_set_mapping\n"));
|
---|
123 | cont(private_data, False);
|
---|
124 | return;
|
---|
125 | }
|
---|
126 |
|
---|
127 | if (response->result != WINBINDD_OK) {
|
---|
128 | DEBUG(5, ("idmap_set_mapping returned an error\n"));
|
---|
129 | cont(private_data, False);
|
---|
130 | return;
|
---|
131 | }
|
---|
132 |
|
---|
133 | cont(private_data, True);
|
---|
134 | }
|
---|
135 |
|
---|
136 | void winbindd_set_mapping_async(TALLOC_CTX *mem_ctx, const struct id_map *map,
|
---|
137 | void (*cont)(void *private_data, BOOL success),
|
---|
138 | void *private_data)
|
---|
139 | {
|
---|
140 | struct winbindd_request request;
|
---|
141 | ZERO_STRUCT(request);
|
---|
142 | request.cmd = WINBINDD_DUAL_SET_MAPPING;
|
---|
143 | request.data.dual_idmapset.id = map->xid.id;
|
---|
144 | request.data.dual_idmapset.type = map->xid.type;
|
---|
145 | sid_to_string(request.data.dual_idmapset.sid, map->sid);
|
---|
146 |
|
---|
147 | do_async(mem_ctx, idmap_child(), &request, winbindd_set_mapping_recv,
|
---|
148 | (void *)cont, private_data);
|
---|
149 | }
|
---|
150 |
|
---|
151 | enum winbindd_result winbindd_dual_set_mapping(struct winbindd_domain *domain,
|
---|
152 | struct winbindd_cli_state *state)
|
---|
153 | {
|
---|
154 | struct id_map map;
|
---|
155 | DOM_SID sid;
|
---|
156 | NTSTATUS result;
|
---|
157 |
|
---|
158 | DEBUG(3, ("[%5lu]: dual_idmapset\n", (unsigned long)state->pid));
|
---|
159 |
|
---|
160 | if (!string_to_sid(&sid, state->request.data.dual_idmapset.sid))
|
---|
161 | return WINBINDD_ERROR;
|
---|
162 |
|
---|
163 | map.sid = &sid;
|
---|
164 | map.xid.id = state->request.data.dual_idmapset.id;
|
---|
165 | map.xid.type = state->request.data.dual_idmapset.type;
|
---|
166 | map.status = ID_MAPPED;
|
---|
167 |
|
---|
168 | result = idmap_set_mapping(&map);
|
---|
169 | return NT_STATUS_IS_OK(result) ? WINBINDD_OK : WINBINDD_ERROR;
|
---|
170 | }
|
---|
171 |
|
---|
172 | static void winbindd_set_hwm_recv(TALLOC_CTX *mem_ctx, BOOL success,
|
---|
173 | struct winbindd_response *response,
|
---|
174 | void *c, void *private_data)
|
---|
175 | {
|
---|
176 | void (*cont)(void *priv, BOOL succ) = (void (*)(void *, BOOL))c;
|
---|
177 |
|
---|
178 | if (!success) {
|
---|
179 | DEBUG(5, ("Could not trigger idmap_set_hwm\n"));
|
---|
180 | cont(private_data, False);
|
---|
181 | return;
|
---|
182 | }
|
---|
183 |
|
---|
184 | if (response->result != WINBINDD_OK) {
|
---|
185 | DEBUG(5, ("idmap_set_hwm returned an error\n"));
|
---|
186 | cont(private_data, False);
|
---|
187 | return;
|
---|
188 | }
|
---|
189 |
|
---|
190 | cont(private_data, True);
|
---|
191 | }
|
---|
192 |
|
---|
193 | void winbindd_set_hwm_async(TALLOC_CTX *mem_ctx, const struct unixid *xid,
|
---|
194 | void (*cont)(void *private_data, BOOL success),
|
---|
195 | void *private_data)
|
---|
196 | {
|
---|
197 | struct winbindd_request request;
|
---|
198 | ZERO_STRUCT(request);
|
---|
199 | request.cmd = WINBINDD_DUAL_SET_HWM;
|
---|
200 | request.data.dual_idmapset.id = xid->id;
|
---|
201 | request.data.dual_idmapset.type = xid->type;
|
---|
202 |
|
---|
203 | do_async(mem_ctx, idmap_child(), &request, winbindd_set_hwm_recv,
|
---|
204 | (void *)cont, private_data);
|
---|
205 | }
|
---|
206 |
|
---|
207 | enum winbindd_result winbindd_dual_set_hwm(struct winbindd_domain *domain,
|
---|
208 | struct winbindd_cli_state *state)
|
---|
209 | {
|
---|
210 | struct unixid xid;
|
---|
211 | NTSTATUS result;
|
---|
212 |
|
---|
213 | DEBUG(3, ("[%5lu]: dual_set_hwm\n", (unsigned long)state->pid));
|
---|
214 |
|
---|
215 | xid.id = state->request.data.dual_idmapset.id;
|
---|
216 | xid.type = state->request.data.dual_idmapset.type;
|
---|
217 |
|
---|
218 | switch (xid.type) {
|
---|
219 | case ID_TYPE_UID:
|
---|
220 | result = idmap_set_uid_hwm(&xid);
|
---|
221 | break;
|
---|
222 | case ID_TYPE_GID:
|
---|
223 | result = idmap_set_gid_hwm(&xid);
|
---|
224 | break;
|
---|
225 | default:
|
---|
226 | return WINBINDD_ERROR;
|
---|
227 | }
|
---|
228 | return NT_STATUS_IS_OK(result) ? WINBINDD_OK : WINBINDD_ERROR;
|
---|
229 | }
|
---|
230 |
|
---|
231 | static void winbindd_sids2xids_recv(TALLOC_CTX *mem_ctx, BOOL success,
|
---|
232 | struct winbindd_response *response,
|
---|
233 | void *c, void *private_data)
|
---|
234 | {
|
---|
235 | void (*cont)(void *priv, BOOL succ, void *, int) =
|
---|
236 | (void (*)(void *, BOOL, void *, int))c;
|
---|
237 |
|
---|
238 | if (!success) {
|
---|
239 | DEBUG(5, ("Could not trigger sids2xids\n"));
|
---|
240 | cont(private_data, False, NULL, 0);
|
---|
241 | return;
|
---|
242 | }
|
---|
243 |
|
---|
244 | if (response->result != WINBINDD_OK) {
|
---|
245 | DEBUG(5, ("sids2xids returned an error\n"));
|
---|
246 | cont(private_data, False, NULL, 0);
|
---|
247 | return;
|
---|
248 | }
|
---|
249 |
|
---|
250 | cont(private_data, True, response->extra_data.data, response->length - sizeof(response));
|
---|
251 | }
|
---|
252 |
|
---|
253 | void winbindd_sids2xids_async(TALLOC_CTX *mem_ctx, void *sids, int size,
|
---|
254 | void (*cont)(void *private_data, BOOL success, void *data, int len),
|
---|
255 | void *private_data)
|
---|
256 | {
|
---|
257 | struct winbindd_request request;
|
---|
258 | ZERO_STRUCT(request);
|
---|
259 | request.cmd = WINBINDD_DUAL_SIDS2XIDS;
|
---|
260 | request.extra_data.data = (char *)sids;
|
---|
261 | request.extra_len = size;
|
---|
262 | do_async(mem_ctx, idmap_child(), &request, winbindd_sids2xids_recv,
|
---|
263 | (void *)cont, private_data);
|
---|
264 | }
|
---|
265 |
|
---|
266 | enum winbindd_result winbindd_dual_sids2xids(struct winbindd_domain *domain,
|
---|
267 | struct winbindd_cli_state *state)
|
---|
268 | {
|
---|
269 | DOM_SID *sids;
|
---|
270 | struct unixid *xids;
|
---|
271 | struct id_map **ids;
|
---|
272 | NTSTATUS result;
|
---|
273 | int num, i;
|
---|
274 |
|
---|
275 | DEBUG(3, ("[%5lu]: sids to unix ids\n", (unsigned long)state->pid));
|
---|
276 |
|
---|
277 | if (state->request.extra_len == 0) {
|
---|
278 | DEBUG(0, ("Invalid buffer size!\n"));
|
---|
279 | return WINBINDD_ERROR;
|
---|
280 | }
|
---|
281 |
|
---|
282 | sids = (DOM_SID *)state->request.extra_data.data;
|
---|
283 | num = state->request.extra_len / sizeof(DOM_SID);
|
---|
284 |
|
---|
285 | ids = TALLOC_ZERO_ARRAY(state->mem_ctx, struct id_map *, num + 1);
|
---|
286 | if ( ! ids) {
|
---|
287 | DEBUG(0, ("Out of memory!\n"));
|
---|
288 | return WINBINDD_ERROR;
|
---|
289 | }
|
---|
290 | for (i = 0; i < num; i++) {
|
---|
291 | ids[i] = TALLOC_P(ids, struct id_map);
|
---|
292 | if ( ! ids[i]) {
|
---|
293 | DEBUG(0, ("Out of memory!\n"));
|
---|
294 | talloc_free(ids);
|
---|
295 | return WINBINDD_ERROR;
|
---|
296 | }
|
---|
297 | ids[i]->sid = &sids[i];
|
---|
298 | }
|
---|
299 |
|
---|
300 | result = idmap_sids_to_unixids(ids);
|
---|
301 |
|
---|
302 | if (NT_STATUS_IS_OK(result)) {
|
---|
303 |
|
---|
304 | xids = SMB_MALLOC_ARRAY(struct unixid, num);
|
---|
305 | if ( ! xids) {
|
---|
306 | DEBUG(0, ("Out of memory!\n"));
|
---|
307 | talloc_free(ids);
|
---|
308 | return WINBINDD_ERROR;
|
---|
309 | }
|
---|
310 |
|
---|
311 | for (i = 0; i < num; i++) {
|
---|
312 | if (ids[i]->status == ID_MAPPED) {
|
---|
313 | xids[i].type = ids[i]->xid.type;
|
---|
314 | xids[i].id = ids[i]->xid.id;
|
---|
315 | } else {
|
---|
316 | xids[i].type = -1;
|
---|
317 | }
|
---|
318 | }
|
---|
319 |
|
---|
320 | state->response.length = sizeof(state->response) + (sizeof(struct unixid) * num);
|
---|
321 | state->response.extra_data.data = xids;
|
---|
322 |
|
---|
323 | } else {
|
---|
324 | DEBUG (2, ("idmap_sids_to_unixids returned an error: 0x%08x\n", NT_STATUS_V(result)));
|
---|
325 | talloc_free(ids);
|
---|
326 | return WINBINDD_ERROR;
|
---|
327 | }
|
---|
328 |
|
---|
329 | talloc_free(ids);
|
---|
330 | return WINBINDD_OK;
|
---|
331 | }
|
---|
332 |
|
---|
333 | static void winbindd_sid2uid_recv(TALLOC_CTX *mem_ctx, BOOL success,
|
---|
334 | struct winbindd_response *response,
|
---|
335 | void *c, void *private_data)
|
---|
336 | {
|
---|
337 | void (*cont)(void *priv, BOOL succ, uid_t uid) =
|
---|
338 | (void (*)(void *, BOOL, uid_t))c;
|
---|
339 |
|
---|
340 | if (!success) {
|
---|
341 | DEBUG(5, ("Could not trigger sid2uid\n"));
|
---|
342 | cont(private_data, False, 0);
|
---|
343 | return;
|
---|
344 | }
|
---|
345 |
|
---|
346 | if (response->result != WINBINDD_OK) {
|
---|
347 | DEBUG(5, ("sid2uid returned an error\n"));
|
---|
348 | cont(private_data, False, 0);
|
---|
349 | return;
|
---|
350 | }
|
---|
351 |
|
---|
352 | cont(private_data, True, response->data.uid);
|
---|
353 | }
|
---|
354 |
|
---|
355 | void winbindd_sid2uid_async(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
|
---|
356 | void (*cont)(void *private_data, BOOL success, uid_t uid),
|
---|
357 | void *private_data)
|
---|
358 | {
|
---|
359 | struct winbindd_request request;
|
---|
360 | ZERO_STRUCT(request);
|
---|
361 | request.cmd = WINBINDD_DUAL_SID2UID;
|
---|
362 | sid_to_string(request.data.dual_sid2id.sid, sid);
|
---|
363 | do_async(mem_ctx, idmap_child(), &request, winbindd_sid2uid_recv,
|
---|
364 | (void *)cont, private_data);
|
---|
365 | }
|
---|
366 |
|
---|
367 | enum winbindd_result winbindd_dual_sid2uid(struct winbindd_domain *domain,
|
---|
368 | struct winbindd_cli_state *state)
|
---|
369 | {
|
---|
370 | DOM_SID sid;
|
---|
371 | NTSTATUS result;
|
---|
372 |
|
---|
373 | DEBUG(3, ("[%5lu]: sid to uid %s\n", (unsigned long)state->pid,
|
---|
374 | state->request.data.dual_sid2id.sid));
|
---|
375 |
|
---|
376 | if (!string_to_sid(&sid, state->request.data.dual_sid2id.sid)) {
|
---|
377 | DEBUG(1, ("Could not get convert sid %s from string\n",
|
---|
378 | state->request.data.dual_sid2id.sid));
|
---|
379 | return WINBINDD_ERROR;
|
---|
380 | }
|
---|
381 |
|
---|
382 | /* Find uid for this sid and return it, possibly ask the slow remote idmap */
|
---|
383 |
|
---|
384 | result = idmap_sid_to_uid(&sid, &(state->response.data.uid));
|
---|
385 |
|
---|
386 | return NT_STATUS_IS_OK(result) ? WINBINDD_OK : WINBINDD_ERROR;
|
---|
387 | }
|
---|
388 |
|
---|
389 | #if 0 /* not used */
|
---|
390 | static void uid2name_recv(TALLOC_CTX *mem_ctx, BOOL success,
|
---|
391 | struct winbindd_response *response,
|
---|
392 | void *c, void *private_data);
|
---|
393 |
|
---|
394 | void winbindd_uid2name_async(TALLOC_CTX *mem_ctx, uid_t uid,
|
---|
395 | void (*cont)(void *private_data, BOOL success,
|
---|
396 | const char *name),
|
---|
397 | void *private_data)
|
---|
398 | {
|
---|
399 | struct winbindd_request request;
|
---|
400 | ZERO_STRUCT(request);
|
---|
401 | request.cmd = WINBINDD_DUAL_UID2NAME;
|
---|
402 | request.data.uid = uid;
|
---|
403 | do_async(mem_ctx, idmap_child(), &request, uid2name_recv,
|
---|
404 | (void *)cont, private_data);
|
---|
405 | }
|
---|
406 | #endif /* not used */
|
---|
407 |
|
---|
408 | enum winbindd_result winbindd_dual_uid2name(struct winbindd_domain *domain,
|
---|
409 | struct winbindd_cli_state *state)
|
---|
410 | {
|
---|
411 | struct passwd *pw;
|
---|
412 |
|
---|
413 | DEBUG(3, ("[%5lu]: uid2name %lu\n", (unsigned long)state->pid,
|
---|
414 | (unsigned long)state->request.data.uid));
|
---|
415 |
|
---|
416 | pw = getpwuid(state->request.data.uid);
|
---|
417 | if (pw == NULL) {
|
---|
418 | DEBUG(5, ("User %lu not found\n",
|
---|
419 | (unsigned long)state->request.data.uid));
|
---|
420 | return WINBINDD_ERROR;
|
---|
421 | }
|
---|
422 |
|
---|
423 | fstrcpy(state->response.data.name.name, pw->pw_name);
|
---|
424 | return WINBINDD_OK;
|
---|
425 | }
|
---|
426 |
|
---|
427 | #if 0 /* not used */
|
---|
428 | static void uid2name_recv(TALLOC_CTX *mem_ctx, BOOL success,
|
---|
429 | struct winbindd_response *response,
|
---|
430 | void *c, void *private_data)
|
---|
431 | {
|
---|
432 | void (*cont)(void *priv, BOOL succ, const char *name) =
|
---|
433 | (void (*)(void *, BOOL, const char *))c;
|
---|
434 |
|
---|
435 | if (!success) {
|
---|
436 | DEBUG(5, ("Could not trigger uid2name\n"));
|
---|
437 | cont(private_data, False, NULL);
|
---|
438 | return;
|
---|
439 | }
|
---|
440 |
|
---|
441 | if (response->result != WINBINDD_OK) {
|
---|
442 | DEBUG(5, ("uid2name returned an error\n"));
|
---|
443 | cont(private_data, False, NULL);
|
---|
444 | return;
|
---|
445 | }
|
---|
446 |
|
---|
447 | cont(private_data, True, response->data.name.name);
|
---|
448 | }
|
---|
449 |
|
---|
450 | static void name2uid_recv(TALLOC_CTX *mem_ctx, BOOL success,
|
---|
451 | struct winbindd_response *response,
|
---|
452 | void *c, void *private_data);
|
---|
453 |
|
---|
454 | static void winbindd_name2uid_async(TALLOC_CTX *mem_ctx, const char *name,
|
---|
455 | void (*cont)(void *private_data, BOOL success,
|
---|
456 | uid_t uid),
|
---|
457 | void *private_data)
|
---|
458 | {
|
---|
459 | struct winbindd_request request;
|
---|
460 | ZERO_STRUCT(request);
|
---|
461 | request.cmd = WINBINDD_DUAL_NAME2UID;
|
---|
462 | fstrcpy(request.data.username, name);
|
---|
463 | do_async(mem_ctx, idmap_child(), &request, name2uid_recv,
|
---|
464 | (void *)cont, private_data);
|
---|
465 | }
|
---|
466 | #endif /* not used */
|
---|
467 |
|
---|
468 | enum winbindd_result winbindd_dual_name2uid(struct winbindd_domain *domain,
|
---|
469 | struct winbindd_cli_state *state)
|
---|
470 | {
|
---|
471 | struct passwd *pw;
|
---|
472 |
|
---|
473 | /* Ensure null termination */
|
---|
474 | state->request.data.username
|
---|
475 | [sizeof(state->request.data.username)-1] = '\0';
|
---|
476 |
|
---|
477 | DEBUG(3, ("[%5lu]: name2uid %s\n", (unsigned long)state->pid,
|
---|
478 | state->request.data.username));
|
---|
479 |
|
---|
480 | pw = getpwnam(state->request.data.username);
|
---|
481 | if (pw == NULL) {
|
---|
482 | return WINBINDD_ERROR;
|
---|
483 | }
|
---|
484 |
|
---|
485 | state->response.data.uid = pw->pw_uid;
|
---|
486 | return WINBINDD_OK;
|
---|
487 | }
|
---|
488 |
|
---|
489 | #if 0 /* not used */
|
---|
490 | static void name2uid_recv(TALLOC_CTX *mem_ctx, BOOL success,
|
---|
491 | struct winbindd_response *response,
|
---|
492 | void *c, void *private_data)
|
---|
493 | {
|
---|
494 | void (*cont)(void *priv, BOOL succ, uid_t uid) =
|
---|
495 | (void (*)(void *, BOOL, uid_t))c;
|
---|
496 |
|
---|
497 | if (!success) {
|
---|
498 | DEBUG(5, ("Could not trigger name2uid\n"));
|
---|
499 | cont(private_data, False, 0);
|
---|
500 | return;
|
---|
501 | }
|
---|
502 |
|
---|
503 | if (response->result != WINBINDD_OK) {
|
---|
504 | DEBUG(5, ("name2uid returned an error\n"));
|
---|
505 | cont(private_data, False, 0);
|
---|
506 | return;
|
---|
507 | }
|
---|
508 |
|
---|
509 | cont(private_data, True, response->data.uid);
|
---|
510 | }
|
---|
511 | #endif /* not used */
|
---|
512 |
|
---|
513 | static void winbindd_sid2gid_recv(TALLOC_CTX *mem_ctx, BOOL success,
|
---|
514 | struct winbindd_response *response,
|
---|
515 | void *c, void *private_data)
|
---|
516 | {
|
---|
517 | void (*cont)(void *priv, BOOL succ, gid_t gid) =
|
---|
518 | (void (*)(void *, BOOL, gid_t))c;
|
---|
519 |
|
---|
520 | if (!success) {
|
---|
521 | DEBUG(5, ("Could not trigger sid2gid\n"));
|
---|
522 | cont(private_data, False, 0);
|
---|
523 | return;
|
---|
524 | }
|
---|
525 |
|
---|
526 | if (response->result != WINBINDD_OK) {
|
---|
527 | DEBUG(5, ("sid2gid returned an error\n"));
|
---|
528 | cont(private_data, False, 0);
|
---|
529 | return;
|
---|
530 | }
|
---|
531 |
|
---|
532 | cont(private_data, True, response->data.gid);
|
---|
533 | }
|
---|
534 |
|
---|
535 | void winbindd_sid2gid_async(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
|
---|
536 | void (*cont)(void *private_data, BOOL success, gid_t gid),
|
---|
537 | void *private_data)
|
---|
538 | {
|
---|
539 | struct winbindd_request request;
|
---|
540 | ZERO_STRUCT(request);
|
---|
541 | request.cmd = WINBINDD_DUAL_SID2GID;
|
---|
542 | sid_to_string(request.data.dual_sid2id.sid, sid);
|
---|
543 |
|
---|
544 | DEBUG(7,("winbindd_sid2gid_async: Resolving %s to a gid\n",
|
---|
545 | request.data.dual_sid2id.sid));
|
---|
546 |
|
---|
547 | do_async(mem_ctx, idmap_child(), &request, winbindd_sid2gid_recv,
|
---|
548 | (void *)cont, private_data);
|
---|
549 | }
|
---|
550 |
|
---|
551 | enum winbindd_result winbindd_dual_sid2gid(struct winbindd_domain *domain,
|
---|
552 | struct winbindd_cli_state *state)
|
---|
553 | {
|
---|
554 | DOM_SID sid;
|
---|
555 | NTSTATUS result;
|
---|
556 |
|
---|
557 | DEBUG(3, ("[%5lu]: sid to gid %s\n", (unsigned long)state->pid,
|
---|
558 | state->request.data.dual_sid2id.sid));
|
---|
559 |
|
---|
560 | if (!string_to_sid(&sid, state->request.data.dual_sid2id.sid)) {
|
---|
561 | DEBUG(1, ("Could not get convert sid %s from string\n",
|
---|
562 | state->request.data.dual_sid2id.sid));
|
---|
563 | return WINBINDD_ERROR;
|
---|
564 | }
|
---|
565 |
|
---|
566 | /* Find gid for this sid and return it, possibly ask the slow remote idmap */
|
---|
567 |
|
---|
568 | result = idmap_sid_to_gid(&sid, &state->response.data.gid);
|
---|
569 |
|
---|
570 | DEBUG(10, ("winbindd_dual_sid2gid: 0x%08x - %s - %u\n", NT_STATUS_V(result), sid_string_static(&sid), state->response.data.gid));
|
---|
571 |
|
---|
572 | return NT_STATUS_IS_OK(result) ? WINBINDD_OK : WINBINDD_ERROR;
|
---|
573 | }
|
---|
574 |
|
---|
575 | static void gid2name_recv(TALLOC_CTX *mem_ctx, BOOL success,
|
---|
576 | struct winbindd_response *response,
|
---|
577 | void *c, void *private_data)
|
---|
578 | {
|
---|
579 | void (*cont)(void *priv, BOOL succ, const char *name) =
|
---|
580 | (void (*)(void *, BOOL, const char *))c;
|
---|
581 |
|
---|
582 | if (!success) {
|
---|
583 | DEBUG(5, ("Could not trigger gid2name\n"));
|
---|
584 | cont(private_data, False, NULL);
|
---|
585 | return;
|
---|
586 | }
|
---|
587 |
|
---|
588 | if (response->result != WINBINDD_OK) {
|
---|
589 | DEBUG(5, ("gid2name returned an error\n"));
|
---|
590 | cont(private_data, False, NULL);
|
---|
591 | return;
|
---|
592 | }
|
---|
593 |
|
---|
594 | cont(private_data, True, response->data.name.name);
|
---|
595 | }
|
---|
596 |
|
---|
597 | void winbindd_gid2name_async(TALLOC_CTX *mem_ctx, gid_t gid,
|
---|
598 | void (*cont)(void *private_data, BOOL success,
|
---|
599 | const char *name),
|
---|
600 | void *private_data)
|
---|
601 | {
|
---|
602 | struct winbindd_request request;
|
---|
603 | ZERO_STRUCT(request);
|
---|
604 | request.cmd = WINBINDD_DUAL_GID2NAME;
|
---|
605 | request.data.gid = gid;
|
---|
606 | do_async(mem_ctx, idmap_child(), &request, gid2name_recv,
|
---|
607 | (void *)cont, private_data);
|
---|
608 | }
|
---|
609 |
|
---|
610 | enum winbindd_result winbindd_dual_gid2name(struct winbindd_domain *domain,
|
---|
611 | struct winbindd_cli_state *state)
|
---|
612 | {
|
---|
613 | struct group *gr;
|
---|
614 |
|
---|
615 | DEBUG(3, ("[%5lu]: gid2name %lu\n", (unsigned long)state->pid,
|
---|
616 | (unsigned long)state->request.data.gid));
|
---|
617 |
|
---|
618 | gr = getgrgid(state->request.data.gid);
|
---|
619 | if (gr == NULL)
|
---|
620 | return WINBINDD_ERROR;
|
---|
621 |
|
---|
622 | fstrcpy(state->response.data.name.name, gr->gr_name);
|
---|
623 | return WINBINDD_OK;
|
---|
624 | }
|
---|
625 |
|
---|
626 | #if 0 /* not used */
|
---|
627 | static void name2gid_recv(TALLOC_CTX *mem_ctx, BOOL success,
|
---|
628 | struct winbindd_response *response,
|
---|
629 | void *c, void *private_data);
|
---|
630 |
|
---|
631 | static void winbindd_name2gid_async(TALLOC_CTX *mem_ctx, const char *name,
|
---|
632 | void (*cont)(void *private_data, BOOL success,
|
---|
633 | gid_t gid),
|
---|
634 | void *private_data)
|
---|
635 | {
|
---|
636 | struct winbindd_request request;
|
---|
637 | ZERO_STRUCT(request);
|
---|
638 | request.cmd = WINBINDD_DUAL_NAME2GID;
|
---|
639 | fstrcpy(request.data.groupname, name);
|
---|
640 | do_async(mem_ctx, idmap_child(), &request, name2gid_recv,
|
---|
641 | (void *)cont, private_data);
|
---|
642 | }
|
---|
643 | #endif /* not used */
|
---|
644 |
|
---|
645 | enum winbindd_result winbindd_dual_name2gid(struct winbindd_domain *domain,
|
---|
646 | struct winbindd_cli_state *state)
|
---|
647 | {
|
---|
648 | struct group *gr;
|
---|
649 |
|
---|
650 | /* Ensure null termination */
|
---|
651 | state->request.data.groupname
|
---|
652 | [sizeof(state->request.data.groupname)-1] = '\0';
|
---|
653 |
|
---|
654 | DEBUG(3, ("[%5lu]: name2gid %s\n", (unsigned long)state->pid,
|
---|
655 | state->request.data.groupname));
|
---|
656 |
|
---|
657 | gr = getgrnam(state->request.data.groupname);
|
---|
658 | if (gr == NULL) {
|
---|
659 | return WINBINDD_ERROR;
|
---|
660 | }
|
---|
661 |
|
---|
662 | state->response.data.gid = gr->gr_gid;
|
---|
663 | return WINBINDD_OK;
|
---|
664 | }
|
---|
665 |
|
---|
666 | #if 0 /* not used */
|
---|
667 | static void name2gid_recv(TALLOC_CTX *mem_ctx, BOOL success,
|
---|
668 | struct winbindd_response *response,
|
---|
669 | void *c, void *private_data)
|
---|
670 | {
|
---|
671 | void (*cont)(void *priv, BOOL succ, gid_t gid) =
|
---|
672 | (void (*)(void *, BOOL, gid_t))c;
|
---|
673 |
|
---|
674 | if (!success) {
|
---|
675 | DEBUG(5, ("Could not trigger name2gid\n"));
|
---|
676 | cont(private_data, False, 0);
|
---|
677 | return;
|
---|
678 | }
|
---|
679 |
|
---|
680 | if (response->result != WINBINDD_OK) {
|
---|
681 | DEBUG(5, ("name2gid returned an error\n"));
|
---|
682 | cont(private_data, False, 0);
|
---|
683 | return;
|
---|
684 | }
|
---|
685 |
|
---|
686 | cont(private_data, True, response->data.gid);
|
---|
687 | }
|
---|
688 | #endif /* not used */
|
---|
689 |
|
---|
690 | static void lookupsid_recv(TALLOC_CTX *mem_ctx, BOOL success,
|
---|
691 | struct winbindd_response *response,
|
---|
692 | void *c, void *private_data)
|
---|
693 | {
|
---|
694 | void (*cont)(void *priv, BOOL succ, const char *dom_name,
|
---|
695 | const char *name, enum lsa_SidType type) =
|
---|
696 | (void (*)(void *, BOOL, const char *, const char *,
|
---|
697 | enum lsa_SidType))c;
|
---|
698 |
|
---|
699 | if (!success) {
|
---|
700 | DEBUG(5, ("Could not trigger lookupsid\n"));
|
---|
701 | cont(private_data, False, NULL, NULL, SID_NAME_UNKNOWN);
|
---|
702 | return;
|
---|
703 | }
|
---|
704 |
|
---|
705 | if (response->result != WINBINDD_OK) {
|
---|
706 | DEBUG(5, ("lookupsid returned an error\n"));
|
---|
707 | cont(private_data, False, NULL, NULL, SID_NAME_UNKNOWN);
|
---|
708 | return;
|
---|
709 | }
|
---|
710 |
|
---|
711 | cont(private_data, True, response->data.name.dom_name,
|
---|
712 | response->data.name.name,
|
---|
713 | (enum lsa_SidType)response->data.name.type);
|
---|
714 | }
|
---|
715 |
|
---|
716 | void winbindd_lookupsid_async(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
|
---|
717 | void (*cont)(void *private_data, BOOL success,
|
---|
718 | const char *dom_name,
|
---|
719 | const char *name,
|
---|
720 | enum lsa_SidType type),
|
---|
721 | void *private_data)
|
---|
722 | {
|
---|
723 | struct winbindd_domain *domain;
|
---|
724 | struct winbindd_request request;
|
---|
725 |
|
---|
726 | domain = find_lookup_domain_from_sid(sid);
|
---|
727 | if (domain == NULL) {
|
---|
728 | DEBUG(5, ("Could not find domain for sid %s\n",
|
---|
729 | sid_string_static(sid)));
|
---|
730 | cont(private_data, False, NULL, NULL, SID_NAME_UNKNOWN);
|
---|
731 | return;
|
---|
732 | }
|
---|
733 |
|
---|
734 | ZERO_STRUCT(request);
|
---|
735 | request.cmd = WINBINDD_LOOKUPSID;
|
---|
736 | fstrcpy(request.data.sid, sid_string_static(sid));
|
---|
737 |
|
---|
738 | do_async_domain(mem_ctx, domain, &request, lookupsid_recv,
|
---|
739 | (void *)cont, private_data);
|
---|
740 | }
|
---|
741 |
|
---|
742 | enum winbindd_result winbindd_dual_lookupsid(struct winbindd_domain *domain,
|
---|
743 | struct winbindd_cli_state *state)
|
---|
744 | {
|
---|
745 | enum lsa_SidType type;
|
---|
746 | DOM_SID sid;
|
---|
747 | char *name;
|
---|
748 | char *dom_name;
|
---|
749 |
|
---|
750 | /* Ensure null termination */
|
---|
751 | state->request.data.sid[sizeof(state->request.data.sid)-1]='\0';
|
---|
752 |
|
---|
753 | DEBUG(3, ("[%5lu]: lookupsid %s\n", (unsigned long)state->pid,
|
---|
754 | state->request.data.sid));
|
---|
755 |
|
---|
756 | /* Lookup sid from PDC using lsa_lookup_sids() */
|
---|
757 |
|
---|
758 | if (!string_to_sid(&sid, state->request.data.sid)) {
|
---|
759 | DEBUG(5, ("%s not a SID\n", state->request.data.sid));
|
---|
760 | return WINBINDD_ERROR;
|
---|
761 | }
|
---|
762 |
|
---|
763 | /* Lookup the sid */
|
---|
764 |
|
---|
765 | if (!winbindd_lookup_name_by_sid(state->mem_ctx, &sid, &dom_name, &name,
|
---|
766 | &type)) {
|
---|
767 | TALLOC_FREE(dom_name);
|
---|
768 | TALLOC_FREE(name);
|
---|
769 | return WINBINDD_ERROR;
|
---|
770 | }
|
---|
771 |
|
---|
772 | fstrcpy(state->response.data.name.dom_name, dom_name);
|
---|
773 | fstrcpy(state->response.data.name.name, name);
|
---|
774 | state->response.data.name.type = type;
|
---|
775 |
|
---|
776 | TALLOC_FREE(dom_name);
|
---|
777 | TALLOC_FREE(name);
|
---|
778 | return WINBINDD_OK;
|
---|
779 | }
|
---|
780 |
|
---|
781 | /********************************************************************
|
---|
782 | This is the second callback after contacting the forest root
|
---|
783 | ********************************************************************/
|
---|
784 |
|
---|
785 | static void lookupname_recv2(TALLOC_CTX *mem_ctx, BOOL success,
|
---|
786 | struct winbindd_response *response,
|
---|
787 | void *c, void *private_data)
|
---|
788 | {
|
---|
789 | void (*cont)(void *priv, BOOL succ, const DOM_SID *sid,
|
---|
790 | enum lsa_SidType type) =
|
---|
791 | (void (*)(void *, BOOL, const DOM_SID *, enum lsa_SidType))c;
|
---|
792 | DOM_SID sid;
|
---|
793 |
|
---|
794 | if (!success) {
|
---|
795 | DEBUG(5, ("Could not trigger lookup_name\n"));
|
---|
796 | cont(private_data, False, NULL, SID_NAME_UNKNOWN);
|
---|
797 | return;
|
---|
798 | }
|
---|
799 |
|
---|
800 | if (response->result != WINBINDD_OK) {
|
---|
801 | DEBUG(5, ("lookup_name returned an error\n"));
|
---|
802 | cont(private_data, False, NULL, SID_NAME_UNKNOWN);
|
---|
803 | return;
|
---|
804 | }
|
---|
805 |
|
---|
806 | if (!string_to_sid(&sid, response->data.sid.sid)) {
|
---|
807 | DEBUG(0, ("Could not convert string %s to sid\n",
|
---|
808 | response->data.sid.sid));
|
---|
809 | cont(private_data, False, NULL, SID_NAME_UNKNOWN);
|
---|
810 | return;
|
---|
811 | }
|
---|
812 |
|
---|
813 | cont(private_data, True, &sid,
|
---|
814 | (enum lsa_SidType)response->data.sid.type);
|
---|
815 | }
|
---|
816 |
|
---|
817 | /********************************************************************
|
---|
818 | This is the first callback after contacting our own domain
|
---|
819 | ********************************************************************/
|
---|
820 |
|
---|
821 | static void lookupname_recv(TALLOC_CTX *mem_ctx, BOOL success,
|
---|
822 | struct winbindd_response *response,
|
---|
823 | void *c, void *private_data)
|
---|
824 | {
|
---|
825 | void (*cont)(void *priv, BOOL succ, const DOM_SID *sid,
|
---|
826 | enum lsa_SidType type) =
|
---|
827 | (void (*)(void *, BOOL, const DOM_SID *, enum lsa_SidType))c;
|
---|
828 | DOM_SID sid;
|
---|
829 |
|
---|
830 | if (!success) {
|
---|
831 | DEBUG(5, ("lookupname_recv: lookup_name() failed!\n"));
|
---|
832 | cont(private_data, False, NULL, SID_NAME_UNKNOWN);
|
---|
833 | return;
|
---|
834 | }
|
---|
835 |
|
---|
836 | if (response->result != WINBINDD_OK) {
|
---|
837 | /* Try again using the forest root */
|
---|
838 | struct winbindd_domain *root_domain = find_root_domain();
|
---|
839 | struct winbindd_cli_state *state = (struct winbindd_cli_state*)private_data;
|
---|
840 | struct winbindd_request request;
|
---|
841 | char *name_domain, *name_account;
|
---|
842 |
|
---|
843 | if ( !root_domain ) {
|
---|
844 | DEBUG(5,("lookupname_recv: unable to determine forest root\n"));
|
---|
845 | cont(private_data, False, NULL, SID_NAME_UNKNOWN);
|
---|
846 | return;
|
---|
847 | }
|
---|
848 |
|
---|
849 | name_domain = state->request.data.name.dom_name;
|
---|
850 | name_account = state->request.data.name.name;
|
---|
851 |
|
---|
852 | ZERO_STRUCT(request);
|
---|
853 | request.cmd = WINBINDD_LOOKUPNAME;
|
---|
854 | fstrcpy(request.data.name.dom_name, name_domain);
|
---|
855 | fstrcpy(request.data.name.name, name_account);
|
---|
856 |
|
---|
857 | do_async_domain(mem_ctx, root_domain, &request, lookupname_recv2,
|
---|
858 | (void *)cont, private_data);
|
---|
859 |
|
---|
860 | return;
|
---|
861 | }
|
---|
862 |
|
---|
863 | if (!string_to_sid(&sid, response->data.sid.sid)) {
|
---|
864 | DEBUG(0, ("Could not convert string %s to sid\n",
|
---|
865 | response->data.sid.sid));
|
---|
866 | cont(private_data, False, NULL, SID_NAME_UNKNOWN);
|
---|
867 | return;
|
---|
868 | }
|
---|
869 |
|
---|
870 | cont(private_data, True, &sid,
|
---|
871 | (enum lsa_SidType)response->data.sid.type);
|
---|
872 | }
|
---|
873 |
|
---|
874 | /********************************************************************
|
---|
875 | The lookup name call first contacts a DC in its own domain
|
---|
876 | and fallbacks to contact a DC in the forest in our domain doesn't
|
---|
877 | know the name.
|
---|
878 | ********************************************************************/
|
---|
879 |
|
---|
880 | void winbindd_lookupname_async(TALLOC_CTX *mem_ctx,
|
---|
881 | const char *dom_name, const char *name,
|
---|
882 | void (*cont)(void *private_data, BOOL success,
|
---|
883 | const DOM_SID *sid,
|
---|
884 | enum lsa_SidType type),
|
---|
885 | void *private_data)
|
---|
886 | {
|
---|
887 | struct winbindd_request request;
|
---|
888 | struct winbindd_domain *domain;
|
---|
889 |
|
---|
890 | if ( (domain = find_lookup_domain_from_name(dom_name)) == NULL ) {
|
---|
891 | DEBUG(5, ("Could not find domain for name %s\n", dom_name));
|
---|
892 | cont(private_data, False, NULL, SID_NAME_UNKNOWN);
|
---|
893 | return;
|
---|
894 | }
|
---|
895 |
|
---|
896 | ZERO_STRUCT(request);
|
---|
897 | request.cmd = WINBINDD_LOOKUPNAME;
|
---|
898 | fstrcpy(request.data.name.dom_name, dom_name);
|
---|
899 | fstrcpy(request.data.name.name, name);
|
---|
900 |
|
---|
901 | do_async_domain(mem_ctx, domain, &request, lookupname_recv,
|
---|
902 | (void *)cont, private_data);
|
---|
903 | }
|
---|
904 |
|
---|
905 | enum winbindd_result winbindd_dual_lookupname(struct winbindd_domain *domain,
|
---|
906 | struct winbindd_cli_state *state)
|
---|
907 | {
|
---|
908 | enum lsa_SidType type;
|
---|
909 | char *name_domain, *name_user;
|
---|
910 | DOM_SID sid;
|
---|
911 | char *p;
|
---|
912 |
|
---|
913 | /* Ensure null termination */
|
---|
914 | state->request.data.name.dom_name[sizeof(state->request.data.name.dom_name)-1]='\0';
|
---|
915 |
|
---|
916 | /* Ensure null termination */
|
---|
917 | state->request.data.name.name[sizeof(state->request.data.name.name)-1]='\0';
|
---|
918 |
|
---|
919 | /* cope with the name being a fully qualified name */
|
---|
920 | p = strstr(state->request.data.name.name, lp_winbind_separator());
|
---|
921 | if (p) {
|
---|
922 | *p = 0;
|
---|
923 | name_domain = state->request.data.name.name;
|
---|
924 | name_user = p+1;
|
---|
925 | } else {
|
---|
926 | name_domain = state->request.data.name.dom_name;
|
---|
927 | name_user = state->request.data.name.name;
|
---|
928 | }
|
---|
929 |
|
---|
930 | DEBUG(3, ("[%5lu]: lookupname %s%s%s\n", (unsigned long)state->pid,
|
---|
931 | name_domain, lp_winbind_separator(), name_user));
|
---|
932 |
|
---|
933 | /* Lookup name from DC using lsa_lookup_names() */
|
---|
934 | if (!winbindd_lookup_sid_by_name(state->mem_ctx, domain, name_domain,
|
---|
935 | name_user, &sid, &type)) {
|
---|
936 | return WINBINDD_ERROR;
|
---|
937 | }
|
---|
938 |
|
---|
939 | sid_to_string(state->response.data.sid.sid, &sid);
|
---|
940 | state->response.data.sid.type = type;
|
---|
941 |
|
---|
942 | return WINBINDD_OK;
|
---|
943 | }
|
---|
944 |
|
---|
945 | BOOL print_sidlist(TALLOC_CTX *mem_ctx, const DOM_SID *sids,
|
---|
946 | size_t num_sids, char **result, ssize_t *len)
|
---|
947 | {
|
---|
948 | size_t i;
|
---|
949 | size_t buflen = 0;
|
---|
950 |
|
---|
951 | *len = 0;
|
---|
952 | *result = NULL;
|
---|
953 | for (i=0; i<num_sids; i++) {
|
---|
954 | sprintf_append(mem_ctx, result, len, &buflen,
|
---|
955 | "%s\n", sid_string_static(&sids[i]));
|
---|
956 | }
|
---|
957 |
|
---|
958 | if ((num_sids != 0) && (*result == NULL)) {
|
---|
959 | return False;
|
---|
960 | }
|
---|
961 |
|
---|
962 | return True;
|
---|
963 | }
|
---|
964 |
|
---|
965 | static BOOL parse_sidlist(TALLOC_CTX *mem_ctx, char *sidstr,
|
---|
966 | DOM_SID **sids, size_t *num_sids)
|
---|
967 | {
|
---|
968 | char *p, *q;
|
---|
969 |
|
---|
970 | p = sidstr;
|
---|
971 | if (p == NULL)
|
---|
972 | return False;
|
---|
973 |
|
---|
974 | while (p[0] != '\0') {
|
---|
975 | DOM_SID sid;
|
---|
976 | q = strchr(p, '\n');
|
---|
977 | if (q == NULL) {
|
---|
978 | DEBUG(0, ("Got invalid sidstr: %s\n", p));
|
---|
979 | return False;
|
---|
980 | }
|
---|
981 | *q = '\0';
|
---|
982 | q += 1;
|
---|
983 | if (!string_to_sid(&sid, p)) {
|
---|
984 | DEBUG(0, ("Could not parse sid %s\n", p));
|
---|
985 | return False;
|
---|
986 | }
|
---|
987 | if (!add_sid_to_array(mem_ctx, &sid, sids, num_sids)) {
|
---|
988 | return False;
|
---|
989 | }
|
---|
990 | p = q;
|
---|
991 | }
|
---|
992 | return True;
|
---|
993 | }
|
---|
994 |
|
---|
995 | static BOOL parse_ridlist(TALLOC_CTX *mem_ctx, char *ridstr,
|
---|
996 | uint32 **rids, size_t *num_rids)
|
---|
997 | {
|
---|
998 | char *p;
|
---|
999 |
|
---|
1000 | p = ridstr;
|
---|
1001 | if (p == NULL)
|
---|
1002 | return False;
|
---|
1003 |
|
---|
1004 | while (p[0] != '\0') {
|
---|
1005 | uint32 rid;
|
---|
1006 | char *q;
|
---|
1007 | rid = strtoul(p, &q, 10);
|
---|
1008 | if (*q != '\n') {
|
---|
1009 | DEBUG(0, ("Got invalid ridstr: %s\n", p));
|
---|
1010 | return False;
|
---|
1011 | }
|
---|
1012 | p = q+1;
|
---|
1013 | ADD_TO_ARRAY(mem_ctx, uint32, rid, rids, num_rids);
|
---|
1014 | }
|
---|
1015 | return True;
|
---|
1016 | }
|
---|
1017 |
|
---|
1018 | enum winbindd_result winbindd_dual_lookuprids(struct winbindd_domain *domain,
|
---|
1019 | struct winbindd_cli_state *state)
|
---|
1020 | {
|
---|
1021 | uint32 *rids = NULL;
|
---|
1022 | size_t i, buflen, num_rids = 0;
|
---|
1023 | ssize_t len;
|
---|
1024 | DOM_SID domain_sid;
|
---|
1025 | char *domain_name;
|
---|
1026 | char **names;
|
---|
1027 | enum lsa_SidType *types;
|
---|
1028 | NTSTATUS status;
|
---|
1029 | char *result;
|
---|
1030 |
|
---|
1031 | DEBUG(10, ("Looking up RIDs for domain %s (%s)\n",
|
---|
1032 | state->request.domain_name,
|
---|
1033 | state->request.data.sid));
|
---|
1034 |
|
---|
1035 | if (!parse_ridlist(state->mem_ctx, state->request.extra_data.data,
|
---|
1036 | &rids, &num_rids)) {
|
---|
1037 | DEBUG(5, ("Could not parse ridlist\n"));
|
---|
1038 | return WINBINDD_ERROR;
|
---|
1039 | }
|
---|
1040 |
|
---|
1041 | if (!string_to_sid(&domain_sid, state->request.data.sid)) {
|
---|
1042 | DEBUG(5, ("Could not parse domain sid %s\n",
|
---|
1043 | state->request.data.sid));
|
---|
1044 | return WINBINDD_ERROR;
|
---|
1045 | }
|
---|
1046 |
|
---|
1047 | status = domain->methods->rids_to_names(domain, state->mem_ctx,
|
---|
1048 | &domain_sid, rids, num_rids,
|
---|
1049 | &domain_name,
|
---|
1050 | &names, &types);
|
---|
1051 |
|
---|
1052 | if (!NT_STATUS_IS_OK(status) &&
|
---|
1053 | !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
|
---|
1054 | return WINBINDD_ERROR;
|
---|
1055 | }
|
---|
1056 |
|
---|
1057 | len = 0;
|
---|
1058 | buflen = 0;
|
---|
1059 | result = NULL;
|
---|
1060 |
|
---|
1061 | for (i=0; i<num_rids; i++) {
|
---|
1062 | sprintf_append(state->mem_ctx, &result, &len, &buflen,
|
---|
1063 | "%d %s\n", types[i], names[i]);
|
---|
1064 | }
|
---|
1065 |
|
---|
1066 | fstrcpy(state->response.data.domain_name, domain_name);
|
---|
1067 |
|
---|
1068 | if (result != NULL) {
|
---|
1069 | state->response.extra_data.data = SMB_STRDUP(result);
|
---|
1070 | if (!state->response.extra_data.data) {
|
---|
1071 | return WINBINDD_ERROR;
|
---|
1072 | }
|
---|
1073 | state->response.length += len+1;
|
---|
1074 | }
|
---|
1075 |
|
---|
1076 | return WINBINDD_OK;
|
---|
1077 | }
|
---|
1078 |
|
---|
1079 | static void getsidaliases_recv(TALLOC_CTX *mem_ctx, BOOL success,
|
---|
1080 | struct winbindd_response *response,
|
---|
1081 | void *c, void *private_data)
|
---|
1082 | {
|
---|
1083 | void (*cont)(void *priv, BOOL succ,
|
---|
1084 | DOM_SID *aliases, size_t num_aliases) =
|
---|
1085 | (void (*)(void *, BOOL, DOM_SID *, size_t))c;
|
---|
1086 | char *aliases_str;
|
---|
1087 | DOM_SID *sids = NULL;
|
---|
1088 | size_t num_sids = 0;
|
---|
1089 |
|
---|
1090 | if (!success) {
|
---|
1091 | DEBUG(5, ("Could not trigger getsidaliases\n"));
|
---|
1092 | cont(private_data, success, NULL, 0);
|
---|
1093 | return;
|
---|
1094 | }
|
---|
1095 |
|
---|
1096 | if (response->result != WINBINDD_OK) {
|
---|
1097 | DEBUG(5, ("getsidaliases returned an error\n"));
|
---|
1098 | cont(private_data, False, NULL, 0);
|
---|
1099 | return;
|
---|
1100 | }
|
---|
1101 |
|
---|
1102 | aliases_str = (char *)response->extra_data.data;
|
---|
1103 |
|
---|
1104 | if (aliases_str == NULL) {
|
---|
1105 | DEBUG(10, ("getsidaliases return 0 SIDs\n"));
|
---|
1106 | cont(private_data, True, NULL, 0);
|
---|
1107 | return;
|
---|
1108 | }
|
---|
1109 |
|
---|
1110 | if (!parse_sidlist(mem_ctx, aliases_str, &sids, &num_sids)) {
|
---|
1111 | DEBUG(0, ("Could not parse sids\n"));
|
---|
1112 | cont(private_data, False, NULL, 0);
|
---|
1113 | return;
|
---|
1114 | }
|
---|
1115 |
|
---|
1116 | SAFE_FREE(response->extra_data.data);
|
---|
1117 |
|
---|
1118 | cont(private_data, True, sids, num_sids);
|
---|
1119 | }
|
---|
1120 |
|
---|
1121 | void winbindd_getsidaliases_async(struct winbindd_domain *domain,
|
---|
1122 | TALLOC_CTX *mem_ctx,
|
---|
1123 | const DOM_SID *sids, size_t num_sids,
|
---|
1124 | void (*cont)(void *private_data,
|
---|
1125 | BOOL success,
|
---|
1126 | const DOM_SID *aliases,
|
---|
1127 | size_t num_aliases),
|
---|
1128 | void *private_data)
|
---|
1129 | {
|
---|
1130 | struct winbindd_request request;
|
---|
1131 | char *sidstr = NULL;
|
---|
1132 | ssize_t len;
|
---|
1133 |
|
---|
1134 | if (num_sids == 0) {
|
---|
1135 | cont(private_data, True, NULL, 0);
|
---|
1136 | return;
|
---|
1137 | }
|
---|
1138 |
|
---|
1139 | if (!print_sidlist(mem_ctx, sids, num_sids, &sidstr, &len)) {
|
---|
1140 | cont(private_data, False, NULL, 0);
|
---|
1141 | return;
|
---|
1142 | }
|
---|
1143 |
|
---|
1144 | ZERO_STRUCT(request);
|
---|
1145 | request.cmd = WINBINDD_DUAL_GETSIDALIASES;
|
---|
1146 | request.extra_len = len;
|
---|
1147 | request.extra_data.data = sidstr;
|
---|
1148 |
|
---|
1149 | do_async_domain(mem_ctx, domain, &request, getsidaliases_recv,
|
---|
1150 | (void *)cont, private_data);
|
---|
1151 | }
|
---|
1152 |
|
---|
1153 | enum winbindd_result winbindd_dual_getsidaliases(struct winbindd_domain *domain,
|
---|
1154 | struct winbindd_cli_state *state)
|
---|
1155 | {
|
---|
1156 | DOM_SID *sids = NULL;
|
---|
1157 | size_t num_sids = 0;
|
---|
1158 | char *sidstr = NULL;
|
---|
1159 | ssize_t len;
|
---|
1160 | size_t i;
|
---|
1161 | uint32 num_aliases;
|
---|
1162 | uint32 *alias_rids;
|
---|
1163 | NTSTATUS result;
|
---|
1164 |
|
---|
1165 | DEBUG(3, ("[%5lu]: getsidaliases\n", (unsigned long)state->pid));
|
---|
1166 |
|
---|
1167 | sidstr = state->request.extra_data.data;
|
---|
1168 | if (sidstr == NULL) {
|
---|
1169 | sidstr = talloc_strdup(state->mem_ctx, "\n"); /* No SID */
|
---|
1170 | if (!sidstr) {
|
---|
1171 | DEBUG(0, ("Out of memory\n"));
|
---|
1172 | return WINBINDD_ERROR;
|
---|
1173 | }
|
---|
1174 | }
|
---|
1175 |
|
---|
1176 | DEBUG(10, ("Sidlist: %s\n", sidstr));
|
---|
1177 |
|
---|
1178 | if (!parse_sidlist(state->mem_ctx, sidstr, &sids, &num_sids)) {
|
---|
1179 | DEBUG(0, ("Could not parse SID list: %s\n", sidstr));
|
---|
1180 | return WINBINDD_ERROR;
|
---|
1181 | }
|
---|
1182 |
|
---|
1183 | num_aliases = 0;
|
---|
1184 | alias_rids = NULL;
|
---|
1185 |
|
---|
1186 | result = domain->methods->lookup_useraliases(domain,
|
---|
1187 | state->mem_ctx,
|
---|
1188 | num_sids, sids,
|
---|
1189 | &num_aliases,
|
---|
1190 | &alias_rids);
|
---|
1191 |
|
---|
1192 | if (!NT_STATUS_IS_OK(result)) {
|
---|
1193 | DEBUG(3, ("Could not lookup_useraliases: %s\n",
|
---|
1194 | nt_errstr(result)));
|
---|
1195 | return WINBINDD_ERROR;
|
---|
1196 | }
|
---|
1197 |
|
---|
1198 | num_sids = 0;
|
---|
1199 | sids = NULL;
|
---|
1200 | sidstr = NULL;
|
---|
1201 |
|
---|
1202 | DEBUG(10, ("Got %d aliases\n", num_aliases));
|
---|
1203 |
|
---|
1204 | for (i=0; i<num_aliases; i++) {
|
---|
1205 | DOM_SID sid;
|
---|
1206 | DEBUGADD(10, (" rid %d\n", alias_rids[i]));
|
---|
1207 | sid_copy(&sid, &domain->sid);
|
---|
1208 | sid_append_rid(&sid, alias_rids[i]);
|
---|
1209 | if (!add_sid_to_array(state->mem_ctx, &sid, &sids, &num_sids)) {
|
---|
1210 | return WINBINDD_ERROR;
|
---|
1211 | }
|
---|
1212 | }
|
---|
1213 |
|
---|
1214 |
|
---|
1215 | if (!print_sidlist(state->mem_ctx, sids, num_sids, &sidstr, &len)) {
|
---|
1216 | DEBUG(0, ("Could not print_sidlist\n"));
|
---|
1217 | state->response.extra_data.data = NULL;
|
---|
1218 | return WINBINDD_ERROR;
|
---|
1219 | }
|
---|
1220 |
|
---|
1221 | state->response.extra_data.data = NULL;
|
---|
1222 |
|
---|
1223 | if (sidstr) {
|
---|
1224 | state->response.extra_data.data = SMB_STRDUP(sidstr);
|
---|
1225 | if (!state->response.extra_data.data) {
|
---|
1226 | DEBUG(0, ("Out of memory\n"));
|
---|
1227 | return WINBINDD_ERROR;
|
---|
1228 | }
|
---|
1229 | DEBUG(10, ("aliases_list: %s\n",
|
---|
1230 | (char *)state->response.extra_data.data));
|
---|
1231 | state->response.length += len+1;
|
---|
1232 | }
|
---|
1233 |
|
---|
1234 | return WINBINDD_OK;
|
---|
1235 | }
|
---|
1236 |
|
---|
1237 | struct gettoken_state {
|
---|
1238 | TALLOC_CTX *mem_ctx;
|
---|
1239 | DOM_SID user_sid;
|
---|
1240 | struct winbindd_domain *alias_domain;
|
---|
1241 | struct winbindd_domain *local_alias_domain;
|
---|
1242 | struct winbindd_domain *builtin_domain;
|
---|
1243 | DOM_SID *sids;
|
---|
1244 | size_t num_sids;
|
---|
1245 | void (*cont)(void *private_data, BOOL success, DOM_SID *sids, size_t num_sids);
|
---|
1246 | void *private_data;
|
---|
1247 | };
|
---|
1248 |
|
---|
1249 | static void gettoken_recvdomgroups(TALLOC_CTX *mem_ctx, BOOL success,
|
---|
1250 | struct winbindd_response *response,
|
---|
1251 | void *c, void *private_data);
|
---|
1252 | static void gettoken_recvaliases(void *private_data, BOOL success,
|
---|
1253 | const DOM_SID *aliases,
|
---|
1254 | size_t num_aliases);
|
---|
1255 |
|
---|
1256 |
|
---|
1257 | void winbindd_gettoken_async(TALLOC_CTX *mem_ctx, const DOM_SID *user_sid,
|
---|
1258 | void (*cont)(void *private_data, BOOL success,
|
---|
1259 | DOM_SID *sids, size_t num_sids),
|
---|
1260 | void *private_data)
|
---|
1261 | {
|
---|
1262 | struct winbindd_domain *domain;
|
---|
1263 | struct winbindd_request request;
|
---|
1264 | struct gettoken_state *state;
|
---|
1265 |
|
---|
1266 | state = TALLOC_ZERO_P(mem_ctx, struct gettoken_state);
|
---|
1267 | if (state == NULL) {
|
---|
1268 | DEBUG(0, ("talloc failed\n"));
|
---|
1269 | cont(private_data, False, NULL, 0);
|
---|
1270 | return;
|
---|
1271 | }
|
---|
1272 |
|
---|
1273 | state->mem_ctx = mem_ctx;
|
---|
1274 | sid_copy(&state->user_sid, user_sid);
|
---|
1275 | state->alias_domain = find_our_domain();
|
---|
1276 | state->local_alias_domain = find_domain_from_name( get_global_sam_name() );
|
---|
1277 | state->builtin_domain = find_builtin_domain();
|
---|
1278 | state->cont = cont;
|
---|
1279 | state->private_data = private_data;
|
---|
1280 |
|
---|
1281 | domain = find_domain_from_sid_noinit(user_sid);
|
---|
1282 | if (domain == NULL) {
|
---|
1283 | DEBUG(5, ("Could not find domain from SID %s\n",
|
---|
1284 | sid_string_static(user_sid)));
|
---|
1285 | cont(private_data, False, NULL, 0);
|
---|
1286 | return;
|
---|
1287 | }
|
---|
1288 |
|
---|
1289 | ZERO_STRUCT(request);
|
---|
1290 | request.cmd = WINBINDD_GETUSERDOMGROUPS;
|
---|
1291 | fstrcpy(request.data.sid, sid_string_static(user_sid));
|
---|
1292 |
|
---|
1293 | do_async_domain(mem_ctx, domain, &request, gettoken_recvdomgroups,
|
---|
1294 | NULL, state);
|
---|
1295 | }
|
---|
1296 |
|
---|
1297 | static void gettoken_recvdomgroups(TALLOC_CTX *mem_ctx, BOOL success,
|
---|
1298 | struct winbindd_response *response,
|
---|
1299 | void *c, void *private_data)
|
---|
1300 | {
|
---|
1301 | struct gettoken_state *state =
|
---|
1302 | talloc_get_type_abort(private_data, struct gettoken_state);
|
---|
1303 | char *sids_str;
|
---|
1304 |
|
---|
1305 | if (!success) {
|
---|
1306 | DEBUG(10, ("Could not get domain groups\n"));
|
---|
1307 | state->cont(state->private_data, False, NULL, 0);
|
---|
1308 | return;
|
---|
1309 | }
|
---|
1310 |
|
---|
1311 | sids_str = (char *)response->extra_data.data;
|
---|
1312 |
|
---|
1313 | if (sids_str == NULL) {
|
---|
1314 | /* This could be normal if we are dealing with a
|
---|
1315 | local user and local groups */
|
---|
1316 |
|
---|
1317 | if ( !sid_check_is_in_our_domain( &state->user_sid ) ) {
|
---|
1318 | DEBUG(10, ("Received no domain groups\n"));
|
---|
1319 | state->cont(state->private_data, True, NULL, 0);
|
---|
1320 | return;
|
---|
1321 | }
|
---|
1322 | }
|
---|
1323 |
|
---|
1324 | state->sids = NULL;
|
---|
1325 | state->num_sids = 0;
|
---|
1326 |
|
---|
1327 | if (!add_sid_to_array(mem_ctx, &state->user_sid, &state->sids,
|
---|
1328 | &state->num_sids)) {
|
---|
1329 | DEBUG(0, ("Out of memory\n"));
|
---|
1330 | state->cont(state->private_data, False, NULL, 0);
|
---|
1331 | return;
|
---|
1332 | }
|
---|
1333 |
|
---|
1334 | if (sids_str && !parse_sidlist(mem_ctx, sids_str, &state->sids,
|
---|
1335 | &state->num_sids)) {
|
---|
1336 | DEBUG(0, ("Could not parse sids\n"));
|
---|
1337 | state->cont(state->private_data, False, NULL, 0);
|
---|
1338 | return;
|
---|
1339 | }
|
---|
1340 |
|
---|
1341 | SAFE_FREE(response->extra_data.data);
|
---|
1342 |
|
---|
1343 | if (state->alias_domain == NULL) {
|
---|
1344 | DEBUG(10, ("Don't expand domain local groups\n"));
|
---|
1345 | state->cont(state->private_data, True, state->sids,
|
---|
1346 | state->num_sids);
|
---|
1347 | return;
|
---|
1348 | }
|
---|
1349 |
|
---|
1350 | winbindd_getsidaliases_async(state->alias_domain, mem_ctx,
|
---|
1351 | state->sids, state->num_sids,
|
---|
1352 | gettoken_recvaliases, state);
|
---|
1353 | }
|
---|
1354 |
|
---|
1355 | static void gettoken_recvaliases(void *private_data, BOOL success,
|
---|
1356 | const DOM_SID *aliases,
|
---|
1357 | size_t num_aliases)
|
---|
1358 | {
|
---|
1359 | struct gettoken_state *state = (struct gettoken_state *)private_data;
|
---|
1360 | size_t i;
|
---|
1361 |
|
---|
1362 | if (!success) {
|
---|
1363 | DEBUG(10, ("Could not receive domain local groups\n"));
|
---|
1364 | state->cont(state->private_data, False, NULL, 0);
|
---|
1365 | return;
|
---|
1366 | }
|
---|
1367 |
|
---|
1368 | for (i=0; i<num_aliases; i++) {
|
---|
1369 | if (!add_sid_to_array(state->mem_ctx, &aliases[i],
|
---|
1370 | &state->sids, &state->num_sids)) {
|
---|
1371 | DEBUG(0, ("Out of memory\n"));
|
---|
1372 | state->cont(state->private_data, False, NULL, 0);
|
---|
1373 | return;
|
---|
1374 | }
|
---|
1375 | }
|
---|
1376 |
|
---|
1377 | if (state->local_alias_domain != NULL) {
|
---|
1378 | struct winbindd_domain *local_domain = state->local_alias_domain;
|
---|
1379 | DEBUG(10, ("Expanding our own local groups\n"));
|
---|
1380 | state->local_alias_domain = NULL;
|
---|
1381 | winbindd_getsidaliases_async(local_domain, state->mem_ctx,
|
---|
1382 | state->sids, state->num_sids,
|
---|
1383 | gettoken_recvaliases, state);
|
---|
1384 | return;
|
---|
1385 | }
|
---|
1386 |
|
---|
1387 | if (state->builtin_domain != NULL) {
|
---|
1388 | struct winbindd_domain *builtin_domain = state->builtin_domain;
|
---|
1389 | DEBUG(10, ("Expanding our own BUILTIN groups\n"));
|
---|
1390 | state->builtin_domain = NULL;
|
---|
1391 | winbindd_getsidaliases_async(builtin_domain, state->mem_ctx,
|
---|
1392 | state->sids, state->num_sids,
|
---|
1393 | gettoken_recvaliases, state);
|
---|
1394 | return;
|
---|
1395 | }
|
---|
1396 |
|
---|
1397 | state->cont(state->private_data, True, state->sids, state->num_sids);
|
---|
1398 | }
|
---|
1399 |
|
---|
1400 | static void query_user_recv(TALLOC_CTX *mem_ctx, BOOL success,
|
---|
1401 | struct winbindd_response *response,
|
---|
1402 | void *c, void *private_data)
|
---|
1403 | {
|
---|
1404 | void (*cont)(void *priv, BOOL succ, const char *acct_name,
|
---|
1405 | const char *full_name, const char *homedir,
|
---|
1406 | const char *shell, uint32 gid, uint32 group_rid) =
|
---|
1407 | (void (*)(void *, BOOL, const char *, const char *,
|
---|
1408 | const char *, const char *, uint32, uint32))c;
|
---|
1409 |
|
---|
1410 | if (!success) {
|
---|
1411 | DEBUG(5, ("Could not trigger query_user\n"));
|
---|
1412 | cont(private_data, False, NULL, NULL, NULL, NULL, -1, -1);
|
---|
1413 | return;
|
---|
1414 | }
|
---|
1415 |
|
---|
1416 | cont(private_data, True, response->data.user_info.acct_name,
|
---|
1417 | response->data.user_info.full_name,
|
---|
1418 | response->data.user_info.homedir,
|
---|
1419 | response->data.user_info.shell,
|
---|
1420 | response->data.user_info.primary_gid,
|
---|
1421 | response->data.user_info.group_rid);
|
---|
1422 | }
|
---|
1423 |
|
---|
1424 | void query_user_async(TALLOC_CTX *mem_ctx, struct winbindd_domain *domain,
|
---|
1425 | const DOM_SID *sid,
|
---|
1426 | void (*cont)(void *private_data, BOOL success,
|
---|
1427 | const char *acct_name,
|
---|
1428 | const char *full_name,
|
---|
1429 | const char *homedir,
|
---|
1430 | const char *shell,
|
---|
1431 | gid_t gid,
|
---|
1432 | uint32 group_rid),
|
---|
1433 | void *private_data)
|
---|
1434 | {
|
---|
1435 | struct winbindd_request request;
|
---|
1436 | ZERO_STRUCT(request);
|
---|
1437 | request.cmd = WINBINDD_DUAL_USERINFO;
|
---|
1438 | sid_to_string(request.data.sid, sid);
|
---|
1439 | do_async_domain(mem_ctx, domain, &request, query_user_recv,
|
---|
1440 | (void *)cont, private_data);
|
---|
1441 | }
|
---|
1442 |
|
---|
1443 | /* The following uid2sid/gid2sid functions has been contributed by
|
---|
1444 | * Keith Reynolds <Keith.Reynolds@centrify.com> */
|
---|
1445 |
|
---|
1446 | static void winbindd_uid2sid_recv(TALLOC_CTX *mem_ctx, BOOL success,
|
---|
1447 | struct winbindd_response *response,
|
---|
1448 | void *c, void *private_data)
|
---|
1449 | {
|
---|
1450 | void (*cont)(void *priv, BOOL succ, const char *sid) =
|
---|
1451 | (void (*)(void *, BOOL, const char *))c;
|
---|
1452 |
|
---|
1453 | if (!success) {
|
---|
1454 | DEBUG(5, ("Could not trigger uid2sid\n"));
|
---|
1455 | cont(private_data, False, NULL);
|
---|
1456 | return;
|
---|
1457 | }
|
---|
1458 |
|
---|
1459 | if (response->result != WINBINDD_OK) {
|
---|
1460 | DEBUG(5, ("uid2sid returned an error\n"));
|
---|
1461 | cont(private_data, False, NULL);
|
---|
1462 | return;
|
---|
1463 | }
|
---|
1464 |
|
---|
1465 | cont(private_data, True, response->data.sid.sid);
|
---|
1466 | }
|
---|
1467 |
|
---|
1468 | void winbindd_uid2sid_async(TALLOC_CTX *mem_ctx, uid_t uid,
|
---|
1469 | void (*cont)(void *private_data, BOOL success, const char *sid),
|
---|
1470 | void *private_data)
|
---|
1471 | {
|
---|
1472 | struct winbindd_request request;
|
---|
1473 |
|
---|
1474 | ZERO_STRUCT(request);
|
---|
1475 | request.cmd = WINBINDD_DUAL_UID2SID;
|
---|
1476 | request.data.uid = uid;
|
---|
1477 | do_async(mem_ctx, idmap_child(), &request, winbindd_uid2sid_recv,
|
---|
1478 | (void *)cont, private_data);
|
---|
1479 | }
|
---|
1480 |
|
---|
1481 | enum winbindd_result winbindd_dual_uid2sid(struct winbindd_domain *domain,
|
---|
1482 | struct winbindd_cli_state *state)
|
---|
1483 | {
|
---|
1484 | DOM_SID sid;
|
---|
1485 | NTSTATUS result;
|
---|
1486 |
|
---|
1487 | DEBUG(3,("[%5lu]: uid to sid %lu\n",
|
---|
1488 | (unsigned long)state->pid,
|
---|
1489 | (unsigned long) state->request.data.uid));
|
---|
1490 |
|
---|
1491 | /* Find sid for this uid and return it, possibly ask the slow remote idmap */
|
---|
1492 | result = idmap_uid_to_sid(&sid, state->request.data.uid);
|
---|
1493 |
|
---|
1494 | if (NT_STATUS_IS_OK(result)) {
|
---|
1495 | sid_to_string(state->response.data.sid.sid, &sid);
|
---|
1496 | state->response.data.sid.type = SID_NAME_USER;
|
---|
1497 | return WINBINDD_OK;
|
---|
1498 | }
|
---|
1499 |
|
---|
1500 | return WINBINDD_ERROR;
|
---|
1501 | }
|
---|
1502 |
|
---|
1503 | static void winbindd_gid2sid_recv(TALLOC_CTX *mem_ctx, BOOL success,
|
---|
1504 | struct winbindd_response *response,
|
---|
1505 | void *c, void *private_data)
|
---|
1506 | {
|
---|
1507 | void (*cont)(void *priv, BOOL succ, const char *sid) =
|
---|
1508 | (void (*)(void *, BOOL, const char *))c;
|
---|
1509 |
|
---|
1510 | if (!success) {
|
---|
1511 | DEBUG(5, ("Could not trigger gid2sid\n"));
|
---|
1512 | cont(private_data, False, NULL);
|
---|
1513 | return;
|
---|
1514 | }
|
---|
1515 |
|
---|
1516 | if (response->result != WINBINDD_OK) {
|
---|
1517 | DEBUG(5, ("gid2sid returned an error\n"));
|
---|
1518 | cont(private_data, False, NULL);
|
---|
1519 | return;
|
---|
1520 | }
|
---|
1521 |
|
---|
1522 | cont(private_data, True, response->data.sid.sid);
|
---|
1523 | }
|
---|
1524 |
|
---|
1525 | void winbindd_gid2sid_async(TALLOC_CTX *mem_ctx, gid_t gid,
|
---|
1526 | void (*cont)(void *private_data, BOOL success, const char *sid),
|
---|
1527 | void *private_data)
|
---|
1528 | {
|
---|
1529 | struct winbindd_request request;
|
---|
1530 |
|
---|
1531 | ZERO_STRUCT(request);
|
---|
1532 | request.cmd = WINBINDD_DUAL_GID2SID;
|
---|
1533 | request.data.gid = gid;
|
---|
1534 | do_async(mem_ctx, idmap_child(), &request, winbindd_gid2sid_recv,
|
---|
1535 | (void *)cont, private_data);
|
---|
1536 | }
|
---|
1537 |
|
---|
1538 | enum winbindd_result winbindd_dual_gid2sid(struct winbindd_domain *domain,
|
---|
1539 | struct winbindd_cli_state *state)
|
---|
1540 | {
|
---|
1541 | DOM_SID sid;
|
---|
1542 | NTSTATUS result;
|
---|
1543 |
|
---|
1544 | DEBUG(3,("[%5lu]: gid %lu to sid\n",
|
---|
1545 | (unsigned long)state->pid,
|
---|
1546 | (unsigned long) state->request.data.gid));
|
---|
1547 |
|
---|
1548 | /* Find sid for this gid and return it, possibly ask the slow remote idmap */
|
---|
1549 | result = idmap_gid_to_sid(&sid, state->request.data.gid);
|
---|
1550 |
|
---|
1551 | if (NT_STATUS_IS_OK(result)) {
|
---|
1552 | sid_to_string(state->response.data.sid.sid, &sid);
|
---|
1553 | DEBUG(10, ("[%5lu]: retrieved sid: %s\n",
|
---|
1554 | (unsigned long)state->pid,
|
---|
1555 | state->response.data.sid.sid));
|
---|
1556 | state->response.data.sid.type = SID_NAME_DOM_GRP;
|
---|
1557 | return WINBINDD_OK;
|
---|
1558 | }
|
---|
1559 |
|
---|
1560 | return WINBINDD_ERROR;
|
---|
1561 | }
|
---|
1562 |
|
---|
1563 | static void winbindd_dump_id_maps_recv(TALLOC_CTX *mem_ctx, BOOL success,
|
---|
1564 | struct winbindd_response *response,
|
---|
1565 | void *c, void *private_data)
|
---|
1566 | {
|
---|
1567 | void (*cont)(void *priv, BOOL succ) =
|
---|
1568 | (void (*)(void *, BOOL))c;
|
---|
1569 |
|
---|
1570 | if (!success) {
|
---|
1571 | DEBUG(5, ("Could not trigger a map dump\n"));
|
---|
1572 | cont(private_data, False);
|
---|
1573 | return;
|
---|
1574 | }
|
---|
1575 |
|
---|
1576 | if (response->result != WINBINDD_OK) {
|
---|
1577 | DEBUG(5, ("idmap dump maps returned an error\n"));
|
---|
1578 | cont(private_data, False);
|
---|
1579 | return;
|
---|
1580 | }
|
---|
1581 |
|
---|
1582 | cont(private_data, True);
|
---|
1583 | }
|
---|
1584 |
|
---|
1585 | void winbindd_dump_maps_async(TALLOC_CTX *mem_ctx, void *data, int size,
|
---|
1586 | void (*cont)(void *private_data, BOOL success),
|
---|
1587 | void *private_data)
|
---|
1588 | {
|
---|
1589 | struct winbindd_request request;
|
---|
1590 | ZERO_STRUCT(request);
|
---|
1591 | request.cmd = WINBINDD_DUAL_DUMP_MAPS;
|
---|
1592 | request.extra_data.data = (char *)data;
|
---|
1593 | request.extra_len = size;
|
---|
1594 | do_async(mem_ctx, idmap_child(), &request, winbindd_dump_id_maps_recv,
|
---|
1595 | (void *)cont, private_data);
|
---|
1596 | }
|
---|
1597 |
|
---|
1598 | enum winbindd_result winbindd_dual_dump_maps(struct winbindd_domain *domain,
|
---|
1599 | struct winbindd_cli_state *state)
|
---|
1600 | {
|
---|
1601 | DEBUG(3, ("[%5lu]: dual dump maps\n", (unsigned long)state->pid));
|
---|
1602 |
|
---|
1603 | idmap_dump_maps((char *)state->request.extra_data.data);
|
---|
1604 |
|
---|
1605 | return WINBINDD_OK;
|
---|
1606 | }
|
---|
1607 |
|
---|