1999-06-20 10:08:13 +04:00
|
|
|
/* $NetBSD: net.c,v 1.46 1999/06/20 06:08:15 cgd Exp $ */
|
1997-09-27 03:02:53 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 1997 Piermont Information Systems Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Written by Philip A. Nelson for Piermont Information Systems Inc.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
1999-06-20 10:08:13 +04:00
|
|
|
* This product includes software developed for the NetBSD Project by
|
1997-09-27 03:02:53 +04:00
|
|
|
* Piermont Information Systems Inc.
|
|
|
|
* 4. The name of Piermont Information Systems Inc. may not be used to endorse
|
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* net.c -- routines to fetch files off the network. */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <curses.h>
|
1998-02-09 10:34:16 +03:00
|
|
|
#include <time.h>
|
1997-09-27 03:02:53 +04:00
|
|
|
#include <unistd.h>
|
1997-11-22 17:16:55 +03:00
|
|
|
#include <sys/param.h>
|
1997-09-27 03:02:53 +04:00
|
|
|
#include "defs.h"
|
|
|
|
#include "md.h"
|
|
|
|
#include "msg_defs.h"
|
|
|
|
#include "menu_defs.h"
|
|
|
|
#include "txtwalk.h"
|
|
|
|
|
1997-12-26 04:58:44 +03:00
|
|
|
int network_up = 0;
|
1997-10-20 10:13:25 +04:00
|
|
|
|
1999-03-19 17:49:07 +03:00
|
|
|
/* URL encode unsafe characters. */
|
|
|
|
|
|
|
|
static char *url_encode __P((char *dst, const char *src, size_t len,
|
1999-06-19 03:26:40 +04:00
|
|
|
const char *safe_chars,
|
|
|
|
int encode_leading_slash));
|
1999-03-19 17:49:07 +03:00
|
|
|
|
1997-10-22 19:28:33 +04:00
|
|
|
/* Get the list of network interfaces. */
|
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
static void get_ifconfig_info __P((void));
|
|
|
|
static void get_ifinterface_info __P((void));
|
|
|
|
|
1999-03-19 17:49:07 +03:00
|
|
|
/*
|
|
|
|
* URL encode unsafe characters. See RFC 1738.
|
|
|
|
*
|
|
|
|
* Copies src string to dst, encoding unsafe or reserved characters
|
|
|
|
* in %hex form as it goes, and returning a pointer to the result.
|
|
|
|
* The result is always a nul-terminated string even if it had to be
|
|
|
|
* truncated to avoid overflowing the available space.
|
|
|
|
*
|
|
|
|
* len is the length of the destination buffer. The result will be
|
|
|
|
* truncated if necessary to fit in the destination buffer.
|
|
|
|
*
|
1999-06-19 03:26:40 +04:00
|
|
|
* safe_chars is a string of characters that should not be encoded. If
|
|
|
|
* safe_chars is non-NULL, any characters in safe_chars as well as any
|
|
|
|
* alphanumeric characters will be copied from src to dst without
|
|
|
|
* encoding. Some potentially useful settings for this parameter are:
|
1999-03-19 17:49:07 +03:00
|
|
|
*
|
1999-06-19 03:26:40 +04:00
|
|
|
* NULL Everything is encoded (even alphanumerics)
|
|
|
|
* "" Everything except alphanumerics are encoded
|
1999-03-19 17:49:07 +03:00
|
|
|
* "/" Alphanumerics and '/' remain unencoded
|
|
|
|
* "$-_.+!*'()," Consistent with a strict reading of RFC 1738
|
|
|
|
* "$-_.+!*'(),/" As above, except '/' is not encoded
|
|
|
|
* "-_.+!,/" As above, except shell special characters are encoded
|
|
|
|
*
|
|
|
|
* Unsafe and reserved characters are defined in RFC 1738 section 2.2.
|
|
|
|
* The most important parts are:
|
|
|
|
*
|
|
|
|
* The characters ";", "/", "?", ":", "@", "=" and "&" are the
|
|
|
|
* characters which may be reserved for special meaning within a
|
|
|
|
* scheme. No other characters may be reserved within a scheme.
|
|
|
|
* [...]
|
|
|
|
*
|
|
|
|
* Thus, only alphanumerics, the special characters "$-_.+!*'(),",
|
|
|
|
* and reserved characters used for their reserved purposes may be
|
|
|
|
* used unencoded within a URL.
|
|
|
|
*
|
1999-04-07 17:09:55 +04:00
|
|
|
* The encoded URL _does_not_ start with a '/'. A '/' is inserted
|
|
|
|
* between the hostname and the pathname components when the complete
|
|
|
|
* URL is constructed.
|
|
|
|
*
|
1999-03-19 17:49:07 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define RFC1738_SAFE "$-_.+!*'(),"
|
|
|
|
#define RFC1738_SAFE_LESS_SHELL "-_.+!,"
|
|
|
|
#define RFC1738_SAFE_LESS_SHELL_PLUS_SLASH "-_.+!,/"
|
|
|
|
|
|
|
|
static char *
|
|
|
|
url_encode(char *dst, const char *src, size_t len,
|
1999-06-19 03:26:40 +04:00
|
|
|
const char *safe_chars, int encode_leading_slash)
|
1999-03-19 17:49:07 +03:00
|
|
|
{
|
|
|
|
char *p = dst;
|
1999-06-19 03:26:40 +04:00
|
|
|
const char *initialsrc = src;
|
1999-03-19 17:49:07 +03:00
|
|
|
|
1999-04-07 17:09:55 +04:00
|
|
|
/* Remove any initial '/'s if present */
|
|
|
|
while (*src == '/')
|
|
|
|
src++;
|
1999-06-19 03:26:40 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If encoding of a leading slash was desired, and there was in
|
|
|
|
* fact one or more leading shashes, encode one in the output string.
|
|
|
|
*/
|
|
|
|
if (encode_leading_slash && (src != initialsrc)) {
|
|
|
|
if (len < 3)
|
|
|
|
goto done;
|
|
|
|
sprintf(p, "%%%02X", '/');
|
|
|
|
p += 3;
|
|
|
|
}
|
|
|
|
|
1999-03-19 17:49:07 +03:00
|
|
|
while (--len > 0 && *src != '\0') {
|
1999-06-19 03:26:40 +04:00
|
|
|
if (safe_chars != NULL &&
|
|
|
|
(isalnum(*src) || strchr(safe_chars, *src))) {
|
1999-03-19 17:49:07 +03:00
|
|
|
*p++ = *src++;
|
|
|
|
} else {
|
|
|
|
/* encode this char */
|
|
|
|
if (len < 3)
|
|
|
|
break;
|
|
|
|
sprintf(p, "%%%02X", *src++);
|
|
|
|
p += 3;
|
|
|
|
len -= 2;
|
|
|
|
}
|
|
|
|
}
|
1999-06-19 03:26:40 +04:00
|
|
|
done:
|
1999-03-19 17:49:07 +03:00
|
|
|
*p = '\0';
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
static void
|
|
|
|
get_ifconfig_info()
|
1997-09-27 03:02:53 +04:00
|
|
|
{
|
|
|
|
char *textbuf;
|
|
|
|
int textsize;
|
1997-10-07 08:01:29 +04:00
|
|
|
char *t;
|
1997-09-27 03:02:53 +04:00
|
|
|
|
|
|
|
/* Get ifconfig information */
|
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
textsize = collect(T_OUTPUT, &textbuf, "/sbin/ifconfig -l 2>/dev/null");
|
1997-09-27 03:02:53 +04:00
|
|
|
if (textsize < 0) {
|
1999-01-21 11:02:17 +03:00
|
|
|
if (logging)
|
|
|
|
(void)fprintf(log, "Aborting: Could not run ifconfig.\n");
|
1998-06-20 17:05:48 +04:00
|
|
|
(void)fprintf(stderr, "Could not run ifconfig.");
|
|
|
|
exit(1);
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
1998-06-20 17:05:48 +04:00
|
|
|
(void)strtok(textbuf,"\n");
|
|
|
|
strncpy(net_devices, textbuf, textsize<STRSIZE ? textsize : STRSIZE);
|
1997-10-01 09:04:24 +04:00
|
|
|
net_devices[STRSIZE] = 0;
|
1998-06-20 17:05:48 +04:00
|
|
|
free(textbuf);
|
1997-10-07 08:01:29 +04:00
|
|
|
|
|
|
|
/* Remove lo0 and anything after ... */
|
1998-06-20 17:05:48 +04:00
|
|
|
t = strstr(net_devices, "lo0");
|
1997-10-07 08:01:29 +04:00
|
|
|
if (t != NULL)
|
|
|
|
*t = 0;
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
1997-11-22 17:16:55 +03:00
|
|
|
/* Fill in defaults network values for the selected interface */
|
1998-06-20 17:05:48 +04:00
|
|
|
static void
|
|
|
|
get_ifinterface_info()
|
1997-11-22 17:16:55 +03:00
|
|
|
{
|
|
|
|
char *textbuf;
|
|
|
|
int textsize;
|
|
|
|
char *t;
|
1998-07-06 10:56:06 +04:00
|
|
|
char hostname[MAXHOSTNAMELEN + 1];
|
1997-11-22 17:16:55 +03:00
|
|
|
|
|
|
|
/* First look to see if the selected interface is already configured. */
|
|
|
|
textsize = collect(T_OUTPUT, &textbuf, "/sbin/ifconfig %s 2>/dev/null",
|
1998-06-20 17:05:48 +04:00
|
|
|
net_dev);
|
1997-11-22 17:16:55 +03:00
|
|
|
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);
|
1998-06-20 17:05:48 +04:00
|
|
|
} else if (strcmp(t, "netmask") == 0) {
|
1997-11-22 17:16:55 +03:00
|
|
|
t = strtok(NULL, " \t\n");
|
|
|
|
if (strcmp(t, "0x0") != 0)
|
|
|
|
strcpy(net_mask, t);
|
1998-06-20 17:05:48 +04:00
|
|
|
} else if (strcmp(t, "media:") == 0) {
|
1997-12-26 04:58:44 +03:00
|
|
|
t = strtok(NULL, " \t\n");
|
1998-11-09 10:56:11 +03:00
|
|
|
/* handle "media: Ethernet manual" */
|
|
|
|
if (strcmp(t, "Ethernet") == 0)
|
|
|
|
t = strtok(NULL, " \t\n");
|
1997-12-26 04:58:44 +03:00
|
|
|
if (strcmp(t, "none") != 0 &&
|
|
|
|
strcmp(t, "manual") != 0)
|
|
|
|
strcpy(net_media, t);
|
|
|
|
}
|
1997-11-22 17:16:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check host (and domain?) name */
|
1998-07-06 10:56:06 +04:00
|
|
|
if (gethostname(hostname, sizeof(hostname)) == 0) {
|
|
|
|
hostname[sizeof(hostname) - 1] = '\0';
|
1997-11-22 17:16:55 +03:00
|
|
|
strncpy(net_host, hostname, sizeof(net_host));
|
1998-07-06 10:56:06 +04:00
|
|
|
}
|
1997-11-22 17:16:55 +03:00
|
|
|
}
|
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
/*
|
|
|
|
* Get the information to configure the network, configure it and
|
|
|
|
* make sure both the gateway and the name server are up.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
config_network()
|
1997-09-27 03:02:53 +04:00
|
|
|
{ char *tp;
|
|
|
|
char defname[255];
|
|
|
|
int octet0;
|
1997-12-26 04:58:44 +03:00
|
|
|
int pass, needmedia;
|
1997-09-27 03:02:53 +04:00
|
|
|
|
|
|
|
FILE *f;
|
1997-11-02 11:20:40 +03:00
|
|
|
time_t now;
|
1997-09-27 03:02:53 +04:00
|
|
|
|
1997-10-20 10:13:25 +04:00
|
|
|
if (network_up)
|
1998-06-20 17:05:48 +04:00
|
|
|
return (1);
|
1997-10-20 10:13:25 +04:00
|
|
|
|
1997-11-22 16:52:45 +03:00
|
|
|
network_up = 1;
|
1997-09-27 03:02:53 +04:00
|
|
|
net_devices[0] = '\0';
|
1998-06-20 17:05:48 +04:00
|
|
|
get_ifconfig_info();
|
1997-11-22 03:29:33 +03:00
|
|
|
if (strlen(net_devices) == 0) {
|
|
|
|
/* No network interfaces found! */
|
1998-06-20 17:05:48 +04:00
|
|
|
msg_display(MSG_nonet);
|
|
|
|
process_menu(MENU_ok);
|
|
|
|
return (-1);
|
1997-11-22 03:29:33 +03:00
|
|
|
}
|
1998-06-20 17:05:48 +04:00
|
|
|
strncpy(defname, net_devices, 255);
|
1997-09-27 03:02:53 +04:00
|
|
|
tp = defname;
|
|
|
|
strsep(&tp, " ");
|
1998-06-20 17:05:48 +04:00
|
|
|
msg_prompt(MSG_asknetdev, defname, net_dev, 255, net_devices);
|
1997-09-27 03:02:53 +04:00
|
|
|
tp = net_dev;
|
|
|
|
strsep(&tp, " ");
|
|
|
|
net_dev[strlen(net_dev)+1] = 0;
|
|
|
|
net_dev[strlen(net_dev)] = ' ';
|
1998-10-14 09:27:52 +04:00
|
|
|
while (strstr(net_devices, net_dev) == NULL) {
|
|
|
|
msg_prompt(MSG_badnet, defname, net_dev, 255, net_devices);
|
1997-09-27 03:02:53 +04:00
|
|
|
tp = net_dev;
|
|
|
|
strsep(&tp, " ");
|
|
|
|
net_dev[strlen(net_dev)+1] = 0;
|
|
|
|
net_dev[strlen(net_dev)] = ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove that space we added. */
|
1998-06-20 17:05:48 +04:00
|
|
|
net_dev[strlen(net_dev) - 1] = 0;
|
1997-11-22 17:16:55 +03:00
|
|
|
|
|
|
|
/* Preload any defaults we can find */
|
1998-06-20 17:05:48 +04:00
|
|
|
get_ifinterface_info();
|
1997-11-22 17:16:55 +03:00
|
|
|
pass = strlen(net_mask) == 0 ? 0 : 1;
|
1997-12-26 04:58:44 +03:00
|
|
|
needmedia = strlen(net_media) == 0 ? 0 : 1;
|
1997-09-27 03:02:53 +04:00
|
|
|
|
|
|
|
/* Get other net information */
|
1998-06-20 17:05:48 +04:00
|
|
|
msg_display(MSG_netinfo);
|
1997-09-27 03:02:53 +04:00
|
|
|
do {
|
1998-06-20 17:05:48 +04:00
|
|
|
msg_prompt_add(MSG_net_domain, net_domain, net_domain, STRSIZE);
|
|
|
|
msg_prompt_add(MSG_net_host, net_host, net_host, STRSIZE);
|
|
|
|
msg_prompt_add(MSG_net_ip, net_ip, net_ip, STRSIZE);
|
1997-09-27 03:02:53 +04:00
|
|
|
octet0 = atoi(net_ip);
|
|
|
|
if (!pass) {
|
|
|
|
if (0 <= octet0 && octet0 <= 127)
|
1998-06-20 17:05:48 +04:00
|
|
|
strcpy(net_mask, "0xff000000");
|
1998-09-17 20:45:36 +04:00
|
|
|
else if (128 <= octet0 && octet0 <= 191)
|
1998-06-20 17:05:48 +04:00
|
|
|
strcpy(net_mask, "0xffff0000");
|
1997-09-27 03:02:53 +04:00
|
|
|
else if (192 <= octet0 && octet0 <= 223)
|
1998-09-17 20:45:36 +04:00
|
|
|
strcpy(net_mask, "0xffffff00");
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
1998-06-20 17:05:48 +04:00
|
|
|
msg_prompt_add(MSG_net_mask, net_mask, net_mask, STRSIZE);
|
|
|
|
msg_prompt_add(MSG_net_defroute, net_defroute, net_defroute,
|
1997-09-27 03:02:53 +04:00
|
|
|
STRSIZE);
|
1998-06-20 17:05:48 +04:00
|
|
|
msg_prompt_add(MSG_net_namesrv, net_namesvr, net_namesvr,
|
1997-10-20 10:13:25 +04:00
|
|
|
STRSIZE);
|
1997-12-26 04:58:44 +03:00
|
|
|
if (needmedia)
|
|
|
|
msg_prompt_add(MSG_net_media, net_media, net_media,
|
|
|
|
STRSIZE);
|
1997-09-27 03:02:53 +04:00
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
msg_display(MSG_netok, net_domain, net_host, net_ip, net_mask,
|
1997-11-22 16:52:45 +03:00
|
|
|
*net_namesvr == '\0' ? "<none>" : net_namesvr,
|
1997-12-26 04:58:44 +03:00
|
|
|
*net_defroute == '\0' ? "<none>" : net_defroute,
|
|
|
|
*net_media == '\0' ? "<default>" : net_media);
|
1998-06-20 17:05:48 +04:00
|
|
|
process_menu(MENU_yesno);
|
1997-09-27 03:02:53 +04:00
|
|
|
if (!yesno)
|
1998-06-20 17:05:48 +04:00
|
|
|
msg_display(MSG_netagain);
|
1997-09-27 03:02:53 +04:00
|
|
|
pass++;
|
|
|
|
} while (!yesno);
|
|
|
|
|
1997-11-22 16:52:45 +03:00
|
|
|
/* Create /etc/resolv.conf if a nameserver was given */
|
|
|
|
if (strcmp(net_namesvr, "") != 0) {
|
1997-09-27 03:02:53 +04:00
|
|
|
#ifdef DEBUG
|
1998-06-20 17:05:48 +04:00
|
|
|
f = fopen("/tmp/resolv.conf", "w");
|
1997-09-27 03:02:53 +04:00
|
|
|
#else
|
1998-06-20 17:05:48 +04:00
|
|
|
f = fopen("/etc/resolv.conf", "w");
|
1997-09-27 03:02:53 +04:00
|
|
|
#endif
|
1997-11-22 16:52:45 +03:00
|
|
|
if (f == NULL) {
|
1999-01-21 11:02:17 +03:00
|
|
|
if (logging)
|
|
|
|
(void)fprintf(log, "%s", msg_string(MSG_resolv));
|
1997-11-22 16:52:45 +03:00
|
|
|
(void)fprintf(stderr, "%s", msg_string(MSG_resolv));
|
|
|
|
exit(1);
|
|
|
|
}
|
1999-01-21 11:02:17 +03:00
|
|
|
if (scripting)
|
|
|
|
(void)fprintf(script, "cat <<EOF >/etc/resolv.conf\n");
|
1997-11-22 16:52:45 +03:00
|
|
|
time(&now);
|
|
|
|
/* NB: ctime() returns a string ending in '\n' */
|
1998-06-20 17:05:48 +04:00
|
|
|
(void)fprintf(f, ";\n; BIND data file\n; %s %s;\n",
|
|
|
|
"Created by NetBSD sysinst on", ctime(&now));
|
1997-11-22 16:52:45 +03:00
|
|
|
(void)fprintf (f,
|
1998-06-20 17:05:48 +04:00
|
|
|
"nameserver %s\nlookup file bind\nsearch %s\n",
|
|
|
|
net_namesvr, net_domain);
|
1999-01-21 11:02:17 +03:00
|
|
|
if (scripting) {
|
|
|
|
(void)fprintf(script, ";\n; BIND data file\n; %s %s;\n",
|
|
|
|
"Created by NetBSD sysinst on", ctime(&now));
|
|
|
|
(void)fprintf (script,
|
|
|
|
"nameserver %s\nlookup file bind\nsearch %s\n",
|
|
|
|
net_namesvr, net_domain);
|
|
|
|
}
|
|
|
|
fflush(NULL);
|
1998-06-20 17:05:48 +04:00
|
|
|
fclose(f);
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
1999-04-09 14:24:38 +04:00
|
|
|
run_prog(0, 0, NULL, "/sbin/ifconfig lo0 127.0.0.1");
|
1998-11-09 10:56:11 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ifconfig does not allow media specifiers on IFM_MANUAL interfaces.
|
|
|
|
* Our UI gies no way to set an option back to null-string if it
|
|
|
|
* gets accidentally set.
|
|
|
|
* good way to re-set the media media to null-string.
|
|
|
|
* Check for plausible alternatives.
|
|
|
|
*/
|
|
|
|
if (strcmp(net_media, "<default>") == 0 ||
|
|
|
|
strcmp(net_media, "default") == 0 ||
|
|
|
|
strcmp(net_media, "<manual>") == 0 ||
|
|
|
|
strcmp(net_media, "manual") == 0 ||
|
|
|
|
strcmp(net_media, "<none>") == 0 ||
|
|
|
|
strcmp(net_media, "none") == 0 ||
|
|
|
|
strcmp(net_media, " ") == 0) {
|
|
|
|
*net_media = '\0';
|
|
|
|
}
|
|
|
|
|
1997-12-26 04:58:44 +03:00
|
|
|
if (*net_media != '\0')
|
1999-04-09 14:24:38 +04:00
|
|
|
run_prog(0, 0, NULL,
|
|
|
|
"/sbin/ifconfig %s inet %s netmask %s media %s",
|
1997-12-26 04:58:44 +03:00
|
|
|
net_dev, net_ip, net_mask, net_media);
|
|
|
|
else
|
1999-04-09 14:24:38 +04:00
|
|
|
run_prog(0, 0, NULL,
|
|
|
|
"/sbin/ifconfig %s inet %s netmask %s", net_dev,
|
1997-12-26 04:58:44 +03:00
|
|
|
net_ip, net_mask);
|
1997-10-01 09:04:24 +04:00
|
|
|
|
1998-02-07 13:28:02 +03:00
|
|
|
/* Set host name */
|
1998-06-20 17:05:48 +04:00
|
|
|
if (strcmp(net_host, "") != 0)
|
1998-02-07 13:28:02 +03:00
|
|
|
sethostname(net_host, strlen(net_host));
|
|
|
|
|
1997-11-22 16:52:45 +03:00
|
|
|
/* Set a default route if one was given */
|
|
|
|
if (strcmp(net_defroute, "") != 0) {
|
1999-04-09 14:24:38 +04:00
|
|
|
run_prog(0, 0, NULL,
|
|
|
|
"/sbin/route -n flush");
|
|
|
|
run_prog(0, 0, NULL,
|
|
|
|
"/sbin/route -n add default %s",
|
1997-11-22 16:52:45 +03:00
|
|
|
net_defroute);
|
|
|
|
}
|
|
|
|
|
1999-01-21 11:02:17 +03:00
|
|
|
/*
|
|
|
|
* ping should be verbose, so users can see the cause
|
|
|
|
* of a network failure.
|
|
|
|
*/
|
|
|
|
|
1997-11-22 16:52:45 +03:00
|
|
|
if (strcmp(net_namesvr, "") != 0 && network_up)
|
1999-04-09 14:24:38 +04:00
|
|
|
network_up = !run_prog(0, 1, NULL,
|
|
|
|
"/sbin/ping -c 2 %s",
|
1997-12-05 20:19:48 +03:00
|
|
|
net_namesvr);
|
1997-11-22 16:52:45 +03:00
|
|
|
|
|
|
|
if (strcmp(net_defroute, "") != 0 && network_up)
|
1999-04-09 14:24:38 +04:00
|
|
|
network_up = !run_prog(0, 1, NULL,
|
|
|
|
"/sbin/ping -c 2 %s",
|
1997-12-05 20:19:48 +03:00
|
|
|
net_defroute);
|
1999-01-21 11:02:17 +03:00
|
|
|
fflush(NULL);
|
1997-10-20 10:13:25 +04:00
|
|
|
|
|
|
|
return network_up;
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
1997-09-27 04:09:22 +04:00
|
|
|
int
|
1998-06-20 17:05:48 +04:00
|
|
|
get_via_ftp()
|
1997-09-27 04:09:22 +04:00
|
|
|
{
|
1997-10-29 04:06:42 +03:00
|
|
|
distinfo *list;
|
1999-03-19 17:49:07 +03:00
|
|
|
char ftp_user_encoded[STRSIZE];
|
|
|
|
char ftp_pass_encoded[STRSIZE];
|
|
|
|
char ftp_dir_encoded[STRSIZE];
|
1997-10-15 08:35:17 +04:00
|
|
|
char filename[SSTRSIZE];
|
1997-09-27 04:09:22 +04:00
|
|
|
int ret;
|
1997-09-27 03:02:53 +04:00
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
while (!config_network()) {
|
|
|
|
msg_display(MSG_netnotup);
|
|
|
|
process_menu(MENU_yesno);
|
1997-10-01 09:04:24 +04:00
|
|
|
if (!yesno)
|
|
|
|
return 0;
|
|
|
|
}
|
1997-10-29 04:06:42 +03:00
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
cd_dist_dir("ftp");
|
1997-10-29 04:06:42 +03:00
|
|
|
|
1997-11-05 04:23:06 +03:00
|
|
|
/* Fill in final values for ftp_dir. */
|
1998-06-20 17:05:48 +04:00
|
|
|
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));
|
|
|
|
process_menu(MENU_ftpsource);
|
- Add 2 functions in label.c, getpartoff()/getpartsize() used to let the user
enter partitions offet and size. The user can chose unit independantly of
the unit used for display ('M'/'c'/'s'). These functions do the proper
bound checks and alignement/roudups. Used in the edfspart menu and
i386 md_make_bsd_partitions() (other ports should do the change as
well).
- now that getpartsize() does the rigth thing, kill the swapadj hack (which was
buggy anyway).
- in i386 md_make_bsd_partitions(), don't propose defaults that don't fit on
the disk. If the disk is too small, fallback to custom instead.
- fix a bug in mbr.c, where the partition flags would not have always been
reset. sysinst created me a MBR with 2 active partition. The boot code
doesn't like it :)
- added a message for eventual mount failures.
- killed donewfs and extracting messages, as we run the commands in a
subwindow these messages just flashed on the screen.
- Changes a few exit(1) to return(1), to give the user a second chance.
- added msg_clear() or wclear(stdscr) in a place or two, to make
display a bit nicer.
- in run_cmd(), if the command succeeded, don't wait for the user to
press enter.
1999-04-12 02:40:19 +04:00
|
|
|
|
1997-10-18 02:17:05 +04:00
|
|
|
list = dist_list;
|
1997-10-29 04:06:42 +03:00
|
|
|
while (list->name) {
|
|
|
|
if (!list->getit) {
|
|
|
|
list++;
|
|
|
|
continue;
|
|
|
|
}
|
1998-06-20 17:05:48 +04:00
|
|
|
(void)snprintf(filename, SSTRSIZE, "%s%s", list->name,
|
|
|
|
dist_postfix);
|
1999-03-19 17:49:07 +03:00
|
|
|
/*
|
|
|
|
* Invoke ftp to fetch the file.
|
|
|
|
*
|
|
|
|
* ftp_pass is quite likely to contain unsafe characters
|
|
|
|
* that need to be encoded in the URL (for example,
|
|
|
|
* "@", ":" and "/" need quoting). Let's be
|
|
|
|
* paranoid and also encode ftp_user and ftp_dir. (For
|
|
|
|
* example, ftp_dir could easily contain '~', which is
|
1999-04-07 09:18:49 +04:00
|
|
|
* unsafe by a strict reading of RFC 1738).
|
1999-03-19 17:49:07 +03:00
|
|
|
*/
|
1997-09-27 03:02:53 +04:00
|
|
|
if (strcmp ("ftp", ftp_user) == 0)
|
1999-04-09 14:24:38 +04:00
|
|
|
ret = run_prog(0, 1, NULL,
|
|
|
|
"/usr/bin/ftp -a ftp://%s/%s/%s",
|
1999-03-19 17:49:07 +03:00
|
|
|
ftp_host,
|
|
|
|
url_encode(ftp_dir_encoded, ftp_dir, STRSIZE,
|
1999-06-19 03:26:40 +04:00
|
|
|
RFC1738_SAFE_LESS_SHELL_PLUS_SLASH, 1),
|
1999-03-19 17:49:07 +03:00
|
|
|
filename);
|
|
|
|
else {
|
1999-04-09 14:24:38 +04:00
|
|
|
ret = run_prog(0, 1, NULL,
|
|
|
|
"/usr/bin/ftp ftp://%s:%s@%s/%s/%s",
|
1999-03-19 17:49:07 +03:00
|
|
|
url_encode(ftp_user_encoded, ftp_user, STRSIZE,
|
1999-06-19 03:26:40 +04:00
|
|
|
RFC1738_SAFE_LESS_SHELL, 0),
|
1999-03-19 17:49:07 +03:00
|
|
|
url_encode(ftp_pass_encoded, ftp_pass, STRSIZE,
|
1999-06-19 03:26:40 +04:00
|
|
|
NULL, 0),
|
1999-03-19 17:49:07 +03:00
|
|
|
ftp_host,
|
|
|
|
url_encode(ftp_dir_encoded, ftp_dir, STRSIZE,
|
1999-06-19 03:26:40 +04:00
|
|
|
RFC1738_SAFE_LESS_SHELL_PLUS_SLASH, 1),
|
1999-03-19 17:49:07 +03:00
|
|
|
filename);
|
|
|
|
}
|
1997-09-27 04:09:22 +04:00
|
|
|
if (ret) {
|
|
|
|
/* Error getting the file. Bad host name ... ? */
|
1998-06-20 17:05:48 +04:00
|
|
|
msg_display(MSG_ftperror_cont);
|
1997-11-25 03:24:52 +03:00
|
|
|
getchar();
|
1998-06-20 17:05:48 +04:00
|
|
|
puts(CL);
|
|
|
|
wrefresh(stdscr);
|
|
|
|
msg_display(MSG_ftperror);
|
|
|
|
process_menu(MENU_yesno);
|
1997-09-27 04:09:22 +04:00
|
|
|
if (yesno)
|
1998-06-20 17:05:48 +04:00
|
|
|
process_menu(MENU_ftpsource);
|
1997-09-27 04:09:22 +04:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
} else
|
|
|
|
list++;
|
1997-11-11 03:43:31 +03:00
|
|
|
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
1998-06-20 17:05:48 +04:00
|
|
|
puts(CL); /* Just to make sure. */
|
|
|
|
wrefresh(stdscr);
|
1997-09-27 03:02:53 +04:00
|
|
|
#ifndef DEBUG
|
1997-11-02 11:20:40 +03:00
|
|
|
chdir("/"); /* back to current real root */
|
1997-09-27 03:02:53 +04:00
|
|
|
#endif
|
1998-06-20 17:05:48 +04:00
|
|
|
return (1);
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
1997-10-15 08:35:17 +04:00
|
|
|
int
|
1998-06-20 17:05:48 +04:00
|
|
|
get_via_nfs()
|
1997-09-27 03:02:53 +04:00
|
|
|
{
|
1998-06-20 17:05:48 +04:00
|
|
|
|
|
|
|
while (!config_network()) {
|
|
|
|
msg_display(MSG_netnotup);
|
|
|
|
process_menu(MENU_yesno);
|
1997-10-15 08:35:17 +04:00
|
|
|
if (!yesno)
|
1998-06-20 17:05:48 +04:00
|
|
|
return (0);
|
1997-10-15 08:35:17 +04:00
|
|
|
}
|
|
|
|
|
1997-09-27 03:02:53 +04:00
|
|
|
/* Get server and filepath */
|
1998-06-20 17:05:48 +04:00
|
|
|
process_menu(MENU_nfssource);
|
1997-12-05 17:00:59 +03:00
|
|
|
again:
|
1997-10-15 08:35:17 +04:00
|
|
|
|
1999-04-09 14:24:38 +04:00
|
|
|
run_prog(0, 0, NULL,
|
|
|
|
"/sbin/umount /mnt2");
|
1997-12-05 17:00:59 +03:00
|
|
|
|
1997-09-27 03:02:53 +04:00
|
|
|
/* Mount it */
|
1999-04-09 14:24:38 +04:00
|
|
|
if (run_prog(0, 0, NULL,
|
|
|
|
"/sbin/mount -r -o -i,-r=1024 -t nfs %s:%s /mnt2",
|
1998-06-20 17:05:48 +04:00
|
|
|
nfs_host, nfs_dir)) {
|
|
|
|
msg_display(MSG_nfsbadmount, nfs_host, nfs_dir);
|
|
|
|
process_menu(MENU_nfsbadmount);
|
1997-10-15 08:35:17 +04:00
|
|
|
if (!yesno)
|
1998-06-20 17:05:48 +04:00
|
|
|
return (0);
|
1997-12-05 17:00:59 +03:00
|
|
|
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;
|
1997-10-15 08:35:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* return location, don't clean... */
|
1998-06-20 17:05:48 +04:00
|
|
|
strcpy(ext_dir, "/mnt2");
|
1997-10-15 08:35:17 +04:00
|
|
|
clean_dist_dir = 0;
|
1997-10-20 10:13:25 +04:00
|
|
|
mnt2_mounted = 1;
|
1997-10-15 08:35:17 +04:00
|
|
|
return 1;
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
1997-10-20 10:13:25 +04:00
|
|
|
|
1997-11-03 02:43:11 +03:00
|
|
|
/*
|
|
|
|
* 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.
|
1998-06-20 17:05:48 +04:00
|
|
|
*
|
|
|
|
* XXXX rc.conf support is needed here!
|
1997-11-03 02:43:11 +03:00
|
|
|
*/
|
1997-10-20 10:13:25 +04:00
|
|
|
void
|
|
|
|
mnt_net_config(void)
|
|
|
|
{
|
|
|
|
char ans [5] = "y";
|
1997-11-02 11:20:40 +03:00
|
|
|
char ifconfig_fn [STRSIZE];
|
1997-11-05 10:28:20 +03:00
|
|
|
FILE *f;
|
1997-10-20 10:13:25 +04:00
|
|
|
|
|
|
|
if (network_up) {
|
1998-06-20 17:05:48 +04:00
|
|
|
msg_prompt(MSG_mntnetconfig, ans, ans, 5);
|
1997-10-20 10:13:25 +04:00
|
|
|
if (*ans == 'y') {
|
1997-11-02 11:20:40 +03:00
|
|
|
|
1998-02-07 13:28:02 +03:00
|
|
|
/* Write hostname to /etc/myname */
|
|
|
|
f = target_fopen("/etc/myname", "w");
|
|
|
|
if (f != 0) {
|
1998-06-20 17:05:48 +04:00
|
|
|
(void)fprintf(f, "%s\n", net_host);
|
1999-01-21 11:02:17 +03:00
|
|
|
if (scripting)
|
|
|
|
(void)fprintf(script, "echo \"%s\" >%s/etc/myname\n", net_host, target_prefix());
|
1998-06-20 17:05:48 +04:00
|
|
|
(void)fclose(f);
|
1998-02-07 13:28:02 +03:00
|
|
|
}
|
|
|
|
|
1997-11-03 02:43:11 +03:00
|
|
|
/* If not running in target, copy resolv.conf there. */
|
1997-12-26 04:58:44 +03:00
|
|
|
if (strcmp(net_namesvr, "") != 0)
|
|
|
|
dup_file_into_target("/etc/resolv.conf");
|
1997-11-03 02:43:11 +03:00
|
|
|
/*
|
|
|
|
* Add IPaddr/hostname to /etc/hosts.
|
|
|
|
* Be careful not to clobber any existing contents.
|
|
|
|
* Relies on ordered seach of /etc/hosts. XXX YP?
|
|
|
|
*/
|
1997-11-05 10:28:20 +03:00
|
|
|
f = target_fopen("/etc/hosts", "a");
|
|
|
|
if (f != 0) {
|
1998-06-20 17:05:48 +04:00
|
|
|
(void)fprintf(f, msg_string(MSG_etc_hosts),
|
|
|
|
net_ip, net_host, net_domain, net_host);
|
|
|
|
(void)fclose(f);
|
1999-01-21 11:02:17 +03:00
|
|
|
if (scripting) {
|
|
|
|
(void)fprintf(script, "cat <<EOF >>%s/etc/hosts\n", target_prefix());
|
|
|
|
(void)fprintf(script, msg_string(MSG_etc_hosts),
|
|
|
|
net_ip, net_host, net_domain, net_host);
|
|
|
|
(void)fprintf(script, "EOF\n");
|
|
|
|
}
|
1997-11-05 10:28:20 +03:00
|
|
|
}
|
1997-11-03 02:43:11 +03:00
|
|
|
|
|
|
|
/* Write IPaddr and netmask to /etc/ifconfig.if[0-9] */
|
1998-06-20 17:05:48 +04:00
|
|
|
snprintf(ifconfig_fn, STRSIZE, "/etc/ifconfig.%s",
|
|
|
|
net_dev);
|
1997-11-05 10:28:20 +03:00
|
|
|
f = target_fopen(ifconfig_fn, "w");
|
|
|
|
if (f != 0) {
|
1999-01-21 11:02:17 +03:00
|
|
|
if (*net_media != '\0') {
|
1997-12-26 04:58:44 +03:00
|
|
|
fprintf(f, "%s netmask %s media %s\n",
|
|
|
|
net_ip, net_mask, net_media);
|
1999-01-21 11:02:17 +03:00
|
|
|
if (scripting)
|
|
|
|
fprintf(script, "echo \"%s netmask %s media %s\">%s%s\n",
|
|
|
|
net_ip, net_mask, net_media, target_prefix(), ifconfig_fn);
|
|
|
|
} else {
|
1997-12-26 04:58:44 +03:00
|
|
|
fprintf(f, "%s netmask %s\n",
|
|
|
|
net_ip, net_mask);
|
1999-01-21 11:02:17 +03:00
|
|
|
if (scripting)
|
|
|
|
fprintf(script, "echo \"%s netmask %s\">%s%s\n",
|
|
|
|
net_ip, net_mask, target_prefix(), ifconfig_fn);
|
|
|
|
}
|
1997-11-05 10:28:20 +03:00
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
f = target_fopen("/etc/mygate", "w");
|
|
|
|
if (f != 0) {
|
|
|
|
fprintf(f, "%s\n", net_defroute);
|
1999-01-21 11:02:17 +03:00
|
|
|
if (scripting)
|
|
|
|
fprintf(script, "echo \"%s\" >%s/etc/mygate\n", net_defroute, target_prefix());
|
1997-11-05 10:28:20 +03:00
|
|
|
fclose(f);
|
|
|
|
}
|
1999-01-21 11:02:17 +03:00
|
|
|
fflush(NULL);
|
1997-10-20 10:13:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|