2 Unix SMB/CIFS implementation.
4 Winbind rpc backend functions
6 Copyright (C) Tim Potter 2000-2001,2003
7 Copyright (C) Andrew Tridgell 2001
8 Copyright (C) Volker Lendecke 2005
9 Copyright (C) Guenther Deschner 2008 (pidl conversion)
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include "winbindd_rpc.h"
29 #include "../librpc/gen_ndr/ndr_samr_c.h"
30 #include "rpc_client/cli_pipe.h"
31 #include "rpc_client/cli_samr.h"
32 #include "rpc_client/cli_lsarpc.h"
33 #include "../libcli/security/security.h"
34 #include "libsmb/samlogon_cache.h"
37 #define DBGC_CLASS DBGC_WINBIND
39 static NTSTATUS winbindd_lookup_names(TALLOC_CTX *mem_ctx,
40 struct winbindd_domain *domain,
43 const char ***domains,
44 struct dom_sid **sids,
45 enum lsa_SidType **types);
47 /* Query display info for a domain. This returns enough information plus a
48 bit extra to give an overview of domain users for the User Manager
50 static NTSTATUS msrpc_query_user_list(struct winbindd_domain *domain,
54 struct rpc_pipe_client *samr_pipe = NULL;
55 struct policy_handle dom_pol;
56 uint32_t *rids = NULL;
60 DEBUG(3, ("msrpc_query_user_list\n"));
62 tmp_ctx = talloc_stackframe();
63 if (tmp_ctx == NULL) {
64 return NT_STATUS_NO_MEMORY;
67 if ( !winbindd_can_contact_domain( domain ) ) {
68 DEBUG(10,("query_user_list: No incoming trust for domain %s\n",
70 status = NT_STATUS_OK;
74 status = cm_connect_sam(domain, tmp_ctx, false, &samr_pipe, &dom_pol);
75 if (!NT_STATUS_IS_OK(status)) {
79 status = rpc_query_user_list(tmp_ctx,
84 if (!NT_STATUS_IS_OK(status)) {
89 *prids = talloc_move(mem_ctx, &rids);
98 /* list all domain groups */
99 static NTSTATUS msrpc_enum_dom_groups(struct winbindd_domain *domain,
102 struct wb_acct_info **pinfo)
104 struct rpc_pipe_client *samr_pipe;
105 struct policy_handle dom_pol;
106 struct wb_acct_info *info = NULL;
107 uint32_t num_info = 0;
111 DEBUG(3,("msrpc_enum_dom_groups\n"));
117 tmp_ctx = talloc_stackframe();
118 if (tmp_ctx == NULL) {
119 return NT_STATUS_NO_MEMORY;
122 if ( !winbindd_can_contact_domain( domain ) ) {
123 DEBUG(10,("enum_domain_groups: No incoming trust for domain %s\n",
125 status = NT_STATUS_OK;
129 status = cm_connect_sam(domain, tmp_ctx, false, &samr_pipe, &dom_pol);
130 if (!NT_STATUS_IS_OK(status)) {
134 status = rpc_enum_dom_groups(tmp_ctx,
139 if (!NT_STATUS_IS_OK(status)) {
144 *pnum_info = num_info;
148 *pinfo = talloc_move(mem_ctx, &info);
152 TALLOC_FREE(tmp_ctx);
156 /* List all domain groups */
158 static NTSTATUS msrpc_enum_local_groups(struct winbindd_domain *domain,
161 struct wb_acct_info **pinfo)
163 struct rpc_pipe_client *samr_pipe;
164 struct policy_handle dom_pol;
165 struct wb_acct_info *info = NULL;
166 uint32_t num_info = 0;
170 DEBUG(3,("msrpc_enum_local_groups\n"));
176 tmp_ctx = talloc_stackframe();
177 if (tmp_ctx == NULL) {
178 return NT_STATUS_NO_MEMORY;
181 if ( !winbindd_can_contact_domain( domain ) ) {
182 DEBUG(10,("enum_local_groups: No incoming trust for domain %s\n",
184 status = NT_STATUS_OK;
188 status = cm_connect_sam(domain, tmp_ctx, false, &samr_pipe, &dom_pol);
189 if (!NT_STATUS_IS_OK(status)) {
193 status = rpc_enum_local_groups(mem_ctx,
198 if (!NT_STATUS_IS_OK(status)) {
203 *pnum_info = num_info;
207 *pinfo = talloc_move(mem_ctx, &info);
211 TALLOC_FREE(tmp_ctx);
215 /* convert a single name to a sid in a domain */
216 static NTSTATUS msrpc_name_to_sid(struct winbindd_domain *domain,
218 const char *domain_name,
222 enum lsa_SidType *type)
225 struct dom_sid *sids = NULL;
226 enum lsa_SidType *types = NULL;
227 char *full_name = NULL;
228 const char *names[1];
229 NTSTATUS name_map_status = NT_STATUS_UNSUCCESSFUL;
230 char *mapped_name = NULL;
232 if (name == NULL || *name=='\0') {
233 full_name = talloc_asprintf(mem_ctx, "%s", domain_name);
234 } else if (domain_name == NULL || *domain_name == '\0') {
235 full_name = talloc_asprintf(mem_ctx, "%s", name);
237 full_name = talloc_asprintf(mem_ctx, "%s\\%s", domain_name, name);
240 DEBUG(0, ("talloc_asprintf failed!\n"));
241 return NT_STATUS_NO_MEMORY;
244 DEBUG(3, ("msrpc_name_to_sid: name=%s\n", full_name));
246 name_map_status = normalize_name_unmap(mem_ctx, full_name,
249 /* Reset the full_name pointer if we mapped anything */
251 if (NT_STATUS_IS_OK(name_map_status) ||
252 NT_STATUS_EQUAL(name_map_status, NT_STATUS_FILE_RENAMED))
254 full_name = mapped_name;
257 DEBUG(3,("name_to_sid [rpc] %s for domain %s\n",
258 full_name?full_name:"", domain_name ));
260 names[0] = full_name;
262 result = winbindd_lookup_names(mem_ctx, domain, 1,
265 if (!NT_STATUS_IS_OK(result))
268 /* Return rid and type if lookup successful */
270 sid_copy(sid, &sids[0]);
277 convert a domain SID to a user or group name
279 static NTSTATUS msrpc_sid_to_name(struct winbindd_domain *domain,
281 const struct dom_sid *sid,
284 enum lsa_SidType *type)
288 enum lsa_SidType *types = NULL;
290 NTSTATUS name_map_status = NT_STATUS_UNSUCCESSFUL;
291 char *mapped_name = NULL;
293 DEBUG(3, ("msrpc_sid_to_name: %s for domain %s\n", sid_string_dbg(sid),
296 result = winbindd_lookup_sids(mem_ctx,
303 if (!NT_STATUS_IS_OK(result)) {
304 DEBUG(2,("msrpc_sid_to_name: failed to lookup sids: %s\n",
310 *type = (enum lsa_SidType)types[0];
311 *domain_name = domains[0];
314 DEBUG(5,("Mapped sid to [%s]\\[%s]\n", domains[0], *name));
316 name_map_status = normalize_name_map(mem_ctx, domain, *name,
318 if (NT_STATUS_IS_OK(name_map_status) ||
319 NT_STATUS_EQUAL(name_map_status, NT_STATUS_FILE_RENAMED))
322 DEBUG(5,("returning mapped name -- %s\n", *name));
328 static NTSTATUS msrpc_rids_to_names(struct winbindd_domain *domain,
330 const struct dom_sid *sid,
335 enum lsa_SidType **types)
339 struct dom_sid *sids;
343 DEBUG(3, ("msrpc_rids_to_names: domain %s\n", domain->name ));
346 sids = talloc_array(mem_ctx, struct dom_sid, num_rids);
348 return NT_STATUS_NO_MEMORY;
354 for (i=0; i<num_rids; i++) {
355 if (!sid_compose(&sids[i], sid, rids[i])) {
356 return NT_STATUS_INTERNAL_ERROR;
360 result = winbindd_lookup_sids(mem_ctx,
368 if (!NT_STATUS_IS_OK(result) &&
369 !NT_STATUS_EQUAL(result, STATUS_SOME_UNMAPPED)) {
374 for (i=0; i<num_rids; i++) {
375 NTSTATUS name_map_status = NT_STATUS_UNSUCCESSFUL;
376 char *mapped_name = NULL;
378 if ((*types)[i] != SID_NAME_UNKNOWN) {
379 name_map_status = normalize_name_map(mem_ctx,
383 if (NT_STATUS_IS_OK(name_map_status) ||
384 NT_STATUS_EQUAL(name_map_status, NT_STATUS_FILE_RENAMED))
386 ret_names[i] = mapped_name;
389 *domain_name = domains[i];
396 /* Lookup groups a user is a member of. I wish Unix had a call like this! */
397 static NTSTATUS msrpc_lookup_usergroups(struct winbindd_domain *domain,
399 const struct dom_sid *user_sid,
400 uint32_t *pnum_groups,
401 struct dom_sid **puser_grpsids)
403 struct rpc_pipe_client *samr_pipe;
404 struct policy_handle dom_pol;
405 struct dom_sid *user_grpsids = NULL;
406 uint32_t num_groups = 0;
410 DEBUG(3,("msrpc_lookup_usergroups sid=%s\n", sid_string_dbg(user_sid)));
414 tmp_ctx = talloc_stackframe();
415 if (tmp_ctx == NULL) {
416 return NT_STATUS_NO_MEMORY;
419 /* Check if we have a cached user_info_3 */
420 status = lookup_usergroups_cached(tmp_ctx,
424 if (NT_STATUS_IS_OK(status)) {
428 if ( !winbindd_can_contact_domain( domain ) ) {
429 DEBUG(10,("lookup_usergroups: No incoming trust for domain %s\n",
432 /* Tell the cache manager not to remember this one */
433 status = NT_STATUS_SYNCHRONIZATION_REQUIRED;
437 /* no cache; hit the wire */
438 status = cm_connect_sam(domain, tmp_ctx, false, &samr_pipe, &dom_pol);
439 if (!NT_STATUS_IS_OK(status)) {
443 status = rpc_lookup_usergroups(tmp_ctx,
450 if (!NT_STATUS_IS_OK(status)) {
455 *pnum_groups = num_groups;
458 *puser_grpsids = talloc_move(mem_ctx, &user_grpsids);
462 TALLOC_FREE(tmp_ctx);
467 #define MAX_SAM_ENTRIES_W2K 0x400 /* 1024 */
469 static NTSTATUS msrpc_lookup_useraliases(struct winbindd_domain *domain,
471 uint32_t num_sids, const struct dom_sid *sids,
472 uint32_t *pnum_aliases,
473 uint32_t **palias_rids)
475 struct rpc_pipe_client *samr_pipe;
476 struct policy_handle dom_pol;
477 uint32_t num_aliases = 0;
478 uint32_t *alias_rids = NULL;
482 DEBUG(3,("msrpc_lookup_useraliases\n"));
488 tmp_ctx = talloc_stackframe();
489 if (tmp_ctx == NULL) {
490 return NT_STATUS_NO_MEMORY;
493 if (!winbindd_can_contact_domain(domain)) {
494 DEBUG(10,("msrpc_lookup_useraliases: No incoming trust for domain %s\n",
496 /* Tell the cache manager not to remember this one */
497 status = NT_STATUS_SYNCHRONIZATION_REQUIRED;
501 status = cm_connect_sam(domain, tmp_ctx, false, &samr_pipe, &dom_pol);
502 if (!NT_STATUS_IS_OK(status)) {
506 status = rpc_lookup_useraliases(tmp_ctx,
513 if (!NT_STATUS_IS_OK(status)) {
518 *pnum_aliases = num_aliases;
522 *palias_rids = talloc_move(mem_ctx, &alias_rids);
526 TALLOC_FREE(tmp_ctx);
531 /* Lookup group membership given a rid. */
532 static NTSTATUS msrpc_lookup_groupmem(struct winbindd_domain *domain,
534 const struct dom_sid *group_sid,
535 enum lsa_SidType type,
537 struct dom_sid **sid_mem,
539 uint32_t **name_types)
541 NTSTATUS status, result;
542 uint32_t i, total_names = 0;
543 struct policy_handle dom_pol, group_pol;
544 uint32_t des_access = SEC_FLAG_MAXIMUM_ALLOWED;
545 uint32_t *rid_mem = NULL;
548 struct rpc_pipe_client *cli;
549 unsigned int orig_timeout;
550 struct samr_RidAttrArray *rids = NULL;
551 struct dcerpc_binding_handle *b;
553 DEBUG(3,("msrpc_lookup_groupmem: %s sid=%s\n", domain->name,
554 sid_string_dbg(group_sid)));
556 if ( !winbindd_can_contact_domain( domain ) ) {
557 DEBUG(10,("lookup_groupmem: No incoming trust for domain %s\n",
562 if (!sid_peek_check_rid(&domain->sid, group_sid, &group_rid))
563 return NT_STATUS_UNSUCCESSFUL;
567 result = cm_connect_sam(domain, mem_ctx, false, &cli, &dom_pol);
568 if (!NT_STATUS_IS_OK(result))
571 b = cli->binding_handle;
573 status = dcerpc_samr_OpenGroup(b, mem_ctx,
579 if (!NT_STATUS_IS_OK(status)) {
582 if (!NT_STATUS_IS_OK(result)) {
586 /* Step #1: Get a list of user rids that are the members of the
589 /* This call can take a long time - allow the server to time out.
590 35 seconds should do it. */
592 orig_timeout = rpccli_set_timeout(cli, 35000);
594 status = dcerpc_samr_QueryGroupMember(b, mem_ctx,
599 /* And restore our original timeout. */
600 rpccli_set_timeout(cli, orig_timeout);
604 dcerpc_samr_Close(b, mem_ctx, &group_pol, &_result);
607 if (!NT_STATUS_IS_OK(status)) {
611 if (!NT_STATUS_IS_OK(result)) {
615 if (!rids || !rids->count) {
622 *num_names = rids->count;
623 rid_mem = rids->rids;
625 /* Step #2: Convert list of rids into list of usernames. Do this
626 in bunches of ~1000 to avoid crashing NT4. It looks like there
627 is a buffer overflow or something like that lurking around
630 #define MAX_LOOKUP_RIDS 900
632 *names = talloc_zero_array(mem_ctx, char *, *num_names);
633 *name_types = talloc_zero_array(mem_ctx, uint32_t, *num_names);
634 *sid_mem = talloc_zero_array(mem_ctx, struct dom_sid, *num_names);
636 for (j=0;j<(*num_names);j++)
637 sid_compose(&(*sid_mem)[j], &domain->sid, rid_mem[j]);
639 if (*num_names>0 && (!*names || !*name_types))
640 return NT_STATUS_NO_MEMORY;
642 for (i = 0; i < *num_names; i += MAX_LOOKUP_RIDS) {
643 int num_lookup_rids = MIN(*num_names - i, MAX_LOOKUP_RIDS);
644 struct lsa_Strings tmp_names;
645 struct samr_Ids tmp_types;
647 /* Lookup a chunk of rids */
649 status = dcerpc_samr_LookupRids(b, mem_ctx,
656 if (!NT_STATUS_IS_OK(status)) {
660 /* see if we have a real error (and yes the
661 STATUS_SOME_UNMAPPED is the one returned from 2k) */
663 if (!NT_STATUS_IS_OK(result) &&
664 !NT_STATUS_EQUAL(result, STATUS_SOME_UNMAPPED))
667 /* Copy result into array. The talloc system will take
668 care of freeing the temporary arrays later on. */
670 if (tmp_names.count != num_lookup_rids) {
671 return NT_STATUS_INVALID_NETWORK_RESPONSE;
673 if (tmp_types.count != num_lookup_rids) {
674 return NT_STATUS_INVALID_NETWORK_RESPONSE;
677 for (r=0; r<tmp_names.count; r++) {
678 if (tmp_types.ids[r] == SID_NAME_UNKNOWN) {
681 if (total_names >= *num_names) {
684 (*names)[total_names] = fill_domain_username_talloc(
685 mem_ctx, domain->name,
686 tmp_names.names[r].string, true);
687 (*name_types)[total_names] = tmp_types.ids[r];
692 *num_names = total_names;
701 static int get_ldap_seq(const char *server, struct sockaddr_storage *ss, int port, uint32_t *seq)
705 const char *attrs[] = {"highestCommittedUSN", NULL};
706 LDAPMessage *res = NULL;
707 char **values = NULL;
710 *seq = DOM_SEQUENCE_NONE;
713 * Parameterised (5) second timeout on open. This is needed as the
714 * search timeout doesn't seem to apply to doing an open as well. JRA.
717 ldp = ldap_open_with_timeout(server, ss, port, lp_ldap_timeout());
721 /* Timeout if no response within 20 seconds. */
725 if (ldap_search_st(ldp, "", LDAP_SCOPE_BASE, "(objectclass=*)",
726 discard_const_p(char *, attrs), 0, &to, &res))
729 if (ldap_count_entries(ldp, res) != 1)
732 values = ldap_get_values(ldp, res, "highestCommittedUSN");
733 if (!values || !values[0])
736 *seq = atoi(values[0]);
742 ldap_value_free(values);
750 /**********************************************************************
751 Get the sequence number for a Windows AD native mode domain using
753 **********************************************************************/
755 static int get_ldap_sequence_number(struct winbindd_domain *domain, uint32_t *seq)
758 char addr[INET6_ADDRSTRLEN];
760 print_sockaddr(addr, sizeof(addr), &domain->dcaddr);
761 if ((ret = get_ldap_seq(addr, &domain->dcaddr, LDAP_PORT, seq)) == 0) {
762 DEBUG(3, ("get_ldap_sequence_number: Retrieved sequence "
763 "number for Domain (%s) from DC (%s)\n",
764 domain->name, addr));
769 #endif /* HAVE_LDAP */
771 /* find the sequence number for a domain */
772 static NTSTATUS msrpc_sequence_number(struct winbindd_domain *domain,
775 struct rpc_pipe_client *samr_pipe;
776 struct policy_handle dom_pol;
777 uint32_t seq = DOM_SEQUENCE_NONE;
781 DEBUG(3, ("msrpc_sequence_number: fetch sequence_number for %s\n", domain->name));
784 *pseq = DOM_SEQUENCE_NONE;
787 tmp_ctx = talloc_stackframe();
788 if (tmp_ctx == NULL) {
789 return NT_STATUS_NO_MEMORY;
792 if ( !winbindd_can_contact_domain( domain ) ) {
793 DEBUG(10,("sequence_number: No incoming trust for domain %s\n",
798 status = NT_STATUS_OK;
803 if (domain->active_directory) {
806 DEBUG(8,("using get_ldap_seq() to retrieve the "
807 "sequence number\n"));
809 rc = get_ldap_sequence_number(domain, &seq);
811 DEBUG(10,("domain_sequence_number: LDAP for "
819 status = NT_STATUS_OK;
823 DEBUG(10,("domain_sequence_number: failed to get LDAP "
824 "sequence number for domain %s\n",
827 #endif /* HAVE_LDAP */
829 status = cm_connect_sam(domain, tmp_ctx, false, &samr_pipe, &dom_pol);
830 if (!NT_STATUS_IS_OK(status)) {
834 status = rpc_sequence_number(tmp_ctx,
839 if (!NT_STATUS_IS_OK(status)) {
848 TALLOC_FREE(tmp_ctx);
852 /* get a list of trusted domains */
853 static NTSTATUS msrpc_trusted_domains(struct winbindd_domain *domain,
855 struct netr_DomainTrustList *ptrust_list)
857 struct rpc_pipe_client *lsa_pipe;
858 struct policy_handle lsa_policy;
859 struct netr_DomainTrust *trusts = NULL;
860 uint32_t num_trusts = 0;
864 DEBUG(3,("msrpc_trusted_domains\n"));
867 ZERO_STRUCTP(ptrust_list);
870 tmp_ctx = talloc_stackframe();
871 if (tmp_ctx == NULL) {
872 return NT_STATUS_NO_MEMORY;
875 status = cm_connect_lsa(domain, tmp_ctx, &lsa_pipe, &lsa_policy);
876 if (!NT_STATUS_IS_OK(status)) {
880 status = rpc_trusted_domains(tmp_ctx,
885 if (!NT_STATUS_IS_OK(status)) {
890 ptrust_list->count = num_trusts;
891 ptrust_list->array = talloc_move(mem_ctx, &trusts);
895 TALLOC_FREE(tmp_ctx);
899 /* find the lockout policy for a domain */
900 static NTSTATUS msrpc_lockout_policy(struct winbindd_domain *domain,
902 struct samr_DomInfo12 *lockout_policy)
904 NTSTATUS status, result;
905 struct rpc_pipe_client *cli;
906 struct policy_handle dom_pol;
907 union samr_DomainInfo *info = NULL;
908 struct dcerpc_binding_handle *b;
910 DEBUG(3, ("msrpc_lockout_policy: fetch lockout policy for %s\n", domain->name));
912 if ( !winbindd_can_contact_domain( domain ) ) {
913 DEBUG(10,("msrpc_lockout_policy: No incoming trust for domain %s\n",
915 return NT_STATUS_NOT_SUPPORTED;
918 status = cm_connect_sam(domain, mem_ctx, false, &cli, &dom_pol);
919 if (!NT_STATUS_IS_OK(status)) {
923 b = cli->binding_handle;
925 status = dcerpc_samr_QueryDomainInfo(b, mem_ctx,
927 DomainLockoutInformation,
930 if (!NT_STATUS_IS_OK(status)) {
933 if (!NT_STATUS_IS_OK(result)) {
938 *lockout_policy = info->info12;
940 DEBUG(10,("msrpc_lockout_policy: lockout_threshold %d\n",
941 info->info12.lockout_threshold));
948 /* find the password policy for a domain */
949 static NTSTATUS msrpc_password_policy(struct winbindd_domain *domain,
951 struct samr_DomInfo1 *password_policy)
953 NTSTATUS status, result;
954 struct rpc_pipe_client *cli;
955 struct policy_handle dom_pol;
956 union samr_DomainInfo *info = NULL;
957 struct dcerpc_binding_handle *b;
959 DEBUG(3, ("msrpc_password_policy: fetch password policy for %s\n",
962 if ( !winbindd_can_contact_domain( domain ) ) {
963 DEBUG(10,("msrpc_password_policy: No incoming trust for domain %s\n",
965 return NT_STATUS_NOT_SUPPORTED;
968 status = cm_connect_sam(domain, mem_ctx, false, &cli, &dom_pol);
969 if (!NT_STATUS_IS_OK(status)) {
973 b = cli->binding_handle;
975 status = dcerpc_samr_QueryDomainInfo(b, mem_ctx,
977 DomainPasswordInformation,
980 if (!NT_STATUS_IS_OK(status)) {
983 if (!NT_STATUS_IS_OK(result)) {
987 *password_policy = info->info1;
989 DEBUG(10,("msrpc_password_policy: min_length_password %d\n",
990 info->info1.min_password_length));
997 NTSTATUS winbindd_lookup_sids(TALLOC_CTX *mem_ctx,
998 struct winbindd_domain *domain,
1000 const struct dom_sid *sids,
1003 enum lsa_SidType **types)
1007 struct rpc_pipe_client *cli = NULL;
1008 struct dcerpc_binding_handle *b = NULL;
1009 struct policy_handle lsa_policy;
1010 unsigned int orig_timeout;
1011 bool use_lookupsids3 = false;
1012 bool retried = false;
1015 status = cm_connect_lsat(domain, mem_ctx, &cli, &lsa_policy);
1016 if (!NT_STATUS_IS_OK(status)) {
1020 b = cli->binding_handle;
1022 if (cli->transport->transport == NCACN_IP_TCP) {
1023 use_lookupsids3 = true;
1027 * This call can take a long time
1028 * allow the server to time out.
1029 * 35 seconds should do it.
1031 orig_timeout = dcerpc_binding_handle_set_timeout(b, 35000);
1033 status = dcerpc_lsa_lookup_sids_generic(b,
1044 /* And restore our original timeout. */
1045 dcerpc_binding_handle_set_timeout(b, orig_timeout);
1047 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
1048 NT_STATUS_EQUAL(status, NT_STATUS_RPC_SEC_PKG_ERROR) ||
1049 NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_ACCESS_DENIED)) {
1051 * This can happen if the schannel key is not
1052 * valid anymore, we need to invalidate the
1053 * all connections to the dc and reestablish
1054 * a netlogon connection first.
1056 invalidate_cm_connection(domain);
1057 domain->can_do_ncacn_ip_tcp = domain->active_directory;
1062 status = NT_STATUS_ACCESS_DENIED;
1065 if (!NT_STATUS_IS_OK(status)) {
1069 if (!NT_STATUS_IS_OK(result)) {
1073 return NT_STATUS_OK;
1076 static NTSTATUS winbindd_lookup_names(TALLOC_CTX *mem_ctx,
1077 struct winbindd_domain *domain,
1080 const char ***domains,
1081 struct dom_sid **sids,
1082 enum lsa_SidType **types)
1086 struct rpc_pipe_client *cli = NULL;
1087 struct dcerpc_binding_handle *b = NULL;
1088 struct policy_handle lsa_policy;
1089 unsigned int orig_timeout = 0;
1090 bool use_lookupnames4 = false;
1091 bool retried = false;
1094 status = cm_connect_lsat(domain, mem_ctx, &cli, &lsa_policy);
1095 if (!NT_STATUS_IS_OK(status)) {
1099 b = cli->binding_handle;
1101 if (cli->transport->transport == NCACN_IP_TCP) {
1102 use_lookupnames4 = true;
1106 * This call can take a long time
1107 * allow the server to time out.
1108 * 35 seconds should do it.
1110 orig_timeout = dcerpc_binding_handle_set_timeout(b, 35000);
1112 status = dcerpc_lsa_lookup_names_generic(b,
1116 (const char **) names,
1124 /* And restore our original timeout. */
1125 dcerpc_binding_handle_set_timeout(b, orig_timeout);
1127 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
1128 NT_STATUS_EQUAL(status, NT_STATUS_RPC_SEC_PKG_ERROR) ||
1129 NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_ACCESS_DENIED)) {
1131 * This can happen if the schannel key is not
1132 * valid anymore, we need to invalidate the
1133 * all connections to the dc and reestablish
1134 * a netlogon connection first.
1136 invalidate_cm_connection(domain);
1141 status = NT_STATUS_ACCESS_DENIED;
1144 if (!NT_STATUS_IS_OK(status)) {
1148 if (!NT_STATUS_IS_OK(result)) {
1152 return NT_STATUS_OK;
1155 /* the rpc backend methods are exposed via this structure */
1156 struct winbindd_methods msrpc_methods = {
1158 msrpc_query_user_list,
1159 msrpc_enum_dom_groups,
1160 msrpc_enum_local_groups,
1163 msrpc_rids_to_names,
1164 msrpc_lookup_usergroups,
1165 msrpc_lookup_useraliases,
1166 msrpc_lookup_groupmem,
1167 msrpc_sequence_number,
1168 msrpc_lockout_policy,
1169 msrpc_password_policy,
1170 msrpc_trusted_domains,