Subject: bin/4539: netconfig with sysinst needs some changes to handle empty input
To: None <gnats-bugs@gnats.netbsd.org>
From: None <frueauf@ira.uka.de>
List: netbsd-bugs
Date: 11/18/1997 21:06:16
>Number:         4539
>Category:       bin
>Synopsis:       netconfig with sysinst needs some changes to handle empty input
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Tue Nov 18 12:35:01 1997
>Last-Modified:
>Originator:     Thorsten Frueauf
>Organization:
private
	
>Release:        <NetBSD-current source date> NetBSD 1.3_ALPHA 17.11.1997
>Environment:
	
System: NetBSD cyberlap 1.3_ALPHA NetBSD 1.3_ALPHA (CYBERLAP) #4: Tue Nov 18 08:16:35 MET 1997 frueauf@cyberlap:/usr/src/sys/arch/i386/compile/CYBERLAP i386


>Description:
	
At the moment, sysinst does not check if the user made empty input (e.g. just
hit return). So if you try to configure a local network, which does
not necessarily need a nameserver or default gateway, by just hiting return
at those questions, sysinst calls `ping -c 2` with an empty argument, which
makes ping putting out its usage.

>How-To-Repeat:
	
Try to set up network with sysinst with not having a nameserver nor
default gateway (cause you have a simple local network with just some
hosts at the same ethernet segment).

>Fix:
	
I know that I am a lousy programmer, so the following changes are surely not
best coding style :-) Nonetheless it adresses above problems, at least it
works for my testing envirement.

Note that sysinst still assumes that your input is correct and reasonable.
Especialy it is required that one gives a network adress - but sysinst
does not complain even if you just hit return on every question. So from
a userfriendly point of view it still needs rework.

Apply the following patch to /src/distrib/utils/sysinst/net.c:

*** net.c-orig	Fri Nov 14 18:00:31 1997
--- net.c	Tue Nov 18 17:37:04 1997
***************
*** 163,181 ****
  	/* NB: ctime() returns a string ending in  '\n' */
  	(void)fprintf (f, ";\n; BIND data file\n; %s %s;\n", 
  		       "Created by NetBSD sysinst on", ctime(&now)); 
! 	(void)fprintf (f, "nameserver %s\nlookup file bind\nsearch %s\n",
! 		       net_namesvr, net_domain);
  	fclose (f);
  
  	run_prog ("/sbin/ifconfig lo0 127.0.0.1");
  	run_prog ("/sbin/ifconfig %s inet %s netmask %s", net_dev, net_ip,
  		  net_mask);
! 	run_prog ("/sbin/route -f > /dev/null 2> /dev/null");
! 	run_prog ("/sbin/route add default %s > /dev/null 2> /dev/null",
  		  net_defroute);
  
! 	network_up = !run_prog ("/sbin/ping -c 2 %s > /dev/null", net_defroute)
! 		&& !run_prog ("/sbin/ping -c 2 %s > /dev/null", net_namesvr);
  
  	return network_up;
  }
--- 163,188 ----
  	/* NB: ctime() returns a string ending in  '\n' */
  	(void)fprintf (f, ";\n; BIND data file\n; %s %s;\n", 
  		       "Created by NetBSD sysinst on", ctime(&now)); 
! 	if (strcmp(net_namesvr,"") != 0)
! 	  (void)fprintf (f, "nameserver %s\n", net_namesvr);
! 	(void)fprintf (f, "lookup file bind\n");
! 	if (strcmp(net_domain,"") != 0)
! 	  (void)fprintf (f, "search %s\n", net_domain);
  	fclose (f);
  
  	run_prog ("/sbin/ifconfig lo0 127.0.0.1");
  	run_prog ("/sbin/ifconfig %s inet %s netmask %s", net_dev, net_ip,
  		  net_mask);
! 	if (strcmp(net_defroute,"") != 0) {
! 	  run_prog ("/sbin/route -f > /dev/null 2> /dev/null");
! 	  run_prog ("/sbin/route add default %s > /dev/null 2> /dev/null",
  		  net_defroute);
+ 	}
  
! 	if (strcmp(net_namesvr, "") != 0)
! 	  network_up = run_prog ("/sbin/ping -c 2 %s > /dev/null", net_namesvr);
! 	if (strcmp(net_defroute, "") != 0)
! 	  network_up = !network_up && !run_prog ("/sbin/ping -c 2 %s > /dev/null", net_defroute);
  
  	return network_up;
  }
>Audit-Trail:
>Unformatted:
netconfig with sysinst needs some changes to handle empty input