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
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #define DBGC_CLASS DBGC_WINBIND
32 return our ads connections structure for a domain. We keep the connection
33 open to make things faster
35 static ADS_STRUCT
*ads_cached_connection(struct winbindd_domain
*domain
)
40 if (domain
->private) {
41 return (ADS_STRUCT
*)domain
->private;
44 /* we don't want this to affect the users ccache */
45 setenv("KRB5CCNAME", "MEMORY:winbind_ccache", 1);
47 ads
= ads_init(domain
->alt_name
, domain
->name
, NULL
);
49 DEBUG(1,("ads_init for domain %s failed\n", domain
->name
));
53 /* the machine acct password might have change - fetch it every time */
54 SAFE_FREE(ads
->auth
.password
);
55 ads
->auth
.password
= secrets_fetch_machine_password(lp_workgroup(), NULL
, NULL
);
57 SAFE_FREE(ads
->auth
.realm
);
58 ads
->auth
.realm
= strdup(lp_realm());
60 status
= ads_connect(ads
);
61 if (!ADS_ERR_OK(status
) || !ads
->config
.realm
) {
62 extern struct winbindd_methods msrpc_methods
, cache_methods
;
63 DEBUG(1,("ads_connect for domain %s failed: %s\n",
64 domain
->name
, ads_errstr(status
)));
67 /* if we get ECONNREFUSED then it might be a NT4
68 server, fall back to MSRPC */
69 if (status
.error_type
== ADS_ERROR_SYSTEM
&&
70 status
.err
.rc
== ECONNREFUSED
) {
71 DEBUG(1,("Trying MSRPC methods\n"));
72 if (domain
->methods
== &cache_methods
) {
73 domain
->backend
= &msrpc_methods
;
75 domain
->methods
= &msrpc_methods
;
81 domain
->private = (void *)ads
;
86 /* Query display info for a realm. This is the basic user list fn */
87 static NTSTATUS
query_user_list(struct winbindd_domain
*domain
,
90 WINBIND_USERINFO
**info
)
92 ADS_STRUCT
*ads
= NULL
;
93 const char *attrs
[] = {"userPrincipalName",
95 "name", "objectSid", "primaryGroupID",
96 "sAMAccountType", NULL
};
101 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
105 DEBUG(3,("ads: query_user_list\n"));
107 ads
= ads_cached_connection(domain
);
110 domain
->last_status
= NT_STATUS_SERVER_DISABLED
;
114 rc
= ads_search_retry(ads
, &res
, "(objectCategory=user)", attrs
);
115 if (!ADS_ERR_OK(rc
) || !res
) {
116 DEBUG(1,("query_user_list ads_search: %s\n", ads_errstr(rc
)));
120 count
= ads_count_replies(ads
, res
);
122 DEBUG(1,("query_user_list: No users found\n"));
126 (*info
) = talloc_zero(mem_ctx
, count
* sizeof(**info
));
128 status
= NT_STATUS_NO_MEMORY
;
134 for (msg
= ads_first_entry(ads
, res
); msg
; msg
= ads_next_entry(ads
, msg
)) {
142 if (!ads_pull_uint32(ads
, msg
, "sAMAccountType", &atype
) ||
143 ads_atype_map(atype
) != SID_NAME_USER
) {
144 DEBUG(1,("Not a user account? atype=0x%x\n", atype
));
148 name
= ads_pull_username(ads
, mem_ctx
, msg
);
149 gecos
= ads_pull_string(ads
, mem_ctx
, msg
, "name");
150 if (!ads_pull_sid(ads
, msg
, "objectSid", &sid
)) {
151 DEBUG(1,("No sid for %s !?\n", name
));
154 if (!ads_pull_uint32(ads
, msg
, "primaryGroupID", &group
)) {
155 DEBUG(1,("No primary group for %s !?\n", name
));
159 sid2
= talloc(mem_ctx
, sizeof(*sid2
));
161 status
= NT_STATUS_NO_MEMORY
;
165 sid_copy(sid2
, &sid
);
167 group_sid
= rid_to_talloced_sid(domain
, mem_ctx
, group
);
169 (*info
)[i
].acct_name
= name
;
170 (*info
)[i
].full_name
= gecos
;
171 (*info
)[i
].user_sid
= sid2
;
172 (*info
)[i
].group_sid
= group_sid
;
177 status
= NT_STATUS_OK
;
179 DEBUG(3,("ads query_user_list gave %d entries\n", (*num_entries
)));
183 ads_msgfree(ads
, res
);
188 /* list all domain groups */
189 static NTSTATUS
enum_dom_groups(struct winbindd_domain
*domain
,
192 struct acct_info
**info
)
194 ADS_STRUCT
*ads
= NULL
;
195 const char *attrs
[] = {"userPrincipalName", "sAMAccountName",
197 "sAMAccountType", NULL
};
202 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
207 DEBUG(3,("ads: enum_dom_groups\n"));
209 ads
= ads_cached_connection(domain
);
212 domain
->last_status
= NT_STATUS_SERVER_DISABLED
;
216 rc
= ads_search_retry(ads
, &res
, "(objectCategory=group)", attrs
);
217 if (!ADS_ERR_OK(rc
) || !res
) {
218 DEBUG(1,("enum_dom_groups ads_search: %s\n", ads_errstr(rc
)));
222 count
= ads_count_replies(ads
, res
);
224 DEBUG(1,("enum_dom_groups: No groups found\n"));
228 (*info
) = talloc_zero(mem_ctx
, count
* sizeof(**info
));
230 status
= NT_STATUS_NO_MEMORY
;
236 group_flags
= ATYPE_GLOBAL_GROUP
;
238 /* only grab domain local groups for our domain */
239 if ( domain
->native_mode
&& strequal(lp_realm(), domain
->alt_name
) )
240 group_flags
|= ATYPE_LOCAL_GROUP
;
242 for (msg
= ads_first_entry(ads
, res
); msg
; msg
= ads_next_entry(ads
, msg
)) {
248 if (!ads_pull_uint32(ads
, msg
, "sAMAccountType", &account_type
) || !(account_type
& group_flags
) )
251 name
= ads_pull_username(ads
, mem_ctx
, msg
);
252 gecos
= ads_pull_string(ads
, mem_ctx
, msg
, "name");
253 if (!ads_pull_sid(ads
, msg
, "objectSid", &sid
)) {
254 DEBUG(1,("No sid for %s !?\n", name
));
258 if (!sid_peek_check_rid(&domain
->sid
, &sid
, &rid
)) {
259 DEBUG(1,("No rid for %s !?\n", name
));
263 fstrcpy((*info
)[i
].acct_name
, name
);
264 fstrcpy((*info
)[i
].acct_desc
, gecos
);
265 (*info
)[i
].rid
= rid
;
271 status
= NT_STATUS_OK
;
273 DEBUG(3,("ads enum_dom_groups gave %d entries\n", (*num_entries
)));
277 ads_msgfree(ads
, res
);
282 /* list all domain local groups */
283 static NTSTATUS
enum_local_groups(struct winbindd_domain
*domain
,
286 struct acct_info
**info
)
289 * This is a stub function only as we returned the domain
290 * local groups in enum_dom_groups() if the domain->native field
291 * was true. This is a simple performance optimization when
294 * if we ever need to enumerate domain local groups separately,
295 * then this the optimization in enum_dom_groups() will need
303 /* convert a single name to a sid in a domain */
304 static NTSTATUS
name_to_sid(struct winbindd_domain
*domain
,
308 enum SID_NAME_USE
*type
)
312 DEBUG(3,("ads: name_to_sid\n"));
314 ads
= ads_cached_connection(domain
);
317 domain
->last_status
= NT_STATUS_SERVER_DISABLED
;
318 return NT_STATUS_UNSUCCESSFUL
;
321 return ads_name_to_sid(ads
, name
, sid
, type
);
324 /* convert a sid to a user or group name */
325 static NTSTATUS
sid_to_name(struct winbindd_domain
*domain
,
329 enum SID_NAME_USE
*type
)
331 ADS_STRUCT
*ads
= NULL
;
332 DEBUG(3,("ads: sid_to_name\n"));
334 ads
= ads_cached_connection(domain
);
337 domain
->last_status
= NT_STATUS_SERVER_DISABLED
;
338 return NT_STATUS_UNSUCCESSFUL
;
341 return ads_sid_to_name(ads
, mem_ctx
, sid
, name
, type
);
345 /* convert a DN to a name, SID and name type
346 this might become a major speed bottleneck if groups have
347 lots of users, in which case we could cache the results
349 static BOOL
dn_lookup(ADS_STRUCT
*ads
, TALLOC_CTX
*mem_ctx
,
351 char **name
, uint32
*name_type
, DOM_SID
*sid
)
355 const char *attrs
[] = {"userPrincipalName", "sAMAccountName",
356 "objectSid", "sAMAccountType", NULL
};
359 char *escaped_dn
= escape_ldap_string_alloc(dn
);
361 DEBUG(3,("ads: dn_lookup\n"));
367 asprintf(&ldap_exp
, "(distinguishedName=%s)", escaped_dn
);
368 rc
= ads_search_retry(ads
, &res
, ldap_exp
, attrs
);
370 SAFE_FREE(escaped_dn
);
372 if (!ADS_ERR_OK(rc
) || !res
) {
376 (*name
) = ads_pull_username(ads
, mem_ctx
, res
);
378 if (!ads_pull_uint32(ads
, res
, "sAMAccountType", &atype
)) {
381 (*name_type
) = ads_atype_map(atype
);
383 if (!ads_pull_sid(ads
, res
, "objectSid", sid
)) {
388 ads_msgfree(ads
, res
);
394 ads_msgfree(ads
, res
);
399 /* Lookup user information from a rid */
400 static NTSTATUS
query_user(struct winbindd_domain
*domain
,
403 WINBIND_USERINFO
*info
)
405 ADS_STRUCT
*ads
= NULL
;
406 const char *attrs
[] = {"userPrincipalName",
409 "primaryGroupID", NULL
};
416 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
420 DEBUG(3,("ads: query_user\n"));
422 ads
= ads_cached_connection(domain
);
425 domain
->last_status
= NT_STATUS_SERVER_DISABLED
;
429 sidstr
= sid_binstring(sid
);
430 asprintf(&ldap_exp
, "(objectSid=%s)", sidstr
);
431 rc
= ads_search_retry(ads
, &msg
, ldap_exp
, attrs
);
434 if (!ADS_ERR_OK(rc
) || !msg
) {
435 DEBUG(1,("query_user(sid=%s) ads_search: %s\n", sid_to_string(sid_string
, sid
), ads_errstr(rc
)));
439 count
= ads_count_replies(ads
, msg
);
441 DEBUG(1,("query_user(sid=%s): Not found\n", sid_to_string(sid_string
, sid
)));
445 info
->acct_name
= ads_pull_username(ads
, mem_ctx
, msg
);
446 info
->full_name
= ads_pull_string(ads
, mem_ctx
, msg
, "name");
448 if (!ads_pull_uint32(ads
, msg
, "primaryGroupID", &group_rid
)) {
449 DEBUG(1,("No primary group for %s !?\n", sid_to_string(sid_string
, sid
)));
453 sid2
= talloc(mem_ctx
, sizeof(*sid2
));
455 status
= NT_STATUS_NO_MEMORY
;
460 info
->user_sid
= sid2
;
462 info
->group_sid
= rid_to_talloced_sid(domain
, mem_ctx
, group_rid
);
464 status
= NT_STATUS_OK
;
466 DEBUG(3,("ads query_user gave %s\n", info
->acct_name
));
469 ads_msgfree(ads
, msg
);
474 /* Lookup groups a user is a member of - alternate method, for when
475 tokenGroups are not available. */
476 static NTSTATUS
lookup_usergroups_alt(struct winbindd_domain
*domain
,
479 DOM_SID
*primary_group
,
480 uint32
*num_groups
, DOM_SID
***user_gids
)
483 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
489 const char *group_attrs
[] = {"objectSid", NULL
};
491 DEBUG(3,("ads: lookup_usergroups_alt\n"));
493 ads
= ads_cached_connection(domain
);
496 domain
->last_status
= NT_STATUS_SERVER_DISABLED
;
500 /* buggy server, no tokenGroups. Instead lookup what groups this user
501 is a member of by DN search on member*/
502 if (asprintf(&ldap_exp
, "(&(member=%s)(objectClass=group))", user_dn
) == -1) {
503 DEBUG(1,("lookup_usergroups(dn=%s) asprintf failed!\n", user_dn
));
504 return NT_STATUS_NO_MEMORY
;
507 rc
= ads_search_retry(ads
, &res
, ldap_exp
, group_attrs
);
510 if (!ADS_ERR_OK(rc
) || !res
) {
511 DEBUG(1,("lookup_usergroups ads_search member=%s: %s\n", user_dn
, ads_errstr(rc
)));
512 return ads_ntstatus(rc
);
515 count
= ads_count_replies(ads
, res
);
517 DEBUG(5,("lookup_usergroups: No supp groups found\n"));
519 status
= ads_ntstatus(rc
);
523 (*user_gids
) = talloc_zero(mem_ctx
, sizeof(**user_gids
) * (count
+ 1));
524 (*user_gids
)[0] = primary_group
;
528 for (msg
= ads_first_entry(ads
, res
); msg
; msg
= ads_next_entry(ads
, msg
)) {
531 if (!ads_pull_sid(ads
, msg
, "objectSid", &group_sid
)) {
532 DEBUG(1,("No sid for this group ?!?\n"));
536 if (sid_equal(&group_sid
, primary_group
)) continue;
538 (*user_gids
)[*num_groups
] = talloc(mem_ctx
, sizeof(***user_gids
));
539 if (!(*user_gids
)[*num_groups
]) {
540 status
= NT_STATUS_NO_MEMORY
;
544 sid_copy((*user_gids
)[*num_groups
], &group_sid
);
550 status
= NT_STATUS_OK
;
552 DEBUG(3,("ads lookup_usergroups (alt) for dn=%s\n", user_dn
));
555 ads_msgfree(ads
, res
);
557 ads_msgfree(ads
, msg
);
562 /* Lookup groups a user is a member of. */
563 static NTSTATUS
lookup_usergroups(struct winbindd_domain
*domain
,
566 uint32
*num_groups
, DOM_SID
***user_gids
)
568 ADS_STRUCT
*ads
= NULL
;
569 const char *attrs
[] = {"distinguishedName", NULL
};
570 const char *attrs2
[] = {"tokenGroups", "primaryGroupID", NULL
};
578 DOM_SID
*primary_group
;
579 uint32 primary_group_rid
;
582 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
584 DEBUG(3,("ads: lookup_usergroups\n"));
587 ads
= ads_cached_connection(domain
);
590 domain
->last_status
= NT_STATUS_SERVER_DISABLED
;
594 if (!(sidstr
= sid_binstring(sid
))) {
595 DEBUG(1,("lookup_usergroups(sid=%s) sid_binstring returned NULL\n", sid_to_string(sid_string
, sid
)));
596 status
= NT_STATUS_NO_MEMORY
;
599 if (asprintf(&ldap_exp
, "(objectSid=%s)", sidstr
) == -1) {
601 DEBUG(1,("lookup_usergroups(sid=%s) asprintf failed!\n", sid_to_string(sid_string
, sid
)));
602 status
= NT_STATUS_NO_MEMORY
;
606 rc
= ads_search_retry(ads
, &msg
, ldap_exp
, attrs
);
610 if (!ADS_ERR_OK(rc
) || !msg
) {
611 DEBUG(1,("lookup_usergroups(sid=%s) ads_search: %s\n", sid_to_string(sid_string
, sid
), ads_errstr(rc
)));
615 user_dn
= ads_pull_string(ads
, mem_ctx
, msg
, "distinguishedName");
617 DEBUG(1,("lookup_usergroups(sid=%s) ads_search did not return a a distinguishedName!\n", sid_to_string(sid_string
, sid
)));
619 ads_msgfree(ads
, msg
);
624 ads_msgfree(ads
, msg
);
626 rc
= ads_search_retry_dn(ads
, &msg
, user_dn
, attrs2
);
627 if (!ADS_ERR_OK(rc
) || !msg
) {
628 DEBUG(1,("lookup_usergroups(sid=%s) ads_search tokenGroups: %s\n", sid_to_string(sid_string
, sid
), ads_errstr(rc
)));
632 if (!ads_pull_uint32(ads
, msg
, "primaryGroupID", &primary_group_rid
)) {
633 DEBUG(1,("%s: No primary group for sid=%s !?\n", domain
->name
, sid_to_string(sid_string
, sid
)));
637 primary_group
= rid_to_talloced_sid(domain
, mem_ctx
, primary_group_rid
);
639 count
= ads_pull_sids(ads
, mem_ctx
, msg
, "tokenGroups", &sids
);
642 ads_msgfree(ads
, msg
);
644 /* there must always be at least one group in the token,
645 unless we are talking to a buggy Win2k server */
647 return lookup_usergroups_alt(domain
, mem_ctx
, user_dn
,
649 num_groups
, user_gids
);
652 (*user_gids
) = talloc_zero(mem_ctx
, sizeof(**user_gids
) * (count
+ 1));
653 (*user_gids
)[0] = primary_group
;
657 for (i
=0;i
<count
;i
++) {
658 if (sid_equal(&sids
[i
], primary_group
)) continue;
660 (*user_gids
)[*num_groups
] = talloc(mem_ctx
, sizeof(***user_gids
));
661 if (!(*user_gids
)[*num_groups
]) {
662 status
= NT_STATUS_NO_MEMORY
;
666 sid_copy((*user_gids
)[*num_groups
], &sids
[i
]);
670 status
= NT_STATUS_OK
;
671 DEBUG(3,("ads lookup_usergroups for sid=%s\n", sid_to_string(sid_string
, sid
)));
677 find the members of a group, given a group rid and domain
679 static NTSTATUS
lookup_groupmem(struct winbindd_domain
*domain
,
681 DOM_SID
*group_sid
, uint32
*num_names
,
682 DOM_SID
***sid_mem
, char ***names
,
688 ADS_STRUCT
*ads
= NULL
;
690 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
692 const char *attrs
[] = {"member", NULL
};
697 DEBUG(10,("ads: lookup_groupmem %s sid=%s\n", domain
->name
, sid_string_static(group_sid
)));
701 ads
= ads_cached_connection(domain
);
704 domain
->last_status
= NT_STATUS_SERVER_DISABLED
;
708 sidstr
= sid_binstring(group_sid
);
710 /* search for all members of the group */
711 asprintf(&ldap_exp
, "(objectSid=%s)",sidstr
);
712 rc
= ads_search_retry(ads
, &res
, ldap_exp
, attrs
);
716 if (!ADS_ERR_OK(rc
) || !res
) {
717 DEBUG(1,("query_user_list ads_search: %s\n", ads_errstr(rc
)));
721 count
= ads_count_replies(ads
, res
);
723 status
= NT_STATUS_OK
;
727 members
= ads_pull_strings(ads
, mem_ctx
, res
, "member");
729 /* no members? ok ... */
730 status
= NT_STATUS_OK
;
734 /* now we need to turn a list of members into rids, names and name types
735 the problem is that the members are in the form of distinguised names
737 for (i
=0;members
[i
];i
++) /* noop */ ;
740 (*sid_mem
) = talloc_zero(mem_ctx
, sizeof(**sid_mem
) * num_members
);
741 (*name_types
) = talloc_zero(mem_ctx
, sizeof(**name_types
) * num_members
);
742 (*names
) = talloc_zero(mem_ctx
, sizeof(**names
) * num_members
);
744 for (i
=0;i
<num_members
;i
++) {
749 if (dn_lookup(ads
, mem_ctx
, members
[i
], &name
, &name_type
, &sid
)) {
750 (*names
)[*num_names
] = name
;
751 (*name_types
)[*num_names
] = name_type
;
752 (*sid_mem
)[*num_names
] = talloc(mem_ctx
, sizeof(***sid_mem
));
753 if (!(*sid_mem
)[*num_names
]) {
754 status
= NT_STATUS_NO_MEMORY
;
757 sid_copy((*sid_mem
)[*num_names
], &sid
);
762 status
= NT_STATUS_OK
;
763 DEBUG(3,("ads lookup_groupmem for sid=%s\n", sid_to_string(sid_string
, group_sid
)));
766 ads_msgfree(ads
, res
);
772 /* find the sequence number for a domain */
773 static NTSTATUS
sequence_number(struct winbindd_domain
*domain
, uint32
*seq
)
775 ADS_STRUCT
*ads
= NULL
;
778 DEBUG(3,("ads: fetch sequence_number for %s\n", domain
->name
));
780 *seq
= DOM_SEQUENCE_NONE
;
782 ads
= ads_cached_connection(domain
);
785 domain
->last_status
= NT_STATUS_SERVER_DISABLED
;
786 return NT_STATUS_UNSUCCESSFUL
;
789 rc
= ads_USN(ads
, seq
);
791 if (!ADS_ERR_OK(rc
)) {
793 /* its a dead connection ; don't destroy it
794 through since ads_USN() has already done
797 domain
->private = NULL
;
799 return ads_ntstatus(rc
);
802 /* get a list of trusted domains */
803 static NTSTATUS
trusted_domains(struct winbindd_domain
*domain
,
810 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
811 DS_DOMAIN_TRUSTS
*domains
= NULL
;
814 struct cli_state
*cli
= NULL
;
815 /* i think we only need our forest and downlevel trusted domains */
816 uint32 flags
= DS_DOMAIN_IN_FOREST
| DS_DOMAIN_DIRECT_OUTBOUND
;
817 char *contact_domain_name
;
819 DEBUG(3,("ads: trusted_domains\n"));
826 contact_domain_name
= *domain
->alt_name
? domain
->alt_name
: domain
->name
;
827 if ( !NT_STATUS_IS_OK(result
= cm_fresh_connection(contact_domain_name
, PI_NETLOGON
, &cli
)) ) {
828 DEBUG(5, ("trusted_domains: Could not open a connection to %s for PIPE_NETLOGON (%s)\n",
829 contact_domain_name
, nt_errstr(result
)));
830 return NT_STATUS_UNSUCCESSFUL
;
833 if ( NT_STATUS_IS_OK(result
) )
834 result
= cli_ds_enum_domain_trusts( cli
, mem_ctx
, cli
->desthost
, flags
, &domains
, (unsigned int *)&count
);
836 if ( NT_STATUS_IS_OK(result
) && count
) {
838 /* Allocate memory for trusted domain names and sids */
840 if ( !(*names
= (char **)talloc(mem_ctx
, sizeof(char *) * count
)) ) {
841 DEBUG(0, ("trusted_domains: out of memory\n"));
842 result
= NT_STATUS_NO_MEMORY
;
846 if ( !(*alt_names
= (char **)talloc(mem_ctx
, sizeof(char *) * count
)) ) {
847 DEBUG(0, ("trusted_domains: out of memory\n"));
848 result
= NT_STATUS_NO_MEMORY
;
852 if ( !(*dom_sids
= (DOM_SID
*)talloc(mem_ctx
, sizeof(DOM_SID
) * count
)) ) {
853 DEBUG(0, ("trusted_domains: out of memory\n"));
854 result
= NT_STATUS_NO_MEMORY
;
858 /* Copy across names and sids */
860 for (i
= 0; i
< count
; i
++) {
865 (*alt_names
)[i
] = NULL
;
866 ZERO_STRUCT( (*dom_sids
)[i
] );
868 if ( domains
[i
].netbios_ptr
) {
869 unistr2_to_ascii(tmp
, &domains
[i
].netbios_domain
, sizeof(tmp
) - 1);
870 (*names
)[i
] = talloc_strdup(mem_ctx
, tmp
);
873 if ( domains
[i
].dns_ptr
) {
874 unistr2_to_ascii(tmp2
, &domains
[i
].dns_domain
, sizeof(tmp2
) - 1);
875 (*alt_names
)[i
] = talloc_strdup(mem_ctx
, tmp2
);
878 /* sometimes we will get back a NULL SID from this call */
880 if ( domains
[i
].sid_ptr
)
881 sid_copy(&(*dom_sids
)[i
], &domains
[i
].sid
.sid
);
884 *num_domains
= count
;
889 SAFE_FREE( domains
);
891 /* remove connection; This is a special case to the \NETLOGON pipe */
899 /* find the domain sid for a domain */
900 static NTSTATUS
domain_sid(struct winbindd_domain
*domain
, DOM_SID
*sid
)
905 DEBUG(3,("ads: domain_sid\n"));
907 ads
= ads_cached_connection(domain
);
910 domain
->last_status
= NT_STATUS_SERVER_DISABLED
;
911 return NT_STATUS_UNSUCCESSFUL
;
914 rc
= ads_domain_sid(ads
, sid
);
916 if (!ADS_ERR_OK(rc
)) {
918 /* its a dead connection; don't destroy it though
919 since that has already been done indirectly
920 by ads_domain_sid() */
922 domain
->private = NULL
;
925 return ads_ntstatus(rc
);
929 /* find alternate names list for the domain - for ADS this is the
931 static NTSTATUS
alternate_name(struct winbindd_domain
*domain
)
938 DEBUG(3,("ads: alternate_name\n"));
940 ads
= ads_cached_connection(domain
);
943 domain
->last_status
= NT_STATUS_SERVER_DISABLED
;
944 return NT_STATUS_UNSUCCESSFUL
;
947 if (!(ctx
= talloc_init("alternate_name"))) {
948 return NT_STATUS_NO_MEMORY
;
951 rc
= ads_workgroup_name(ads
, ctx
, &workgroup
);
953 if (ADS_ERR_OK(rc
)) {
954 fstrcpy(domain
->name
, workgroup
);
955 fstrcpy(domain
->alt_name
, ads
->config
.realm
);
956 strupper_m(domain
->alt_name
);
957 strupper_m(domain
->name
);
962 return ads_ntstatus(rc
);
965 /* the ADS backend methods are exposed via this structure */
966 struct winbindd_methods ads_methods
= {