[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.127 and 1.127.4.2

version 1.127, 2011/04/04 08:30:13 version 1.127.4.2, 2012/05/23 10:07:20
Line 241  get_ifconfig_info(void)
Line 241  get_ifconfig_info(void)
   
         textsize = collect(T_OUTPUT, &textbuf, "/sbin/ifconfig -a 2>/dev/null");          textsize = collect(T_OUTPUT, &textbuf, "/sbin/ifconfig -a 2>/dev/null");
         if (textsize < 0) {          if (textsize < 0) {
                 if (logging)                  if (logfp)
                         (void)fprintf(logfp,                          (void)fprintf(logfp,
                             "Aborting: Could not run ifconfig.\n");                              "Aborting: Could not run ifconfig.\n");
                 (void)fprintf(stderr, "Could not run ifconfig.");                  (void)fprintf(stderr, "Could not run ifconfig.");
Line 820  done:
Line 820  done:
                 ) {                  ) {
                 f = fopen("/etc/resolv.conf", "w");                  f = fopen("/etc/resolv.conf", "w");
                 if (f == NULL) {                  if (f == NULL) {
                         if (logging)                          if (logfp)
                                 (void)fprintf(logfp,                                  (void)fprintf(logfp,
                                     "%s", msg_string(MSG_resolv));                                      "%s", msg_string(MSG_resolv));
                         (void)fprintf(stderr, "%s", msg_string(MSG_resolv));                          (void)fprintf(stderr, "%s", msg_string(MSG_resolv));
Line 939  done:
Line 939  done:
         return network_up;          return network_up;
 }  }
   
 static int  void
 ftp_fetch(const char *set_name)  make_url(char *urlbuffer, struct ftpinfo *f, const char *dir)
 {  {
         const char *ftp_opt;  
         char ftp_user_encoded[STRSIZE];          char ftp_user_encoded[STRSIZE];
         char ftp_dir_encoded[STRSIZE];          char ftp_dir_encoded[STRSIZE];
         char *cp, *set_dir2;          char *cp;
         int rval;          const char *dir2;
   
         /*          /*
          * Invoke ftp to fetch the file.           * f->pass is quite likely to contain unsafe characters
          *  
          * ftp.pass is quite likely to contain unsafe characters  
          * that need to be encoded in the URL (for example,           * that need to be encoded in the URL (for example,
          * "@", ":" and "/" need quoting).  Let's be           * "@", ":" and "/" need quoting).  Let's be
          * paranoid and also encode ftp.user and ftp.dir.  (For           * paranoid and also encode f->user and f->dir.  (For
          * example, ftp.dir could easily contain '~', which is           * example, f->dir could easily contain '~', which is
          * unsafe by a strict reading of RFC 1738).           * unsafe by a strict reading of RFC 1738).
          */           */
         if (strcmp("ftp", ftp.user) == 0 && ftp.pass[0] == 0) {          if (strcmp("ftp", f->user) == 0 && f->pass[0] == 0) {
                 /* do anon ftp */  
                 ftp_opt = "-a ";  
                 ftp_user_encoded[0] = 0;                  ftp_user_encoded[0] = 0;
         } else {          } else {
                 ftp_opt = "";                  cp = url_encode(ftp_user_encoded, f->user,
                 cp = url_encode(ftp_user_encoded, ftp.user,  
                         ftp_user_encoded + sizeof ftp_user_encoded - 1,                          ftp_user_encoded + sizeof ftp_user_encoded - 1,
                         RFC1738_SAFE_LESS_SHELL, 0);                          RFC1738_SAFE_LESS_SHELL, 0);
                 *cp++ = ':';                  *cp++ = ':';
                 cp = url_encode(cp, ftp.pass,                  cp = url_encode(cp, f->pass,
                         ftp_user_encoded + sizeof ftp_user_encoded - 1,                          ftp_user_encoded + sizeof ftp_user_encoded - 1,
                         NULL, 0);                          NULL, 0);
                 *cp++ = '@';                  *cp++ = '@';
                 *cp = 0;                  *cp = 0;
         }          }
           cp = url_encode(ftp_dir_encoded, f->dir,
         cp = url_encode(ftp_dir_encoded, ftp.dir,  
                         ftp_dir_encoded + sizeof ftp_dir_encoded - 1,                          ftp_dir_encoded + sizeof ftp_dir_encoded - 1,
                         RFC1738_SAFE_LESS_SHELL_PLUS_SLASH, 1);                          RFC1738_SAFE_LESS_SHELL_PLUS_SLASH, 1);
         if (cp != ftp_dir_encoded && cp[-1] != '/')          if (cp != ftp_dir_encoded && cp[-1] != '/')
                 *cp++ = '/';                  *cp++ = '/';
   
         set_dir2 = set_dir;          dir2 = dir;
         while (*set_dir2 == '/')          while (*dir2 == '/')
                 ++set_dir2;                  ++dir2;
   
         url_encode(cp, set_dir2,          url_encode(cp, dir2,
                         ftp_dir_encoded + sizeof ftp_dir_encoded,                          ftp_dir_encoded + sizeof ftp_dir_encoded,
                         RFC1738_SAFE_LESS_SHELL_PLUS_SLASH, 0);                          RFC1738_SAFE_LESS_SHELL_PLUS_SLASH, 0);
   
           snprintf(urlbuffer, STRSIZE, "%s://%s%s/%s", f->xfer_type,
               ftp_user_encoded, f->host, ftp_dir_encoded);
   }
   
   
   /* ftp_fetch() and pkgsrc_fetch() are essentially the same, with a different
    * ftpinfo var. */
   static int do_ftp_fetch(const char *, struct ftpinfo *);
   
   static int
   ftp_fetch(const char *set_name)
   {
           return do_ftp_fetch(set_name, &ftp);
   }
   
   static int
   pkgsrc_fetch(const char *set_name)
   {
           return do_ftp_fetch(set_name, &pkgsrc);
   }
   
   static int
   do_ftp_fetch(const char *set_name, struct ftpinfo *f)
   {
           const char *ftp_opt;
           char url[STRSIZE];
           int rval;
   
           /*
            * Invoke ftp to fetch the file.
            */
           if (strcmp("ftp", f->user) == 0 && f->pass[0] == 0) {
                   /* do anon ftp */
                   ftp_opt = "-a ";
           } else {
                   ftp_opt = "";
           }
   
           make_url(url, f, set_dir_for_set(set_name));
         rval = run_program(RUN_DISPLAY | RUN_PROGRESS | RUN_XFER_DIR,          rval = run_program(RUN_DISPLAY | RUN_PROGRESS | RUN_XFER_DIR,
                     "/usr/bin/ftp %s%s://%s%s/%s/%s%s",                      "/usr/bin/ftp %s%s/%s%s",
                     ftp_opt, ftp.xfer_type, ftp_user_encoded, ftp.host,                      ftp_opt, url, set_name, dist_postfix);
                     ftp_dir_encoded, set_name, dist_postfix);  
   
         return rval ? SET_RETRY : SET_OK;          return rval ? SET_RETRY : SET_OK;
 }  }
Line 1020  do_config_network(void)
Line 1051  do_config_network(void)
 }  }
   
 int  int
   get_pkgsrc(void)
   {
           if (!network_up)
                   if (do_config_network() != 0)
                           return SET_RETRY;
   
           yesno = 1;
           process_menu(MENU_pkgsrc, NULL);
   
           if (yesno == 0)
                   return SET_SKIP;
           fetch_fn = pkgsrc_fetch;
           snprintf(ext_dir_pkgsrc, sizeof ext_dir_pkgsrc, "%s/%s",
               target_prefix(), xfer_dir + (*xfer_dir == '/'));
   
           return SET_OK;
   }
   
   int
 get_via_ftp(const char *xfer_type)  get_via_ftp(const char *xfer_type)
 {  {
   
Line 1031  get_via_ftp(const char *xfer_type)
Line 1081  get_via_ftp(const char *xfer_type)
         /* We'll fetch each file just before installing it */          /* We'll fetch each file just before installing it */
         fetch_fn = ftp_fetch;          fetch_fn = ftp_fetch;
         ftp.xfer_type = xfer_type;          ftp.xfer_type = xfer_type;
         snprintf(ext_dir, sizeof ext_dir, "%s/%s", target_prefix(),          snprintf(ext_dir_bin, sizeof ext_dir_bin, "%s/%s", target_prefix(),
               xfer_dir + (*xfer_dir == '/'));
           snprintf(ext_dir_src, sizeof ext_dir_src, "%s/%s", target_prefix(),
             xfer_dir + (*xfer_dir == '/'));              xfer_dir + (*xfer_dir == '/'));
   
         return SET_OK;          return SET_OK;
Line 1046  get_via_nfs(void)
Line 1098  get_via_nfs(void)
                 return SET_RETRY;                  return SET_RETRY;
   
         /* If root is on NFS and we have sets, skip this step. */          /* If root is on NFS and we have sets, skip this step. */
         if (statvfs(set_dir, &sb) == 0 &&          if (statvfs(set_dir_bin, &sb) == 0 &&
             strcmp(sb.f_fstypename, "nfs") == 0) {              strcmp(sb.f_fstypename, "nfs") == 0) {
                 strlcpy(ext_dir, set_dir, sizeof ext_dir);                  strlcpy(ext_dir_bin, set_dir_bin, sizeof ext_dir_bin);
                   strlcpy(ext_dir_src, set_dir_src, sizeof ext_dir_src);
                 return SET_OK;                  return SET_OK;
         }          }
   
Line 1062  get_via_nfs(void)
Line 1115  get_via_nfs(void)
   
         mnt2_mounted = 1;          mnt2_mounted = 1;
   
         snprintf(ext_dir, sizeof ext_dir, "/mnt2/%s", set_dir);          snprintf(ext_dir_bin, sizeof ext_dir_bin, "/mnt2/%s", set_dir_bin);
           snprintf(ext_dir_src, sizeof ext_dir_src, "/mnt2/%s", set_dir_src);
   
         /* return location, don't clean... */          /* return location, don't clean... */
         return SET_OK;          return SET_OK;
Line 1097  void
Line 1151  void
 mnt_net_config(void)  mnt_net_config(void)
 {  {
         char ifconfig_fn[STRSIZE];          char ifconfig_fn[STRSIZE];
           char ifconfig_str[STRSIZE];
         FILE *ifconf = NULL;          FILE *ifconf = NULL;
   
         if (!network_up)          if (!network_up)
Line 1106  mnt_net_config(void)
Line 1161  mnt_net_config(void)
                 return;                  return;
   
         /* Write hostname to /etc/rc.conf */          /* Write hostname to /etc/rc.conf */
         if ((net_dhcpconf & DHCPCONF_HOST) == 0)          if ((net_dhcpconf & DHCPCONF_HOST) == 0)
                 add_rc_conf("hostname=%s\n", recombine_host_domain());                  if (del_rc_conf("hostname") == 0)
                           add_rc_conf("hostname=%s\n", recombine_host_domain());
   
         /* If not running in target, copy resolv.conf there. */          /* Copy resolv.conf to target.  If DHCP was used to create it,
         if ((net_dhcpconf & DHCPCONF_NAMESVR) == 0) {           * it will be replaced on next boot anyway. */
 #ifndef INET6  #ifndef INET6
                 if (net_namesvr[0] != '\0')          if (net_namesvr[0] != '\0')
                         dup_file_into_target("/etc/resolv.conf");                  dup_file_into_target("/etc/resolv.conf");
 #else  #else
                 /*          /*
                  * not sure if it is a good idea, to allow dhcp config to           * not sure if it is a good idea, to allow dhcp config to
                  * override IPv6 configuration           * override IPv6 configuration
                  */           */
                 if (net_namesvr[0] != '\0' || net_namesvr6[0] != '\0')          if (net_namesvr[0] != '\0' || net_namesvr6[0] != '\0')
                         dup_file_into_target("/etc/resolv.conf");                  dup_file_into_target("/etc/resolv.conf");
 #endif  #endif
         }  
   
         /*          /*
          * bring the interface up, it will be necessary for IPv6, and           * bring the interface up, it will be necessary for IPv6, and
Line 1172  mnt_net_config(void)
Line 1227  mnt_net_config(void)
                         fclose(hosts);                          fclose(hosts);
                 }                  }
   
                 add_rc_conf("defaultroute=\"%s\"\n", net_defroute);                  if (del_rc_conf("defaultroute") == 0)
                           add_rc_conf("defaultroute=\"%s\"\n", net_defroute);
         } else {          } else {
                 add_rc_conf("ifconfig_%s=dhcp\n", net_dev);                  if (snprintf(ifconfig_str, sizeof ifconfig_str,
                       "ifconfig_%s", net_dev) > 0 &&
                       del_rc_conf(ifconfig_str) == 0) {
                           add_rc_conf("ifconfig_%s=dhcp\n", net_dev);
                   }
         }          }
   
 #ifdef INET6  #ifdef INET6
         if ((net_ip6conf & IP6CONF_AUTOHOST) != 0) {          if ((net_ip6conf & IP6CONF_AUTOHOST) != 0) {
                 add_rc_conf("ip6mode=autohost\n");                  if (del_rc_conf("ip6mode") == 0)
                           add_rc_conf("ip6mode=autohost\n");
                 if (ifconf != NULL) {                  if (ifconf != NULL) {
                         scripting_fprintf(NULL, "cat <<EOF >>%s%s\n",                          scripting_fprintf(NULL, "cat <<EOF >>%s%s\n",
                             target_prefix(), ifconfig_fn);                              target_prefix(), ifconfig_fn);

Legend:
Removed from v.1.127  
changed lines
  Added in v.1.127.4.2

CVSweb <webmaster@jp.NetBSD.org>