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/cli_samr.h"
30 #include "rpc_client/cli_samr.h"
31 #include "../librpc/gen_ndr/cli_lsa.h"
32 #include "rpc_client/cli_lsarpc.h"
35 #define DBGC_CLASS DBGC_WINBIND
38 /* Query display info for a domain. This returns enough information plus a
39 bit extra to give an overview of domain users for the User Manager
41 static NTSTATUS
msrpc_query_user_list(struct winbindd_domain
*domain
,
44 struct wbint_userinfo
**pinfo
)
46 struct rpc_pipe_client
*samr_pipe
= NULL
;
47 struct policy_handle dom_pol
;
48 struct wbint_userinfo
*info
= NULL
;
49 uint32_t num_info
= 0;
53 DEBUG(3,("rpc_query_user_list\n"));
59 tmp_ctx
= talloc_stackframe();
60 if (tmp_ctx
== NULL
) {
61 return NT_STATUS_NO_MEMORY
;
64 if ( !winbindd_can_contact_domain( domain
) ) {
65 DEBUG(10,("query_user_list: No incoming trust for domain %s\n",
67 status
= NT_STATUS_OK
;
71 status
= cm_connect_sam(domain
, tmp_ctx
, &samr_pipe
, &dom_pol
);
72 if (!NT_STATUS_IS_OK(status
)) {
76 status
= rpc_query_user_list(tmp_ctx
,
82 if (!NT_STATUS_IS_OK(status
)) {
87 *pnum_info
= num_info
;
91 *pinfo
= talloc_move(mem_ctx
, &info
);
99 /* list all domain groups */
100 static NTSTATUS
msrpc_enum_dom_groups(struct winbindd_domain
*domain
,
103 struct acct_info
**pinfo
)
105 struct rpc_pipe_client
*samr_pipe
;
106 struct policy_handle dom_pol
;
107 struct acct_info
*info
= NULL
;
108 uint32_t num_info
= 0;
112 DEBUG(3,("msrpc_enum_dom_groups\n"));
118 tmp_ctx
= talloc_stackframe();
119 if (tmp_ctx
== NULL
) {
120 return NT_STATUS_NO_MEMORY
;
123 if ( !winbindd_can_contact_domain( domain
) ) {
124 DEBUG(10,("enum_domain_groups: No incoming trust for domain %s\n",
126 status
= NT_STATUS_OK
;
130 status
= cm_connect_sam(domain
, tmp_ctx
, &samr_pipe
, &dom_pol
);
131 if (!NT_STATUS_IS_OK(status
)) {
135 status
= rpc_enum_dom_groups(tmp_ctx
,
140 if (!NT_STATUS_IS_OK(status
)) {
145 *pnum_info
= num_info
;
149 *pinfo
= talloc_move(mem_ctx
, &info
);
153 TALLOC_FREE(tmp_ctx
);
157 /* List all domain groups */
159 static NTSTATUS
msrpc_enum_local_groups(struct winbindd_domain
*domain
,
162 struct acct_info
**pinfo
)
164 struct rpc_pipe_client
*samr_pipe
;
165 struct policy_handle dom_pol
;
166 struct acct_info
*info
= NULL
;
167 uint32_t num_info
= 0;
171 DEBUG(3,("msrpc_enum_local_groups\n"));
177 tmp_ctx
= talloc_stackframe();
178 if (tmp_ctx
== NULL
) {
179 return NT_STATUS_NO_MEMORY
;
182 if ( !winbindd_can_contact_domain( domain
) ) {
183 DEBUG(10,("enum_local_groups: No incoming trust for domain %s\n",
185 status
= NT_STATUS_OK
;
189 status
= cm_connect_sam(domain
, tmp_ctx
, &samr_pipe
, &dom_pol
);
190 if (!NT_STATUS_IS_OK(status
)) {
194 status
= rpc_enum_local_groups(mem_ctx
,
199 if (!NT_STATUS_IS_OK(status
)) {
204 *pnum_info
= num_info
;
208 *pinfo
= talloc_move(mem_ctx
, &info
);
212 TALLOC_FREE(tmp_ctx
);
216 /* convert a single name to a sid in a domain */
217 static NTSTATUS
msrpc_name_to_sid(struct winbindd_domain
*domain
,
219 const char *domain_name
,
223 enum lsa_SidType
*type
)
226 struct dom_sid
*sids
= NULL
;
227 enum lsa_SidType
*types
= NULL
;
228 char *full_name
= NULL
;
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,("rpc: 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 anytthing */
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 result
= winbindd_lookup_names(mem_ctx
, domain
, 1,
261 (const char **)&full_name
, NULL
,
263 if (!NT_STATUS_IS_OK(result
))
266 /* Return rid and type if lookup successful */
268 sid_copy(sid
, &sids
[0]);
275 convert a domain SID to a user or group name
277 static NTSTATUS
msrpc_sid_to_name(struct winbindd_domain
*domain
,
279 const struct dom_sid
*sid
,
282 enum lsa_SidType
*type
)
286 enum lsa_SidType
*types
= NULL
;
288 NTSTATUS name_map_status
= NT_STATUS_UNSUCCESSFUL
;
289 char *mapped_name
= NULL
;
291 DEBUG(3,("sid_to_name [rpc] %s for domain %s\n", sid_string_dbg(sid
),
294 result
= winbindd_lookup_sids(mem_ctx
,
301 if (!NT_STATUS_IS_OK(result
)) {
302 DEBUG(2,("msrpc_sid_to_name: failed to lookup sids: %s\n",
308 *type
= (enum lsa_SidType
)types
[0];
309 *domain_name
= domains
[0];
312 DEBUG(5,("Mapped sid to [%s]\\[%s]\n", domains
[0], *name
));
314 name_map_status
= normalize_name_map(mem_ctx
, domain
, *name
,
316 if (NT_STATUS_IS_OK(name_map_status
) ||
317 NT_STATUS_EQUAL(name_map_status
, NT_STATUS_FILE_RENAMED
))
320 DEBUG(5,("returning mapped name -- %s\n", *name
));
326 static NTSTATUS
msrpc_rids_to_names(struct winbindd_domain
*domain
,
328 const struct dom_sid
*sid
,
333 enum lsa_SidType
**types
)
337 struct dom_sid
*sids
;
341 DEBUG(3, ("rids_to_names [rpc] for domain %s\n", domain
->name
));
344 sids
= TALLOC_ARRAY(mem_ctx
, struct dom_sid
, num_rids
);
346 return NT_STATUS_NO_MEMORY
;
352 for (i
=0; i
<num_rids
; i
++) {
353 if (!sid_compose(&sids
[i
], sid
, rids
[i
])) {
354 return NT_STATUS_INTERNAL_ERROR
;
358 result
= winbindd_lookup_sids(mem_ctx
,
366 if (!NT_STATUS_IS_OK(result
) &&
367 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
)) {
372 for (i
=0; i
<num_rids
; i
++) {
373 NTSTATUS name_map_status
= NT_STATUS_UNSUCCESSFUL
;
374 char *mapped_name
= NULL
;
376 if ((*types
)[i
] != SID_NAME_UNKNOWN
) {
377 name_map_status
= normalize_name_map(mem_ctx
,
381 if (NT_STATUS_IS_OK(name_map_status
) ||
382 NT_STATUS_EQUAL(name_map_status
, NT_STATUS_FILE_RENAMED
))
384 ret_names
[i
] = mapped_name
;
387 *domain_name
= domains
[i
];
394 /* Lookup user information from a rid or username. */
395 static NTSTATUS
msrpc_query_user(struct winbindd_domain
*domain
,
397 const struct dom_sid
*user_sid
,
398 struct wbint_userinfo
*user_info
)
400 struct rpc_pipe_client
*samr_pipe
;
401 struct policy_handle dom_pol
;
402 struct netr_SamInfo3
*user
;
406 DEBUG(3,("msrpc_query_user sid=%s\n", sid_string_dbg(user_sid
)));
408 tmp_ctx
= talloc_stackframe();
409 if (tmp_ctx
== NULL
) {
410 return NT_STATUS_NO_MEMORY
;
414 user_info
->homedir
= NULL
;
415 user_info
->shell
= NULL
;
416 user_info
->primary_gid
= (gid_t
)-1;
419 /* try netsamlogon cache first */
420 user
= netsamlogon_cache_get(tmp_ctx
, user_sid
);
422 DEBUG(5,("msrpc_query_user: Cache lookup succeeded for %s\n",
423 sid_string_dbg(user_sid
)));
425 sid_compose(&user_info
->user_sid
, &domain
->sid
, user
->base
.rid
);
426 sid_compose(&user_info
->group_sid
, &domain
->sid
,
427 user
->base
.primary_gid
);
429 user_info
->acct_name
= talloc_strdup(user_info
,
430 user
->base
.account_name
.string
);
431 user_info
->full_name
= talloc_strdup(user_info
,
432 user
->base
.full_name
.string
);
434 status
= NT_STATUS_OK
;
438 if ( !winbindd_can_contact_domain( domain
) ) {
439 DEBUG(10,("query_user: No incoming trust for domain %s\n",
444 /* no cache; hit the wire */
445 status
= cm_connect_sam(domain
, tmp_ctx
, &samr_pipe
, &dom_pol
);
446 if (!NT_STATUS_IS_OK(status
)) {
450 status
= rpc_query_user(tmp_ctx
,
458 TALLOC_FREE(tmp_ctx
);
462 /* Lookup groups a user is a member of. I wish Unix had a call like this! */
463 static NTSTATUS
msrpc_lookup_usergroups(struct winbindd_domain
*domain
,
465 const struct dom_sid
*user_sid
,
466 uint32_t *pnum_groups
,
467 struct dom_sid
**puser_grpsids
)
469 struct rpc_pipe_client
*samr_pipe
;
470 struct policy_handle dom_pol
;
471 struct dom_sid
*user_grpsids
= NULL
;
472 uint32_t num_groups
= 0;
476 DEBUG(3,("msrpc_lookup_usergroups sid=%s\n", sid_string_dbg(user_sid
)));
480 tmp_ctx
= talloc_stackframe();
481 if (tmp_ctx
== NULL
) {
482 return NT_STATUS_NO_MEMORY
;
485 /* Check if we have a cached user_info_3 */
486 status
= lookup_usergroups_cached(domain
,
491 if (NT_STATUS_IS_OK(status
)) {
495 if ( !winbindd_can_contact_domain( domain
) ) {
496 DEBUG(10,("lookup_usergroups: No incoming trust for domain %s\n",
499 /* Tell the cache manager not to remember this one */
500 status
= NT_STATUS_SYNCHRONIZATION_REQUIRED
;
504 /* no cache; hit the wire */
505 status
= cm_connect_sam(domain
, tmp_ctx
, &samr_pipe
, &dom_pol
);
506 if (!NT_STATUS_IS_OK(status
)) {
510 status
= rpc_lookup_usergroups(tmp_ctx
,
517 if (!NT_STATUS_IS_OK(status
)) {
523 *pnum_groups
= num_groups
;
527 *puser_grpsids
= talloc_move(mem_ctx
, &user_grpsids
);
531 TALLOC_FREE(tmp_ctx
);
536 #define MAX_SAM_ENTRIES_W2K 0x400 /* 1024 */
538 static NTSTATUS
msrpc_lookup_useraliases(struct winbindd_domain
*domain
,
540 uint32 num_sids
, const struct dom_sid
*sids
,
541 uint32
*pnum_aliases
,
542 uint32
**palias_rids
)
544 struct rpc_pipe_client
*samr_pipe
;
545 struct policy_handle dom_pol
;
546 uint32_t num_aliases
= 0;
547 uint32_t *alias_rids
= NULL
;
551 DEBUG(3,("msrpc_lookup_useraliases\n"));
557 tmp_ctx
= talloc_stackframe();
558 if (tmp_ctx
== NULL
) {
559 return NT_STATUS_NO_MEMORY
;
562 if (!winbindd_can_contact_domain(domain
)) {
563 DEBUG(10,("msrpc_lookup_useraliases: No incoming trust for domain %s\n",
568 status
= cm_connect_sam(domain
, tmp_ctx
, &samr_pipe
, &dom_pol
);
569 if (!NT_STATUS_IS_OK(status
)) {
573 status
= rpc_lookup_useraliases(tmp_ctx
,
580 if (!NT_STATUS_IS_OK(status
)) {
585 *pnum_aliases
= num_aliases
;
589 *palias_rids
= talloc_move(mem_ctx
, &alias_rids
);
593 TALLOC_FREE(tmp_ctx
);
598 /* Lookup group membership given a rid. */
599 static NTSTATUS
lookup_groupmem(struct winbindd_domain
*domain
,
601 const struct dom_sid
*group_sid
,
602 enum lsa_SidType type
,
604 struct dom_sid
**sid_mem
, char ***names
,
607 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
608 uint32 i
, total_names
= 0;
609 struct policy_handle dom_pol
, group_pol
;
610 uint32 des_access
= SEC_FLAG_MAXIMUM_ALLOWED
;
611 uint32
*rid_mem
= NULL
;
614 struct rpc_pipe_client
*cli
;
615 unsigned int orig_timeout
;
616 struct samr_RidTypeArray
*rids
= NULL
;
618 DEBUG(10,("rpc: lookup_groupmem %s sid=%s\n", domain
->name
,
619 sid_string_dbg(group_sid
)));
621 if ( !winbindd_can_contact_domain( domain
) ) {
622 DEBUG(10,("lookup_groupmem: No incoming trust for domain %s\n",
627 if (!sid_peek_check_rid(&domain
->sid
, group_sid
, &group_rid
))
628 return NT_STATUS_UNSUCCESSFUL
;
632 result
= cm_connect_sam(domain
, mem_ctx
, &cli
, &dom_pol
);
633 if (!NT_STATUS_IS_OK(result
))
636 result
= rpccli_samr_OpenGroup(cli
, mem_ctx
,
642 if (!NT_STATUS_IS_OK(result
))
645 /* Step #1: Get a list of user rids that are the members of the
648 /* This call can take a long time - allow the server to time out.
649 35 seconds should do it. */
651 orig_timeout
= rpccli_set_timeout(cli
, 35000);
653 result
= rpccli_samr_QueryGroupMember(cli
, mem_ctx
,
657 /* And restore our original timeout. */
658 rpccli_set_timeout(cli
, orig_timeout
);
660 rpccli_samr_Close(cli
, mem_ctx
, &group_pol
);
662 if (!NT_STATUS_IS_OK(result
))
665 if (!rids
|| !rids
->count
) {
672 *num_names
= rids
->count
;
673 rid_mem
= rids
->rids
;
675 /* Step #2: Convert list of rids into list of usernames. Do this
676 in bunches of ~1000 to avoid crashing NT4. It looks like there
677 is a buffer overflow or something like that lurking around
680 #define MAX_LOOKUP_RIDS 900
682 *names
= TALLOC_ZERO_ARRAY(mem_ctx
, char *, *num_names
);
683 *name_types
= TALLOC_ZERO_ARRAY(mem_ctx
, uint32
, *num_names
);
684 *sid_mem
= TALLOC_ZERO_ARRAY(mem_ctx
, struct dom_sid
, *num_names
);
686 for (j
=0;j
<(*num_names
);j
++)
687 sid_compose(&(*sid_mem
)[j
], &domain
->sid
, rid_mem
[j
]);
689 if (*num_names
>0 && (!*names
|| !*name_types
))
690 return NT_STATUS_NO_MEMORY
;
692 for (i
= 0; i
< *num_names
; i
+= MAX_LOOKUP_RIDS
) {
693 int num_lookup_rids
= MIN(*num_names
- i
, MAX_LOOKUP_RIDS
);
694 struct lsa_Strings tmp_names
;
695 struct samr_Ids tmp_types
;
697 /* Lookup a chunk of rids */
699 result
= rpccli_samr_LookupRids(cli
, mem_ctx
,
706 /* see if we have a real error (and yes the
707 STATUS_SOME_UNMAPPED is the one returned from 2k) */
709 if (!NT_STATUS_IS_OK(result
) &&
710 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
))
713 /* Copy result into array. The talloc system will take
714 care of freeing the temporary arrays later on. */
716 if (tmp_names
.count
!= tmp_types
.count
) {
717 return NT_STATUS_UNSUCCESSFUL
;
720 for (r
=0; r
<tmp_names
.count
; r
++) {
721 if (tmp_types
.ids
[r
] == SID_NAME_UNKNOWN
) {
724 (*names
)[total_names
] = fill_domain_username_talloc(
725 mem_ctx
, domain
->name
,
726 tmp_names
.names
[r
].string
, true);
727 (*name_types
)[total_names
] = tmp_types
.ids
[r
];
732 *num_names
= total_names
;
741 static int get_ldap_seq(const char *server
, int port
, uint32
*seq
)
745 const char *attrs
[] = {"highestCommittedUSN", NULL
};
746 LDAPMessage
*res
= NULL
;
747 char **values
= NULL
;
750 *seq
= DOM_SEQUENCE_NONE
;
753 * Parameterised (5) second timeout on open. This is needed as the
754 * search timeout doesn't seem to apply to doing an open as well. JRA.
757 ldp
= ldap_open_with_timeout(server
, port
, lp_ldap_timeout());
761 /* Timeout if no response within 20 seconds. */
765 if (ldap_search_st(ldp
, "", LDAP_SCOPE_BASE
, "(objectclass=*)",
766 CONST_DISCARD(char **, attrs
), 0, &to
, &res
))
769 if (ldap_count_entries(ldp
, res
) != 1)
772 values
= ldap_get_values(ldp
, res
, "highestCommittedUSN");
773 if (!values
|| !values
[0])
776 *seq
= atoi(values
[0]);
782 ldap_value_free(values
);
790 /**********************************************************************
791 Get the sequence number for a Windows AD native mode domain using
793 **********************************************************************/
795 static int get_ldap_sequence_number(struct winbindd_domain
*domain
, uint32
*seq
)
798 char addr
[INET6_ADDRSTRLEN
];
800 print_sockaddr(addr
, sizeof(addr
), &domain
->dcaddr
);
801 if ((ret
= get_ldap_seq(addr
, LDAP_PORT
, seq
)) == 0) {
802 DEBUG(3, ("get_ldap_sequence_number: Retrieved sequence "
803 "number for Domain (%s) from DC (%s)\n",
804 domain
->name
, addr
));
809 #endif /* HAVE_LDAP */
811 /* find the sequence number for a domain */
812 static NTSTATUS
sequence_number(struct winbindd_domain
*domain
, uint32
*seq
)
815 union samr_DomainInfo
*info
= NULL
;
817 struct policy_handle dom_pol
;
818 bool got_seq_num
= False
;
819 struct rpc_pipe_client
*cli
;
821 DEBUG(10,("rpc: fetch sequence_number for %s\n", domain
->name
));
823 if ( !winbindd_can_contact_domain( domain
) ) {
824 DEBUG(10,("sequence_number: No incoming trust for domain %s\n",
830 *seq
= DOM_SEQUENCE_NONE
;
832 if (!(mem_ctx
= talloc_init("sequence_number[rpc]")))
833 return NT_STATUS_NO_MEMORY
;
836 if ( domain
->active_directory
)
840 DEBUG(8,("using get_ldap_seq() to retrieve the "
841 "sequence number\n"));
843 res
= get_ldap_sequence_number( domain
, seq
);
846 result
= NT_STATUS_OK
;
847 DEBUG(10,("domain_sequence_number: LDAP for "
849 domain
->name
, *seq
));
853 DEBUG(10,("domain_sequence_number: failed to get LDAP "
854 "sequence number for domain %s\n",
857 #endif /* HAVE_LDAP */
859 result
= cm_connect_sam(domain
, mem_ctx
, &cli
, &dom_pol
);
860 if (!NT_STATUS_IS_OK(result
)) {
864 /* Query domain info */
866 result
= rpccli_samr_QueryDomainInfo(cli
, mem_ctx
,
871 if (NT_STATUS_IS_OK(result
)) {
872 *seq
= info
->info8
.sequence_num
;
877 /* retry with info-level 2 in case the dc does not support info-level 8
878 * (like all older samba2 and samba3 dc's) - Guenther */
880 result
= rpccli_samr_QueryDomainInfo(cli
, mem_ctx
,
885 if (NT_STATUS_IS_OK(result
)) {
886 *seq
= info
->general
.sequence_num
;
892 DEBUG(10,("domain_sequence_number: for domain %s is %u\n",
893 domain
->name
, (unsigned)*seq
));
895 DEBUG(10,("domain_sequence_number: failed to get sequence "
896 "number (%u) for domain %s\n",
897 (unsigned)*seq
, domain
->name
));
902 talloc_destroy(mem_ctx
);
907 /* get a list of trusted domains */
908 static NTSTATUS
trusted_domains(struct winbindd_domain
*domain
,
910 struct netr_DomainTrustList
*trusts
)
912 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
914 struct rpc_pipe_client
*cli
;
915 struct policy_handle lsa_policy
;
917 DEBUG(3,("rpc: trusted_domains\n"));
919 ZERO_STRUCTP(trusts
);
921 result
= cm_connect_lsa(domain
, mem_ctx
, &cli
, &lsa_policy
);
922 if (!NT_STATUS_IS_OK(result
))
925 result
= STATUS_MORE_ENTRIES
;
927 while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
)) {
930 struct lsa_DomainList dom_list
;
932 result
= rpccli_lsa_EnumTrustDom(cli
, mem_ctx
,
938 if (!NT_STATUS_IS_OK(result
) &&
939 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
942 start_idx
= trusts
->count
;
943 trusts
->count
+= dom_list
.count
;
945 trusts
->array
= talloc_realloc(
946 mem_ctx
, trusts
->array
, struct netr_DomainTrust
,
948 if (trusts
->array
== NULL
) {
949 return NT_STATUS_NO_MEMORY
;
952 for (i
=0; i
<dom_list
.count
; i
++) {
953 struct netr_DomainTrust
*trust
= &trusts
->array
[i
];
958 trust
->netbios_name
= talloc_move(
960 &dom_list
.domains
[i
].name
.string
);
961 trust
->dns_name
= NULL
;
963 sid
= talloc(trusts
->array
, struct dom_sid
);
965 return NT_STATUS_NO_MEMORY
;
967 sid_copy(sid
, dom_list
.domains
[i
].sid
);
974 /* find the lockout policy for a domain */
975 static NTSTATUS
msrpc_lockout_policy(struct winbindd_domain
*domain
,
977 struct samr_DomInfo12
*lockout_policy
)
980 struct rpc_pipe_client
*cli
;
981 struct policy_handle dom_pol
;
982 union samr_DomainInfo
*info
= NULL
;
984 DEBUG(10,("rpc: fetch lockout policy for %s\n", domain
->name
));
986 if ( !winbindd_can_contact_domain( domain
) ) {
987 DEBUG(10,("msrpc_lockout_policy: No incoming trust for domain %s\n",
989 return NT_STATUS_NOT_SUPPORTED
;
992 result
= cm_connect_sam(domain
, mem_ctx
, &cli
, &dom_pol
);
993 if (!NT_STATUS_IS_OK(result
)) {
997 result
= rpccli_samr_QueryDomainInfo(cli
, mem_ctx
,
1001 if (!NT_STATUS_IS_OK(result
)) {
1005 *lockout_policy
= info
->info12
;
1007 DEBUG(10,("msrpc_lockout_policy: lockout_threshold %d\n",
1008 info
->info12
.lockout_threshold
));
1015 /* find the password policy for a domain */
1016 static NTSTATUS
msrpc_password_policy(struct winbindd_domain
*domain
,
1017 TALLOC_CTX
*mem_ctx
,
1018 struct samr_DomInfo1
*password_policy
)
1021 struct rpc_pipe_client
*cli
;
1022 struct policy_handle dom_pol
;
1023 union samr_DomainInfo
*info
= NULL
;
1025 DEBUG(10,("rpc: fetch password policy for %s\n", domain
->name
));
1027 if ( !winbindd_can_contact_domain( domain
) ) {
1028 DEBUG(10,("msrpc_password_policy: No incoming trust for domain %s\n",
1030 return NT_STATUS_NOT_SUPPORTED
;
1033 result
= cm_connect_sam(domain
, mem_ctx
, &cli
, &dom_pol
);
1034 if (!NT_STATUS_IS_OK(result
)) {
1038 result
= rpccli_samr_QueryDomainInfo(cli
, mem_ctx
,
1042 if (!NT_STATUS_IS_OK(result
)) {
1046 *password_policy
= info
->info1
;
1048 DEBUG(10,("msrpc_password_policy: min_length_password %d\n",
1049 info
->info1
.min_password_length
));
1056 typedef NTSTATUS (*lookup_sids_fn_t
)(struct rpc_pipe_client
*cli
,
1057 TALLOC_CTX
*mem_ctx
,
1058 struct policy_handle
*pol
,
1060 const struct dom_sid
*sids
,
1063 enum lsa_SidType
**ptypes
);
1065 NTSTATUS
winbindd_lookup_sids(TALLOC_CTX
*mem_ctx
,
1066 struct winbindd_domain
*domain
,
1068 const struct dom_sid
*sids
,
1071 enum lsa_SidType
**types
)
1074 struct rpc_pipe_client
*cli
= NULL
;
1075 struct policy_handle lsa_policy
;
1076 unsigned int orig_timeout
;
1077 lookup_sids_fn_t lookup_sids_fn
= rpccli_lsa_lookup_sids
;
1079 if (domain
->can_do_ncacn_ip_tcp
) {
1080 status
= cm_connect_lsa_tcp(domain
, mem_ctx
, &cli
);
1081 if (NT_STATUS_IS_OK(status
)) {
1082 lookup_sids_fn
= rpccli_lsa_lookup_sids3
;
1085 domain
->can_do_ncacn_ip_tcp
= false;
1087 status
= cm_connect_lsa(domain
, mem_ctx
, &cli
, &lsa_policy
);
1089 if (!NT_STATUS_IS_OK(status
)) {
1095 * This call can take a long time
1096 * allow the server to time out.
1097 * 35 seconds should do it.
1099 orig_timeout
= rpccli_set_timeout(cli
, 35000);
1101 status
= lookup_sids_fn(cli
,
1110 /* And restore our original timeout. */
1111 rpccli_set_timeout(cli
, orig_timeout
);
1113 if (!NT_STATUS_IS_OK(status
)) {
1120 typedef NTSTATUS (*lookup_names_fn_t
)(struct rpc_pipe_client
*cli
,
1121 TALLOC_CTX
*mem_ctx
,
1122 struct policy_handle
*pol
,
1125 const char ***dom_names
,
1127 struct dom_sid
**sids
,
1128 enum lsa_SidType
**types
);
1130 NTSTATUS
winbindd_lookup_names(TALLOC_CTX
*mem_ctx
,
1131 struct winbindd_domain
*domain
,
1134 const char ***domains
,
1135 struct dom_sid
**sids
,
1136 enum lsa_SidType
**types
)
1139 struct rpc_pipe_client
*cli
= NULL
;
1140 struct policy_handle lsa_policy
;
1141 unsigned int orig_timeout
= 0;
1142 lookup_names_fn_t lookup_names_fn
= rpccli_lsa_lookup_names
;
1144 if (domain
->can_do_ncacn_ip_tcp
) {
1145 status
= cm_connect_lsa_tcp(domain
, mem_ctx
, &cli
);
1146 if (NT_STATUS_IS_OK(status
)) {
1147 lookup_names_fn
= rpccli_lsa_lookup_names4
;
1150 domain
->can_do_ncacn_ip_tcp
= false;
1152 status
= cm_connect_lsa(domain
, mem_ctx
, &cli
, &lsa_policy
);
1154 if (!NT_STATUS_IS_OK(status
)) {
1161 * This call can take a long time
1162 * allow the server to time out.
1163 * 35 seconds should do it.
1165 orig_timeout
= rpccli_set_timeout(cli
, 35000);
1167 status
= lookup_names_fn(cli
,
1171 (const char **) names
,
1177 /* And restore our original timeout. */
1178 rpccli_set_timeout(cli
, orig_timeout
);
1180 if (!NT_STATUS_IS_OK(status
)) {
1187 /* the rpc backend methods are exposed via this structure */
1188 struct winbindd_methods msrpc_methods
= {
1190 msrpc_query_user_list
,
1191 msrpc_enum_dom_groups
,
1192 msrpc_enum_local_groups
,
1195 msrpc_rids_to_names
,
1197 msrpc_lookup_usergroups
,
1198 msrpc_lookup_useraliases
,
1201 msrpc_lockout_policy
,
1202 msrpc_password_policy
,