2 Unix SMB/CIFS implementation.
6 Copyright (C) Gerald Carter 2006
7 Copyright (C) Guenther Deschner 2007-2008
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 3 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, see <http://www.gnu.org/licenses/>.
25 #define DSGETDCNAME_FMT "DSGETDCNAME/DOMAIN/%s"
27 #define DSGETDCNAME_CACHE_TTL 60*15
29 struct ip_service_name
{
30 struct sockaddr_storage ss
;
35 /****************************************************************
36 ****************************************************************/
38 void debug_dsdcinfo_flags(int lvl
, uint32_t flags
)
40 DEBUG(lvl
,("debug_dsdcinfo_flags: 0x%08x\n\t", flags
));
42 if (flags
& DS_FORCE_REDISCOVERY
)
43 DEBUGADD(lvl
,("DS_FORCE_REDISCOVERY "));
44 if (flags
& 0x000000002)
45 DEBUGADD(lvl
,("0x00000002 "));
46 if (flags
& 0x000000004)
47 DEBUGADD(lvl
,("0x00000004 "));
48 if (flags
& 0x000000008)
49 DEBUGADD(lvl
,("0x00000008 "));
50 if (flags
& DS_DIRECTORY_SERVICE_REQUIRED
)
51 DEBUGADD(lvl
,("DS_DIRECTORY_SERVICE_REQUIRED "));
52 if (flags
& DS_DIRECTORY_SERVICE_PREFERRED
)
53 DEBUGADD(lvl
,("DS_DIRECTORY_SERVICE_PREFERRED "));
54 if (flags
& DS_GC_SERVER_REQUIRED
)
55 DEBUGADD(lvl
,("DS_GC_SERVER_REQUIRED "));
56 if (flags
& DS_PDC_REQUIRED
)
57 DEBUGADD(lvl
,("DS_PDC_REQUIRED "));
58 if (flags
& DS_BACKGROUND_ONLY
)
59 DEBUGADD(lvl
,("DS_BACKGROUND_ONLY "));
60 if (flags
& DS_IP_REQUIRED
)
61 DEBUGADD(lvl
,("DS_IP_REQUIRED "));
62 if (flags
& DS_KDC_REQUIRED
)
63 DEBUGADD(lvl
,("DS_KDC_REQUIRED "));
64 if (flags
& DS_TIMESERV_REQUIRED
)
65 DEBUGADD(lvl
,("DS_TIMESERV_REQUIRED "));
66 if (flags
& DS_WRITABLE_REQUIRED
)
67 DEBUGADD(lvl
,("DS_WRITABLE_REQUIRED "));
68 if (flags
& DS_GOOD_TIMESERV_PREFERRED
)
69 DEBUGADD(lvl
,("DS_GOOD_TIMESERV_PREFERRED "));
70 if (flags
& DS_AVOID_SELF
)
71 DEBUGADD(lvl
,("DS_AVOID_SELF "));
72 if (flags
& DS_ONLY_LDAP_NEEDED
)
73 DEBUGADD(lvl
,("DS_ONLY_LDAP_NEEDED "));
74 if (flags
& DS_IS_FLAT_NAME
)
75 DEBUGADD(lvl
,("DS_IS_FLAT_NAME "));
76 if (flags
& DS_IS_DNS_NAME
)
77 DEBUGADD(lvl
,("DS_IS_DNS_NAME "));
78 if (flags
& 0x00040000)
79 DEBUGADD(lvl
,("0x00040000 "));
80 if (flags
& 0x00080000)
81 DEBUGADD(lvl
,("0x00080000 "));
82 if (flags
& 0x00100000)
83 DEBUGADD(lvl
,("0x00100000 "));
84 if (flags
& 0x00200000)
85 DEBUGADD(lvl
,("0x00200000 "));
86 if (flags
& 0x00400000)
87 DEBUGADD(lvl
,("0x00400000 "));
88 if (flags
& 0x00800000)
89 DEBUGADD(lvl
,("0x00800000 "));
90 if (flags
& 0x01000000)
91 DEBUGADD(lvl
,("0x01000000 "));
92 if (flags
& 0x02000000)
93 DEBUGADD(lvl
,("0x02000000 "));
94 if (flags
& 0x04000000)
95 DEBUGADD(lvl
,("0x04000000 "));
96 if (flags
& 0x08000000)
97 DEBUGADD(lvl
,("0x08000000 "));
98 if (flags
& 0x10000000)
99 DEBUGADD(lvl
,("0x10000000 "));
100 if (flags
& 0x20000000)
101 DEBUGADD(lvl
,("0x20000000 "));
102 if (flags
& DS_RETURN_DNS_NAME
)
103 DEBUGADD(lvl
,("DS_RETURN_DNS_NAME "));
104 if (flags
& DS_RETURN_FLAT_NAME
)
105 DEBUGADD(lvl
,("DS_RETURN_FLAT_NAME "));
107 DEBUGADD(lvl
,("\n"));
110 /*********************************************************************
111 ********************************************************************/
113 static int pack_dsdcinfo(struct DS_DOMAIN_CONTROLLER_INFO
*info
,
116 unsigned char *buffer
= NULL
;
121 DEBUG(10,("pack_dsdcinfo: Packing dsdcinfo\n"));
123 ZERO_STRUCT(guid_flat
);
125 if (info
->domain_guid
) {
126 const struct GUID
*guid
= info
->domain_guid
;
127 smb_uuid_pack(*guid
, &guid_flat
);
134 DEBUG(10,("pack_dsdcinfo: Packing domain %s (%s)\n",
135 info
->domain_name
, info
->domain_controller_name
));
138 len
+= tdb_pack(buffer
+len
, buflen
-len
, "ffdBffdff",
139 info
->domain_controller_name
,
140 info
->domain_controller_address
,
141 info
->domain_controller_address_type
,
142 UUID_FLAT_SIZE
, guid_flat
.info
,
144 info
->dns_forest_name
,
147 info
->client_site_name
);
151 if ((buffer
= SMB_MALLOC_ARRAY(unsigned char, len
)) == NULL
) {
152 DEBUG(0,("pack_dsdcinfo: failed to alloc buffer!\n"));
166 /*********************************************************************
167 ********************************************************************/
169 static NTSTATUS
unpack_dsdcinfo(TALLOC_CTX
*mem_ctx
,
172 struct DS_DOMAIN_CONTROLLER_INFO
**info_ret
)
175 struct DS_DOMAIN_CONTROLLER_INFO
*info
= NULL
;
176 uint32_t guid_len
= 0;
177 unsigned char *guid_buf
= NULL
;
180 /* forgive me 6 times */
181 fstring domain_controller_name
;
182 fstring domain_controller_address
;
184 fstring dns_forest_name
;
185 fstring dc_site_name
;
186 fstring client_site_name
;
188 info
= TALLOC_ZERO_P(mem_ctx
, struct DS_DOMAIN_CONTROLLER_INFO
);
189 NT_STATUS_HAVE_NO_MEMORY(info
);
191 len
+= tdb_unpack(buf
+len
, buflen
-len
, "ffdBffdff",
192 &domain_controller_name
,
193 &domain_controller_address
,
194 &info
->domain_controller_address_type
,
195 &guid_len
, &guid_buf
,
202 DEBUG(5,("unpack_dsdcinfo: Failed to unpack domain\n"));
206 info
->domain_controller_name
=
207 talloc_strdup(mem_ctx
, domain_controller_name
);
208 info
->domain_controller_address
=
209 talloc_strdup(mem_ctx
, domain_controller_address
);
211 talloc_strdup(mem_ctx
, domain_name
);
212 info
->dns_forest_name
=
213 talloc_strdup(mem_ctx
, dns_forest_name
);
215 talloc_strdup(mem_ctx
, dc_site_name
);
216 info
->client_site_name
=
217 talloc_strdup(mem_ctx
, client_site_name
);
219 if (!info
->domain_controller_name
||
220 !info
->domain_controller_address
||
221 !info
->domain_name
||
222 !info
->dns_forest_name
||
223 !info
->dc_site_name
||
224 !info
->client_site_name
) {
231 if (guid_len
!= UUID_FLAT_SIZE
) {
235 memcpy(&guid_flat
.info
, guid_buf
, guid_len
);
236 smb_uuid_unpack(guid_flat
, &guid
);
238 info
->domain_guid
= (struct GUID
*)talloc_memdup(
239 mem_ctx
, &guid
, sizeof(guid
));
240 if (!info
->domain_guid
) {
246 DEBUG(10,("unpack_dcscinfo: Unpacked domain %s (%s)\n",
247 info
->domain_name
, info
->domain_controller_name
));
256 return NT_STATUS_NO_MEMORY
;
259 /****************************************************************
260 ****************************************************************/
262 static char *dsgetdcname_cache_key(TALLOC_CTX
*mem_ctx
, const char *domain
)
264 if (!mem_ctx
|| !domain
) {
268 return talloc_asprintf_strupper_m(mem_ctx
, DSGETDCNAME_FMT
, domain
);
271 /****************************************************************
272 ****************************************************************/
274 static NTSTATUS
dsgetdcname_cache_delete(TALLOC_CTX
*mem_ctx
,
275 const char *domain_name
)
279 if (!gencache_init()) {
280 return NT_STATUS_INTERNAL_DB_ERROR
;
283 key
= dsgetdcname_cache_key(mem_ctx
, domain_name
);
285 return NT_STATUS_NO_MEMORY
;
288 if (!gencache_del(key
)) {
289 return NT_STATUS_UNSUCCESSFUL
;
295 /****************************************************************
296 ****************************************************************/
298 static NTSTATUS
dsgetdcname_cache_store(TALLOC_CTX
*mem_ctx
,
299 const char *domain_name
,
300 struct DS_DOMAIN_CONTROLLER_INFO
*info
)
306 unsigned char *buf
= NULL
;
309 if (!gencache_init()) {
310 return NT_STATUS_INTERNAL_DB_ERROR
;
313 key
= dsgetdcname_cache_key(mem_ctx
, domain_name
);
315 return NT_STATUS_NO_MEMORY
;
318 expire_time
= time(NULL
) + DSGETDCNAME_CACHE_TTL
;
320 len
= pack_dsdcinfo(info
, &buf
);
322 return NT_STATUS_UNSUCCESSFUL
;
325 blob
= data_blob(buf
, len
);
328 if (gencache_lock_entry(key
) != 0) {
329 data_blob_free(&blob
);
330 return NT_STATUS_LOCK_NOT_GRANTED
;
333 ret
= gencache_set_data_blob(key
, &blob
, expire_time
);
334 data_blob_free(&blob
);
336 gencache_unlock_entry(key
);
338 return ret
? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
341 /****************************************************************
342 ****************************************************************/
344 static NTSTATUS
dsgetdcname_cache_refresh(TALLOC_CTX
*mem_ctx
,
345 const char *domain_name
,
346 struct GUID
*domain_guid
,
348 const char *site_name
,
349 struct DS_DOMAIN_CONTROLLER_INFO
*info
)
351 struct cldap_netlogon_reply r
;
353 /* check if matching entry is older then 15 minutes, if yes, send
354 * CLDAP/MAILSLOT ping again and store the cached data */
358 if (ads_cldap_netlogon(info
->domain_controller_name
,
359 info
->domain_name
, &r
)) {
361 dsgetdcname_cache_delete(mem_ctx
, domain_name
);
363 return dsgetdcname_cache_store(mem_ctx
,
368 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
371 /****************************************************************
372 ****************************************************************/
374 #define RETURN_ON_FALSE(x) if (!x) return false;
376 static bool check_cldap_reply_required_flags(uint32_t ret_flags
,
379 if (req_flags
& DS_PDC_REQUIRED
)
380 RETURN_ON_FALSE(ret_flags
& ADS_PDC
);
382 if (req_flags
& DS_GC_SERVER_REQUIRED
)
383 RETURN_ON_FALSE(ret_flags
& ADS_GC
);
385 if (req_flags
& DS_ONLY_LDAP_NEEDED
)
386 RETURN_ON_FALSE(ret_flags
& ADS_LDAP
);
388 if ((req_flags
& DS_DIRECTORY_SERVICE_REQUIRED
) ||
389 (req_flags
& DS_DIRECTORY_SERVICE_PREFERRED
))
390 RETURN_ON_FALSE(ret_flags
& ADS_DS
);
392 if (req_flags
& DS_KDC_REQUIRED
)
393 RETURN_ON_FALSE(ret_flags
& ADS_KDC
);
395 if (req_flags
& DS_TIMESERV_REQUIRED
)
396 RETURN_ON_FALSE(ret_flags
& ADS_TIMESERV
);
398 if (req_flags
& DS_WRITABLE_REQUIRED
)
399 RETURN_ON_FALSE(ret_flags
& ADS_WRITABLE
);
404 /****************************************************************
405 ****************************************************************/
407 static NTSTATUS
dsgetdcname_cache_fetch(TALLOC_CTX
*mem_ctx
,
408 const char *domain_name
,
409 struct GUID
*domain_guid
,
411 const char *site_name
,
412 struct DS_DOMAIN_CONTROLLER_INFO
**info
,
419 if (!gencache_init()) {
420 return NT_STATUS_INTERNAL_DB_ERROR
;
423 key
= dsgetdcname_cache_key(mem_ctx
, domain_name
);
425 return NT_STATUS_NO_MEMORY
;
428 if (!gencache_get_data_blob(key
, &blob
, expired
)) {
429 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
432 status
= unpack_dsdcinfo(mem_ctx
, blob
.data
, blob
.length
, info
);
433 if (!NT_STATUS_IS_OK(status
)) {
434 data_blob_free(&blob
);
438 data_blob_free(&blob
);
441 if (!check_cldap_reply_required_flags((*info
)->flags
, flags
)) {
442 DEBUG(10,("invalid flags\n"));
443 return NT_STATUS_INVALID_PARAMETER
;
446 if ((flags
& DS_IP_REQUIRED
) &&
447 ((*info
)->domain_controller_address_type
!= ADS_INET_ADDRESS
)) {
448 return NT_STATUS_INVALID_PARAMETER_MIX
;
454 /****************************************************************
455 ****************************************************************/
457 static NTSTATUS
dsgetdcname_cached(TALLOC_CTX
*mem_ctx
,
458 const char *domain_name
,
459 struct GUID
*domain_guid
,
461 const char *site_name
,
462 struct DS_DOMAIN_CONTROLLER_INFO
**info
)
465 bool expired
= false;
467 status
= dsgetdcname_cache_fetch(mem_ctx
, domain_name
, domain_guid
,
468 flags
, site_name
, info
, &expired
);
469 if (!NT_STATUS_IS_OK(status
)) {
470 DEBUG(10,("dsgetdcname_cached: cache fetch failed with: %s\n",
472 return NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND
;
475 if (flags
& DS_BACKGROUND_ONLY
) {
480 status
= dsgetdcname_cache_refresh(mem_ctx
, domain_name
,
483 if (!NT_STATUS_IS_OK(status
)) {
491 /****************************************************************
492 ****************************************************************/
494 static bool check_allowed_required_flags(uint32_t flags
)
496 uint32_t return_type
= flags
& (DS_RETURN_FLAT_NAME
|DS_RETURN_DNS_NAME
);
497 uint32_t offered_type
= flags
& (DS_IS_FLAT_NAME
|DS_IS_DNS_NAME
);
498 uint32_t query_type
= flags
& (DS_BACKGROUND_ONLY
|DS_FORCE_REDISCOVERY
);
500 /* FIXME: check for DSGETDC_VALID_FLAGS and check for excluse bits
501 * (DS_PDC_REQUIRED, DS_KDC_REQUIRED, DS_GC_SERVER_REQUIRED) */
503 debug_dsdcinfo_flags(10, flags
);
505 if (return_type
== (DS_RETURN_FLAT_NAME
|DS_RETURN_DNS_NAME
)) {
509 if (offered_type
== (DS_IS_DNS_NAME
|DS_IS_FLAT_NAME
)) {
513 if (query_type
== (DS_BACKGROUND_ONLY
|DS_FORCE_REDISCOVERY
)) {
518 if ((flags
& DS_RETURN_DNS_NAME
) && (!(flags
& DS_IP_REQUIRED
))) {
519 printf("gd: here5 \n");
526 /****************************************************************
527 ****************************************************************/
529 static NTSTATUS
discover_dc_netbios(TALLOC_CTX
*mem_ctx
,
530 const char *domain_name
,
532 struct ip_service_name
**returned_dclist
,
535 if (lp_disable_netbios()) {
536 return NT_STATUS_NOT_SUPPORTED
;
539 /* FIXME: code here */
541 return NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND
;
544 /****************************************************************
545 ****************************************************************/
547 static NTSTATUS
discover_dc_dns(TALLOC_CTX
*mem_ctx
,
548 const char *domain_name
,
549 struct GUID
*domain_guid
,
551 const char *site_name
,
552 struct ip_service_name
**returned_dclist
,
557 struct dns_rr_srv
*dcs
= NULL
;
561 if ((!(flags
& DS_DIRECTORY_SERVICE_REQUIRED
)) &&
562 (!(flags
& DS_KDC_REQUIRED
)) &&
563 (!(flags
& DS_GC_SERVER_REQUIRED
)) &&
564 (!(flags
& DS_PDC_REQUIRED
))) {
565 DEBUG(1,("discover_dc_dns: invalid flags\n"));
566 return NT_STATUS_INVALID_PARAMETER
;
569 if (flags
& DS_PDC_REQUIRED
) {
570 status
= ads_dns_query_pdc(mem_ctx
, domain_name
,
572 } else if (flags
& DS_GC_SERVER_REQUIRED
) {
573 status
= ads_dns_query_gcs(mem_ctx
, domain_name
, site_name
,
575 } else if (flags
& DS_KDC_REQUIRED
) {
576 status
= ads_dns_query_kdcs(mem_ctx
, domain_name
, site_name
,
578 } else if (flags
& DS_DIRECTORY_SERVICE_REQUIRED
) {
579 status
= ads_dns_query_dcs(mem_ctx
, domain_name
, site_name
,
581 } else if (domain_guid
) {
582 status
= ads_dns_query_dcs_guid(mem_ctx
, domain_name
,
583 domain_guid
, &dcs
, &numdcs
);
586 DEBUG(1,("discover_dc_dns: not enough input\n"));
587 status
= NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND
;
590 if (!NT_STATUS_IS_OK(status
)) {
595 return NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND
;
598 for (i
=0;i
<numdcs
;i
++) {
599 numaddrs
+= MAX(dcs
[i
].num_ips
,1);
602 if ((*returned_dclist
= TALLOC_ZERO_ARRAY(mem_ctx
,
603 struct ip_service_name
,
604 numaddrs
)) == NULL
) {
605 return NT_STATUS_NO_MEMORY
;
608 /* now unroll the list of IP addresses */
613 while (i
< numdcs
&& (*return_count
<numaddrs
)) {
615 struct ip_service_name
*r
= &(*returned_dclist
)[*return_count
];
617 r
->port
= dcs
[i
].port
;
618 r
->hostname
= dcs
[i
].hostname
;
620 if (!(flags
& DS_IP_REQUIRED
)) {
625 /* If we don't have an IP list for a name, lookup it up */
628 interpret_string_addr(&r
->ss
, dcs
[i
].hostname
, 0);
632 /* use the IP addresses from the SRV sresponse */
634 if (j
>= dcs
[i
].num_ips
) {
640 r
->ss
= dcs
[i
].ss_s
[j
];
644 /* make sure it is a valid IP. I considered checking the
645 * negative connection cache, but this is the wrong place for
646 * it. Maybe only as a hac. After think about it, if all of
647 * the IP addresses retuend from DNS are dead, what hope does a
648 * netbios name lookup have? The standard reason for falling
649 * back to netbios lookups is that our DNS server doesn't know
650 * anything about the DC's -- jerry */
652 if (!is_zero_addr(&r
->ss
)) {
658 return (*return_count
> 0) ? NT_STATUS_OK
:
659 NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND
;
662 /****************************************************************
663 ****************************************************************/
665 static NTSTATUS
make_domain_controller_info(TALLOC_CTX
*mem_ctx
,
666 const char *domain_controller_name
,
667 const char *domain_controller_address
,
668 uint32_t domain_controller_address_type
,
669 const struct GUID
*domain_guid
,
670 const char *domain_name
,
671 const char *dns_forest_name
,
673 const char *dc_site_name
,
674 const char *client_site_name
,
675 struct DS_DOMAIN_CONTROLLER_INFO
**info_out
)
677 struct DS_DOMAIN_CONTROLLER_INFO
*info
;
679 info
= TALLOC_ZERO_P(mem_ctx
, struct DS_DOMAIN_CONTROLLER_INFO
);
680 NT_STATUS_HAVE_NO_MEMORY(info
);
682 if (domain_controller_name
) {
683 info
->domain_controller_name
= talloc_strdup(mem_ctx
,
684 domain_controller_name
);
685 NT_STATUS_HAVE_NO_MEMORY(info
->domain_controller_name
);
688 if (domain_controller_address
) {
689 info
->domain_controller_address
= talloc_strdup(mem_ctx
,
690 domain_controller_address
);
691 NT_STATUS_HAVE_NO_MEMORY(info
->domain_controller_address
);
694 info
->domain_controller_address_type
= domain_controller_address_type
;
697 info
->domain_guid
= (struct GUID
*)talloc_memdup(
698 mem_ctx
, domain_guid
, sizeof(*domain_guid
));
699 NT_STATUS_HAVE_NO_MEMORY(info
->domain_guid
);
703 info
->domain_name
= talloc_strdup(mem_ctx
, domain_name
);
704 NT_STATUS_HAVE_NO_MEMORY(info
->domain_name
);
707 if (dns_forest_name
) {
708 info
->dns_forest_name
= talloc_strdup(mem_ctx
,
710 NT_STATUS_HAVE_NO_MEMORY(info
->dns_forest_name
);
716 info
->dc_site_name
= talloc_strdup(mem_ctx
, dc_site_name
);
717 NT_STATUS_HAVE_NO_MEMORY(info
->dc_site_name
);
720 if (client_site_name
) {
721 info
->client_site_name
= talloc_strdup(mem_ctx
,
723 NT_STATUS_HAVE_NO_MEMORY(info
->client_site_name
);
731 /****************************************************************
732 ****************************************************************/
734 static NTSTATUS
process_dc_dns(TALLOC_CTX
*mem_ctx
,
735 const char *domain_name
,
737 struct ip_service_name
**dclist
,
739 struct DS_DOMAIN_CONTROLLER_INFO
**info
)
742 bool valid_dc
= false;
743 struct cldap_netlogon_reply r
;
744 const char *dc_hostname
, *dc_domain_name
;
745 const char *dc_address
;
746 uint32_t dc_address_type
;
750 for (i
=0; i
<num_dcs
; i
++) {
754 if ((ads_cldap_netlogon(dclist
[i
]->hostname
,
756 (check_cldap_reply_required_flags(r
.flags
, flags
))) {
765 return NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND
;
770 if (flags
& DS_RETURN_FLAT_NAME
) {
771 if (!strlen(r
.netbios_hostname
) || !strlen(r
.netbios_domain
)) {
772 return NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND
;
774 dc_hostname
= r
.netbios_hostname
;
775 dc_domain_name
= r
.netbios_domain
;
776 } else if (flags
& DS_RETURN_DNS_NAME
) {
777 if (!strlen(r
.hostname
) || !strlen(r
.domain
)) {
778 return NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND
;
780 dc_hostname
= r
.hostname
;
781 dc_domain_name
= r
.domain
;
782 dc_flags
|= ADS_DNS_DOMAIN
| ADS_DNS_CONTROLLER
;
785 dc_hostname
= r
.hostname
;
786 dc_domain_name
= r
.domain
;
787 dc_flags
|= ADS_DNS_DOMAIN
| ADS_DNS_CONTROLLER
;
790 if (flags
& DS_IP_REQUIRED
) {
791 char addr
[INET6_ADDRSTRLEN
];
792 print_sockaddr(addr
, sizeof(addr
), &dclist
[i
]->ss
);
793 dc_address
= talloc_asprintf(mem_ctx
, "\\\\%s",
795 dc_address_type
= ADS_INET_ADDRESS
;
797 dc_address
= talloc_asprintf(mem_ctx
, "\\\\%s",
799 dc_address_type
= ADS_NETBIOS_ADDRESS
;
801 NT_STATUS_HAVE_NO_MEMORY(dc_address
);
802 smb_uuid_unpack(r
.guid
, &dc_guid
);
805 dc_flags
|= ADS_DNS_FOREST
;
808 return make_domain_controller_info(mem_ctx
,
822 /****************************************************************
823 ****************************************************************/
825 static NTSTATUS
process_dc_netbios(TALLOC_CTX
*mem_ctx
,
826 const char *domain_name
,
828 struct ip_service_name
**dclist
,
830 struct DS_DOMAIN_CONTROLLER_INFO
**info
)
832 /* FIXME: code here */
834 return NT_STATUS_NOT_SUPPORTED
;
837 /****************************************************************
838 ****************************************************************/
840 static NTSTATUS
dsgetdcname_rediscover(TALLOC_CTX
*mem_ctx
,
841 const char *domain_name
,
842 struct GUID
*domain_guid
,
844 const char *site_name
,
845 struct DS_DOMAIN_CONTROLLER_INFO
**info
)
847 NTSTATUS status
= NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND
;
848 struct ip_service_name
*dclist
;
851 DEBUG(10,("dsgetdcname_rediscover\n"));
853 if (flags
& DS_IS_FLAT_NAME
) {
855 status
= discover_dc_netbios(mem_ctx
, domain_name
, flags
,
857 NT_STATUS_NOT_OK_RETURN(status
);
859 return process_dc_netbios(mem_ctx
, domain_name
, flags
,
860 &dclist
, num_dcs
, info
);
863 if (flags
& DS_IS_DNS_NAME
) {
865 status
= discover_dc_dns(mem_ctx
, domain_name
, domain_guid
,
866 flags
, site_name
, &dclist
, &num_dcs
);
867 NT_STATUS_NOT_OK_RETURN(status
);
869 return process_dc_dns(mem_ctx
, domain_name
, flags
,
870 &dclist
, num_dcs
, info
);
873 status
= discover_dc_dns(mem_ctx
, domain_name
, domain_guid
, flags
,
874 site_name
, &dclist
, &num_dcs
);
876 if (NT_STATUS_IS_OK(status
) && num_dcs
!= 0) {
878 status
= process_dc_dns(mem_ctx
, domain_name
, flags
, &dclist
,
880 if (NT_STATUS_IS_OK(status
)) {
885 status
= discover_dc_netbios(mem_ctx
, domain_name
, flags
, &dclist
,
887 NT_STATUS_NOT_OK_RETURN(status
);
889 return process_dc_netbios(mem_ctx
, domain_name
, flags
, &dclist
,
893 /********************************************************************
896 This will be the only public function here.
897 ********************************************************************/
899 NTSTATUS
dsgetdcname(TALLOC_CTX
*mem_ctx
,
900 const char *domain_name
,
901 struct GUID
*domain_guid
,
902 const char *site_name
,
904 struct DS_DOMAIN_CONTROLLER_INFO
**info
)
906 NTSTATUS status
= NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND
;
907 struct DS_DOMAIN_CONTROLLER_INFO
*myinfo
= NULL
;
909 DEBUG(10,("dsgetdcname: domain_name: %s, "
910 "domain_guid: %s, site_name: %s, flags: 0x%08x\n",
912 domain_guid
? GUID_string(mem_ctx
, domain_guid
) : "(null)",
917 if (!check_allowed_required_flags(flags
)) {
918 DEBUG(0,("invalid flags specified\n"));
919 return NT_STATUS_INVALID_PARAMETER
;
922 if (flags
& DS_FORCE_REDISCOVERY
) {
926 status
= dsgetdcname_cached(mem_ctx
, domain_name
, domain_guid
,
927 flags
, site_name
, &myinfo
);
928 if (NT_STATUS_IS_OK(status
)) {
933 if (flags
& DS_BACKGROUND_ONLY
) {
938 status
= dsgetdcname_rediscover(mem_ctx
, domain_name
,
939 domain_guid
, flags
, site_name
,
942 if (NT_STATUS_IS_OK(status
)) {
943 dsgetdcname_cache_store(mem_ctx
, domain_name
, myinfo
);