From 22c6b5be5ac67219694ad90b20aaf2f56dd4ed01 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 2 Apr 2003 14:11:51 +0000 Subject: Fix searching master ip by bcast when old master has gone away (based on patch by Stephan Kulow ) (This used to be commit 5c0e4b4dc630bd304f53c37f2340f954190b7aef) --- source3/utils/smbtree.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'source3') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 52de5ab467..d245c324dd 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -90,10 +90,12 @@ static struct cli_state *get_ipc_connect(char *server, struct in_addr *server_ip /* Return the IP address and workgroup of a master browser on the network. */ -static BOOL find_master_ip_bcast(pstring workgroup, struct in_addr *server_ip) +static struct cli_state *get_ipc_connect_master_ip_bcast(pstring workgroup, struct user_auth_info *user_info) { struct in_addr *ip_list; + struct cli_state *cli; int i, count; + struct in_addr server_ip; /* Go looking for workgroups by broadcasting on the local network */ @@ -107,7 +109,7 @@ static BOOL find_master_ip_bcast(pstring workgroup, struct in_addr *server_ip) if (!name_status_find("*", 0, 0x1d, ip_list[i], name)) continue; - if (!find_master_ip(name, server_ip)) + if (!find_master_ip(name, &server_ip)) continue; pstrcpy(workgroup, name); @@ -115,10 +117,13 @@ static BOOL find_master_ip_bcast(pstring workgroup, struct in_addr *server_ip) DEBUG(4, ("found master browser %s, %s\n", name, inet_ntoa(ip_list[i]))); - return True; + if (!(cli = get_ipc_connect(inet_ntoa(server_ip), &server_ip, user_info))) + continue; + + return cli; } - return False; + return NULL; } /**************************************************************************** @@ -136,19 +141,21 @@ static BOOL get_workgroups(struct user_auth_info *user_info) pstrcpy(master_workgroup, lp_workgroup()); - if (use_bcast || !find_master_ip(lp_workgroup(), &server_ip)) { - DEBUG(4, ("Unable to find master browser for workgroup %s\n", + if (!use_bcast && !find_master_ip(lp_workgroup(), &server_ip)) { + DEBUG(4, ("Unable to find master browser for workgroup %s, falling back to broadcast\n", master_workgroup)); - if (!find_master_ip_bcast(master_workgroup, &server_ip)) { + use_bcast = True; + } else if(!use_bcast) { + if (!(cli = get_ipc_connect(inet_ntoa(server_ip), &server_ip, user_info))) + return False; + } + + if (!(cli = get_ipc_connect_master_ip_bcast(master_workgroup, user_info))) { DEBUG(4, ("Unable to find master browser by " "broadcast\n")); return False; - } } - if (!(cli = get_ipc_connect(inet_ntoa(server_ip), &server_ip, user_info))) - return False; - if (!cli_NetServerEnum(cli, master_workgroup, SV_TYPE_DOMAIN_ENUM, add_name, &workgroups)) return False; -- cgit