2004-06-06 01:18:59 +04:00
|
|
|
/* $NetBSD: net.c,v 1.102 2004/06/05 21:19:00 dsl 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
|
2003-07-18 13:42:59 +04:00
|
|
|
* 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
|
1997-09-27 03:02:53 +04:00
|
|
|
* 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)
|
2003-07-18 13:42:59 +04:00
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
1997-09-27 03:02:53 +04:00
|
|
|
* 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>
|
2000-09-26 17:26:02 +04:00
|
|
|
#include <sys/stat.h>
|
2000-01-04 11:33:51 +03:00
|
|
|
#ifdef INET6
|
|
|
|
#include <sys/sysctl.h>
|
2000-07-24 14:52:28 +04:00
|
|
|
#endif
|
2000-01-04 11:33:51 +03:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
2003-07-18 13:42:59 +04:00
|
|
|
#include <net/if.h>
|
2000-07-24 14:52:28 +04:00
|
|
|
#include <arpa/inet.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;
|
2003-07-18 13:42:59 +04:00
|
|
|
/* Access to network information */
|
|
|
|
static char *net_devices;
|
|
|
|
static char *net_up;
|
|
|
|
static char net_dev[STRSIZE];
|
|
|
|
static char net_domain[STRSIZE];
|
|
|
|
static char net_host[STRSIZE];
|
|
|
|
static char net_ip[STRSIZE];
|
|
|
|
static char net_mask[STRSIZE];
|
|
|
|
static char net_namesvr[STRSIZE];
|
|
|
|
static char net_defroute[STRSIZE];
|
|
|
|
static char net_media[STRSIZE];
|
|
|
|
static int net_dhcpconf;
|
|
|
|
#define DHCPCONF_IPADDR 0x01
|
|
|
|
#define DHCPCONF_NAMESVR 0x02
|
|
|
|
#define DHCPCONF_HOST 0x04
|
|
|
|
#define DHCPCONF_DOMAIN 0x08
|
|
|
|
#ifdef INET6
|
|
|
|
static char net_ip6[STRSIZE];
|
2003-07-20 02:07:36 +04:00
|
|
|
char net_namesvr6[STRSIZE];
|
2003-07-18 13:42:59 +04:00
|
|
|
static int net_ip6conf;
|
|
|
|
#define IP6CONF_AUTOHOST 0x01
|
|
|
|
#endif
|
|
|
|
|
1997-10-20 10:13:25 +04:00
|
|
|
|
1999-03-19 17:49:07 +03:00
|
|
|
/* URL encode unsafe characters. */
|
|
|
|
|
2000-12-22 13:12:12 +03:00
|
|
|
static char *url_encode (char *dst, const char *src, size_t len,
|
1999-06-19 03:26:40 +04:00
|
|
|
const char *safe_chars,
|
2000-12-22 13:12:12 +03:00
|
|
|
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. */
|
|
|
|
|
2000-12-22 13:12:12 +03:00
|
|
|
static void get_ifinterface_info (void);
|
1998-06-20 17:05:48 +04:00
|
|
|
|
1999-06-24 02:55:14 +04:00
|
|
|
static void write_etc_hosts(FILE *f);
|
|
|
|
|
2000-06-19 03:50:02 +04:00
|
|
|
#define DHCLIENT_EX "/sbin/dhclient"
|
|
|
|
#include <signal.h>
|
2003-07-18 13:42:59 +04:00
|
|
|
static int config_dhcp(char *);
|
2003-08-06 17:56:58 +04:00
|
|
|
static void get_command_out(char *, size_t, int, const char *, const char *);
|
|
|
|
static void get_dhcp_value(char *, size_t, const char *);
|
2000-06-19 03:50:02 +04:00
|
|
|
|
2000-01-05 04:50:45 +03:00
|
|
|
#ifdef INET6
|
2000-12-22 13:12:12 +03:00
|
|
|
static int is_v6kernel (void);
|
|
|
|
static void init_v6kernel (int);
|
|
|
|
static int get_v6wait (void);
|
2000-01-05 04:50:45 +03:00
|
|
|
#endif
|
1999-06-24 02:55:14 +04:00
|
|
|
|
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.
|
|
|
|
*
|
1999-07-03 13:02:23 +04:00
|
|
|
* This url_encode() function does not operate on complete URLs, it
|
|
|
|
* operates on strings that make up parts of URLs. For example, in a
|
|
|
|
* URL like "ftp://username:password@host/path", the username, password,
|
|
|
|
* host and path should each be encoded separately before they are
|
|
|
|
* joined together with the punctuation characters.
|
|
|
|
*
|
|
|
|
* In most ordinary use, the path portion of a URL does not start with
|
|
|
|
* a slash; the slash is a separator between the host portion and the
|
|
|
|
* path portion, and is dealt with by software outside the url_encode()
|
|
|
|
* function. However, it is valid for url_encode() to be passed a
|
|
|
|
* string that does begin with a slash. For example, the string might
|
|
|
|
* represent a password, or a path part of a URL that the user really
|
|
|
|
* does want to begin with a slash.
|
|
|
|
*
|
1999-03-19 17:49:07 +03:00
|
|
|
* 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
|
|
|
|
*
|
1999-07-03 13:02:23 +04:00
|
|
|
* encode_leading_slash is a flag that determines whether or not to
|
|
|
|
* encode a leading slash in a string. If this flag is set, and if the
|
|
|
|
* first character in the src string is '/', then the leading slash will
|
|
|
|
* be encoded (as "%2F"), even if '/' is one of the characters in the
|
|
|
|
* safe_chars string. Note that only the first character of the src
|
|
|
|
* string is affected by this flag, and that leading slashes are never
|
|
|
|
* deleted, but either retained unchanged or encoded.
|
|
|
|
*
|
1999-03-19 17:49:07 +03:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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;
|
2003-08-06 17:56:58 +04:00
|
|
|
char *ep = dst + len;
|
2004-06-06 01:18:59 +04:00
|
|
|
int ch;
|
1999-06-19 03:26:40 +04:00
|
|
|
|
2004-06-06 01:18:59 +04:00
|
|
|
for (; ep - p > 1; src++) {
|
|
|
|
ch = *src & 0xff;
|
|
|
|
if (ch == 0)
|
|
|
|
break;
|
1999-06-19 03:26:40 +04:00
|
|
|
if (safe_chars != NULL &&
|
2004-06-06 01:18:59 +04:00
|
|
|
(ch != '/' || !encode_leading_slash) &&
|
|
|
|
(isalnum(ch) || strchr(safe_chars, ch))) {
|
|
|
|
*p++ = ch;
|
1999-03-19 17:49:07 +03:00
|
|
|
} else {
|
|
|
|
/* encode this char */
|
2003-08-06 17:56:58 +04:00
|
|
|
if (ep - p < 3)
|
1999-03-19 17:49:07 +03:00
|
|
|
break;
|
2004-06-06 01:18:59 +04:00
|
|
|
snprintf(p, ep - p, "%%%02X", ch);
|
1999-03-19 17:49:07 +03:00
|
|
|
p += 3;
|
|
|
|
}
|
2004-06-06 01:18:59 +04:00
|
|
|
encode_leading_slash = 0;
|
1999-03-19 17:49:07 +03:00
|
|
|
}
|
1999-06-19 03:26:40 +04:00
|
|
|
done:
|
1999-03-19 17:49:07 +03:00
|
|
|
*p = '\0';
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
1999-06-20 11:55:00 +04:00
|
|
|
static const char *ignored_if_names[] = {
|
|
|
|
"eon", /* netiso */
|
|
|
|
"gre", /* net */
|
|
|
|
"ipip", /* netinet */
|
1999-09-05 20:33:03 +04:00
|
|
|
"gif", /* netinet6 */
|
|
|
|
"faith", /* netinet6 */
|
1999-06-20 11:55:00 +04:00
|
|
|
"lo", /* net */
|
|
|
|
#if 0
|
|
|
|
"mdecap", /* netinet -- never in IF list (?) XXX */
|
|
|
|
#endif
|
|
|
|
"nsip", /* netns */
|
|
|
|
"ppp", /* net */
|
|
|
|
"sl", /* net */
|
|
|
|
"strip", /* net */
|
|
|
|
"tun", /* net */
|
|
|
|
/* XXX others? */
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
static void
|
2003-06-16 23:42:13 +04:00
|
|
|
get_ifconfig_info(void)
|
1997-09-27 03:02:53 +04:00
|
|
|
{
|
|
|
|
char *textbuf;
|
2003-07-18 13:42:59 +04:00
|
|
|
char *t, *nt;
|
1999-06-20 11:55:00 +04:00
|
|
|
const char **ignore;
|
2003-01-10 23:00:27 +03:00
|
|
|
int textsize;
|
2003-07-18 13:42:59 +04:00
|
|
|
ulong fl;
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
free(net_devices);
|
|
|
|
net_devices = NULL;
|
|
|
|
free(net_up);
|
|
|
|
net_up = NULL;
|
1997-09-27 03:02:53 +04:00
|
|
|
|
|
|
|
/* Get ifconfig information */
|
2003-07-18 13:42:59 +04:00
|
|
|
|
|
|
|
textsize = collect(T_OUTPUT, &textbuf, "/sbin/ifconfig -a 2>/dev/null");
|
1997-09-27 03:02:53 +04:00
|
|
|
if (textsize < 0) {
|
1999-01-21 11:02:17 +03:00
|
|
|
if (logging)
|
2002-12-05 04:17:15 +03:00
|
|
|
(void)fprintf(logfp,
|
|
|
|
"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
|
|
|
}
|
1997-10-07 08:01:29 +04:00
|
|
|
|
2003-07-18 13:42:59 +04:00
|
|
|
for (t = textbuf; t != NULL && *t != 0; t = nt) {
|
|
|
|
/* find entry for next interface */
|
|
|
|
for (nt = t; (nt = strchr(nt, '\n')); ) {
|
|
|
|
if (*++nt != '\t')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (memcmp(t, "lo0:", 4) == 0)
|
|
|
|
/* completely ignore loopback interface */
|
|
|
|
continue;
|
|
|
|
cp = strchr(t, '=');
|
|
|
|
if (cp == NULL)
|
|
|
|
break;
|
|
|
|
/* get interface flags */
|
|
|
|
fl = strtoul(cp + 1, &cp, 16);
|
|
|
|
if (*cp != '<')
|
|
|
|
break;
|
|
|
|
if (fl & IFF_UP) {
|
|
|
|
/* This interface might be connected to the server */
|
|
|
|
cp = strchr(t, ':');
|
|
|
|
if (cp == NULL)
|
|
|
|
break;
|
|
|
|
asprintf(&cp, "%s%.*s ",
|
|
|
|
net_up ? net_up : "", (int)(cp - t), t);
|
|
|
|
free(net_up);
|
|
|
|
net_up = cp;
|
|
|
|
}
|
|
|
|
|
1999-06-20 11:55:00 +04:00
|
|
|
for (ignore = ignored_if_names; *ignore != NULL; ignore++) {
|
2003-01-10 23:00:27 +03:00
|
|
|
size_t len = strlen(*ignore);
|
1999-06-20 11:55:00 +04:00
|
|
|
if (strncmp(t, *ignore, len) == 0 &&
|
|
|
|
isdigit((unsigned char)t[len]))
|
2003-07-18 13:42:59 +04:00
|
|
|
break;
|
1999-06-20 11:55:00 +04:00
|
|
|
}
|
2003-07-18 13:42:59 +04:00
|
|
|
if (*ignore != NULL)
|
|
|
|
continue;
|
1999-06-20 11:55:00 +04:00
|
|
|
|
2003-07-18 13:42:59 +04:00
|
|
|
cp = strchr(t, ':');
|
|
|
|
if (cp == NULL)
|
|
|
|
break;
|
|
|
|
asprintf(&cp, "%s%.*s ",
|
|
|
|
net_devices ? net_devices : "", (int)(cp - t), t);
|
|
|
|
free(net_devices);
|
|
|
|
net_devices = cp;
|
1999-06-20 11:55:00 +04:00
|
|
|
}
|
|
|
|
free(textbuf);
|
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
|
2003-06-16 23:42:13 +04:00
|
|
|
get_ifinterface_info(void)
|
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];
|
2000-06-19 03:50:02 +04:00
|
|
|
char *dot;
|
1997-11-22 17:16:55 +03:00
|
|
|
|
|
|
|
/* First look to see if the selected interface is already configured. */
|
2000-01-04 11:33:51 +03:00
|
|
|
textsize = collect(T_OUTPUT, &textbuf,
|
|
|
|
"/sbin/ifconfig %s inet 2>/dev/null", 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)
|
2003-08-06 17:56:58 +04:00
|
|
|
strlcpy(net_ip, t, sizeof(net_ip));
|
2003-07-18 13:42:59 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (strcmp(t, "netmask") == 0) {
|
1997-11-22 17:16:55 +03:00
|
|
|
t = strtok(NULL, " \t\n");
|
|
|
|
if (strcmp(t, "0x0") != 0)
|
2003-08-06 17:56:58 +04:00
|
|
|
strlcpy(net_mask, t, sizeof(net_mask));
|
2003-07-18 13:42:59 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
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)
|
2003-08-06 17:56:58 +04:00
|
|
|
strlcpy(net_media, t,
|
|
|
|
sizeof(net_media));
|
1997-12-26 04:58:44 +03:00
|
|
|
}
|
1997-11-22 17:16:55 +03:00
|
|
|
}
|
|
|
|
}
|
2003-07-18 13:42:59 +04:00
|
|
|
free(textbuf);
|
2000-01-04 11:33:51 +03:00
|
|
|
#ifdef INET6
|
|
|
|
textsize = collect(T_OUTPUT, &textbuf,
|
|
|
|
"/sbin/ifconfig %s inet6 2>/dev/null", net_dev);
|
|
|
|
if (textsize >= 0) {
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
(void)strtok(textbuf, "\n"); /* ignore first line */
|
|
|
|
while ((t = strtok(NULL, "\n")) != NULL) {
|
|
|
|
if (strncmp(t, "\tinet6 ", 7) != 0)
|
|
|
|
continue;
|
|
|
|
t += 7;
|
|
|
|
if (strstr(t, "tentative") || strstr(t, "duplicated"))
|
|
|
|
continue;
|
|
|
|
if (strncmp(t, "fe80:", 5) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
p = t;
|
|
|
|
while (*p && *p != ' ' && *p != '\n')
|
|
|
|
p++;
|
|
|
|
*p = '\0';
|
2003-08-06 17:56:58 +04:00
|
|
|
strlcpy(net_ip6, t, sizeof(net_ip6));
|
2000-01-04 11:33:51 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-07-18 13:42:59 +04:00
|
|
|
free(textbuf);
|
2000-01-04 11:33:51 +03:00
|
|
|
#endif
|
1997-11-22 17:16:55 +03:00
|
|
|
|
|
|
|
/* Check host (and domain?) name */
|
2004-06-06 01:18:59 +04:00
|
|
|
if (gethostname(hostname, sizeof(hostname)) == 0 && hostname[0] != 0) {
|
2003-07-18 13:42:59 +04:00
|
|
|
hostname[sizeof(hostname) - 1] = 0;
|
2000-06-19 03:50:02 +04:00
|
|
|
/* check for a . */
|
|
|
|
dot = strchr(hostname, '.');
|
2003-07-18 13:42:59 +04:00
|
|
|
if (dot == NULL) {
|
2000-06-19 03:50:02 +04:00
|
|
|
/* if not found its just a host, punt on domain */
|
2003-07-18 13:42:59 +04:00
|
|
|
strlcpy(net_host, hostname, sizeof net_host);
|
2000-06-19 03:50:02 +04:00
|
|
|
} else {
|
|
|
|
/* split hostname into host/domain parts */
|
2003-07-18 13:42:59 +04:00
|
|
|
*dot++ = 0;
|
|
|
|
strlcpy(net_host, hostname, sizeof net_host);
|
|
|
|
strlcpy(net_domain, dot, sizeof net_domain);
|
2000-06-19 03:50:02 +04:00
|
|
|
}
|
1998-07-06 10:56:06 +04:00
|
|
|
}
|
1997-11-22 17:16:55 +03:00
|
|
|
}
|
|
|
|
|
2003-11-04 04:53:28 +03:00
|
|
|
/*
|
|
|
|
* recombine name parts split in get_ifinterface_info and config_network
|
|
|
|
* (common code moved here from write_etc_hosts)
|
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
recombine_host_domain(void)
|
|
|
|
{
|
|
|
|
static char recombined[MAXHOSTNAMELEN + 1];
|
|
|
|
int l = strlen(net_host) - strlen(net_domain);
|
|
|
|
|
|
|
|
strlcpy(recombined, net_host, sizeof(recombined));
|
|
|
|
|
|
|
|
if (l <= 0 ||
|
|
|
|
net_host[l - 1] != '.' ||
|
|
|
|
strcasecmp(net_domain, net_host + l) != 0) {
|
|
|
|
/* net_host isn't an FQDN. */
|
|
|
|
strlcat(recombined, ".", sizeof(recombined));
|
|
|
|
strlcat(recombined, net_domain, sizeof(recombined));
|
|
|
|
}
|
|
|
|
return recombined;
|
|
|
|
}
|
|
|
|
|
2000-01-04 11:33:51 +03:00
|
|
|
#ifdef INET6
|
|
|
|
static int
|
2003-06-16 23:42:13 +04:00
|
|
|
is_v6kernel(void)
|
2000-01-04 11:33:51 +03:00
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = socket(PF_INET6, SOCK_DGRAM, 0);
|
|
|
|
if (s < 0)
|
|
|
|
return 0;
|
2003-07-18 13:42:59 +04:00
|
|
|
close(s);
|
|
|
|
return 1;
|
2000-01-04 11:33:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* initialize as v6 client.
|
|
|
|
* we are sure that we will never become router with boot floppy :-)
|
|
|
|
* (include and use sysctl(8) if you are willing to)
|
|
|
|
*/
|
|
|
|
static void
|
2003-06-16 23:42:13 +04:00
|
|
|
init_v6kernel(int autoconf)
|
2000-01-04 11:33:51 +03:00
|
|
|
{
|
|
|
|
int v;
|
|
|
|
int mib[4] = {CTL_NET, PF_INET6, IPPROTO_IPV6, 0};
|
|
|
|
|
|
|
|
mib[3] = IPV6CTL_FORWARDING;
|
|
|
|
v = 0;
|
|
|
|
if (sysctl(mib, 4, NULL, NULL, (void *)&v, sizeof(v)) < 0)
|
|
|
|
; /* warn("sysctl(net.inet6.ip6.fowarding"); */
|
|
|
|
|
|
|
|
mib[3] = IPV6CTL_ACCEPT_RTADV;
|
|
|
|
v = autoconf ? 1 : 0;
|
|
|
|
if (sysctl(mib, 4, NULL, NULL, (void *)&v, sizeof(v)) < 0)
|
|
|
|
; /* warn("sysctl(net.inet6.ip6.accept_rtadv"); */
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2003-06-16 23:42:13 +04:00
|
|
|
get_v6wait(void)
|
2000-01-04 11:33:51 +03:00
|
|
|
{
|
2003-08-10 12:28:09 +04:00
|
|
|
size_t len = sizeof(int);
|
2000-01-04 11:33:51 +03:00
|
|
|
int v;
|
|
|
|
int mib[4] = {CTL_NET, PF_INET6, IPPROTO_IPV6, IPV6CTL_DAD_COUNT};
|
|
|
|
|
|
|
|
len = sizeof(v);
|
2003-08-10 12:28:09 +04:00
|
|
|
if (sysctl(mib, 4, (void *)&v, &len, NULL, 0) < 0) {
|
2000-01-04 11:33:51 +03:00
|
|
|
/* warn("sysctl(net.inet6.ip6.dadcount)"); */
|
|
|
|
return 1; /* guess */
|
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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
|
2003-06-16 23:42:13 +04:00
|
|
|
config_network(void)
|
|
|
|
{
|
|
|
|
char *tp;
|
2003-07-18 13:42:59 +04:00
|
|
|
char *defname;
|
|
|
|
const char *prompt;
|
1997-09-27 03:02:53 +04:00
|
|
|
int octet0;
|
2003-01-10 23:00:27 +03:00
|
|
|
int pass, dhcp_config;
|
2003-07-18 13:42:59 +04:00
|
|
|
int l;
|
2004-06-06 01:18:59 +04:00
|
|
|
char dhcp_host[STRSIZE];
|
2003-01-10 23:00:27 +03:00
|
|
|
#ifdef INET6
|
|
|
|
int v6config = 1;
|
|
|
|
#endif
|
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
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
get_ifconfig_info();
|
1999-06-22 22:47:07 +04:00
|
|
|
|
2003-07-28 01:09:57 +04:00
|
|
|
if (net_up != NULL) {
|
2003-07-18 13:42:59 +04:00
|
|
|
/* active interfaces found */
|
|
|
|
msg_display(MSG_netup, net_up);
|
|
|
|
process_menu(MENU_yesno, NULL);
|
|
|
|
if (yesno)
|
|
|
|
return 1;
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
2003-07-28 01:09:57 +04:00
|
|
|
if (net_devices == NULL) {
|
|
|
|
/* No network interfaces found! */
|
|
|
|
msg_display(MSG_nonet);
|
|
|
|
process_menu(MENU_ok, NULL);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
network_up = 1;
|
|
|
|
|
2003-07-18 13:42:59 +04:00
|
|
|
again:
|
|
|
|
tp = strchr(net_devices, ' ');
|
|
|
|
asprintf(&defname, "%.*s", (int)(tp - net_devices), net_devices);
|
|
|
|
for (prompt = MSG_asknetdev;; prompt = MSG_badnet) {
|
|
|
|
msg_prompt(prompt, defname, net_dev, sizeof net_dev - 1,
|
|
|
|
net_devices);
|
|
|
|
l = strlen(net_dev);
|
|
|
|
net_dev[l] = ' ';
|
|
|
|
net_dev[l + 1] = 0;
|
|
|
|
tp = strstr(net_devices, net_dev);
|
|
|
|
if (tp == NULL)
|
|
|
|
continue;
|
|
|
|
if (tp != net_devices && tp[-1] != ' ')
|
|
|
|
continue;
|
|
|
|
net_dev[l] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free(defname);
|
2000-01-04 11:33:51 +03:00
|
|
|
|
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();
|
2003-11-04 04:53:28 +03:00
|
|
|
pass = net_mask[0] == '\0' ? 0 : 1;
|
2000-07-24 14:52:28 +04:00
|
|
|
|
|
|
|
/* domain and host */
|
|
|
|
msg_display(MSG_netinfo);
|
|
|
|
|
|
|
|
/* ethernet medium */
|
2003-11-04 04:53:28 +03:00
|
|
|
if (net_media[0] != '\0')
|
2003-07-18 13:42:59 +04:00
|
|
|
msg_prompt_add(MSG_net_media, net_media, net_media,
|
|
|
|
sizeof net_media);
|
2000-07-24 14:52:28 +04:00
|
|
|
|
|
|
|
/* try a dhcp configuration */
|
|
|
|
dhcp_config = config_dhcp(net_dev);
|
2000-07-24 10:05:51 +04:00
|
|
|
if (dhcp_config) {
|
2003-02-11 14:29:35 +03:00
|
|
|
/* Get newly configured data off interface. */
|
|
|
|
get_ifinterface_info();
|
|
|
|
|
2000-07-24 14:52:28 +04:00
|
|
|
net_dhcpconf |= DHCPCONF_IPADDR;
|
|
|
|
|
2000-06-19 03:50:02 +04:00
|
|
|
/* run route show and extract data */
|
2003-08-06 17:56:58 +04:00
|
|
|
get_command_out(net_defroute, sizeof(net_defroute), AF_INET,
|
2000-07-24 14:52:28 +04:00
|
|
|
"/sbin/route -n show -inet 2>/dev/null", "default");
|
|
|
|
|
2000-06-19 03:50:02 +04:00
|
|
|
/* pull nameserver info out of /etc/resolv.conf */
|
2003-08-06 17:56:58 +04:00
|
|
|
get_command_out(net_namesvr, sizeof(net_namesvr), AF_INET,
|
2000-07-24 14:52:28 +04:00
|
|
|
"cat /etc/resolv.conf 2> /dev/null", "nameserver");
|
2003-11-04 04:53:28 +03:00
|
|
|
if (net_namesvr[0] != '\0')
|
2000-07-24 14:52:28 +04:00
|
|
|
net_dhcpconf |= DHCPCONF_NAMESVR;
|
2000-06-19 03:50:02 +04:00
|
|
|
|
|
|
|
/* pull domainname out of leases file */
|
2003-08-06 17:56:58 +04:00
|
|
|
get_dhcp_value(net_domain, sizeof(net_domain), "domain-name");
|
2003-11-04 04:53:28 +03:00
|
|
|
if (net_domain[0] != '\0')
|
2000-07-24 14:52:28 +04:00
|
|
|
net_dhcpconf |= DHCPCONF_DOMAIN;
|
2000-06-19 03:50:02 +04:00
|
|
|
|
2000-07-24 14:52:28 +04:00
|
|
|
/* pull hostname out of leases file */
|
2004-06-06 01:18:59 +04:00
|
|
|
dhcp_host[0] = 0;
|
|
|
|
get_dhcp_value(dhcp_host, sizeof(net_host), "hostname");
|
|
|
|
if (dhcp_host[0] != '\0') {
|
2000-07-24 14:52:28 +04:00
|
|
|
net_dhcpconf |= DHCPCONF_HOST;
|
2004-06-06 01:18:59 +04:00
|
|
|
strlcpy(net_host, dhcp_host, sizeof net_host);
|
|
|
|
}
|
2000-06-19 03:50:02 +04:00
|
|
|
}
|
2000-01-04 11:33:51 +03:00
|
|
|
|
2003-07-18 13:42:59 +04:00
|
|
|
msg_prompt_add(MSG_net_domain, net_domain, net_domain,
|
|
|
|
sizeof net_domain);
|
|
|
|
msg_prompt_add(MSG_net_host, net_host, net_host, sizeof net_host);
|
2000-01-04 11:33:51 +03:00
|
|
|
|
2000-07-24 14:52:28 +04:00
|
|
|
if (!dhcp_config) {
|
|
|
|
/* Manually configure IPv4 */
|
2003-07-18 13:42:59 +04:00
|
|
|
msg_prompt_add(MSG_net_ip, net_ip, net_ip, sizeof net_ip);
|
2000-07-24 14:52:28 +04:00
|
|
|
octet0 = atoi(net_ip);
|
|
|
|
if (!pass) {
|
|
|
|
if (0 <= octet0 && octet0 <= 127)
|
2003-08-06 17:56:58 +04:00
|
|
|
strlcpy(net_mask, "0xff000000",
|
|
|
|
sizeof(net_mask));
|
2000-07-24 14:52:28 +04:00
|
|
|
else if (128 <= octet0 && octet0 <= 191)
|
2003-08-06 17:56:58 +04:00
|
|
|
strlcpy(net_mask, "0xffff0000",
|
|
|
|
sizeof(net_mask));
|
2000-07-24 14:52:28 +04:00
|
|
|
else if (192 <= octet0 && octet0 <= 223)
|
2003-08-06 17:56:58 +04:00
|
|
|
strlcpy(net_mask, "0xffffff00",
|
|
|
|
sizeof(net_mask));
|
2000-07-24 14:52:28 +04:00
|
|
|
}
|
2003-07-18 13:42:59 +04:00
|
|
|
msg_prompt_add(MSG_net_mask, net_mask, net_mask,
|
|
|
|
sizeof net_mask);
|
2000-07-24 14:52:28 +04:00
|
|
|
msg_prompt_add(MSG_net_defroute, net_defroute, net_defroute,
|
2003-07-18 13:42:59 +04:00
|
|
|
sizeof net_defroute);
|
2004-06-06 01:18:59 +04:00
|
|
|
}
|
|
|
|
if (!dhcp_config || net_namesvr[0] == 0)
|
2000-07-24 14:52:28 +04:00
|
|
|
msg_prompt_add(MSG_net_namesrv, net_namesvr, net_namesvr,
|
2003-07-18 13:42:59 +04:00
|
|
|
sizeof net_namesvr);
|
2000-01-04 11:33:51 +03:00
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
/* IPv6 autoconfiguration */
|
2000-07-24 10:05:51 +04:00
|
|
|
if (!is_v6kernel())
|
2000-01-04 11:33:51 +03:00
|
|
|
v6config = 0;
|
2002-05-24 11:58:23 +04:00
|
|
|
else if (v6config) {
|
2004-06-06 01:18:59 +04:00
|
|
|
process_menu(MENU_yesno, deconst(MSG_Perform_IPv6_autoconfiguration));
|
2000-01-04 11:33:51 +03:00
|
|
|
v6config = yesno ? 1 : 0;
|
2001-04-15 15:08:51 +04:00
|
|
|
net_ip6conf |= yesno ? IP6CONF_AUTOHOST : 0;
|
2000-01-04 11:33:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (v6config) {
|
2003-06-03 15:54:48 +04:00
|
|
|
process_menu(MENU_namesrv6, NULL);
|
1997-09-27 03:02:53 +04:00
|
|
|
if (!yesno)
|
2000-01-04 11:33:51 +03:00
|
|
|
msg_prompt_add(MSG_net_namesrv6, net_namesvr6,
|
2003-07-18 13:42:59 +04:00
|
|
|
net_namesvr6, sizeof net_namesvr6);
|
2000-01-04 11:33:51 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* confirm the setting */
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
msg_display(MSG_netok, net_domain, net_host, net_dev,
|
2000-01-04 11:33:51 +03:00
|
|
|
*net_ip == '\0' ? "<none>" : net_ip,
|
|
|
|
*net_mask == '\0' ? "<none>" : net_mask,
|
|
|
|
*net_namesvr == '\0' ? "<none>" : net_namesvr,
|
|
|
|
*net_defroute == '\0' ? "<none>" : net_defroute,
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
*net_media == '\0' ? "<default>" : net_media);
|
2000-01-04 11:33:51 +03:00
|
|
|
#ifdef INET6
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
msg_display_add(MSG_netokv6,
|
2000-01-04 11:33:51 +03:00
|
|
|
!is_v6kernel() ? "<not supported>" :
|
|
|
|
(v6config ? "yes" : "no"),
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
*net_namesvr6 == '\0' ? "<none>" : net_namesvr6);
|
2000-01-04 11:33:51 +03:00
|
|
|
#endif
|
2004-06-06 01:18:59 +04:00
|
|
|
process_menu(MENU_yesno, deconst(MSG_netok_ok));
|
2000-01-04 11:33:51 +03:00
|
|
|
if (!yesno)
|
|
|
|
msg_display(MSG_netagain);
|
|
|
|
pass++;
|
|
|
|
if (!yesno)
|
|
|
|
goto again;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we may want to perform checks against inconsistent configuration,
|
|
|
|
* like IPv4 DNS server without IPv4 configuration.
|
|
|
|
*/
|
1997-09-27 03:02:53 +04:00
|
|
|
|
1997-11-22 16:52:45 +03:00
|
|
|
/* Create /etc/resolv.conf if a nameserver was given */
|
2003-11-04 04:53:28 +03:00
|
|
|
if (net_namesvr[0] != '\0'
|
2000-01-04 11:33:51 +03:00
|
|
|
#ifdef INET6
|
2003-11-04 04:53:28 +03:00
|
|
|
|| net_namesvr6[0] != '\0'
|
2000-01-04 11:33:51 +03:00
|
|
|
#endif
|
|
|
|
) {
|
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)
|
2002-12-05 04:17:15 +03:00
|
|
|
(void)fprintf(logfp,
|
|
|
|
"%s", msg_string(MSG_resolv));
|
1997-11-22 16:52:45 +03:00
|
|
|
(void)fprintf(stderr, "%s", msg_string(MSG_resolv));
|
|
|
|
exit(1);
|
|
|
|
}
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
scripting_fprintf(NULL, "cat <<EOF >/etc/resolv.conf\n");
|
1997-11-22 16:52:45 +03:00
|
|
|
time(&now);
|
|
|
|
/* NB: ctime() returns a string ending in '\n' */
|
2003-07-18 13:42:59 +04:00
|
|
|
scripting_fprintf(f, ";\n; BIND data file\n; %s %s;\n",
|
|
|
|
"Created by NetBSD sysinst on", ctime(&now));
|
2003-11-04 19:27:22 +03:00
|
|
|
if (net_domain[0] != '\0')
|
|
|
|
scripting_fprintf(f, "search %s\n", net_domain);
|
2003-11-04 04:53:28 +03:00
|
|
|
if (net_namesvr[0] != '\0')
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
scripting_fprintf(f, "nameserver %s\n", net_namesvr);
|
2000-01-04 11:33:51 +03:00
|
|
|
#ifdef INET6
|
2003-11-04 04:53:28 +03:00
|
|
|
if (net_namesvr6[0] != '\0')
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
scripting_fprintf(f, "nameserver %s\n", net_namesvr6);
|
2000-01-04 11:33:51 +03:00
|
|
|
#endif
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
scripting_fprintf(NULL, "EOF\n");
|
1999-01-21 11:02:17 +03:00
|
|
|
fflush(NULL);
|
1998-06-20 17:05:48 +04:00
|
|
|
fclose(f);
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
run_program(0, "/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.
|
2003-07-18 13:42:59 +04:00
|
|
|
* Our UI gives no way to set an option back to null-string if it
|
1998-11-09 10:56:11 +03:00
|
|
|
* gets accidentally set.
|
|
|
|
* 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')
|
2003-11-30 17:36:43 +03:00
|
|
|
run_program(0, "/sbin/ifconfig %s media %s",
|
2000-01-04 11:33:51 +03:00
|
|
|
net_dev, net_media);
|
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
if (v6config) {
|
|
|
|
init_v6kernel(1);
|
2003-11-30 17:36:43 +03:00
|
|
|
run_program(0, "/sbin/ifconfig %s up", net_dev);
|
2000-01-04 11:33:51 +03:00
|
|
|
sleep(get_v6wait() + 1);
|
2003-11-30 17:36:43 +03:00
|
|
|
run_program(RUN_DISPLAY, "/sbin/rtsol -D %s", net_dev);
|
2000-01-04 11:33:51 +03:00
|
|
|
sleep(get_v6wait() + 1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-11-04 04:53:28 +03:00
|
|
|
if (net_ip[0] != '\0') {
|
|
|
|
if (net_mask[0] != '\0') {
|
2003-11-30 17:36:43 +03:00
|
|
|
run_program(0, "/sbin/ifconfig %s inet %s netmask %s",
|
2000-01-04 11:33:51 +03:00
|
|
|
net_dev, net_ip, net_mask);
|
|
|
|
} else {
|
2003-11-30 17:36:43 +03:00
|
|
|
run_program(0, "/sbin/ifconfig %s inet %s",
|
|
|
|
net_dev, net_ip);
|
2000-01-04 11:33:51 +03:00
|
|
|
}
|
|
|
|
}
|
1997-10-01 09:04:24 +04:00
|
|
|
|
1998-02-07 13:28:02 +03:00
|
|
|
/* Set host name */
|
2003-11-04 04:53:28 +03:00
|
|
|
if (net_host[0] != '\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 */
|
2003-11-04 04:53:28 +03:00
|
|
|
if (net_defroute[0] != '\0') {
|
2004-05-16 01:48:09 +04:00
|
|
|
run_program(RUN_DISPLAY | RUN_PROGRESS,
|
|
|
|
"/sbin/route -n flush -inet");
|
|
|
|
run_program(RUN_DISPLAY | RUN_PROGRESS,
|
|
|
|
"/sbin/route -n add default %s", net_defroute);
|
1997-11-22 16:52:45 +03:00
|
|
|
}
|
|
|
|
|
2001-06-07 16:34:55 +04:00
|
|
|
/*
|
|
|
|
* wait a couple of seconds for the interface to go live.
|
|
|
|
*/
|
2003-07-22 12:30:10 +04:00
|
|
|
msg_display_add(MSG_wait_network);
|
2001-06-07 16:34:55 +04:00
|
|
|
sleep(5);
|
|
|
|
|
1999-01-21 11:02:17 +03:00
|
|
|
/*
|
|
|
|
* ping should be verbose, so users can see the cause
|
|
|
|
* of a network failure.
|
|
|
|
*/
|
|
|
|
|
2000-01-04 11:33:51 +03:00
|
|
|
#ifdef INET6
|
|
|
|
if (v6config && network_up) {
|
2003-11-30 17:36:43 +03:00
|
|
|
network_up = !run_program(RUN_DISPLAY | RUN_PROGRESS,
|
2000-07-02 19:07:52 +04:00
|
|
|
"/sbin/ping6 -v -c 3 -n -I %s ff02::2", net_dev);
|
2000-01-04 11:33:51 +03:00
|
|
|
|
2003-11-04 04:53:28 +03:00
|
|
|
if (net_namesvr6[0] != '\0')
|
2003-11-30 17:36:43 +03:00
|
|
|
network_up = !run_program(RUN_DISPLAY | RUN_PROGRESS,
|
2000-01-04 11:33:51 +03:00
|
|
|
"/sbin/ping6 -v -c 3 -n %s", net_namesvr6);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-11-04 04:53:28 +03:00
|
|
|
if (net_namesvr[0] != '\0' && network_up)
|
2003-11-30 17:36:43 +03:00
|
|
|
network_up = !run_program(RUN_DISPLAY | RUN_PROGRESS,
|
2003-07-18 13:42:59 +04:00
|
|
|
"/sbin/ping -v -c 5 -w 5 -o -n %s", net_namesvr);
|
1997-11-22 16:52:45 +03:00
|
|
|
|
2003-11-04 04:53:28 +03:00
|
|
|
if (net_defroute[0] != '\0' && network_up)
|
2003-11-30 17:36:43 +03:00
|
|
|
network_up = !run_program(RUN_DISPLAY | RUN_PROGRESS,
|
2003-07-18 13:42:59 +04:00
|
|
|
"/sbin/ping -v -c 5 -w 5 -o -n %s", 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
|
2003-06-16 23:42:13 +04:00
|
|
|
get_via_ftp(void)
|
2003-07-18 13:42:59 +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_dir_encoded[STRSIZE];
|
1997-09-27 04:09:22 +04:00
|
|
|
int ret;
|
2004-06-06 01:18:59 +04:00
|
|
|
int got_one = 0;
|
|
|
|
char *cp;
|
|
|
|
const char *ftp_opt;
|
|
|
|
int cwd;
|
1997-09-27 03:02:53 +04:00
|
|
|
|
1999-06-22 22:47:07 +04:00
|
|
|
while ((ret = config_network()) <= 0) {
|
|
|
|
if (ret < 0)
|
|
|
|
return (-1);
|
1998-06-20 17:05:48 +04:00
|
|
|
msg_display(MSG_netnotup);
|
2003-06-03 15:54:48 +04:00
|
|
|
process_menu(MENU_yesno, NULL);
|
2002-02-04 17:35:10 +03:00
|
|
|
if (!yesno) {
|
|
|
|
msg_display(MSG_netnotup_continueanyway);
|
2003-06-03 15:54:48 +04:00
|
|
|
process_menu(MENU_yesno, NULL);
|
2002-02-04 17:35:10 +03:00
|
|
|
if (!yesno)
|
|
|
|
return 0;
|
|
|
|
network_up = 1;
|
|
|
|
}
|
1997-10-01 09:04:24 +04:00
|
|
|
}
|
1997-10-29 04:06:42 +03:00
|
|
|
|
2004-06-06 01:18:59 +04:00
|
|
|
cwd = open(".", O_RDONLY);
|
1998-06-20 17:05:48 +04:00
|
|
|
cd_dist_dir("ftp");
|
1997-10-29 04:06:42 +03:00
|
|
|
|
2003-06-03 15:54:48 +04:00
|
|
|
process_menu(MENU_ftpsource, NULL);
|
- 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;
|
2003-06-12 01:35:35 +04:00
|
|
|
while (list->desc) {
|
|
|
|
if (list->name == NULL || (sets_selected & list->set) == 0) {
|
1997-10-29 04:06:42 +03:00
|
|
|
list++;
|
|
|
|
continue;
|
|
|
|
}
|
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
|
|
|
*/
|
2004-06-06 01:18:59 +04:00
|
|
|
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;
|
1999-03-19 17:49:07 +03:00
|
|
|
}
|
2004-06-06 01:18:59 +04:00
|
|
|
|
|
|
|
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 {
|
1997-09-27 04:09:22 +04:00
|
|
|
/* Error getting the file. Bad host name ... ? */
|
2004-06-06 01:18:59 +04:00
|
|
|
process_menu(MENU_yesno, deconst(MSG_ftperror));
|
|
|
|
if (yesno) {
|
2003-06-03 15:54:48 +04:00
|
|
|
process_menu(MENU_ftpsource, NULL);
|
2004-06-06 01:18:59 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (got_one == 0) {
|
|
|
|
fchdir(cwd); /* back to current real root */
|
|
|
|
close(cwd);
|
1997-09-27 04:09:22 +04:00
|
|
|
return 0;
|
2004-06-06 01:18:59 +04:00
|
|
|
}
|
|
|
|
/* Continue without this set... */
|
|
|
|
}
|
|
|
|
list++;
|
1997-11-11 03:43:31 +03:00
|
|
|
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
2001-01-07 16:07:57 +03:00
|
|
|
wrefresh(curscr);
|
2000-12-22 00:42:00 +03:00
|
|
|
wmove(stdscr, 0, 0);
|
2000-10-12 03:47:55 +04:00
|
|
|
touchwin(stdscr);
|
1999-06-22 04:57:06 +04:00
|
|
|
wclear(stdscr);
|
1998-06-20 17:05:48 +04:00
|
|
|
wrefresh(stdscr);
|
2004-06-06 01:18:59 +04:00
|
|
|
|
|
|
|
fchdir(cwd); /* back to current real root */
|
|
|
|
close(cwd);
|
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
|
2003-06-16 23:42:13 +04:00
|
|
|
get_via_nfs(void)
|
1997-09-27 03:02:53 +04:00
|
|
|
{
|
1999-06-22 22:47:07 +04:00
|
|
|
int ret;
|
1998-06-20 17:05:48 +04:00
|
|
|
|
1999-06-22 22:47:07 +04:00
|
|
|
while ((ret = config_network()) <= 0) {
|
|
|
|
if (ret < 0)
|
|
|
|
return (-1);
|
1998-06-20 17:05:48 +04:00
|
|
|
msg_display(MSG_netnotup);
|
2003-06-03 15:54:48 +04:00
|
|
|
process_menu(MENU_yesno, NULL);
|
2002-02-04 17:35:10 +03:00
|
|
|
if (!yesno) {
|
|
|
|
msg_display(MSG_netnotup_continueanyway);
|
2003-06-03 15:54:48 +04:00
|
|
|
process_menu(MENU_yesno, NULL);
|
2002-02-04 17:35:10 +03:00
|
|
|
if (!yesno)
|
|
|
|
return 0;
|
|
|
|
network_up = 1;
|
|
|
|
}
|
1997-10-15 08:35:17 +04:00
|
|
|
}
|
|
|
|
|
2004-06-06 01:18:59 +04:00
|
|
|
again:
|
1997-09-27 03:02:53 +04:00
|
|
|
/* Get server and filepath */
|
2003-06-03 15:54:48 +04:00
|
|
|
process_menu(MENU_nfssource, NULL);
|
1997-10-15 08:35:17 +04:00
|
|
|
|
2003-10-20 00:17:31 +04:00
|
|
|
umount_mnt2();
|
2003-07-18 13:42:59 +04:00
|
|
|
|
1997-09-27 03:02:53 +04:00
|
|
|
/* Mount it */
|
2003-11-30 17:36:43 +03:00
|
|
|
if (run_program(0, "/sbin/mount -r -o -2,-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);
|
2003-06-03 15:54:48 +04:00
|
|
|
process_menu(MENU_nfsbadmount, NULL);
|
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;
|
|
|
|
}
|
2003-10-20 00:17:31 +04:00
|
|
|
mnt2_mounted = 1;
|
1997-12-05 17:00:59 +03:00
|
|
|
|
2004-06-06 01:18:59 +04:00
|
|
|
snprintf(ext_dir, sizeof ext_dir, "/mnt2/%s", set_dir);
|
|
|
|
|
1997-12-05 17:00:59 +03:00
|
|
|
/* Verify distribution files exist. */
|
2004-06-06 01:18:59 +04:00
|
|
|
if (distribution_sets_exist_p(ext_dir) == 0) {
|
|
|
|
msg_display(MSG_badsetdir, ext_dir);
|
2003-06-03 15:54:48 +04:00
|
|
|
process_menu (MENU_nfsbadmount, NULL);
|
1997-12-05 17:00:59 +03:00
|
|
|
if (!yesno)
|
|
|
|
return (0);
|
|
|
|
if (!ignorerror)
|
|
|
|
goto again;
|
1997-10-15 08:35:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* return location, don't clean... */
|
|
|
|
clean_dist_dir = 0;
|
|
|
|
return 1;
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
1997-10-20 10:13:25 +04:00
|
|
|
|
1999-06-24 02:55:14 +04:00
|
|
|
/*
|
|
|
|
* write the new contents of /etc/hosts to the specified file
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
write_etc_hosts(FILE *f)
|
|
|
|
{
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
scripting_fprintf(f, "#\n");
|
|
|
|
scripting_fprintf(f, "# Added by NetBSD sysinst\n");
|
|
|
|
scripting_fprintf(f, "#\n");
|
1999-06-24 02:55:14 +04:00
|
|
|
|
2003-11-04 19:27:22 +03:00
|
|
|
if (net_domain[0] != '\0')
|
|
|
|
scripting_fprintf(f, "127.0.0.1 localhost.%s\n", net_domain);
|
1999-06-24 02:55:14 +04:00
|
|
|
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
scripting_fprintf(f, "%s\t", net_ip);
|
2003-11-04 19:27:22 +03:00
|
|
|
if (net_domain[0] != '\0')
|
|
|
|
scripting_fprintf(f, "%s ", recombine_host_domain());
|
|
|
|
scripting_fprintf(f, "%s\n", net_host);
|
1999-06-24 02:55:14 +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
|
2003-07-18 13:42:59 +04:00
|
|
|
* target is the currently-active root.
|
1997-11-03 02:43:11 +03:00
|
|
|
*/
|
1997-10-20 10:13:25 +04:00
|
|
|
void
|
|
|
|
mnt_net_config(void)
|
|
|
|
{
|
2003-07-18 13:42:59 +04:00
|
|
|
char ans[8];
|
|
|
|
char ifconfig_fn[STRSIZE];
|
2001-05-07 15:49:52 +04:00
|
|
|
FILE *ifconf = NULL;
|
2003-07-18 13:42:59 +04:00
|
|
|
const char *yes = msg_string(MSG_Yes);
|
1997-10-20 10:13:25 +04:00
|
|
|
|
2000-07-24 14:52:28 +04:00
|
|
|
if (!network_up)
|
|
|
|
return;
|
2004-06-06 01:18:59 +04:00
|
|
|
process_menu(MENU_yesno, deconst(MSG_mntnetconfig));
|
|
|
|
if (!yesno)
|
2000-07-24 14:52:28 +04:00
|
|
|
return;
|
|
|
|
|
2003-02-10 05:24:27 +03:00
|
|
|
/* Write hostname to /etc/rc.conf */
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
if ((net_dhcpconf & DHCPCONF_HOST) == 0)
|
2003-11-04 04:53:28 +03:00
|
|
|
add_rc_conf("hostname=%s\n", recombine_host_domain());
|
1998-02-07 13:28:02 +03:00
|
|
|
|
2000-07-24 14:52:28 +04:00
|
|
|
/* If not running in target, copy resolv.conf there. */
|
|
|
|
if ((net_dhcpconf & DHCPCONF_NAMESVR) == 0) {
|
2001-04-15 15:08:51 +04:00
|
|
|
#ifndef INET6
|
2003-11-04 04:53:28 +03:00
|
|
|
if (net_namesvr[0] != '\0')
|
2000-07-24 14:52:28 +04:00
|
|
|
dup_file_into_target("/etc/resolv.conf");
|
2001-04-15 15:08:51 +04:00
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* not sure if it is a good idea, to allow dhcp config to
|
|
|
|
* override IPv6 configuration
|
|
|
|
*/
|
2003-11-04 04:53:28 +03:00
|
|
|
if (net_namesvr[0] != '\0' || net_namesvr6[0] != '\0')
|
2001-04-15 15:08:51 +04:00
|
|
|
dup_file_into_target("/etc/resolv.conf");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* bring the interface up, it will be necessary for IPv6, and
|
|
|
|
* it won't make trouble with IPv4 case either
|
|
|
|
*/
|
2003-07-18 13:42:59 +04:00
|
|
|
snprintf(ifconfig_fn, sizeof ifconfig_fn, "/etc/ifconfig.%s", net_dev);
|
2001-05-07 15:49:52 +04:00
|
|
|
ifconf = target_fopen(ifconfig_fn, "w");
|
|
|
|
if (ifconf != NULL) {
|
2001-04-15 15:08:51 +04:00
|
|
|
scripting_fprintf(NULL, "cat <<EOF >>%s%s\n",
|
|
|
|
target_prefix(), ifconfig_fn);
|
2001-05-07 15:49:52 +04:00
|
|
|
scripting_fprintf(ifconf, "up\n");
|
2001-04-15 15:08:51 +04:00
|
|
|
scripting_fprintf(NULL, "EOF\n");
|
2000-07-24 14:52:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((net_dhcpconf & DHCPCONF_IPADDR) == 0) {
|
2001-05-07 15:49:52 +04:00
|
|
|
FILE *hosts;
|
|
|
|
|
2001-04-15 15:08:51 +04:00
|
|
|
/* Write IPaddr and netmask to /etc/ifconfig.if[0-9] */
|
2001-05-07 15:49:52 +04:00
|
|
|
if (ifconf != NULL) {
|
2001-04-15 15:08:51 +04:00
|
|
|
scripting_fprintf(NULL, "cat <<EOF >>%s%s\n",
|
|
|
|
target_prefix(), ifconfig_fn);
|
|
|
|
if (*net_media != '\0')
|
2001-05-07 15:49:52 +04:00
|
|
|
scripting_fprintf(ifconf,
|
|
|
|
"%s netmask %s media %s\n",
|
2001-04-15 15:08:51 +04:00
|
|
|
net_ip, net_mask, net_media);
|
|
|
|
else
|
2001-05-07 15:49:52 +04:00
|
|
|
scripting_fprintf(ifconf, "%s netmask %s\n",
|
|
|
|
net_ip, net_mask);
|
2001-04-15 15:08:51 +04:00
|
|
|
scripting_fprintf(NULL, "EOF\n");
|
|
|
|
}
|
|
|
|
|
2003-07-18 13:42:59 +04:00
|
|
|
/*
|
2000-07-24 14:52:28 +04:00
|
|
|
* Add IPaddr/hostname to /etc/hosts.
|
|
|
|
* Be careful not to clobber any existing contents.
|
|
|
|
* Relies on ordered seach of /etc/hosts. XXX YP?
|
|
|
|
*/
|
2001-05-07 15:49:52 +04:00
|
|
|
hosts = target_fopen("/etc/hosts", "a");
|
|
|
|
if (hosts != 0) {
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
scripting_fprintf(NULL, "cat <<EOF >>%s/etc/hosts\n",
|
|
|
|
target_prefix());
|
2001-05-07 15:49:52 +04:00
|
|
|
write_etc_hosts(hosts);
|
|
|
|
(void)fclose(hosts);
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
scripting_fprintf(NULL, "EOF\n");
|
2001-05-07 15:49:52 +04:00
|
|
|
|
|
|
|
fclose(hosts);
|
2000-07-24 14:52:28 +04:00
|
|
|
}
|
1997-11-03 02:43:11 +03:00
|
|
|
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
add_rc_conf("defaultroute=\"%s\"\n", net_defroute);
|
2000-12-31 16:08:05 +03:00
|
|
|
} else {
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
add_rc_conf("dhclient=YES\n");
|
2001-03-06 12:22:40 +03:00
|
|
|
add_rc_conf("dhclient_flags=\"%s\"\n", net_dev);
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
}
|
2001-04-15 15:08:51 +04:00
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
if ((net_ip6conf & IP6CONF_AUTOHOST) != 0) {
|
|
|
|
add_rc_conf("ip6mode=autohost\n");
|
2001-05-07 15:49:52 +04:00
|
|
|
if (ifconf != NULL) {
|
|
|
|
scripting_fprintf(NULL, "cat <<EOF >>%s%s\n",
|
|
|
|
target_prefix(), ifconfig_fn);
|
2002-05-24 11:58:23 +04:00
|
|
|
scripting_fprintf(ifconf, "!rtsol $int\n");
|
2001-05-07 15:49:52 +04:00
|
|
|
scripting_fprintf(NULL, "EOF\n");
|
|
|
|
}
|
2001-04-15 15:08:51 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-05-07 15:49:52 +04:00
|
|
|
if (ifconf)
|
|
|
|
fclose(ifconf);
|
|
|
|
|
2000-07-24 14:52:28 +04:00
|
|
|
fflush(NULL);
|
|
|
|
}
|
2000-06-19 03:50:02 +04:00
|
|
|
|
|
|
|
int
|
2003-06-16 23:42:13 +04:00
|
|
|
config_dhcp(char *inter)
|
2000-06-19 03:50:02 +04:00
|
|
|
{
|
|
|
|
int dhcpautoconf;
|
|
|
|
int result;
|
|
|
|
char *textbuf;
|
|
|
|
int pid;
|
|
|
|
|
|
|
|
/* check if dhclient is running, if so, kill it */
|
|
|
|
result = collect(T_FILE, &textbuf, "/tmp/dhclient.pid");
|
2003-07-18 13:42:59 +04:00
|
|
|
if (result >= 0) {
|
2000-06-19 03:50:02 +04:00
|
|
|
pid = atoi(textbuf);
|
|
|
|
if (pid > 0) {
|
2003-07-18 13:42:59 +04:00
|
|
|
kill(pid, 15);
|
2000-06-19 03:50:02 +04:00
|
|
|
sleep(1);
|
2003-07-18 13:42:59 +04:00
|
|
|
kill(pid, 9);
|
2000-06-19 03:50:02 +04:00
|
|
|
}
|
|
|
|
}
|
2003-07-18 13:42:59 +04:00
|
|
|
free(textbuf);
|
2000-06-19 03:50:02 +04:00
|
|
|
|
2000-09-26 17:26:02 +04:00
|
|
|
if (!file_mode_match(DHCLIENT_EX, S_IFREG))
|
2000-06-19 03:50:02 +04:00
|
|
|
return 0;
|
2004-06-06 01:18:59 +04:00
|
|
|
process_menu(MENU_yesno, deconst(MSG_Perform_DHCP_autoconfiguration));
|
2000-06-19 03:50:02 +04:00
|
|
|
if (yesno) {
|
|
|
|
/* spawn off dhclient and wait for parent to exit */
|
2004-05-16 01:48:09 +04:00
|
|
|
dhcpautoconf = run_program(RUN_DISPLAY | RUN_PROGRESS,
|
2003-07-18 13:42:59 +04:00
|
|
|
"%s -pf /tmp/dhclient.pid -lf /tmp/dhclient.leases %s",
|
|
|
|
DHCLIENT_EX, inter);
|
|
|
|
return dhcpautoconf ? 0 : 1;
|
2000-06-19 03:50:02 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-07-24 14:52:28 +04:00
|
|
|
static void
|
2003-08-06 17:56:58 +04:00
|
|
|
get_command_out(char *targ, size_t l, int af, const char *command,
|
|
|
|
const char *search)
|
2000-06-19 03:50:02 +04:00
|
|
|
{
|
|
|
|
int textsize;
|
|
|
|
char *textbuf;
|
2003-07-25 12:26:21 +04:00
|
|
|
const char *t;
|
2000-07-24 14:52:28 +04:00
|
|
|
#ifndef INET6
|
|
|
|
struct in_addr in;
|
|
|
|
#else
|
|
|
|
struct in6_addr in;
|
|
|
|
#endif
|
2000-06-19 03:50:02 +04:00
|
|
|
|
|
|
|
textsize = collect(T_OUTPUT, &textbuf, command);
|
|
|
|
if (textsize < 0) {
|
|
|
|
if (logging)
|
2002-12-05 04:17:15 +03:00
|
|
|
(void)fprintf(logfp,
|
|
|
|
"Aborting: Could not run %s.\n", command);
|
2000-06-19 03:50:02 +04:00
|
|
|
(void)fprintf(stderr, "Could not run ifconfig.");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (textsize >= 0) {
|
|
|
|
(void)strtok(textbuf, " \t\n"); /* ignore interface name */
|
|
|
|
while ((t = strtok(NULL, " \t\n")) != NULL) {
|
|
|
|
if (strcmp(t, search) == 0) {
|
|
|
|
t = strtok(NULL, " \t\n");
|
2000-07-24 14:52:28 +04:00
|
|
|
if (inet_pton(af, t, &in) == 1 &&
|
|
|
|
strcmp(t, "0.0.0.0") != 0) {
|
2003-08-06 17:56:58 +04:00
|
|
|
strlcpy(targ, t, l);
|
2000-06-19 03:50:02 +04:00
|
|
|
}
|
2000-07-24 14:52:28 +04:00
|
|
|
}
|
2000-06-19 03:50:02 +04:00
|
|
|
}
|
|
|
|
}
|
2003-07-18 13:42:59 +04:00
|
|
|
free(textbuf);
|
2000-06-19 03:50:02 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-07-24 14:52:28 +04:00
|
|
|
static void
|
2003-08-06 17:56:58 +04:00
|
|
|
get_dhcp_value(char *targ, size_t l, const char *line)
|
2000-06-19 03:50:02 +04:00
|
|
|
{
|
|
|
|
int textsize;
|
|
|
|
char *textbuf;
|
|
|
|
char *t;
|
2003-01-10 23:00:27 +03:00
|
|
|
char *walkp;
|
2000-06-19 03:50:02 +04:00
|
|
|
|
|
|
|
textsize = collect(T_FILE, &textbuf, "/tmp/dhclient.leases");
|
|
|
|
if (textsize < 0) {
|
|
|
|
if (logging)
|
2002-12-05 04:17:15 +03:00
|
|
|
(void)fprintf(logfp,
|
|
|
|
"Could not open file /tmp/dhclient.leases.\n");
|
2000-06-19 03:50:02 +04:00
|
|
|
(void)fprintf(stderr, "Could not open /tmp/dhclient.leases\n");
|
|
|
|
/* not fatal, just assume value not found */
|
|
|
|
}
|
2000-07-24 14:52:28 +04:00
|
|
|
if (textsize >= 0) {
|
2000-06-19 03:50:02 +04:00
|
|
|
(void)strtok(textbuf, " \t\n"); /* jump past 'lease' */
|
2003-07-18 13:42:59 +04:00
|
|
|
while ((t = strtok(NULL, " \t\n")) != NULL) {
|
2000-06-19 03:50:02 +04:00
|
|
|
if (strcmp(t, line) == 0) {
|
|
|
|
t = strtok(NULL, " \t\n");
|
|
|
|
/* found the tag, extract the value */
|
|
|
|
/* last char should be a ';' */
|
2003-01-10 23:00:27 +03:00
|
|
|
walkp = strrchr(t, ';');
|
|
|
|
if (walkp != NULL) {
|
|
|
|
*walkp = '\0';
|
2000-06-19 03:50:02 +04:00
|
|
|
}
|
|
|
|
/* strip any " from the string */
|
2003-01-10 23:00:27 +03:00
|
|
|
walkp = strrchr(t, '"');
|
|
|
|
if (walkp != NULL) {
|
|
|
|
*walkp = '\0';
|
2000-06-19 03:50:02 +04:00
|
|
|
t++;
|
|
|
|
}
|
2003-08-06 17:56:58 +04:00
|
|
|
strlcpy(targ, t, l);
|
2003-07-18 13:42:59 +04:00
|
|
|
break;
|
2000-06-19 03:50:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-07-18 13:42:59 +04:00
|
|
|
free(textbuf);
|
2000-06-19 03:50:02 +04:00
|
|
|
return;
|
|
|
|
}
|