2 Unix SMB/CIFS implementation.
4 Async helpers for blocking functions
6 Copyright (C) Volker Lendecke 2005
7 Copyright (C) Gerald Carter 2006
9 The helpers always consist of three functions:
11 * A request setup function that takes the necessary parameters together
12 with a continuation function that is to be called upon completion
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.
18 * A worker function that is called inside the appropriate child process.
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 3 of the License, or
23 (at your option) any later version.
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.
30 You should have received a copy of the GNU General Public License
31 along with this program. If not, see <http://www.gnu.org/licenses/>.
38 #define DBGC_CLASS DBGC_WINBIND
40 struct do_async_state {
42 struct winbindd_request request;
43 struct winbindd_response response;
44 void (*cont)(TALLOC_CTX *mem_ctx,
46 struct winbindd_response *response,
47 void *c, void *private_data);
48 void *c, *private_data;
51 static void do_async_recv(void *private_data, bool success)
53 struct do_async_state *state =
54 talloc_get_type_abort(private_data, struct do_async_state);
56 state->cont(state->mem_ctx, success, &state->response,
57 state->c, state->private_data);
60 void do_async(TALLOC_CTX *mem_ctx, struct winbindd_child *child,
61 const struct winbindd_request *request,
62 void (*cont)(TALLOC_CTX *mem_ctx, bool success,
63 struct winbindd_response *response,
64 void *c, void *private_data),
65 void *c, void *private_data)
67 struct do_async_state *state;
69 state = TALLOC_ZERO_P(mem_ctx, struct do_async_state);
71 DEBUG(0, ("talloc failed\n"));
72 cont(mem_ctx, False, NULL, c, private_data);
76 state->mem_ctx = mem_ctx;
77 state->request = *request;
78 state->request.length = sizeof(state->request);
81 state->private_data = private_data;
83 async_request(mem_ctx, child, &state->request,
84 &state->response, do_async_recv, state);
87 static void do_async_domain(TALLOC_CTX *mem_ctx, struct winbindd_domain *domain,
88 const struct winbindd_request *request,
89 void (*cont)(TALLOC_CTX *mem_ctx, bool success,
90 struct winbindd_response *response,
91 void *c, void *private_data),
92 void *c, void *private_data)
94 struct do_async_state *state;
96 state = TALLOC_ZERO_P(mem_ctx, struct do_async_state);
98 DEBUG(0, ("talloc failed\n"));
99 cont(mem_ctx, False, NULL, c, private_data);
103 state->mem_ctx = mem_ctx;
104 state->request = *request;
105 state->request.length = sizeof(state->request);
108 state->private_data = private_data;
110 async_domain_request(mem_ctx, domain, &state->request,
111 &state->response, do_async_recv, state);
114 struct lookupsid_state {
116 void *caller_private_data;
120 static void lookupsid_recv2(TALLOC_CTX *mem_ctx, bool success,
121 struct winbindd_response *response,
122 void *c, void *private_data)
124 void (*cont)(void *priv, bool succ, const char *dom_name,
125 const char *name, enum lsa_SidType type) =
126 (void (*)(void *, bool, const char *, const char *,
128 struct lookupsid_state *s = talloc_get_type_abort(private_data,
129 struct lookupsid_state);
132 DEBUG(5, ("Could not trigger lookupsid\n"));
133 cont(s->caller_private_data, False, NULL, NULL, SID_NAME_UNKNOWN);
137 if (response->result != WINBINDD_OK) {
138 DEBUG(5, ("lookupsid (forest root) returned an error\n"));
139 cont(s->caller_private_data, False, NULL, NULL, SID_NAME_UNKNOWN);
143 cont(s->caller_private_data, True, response->data.name.dom_name,
144 response->data.name.name,
145 (enum lsa_SidType)response->data.name.type);
148 static void lookupsid_recv(TALLOC_CTX *mem_ctx, bool success,
149 struct winbindd_response *response,
150 void *c, void *private_data)
152 void (*cont)(void *priv, bool succ, const char *dom_name,
153 const char *name, enum lsa_SidType type) =
154 (void (*)(void *, bool, const char *, const char *,
156 struct lookupsid_state *s = talloc_get_type_abort(private_data,
157 struct lookupsid_state);
160 DEBUG(5, ("Could not trigger lookupsid\n"));
161 cont(s->caller_private_data, False, NULL, NULL, SID_NAME_UNKNOWN);
165 if (response->result != WINBINDD_OK) {
166 /* Try again using the forest root */
167 struct winbindd_domain *root_domain = find_root_domain();
168 struct winbindd_request request;
170 if ( !root_domain ) {
171 DEBUG(5,("lookupsid_recv: unable to determine forest root\n"));
172 cont(s->caller_private_data, False, NULL, NULL, SID_NAME_UNKNOWN);
176 ZERO_STRUCT(request);
177 request.cmd = WINBINDD_LOOKUPSID;
178 sid_to_fstring(request.data.sid, &s->sid);
180 do_async_domain(mem_ctx, root_domain, &request, lookupsid_recv2,
186 cont(s->caller_private_data, True, response->data.name.dom_name,
187 response->data.name.name,
188 (enum lsa_SidType)response->data.name.type);
191 void winbindd_lookupsid_async(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
192 void (*cont)(void *private_data, bool success,
193 const char *dom_name,
195 enum lsa_SidType type),
198 struct winbindd_domain *domain;
199 struct winbindd_request request;
200 struct lookupsid_state *s;
202 domain = find_lookup_domain_from_sid(sid);
203 if (domain == NULL) {
204 DEBUG(5, ("Could not find domain for sid %s\n",
205 sid_string_dbg(sid)));
206 cont(private_data, False, NULL, NULL, SID_NAME_UNKNOWN);
210 ZERO_STRUCT(request);
211 request.cmd = WINBINDD_LOOKUPSID;
212 sid_to_fstring(request.data.sid, sid);
214 if ( (s = TALLOC_ZERO_P(mem_ctx, struct lookupsid_state)) == NULL ) {
215 DEBUG(0, ("winbindd_lookupsid_async: talloc failed\n"));
216 cont(private_data, False, NULL, NULL, SID_NAME_UNKNOWN);
220 sid_copy( &s->sid, sid );
221 s->caller_private_data = private_data;
223 do_async_domain(mem_ctx, domain, &request, lookupsid_recv,
227 enum winbindd_result winbindd_dual_lookupsid(struct winbindd_domain *domain,
228 struct winbindd_cli_state *state)
230 enum lsa_SidType type;
235 /* Ensure null termination */
236 state->request->data.sid[sizeof(state->request->data.sid)-1]='\0';
238 DEBUG(3, ("[%5lu]: lookupsid %s\n", (unsigned long)state->pid,
239 state->request->data.sid));
241 /* Lookup sid from PDC using lsa_lookup_sids() */
243 if (!string_to_sid(&sid, state->request->data.sid)) {
244 DEBUG(5, ("%s not a SID\n", state->request->data.sid));
245 return WINBINDD_ERROR;
250 if (!winbindd_lookup_name_by_sid(state->mem_ctx, domain, &sid,
251 &dom_name, &name, &type))
253 TALLOC_FREE(dom_name);
255 return WINBINDD_ERROR;
258 fstrcpy(state->response->data.name.dom_name, dom_name);
259 fstrcpy(state->response->data.name.name, name);
260 state->response->data.name.type = type;
262 TALLOC_FREE(dom_name);
267 /********************************************************************
268 This is the second callback after contacting the forest root
269 ********************************************************************/
271 struct lookupname_state {
274 void *caller_private_data;
278 static void lookupname_recv2(TALLOC_CTX *mem_ctx, bool success,
279 struct winbindd_response *response,
280 void *c, void *private_data)
282 void (*cont)(void *priv, bool succ, const DOM_SID *sid,
283 enum lsa_SidType type) =
284 (void (*)(void *, bool, const DOM_SID *, enum lsa_SidType))c;
286 struct lookupname_state *s = talloc_get_type_abort( private_data,
287 struct lookupname_state );
290 DEBUG(5, ("Could not trigger lookup_name\n"));
291 cont(s->caller_private_data, False, NULL, SID_NAME_UNKNOWN);
295 if (response->result != WINBINDD_OK) {
296 DEBUG(5, ("lookup_name returned an error\n"));
297 cont(s->caller_private_data, False, NULL, SID_NAME_UNKNOWN);
301 if (!string_to_sid(&sid, response->data.sid.sid)) {
302 DEBUG(0, ("Could not convert string %s to sid\n",
303 response->data.sid.sid));
304 cont(s->caller_private_data, False, NULL, SID_NAME_UNKNOWN);
308 cont(s->caller_private_data, True, &sid,
309 (enum lsa_SidType)response->data.sid.type);
312 /********************************************************************
313 This is the first callback after contacting our own domain
314 ********************************************************************/
316 static void lookupname_recv(TALLOC_CTX *mem_ctx, bool success,
317 struct winbindd_response *response,
318 void *c, void *private_data)
320 void (*cont)(void *priv, bool succ, const DOM_SID *sid,
321 enum lsa_SidType type) =
322 (void (*)(void *, bool, const DOM_SID *, enum lsa_SidType))c;
324 struct lookupname_state *s = talloc_get_type_abort( private_data,
325 struct lookupname_state );
328 DEBUG(5, ("lookupname_recv: lookup_name() failed!\n"));
329 cont(s->caller_private_data, False, NULL, SID_NAME_UNKNOWN);
333 if (response->result != WINBINDD_OK) {
334 /* Try again using the forest root */
335 struct winbindd_domain *root_domain = find_root_domain();
336 struct winbindd_request request;
338 if ( !root_domain ) {
339 DEBUG(5,("lookupname_recv: unable to determine forest root\n"));
340 cont(s->caller_private_data, False, NULL, SID_NAME_UNKNOWN);
344 ZERO_STRUCT(request);
345 request.cmd = WINBINDD_LOOKUPNAME;
347 fstrcpy( request.data.name.dom_name, s->dom_name );
348 fstrcpy( request.data.name.name, s->name );
350 do_async_domain(mem_ctx, root_domain, &request, lookupname_recv2,
356 if (!string_to_sid(&sid, response->data.sid.sid)) {
357 DEBUG(0, ("Could not convert string %s to sid\n",
358 response->data.sid.sid));
359 cont(s->caller_private_data, False, NULL, SID_NAME_UNKNOWN);
363 cont(s->caller_private_data, True, &sid,
364 (enum lsa_SidType)response->data.sid.type);
367 /********************************************************************
368 The lookup name call first contacts a DC in its own domain
369 and fallbacks to contact a DC if the forest in our domain doesn't
371 ********************************************************************/
373 void winbindd_lookupname_async(TALLOC_CTX *mem_ctx,
374 const char *dom_name, const char *name,
375 void (*cont)(void *private_data, bool success,
377 enum lsa_SidType type),
378 enum winbindd_cmd orig_cmd,
381 struct winbindd_request request;
382 struct winbindd_domain *domain;
383 struct lookupname_state *s;
385 domain = find_lookup_domain_from_name(dom_name);
386 if (domain == NULL) {
387 DEBUG(5, ("Could not find domain for name '%s'\n", dom_name));
388 cont(private_data, False, NULL, SID_NAME_UNKNOWN);
392 ZERO_STRUCT(request);
393 request.cmd = WINBINDD_LOOKUPNAME;
394 request.original_cmd = orig_cmd;
395 fstrcpy(request.data.name.dom_name, dom_name);
396 fstrcpy(request.data.name.name, name);
398 if ( (s = TALLOC_ZERO_P(mem_ctx, struct lookupname_state)) == NULL ) {
399 DEBUG(0, ("winbindd_lookupname_async: talloc failed\n"));
400 cont(private_data, False, NULL, SID_NAME_UNKNOWN);
404 s->dom_name = talloc_strdup( s, dom_name );
405 s->name = talloc_strdup( s, name );
406 if (!s->dom_name || !s->name) {
407 cont(private_data, False, NULL, SID_NAME_UNKNOWN);
411 s->caller_private_data = private_data;
413 do_async_domain(mem_ctx, domain, &request, lookupname_recv,
417 enum winbindd_result winbindd_dual_lookupname(struct winbindd_domain *domain,
418 struct winbindd_cli_state *state)
420 enum lsa_SidType type;
421 char *name_domain, *name_user;
425 /* Ensure null termination */
426 state->request->data.name.dom_name[sizeof(state->request->data.name.dom_name)-1]='\0';
428 /* Ensure null termination */
429 state->request->data.name.name[sizeof(state->request->data.name.name)-1]='\0';
431 /* cope with the name being a fully qualified name */
432 p = strstr(state->request->data.name.name, lp_winbind_separator());
435 name_domain = state->request->data.name.name;
438 name_domain = state->request->data.name.dom_name;
439 name_user = state->request->data.name.name;
442 DEBUG(3, ("[%5lu]: lookupname %s%s%s\n", (unsigned long)state->pid,
443 name_domain, lp_winbind_separator(), name_user));
445 /* Lookup name from DC using lsa_lookup_names() */
446 if (!winbindd_lookup_sid_by_name(state->mem_ctx, state->request->original_cmd, domain, name_domain,
447 name_user, &sid, &type)) {
448 return WINBINDD_ERROR;
451 sid_to_fstring(state->response->data.sid.sid, &sid);
452 state->response->data.sid.type = type;
457 /* This is the first callback after enumerating users/groups from a domain */
458 static void listent_recv(TALLOC_CTX *mem_ctx, bool success,
459 struct winbindd_response *response,
460 void *c, void *private_data)
462 void (*cont)(void *priv, bool succ, fstring dom_name, char *data) =
463 (void (*)(void *, bool, fstring, char*))c;
465 if (!success || response->result != WINBINDD_OK) {
466 DEBUG(5, ("list_ent() failed!\n"));
467 cont(private_data, False, response->data.name.dom_name, NULL);
471 cont(private_data, True, response->data.name.dom_name,
472 (char *)response->extra_data.data);
475 /* Request the name of all users/groups in a single domain */
476 void winbindd_listent_async(TALLOC_CTX *mem_ctx,
477 struct winbindd_domain *domain,
478 void (*cont)(void *private_data, bool success,
479 fstring dom_name, char* extra_data),
480 void *private_data, enum ent_type type)
482 struct winbindd_request request;
484 ZERO_STRUCT(request);
485 if (type == LIST_USERS)
486 request.cmd = WINBINDD_LIST_USERS;
487 else if (type == LIST_GROUPS)
488 request.cmd = WINBINDD_LIST_GROUPS;
490 do_async_domain(mem_ctx, domain, &request, listent_recv,
491 (void *)cont, private_data);
494 enum winbindd_result winbindd_dual_list_users(struct winbindd_domain *domain,
495 struct winbindd_cli_state *state)
497 WINBIND_USERINFO *info;
499 struct winbindd_methods *methods;
500 uint32 num_entries = 0;
502 uint32_t extra_data_len = 0, i;
504 /* Must copy domain into response first for debugging in parent */
505 fstrcpy(state->response->data.name.dom_name, domain->name);
507 /* Query user info */
508 methods = domain->methods;
509 status = methods->query_user_list(domain, state->mem_ctx,
510 &num_entries, &info);
512 if (!NT_STATUS_IS_OK(status))
513 return WINBINDD_ERROR;
515 if (num_entries == 0)
518 /* Allocate some memory for extra data. Note that we limit
519 account names to sizeof(fstring) = 256 characters.
520 +1 for the ',' between group names */
521 extra_data = talloc_array(state->mem_ctx, char,
522 (sizeof(fstring) + 1) * num_entries);
525 DEBUG(0,("failed to enlarge buffer!\n"));
526 return WINBINDD_ERROR;
529 /* Pack user list into extra data fields */
530 for (i = 0; i < num_entries; i++) {
531 fstring acct_name, name;
533 if (info[i].acct_name == NULL)
534 fstrcpy(acct_name, "");
536 fstrcpy(acct_name, info[i].acct_name);
538 fill_domain_username(name, domain->name, acct_name, True);
539 /* Append to extra data */
540 memcpy(&extra_data[extra_data_len], name, strlen(name));
541 extra_data_len += strlen(name);
542 extra_data[extra_data_len++] = ',';
545 /* Assign extra_data fields in response structure */
547 /* remove trailing ',' */
548 extra_data[extra_data_len - 1] = '\0';
549 state->response->extra_data.data = extra_data;
550 state->response->length += extra_data_len;
556 enum winbindd_result winbindd_dual_list_groups(struct winbindd_domain *domain,
557 struct winbindd_cli_state *state)
559 struct getent_state groups;
561 uint32_t extra_data_len = 0, i;
565 /* Must copy domain into response first for debugging in parent */
566 fstrcpy(state->response->data.name.dom_name, domain->name);
567 fstrcpy(groups.domain_name, domain->name);
569 /* Get list of sam groups */
570 if (!get_sam_group_entries(&groups)) {
571 /* this domain is empty or in an error state */
572 return WINBINDD_ERROR;
575 /* Allocate some memory for extra data. Note that we limit
576 account names to sizeof(fstring) = 256 characters.
577 +1 for the ',' between group names */
578 extra_data = talloc_array(
579 state->mem_ctx, char,
580 (sizeof(fstring) + 1) * groups.num_sam_entries);
583 DEBUG(0,("failed to enlarge buffer!\n"));
584 SAFE_FREE(groups.sam_entries);
585 return WINBINDD_ERROR;
588 /* Pack group list into extra data fields */
589 for (i = 0; i < groups.num_sam_entries; i++) {
590 char *group_name = ((struct acct_info *)
591 groups.sam_entries)[i].acct_name;
594 fill_domain_username(name, domain->name, group_name, True);
595 /* Append to extra data */
596 memcpy(&extra_data[extra_data_len], name, strlen(name));
597 extra_data_len += strlen(name);
598 extra_data[extra_data_len++] = ',';
601 SAFE_FREE(groups.sam_entries);
603 /* Assign extra_data fields in response structure */
605 /* remove trailing ',' */
606 extra_data[extra_data_len - 1] = '\0';
607 state->response->extra_data.data = extra_data;
608 state->response->length += extra_data_len;
614 bool print_sidlist(TALLOC_CTX *mem_ctx, const DOM_SID *sids,
615 size_t num_sids, char **result, ssize_t *len)
622 for (i=0; i<num_sids; i++) {
624 sprintf_append(mem_ctx, result, len, &buflen,
625 "%s\n", sid_to_fstring(tmp, &sids[i]));
628 if ((num_sids != 0) && (*result == NULL)) {
635 bool parse_sidlist(TALLOC_CTX *mem_ctx, char *sidstr,
636 DOM_SID **sids, size_t *num_sids)
644 while (p[0] != '\0') {
648 DEBUG(0, ("Got invalid sidstr: %s\n", p));
653 if (!string_to_sid(&sid, p)) {
654 DEBUG(0, ("Could not parse sid %s\n", p));
657 if (!NT_STATUS_IS_OK(add_sid_to_array(mem_ctx, &sid, sids,
667 static bool parse_ridlist(TALLOC_CTX *mem_ctx, char *ridstr,
668 uint32 **rids, size_t *num_rids)
676 while (p[0] != '\0') {
679 rid = strtoul(p, &q, 10);
681 DEBUG(0, ("Got invalid ridstr: %s\n", p));
685 ADD_TO_ARRAY(mem_ctx, uint32, rid, rids, num_rids);
690 enum winbindd_result winbindd_dual_lookuprids(struct winbindd_domain *domain,
691 struct winbindd_cli_state *state)
694 size_t i, buflen, num_rids = 0;
699 enum lsa_SidType *types;
703 DEBUG(10, ("Looking up RIDs for domain %s (%s)\n",
704 state->request->domain_name,
705 state->request->data.sid));
707 if (!parse_ridlist(state->mem_ctx, state->request->extra_data.data,
709 DEBUG(5, ("Could not parse ridlist\n"));
710 return WINBINDD_ERROR;
713 if (!string_to_sid(&domain_sid, state->request->data.sid)) {
714 DEBUG(5, ("Could not parse domain sid %s\n",
715 state->request->data.sid));
716 return WINBINDD_ERROR;
719 status = domain->methods->rids_to_names(domain, state->mem_ctx,
720 &domain_sid, rids, num_rids,
724 if (!NT_STATUS_IS_OK(status) &&
725 !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
726 return WINBINDD_ERROR;
733 for (i=0; i<num_rids; i++) {
734 sprintf_append(state->mem_ctx, &result, &len, &buflen,
735 "%d %s\n", types[i], names[i]);
738 fstrcpy(state->response->data.domain_name, domain_name);
740 if (result != NULL) {
741 state->response->extra_data.data = result;
742 state->response->length += len+1;
748 static void getsidaliases_recv(TALLOC_CTX *mem_ctx, bool success,
749 struct winbindd_response *response,
750 void *c, void *private_data)
752 void (*cont)(void *priv, bool succ,
753 DOM_SID *aliases, size_t num_aliases) =
754 (void (*)(void *, bool, DOM_SID *, size_t))c;
756 DOM_SID *sids = NULL;
760 DEBUG(5, ("Could not trigger getsidaliases\n"));
761 cont(private_data, success, NULL, 0);
765 if (response->result != WINBINDD_OK) {
766 DEBUG(5, ("getsidaliases returned an error\n"));
767 cont(private_data, False, NULL, 0);
771 aliases_str = (char *)response->extra_data.data;
773 if (aliases_str == NULL) {
774 DEBUG(10, ("getsidaliases return 0 SIDs\n"));
775 cont(private_data, True, NULL, 0);
779 if (!parse_sidlist(mem_ctx, aliases_str, &sids, &num_sids)) {
780 DEBUG(0, ("Could not parse sids\n"));
781 cont(private_data, False, NULL, 0);
785 cont(private_data, True, sids, num_sids);
788 void winbindd_getsidaliases_async(struct winbindd_domain *domain,
790 const DOM_SID *sids, size_t num_sids,
791 void (*cont)(void *private_data,
793 const DOM_SID *aliases,
797 struct winbindd_request request;
802 cont(private_data, True, NULL, 0);
806 if (!print_sidlist(mem_ctx, sids, num_sids, &sidstr, &len)) {
807 cont(private_data, False, NULL, 0);
811 ZERO_STRUCT(request);
812 request.cmd = WINBINDD_DUAL_GETSIDALIASES;
813 request.extra_len = len;
814 request.extra_data.data = sidstr;
816 do_async_domain(mem_ctx, domain, &request, getsidaliases_recv,
817 (void *)cont, private_data);
820 struct gettoken_state {
823 struct winbindd_domain *alias_domain;
824 struct winbindd_domain *local_alias_domain;
825 struct winbindd_domain *builtin_domain;
828 void (*cont)(void *private_data, bool success, DOM_SID *sids, size_t num_sids);
832 static void gettoken_recvdomgroups(TALLOC_CTX *mem_ctx, bool success,
833 struct winbindd_response *response,
834 void *c, void *private_data);
835 static void gettoken_recvaliases(void *private_data, bool success,
836 const DOM_SID *aliases,
840 void winbindd_gettoken_async(TALLOC_CTX *mem_ctx, const DOM_SID *user_sid,
841 void (*cont)(void *private_data, bool success,
842 DOM_SID *sids, size_t num_sids),
845 struct winbindd_domain *domain;
846 struct winbindd_request request;
847 struct gettoken_state *state;
849 state = TALLOC_ZERO_P(mem_ctx, struct gettoken_state);
851 DEBUG(0, ("talloc failed\n"));
852 cont(private_data, False, NULL, 0);
856 state->mem_ctx = mem_ctx;
857 sid_copy(&state->user_sid, user_sid);
858 state->alias_domain = find_our_domain();
859 state->local_alias_domain = find_domain_from_name( get_global_sam_name() );
860 state->builtin_domain = find_builtin_domain();
862 state->private_data = private_data;
864 domain = find_domain_from_sid_noinit(user_sid);
865 if (domain == NULL) {
866 DEBUG(5, ("Could not find domain from SID %s\n",
867 sid_string_dbg(user_sid)));
868 cont(private_data, False, NULL, 0);
872 ZERO_STRUCT(request);
873 request.cmd = WINBINDD_GETUSERDOMGROUPS;
874 sid_to_fstring(request.data.sid, user_sid);
876 do_async_domain(mem_ctx, domain, &request, gettoken_recvdomgroups,
880 static void gettoken_recvdomgroups(TALLOC_CTX *mem_ctx, bool success,
881 struct winbindd_response *response,
882 void *c, void *private_data)
884 struct gettoken_state *state =
885 talloc_get_type_abort(private_data, struct gettoken_state);
889 DEBUG(10, ("Could not get domain groups\n"));
890 state->cont(state->private_data, False, NULL, 0);
894 sids_str = (char *)response->extra_data.data;
896 if (sids_str == NULL) {
897 /* This could be normal if we are dealing with a
898 local user and local groups */
900 if ( !sid_check_is_in_our_domain( &state->user_sid ) ) {
901 DEBUG(10, ("Received no domain groups\n"));
902 state->cont(state->private_data, True, NULL, 0);
910 if (!NT_STATUS_IS_OK(add_sid_to_array(mem_ctx, &state->user_sid,
911 &state->sids, &state->num_sids)))
913 DEBUG(0, ("Out of memory\n"));
914 state->cont(state->private_data, False, NULL, 0);
918 if (sids_str && !parse_sidlist(mem_ctx, sids_str, &state->sids,
920 DEBUG(0, ("Could not parse sids\n"));
921 state->cont(state->private_data, False, NULL, 0);
925 if (state->alias_domain == NULL) {
926 DEBUG(10, ("Don't expand domain local groups\n"));
927 state->cont(state->private_data, True, state->sids,
932 winbindd_getsidaliases_async(state->alias_domain, mem_ctx,
933 state->sids, state->num_sids,
934 gettoken_recvaliases, state);
937 static void gettoken_recvaliases(void *private_data, bool success,
938 const DOM_SID *aliases,
941 struct gettoken_state *state = (struct gettoken_state *)private_data;
945 DEBUG(10, ("Could not receive domain local groups\n"));
946 state->cont(state->private_data, False, NULL, 0);
950 for (i=0; i<num_aliases; i++) {
951 if (!NT_STATUS_IS_OK(add_sid_to_array(state->mem_ctx,
956 DEBUG(0, ("Out of memory\n"));
957 state->cont(state->private_data, False, NULL, 0);
962 if (state->local_alias_domain != NULL) {
963 struct winbindd_domain *local_domain = state->local_alias_domain;
964 DEBUG(10, ("Expanding our own local groups\n"));
965 state->local_alias_domain = NULL;
966 winbindd_getsidaliases_async(local_domain, state->mem_ctx,
967 state->sids, state->num_sids,
968 gettoken_recvaliases, state);
972 if (state->builtin_domain != NULL) {
973 struct winbindd_domain *builtin_domain = state->builtin_domain;
974 DEBUG(10, ("Expanding our own BUILTIN groups\n"));
975 state->builtin_domain = NULL;
976 winbindd_getsidaliases_async(builtin_domain, state->mem_ctx,
977 state->sids, state->num_sids,
978 gettoken_recvaliases, state);
982 state->cont(state->private_data, True, state->sids, state->num_sids);
985 static void query_user_recv(TALLOC_CTX *mem_ctx, bool success,
986 struct winbindd_response *response,
987 void *c, void *private_data)
989 void (*cont)(void *priv, bool succ, const char *acct_name,
990 const char *full_name, const char *homedir,
991 const char *shell, uint32 gid, uint32 group_rid) =
992 (void (*)(void *, bool, const char *, const char *,
993 const char *, const char *, uint32, uint32))c;
996 DEBUG(5, ("Could not trigger query_user\n"));
997 cont(private_data, False, NULL, NULL, NULL, NULL, -1, -1);
1001 if (response->result != WINBINDD_OK) {
1002 DEBUG(5, ("query_user returned an error\n"));
1003 cont(private_data, False, NULL, NULL, NULL, NULL, -1, -1);
1007 cont(private_data, True, response->data.user_info.acct_name,
1008 response->data.user_info.full_name,
1009 response->data.user_info.homedir,
1010 response->data.user_info.shell,
1011 response->data.user_info.primary_gid,
1012 response->data.user_info.group_rid);
1015 void query_user_async(TALLOC_CTX *mem_ctx, struct winbindd_domain *domain,
1017 void (*cont)(void *private_data, bool success,
1018 const char *acct_name,
1019 const char *full_name,
1020 const char *homedir,
1026 struct winbindd_request request;
1027 ZERO_STRUCT(request);
1028 request.cmd = WINBINDD_DUAL_USERINFO;
1029 sid_to_fstring(request.data.sid, sid);
1030 do_async_domain(mem_ctx, domain, &request, query_user_recv,
1031 (void *)cont, private_data);
1034 enum winbindd_result winbindd_dual_ping(struct winbindd_domain *domain,
1035 struct winbindd_cli_state *state)