Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-2-0]: src/distrib/utils/sysinst Pull up revision 1.102 (requested...



details:   https://anonhg.NetBSD.org/src/rev/dac8502120b5
branches:  netbsd-2-0
changeset: 561329:dac8502120b5
user:      tron <tron%NetBSD.org@localhost>
date:      Mon Jun 07 10:20:57 2004 +0000

description:
Pull up revision 1.102 (requested by dsl in ticket #453):
A load of usability fixes mainly to network installs.
I've made the error retry loops go back as far as the input menus.
Split all the pathname inputs into 2 pieces (base directory and set directory).
Reduced the size of some fixed strings.
Stopped the install aborting if ftp can't find a set (eg the X ones).
The French and Polish transations don't differenciate between Base_dir and
Set_dir - but that can be fixed later.

diffstat:

 distrib/utils/sysinst/net.c |  158 +++++++++++++++++++++++--------------------
 1 files changed, 85 insertions(+), 73 deletions(-)

diffs (truncated from 303 to 300 lines):

diff -r 292b0c5d153b -r dac8502120b5 distrib/utils/sysinst/net.c
--- a/distrib/utils/sysinst/net.c       Mon Jun 07 10:20:51 2004 +0000
+++ b/distrib/utils/sysinst/net.c       Mon Jun 07 10:20:57 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: net.c,v 1.100 2003/11/30 14:36:43 dsl Exp $    */
+/*     $NetBSD: net.c,v 1.100.2.1 2004/06/07 10:20:57 tron Exp $       */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -177,30 +177,24 @@
 {
        char *p = dst;
        char *ep = dst + len;
+       int ch;
 
-       /*
-        * If encoding of a leading slash was desired, and there was in
-        * fact one or more leading slashes, encode one in the output string.
-        */
-       if (encode_leading_slash && *src == '/') {
-               if (ep - p < 3)
-                       goto done;
-               snprintf(p, ep - p, "%%%02X", '/');
-               src++;
-               p += 3;
-       }
-
-       while (ep - p > 1 && *src != '\0') {
+       for (; ep - p > 1; src++) {
+               ch = *src & 0xff;
+               if (ch == 0)
+                       break;
                if (safe_chars != NULL &&
-                   (isalnum(*src) || strchr(safe_chars, *src))) {
-                       *p++ = *src++;
+                   (ch != '/' || !encode_leading_slash) &&
+                   (isalnum(ch) || strchr(safe_chars, ch))) {
+                       *p++ = ch;
                } else {
                        /* encode this char */
                        if (ep - p < 3)
                                break;
-                       snprintf(p, ep - p, "%%%02X", *src++);
+                       snprintf(p, ep - p, "%%%02X", ch);
                        p += 3;
                }
+               encode_leading_slash = 0;
        }
 done:
        *p = '\0';
@@ -368,7 +362,7 @@
 #endif
 
        /* Check host (and domain?) name */
-       if (gethostname(hostname, sizeof(hostname)) == 0) {
+       if (gethostname(hostname, sizeof(hostname)) == 0 && hostname[0] != 0) {
                hostname[sizeof(hostname) - 1] = 0;
                /* check for a . */
                dot = strchr(hostname, '.');
@@ -470,6 +464,7 @@
        int  octet0;
        int  pass, dhcp_config;
        int l;
+       char dhcp_host[STRSIZE];
 #ifdef INET6
        int v6config = 1;
 #endif
@@ -553,9 +548,12 @@
                        net_dhcpconf |= DHCPCONF_DOMAIN;
 
                /* pull hostname out of leases file */
-               get_dhcp_value(net_host, sizeof(net_host), "hostname");
-               if (net_host[0] != '\0')
+               dhcp_host[0] = 0;
+               get_dhcp_value(dhcp_host, sizeof(net_host), "hostname");
+               if (dhcp_host[0] != '\0') {
                        net_dhcpconf |= DHCPCONF_HOST;
+                       strlcpy(net_host, dhcp_host, sizeof net_host);
+               }
        }
 
        msg_prompt_add(MSG_net_domain, net_domain, net_domain,
@@ -581,16 +579,17 @@
                    sizeof net_mask);
                msg_prompt_add(MSG_net_defroute, net_defroute, net_defroute,
                    sizeof net_defroute);
+       }
+       if (!dhcp_config || net_namesvr[0] == 0)
                msg_prompt_add(MSG_net_namesrv, net_namesvr, net_namesvr,
                    sizeof net_namesvr);
-       }
 
 #ifdef INET6
        /* IPv6 autoconfiguration */
        if (!is_v6kernel())
                v6config = 0;
        else if (v6config) {
-               process_menu(MENU_ip6autoconf, NULL);
+               process_menu(MENU_yesno, deconst(MSG_Perform_IPv6_autoconfiguration));
                v6config = yesno ? 1 : 0;
                net_ip6conf |= yesno ? IP6CONF_AUTOHOST : 0;
        }
@@ -616,7 +615,7 @@
                        (v6config ? "yes" : "no"),
                     *net_namesvr6 == '\0' ? "<none>" : net_namesvr6);
 #endif
-       process_menu(MENU_yesno, NULL);
+       process_menu(MENU_yesno, deconst(MSG_netok_ok));
        if (!yesno)
                msg_display(MSG_netagain);
        pass++;
@@ -755,10 +754,12 @@
 {
        distinfo *list;
        char ftp_user_encoded[STRSIZE];
-       char ftp_pass_encoded[STRSIZE];
        char ftp_dir_encoded[STRSIZE];
-       char filename[SSTRSIZE];
        int  ret;
+       int got_one = 0;
+       char *cp;
+       const char *ftp_opt;
+       int cwd;
 
        while ((ret = config_network()) <= 0) {
                if (ret < 0)
@@ -774,6 +775,7 @@
                }
        }
 
+       cwd = open(".", O_RDONLY);
        cd_dist_dir("ftp");
 
        process_menu(MENU_ftpsource, NULL);
@@ -784,8 +786,6 @@
                        list++;
                        continue;
                }
-               (void)snprintf(filename, sizeof filename, "%s%s", list->name,
-                   dist_postfix);
                /*
                 * Invoke ftp to fetch the file.
                 *
@@ -796,46 +796,57 @@
                 * example, ftp_dir could easily contain '~', which is
                 * unsafe by a strict reading of RFC 1738).
                 */
-               if (strcmp("ftp", ftp_user) == 0 && ftp_pass[0] == 0)
-                       ret = run_program(RUN_DISPLAY | RUN_PROGRESS, 
-                           "/usr/bin/ftp -a ftp://%s/%s/%s";,
-                           ftp_host,
-                           url_encode(ftp_dir_encoded, ftp_dir,
-                                       sizeof ftp_dir_encoded,
-                                       RFC1738_SAFE_LESS_SHELL_PLUS_SLASH, 1),
-                           filename);
-               else {
-                       ret = run_program(RUN_DISPLAY | RUN_PROGRESS, 
-                           "/usr/bin/ftp ftp://%s:%s@%s/%s/%s";,
-                           url_encode(ftp_user_encoded, ftp_user,
-                                       sizeof ftp_user_encoded,
-                                       RFC1738_SAFE_LESS_SHELL, 0),
-                           url_encode(ftp_pass_encoded, ftp_pass,
-                                       sizeof ftp_pass_encoded,
-                                       NULL, 0),
-                           ftp_host,
-                           url_encode(ftp_dir_encoded, ftp_dir,
-                                       sizeof ftp_dir_encoded,
-                                       RFC1738_SAFE_LESS_SHELL_PLUS_SLASH, 1),
-                           filename);
+               if (strcmp("ftp", ftp_user) == 0 && ftp_pass[0] == 0) {
+                       /* do anon ftp */
+                       ftp_opt = "-a ";
+                       ftp_user_encoded[0] = 0;
+               } else {
+                       ftp_opt = "";
+                       url_encode(ftp_user_encoded, ftp_user,
+                                   sizeof ftp_user_encoded / 2 - 1,
+                                   RFC1738_SAFE_LESS_SHELL, 0),
+                       cp = strchr(ftp_user_encoded, 0);
+                       *cp++ = ':';
+                       url_encode(cp, ftp_pass,
+                                   sizeof ftp_user_encoded / 2 - 1,
+                                   NULL, 0),
+                       cp = strchr(cp, 0);
+                       *cp++ = '@';
+                       *cp = 0;
                }
-               if (ret) {
+
+               url_encode(ftp_dir_encoded, ftp_dir,
+                           sizeof ftp_dir_encoded - 1,
+                           RFC1738_SAFE_LESS_SHELL_PLUS_SLASH, 1),
+               cp = strchr(ftp_dir_encoded, 0);
+               if (set_dir[0] != '/')
+                       *cp++ = '/';
+               url_encode(cp, set_dir,
+                           ftp_dir_encoded + sizeof ftp_dir_encoded - cp,
+                           RFC1738_SAFE_LESS_SHELL_PLUS_SLASH, 0),
+
+               ret = run_program(RUN_DISPLAY | RUN_PROGRESS, 
+                           "/usr/bin/ftp %sftp://%s%s/%s/%s%s";,
+                           ftp_opt, ftp_user_encoded, ftp_host,
+                           ftp_dir_encoded, list->name, dist_postfix);
+
+               if (ret == 0) {
+                       got_one = 1;
+               } else {
                        /* Error getting the file.  Bad host name ... ? */
-                       msg_display(MSG_ftperror_cont);
-                       getchar();
-                       wrefresh(curscr);
-                       wmove(stdscr, 0, 0);
-                       touchwin(stdscr);
-                       wclear(stdscr);
-                       wrefresh(stdscr);
-                       msg_display(MSG_ftperror);
-                       process_menu(MENU_yesno, NULL);
-                       if (yesno)
+                       process_menu(MENU_yesno, deconst(MSG_ftperror));
+                       if (yesno) {
                                process_menu(MENU_ftpsource, NULL);
-                       else
+                               continue;
+                       }
+                       if (got_one == 0) {
+                               fchdir(cwd);    /* back to current real root */
+                               close(cwd);
                                return 0;
-               } else
-                       list++;
+                       }
+                       /* Continue without this set... */
+               }
+               list++;
 
        }
        wrefresh(curscr);
@@ -843,9 +854,9 @@
        touchwin(stdscr);
        wclear(stdscr);
        wrefresh(stdscr);
-#ifndef DEBUG
-       chdir("/");     /* back to current real root */
-#endif
+
+       fchdir(cwd);    /* back to current real root */
+       close(cwd);
        return (1);
 }
 
