2 Unix SMB/CIFS implementation.
4 Winbind daemon connection manager
6 Copyright (C) Tim Potter 2001
7 Copyright (C) Andrew Bartlett 2002
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.
27 /****************************************************************************
28 Utility function to return the name of a DC. The name is guaranteed to be
29 valid since we have already done a name_status_find on it
30 ***************************************************************************/
32 BOOL rpc_dc_name(const char *domain, fstring srv_name, struct in_addr *ip_out)
34 struct ip_service *ip_list = NULL;
35 struct in_addr dc_ip, exclude_ip;
42 use_pdc_only = must_use_pdc(domain);
44 /* Lookup domain controller name */
46 if ( use_pdc_only && get_pdc_ip(domain, &dc_ip) )
48 DEBUG(10,("rpc_dc_name: Atempting to lookup PDC to avoid sam sync delays\n"));
50 /* check the connection cache and perform the node status
51 lookup only if the IP is not found to be bad */
53 if (name_status_find(domain, 0x1b, 0x20, dc_ip, srv_name) ) {
54 result = check_negative_conn_cache( domain, srv_name );
55 if ( NT_STATUS_IS_OK(result) )
58 /* Didn't get name, remember not to talk to this DC. */
62 /* get a list of all domain controllers */
64 if ( !get_sorted_dc_list(domain, &ip_list, &count, False) ) {
65 DEBUG(3, ("Could not look up dc's for domain %s\n", domain));
69 /* Remove the entry we've already failed with (should be the PDC). */
72 for (i = 0; i < count; i++) {
73 if (ip_equal( exclude_ip, ip_list[i].ip))
74 zero_ip(&ip_list[i].ip);
78 for (i = 0; i < count; i++) {
79 if (is_zero_ip(ip_list[i].ip))
82 if (name_status_find(domain, 0x1c, 0x20, ip_list[i].ip, srv_name)) {
83 result = check_negative_conn_cache( domain, srv_name );
84 if ( NT_STATUS_IS_OK(result) ) {
85 dc_ip = ip_list[i].ip;
94 /* No-one to talk to )-: */
95 return False; /* Boo-hoo */
98 /* We have the netbios name and IP address of a domain controller.
99 Ideally we should sent a SAMLOGON request to determine whether
100 the DC is alive and kicking. If we can catch a dead DC before
101 performing a cli_connect() we can avoid a 30-second timeout. */
103 DEBUG(3, ("rpc_dc_name: Returning DC %s (%s) for domain %s\n", srv_name,
104 inet_ntoa(dc_ip), domain));