[BACK]Return to net.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / distrib / utils / sysinst

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/distrib/utils/sysinst/Attic/net.c between version 1.8 and 1.8.2.13

version 1.8, 1997/10/20 06:13:36 version 1.8.2.13, 1997/12/05 17:21:15
Line 43 
Line 43 
 #include <string.h>  #include <string.h>
 #include <curses.h>  #include <curses.h>
 #include <unistd.h>  #include <unistd.h>
   #include <sys/param.h>
 #include "defs.h"  #include "defs.h"
 #include "md.h"  #include "md.h"
 #include "msg_defs.h"  #include "msg_defs.h"
 #include "menu_defs.h"  #include "menu_defs.h"
 #include "txtwalk.h"  #include "txtwalk.h"
   
 static network_up = 0;  static int network_up = 0;
   
   /* Get the list of network interfaces. */
   
 static void get_ifconfig_info (void)  static void get_ifconfig_info (void)
 {  {
Line 77  static void get_ifconfig_info (void)
Line 80  static void get_ifconfig_info (void)
                 *t = 0;                  *t = 0;
 }  }
   
   /* Fill in defaults network values for the selected interface */
   
   static void get_ifinterface_info(void)
   {
           char *textbuf;
           int textsize;
           char *t;
           char hostname[MAXHOSTNAMELEN];
   
           /* First look to see if the selected interface is already configured. */
           textsize = collect(T_OUTPUT, &textbuf, "/sbin/ifconfig %s 2>/dev/null",
                              net_dev);
           if (textsize >= 0) {
                   (void)strtok(textbuf, " \t\n"); /* ignore interface name */
                   while ((t = strtok(NULL, " \t\n")) != NULL) {
                           if (strcmp(t, "inet") == 0) {
                                   t = strtok(NULL, " \t\n");
                                   if (strcmp(t, "0.0.0.0") != 0)
                                           strcpy(net_ip, t);
                           }
                           else if (strcmp(t, "netmask") == 0) {
                                   t = strtok(NULL, " \t\n");
                                   if (strcmp(t, "0x0") != 0)
                                           strcpy(net_mask, t);
                           }
                   }
           }
   
           /* Check host (and domain?) name */
           if (gethostname(hostname, sizeof(hostname)) == 0)
                   strncpy(net_host, hostname, sizeof(net_host));
   }
   
   /* Get the information to configure the network, configure it and
      make sure both the gateway and the name server are up. */
   
 static int config_network (void)  int config_network (void)
 {       char *tp;  {       char *tp;
         char defname[255];          char defname[255];
         int  octet0;          int  octet0;
         int  pass;          int  pass;
   
         FILE *f;          FILE *f;
           time_t now;
   
         if (network_up)          if (network_up)
                 return 1;                  return 1;
   
           network_up = 1;
         net_devices[0] = '\0';          net_devices[0] = '\0';
         get_ifconfig_info ();          get_ifconfig_info ();
           if (strlen(net_devices) == 0) {
                   /* No network interfaces found! */
                   msg_display (MSG_nonet);
                   process_menu (MENU_ok);
                   return -1;
           }
         strncpy (defname, net_devices, 255);          strncpy (defname, net_devices, 255);
         tp = defname;          tp = defname;
         strsep(&tp, " ");          strsep(&tp, " ");
Line 111  static int config_network (void)
Line 157  static int config_network (void)
   
         /* Remove that space we added. */          /* Remove that space we added. */
         net_dev[strlen(net_dev)-1] = 0;          net_dev[strlen(net_dev)-1] = 0;
   
           /* Preload any defaults we can find */
           get_ifinterface_info ();
           pass = strlen(net_mask) == 0 ? 0 : 1;
   
         /* Get other net information */          /* Get other net information */
         msg_display (MSG_netinfo);          msg_display (MSG_netinfo);
         pass = 0;  
         do {          do {
                 msg_prompt_add (MSG_net_domain, net_domain, net_domain,                  msg_prompt_add (MSG_net_domain, net_domain, net_domain,
                                 STRSIZE);                                  STRSIZE);
Line 135  static int config_network (void)
Line 184  static int config_network (void)
                 msg_prompt_add (MSG_net_namesrv, net_namesvr, net_namesvr,                  msg_prompt_add (MSG_net_namesrv, net_namesvr, net_namesvr,
                                 STRSIZE);                                  STRSIZE);
   
                 msg_display (MSG_netok, net_domain, net_host, net_ip,                  msg_display (MSG_netok, net_domain, net_host, net_ip, net_mask,
                              net_mask, net_namesvr, net_defroute);                               *net_namesvr == '\0' ? "<none>" : net_namesvr,
                                *net_defroute == '\0' ? "<none>" : net_defroute);
                 process_menu (MENU_yesno);                  process_menu (MENU_yesno);
                 if (!yesno)                  if (!yesno)
                         msg_display (MSG_netagain);                          msg_display (MSG_netagain);
                 pass++;                  pass++;
         } while (!yesno);          } while (!yesno);
   
         /* Create /etc/resolv.conf */          /* Create /etc/resolv.conf if a nameserver was given */
           if (strcmp(net_namesvr, "") != 0) {
 #ifdef DEBUG  #ifdef DEBUG
         f = fopen ("/tmp/resolv.conf", "w");                  f = fopen ("/tmp/resolv.conf", "w");
 #else  #else
         f = fopen ("/etc/resolv.conf", "w");                  f = fopen ("/etc/resolv.conf", "w");
 #endif  #endif
         if (f == NULL) {                  if (f == NULL) {
                 endwin();                          endwin();
                 (void)fprintf(stderr, "%s", msg_string(MSG_resolv));                          (void)fprintf(stderr, "%s", msg_string(MSG_resolv));
                 exit(1);                          exit(1);
                   }
                   time(&now);
                   /* 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);
         }          }
         (void)fprintf (f, "nameserver %s\nlookup file bind\nsearch %s",  
                        net_namesvr, net_domain);  
         fclose (f);  
   
         run_prog ("/sbin/ifconfig lo0 127.0.0.1");          run_prog ("/sbin/ifconfig lo0 127.0.0.1");
         run_prog ("/sbin/ifconfig %s inet %s netmask %s", net_dev, net_ip,          run_prog ("/sbin/ifconfig %s inet %s netmask %s", net_dev, net_ip,
                   net_mask);                    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)          /* Set a default route if one was given */
                 || run_prog ("/sbin/ping -c 2 %s > /dev/null", net_namesvr);          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)
                   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;          return network_up;
 }  }
Line 174  static int config_network (void)
Line 240  static int config_network (void)
 int  int
 get_via_ftp (void)  get_via_ftp (void)
 {  {
         char **list;          distinfo *list;
         char realdir[STRSIZE];  
         char filename[SSTRSIZE];          char filename[SSTRSIZE];
         int  ret;          int  ret;
   
         while (config_network ()) {          while (!config_network ()) {
                 msg_display (MSG_netnotup);                  msg_display (MSG_netnotup);
                 process_menu (MENU_yesno);                  process_menu (MENU_yesno);
                 if (!yesno)                  if (!yesno)
                         return 0;                          return 0;
         }          }
   
           cd_dist_dir ("ftp");
   
           /* Fill in final values for ftp_dir. */
           strncat (ftp_dir, rel, STRSIZE-strlen(ftp_dir));
           strcat  (ftp_dir, "/");
           strncat (ftp_dir, machine, STRSIZE-strlen(ftp_dir));
         strncat (ftp_dir, ftp_prefix, STRSIZE-strlen(ftp_dir));          strncat (ftp_dir, ftp_prefix, STRSIZE-strlen(ftp_dir));
         process_menu (MENU_ftpsource);          process_menu (MENU_ftpsource);
         msg_prompt (MSG_distdir, dist_dir, dist_dir, STRSIZE, "ftp");  
         if (*dist_dir == '/')  
                 snprintf (realdir, STRSIZE, "/mnt%s", dist_dir);  
         else  
                 snprintf (realdir, STRSIZE, "/mnt/%s", dist_dir);  
         strcpy (dist_dir, realdir);  
         run_prog ("/bin/mkdir %s", realdir);  
         clean_dist_dir = 1;  
 #ifndef DEBUG  
         if (chdir(realdir)) {  
                 endwin();  
                 (void)fprintf(stderr, msg_string(MSG_realdir), realdir);  
                 exit(1);  
         }  
 #else  
         printf ("chdir (%s)\n", realdir);  
 #endif  
   
         list = dist_list;          list = dist_list;
         endwin();          endwin();
         while (*list) {          while (list->name) {
                 snprintf (filename, SSTRSIZE, *list, rels, dist_postfix);                  if (!list->getit) {
                           list++;
                           continue;
                   }
                   snprintf (filename, SSTRSIZE, "%s%s", list->name, dist_postfix);
                 if (strcmp ("ftp", ftp_user) == 0)                  if (strcmp ("ftp", ftp_user) == 0)
                         ret = run_prog("/usr/bin/ftp -a ftp://%s/%s/%s",                          ret = run_prog("/usr/bin/ftp -a 'ftp://%s/%s/%s'",
                                        ftp_host, ftp_dir,                                         ftp_host, ftp_dir,
                                        filename);                                         filename);
                 else                  else
                         ret = run_prog("/usr/bin/ftp ftp://%s:%s@%s/%s/%s",                          ret = run_prog("/usr/bin/ftp 'ftp://%s:%s@%s/%s/%s'",
                                        ftp_user, ftp_pass, ftp_host, ftp_dir,                                         ftp_user, ftp_pass, ftp_host, ftp_dir,
                                        filename);                                         filename);
                 if (ret) {                  if (ret) {
                         /* Error getting the file.  Bad host name ... ? */                          /* Error getting the file.  Bad host name ... ? */
                           msg_display (MSG_ftperror_cont);
                           getchar();
                         puts (CL);                          puts (CL);
                         wrefresh (stdscr);                          wrefresh (stdscr);
                         msg_display (MSG_ftperror);                          msg_display (MSG_ftperror);
Line 231  get_via_ftp (void)
Line 291  get_via_ftp (void)
                         endwin();                          endwin();
                 } else                  } else
                         list++;                          list++;
   
         }          }
         puts (CL); /* Just to make sure. */          puts (CL); /* Just to make sure. */
         wrefresh (stdscr);          wrefresh (stdscr);
 #ifndef DEBUG  #ifndef DEBUG
         chdir("/");          chdir("/");     /* back to current real root */
 #endif  #endif
         return 1;          return 1;
 }  }
Line 243  get_via_ftp (void)
Line 304  get_via_ftp (void)
 int  int
 get_via_nfs(void)  get_via_nfs(void)
 {  {
         while (config_network ()) {          while (!config_network ()) {
                 msg_display (MSG_netnotup);                  msg_display (MSG_netnotup);
                 process_menu (MENU_yesno);                  process_menu (MENU_yesno);
                 if (!yesno)                  if (!yesno)
Line 252  get_via_nfs(void)
Line 313  get_via_nfs(void)
   
         /* Get server and filepath */          /* Get server and filepath */
         process_menu (MENU_nfssource);          process_menu (MENU_nfssource);
   again:
   
           run_prog("/sbin/umount /mnt2  2> /dev/null");
   
         /* Mount it */          /* Mount it */
         while(!run_prog("/sbin/mount -t nfs %s:%s /mnt2", nfs_host, nfs_dir)) {          if (run_prog("/sbin/mount -t nfs %s:%s /mnt2", nfs_host, nfs_dir)) {
                   msg_display (MSG_nfsbadmount, nfs_host, nfs_dir);
                 process_menu (MENU_nfsbadmount);                  process_menu (MENU_nfsbadmount);
                 if (!yesno)                  if (!yesno)
                         return 0;                          return 0;
                 /* verify distribution files are there. XXX */                  if (!ignorerror)
                           goto again;
           }
   
           /* Verify distribution files exist.  */
           if (distribution_sets_exist_p("/mnt2") == 0) {
                   msg_display(MSG_badsetdir, "/mnt2");
                   process_menu (MENU_nfsbadmount);
                   if (!yesno)
                           return (0);
                   if (!ignorerror)
                           goto again;
         }          }
   
         /* return location, don't clean... */          /* return location, don't clean... */
         strcpy (dist_dir, "/mnt2");          strcpy (ext_dir, "/mnt2");
         clean_dist_dir = 0;          clean_dist_dir = 0;
         mnt2_mounted = 1;          mnt2_mounted = 1;
         return 1;          return 1;
 }  }
   
   /*
    * Write the network config info the user entered via menus into the
    * config files in the target disk.  Be careful not to lose any
    * information we don't immediately add back, in case the install
    * target is the currently-active root.
    */
 void  void
 mnt_net_config(void)  mnt_net_config(void)
 {  {
         char ans [5] = "y";          char ans [5] = "y";
           char ifconfig_fn [STRSIZE];
           FILE *f;
   
         if (network_up) {          if (network_up) {
                 msg_prompt (MSG_mntnetconfig, ans, ans, 5);                  msg_prompt (MSG_mntnetconfig, ans, ans, 5);
                 if (*ans == 'y') {                  if (*ans == 'y') {
                         run_prog ("/bin/cp /etc/resolv.conf /mnt/etc");  
                         run_prog ("echo %s > /mnt/etc/myname", net_host);                          /* If not running in target, copy resolv.conf there. */
                         run_prog ("echo %s %s >> /mnt/etc/hosts", net_ip,                          dup_file_into_target("/etc/resolv.conf");
                                   net_host);                          /*
                         run_prog ("echo %s > /mnt/etc/defaultdomain",                           * Add IPaddr/hostname to  /etc/hosts.
                                   net_domain);                           * Be careful not to clobber any existing contents.
                         run_prog ("echo %s netmask %s > /mnt/etc/ifconfig.%s",                           * Relies on ordered seach of /etc/hosts. XXX YP?
                                   net_ip, net_mask, net_dev);                           */
                         run_prog ("echo %s > /mnt/etc/mygate", net_defroute);                          f = target_fopen("/etc/hosts", "a");
                           if (f != 0) {
                                   fprintf(f, msg_string(MSG_etc_hosts),
                                           net_ip, net_host, net_domain,
                                           net_host);
                                   fclose(f);
                           }
   
                           /* Write IPaddr and netmask to /etc/ifconfig.if[0-9] */
                           snprintf (ifconfig_fn, STRSIZE,
                                     "/etc/ifconfig.%s", net_dev);
                           f = target_fopen(ifconfig_fn, "w");
                           if (f != 0) {
                                   fprintf(f, "%s netmask %s\n",
                                           net_ip, net_mask);
                                   fclose(f);
                           }
   
                           f = target_fopen("/etc/mygate", "w");
                           if (f != 0) {
                                   fprintf(f, "%s\n", net_defroute);
                                   fclose(f);
                           }
                 }                  }
         }          }
 }  }

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.8.2.13

CVSweb <webmaster@jp.NetBSD.org>