@@ -868,9 +879,9 @@
                }
         }
 
+again:
        /* Get server and filepath */
        process_menu(MENU_nfssource, NULL);
-again:
 
        umount_mnt2();
 
@@ -886,9 +897,11 @@
        }
        mnt2_mounted = 1;
 
+       snprintf(ext_dir, sizeof ext_dir, "/mnt2/%s", set_dir);
+
        /* Verify distribution files exist.  */
-       if (distribution_sets_exist_p("/mnt2") == 0) {
-               msg_display(MSG_badsetdir, "/mnt2");
+       if (distribution_sets_exist_p(ext_dir) == 0) {
+               msg_display(MSG_badsetdir, ext_dir);
                process_menu (MENU_nfsbadmount, NULL);
                if (!yesno)
                        return (0);
@@ -897,7 +910,6 @@
        }
 
        /* return location, don't clean... */
-       strlcpy(ext_dir, "/mnt2", sizeof(ext_dir));
        clean_dist_dir = 0;
        return 1;
 }
@@ -937,8 +949,8 @@
 
        if (!network_up)
                return;
-       msg_prompt(MSG_mntnetconfig, yes, ans, sizeof ans);
-       if (strcmp(ans, yes) != 0)
+       process_menu(MENU_yesno, deconst(MSG_mntnetconfig));
+       if (!yesno)
                return;
 
        /* Write hostname to /etc/rc.conf */
@@ -1052,7 +1064,7 @@
 
        if (!file_mode_match(DHCLIENT_EX, S_IFREG))
                return 0;
-       process_menu(MENU_dhcpautoconf, NULL);
+       process_menu(MENU_yesno, deconst(MSG_Perform_DHCP_autoconfiguration));



Home | Main Index | Thread Index | Old Index