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"
36 #define DBGC_CLASS DBGC_WINBIND
38 static NTSTATUS
winbindd_lookup_names(TALLOC_CTX
*mem_ctx
,
39 struct winbindd_domain
*domain
,
42 const char ***domains
,
43 struct dom_sid
**sids
,
44 enum lsa_SidType
**types
);
46 /* Query display info for a domain. This returns enough information plus a
47 bit extra to give an overview of domain users for the User Manager
49 static NTSTATUS
msrpc_query_user_list(struct winbindd_domain
*domain
,
52 struct wbint_userinfo
**pinfo
)
54 struct rpc_pipe_client
*samr_pipe
= NULL
;
55 struct policy_handle dom_pol
;
56 struct wbint_userinfo
*info
= NULL
;
57 uint32_t num_info
= 0;
61 DEBUG(3, ("msrpc_query_user_list\n"));
67 tmp_ctx
= talloc_stackframe();
68 if (tmp_ctx
== NULL
) {
69 return NT_STATUS_NO_MEMORY
;
72 if ( !winbindd_can_contact_domain( domain
) ) {
73 DEBUG(10,("query_user_list: No incoming trust for domain %s\n",
75 status
= NT_STATUS_OK
;
79 status
= cm_connect_sam(domain
, tmp_ctx
, false, &samr_pipe
, &dom_pol
);
80 if (!NT_STATUS_IS_OK(status
)) {
84 status
= rpc_query_user_list(tmp_ctx
,
90 if (!NT_STATUS_IS_OK(status
)) {
95 *pnum_info
= num_info
;
99 *pinfo
= talloc_move(mem_ctx
, &info
);
103 TALLOC_FREE(tmp_ctx
);
107 /* list all domain groups */
108 static NTSTATUS
msrpc_enum_dom_groups(struct winbindd_domain
*domain
,
111 struct wb_acct_info
**pinfo
)
113 struct rpc_pipe_client
*samr_pipe
;
114 struct policy_handle dom_pol
;
115 struct wb_acct_info
*info
= NULL
;
116 uint32_t num_info
= 0;
120 DEBUG(3,("msrpc_enum_dom_groups\n"));
126 tmp_ctx
= talloc_stackframe();
127 if (tmp_ctx
== NULL
) {
128 return NT_STATUS_NO_MEMORY
;
131 if ( !winbindd_can_contact_domain( domain
) ) {
132 DEBUG(10,("enum_domain_groups: No incoming trust for domain %s\n",
134 status
= NT_STATUS_OK
;
138 status
= cm_connect_sam(domain
, tmp_ctx
, false, &samr_pipe
, &dom_pol
);
139 if (!NT_STATUS_IS_OK(status
)) {
143 status
= rpc_enum_dom_groups(tmp_ctx
,
148 if (!NT_STATUS_IS_OK(status
)) {
153 *pnum_info
= num_info
;
157 *pinfo
= talloc_move(mem_ctx
, &info
);
161 TALLOC_FREE(tmp_ctx
);
165 /* List all domain groups */
167 static NTSTATUS
msrpc_enum_local_groups(struct winbindd_domain
*domain
,
170 struct wb_acct_info
**pinfo
)
172 struct rpc_pipe_client
*samr_pipe
;
173 struct policy_handle dom_pol
;
174 struct wb_acct_info
*info
= NULL
;
175 uint32_t num_info
= 0;
179 DEBUG(3,("msrpc_enum_local_groups\n"));
185 tmp_ctx
= talloc_stackframe();
186 if (tmp_ctx
== NULL
) {
187 return NT_STATUS_NO_MEMORY
;
190 if ( !winbindd_can_contact_domain( domain
) ) {
191 DEBUG(10,("enum_local_groups: No incoming trust for domain %s\n",
193 status
= NT_STATUS_OK
;
197 status
= cm_connect_sam(domain
, tmp_ctx
, false, &samr_pipe
, &dom_pol
);
198 if (!NT_STATUS_IS_OK(status
)) {
202 status
= rpc_enum_local_groups(mem_ctx
,
207 if (!NT_STATUS_IS_OK(status
)) {
212 *pnum_info
= num_info
;
216 *pinfo
= talloc_move(mem_ctx
, &info
);
220 TALLOC_FREE(tmp_ctx
);
224 /* convert a single name to a sid in a domain */
225 static NTSTATUS
msrpc_name_to_sid(struct winbindd_domain
*domain
,
227 const char *domain_name
,
231 enum lsa_SidType
*type
)
234 struct dom_sid
*sids
= NULL
;
235 enum lsa_SidType
*types
= NULL
;
236 char *full_name
= NULL
;
237 const char *names
[1];
238 NTSTATUS name_map_status
= NT_STATUS_UNSUCCESSFUL
;
239 char *mapped_name
= NULL
;
241 if (name
== NULL
|| *name
=='\0') {
242 full_name
= talloc_asprintf(mem_ctx
, "%s", domain_name
);
243 } else if (domain_name
== NULL
|| *domain_name
== '\0') {
244 full_name
= talloc_asprintf(mem_ctx
, "%s", name
);
246 full_name
= talloc_asprintf(mem_ctx
, "%s\\%s", domain_name
, name
);
249 DEBUG(0, ("talloc_asprintf failed!\n"));
250 return NT_STATUS_NO_MEMORY
;
253 DEBUG(3, ("msrpc_name_to_sid: name=%s\n", full_name
));
255 name_map_status
= normalize_name_unmap(mem_ctx
, full_name
,
258 /* Reset the full_name pointer if we mapped anything */
260 if (NT_STATUS_IS_OK(name_map_status
) ||
261 NT_STATUS_EQUAL(name_map_status
, NT_STATUS_FILE_RENAMED
))
263 full_name
= mapped_name
;
266 DEBUG(3,("name_to_sid [rpc] %s for domain %s\n",
267 full_name
?full_name
:"", domain_name
));
269 names
[0] = full_name
;
271 result
= winbindd_lookup_names(mem_ctx
, domain
, 1,
274 if (!NT_STATUS_IS_OK(result
))
277 /* Return rid and type if lookup successful */
279 sid_copy(sid
, &sids
[0]);
286 convert a domain SID to a user or group name
288 static NTSTATUS
msrpc_sid_to_name(struct winbindd_domain
*domain
,
290 const struct dom_sid
*sid
,
293 enum lsa_SidType
*type
)
297 enum lsa_SidType
*types
= NULL
;
299 NTSTATUS name_map_status
= NT_STATUS_UNSUCCESSFUL
;
300 char *mapped_name
= NULL
;
302 DEBUG(3, ("msrpc_sid_to_name: %s for domain %s\n", sid_string_dbg(sid
),
305 result
= winbindd_lookup_sids(mem_ctx
,
312 if (!NT_STATUS_IS_OK(result
)) {
313 DEBUG(2,("msrpc_sid_to_name: failed to lookup sids: %s\n",
319 *type
= (enum lsa_SidType
)types
[0];
320 *domain_name
= domains
[0];
323 DEBUG(5,("Mapped sid to [%s]\\[%s]\n", domains
[0], *name
));
325 name_map_status
= normalize_name_map(mem_ctx
, domain
, *name
,
327 if (NT_STATUS_IS_OK(name_map_status
) ||
328 NT_STATUS_EQUAL(name_map_status
, NT_STATUS_FILE_RENAMED
))
331 DEBUG(5,("returning mapped name -- %s\n", *name
));
337 static NTSTATUS
msrpc_rids_to_names(struct winbindd_domain
*domain
,
339 const struct dom_sid
*sid
,
344 enum lsa_SidType
**types
)
348 struct dom_sid
*sids
;
352 DEBUG(3, ("msrpc_rids_to_names: domain %s\n", domain
->name
));
355 sids
= talloc_array(mem_ctx
, struct dom_sid
, num_rids
);
357 return NT_STATUS_NO_MEMORY
;
363 for (i
=0; i
<num_rids
; i
++) {
364 if (!sid_compose(&sids
[i
], sid
, rids
[i
])) {
365 return NT_STATUS_INTERNAL_ERROR
;
369 result
= winbindd_lookup_sids(mem_ctx
,
377 if (!NT_STATUS_IS_OK(result
) &&
378 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
)) {
383 for (i
=0; i
<num_rids
; i
++) {
384 NTSTATUS name_map_status
= NT_STATUS_UNSUCCESSFUL
;
385 char *mapped_name
= NULL
;
387 if ((*types
)[i
] != SID_NAME_UNKNOWN
) {
388 name_map_status
= normalize_name_map(mem_ctx
,
392 if (NT_STATUS_IS_OK(name_map_status
) ||
393 NT_STATUS_EQUAL(name_map_status
, NT_STATUS_FILE_RENAMED
))
395 ret_names
[i
] = mapped_name
;
398 *domain_name
= domains
[i
];
405 /* Lookup user information from a rid or username. */
406 static NTSTATUS
msrpc_query_user(struct winbindd_domain
*domain
,
408 const struct dom_sid
*user_sid
,
409 struct wbint_userinfo
*user_info
)
411 struct rpc_pipe_client
*samr_pipe
;
412 struct policy_handle dom_pol
;
413 struct netr_SamInfo3
*user
;
417 DEBUG(3,("msrpc_query_user sid=%s\n", sid_string_dbg(user_sid
)));
419 tmp_ctx
= talloc_stackframe();
420 if (tmp_ctx
== NULL
) {
421 return NT_STATUS_NO_MEMORY
;
425 user_info
->homedir
= NULL
;
426 user_info
->shell
= NULL
;
427 user_info
->primary_gid
= (gid_t
)-1;
430 /* try netsamlogon cache first */
431 user
= netsamlogon_cache_get(tmp_ctx
, user_sid
);
433 DEBUG(5,("msrpc_query_user: Cache lookup succeeded for %s\n",
434 sid_string_dbg(user_sid
)));
436 sid_compose(&user_info
->user_sid
, &domain
->sid
, user
->base
.rid
);
437 sid_compose(&user_info
->group_sid
, &domain
->sid
,
438 user
->base
.primary_gid
);
440 user_info
->acct_name
= talloc_strdup(user_info
,
441 user
->base
.account_name
.string
);
442 user_info
->full_name
= talloc_strdup(user_info
,
443 user
->base
.full_name
.string
);
445 if (user_info
->full_name
== NULL
) {
446 /* this might fail so we dont check the return code */
447 wcache_query_user_fullname(domain
,
450 &user_info
->full_name
);
453 status
= NT_STATUS_OK
;
457 if ( !winbindd_can_contact_domain( domain
) ) {
458 DEBUG(10,("query_user: No incoming trust for domain %s\n",
460 /* Tell the cache manager not to remember this one */
461 status
= NT_STATUS_SYNCHRONIZATION_REQUIRED
;
465 /* no cache; hit the wire */
466 status
= cm_connect_sam(domain
, tmp_ctx
, false, &samr_pipe
, &dom_pol
);
467 if (!NT_STATUS_IS_OK(status
)) {
471 status
= rpc_query_user(tmp_ctx
,
479 TALLOC_FREE(tmp_ctx
);
483 /* Lookup groups a user is a member of. I wish Unix had a call like this! */
484 static NTSTATUS
msrpc_lookup_usergroups(struct winbindd_domain
*domain
,
486 const struct dom_sid
*user_sid
,
487 uint32_t *pnum_groups
,
488 struct dom_sid
**puser_grpsids
)
490 struct rpc_pipe_client
*samr_pipe
;
491 struct policy_handle dom_pol
;
492 struct dom_sid
*user_grpsids
= NULL
;
493 uint32_t num_groups
= 0;
497 DEBUG(3,("msrpc_lookup_usergroups sid=%s\n", sid_string_dbg(user_sid
)));
501 tmp_ctx
= talloc_stackframe();
502 if (tmp_ctx
== NULL
) {
503 return NT_STATUS_NO_MEMORY
;
506 /* Check if we have a cached user_info_3 */
507 status
= lookup_usergroups_cached(domain
,
512 if (NT_STATUS_IS_OK(status
)) {
516 if ( !winbindd_can_contact_domain( domain
) ) {
517 DEBUG(10,("lookup_usergroups: No incoming trust for domain %s\n",
520 /* Tell the cache manager not to remember this one */
521 status
= NT_STATUS_SYNCHRONIZATION_REQUIRED
;
525 /* no cache; hit the wire */
526 status
= cm_connect_sam(domain
, tmp_ctx
, false, &samr_pipe
, &dom_pol
);
527 if (!NT_STATUS_IS_OK(status
)) {
531 status
= rpc_lookup_usergroups(tmp_ctx
,
538 if (!NT_STATUS_IS_OK(status
)) {
543 *pnum_groups
= num_groups
;
546 *puser_grpsids
= talloc_move(mem_ctx
, &user_grpsids
);
550 TALLOC_FREE(tmp_ctx
);
555 #define MAX_SAM_ENTRIES_W2K 0x400 /* 1024 */
557 static NTSTATUS
msrpc_lookup_useraliases(struct winbindd_domain
*domain
,
559 uint32 num_sids
, const struct dom_sid
*sids
,
560 uint32
*pnum_aliases
,
561 uint32
**palias_rids
)
563 struct rpc_pipe_client
*samr_pipe
;
564 struct policy_handle dom_pol
;
565 uint32_t num_aliases
= 0;
566 uint32_t *alias_rids
= NULL
;
570 DEBUG(3,("msrpc_lookup_useraliases\n"));
576 tmp_ctx
= talloc_stackframe();
577 if (tmp_ctx
== NULL
) {
578 return NT_STATUS_NO_MEMORY
;
581 if (!winbindd_can_contact_domain(domain
)) {
582 DEBUG(10,("msrpc_lookup_useraliases: No incoming trust for domain %s\n",
584 /* Tell the cache manager not to remember this one */
585 status
= NT_STATUS_SYNCHRONIZATION_REQUIRED
;
589 status
= cm_connect_sam(domain
, tmp_ctx
, false, &samr_pipe
, &dom_pol
);
590 if (!NT_STATUS_IS_OK(status
)) {
594 status
= rpc_lookup_useraliases(tmp_ctx
,
601 if (!NT_STATUS_IS_OK(status
)) {
606 *pnum_aliases
= num_aliases
;
610 *palias_rids
= talloc_move(mem_ctx
, &alias_rids
);
614 TALLOC_FREE(tmp_ctx
);
619 /* Lookup group membership given a rid. */
620 static NTSTATUS
msrpc_lookup_groupmem(struct winbindd_domain
*domain
,
622 const struct dom_sid
*group_sid
,
623 enum lsa_SidType type
,
625 struct dom_sid
**sid_mem
,
627 uint32_t **name_types
)
629 NTSTATUS status
, result
;
630 uint32 i
, total_names
= 0;
631 struct policy_handle dom_pol
, group_pol
;
632 uint32 des_access
= SEC_FLAG_MAXIMUM_ALLOWED
;
633 uint32
*rid_mem
= NULL
;
636 struct rpc_pipe_client
*cli
;
637 unsigned int orig_timeout
;
638 struct samr_RidAttrArray
*rids
= NULL
;
639 struct dcerpc_binding_handle
*b
;
641 DEBUG(3,("msrpc_lookup_groupmem: %s sid=%s\n", domain
->name
,
642 sid_string_dbg(group_sid
)));
644 if ( !winbindd_can_contact_domain( domain
) ) {
645 DEBUG(10,("lookup_groupmem: No incoming trust for domain %s\n",
650 if (!sid_peek_check_rid(&domain
->sid
, group_sid
, &group_rid
))
651 return NT_STATUS_UNSUCCESSFUL
;
655 result
= cm_connect_sam(domain
, mem_ctx
, false, &cli
, &dom_pol
);
656 if (!NT_STATUS_IS_OK(result
))
659 b
= cli
->binding_handle
;
661 status
= dcerpc_samr_OpenGroup(b
, mem_ctx
,
667 if (!NT_STATUS_IS_OK(status
)) {
670 if (!NT_STATUS_IS_OK(result
)) {
674 /* Step #1: Get a list of user rids that are the members of the
677 /* This call can take a long time - allow the server to time out.
678 35 seconds should do it. */
680 orig_timeout
= rpccli_set_timeout(cli
, 35000);
682 status
= dcerpc_samr_QueryGroupMember(b
, mem_ctx
,
687 /* And restore our original timeout. */
688 rpccli_set_timeout(cli
, orig_timeout
);
692 dcerpc_samr_Close(b
, mem_ctx
, &group_pol
, &_result
);
695 if (!NT_STATUS_IS_OK(status
)) {
699 if (!NT_STATUS_IS_OK(result
)) {
703 if (!rids
|| !rids
->count
) {
710 *num_names
= rids
->count
;
711 rid_mem
= rids
->rids
;
713 /* Step #2: Convert list of rids into list of usernames. Do this
714 in bunches of ~1000 to avoid crashing NT4. It looks like there
715 is a buffer overflow or something like that lurking around
718 #define MAX_LOOKUP_RIDS 900
720 *names
= talloc_zero_array(mem_ctx
, char *, *num_names
);
721 *name_types
= talloc_zero_array(mem_ctx
, uint32
, *num_names
);
722 *sid_mem
= talloc_zero_array(mem_ctx
, struct dom_sid
, *num_names
);
724 for (j
=0;j
<(*num_names
);j
++)
725 sid_compose(&(*sid_mem
)[j
], &domain
->sid
, rid_mem
[j
]);
727 if (*num_names
>0 && (!*names
|| !*name_types
))
728 return NT_STATUS_NO_MEMORY
;
730 for (i
= 0; i
< *num_names
; i
+= MAX_LOOKUP_RIDS
) {
731 int num_lookup_rids
= MIN(*num_names
- i
, MAX_LOOKUP_RIDS
);
732 struct lsa_Strings tmp_names
;
733 struct samr_Ids tmp_types
;
735 /* Lookup a chunk of rids */
737 status
= dcerpc_samr_LookupRids(b
, mem_ctx
,
744 if (!NT_STATUS_IS_OK(status
)) {
748 /* see if we have a real error (and yes the
749 STATUS_SOME_UNMAPPED is the one returned from 2k) */
751 if (!NT_STATUS_IS_OK(result
) &&
752 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
))
755 /* Copy result into array. The talloc system will take
756 care of freeing the temporary arrays later on. */
758 if (tmp_names
.count
!= num_lookup_rids
) {
759 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
761 if (tmp_types
.count
!= num_lookup_rids
) {
762 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
765 for (r
=0; r
<tmp_names
.count
; r
++) {
766 if (tmp_types
.ids
[r
] == SID_NAME_UNKNOWN
) {
769 if (total_names
>= *num_names
) {
772 (*names
)[total_names
] = fill_domain_username_talloc(
773 mem_ctx
, domain
->name
,
774 tmp_names
.names
[r
].string
, true);
775 (*name_types
)[total_names
] = tmp_types
.ids
[r
];
780 *num_names
= total_names
;
789 static int get_ldap_seq(const char *server
, struct sockaddr_storage
*ss
, int port
, uint32
*seq
)
793 const char *attrs
[] = {"highestCommittedUSN", NULL
};
794 LDAPMessage
*res
= NULL
;
795 char **values
= NULL
;
798 *seq
= DOM_SEQUENCE_NONE
;
801 * Parameterised (5) second timeout on open. This is needed as the
802 * search timeout doesn't seem to apply to doing an open as well. JRA.
805 ldp
= ldap_open_with_timeout(server
, ss
, port
, lp_ldap_timeout());
809 /* Timeout if no response within 20 seconds. */
813 if (ldap_search_st(ldp
, "", LDAP_SCOPE_BASE
, "(objectclass=*)",
814 discard_const_p(char *, attrs
), 0, &to
, &res
))
817 if (ldap_count_entries(ldp
, res
) != 1)
820 values
= ldap_get_values(ldp
, res
, "highestCommittedUSN");
821 if (!values
|| !values
[0])
824 *seq
= atoi(values
[0]);
830 ldap_value_free(values
);
838 /**********************************************************************
839 Get the sequence number for a Windows AD native mode domain using
841 **********************************************************************/
843 static int get_ldap_sequence_number(struct winbindd_domain
*domain
, uint32
*seq
)
846 char addr
[INET6_ADDRSTRLEN
];
848 print_sockaddr(addr
, sizeof(addr
), &domain
->dcaddr
);
849 if ((ret
= get_ldap_seq(addr
, &domain
->dcaddr
, LDAP_PORT
, seq
)) == 0) {
850 DEBUG(3, ("get_ldap_sequence_number: Retrieved sequence "
851 "number for Domain (%s) from DC (%s)\n",
852 domain
->name
, addr
));
857 #endif /* HAVE_LDAP */
859 /* find the sequence number for a domain */
860 static NTSTATUS
msrpc_sequence_number(struct winbindd_domain
*domain
,
863 struct rpc_pipe_client
*samr_pipe
;
864 struct policy_handle dom_pol
;
869 DEBUG(3, ("msrpc_sequence_number: fetch sequence_number for %s\n", domain
->name
));
872 *pseq
= DOM_SEQUENCE_NONE
;
875 tmp_ctx
= talloc_stackframe();
876 if (tmp_ctx
== NULL
) {
877 return NT_STATUS_NO_MEMORY
;
880 if ( !winbindd_can_contact_domain( domain
) ) {
881 DEBUG(10,("sequence_number: No incoming trust for domain %s\n",
886 status
= NT_STATUS_OK
;
891 if (domain
->active_directory
) {
894 DEBUG(8,("using get_ldap_seq() to retrieve the "
895 "sequence number\n"));
897 rc
= get_ldap_sequence_number(domain
, &seq
);
899 DEBUG(10,("domain_sequence_number: LDAP for "
907 status
= NT_STATUS_OK
;
911 DEBUG(10,("domain_sequence_number: failed to get LDAP "
912 "sequence number for domain %s\n",
915 #endif /* HAVE_LDAP */
917 status
= cm_connect_sam(domain
, tmp_ctx
, false, &samr_pipe
, &dom_pol
);
918 if (!NT_STATUS_IS_OK(status
)) {
922 status
= rpc_sequence_number(tmp_ctx
,
927 if (!NT_STATUS_IS_OK(status
)) {
936 TALLOC_FREE(tmp_ctx
);
940 /* get a list of trusted domains */
941 static NTSTATUS
msrpc_trusted_domains(struct winbindd_domain
*domain
,
943 struct netr_DomainTrustList
*ptrust_list
)
945 struct rpc_pipe_client
*lsa_pipe
;
946 struct policy_handle lsa_policy
;
947 struct netr_DomainTrust
*trusts
= NULL
;
948 uint32_t num_trusts
= 0;
952 DEBUG(3,("msrpc_trusted_domains\n"));
955 ZERO_STRUCTP(ptrust_list
);
958 tmp_ctx
= talloc_stackframe();
959 if (tmp_ctx
== NULL
) {
960 return NT_STATUS_NO_MEMORY
;
963 status
= cm_connect_lsa(domain
, tmp_ctx
, &lsa_pipe
, &lsa_policy
);
964 if (!NT_STATUS_IS_OK(status
)) {
968 status
= rpc_trusted_domains(tmp_ctx
,
973 if (!NT_STATUS_IS_OK(status
)) {
978 ptrust_list
->count
= num_trusts
;
979 ptrust_list
->array
= talloc_move(mem_ctx
, &trusts
);
983 TALLOC_FREE(tmp_ctx
);
987 /* find the lockout policy for a domain */
988 static NTSTATUS
msrpc_lockout_policy(struct winbindd_domain
*domain
,
990 struct samr_DomInfo12
*lockout_policy
)
992 NTSTATUS status
, result
;
993 struct rpc_pipe_client
*cli
;
994 struct policy_handle dom_pol
;
995 union samr_DomainInfo
*info
= NULL
;
996 struct dcerpc_binding_handle
*b
;
998 DEBUG(3, ("msrpc_lockout_policy: fetch lockout policy for %s\n", domain
->name
));
1000 if ( !winbindd_can_contact_domain( domain
) ) {
1001 DEBUG(10,("msrpc_lockout_policy: No incoming trust for domain %s\n",
1003 return NT_STATUS_NOT_SUPPORTED
;
1006 status
= cm_connect_sam(domain
, mem_ctx
, false, &cli
, &dom_pol
);
1007 if (!NT_STATUS_IS_OK(status
)) {
1011 b
= cli
->binding_handle
;
1013 status
= dcerpc_samr_QueryDomainInfo(b
, mem_ctx
,
1015 DomainLockoutInformation
,
1018 if (!NT_STATUS_IS_OK(status
)) {
1021 if (!NT_STATUS_IS_OK(result
)) {
1026 *lockout_policy
= info
->info12
;
1028 DEBUG(10,("msrpc_lockout_policy: lockout_threshold %d\n",
1029 info
->info12
.lockout_threshold
));
1036 /* find the password policy for a domain */
1037 static NTSTATUS
msrpc_password_policy(struct winbindd_domain
*domain
,
1038 TALLOC_CTX
*mem_ctx
,
1039 struct samr_DomInfo1
*password_policy
)
1041 NTSTATUS status
, result
;
1042 struct rpc_pipe_client
*cli
;
1043 struct policy_handle dom_pol
;
1044 union samr_DomainInfo
*info
= NULL
;
1045 struct dcerpc_binding_handle
*b
;
1047 DEBUG(3, ("msrpc_password_policy: fetch password policy for %s\n",
1050 if ( !winbindd_can_contact_domain( domain
) ) {
1051 DEBUG(10,("msrpc_password_policy: No incoming trust for domain %s\n",
1053 return NT_STATUS_NOT_SUPPORTED
;
1056 status
= cm_connect_sam(domain
, mem_ctx
, false, &cli
, &dom_pol
);
1057 if (!NT_STATUS_IS_OK(status
)) {
1061 b
= cli
->binding_handle
;
1063 status
= dcerpc_samr_QueryDomainInfo(b
, mem_ctx
,
1065 DomainPasswordInformation
,
1068 if (!NT_STATUS_IS_OK(status
)) {
1071 if (!NT_STATUS_IS_OK(result
)) {
1075 *password_policy
= info
->info1
;
1077 DEBUG(10,("msrpc_password_policy: min_length_password %d\n",
1078 info
->info1
.min_password_length
));
1085 NTSTATUS
winbindd_lookup_sids(TALLOC_CTX
*mem_ctx
,
1086 struct winbindd_domain
*domain
,
1088 const struct dom_sid
*sids
,
1091 enum lsa_SidType
**types
)
1095 struct rpc_pipe_client
*cli
= NULL
;
1096 struct dcerpc_binding_handle
*b
= NULL
;
1097 struct policy_handle lsa_policy
;
1098 unsigned int orig_timeout
;
1099 bool use_lookupsids3
= false;
1100 bool retried
= false;
1103 status
= cm_connect_lsat(domain
, mem_ctx
, &cli
, &lsa_policy
);
1104 if (!NT_STATUS_IS_OK(status
)) {
1108 b
= cli
->binding_handle
;
1110 if (cli
->transport
->transport
== NCACN_IP_TCP
) {
1111 use_lookupsids3
= true;
1115 * This call can take a long time
1116 * allow the server to time out.
1117 * 35 seconds should do it.
1119 orig_timeout
= dcerpc_binding_handle_set_timeout(b
, 35000);
1121 status
= dcerpc_lsa_lookup_sids_generic(b
,
1132 /* And restore our original timeout. */
1133 dcerpc_binding_handle_set_timeout(b
, orig_timeout
);
1135 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
) ||
1136 NT_STATUS_EQUAL(status
, NT_STATUS_RPC_SEC_PKG_ERROR
) ||
1137 NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_ACCESS_DENIED
)) {
1139 * This can happen if the schannel key is not
1140 * valid anymore, we need to invalidate the
1141 * all connections to the dc and reestablish
1142 * a netlogon connection first.
1144 invalidate_cm_connection(domain
);
1145 domain
->can_do_ncacn_ip_tcp
= domain
->active_directory
;
1150 status
= NT_STATUS_ACCESS_DENIED
;
1153 if (!NT_STATUS_IS_OK(status
)) {
1157 if (!NT_STATUS_IS_OK(result
)) {
1161 return NT_STATUS_OK
;
1164 static NTSTATUS
winbindd_lookup_names(TALLOC_CTX
*mem_ctx
,
1165 struct winbindd_domain
*domain
,
1168 const char ***domains
,
1169 struct dom_sid
**sids
,
1170 enum lsa_SidType
**types
)
1174 struct rpc_pipe_client
*cli
= NULL
;
1175 struct dcerpc_binding_handle
*b
= NULL
;
1176 struct policy_handle lsa_policy
;
1177 unsigned int orig_timeout
= 0;
1178 bool use_lookupnames4
= false;
1179 bool retried
= false;
1182 status
= cm_connect_lsat(domain
, mem_ctx
, &cli
, &lsa_policy
);
1183 if (!NT_STATUS_IS_OK(status
)) {
1187 b
= cli
->binding_handle
;
1189 if (cli
->transport
->transport
== NCACN_IP_TCP
) {
1190 use_lookupnames4
= true;
1194 * This call can take a long time
1195 * allow the server to time out.
1196 * 35 seconds should do it.
1198 orig_timeout
= dcerpc_binding_handle_set_timeout(b
, 35000);
1200 status
= dcerpc_lsa_lookup_names_generic(b
,
1204 (const char **) names
,
1212 /* And restore our original timeout. */
1213 dcerpc_binding_handle_set_timeout(b
, orig_timeout
);
1215 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
) ||
1216 NT_STATUS_EQUAL(status
, NT_STATUS_RPC_SEC_PKG_ERROR
) ||
1217 NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_ACCESS_DENIED
)) {
1219 * This can happen if the schannel key is not
1220 * valid anymore, we need to invalidate the
1221 * all connections to the dc and reestablish
1222 * a netlogon connection first.
1224 invalidate_cm_connection(domain
);
1229 status
= NT_STATUS_ACCESS_DENIED
;
1232 if (!NT_STATUS_IS_OK(status
)) {
1236 if (!NT_STATUS_IS_OK(result
)) {
1240 return NT_STATUS_OK
;
1243 /* the rpc backend methods are exposed via this structure */
1244 struct winbindd_methods msrpc_methods
= {
1246 msrpc_query_user_list
,
1247 msrpc_enum_dom_groups
,
1248 msrpc_enum_local_groups
,
1251 msrpc_rids_to_names
,
1253 msrpc_lookup_usergroups
,
1254 msrpc_lookup_useraliases
,
1255 msrpc_lookup_groupmem
,
1256 msrpc_sequence_number
,
1257 msrpc_lockout_policy
,
1258 msrpc_password_policy
,
1259 msrpc_trusted_domains
,