From ab1cf8d1cf447e85063b43b65fa05c8b4bfde2a9 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 6 Nov 2002 05:14:15 +0000 Subject: Merge of get_dc_list() api change from HEAD. (This used to be commit 6ba7847ce2756fde94e530fd0bf2a055f3e27373) --- source3/auth/auth_domain.c | 19 +++++++++-- source3/libads/ldap.c | 19 +++++------ source3/libsmb/namequery.c | 59 +++++++++++++++++++++++++++-------- source3/nsswitch/winbindd_cm.c | 71 ++++++++++-------------------------------- source3/rpcclient/samsync.c | 9 +++--- source3/smbd/change_trust_pw.c | 14 +++------ source3/utils/net.c | 25 ++++----------- source3/utils/net_lookup.c | 16 +++++----- 8 files changed, 109 insertions(+), 123 deletions(-) (limited to 'source3') diff --git a/source3/auth/auth_domain.c b/source3/auth/auth_domain.c index 129c486562..e18d809efb 100644 --- a/source3/auth/auth_domain.c +++ b/source3/auth/auth_domain.c @@ -288,8 +288,23 @@ static NTSTATUS find_connect_pdc(struct cli_state **cli, if (time_now - last_change_time < 3600) use_pdc_only = True; - if (!get_dc_list(use_pdc_only, domain, &ip_list, &count)) - return NT_STATUS_NO_LOGON_SERVERS; + if (use_pdc_only) { + struct in_addr pdc_ip; + + if (!get_pdc_ip(domain, &pdc_ip)) + return NT_STATUS_NO_LOGON_SERVERS; + + if ((ip_list = (struct in_addr *) + malloc(sizeof(struct in_addr))) == NULL) + return NT_STATUS_NO_MEMORY; + + ip_list[0] = pdc_ip; + count = 1; + + } else { + if (!get_dc_list(domain, &ip_list, &count)) + return NT_STATUS_NO_LOGON_SERVERS; + } /* * Firstly try and contact a PDC/BDC who has the same diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c index 2359dbd7ed..a59b78bf13 100644 --- a/source3/libads/ldap.c +++ b/source3/libads/ldap.c @@ -180,7 +180,7 @@ static BOOL ads_try_dns(ADS_STRUCT *ads) /* try connecting to a ldap server via netbios */ static BOOL ads_try_netbios(ADS_STRUCT *ads) { - struct in_addr *ip_list; + struct in_addr *ip_list, pdc_ip; int count; int i; char *workgroup = ads->server.workgroup; @@ -192,20 +192,15 @@ static BOOL ads_try_netbios(ADS_STRUCT *ads) DEBUG(6,("ads_try_netbios: looking for workgroup '%s'\n", workgroup)); /* try the PDC first */ - if (get_dc_list(True, workgroup, &ip_list, &count)) { - for (i=0;i 1) { + qsort(ip_list, count, sizeof(struct in_addr), QSORT_CAST ip_compare); } - zero_ip(&ip_list[i]); /* Tried and failed. */ - /* Finally return first DC that we can contact using a node - status */ for (i = 0; i < count; i++) { if (is_zero_ip(ip_list[i])) continue; @@ -215,6 +177,7 @@ static BOOL cm_rpc_find_dc(const char *domain, struct in_addr *dc_ip, fstring sr } } + SAFE_FREE(ip_list); return False; diff --git a/source3/rpcclient/samsync.c b/source3/rpcclient/samsync.c index fb07123b77..cbc3601812 100644 --- a/source3/rpcclient/samsync.c +++ b/source3/rpcclient/samsync.c @@ -494,8 +494,7 @@ static struct cli_state *init_connection(struct cli_state **cli, char *password) { extern pstring global_myname; - struct in_addr *dest_ip; - int count; + struct in_addr pdc_ip; fstring dest_host; /* Initialise myname */ @@ -511,13 +510,13 @@ static struct cli_state *init_connection(struct cli_state **cli, /* Look up name of PDC controller */ - if (!get_dc_list(True, lp_workgroup(), &dest_ip, &count)) { + if (!get_pdc_ip(lp_workgroup(), &pdc_ip)) { DEBUG(0, ("Cannot find domain controller for domain %s\n", lp_workgroup())); return NULL; } - if (!lookup_dc_name(global_myname, lp_workgroup(), dest_ip, + if (!lookup_dc_name(global_myname, lp_workgroup(), pdc_ip, dest_host)) { DEBUG(0, ("Could not lookup up PDC name for domain %s\n", lp_workgroup())); @@ -525,7 +524,7 @@ static struct cli_state *init_connection(struct cli_state **cli, } if (NT_STATUS_IS_OK(cli_full_connection(cli, global_myname, dest_host, - dest_ip, 0, + pdc_ip, 0, "IPC$", "IPC", username, domain, password, 0))) { diff --git a/source3/smbd/change_trust_pw.c b/source3/smbd/change_trust_pw.c index 5da735e875..7cb9084072 100644 --- a/source3/smbd/change_trust_pw.c +++ b/source3/smbd/change_trust_pw.c @@ -105,12 +105,11 @@ account password for domain %s.\n", domain)); * We have been asked to dynamcially determine the IP addresses of the PDC. */ - struct in_addr *ip_list = NULL; - int count = 0; - int i; + struct in_addr pdc_ip; + fstring dc_name; /* Use the PDC *only* for this. */ - if(!get_dc_list(True, domain, &ip_list, &count)) + if(!get_pdc_ip(domain, &pdc_ip)) continue; /* @@ -118,16 +117,11 @@ account password for domain %s.\n", domain)); * address used as a string. */ - for(i = 0; i < count; i++) { - fstring dc_name; - if(!lookup_dc_name(global_myname, domain, &ip_list[i], dc_name)) + if(!lookup_dc_name(global_myname, domain, &pdc_ip, dc_name)) continue; if(NT_STATUS_IS_OK(res = modify_trust_password( domain, dc_name, old_trust_passwd_hash))) break; - } - - SAFE_FREE(ip_list); } else { res = modify_trust_password( domain, remote_machine, diff --git a/source3/utils/net.c b/source3/utils/net.c index d38ca58622..27713d863f 100644 --- a/source3/utils/net.c +++ b/source3/utils/net.c @@ -180,20 +180,15 @@ BOOL net_find_server(unsigned flags, struct in_addr *server_ip, char **server_na return False; } } else if (flags & NET_FLAGS_PDC) { - struct in_addr *ip_list; - int addr_count; - if (get_dc_list(True /* PDC only*/, opt_target_workgroup, &ip_list, &addr_count)) { + struct in_addr pdc_ip; + + if (get_pdc_ip(opt_target_workgroup, &pdc_ip)) { fstring dc_name; - if (addr_count < 1) { - return False; - } - - *server_ip = *ip_list; - if (is_zero_ip(*server_ip)) + if (is_zero_ip(pdc_ip)) return False; - if (!lookup_dc_name(global_myname, opt_target_workgroup, server_ip, dc_name)) + if (!lookup_dc_name(global_myname, opt_target_workgroup, &pdc_ip, dc_name)) return False; *server_name = strdup(dc_name); @@ -236,17 +231,9 @@ BOOL net_find_server(unsigned flags, struct in_addr *server_ip, char **server_na BOOL net_find_dc(struct in_addr *server_ip, fstring server_name, const char *domain_name) { - struct in_addr *ip_list; - int addr_count; - - if (get_dc_list(True /* PDC only*/, domain_name, &ip_list, &addr_count)) { + if (get_pdc_ip(domain_name, server_ip)) { fstring dc_name; - if (addr_count < 1) { - return False; - } - *server_ip = *ip_list; - if (is_zero_ip(*server_ip)) return False; diff --git a/source3/utils/net_lookup.c b/source3/utils/net_lookup.c index f76b186251..32921de620 100644 --- a/source3/utils/net_lookup.c +++ b/source3/utils/net_lookup.c @@ -79,8 +79,8 @@ static int net_lookup_ldap(int argc, const char **argv) #ifdef HAVE_LDAP char *srvlist; const char *domain; - int rc, count; - struct in_addr *addr; + int rc; + struct in_addr addr; struct hostent *hostent; if (argc > 0) @@ -96,10 +96,10 @@ static int net_lookup_ldap(int argc, const char **argv) } DEBUG(9, ("Looking up DC for domain %s\n", domain)); - if (!get_dc_list(True, domain, &addr, &count)) + if (!get_pdc_ip(domain, &addr)) return -1; - hostent = gethostbyaddr((char *) &addr->s_addr, sizeof(addr->s_addr), + hostent = gethostbyaddr((char *) &addr.s_addr, sizeof(addr.s_addr), AF_INET); if (!hostent) return -1; @@ -124,7 +124,7 @@ static int net_lookup_ldap(int argc, const char **argv) static int net_lookup_dc(int argc, const char **argv) { - struct in_addr *ip_list; + struct in_addr *ip_list, addr; char *pdc_str = NULL; const char *domain=opt_target_workgroup; int count, i; @@ -133,13 +133,13 @@ static int net_lookup_dc(int argc, const char **argv) domain=argv[0]; /* first get PDC */ - if (!get_dc_list(True, domain, &ip_list, &count)) + if (!get_pdc_ip(domain, &addr)) return -1; - asprintf(&pdc_str, "%s", inet_ntoa(*ip_list)); + asprintf(&pdc_str, "%s", inet_ntoa(addr)); d_printf("%s\n", pdc_str); - if (!get_dc_list(False, domain, &ip_list, &count)) { + if (!get_dc_list(domain, &ip_list, &count)) { SAFE_FREE(pdc_str); return 0; } -- cgit