2 Unix SMB/CIFS implementation.
4 Winbind ADS backend functions
6 Copyright (C) Andrew Tridgell 2001
7 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2003
8 Copyright (C) Gerald (Jerry) Carter 2004
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 #define DBGC_CLASS DBGC_WINBIND
34 return our ads connections structure for a domain. We keep the connection
35 open to make things faster
37 static ADS_STRUCT
*ads_cached_connection(struct winbindd_domain
*domain
)
42 if (domain
->private_data
) {
43 ads
= (ADS_STRUCT
*)domain
->private_data
;
45 /* check for a valid structure */
47 DEBUG(7, ("Current tickets expire at %d, time is now %d\n",
48 (uint32
) ads
->auth
.expire
, (uint32
) time(NULL
)));
49 if ( ads
->config
.realm
&& (ads
->auth
.expire
> time(NULL
))) {
53 /* we own this ADS_STRUCT so make sure it goes away */
56 ads_kdestroy("MEMORY:winbind_ccache");
57 domain
->private_data
= NULL
;
61 /* we don't want this to affect the users ccache */
62 setenv("KRB5CCNAME", "MEMORY:winbind_ccache", 1);
64 ads
= ads_init(domain
->alt_name
, domain
->name
, NULL
);
66 DEBUG(1,("ads_init for domain %s failed\n", domain
->name
));
70 /* the machine acct password might have change - fetch it every time */
72 SAFE_FREE(ads
->auth
.password
);
73 SAFE_FREE(ads
->auth
.realm
);
79 if ( !secrets_fetch_trusted_domain_password( domain
->name
, &ads
->auth
.password
, &sid
, &last_set_time
) ) {
83 ads
->auth
.realm
= SMB_STRDUP( ads
->server
.realm
);
84 strupper_m( ads
->auth
.realm
);
87 struct winbindd_domain
*our_domain
= domain
;
89 ads
->auth
.password
= secrets_fetch_machine_password(lp_workgroup(), NULL
, NULL
);
91 /* always give preference to the alt_name in our
92 primary domain if possible */
94 if ( !domain
->primary
)
95 our_domain
= find_our_domain();
97 if ( our_domain
->alt_name
[0] != '\0' ) {
98 ads
->auth
.realm
= SMB_STRDUP( our_domain
->alt_name
);
99 strupper_m( ads
->auth
.realm
);
102 ads
->auth
.realm
= SMB_STRDUP( lp_realm() );
105 ads
->auth
.renewable
= 1;
107 status
= ads_connect(ads
);
108 if (!ADS_ERR_OK(status
) || !ads
->config
.realm
) {
109 extern struct winbindd_methods msrpc_methods
, cache_methods
;
110 DEBUG(1,("ads_connect for domain %s failed: %s\n",
111 domain
->name
, ads_errstr(status
)));
114 /* if we get ECONNREFUSED then it might be a NT4
115 server, fall back to MSRPC */
116 if (status
.error_type
== ENUM_ADS_ERROR_SYSTEM
&&
117 status
.err
.rc
== ECONNREFUSED
) {
118 DEBUG(1,("Trying MSRPC methods\n"));
119 if (domain
->methods
== &cache_methods
) {
120 domain
->backend
= &msrpc_methods
;
122 domain
->methods
= &msrpc_methods
;
128 if (use_nss_info("sfu") && (!ads_check_sfu_mapping(ads
))) {
129 DEBUG(0,("ads_cached_connection: failed to check sfu attributes\n"));
133 /* set the flag that says we don't own the memory even
134 though we do so that ads_destroy() won't destroy the
135 structure we pass back by reference */
137 ads
->is_mine
= False
;
139 domain
->private_data
= (void *)ads
;
144 /* Query display info for a realm. This is the basic user list fn */
145 static NTSTATUS
query_user_list(struct winbindd_domain
*domain
,
148 WINBIND_USERINFO
**info
)
150 ADS_STRUCT
*ads
= NULL
;
151 const char *attrs
[] = {"userPrincipalName",
153 "name", "objectSid", "primaryGroupID",
155 ADS_ATTR_SFU_HOMEDIR_OID
,
156 ADS_ATTR_SFU_SHELL_OID
,
157 ADS_ATTR_SFU_GECOS_OID
,
163 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
167 DEBUG(3,("ads: query_user_list\n"));
169 ads
= ads_cached_connection(domain
);
172 domain
->last_status
= NT_STATUS_SERVER_DISABLED
;
176 rc
= ads_search_retry(ads
, &res
, "(objectClass=user)", attrs
);
177 if (!ADS_ERR_OK(rc
) || !res
) {
178 DEBUG(1,("query_user_list ads_search: %s\n", ads_errstr(rc
)));
182 count
= ads_count_replies(ads
, res
);
184 DEBUG(1,("query_user_list: No users found\n"));
188 (*info
) = TALLOC_ZERO_ARRAY(mem_ctx
, WINBIND_USERINFO
, count
);
190 status
= NT_STATUS_NO_MEMORY
;
196 for (msg
= ads_first_entry(ads
, res
); msg
; msg
= ads_next_entry(ads
, msg
)) {
197 char *name
, *gecos
= NULL
;
198 char *homedir
= NULL
;
203 if (!ads_pull_uint32(ads
, msg
, "sAMAccountType", &atype
) ||
204 ads_atype_map(atype
) != SID_NAME_USER
) {
205 DEBUG(1,("Not a user account? atype=0x%x\n", atype
));
209 name
= ads_pull_username(ads
, mem_ctx
, msg
);
211 if (use_nss_info("sfu")) {
212 homedir
= ads_pull_string(ads
, mem_ctx
, msg
,
213 ads
->schema
.sfu_homedir_attr
);
214 shell
= ads_pull_string(ads
, mem_ctx
, msg
,
215 ads
->schema
.sfu_shell_attr
);
216 gecos
= ads_pull_string(ads
, mem_ctx
, msg
,
217 ads
->schema
.sfu_gecos_attr
);
221 gecos
= ads_pull_string(ads
, mem_ctx
, msg
, "name");
224 if (!ads_pull_sid(ads
, msg
, "objectSid",
225 &(*info
)[i
].user_sid
)) {
226 DEBUG(1,("No sid for %s !?\n", name
));
229 if (!ads_pull_uint32(ads
, msg
, "primaryGroupID", &group
)) {
230 DEBUG(1,("No primary group for %s !?\n", name
));
234 (*info
)[i
].acct_name
= name
;
235 (*info
)[i
].full_name
= gecos
;
236 (*info
)[i
].homedir
= homedir
;
237 (*info
)[i
].shell
= shell
;
238 sid_compose(&(*info
)[i
].group_sid
, &domain
->sid
, group
);
243 status
= NT_STATUS_OK
;
245 DEBUG(3,("ads query_user_list gave %d entries\n", (*num_entries
)));
249 ads_msgfree(ads
, res
);
254 /* list all domain groups */
255 static NTSTATUS
enum_dom_groups(struct winbindd_domain
*domain
,
258 struct acct_info
**info
)
260 ADS_STRUCT
*ads
= NULL
;
261 const char *attrs
[] = {"userPrincipalName", "sAMAccountName",
262 "name", "objectSid", NULL
};
267 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
269 BOOL enum_dom_local_groups
= False
;
273 DEBUG(3,("ads: enum_dom_groups\n"));
275 /* only grab domain local groups for our domain */
276 if ( domain
->native_mode
&& strequal(lp_realm(), domain
->alt_name
) ) {
277 enum_dom_local_groups
= True
;
280 /* Workaround ADS LDAP bug present in MS W2K3 SP0 and W2K SP4 w/o
283 * According to Section 5.1(4) of RFC 2251 if a value of a type is it's
284 * default value, it MUST be absent. In case of extensible matching the
285 * "dnattr" boolean defaults to FALSE and so it must be only be present
288 * When it is set to FALSE and the OpenLDAP lib (correctly) encodes a
289 * filter using bitwise matching rule then the buggy AD fails to decode
290 * the extensible match. As a workaround set it to TRUE and thereby add
291 * the dnAttributes "dn" field to cope with those older AD versions.
292 * It should not harm and won't put any additional load on the AD since
293 * none of the dn components have a bitmask-attribute.
295 * Thanks to Ralf Haferkamp for input and testing - Guenther */
297 filter
= talloc_asprintf(mem_ctx
, "(&(objectCategory=group)(&(groupType:dn:%s:=%d)(!(groupType:dn:%s:=%d))))",
298 ADS_LDAP_MATCHING_RULE_BIT_AND
, GROUP_TYPE_SECURITY_ENABLED
,
299 ADS_LDAP_MATCHING_RULE_BIT_AND
,
300 enum_dom_local_groups
? GROUP_TYPE_BUILTIN_LOCAL_GROUP
: GROUP_TYPE_RESOURCE_GROUP
);
302 if (filter
== NULL
) {
303 status
= NT_STATUS_NO_MEMORY
;
307 ads
= ads_cached_connection(domain
);
310 domain
->last_status
= NT_STATUS_SERVER_DISABLED
;
314 rc
= ads_search_retry(ads
, &res
, filter
, attrs
);
315 if (!ADS_ERR_OK(rc
) || !res
) {
316 DEBUG(1,("enum_dom_groups ads_search: %s\n", ads_errstr(rc
)));
320 count
= ads_count_replies(ads
, res
);
322 DEBUG(1,("enum_dom_groups: No groups found\n"));
326 (*info
) = TALLOC_ZERO_ARRAY(mem_ctx
, struct acct_info
, count
);
328 status
= NT_STATUS_NO_MEMORY
;
334 for (msg
= ads_first_entry(ads
, res
); msg
; msg
= ads_next_entry(ads
, msg
)) {
339 name
= ads_pull_username(ads
, mem_ctx
, msg
);
340 gecos
= ads_pull_string(ads
, mem_ctx
, msg
, "name");
341 if (!ads_pull_sid(ads
, msg
, "objectSid", &sid
)) {
342 DEBUG(1,("No sid for %s !?\n", name
));
346 if (!sid_peek_check_rid(&domain
->sid
, &sid
, &rid
)) {
347 DEBUG(1,("No rid for %s !?\n", name
));
351 fstrcpy((*info
)[i
].acct_name
, name
);
352 fstrcpy((*info
)[i
].acct_desc
, gecos
);
353 (*info
)[i
].rid
= rid
;
359 status
= NT_STATUS_OK
;
361 DEBUG(3,("ads enum_dom_groups gave %d entries\n", (*num_entries
)));
365 ads_msgfree(ads
, res
);
370 /* list all domain local groups */
371 static NTSTATUS
enum_local_groups(struct winbindd_domain
*domain
,
374 struct acct_info
**info
)
377 * This is a stub function only as we returned the domain
378 * local groups in enum_dom_groups() if the domain->native field
379 * was true. This is a simple performance optimization when
382 * if we ever need to enumerate domain local groups separately,
383 * then this the optimization in enum_dom_groups() will need
391 /* convert a DN to a name, SID and name type
392 this might become a major speed bottleneck if groups have
393 lots of users, in which case we could cache the results
395 static BOOL
dn_lookup(ADS_STRUCT
*ads
, TALLOC_CTX
*mem_ctx
,
397 char **name
, uint32
*name_type
, DOM_SID
*sid
)
400 const char *attrs
[] = {"userPrincipalName", "sAMAccountName",
401 "objectSid", "sAMAccountType", NULL
};
404 DEBUG(3,("ads: dn_lookup\n"));
406 rc
= ads_search_retry_dn(ads
, &res
, dn
, attrs
);
408 if (!ADS_ERR_OK(rc
) || !res
) {
412 (*name
) = ads_pull_username(ads
, mem_ctx
, res
);
414 if (!ads_pull_uint32(ads
, res
, "sAMAccountType", &atype
)) {
417 (*name_type
) = ads_atype_map(atype
);
419 if (!ads_pull_sid(ads
, res
, "objectSid", sid
)) {
424 ads_msgfree(ads
, res
);
430 ads_msgfree(ads
, res
);
435 /* Lookup user information from a rid */
436 static NTSTATUS
query_user(struct winbindd_domain
*domain
,
439 WINBIND_USERINFO
*info
)
441 ADS_STRUCT
*ads
= NULL
;
442 const char *attrs
[] = {"userPrincipalName",
446 ADS_ATTR_SFU_HOMEDIR_OID
,
447 ADS_ATTR_SFU_SHELL_OID
,
448 ADS_ATTR_SFU_GECOS_OID
,
456 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
458 DEBUG(3,("ads: query_user\n"));
460 ads
= ads_cached_connection(domain
);
463 domain
->last_status
= NT_STATUS_SERVER_DISABLED
;
467 sidstr
= sid_binstring(sid
);
468 asprintf(&ldap_exp
, "(objectSid=%s)", sidstr
);
469 rc
= ads_search_retry(ads
, &msg
, ldap_exp
, attrs
);
472 if (!ADS_ERR_OK(rc
) || !msg
) {
473 DEBUG(1,("query_user(sid=%s) ads_search: %s\n",
474 sid_string_static(sid
), ads_errstr(rc
)));
478 count
= ads_count_replies(ads
, msg
);
480 DEBUG(1,("query_user(sid=%s): Not found\n",
481 sid_string_static(sid
)));
485 info
->acct_name
= ads_pull_username(ads
, mem_ctx
, msg
);
487 if (use_nss_info("sfu")) {
488 info
->homedir
= ads_pull_string(ads
, mem_ctx
, msg
,
489 ads
->schema
.sfu_homedir_attr
);
490 info
->shell
= ads_pull_string(ads
, mem_ctx
, msg
,
491 ads
->schema
.sfu_shell_attr
);
492 info
->full_name
= ads_pull_string(ads
, mem_ctx
, msg
,
493 ads
->schema
.sfu_gecos_attr
);
496 if (info
->full_name
== NULL
) {
497 info
->full_name
= ads_pull_string(ads
, mem_ctx
, msg
, "name");
500 if (!ads_pull_uint32(ads
, msg
, "primaryGroupID", &group_rid
)) {
501 DEBUG(1,("No primary group for %s !?\n",
502 sid_string_static(sid
)));
506 sid_copy(&info
->user_sid
, sid
);
507 sid_compose(&info
->group_sid
, &domain
->sid
, group_rid
);
509 status
= NT_STATUS_OK
;
511 DEBUG(3,("ads query_user gave %s\n", info
->acct_name
));
514 ads_msgfree(ads
, msg
);
519 /* Lookup groups a user is a member of - alternate method, for when
520 tokenGroups are not available. */
521 static NTSTATUS
lookup_usergroups_alt(struct winbindd_domain
*domain
,
524 DOM_SID
*primary_group
,
525 size_t *p_num_groups
, DOM_SID
**user_sids
)
528 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
534 const char *group_attrs
[] = {"objectSid", NULL
};
536 size_t num_groups
= 0;
538 DEBUG(3,("ads: lookup_usergroups_alt\n"));
540 ads
= ads_cached_connection(domain
);
543 domain
->last_status
= NT_STATUS_SERVER_DISABLED
;
547 if (!(escaped_dn
= escape_ldap_string_alloc(user_dn
))) {
548 status
= NT_STATUS_NO_MEMORY
;
552 /* buggy server, no tokenGroups. Instead lookup what groups this user
553 is a member of by DN search on member*/
555 if (!(ldap_exp
= talloc_asprintf(mem_ctx
, "(&(member=%s)(objectClass=group))", escaped_dn
))) {
556 DEBUG(1,("lookup_usergroups(dn=%s) asprintf failed!\n", user_dn
));
557 SAFE_FREE(escaped_dn
);
558 status
= NT_STATUS_NO_MEMORY
;
562 SAFE_FREE(escaped_dn
);
564 rc
= ads_search_retry(ads
, &res
, ldap_exp
, group_attrs
);
566 if (!ADS_ERR_OK(rc
) || !res
) {
567 DEBUG(1,("lookup_usergroups ads_search member=%s: %s\n", user_dn
, ads_errstr(rc
)));
568 return ads_ntstatus(rc
);
571 count
= ads_count_replies(ads
, res
);
576 /* always add the primary group to the sid array */
577 add_sid_to_array(mem_ctx
, primary_group
, user_sids
, &num_groups
);
580 for (msg
= ads_first_entry(ads
, res
); msg
;
581 msg
= ads_next_entry(ads
, msg
)) {
584 if (!ads_pull_sid(ads
, msg
, "objectSid", &group_sid
)) {
585 DEBUG(1,("No sid for this group ?!?\n"));
589 add_sid_to_array(mem_ctx
, &group_sid
, user_sids
,
595 *p_num_groups
= num_groups
;
596 status
= (user_sids
!= NULL
) ? NT_STATUS_OK
: NT_STATUS_NO_MEMORY
;
598 DEBUG(3,("ads lookup_usergroups (alt) for dn=%s\n", user_dn
));
601 ads_msgfree(ads
, res
);
606 /* Lookup groups a user is a member of. */
607 static NTSTATUS
lookup_usergroups(struct winbindd_domain
*domain
,
610 uint32
*p_num_groups
, DOM_SID
**user_sids
)
612 ADS_STRUCT
*ads
= NULL
;
613 const char *attrs
[] = {"tokenGroups", "primaryGroupID", NULL
};
616 LDAPMessage
*msg
= NULL
;
620 DOM_SID primary_group
;
621 uint32 primary_group_rid
;
623 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
624 size_t num_groups
= 0;
626 DEBUG(3,("ads: lookup_usergroups\n"));
629 ads
= ads_cached_connection(domain
);
632 domain
->last_status
= NT_STATUS_SERVER_DISABLED
;
633 status
= NT_STATUS_SERVER_DISABLED
;
637 rc
= ads_sid_to_dn(ads
, mem_ctx
, sid
, &user_dn
);
638 if (!ADS_ERR_OK(rc
)) {
639 status
= ads_ntstatus(rc
);
643 rc
= ads_search_retry_dn(ads
, (void**)(void *)&msg
, user_dn
, attrs
);
644 if (!ADS_ERR_OK(rc
)) {
645 status
= ads_ntstatus(rc
);
646 DEBUG(1,("lookup_usergroups(sid=%s) ads_search tokenGroups: %s\n",
647 sid_to_string(sid_string
, sid
), ads_errstr(rc
)));
652 DEBUG(1,("lookup_usergroups(sid=%s) ads_search tokenGroups: NULL msg\n",
653 sid_to_string(sid_string
, sid
)));
654 status
= NT_STATUS_UNSUCCESSFUL
;
658 if (!ads_pull_uint32(ads
, msg
, "primaryGroupID", &primary_group_rid
)) {
659 DEBUG(1,("%s: No primary group for sid=%s !?\n",
660 domain
->name
, sid_to_string(sid_string
, sid
)));
664 sid_copy(&primary_group
, &domain
->sid
);
665 sid_append_rid(&primary_group
, primary_group_rid
);
667 count
= ads_pull_sids(ads
, mem_ctx
, msg
, "tokenGroups", &sids
);
670 ads_msgfree(ads
, msg
);
672 /* there must always be at least one group in the token,
673 unless we are talking to a buggy Win2k server */
675 status
= lookup_usergroups_alt(domain
, mem_ctx
, user_dn
,
677 &num_groups
, user_sids
);
678 *p_num_groups
= (uint32
)num_groups
;
685 add_sid_to_array(mem_ctx
, &primary_group
, user_sids
, &num_groups
);
687 for (i
=0;i
<count
;i
++) {
689 /* ignore Builtin groups from ADS - Guenther */
690 if (sid_check_is_in_builtin(&sids
[i
])) {
694 add_sid_to_array_unique(mem_ctx
, &sids
[i
],
695 user_sids
, &num_groups
);
698 *p_num_groups
= (uint32
)num_groups
;
699 status
= (user_sids
!= NULL
) ? NT_STATUS_OK
: NT_STATUS_NO_MEMORY
;
701 DEBUG(3,("ads lookup_usergroups for sid=%s\n",
702 sid_to_string(sid_string
, sid
)));
708 find the members of a group, given a group rid and domain
710 static NTSTATUS
lookup_groupmem(struct winbindd_domain
*domain
,
712 const DOM_SID
*group_sid
, uint32
*num_names
,
713 DOM_SID
**sid_mem
, char ***names
,
719 ADS_STRUCT
*ads
= NULL
;
721 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
733 DEBUG(10,("ads: lookup_groupmem %s sid=%s\n", domain
->name
,
734 sid_string_static(group_sid
)));
738 ads
= ads_cached_connection(domain
);
741 domain
->last_status
= NT_STATUS_SERVER_DISABLED
;
745 sidstr
= sid_binstring(group_sid
);
747 /* search for all members of the group */
748 if (!(ldap_exp
= talloc_asprintf(mem_ctx
, "(objectSid=%s)",sidstr
))) {
750 DEBUG(1, ("ads: lookup_groupmem: tallloc_asprintf for ldap_exp failed!\n"));
751 status
= NT_STATUS_NO_MEMORY
;
759 attrs
= TALLOC_ARRAY(mem_ctx
, const char *, 3);
760 attrs
[1] = talloc_strdup(mem_ctx
, "usnChanged");
764 if (num_members
== 0)
765 attrs
[0] = talloc_strdup(mem_ctx
, "member");
767 DEBUG(10, ("Searching for attrs[0] = %s, attrs[1] = %s\n", attrs
[0], attrs
[1]));
769 rc
= ads_search_retry(ads
, &res
, ldap_exp
, attrs
);
771 if (!ADS_ERR_OK(rc
) || !res
) {
772 DEBUG(1,("ads: lookup_groupmem ads_search: %s\n",
774 status
= ads_ntstatus(rc
);
778 count
= ads_count_replies(ads
, res
);
782 if (num_members
== 0) {
783 if (!ads_pull_uint32(ads
, res
, "usnChanged", &first_usn
)) {
784 DEBUG(1, ("ads: lookup_groupmem could not pull usnChanged!\n"));
789 if (!ads_pull_uint32(ads
, res
, "usnChanged", ¤t_usn
)) {
790 DEBUG(1, ("ads: lookup_groupmem could not pull usnChanged!\n"));
794 if (first_usn
!= current_usn
) {
795 DEBUG(5, ("ads: lookup_groupmem USN on this record changed"
796 " - restarting search\n"));
797 if (num_retries
< 5) {
802 DEBUG(5, ("ads: lookup_groupmem USN on this record changed"
803 " - restarted search too many times, aborting!\n"));
804 status
= NT_STATUS_UNSUCCESSFUL
;
809 members
= ads_pull_strings_range(ads
, mem_ctx
, res
,
816 if ((members
== NULL
) || (num_members
== 0))
819 } while (more_values
);
821 /* now we need to turn a list of members into rids, names and name types
822 the problem is that the members are in the form of distinguised names
825 (*sid_mem
) = TALLOC_ZERO_ARRAY(mem_ctx
, DOM_SID
, num_members
);
826 (*name_types
) = TALLOC_ZERO_ARRAY(mem_ctx
, uint32
, num_members
);
827 (*names
) = TALLOC_ZERO_ARRAY(mem_ctx
, char *, num_members
);
829 for (i
=0;i
<num_members
;i
++) {
834 if (dn_lookup(ads
, mem_ctx
, members
[i
], &name
, &name_type
, &sid
)) {
835 (*names
)[*num_names
] = name
;
836 (*name_types
)[*num_names
] = name_type
;
837 sid_copy(&(*sid_mem
)[*num_names
], &sid
);
842 status
= NT_STATUS_OK
;
843 DEBUG(3,("ads lookup_groupmem for sid=%s\n", sid_to_string(sid_string
, group_sid
)));
847 ads_msgfree(ads
, res
);
852 /* find the sequence number for a domain */
853 static NTSTATUS
sequence_number(struct winbindd_domain
*domain
, uint32
*seq
)
855 ADS_STRUCT
*ads
= NULL
;
858 DEBUG(3,("ads: fetch sequence_number for %s\n", domain
->name
));
860 *seq
= DOM_SEQUENCE_NONE
;
862 ads
= ads_cached_connection(domain
);
865 domain
->last_status
= NT_STATUS_SERVER_DISABLED
;
866 return NT_STATUS_UNSUCCESSFUL
;
869 rc
= ads_USN(ads
, seq
);
871 if (!ADS_ERR_OK(rc
)) {
873 /* its a dead connection ; don't destroy it
874 through since ads_USN() has already done
877 domain
->private_data
= NULL
;
879 return ads_ntstatus(rc
);
882 /* get a list of trusted domains */
883 static NTSTATUS
trusted_domains(struct winbindd_domain
*domain
,
890 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
891 struct ds_domain_trust
*domains
= NULL
;
894 uint32 flags
= DS_DOMAIN_DIRECT_OUTBOUND
;
895 struct rpc_pipe_client
*cli
;
897 DEBUG(3,("ads: trusted_domains\n"));
904 result
= cm_connect_netlogon(domain
, &cli
);
906 if (!NT_STATUS_IS_OK(result
)) {
907 DEBUG(5, ("trusted_domains: Could not open a connection to %s "
908 "for PIPE_NETLOGON (%s)\n",
909 domain
->name
, nt_errstr(result
)));
910 return NT_STATUS_UNSUCCESSFUL
;
913 if ( NT_STATUS_IS_OK(result
) ) {
914 result
= rpccli_ds_enum_domain_trusts(cli
, mem_ctx
,
917 (unsigned int *)&count
);
920 if ( NT_STATUS_IS_OK(result
) && count
) {
922 /* Allocate memory for trusted domain names and sids */
924 if ( !(*names
= TALLOC_ARRAY(mem_ctx
, char *, count
)) ) {
925 DEBUG(0, ("trusted_domains: out of memory\n"));
926 return NT_STATUS_NO_MEMORY
;
929 if ( !(*alt_names
= TALLOC_ARRAY(mem_ctx
, char *, count
)) ) {
930 DEBUG(0, ("trusted_domains: out of memory\n"));
931 return NT_STATUS_NO_MEMORY
;
934 if ( !(*dom_sids
= TALLOC_ARRAY(mem_ctx
, DOM_SID
, count
)) ) {
935 DEBUG(0, ("trusted_domains: out of memory\n"));
936 return NT_STATUS_NO_MEMORY
;
939 /* Copy across names and sids */
941 for (i
= 0; i
< count
; i
++) {
942 (*names
)[i
] = domains
[i
].netbios_domain
;
943 (*alt_names
)[i
] = domains
[i
].dns_domain
;
945 sid_copy(&(*dom_sids
)[i
], &domains
[i
].sid
);
948 *num_domains
= count
;
954 /* the ADS backend methods are exposed via this structure */
955 struct winbindd_methods ads_methods
= {
964 msrpc_lookup_useraliases
,
967 msrpc_lockout_policy
,
968 msrpc_password_policy
,