1995-05-16 02:53:31 +00:00
|
|
|
/*
|
1996-09-01 08:17:14 +00:00
|
|
|
* $Id: tcpip.c,v 1.45 1996/08/03 10:11:56 jkh Exp $
|
1995-05-16 02:53:31 +00:00
|
|
|
*
|
|
|
|
* Copyright (c) 1995
|
|
|
|
* Gary J Palmer. All rights reserved.
|
1996-09-01 08:17:14 +00:00
|
|
|
* Copyright (c) 1996
|
|
|
|
* Jordan K. Hubbard. All rights reserved.
|
1995-05-16 02:53:31 +00:00
|
|
|
*
|
|
|
|
* 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
|
1995-05-30 08:29:07 +00:00
|
|
|
* notice, this list of conditions and the following disclaimer,
|
|
|
|
* verbatim and that no modifications are made prior to this
|
1995-05-16 02:53:31 +00:00
|
|
|
* point in the file.
|
|
|
|
* 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.
|
|
|
|
*
|
1996-09-01 08:17:14 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
|
1995-05-21 15:40:54 +00:00
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
1996-09-01 08:17:14 +00:00
|
|
|
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
1995-05-21 15:40:54 +00:00
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, LIFE 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.
|
1995-05-16 02:53:31 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1995-05-26 08:41:52 +00:00
|
|
|
/*
|
|
|
|
* All kinds of hacking also performed by jkh on this code. Don't
|
|
|
|
* blame Gary for every bogosity you see here.. :-)
|
|
|
|
*
|
|
|
|
* -jkh
|
|
|
|
*/
|
|
|
|
|
1995-05-16 02:53:31 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <dialog.h>
|
|
|
|
#include "ui_objects.h"
|
|
|
|
#include "dir.h"
|
|
|
|
#include "dialog.priv.h"
|
|
|
|
#include "colors.h"
|
1995-05-16 11:37:27 +00:00
|
|
|
#include "sysinstall.h"
|
1995-05-16 02:53:31 +00:00
|
|
|
|
1996-03-02 07:31:58 +00:00
|
|
|
/* The help file for the TCP/IP setup screen */
|
|
|
|
#define TCP_HELPFILE "tcp"
|
|
|
|
|
1995-05-17 12:09:11 +00:00
|
|
|
/* These are nasty, but they make the layout structure a lot easier ... */
|
|
|
|
|
1995-12-07 10:34:59 +00:00
|
|
|
static char hostname[HOSTNAME_FIELD_LEN], domainname[HOSTNAME_FIELD_LEN],
|
|
|
|
gateway[IPADDR_FIELD_LEN], nameserver[IPADDR_FIELD_LEN];
|
|
|
|
static int okbutton, cancelbutton;
|
|
|
|
static char ipaddr[IPADDR_FIELD_LEN], netmask[IPADDR_FIELD_LEN], extras[EXTRAS_FIELD_LEN];
|
1995-05-16 02:53:31 +00:00
|
|
|
|
1995-05-17 12:09:11 +00:00
|
|
|
/* What the screen size is meant to be */
|
1995-05-16 02:53:31 +00:00
|
|
|
#define TCP_DIALOG_Y 0
|
|
|
|
#define TCP_DIALOG_X 8
|
|
|
|
#define TCP_DIALOG_WIDTH COLS - 16
|
|
|
|
#define TCP_DIALOG_HEIGHT LINES - 2
|
|
|
|
|
1995-05-17 12:09:11 +00:00
|
|
|
/* The screen layout structure */
|
1995-05-16 02:53:31 +00:00
|
|
|
typedef struct _layout {
|
1995-05-17 12:09:11 +00:00
|
|
|
int y; /* x & Y co-ordinates */
|
1995-05-16 11:37:27 +00:00
|
|
|
int x;
|
1995-05-17 12:09:11 +00:00
|
|
|
int len; /* The size of the dialog on the screen */
|
|
|
|
int maxlen; /* How much the user can type in ... */
|
|
|
|
char *prompt; /* The string for the prompt */
|
|
|
|
char *help; /* The display for the help line */
|
|
|
|
void *var; /* The var to set when this changes */
|
|
|
|
int type; /* The type of the dialog to create */
|
|
|
|
void *obj; /* The obj pointer returned by libdialog */
|
1995-05-16 02:53:31 +00:00
|
|
|
} Layout;
|
|
|
|
|
|
|
|
static Layout layout[] = {
|
1995-05-26 08:41:52 +00:00
|
|
|
{ 1, 2, 25, HOSTNAME_FIELD_LEN - 1,
|
1996-09-01 08:17:14 +00:00
|
|
|
"Host:", "Your fully-qualified hostname, e.g. foo.bar.com",
|
1995-05-16 02:53:31 +00:00
|
|
|
hostname, STRINGOBJ, NULL },
|
1995-05-17 12:09:11 +00:00
|
|
|
#define LAYOUT_HOSTNAME 0
|
1995-05-26 08:41:52 +00:00
|
|
|
{ 1, 35, 20, HOSTNAME_FIELD_LEN - 1,
|
1996-09-01 08:17:14 +00:00
|
|
|
"Domain:",
|
1995-05-16 02:53:31 +00:00
|
|
|
"The name of the domain that your machine is in, e.g. bar.com",
|
|
|
|
domainname, STRINGOBJ, NULL },
|
1995-05-17 12:09:11 +00:00
|
|
|
#define LAYOUT_DOMAINNAME 1
|
1995-05-26 08:41:52 +00:00
|
|
|
{ 5, 2, 18, IPADDR_FIELD_LEN - 1,
|
1995-05-16 02:53:31 +00:00
|
|
|
"Gateway:",
|
1995-05-26 08:41:52 +00:00
|
|
|
"IP address of host forwarding packets to non-local destinations",
|
1995-05-16 02:53:31 +00:00
|
|
|
gateway, STRINGOBJ, NULL },
|
1995-05-17 12:09:11 +00:00
|
|
|
#define LAYOUT_GATEWAY 2
|
1995-05-26 08:41:52 +00:00
|
|
|
{ 5, 35, 18, IPADDR_FIELD_LEN - 1,
|
1995-05-16 02:53:31 +00:00
|
|
|
"Name server:", "IP address of your local DNS server",
|
1995-05-16 11:37:27 +00:00
|
|
|
nameserver, STRINGOBJ, NULL },
|
1995-05-17 12:09:11 +00:00
|
|
|
#define LAYOUT_NAMESERVER 3
|
1995-05-26 08:58:35 +00:00
|
|
|
{ 10, 10, 18, IPADDR_FIELD_LEN - 1,
|
1995-05-16 02:53:31 +00:00
|
|
|
"IP Address:",
|
1995-05-26 08:41:52 +00:00
|
|
|
"The IP address to be used for this interface",
|
1995-05-16 02:53:31 +00:00
|
|
|
ipaddr, STRINGOBJ, NULL },
|
1995-12-07 10:34:59 +00:00
|
|
|
#define LAYOUT_IPADDR 4
|
1995-05-26 08:58:35 +00:00
|
|
|
{ 10, 35, 18, IPADDR_FIELD_LEN - 1,
|
1995-05-16 02:53:31 +00:00
|
|
|
"Netmask:",
|
1995-12-07 10:34:59 +00:00
|
|
|
"The netmask for this interface, e.g. 0xffffff00 for a class C network",
|
1995-05-16 02:53:31 +00:00
|
|
|
netmask, STRINGOBJ, NULL },
|
1995-12-07 10:34:59 +00:00
|
|
|
#define LAYOUT_NETMASK 5
|
1995-05-26 08:58:35 +00:00
|
|
|
{ 14, 10, 37, HOSTNAME_FIELD_LEN - 1,
|
1995-05-16 11:37:27 +00:00
|
|
|
"Extra options to ifconfig:",
|
1996-09-01 08:17:14 +00:00
|
|
|
"Any interface-specific options to ifconfig you would like to add",
|
1995-05-16 02:53:31 +00:00
|
|
|
extras, STRINGOBJ, NULL },
|
1995-12-07 10:34:59 +00:00
|
|
|
#define LAYOUT_EXTRAS 6
|
1995-05-26 08:41:52 +00:00
|
|
|
{ 19, 15, 0, 0,
|
1995-05-16 02:53:31 +00:00
|
|
|
"OK", "Select this if you are happy with these settings",
|
|
|
|
&okbutton, BUTTONOBJ, NULL },
|
1995-12-07 10:34:59 +00:00
|
|
|
#define LAYOUT_OKBUTTON 7
|
1995-05-26 08:41:52 +00:00
|
|
|
{ 19, 35, 0, 0,
|
1995-05-16 02:53:31 +00:00
|
|
|
"CANCEL", "Select this if you wish to cancel this screen",
|
|
|
|
&cancelbutton, BUTTONOBJ, NULL },
|
1995-12-07 10:34:59 +00:00
|
|
|
#define LAYOUT_CANCELBUTTON 8
|
1995-05-16 02:53:31 +00:00
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
1995-09-18 16:53:06 +00:00
|
|
|
#define _validByte(b) ((b) >= 0 && (b) <= 255)
|
1995-05-16 02:53:31 +00:00
|
|
|
|
1995-05-26 08:41:52 +00:00
|
|
|
/* whine */
|
1995-05-16 02:53:31 +00:00
|
|
|
static void
|
|
|
|
feepout(char *msg)
|
|
|
|
{
|
|
|
|
beep();
|
1995-05-16 11:37:27 +00:00
|
|
|
dialog_notify(msg);
|
1995-05-16 02:53:31 +00:00
|
|
|
}
|
|
|
|
|
1995-05-17 12:09:11 +00:00
|
|
|
/* Very basic IP address integrity check - could be drastically improved */
|
1995-05-16 02:53:31 +00:00
|
|
|
static int
|
|
|
|
verifyIP(char *ip)
|
|
|
|
{
|
|
|
|
int a, b, c, d;
|
|
|
|
|
|
|
|
if (ip && sscanf(ip, "%d.%d.%d.%d", &a, &b, &c, &d) == 4 &&
|
|
|
|
_validByte(a) && _validByte(b) && _validByte(c) &&
|
1995-09-18 16:53:06 +00:00
|
|
|
_validByte(d) && (d != 255))
|
1995-05-16 02:53:31 +00:00
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1995-05-17 12:09:11 +00:00
|
|
|
/* Check for the settings on the screen - the per interface stuff is
|
|
|
|
moved to the main handling code now to do it on the fly - sigh */
|
|
|
|
|
1995-05-16 02:53:31 +00:00
|
|
|
static int
|
|
|
|
verifySettings(void)
|
|
|
|
{
|
|
|
|
if (!hostname[0])
|
|
|
|
feepout("Must specify a host name of some sort!");
|
|
|
|
else if (gateway[0] && !verifyIP(gateway))
|
|
|
|
feepout("Invalid gateway IP address specified");
|
1995-05-16 11:37:27 +00:00
|
|
|
else if (nameserver[0] && !verifyIP(nameserver))
|
1995-05-16 02:53:31 +00:00
|
|
|
feepout("Invalid name server IP address specified");
|
1995-05-26 08:41:52 +00:00
|
|
|
else if (netmask[0] && (netmask[0] < '0' && netmask[0] > '3'))
|
|
|
|
feepout("Invalid netmask value");
|
|
|
|
else if (ipaddr[0] && !verifyIP(ipaddr))
|
|
|
|
feepout("Invalid IP address");
|
1995-05-16 02:53:31 +00:00
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1995-12-07 10:34:59 +00:00
|
|
|
int
|
|
|
|
tcpInstallDevice(char *str)
|
|
|
|
{
|
|
|
|
Device **devs;
|
|
|
|
Device *dp = NULL;
|
|
|
|
|
|
|
|
/* Clip garbage off the ends */
|
|
|
|
string_prune(str);
|
|
|
|
str = string_skipwhite(str);
|
|
|
|
if (!*str)
|
1996-04-13 13:32:15 +00:00
|
|
|
return DITEM_FAILURE;
|
1995-12-07 10:34:59 +00:00
|
|
|
devs = deviceFind(str, DEVICE_TYPE_NETWORK);
|
|
|
|
if (devs && (dp = devs[0])) {
|
|
|
|
char temp[512], ifn[255];
|
|
|
|
|
|
|
|
if (!dp->private) {
|
|
|
|
DevInfo *di;
|
|
|
|
char *ipaddr, *netmask, *extras;
|
|
|
|
|
|
|
|
di = dp->private = (DevInfo *)malloc(sizeof(DevInfo));
|
|
|
|
|
|
|
|
if ((ipaddr = variable_get(string_concat3(VAR_IPADDR, "_", dp->name))) == NULL)
|
|
|
|
ipaddr = variable_get(VAR_IPADDR);
|
|
|
|
|
|
|
|
if ((netmask = variable_get(string_concat3(VAR_NETMASK, "_", dp->name))) == NULL)
|
|
|
|
netmask = variable_get(VAR_NETMASK);
|
|
|
|
|
|
|
|
if ((extras = variable_get(string_concat3(VAR_EXTRAS, "_", dp->name))) == NULL)
|
|
|
|
extras = variable_get(VAR_EXTRAS);
|
|
|
|
|
|
|
|
string_copy(di->ipaddr, ipaddr);
|
|
|
|
string_copy(di->netmask, netmask);
|
|
|
|
string_copy(di->extras, extras);
|
|
|
|
|
|
|
|
if (ipaddr) {
|
|
|
|
char *ifaces;
|
|
|
|
|
|
|
|
sprintf(temp, "inet %s %s netmask %s", ipaddr, extras ? extras : "", netmask);
|
|
|
|
sprintf(ifn, "%s%s", VAR_IFCONFIG, dp->name);
|
|
|
|
variable_set2(ifn, temp);
|
|
|
|
ifaces = variable_get(VAR_INTERFACES);
|
|
|
|
if (!ifaces)
|
|
|
|
variable_set2(VAR_INTERFACES, ifaces = "lo0");
|
|
|
|
/* Only add it if it's not there already */
|
|
|
|
if (!strstr(ifaces, dp->name)) {
|
|
|
|
sprintf(ifn, "%s %s", dp->name, ifaces);
|
|
|
|
variable_set2(VAR_INTERFACES, ifn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mediaDevice = dp;
|
|
|
|
}
|
1996-04-13 13:32:15 +00:00
|
|
|
return dp ? DITEM_SUCCESS : DITEM_FAILURE;
|
1995-12-07 10:34:59 +00:00
|
|
|
}
|
|
|
|
|
1995-05-16 02:53:31 +00:00
|
|
|
/* This is it - how to get TCP setup values */
|
1995-05-16 11:37:27 +00:00
|
|
|
int
|
1995-05-26 08:41:52 +00:00
|
|
|
tcpOpenDialog(Device *devp)
|
1995-05-16 02:53:31 +00:00
|
|
|
{
|
1996-04-23 01:29:35 +00:00
|
|
|
WINDOW *ds_win, *save;
|
1995-05-16 02:53:31 +00:00
|
|
|
ComposeObj *obj = NULL;
|
|
|
|
ComposeObj *first, *last;
|
1995-05-26 08:41:52 +00:00
|
|
|
int n=0, quit=FALSE, cancel=FALSE, ret;
|
|
|
|
int max;
|
1995-05-16 02:53:31 +00:00
|
|
|
char *tmp;
|
1995-05-17 14:40:00 +00:00
|
|
|
char help[FILENAME_MAX];
|
1995-05-28 03:05:06 +00:00
|
|
|
char title[80];
|
1995-05-16 02:53:31 +00:00
|
|
|
|
1996-04-23 01:29:35 +00:00
|
|
|
save = savescr();
|
1996-08-03 10:11:56 +00:00
|
|
|
dialog_clear_norefresh();
|
1995-05-17 12:09:11 +00:00
|
|
|
/* We need a curses window */
|
1995-05-16 02:53:31 +00:00
|
|
|
ds_win = newwin(LINES, COLS, 0, 0);
|
1995-05-16 11:37:27 +00:00
|
|
|
if (ds_win == 0)
|
1995-05-16 02:53:31 +00:00
|
|
|
msgFatal("Cannot open TCP/IP dialog window!!");
|
1995-05-16 11:37:27 +00:00
|
|
|
|
1995-05-26 08:41:52 +00:00
|
|
|
/* Say where our help comes from */
|
1995-05-17 14:40:00 +00:00
|
|
|
systemHelpFile(TCP_HELPFILE, help);
|
|
|
|
use_helpfile(help);
|
1995-05-26 08:41:52 +00:00
|
|
|
|
|
|
|
/* Setup a nice screen for us to splat stuff onto */
|
|
|
|
draw_box(ds_win, TCP_DIALOG_Y, TCP_DIALOG_X, TCP_DIALOG_HEIGHT, TCP_DIALOG_WIDTH, dialog_attr, border_attr);
|
1995-05-16 02:53:31 +00:00
|
|
|
wattrset(ds_win, dialog_attr);
|
1995-05-29 12:32:41 +00:00
|
|
|
mvwaddstr(ds_win, TCP_DIALOG_Y, TCP_DIALOG_X + 20, " Network Configuration ");
|
1995-05-26 08:41:52 +00:00
|
|
|
draw_box(ds_win, TCP_DIALOG_Y + 9, TCP_DIALOG_X + 8, TCP_DIALOG_HEIGHT - 13, TCP_DIALOG_WIDTH - 17,
|
1995-05-16 11:37:27 +00:00
|
|
|
dialog_attr, border_attr);
|
|
|
|
wattrset(ds_win, dialog_attr);
|
1995-05-29 11:01:42 +00:00
|
|
|
sprintf(title, " Configuration for Interface %s ", devp->name);
|
|
|
|
mvwaddstr(ds_win, TCP_DIALOG_Y + 9, TCP_DIALOG_X + 14, title);
|
1995-05-26 08:41:52 +00:00
|
|
|
|
|
|
|
/* Initialise vars from previous device values */
|
|
|
|
if (devp->private) {
|
|
|
|
DevInfo *di = (DevInfo *)devp->private;
|
1995-05-30 08:29:07 +00:00
|
|
|
|
1995-05-26 08:41:52 +00:00
|
|
|
strcpy(ipaddr, di->ipaddr);
|
|
|
|
strcpy(netmask, di->netmask);
|
|
|
|
strcpy(extras, di->extras);
|
|
|
|
}
|
1995-12-07 10:34:59 +00:00
|
|
|
else { /* See if there are any defaults */
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
if (!ipaddr[0]) {
|
|
|
|
if ((cp = variable_get(VAR_IPADDR)) != NULL)
|
|
|
|
strcpy(ipaddr, cp);
|
|
|
|
else if ((cp = variable_get(string_concat3(devp->name, "_", VAR_IPADDR))) != NULL)
|
|
|
|
strcpy(ipaddr, cp);
|
|
|
|
}
|
|
|
|
if (!netmask[0]) {
|
|
|
|
if ((cp = variable_get(VAR_NETMASK)) != NULL)
|
|
|
|
strcpy(netmask, cp);
|
|
|
|
else if ((cp = variable_get(string_concat3(devp->name, "_", VAR_NETMASK))) != NULL)
|
|
|
|
strcpy(netmask, cp);
|
|
|
|
}
|
|
|
|
if (!extras[0]) {
|
|
|
|
if ((cp = variable_get(VAR_EXTRAS)) != NULL)
|
|
|
|
strcpy(extras, cp);
|
|
|
|
else if ((cp = variable_get(string_concat3(devp->name, "_", VAR_EXTRAS))) != NULL)
|
|
|
|
strcpy(extras, cp);
|
|
|
|
}
|
|
|
|
}
|
1995-05-26 08:41:52 +00:00
|
|
|
/* Look up values already recorded with the system, or blank the string variables ready to accept some new data */
|
1995-12-07 10:34:59 +00:00
|
|
|
tmp = variable_get(VAR_HOSTNAME);
|
1995-05-16 02:53:31 +00:00
|
|
|
if (tmp)
|
|
|
|
strcpy(hostname, tmp);
|
|
|
|
else
|
|
|
|
bzero(hostname, sizeof(hostname));
|
1995-12-07 10:34:59 +00:00
|
|
|
tmp = variable_get(VAR_DOMAINNAME);
|
1995-05-16 02:53:31 +00:00
|
|
|
if (tmp)
|
|
|
|
strcpy(domainname, tmp);
|
|
|
|
else
|
|
|
|
bzero(domainname, sizeof(domainname));
|
1995-12-07 10:34:59 +00:00
|
|
|
tmp = variable_get(VAR_GATEWAY);
|
1995-05-16 02:53:31 +00:00
|
|
|
if (tmp)
|
|
|
|
strcpy(gateway, tmp);
|
|
|
|
else
|
|
|
|
bzero(gateway, sizeof(gateway));
|
1995-12-07 10:34:59 +00:00
|
|
|
tmp = variable_get(VAR_NAMESERVER);
|
1995-05-16 02:53:31 +00:00
|
|
|
if (tmp)
|
1995-05-16 11:37:27 +00:00
|
|
|
strcpy(nameserver, tmp);
|
1995-05-16 02:53:31 +00:00
|
|
|
else
|
1995-05-16 11:37:27 +00:00
|
|
|
bzero(nameserver, sizeof(nameserver));
|
1995-05-16 02:53:31 +00:00
|
|
|
|
1995-05-17 12:09:11 +00:00
|
|
|
/* Loop over the layout list, create the objects, and add them
|
|
|
|
onto the chain of objects that dialog uses for traversal*/
|
1995-05-16 20:00:51 +00:00
|
|
|
n = 0;
|
1995-05-16 02:53:31 +00:00
|
|
|
#define lt layout[n]
|
|
|
|
while (lt.help != NULL) {
|
|
|
|
switch (lt.type) {
|
|
|
|
case STRINGOBJ:
|
|
|
|
lt.obj = NewStringObj(ds_win, lt.prompt, lt.var,
|
|
|
|
lt.y + TCP_DIALOG_Y, lt.x + TCP_DIALOG_X,
|
|
|
|
lt.len, lt.maxlen);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BUTTONOBJ:
|
|
|
|
lt.obj = NewButtonObj(ds_win, lt.prompt, lt.var,
|
|
|
|
lt.y + TCP_DIALOG_Y, lt.x + TCP_DIALOG_X);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1995-05-16 11:37:27 +00:00
|
|
|
msgFatal("Don't support this object yet!");
|
1995-05-16 02:53:31 +00:00
|
|
|
}
|
|
|
|
AddObj(&obj, lt.type, (void *) lt.obj);
|
|
|
|
n++;
|
|
|
|
}
|
1995-05-16 20:00:51 +00:00
|
|
|
max = n - 1;
|
1995-05-17 12:09:11 +00:00
|
|
|
|
|
|
|
/* Find the last object we can traverse to */
|
1995-05-16 02:53:31 +00:00
|
|
|
last = obj;
|
|
|
|
while (last->next)
|
|
|
|
last = last->next;
|
1995-05-30 08:29:07 +00:00
|
|
|
|
1995-05-17 12:09:11 +00:00
|
|
|
/* Find the first object in the list */
|
1995-05-16 02:53:31 +00:00
|
|
|
first = obj;
|
1995-12-07 10:34:59 +00:00
|
|
|
for (first = obj; first->prev; first = first->prev);
|
1995-05-16 11:37:27 +00:00
|
|
|
|
1995-05-17 12:09:11 +00:00
|
|
|
/* Some more initialisation before we go into the main input loop */
|
1995-05-16 02:53:31 +00:00
|
|
|
n = 0;
|
1995-05-16 11:37:27 +00:00
|
|
|
cancelbutton = okbutton = 0;
|
|
|
|
|
1995-05-17 12:09:11 +00:00
|
|
|
/* Incoming user data - DUCK! */
|
1995-05-16 11:37:27 +00:00
|
|
|
while (!quit) {
|
1995-05-16 02:53:31 +00:00
|
|
|
char help_line[80];
|
|
|
|
int i, len = strlen(lt.help);
|
|
|
|
|
1995-05-17 12:09:11 +00:00
|
|
|
/* Display the help line at the bottom of the screen */
|
1995-05-16 02:53:31 +00:00
|
|
|
for (i = 0; i < 79; i++)
|
|
|
|
help_line[i] = (i < len) ? lt.help[i] : ' ';
|
|
|
|
help_line[i] = '\0';
|
|
|
|
use_helpline(help_line);
|
|
|
|
display_helpline(ds_win, LINES - 1, COLS - 1);
|
|
|
|
|
1995-05-17 12:09:11 +00:00
|
|
|
/* Ask for libdialog to do its stuff */
|
1995-05-16 02:53:31 +00:00
|
|
|
ret = PollObj(&obj);
|
|
|
|
|
1995-12-07 10:34:59 +00:00
|
|
|
if (n == LAYOUT_HOSTNAME) {
|
|
|
|
/* We are in the Hostname field - calculate the domainname */
|
1995-05-17 12:09:11 +00:00
|
|
|
if ((tmp = index(hostname, '.')) != NULL) {
|
|
|
|
strncpy(domainname, tmp + 1, strlen(tmp + 1));
|
|
|
|
domainname[strlen(tmp+1)] = '\0';
|
1995-12-07 10:34:59 +00:00
|
|
|
RefreshStringObj(layout[LAYOUT_DOMAINNAME].obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (n == LAYOUT_IPADDR) {
|
|
|
|
/* Insert a default value for the netmask, 0xffffff00 is
|
|
|
|
the most appropriate one (entire class C, or subnetted
|
|
|
|
class A/B network). */
|
|
|
|
if(netmask[0] == '\0') {
|
|
|
|
strcpy(netmask, "255.255.255.0");
|
|
|
|
RefreshStringObj(layout[LAYOUT_NETMASK].obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (n == LAYOUT_DOMAINNAME) {
|
|
|
|
if (!index(hostname, '.') && domainname[0]) {
|
|
|
|
strcat(hostname, ".");
|
|
|
|
strcat(hostname, domainname);
|
|
|
|
RefreshStringObj(layout[LAYOUT_HOSTNAME].obj);
|
1995-05-17 12:09:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Handle special case stuff that libdialog misses. Sigh */
|
1995-05-16 02:53:31 +00:00
|
|
|
switch (ret) {
|
1995-05-17 12:09:11 +00:00
|
|
|
/* Bail out */
|
1995-05-16 02:53:31 +00:00
|
|
|
case SEL_ESC:
|
1995-05-16 11:37:27 +00:00
|
|
|
quit = TRUE, cancel=TRUE;
|
1995-05-16 02:53:31 +00:00
|
|
|
break;
|
|
|
|
|
1995-05-17 12:09:11 +00:00
|
|
|
/* This doesn't work for list dialogs. Oh well. Perhaps
|
|
|
|
should special case the move from the OK button ``up''
|
|
|
|
to make it go to the interface list, but then it gets
|
|
|
|
awkward for the user to go back and correct screw up's
|
|
|
|
in the per-interface section */
|
|
|
|
|
1995-05-16 02:53:31 +00:00
|
|
|
case KEY_DOWN:
|
1995-05-16 20:00:51 +00:00
|
|
|
case SEL_TAB:
|
1996-09-01 08:17:14 +00:00
|
|
|
case SEL_CR:
|
1995-05-26 08:41:52 +00:00
|
|
|
if (n < max)
|
1995-05-16 20:00:51 +00:00
|
|
|
++n;
|
1995-05-26 08:41:52 +00:00
|
|
|
else
|
1995-05-16 20:00:51 +00:00
|
|
|
n = 0;
|
|
|
|
break;
|
|
|
|
|
1995-05-17 12:09:11 +00:00
|
|
|
/* The user has pressed enter over a button object */
|
1995-05-16 02:53:31 +00:00
|
|
|
case SEL_BUTTON:
|
1995-05-26 08:41:52 +00:00
|
|
|
if (cancelbutton)
|
1995-05-16 11:37:27 +00:00
|
|
|
cancel = TRUE, quit = TRUE;
|
1995-05-26 08:41:52 +00:00
|
|
|
else {
|
1995-05-16 11:37:27 +00:00
|
|
|
if (verifySettings())
|
|
|
|
quit = TRUE;
|
|
|
|
}
|
1995-05-16 02:53:31 +00:00
|
|
|
break;
|
|
|
|
|
1996-09-01 08:17:14 +00:00
|
|
|
case KEY_UP:
|
1995-05-16 02:53:31 +00:00
|
|
|
case SEL_BACKTAB:
|
|
|
|
if (n)
|
|
|
|
--n;
|
|
|
|
else
|
|
|
|
n = max;
|
|
|
|
break;
|
1995-05-21 15:40:54 +00:00
|
|
|
|
1995-05-17 14:40:00 +00:00
|
|
|
case KEY_F(1):
|
|
|
|
display_helpfile();
|
1995-05-16 02:53:31 +00:00
|
|
|
|
1995-05-17 12:09:11 +00:00
|
|
|
/* They tried some key combination we don't support - tell them! */
|
1995-05-16 02:53:31 +00:00
|
|
|
default:
|
|
|
|
beep();
|
|
|
|
}
|
1995-05-30 08:29:07 +00:00
|
|
|
|
1995-05-17 12:09:11 +00:00
|
|
|
/* BODGE ALERT! */
|
1995-05-26 20:31:02 +00:00
|
|
|
if (((tmp = index(hostname, '.')) != NULL) && (strlen(domainname)==0)) {
|
1995-05-17 12:09:11 +00:00
|
|
|
strncpy(domainname, tmp + 1, strlen(tmp + 1));
|
|
|
|
domainname[strlen(tmp+1)] = '\0';
|
|
|
|
RefreshStringObj(layout[1].obj);
|
1995-05-16 02:53:31 +00:00
|
|
|
}
|
|
|
|
}
|
1995-05-16 11:37:27 +00:00
|
|
|
|
1995-05-17 12:09:11 +00:00
|
|
|
/* Clear this crap off the screen */
|
1996-08-03 10:11:56 +00:00
|
|
|
dialog_clear_norefresh();
|
1995-05-17 14:40:00 +00:00
|
|
|
use_helpfile(NULL);
|
1995-05-30 08:29:07 +00:00
|
|
|
|
1995-05-17 12:09:11 +00:00
|
|
|
/* We actually need to inform the rest of sysinstall about this
|
|
|
|
data now - if the user hasn't selected cancel, save the stuff
|
|
|
|
out to the environment via the variable_set layers */
|
1995-05-16 11:37:27 +00:00
|
|
|
|
1995-05-16 02:53:31 +00:00
|
|
|
if (!cancel) {
|
1995-05-26 08:41:52 +00:00
|
|
|
DevInfo *di;
|
1995-12-07 10:34:59 +00:00
|
|
|
char temp[512], ifn[255];
|
1995-06-11 19:33:05 +00:00
|
|
|
char *ifaces;
|
1995-05-26 08:41:52 +00:00
|
|
|
|
1995-05-16 11:37:27 +00:00
|
|
|
variable_set2(VAR_HOSTNAME, hostname);
|
1996-06-17 23:04:24 +00:00
|
|
|
sethostname(hostname, strlen(hostname));
|
1995-06-11 19:33:05 +00:00
|
|
|
if (domainname[0])
|
|
|
|
variable_set2(VAR_DOMAINNAME, domainname);
|
1995-05-16 11:37:27 +00:00
|
|
|
if (gateway[0])
|
|
|
|
variable_set2(VAR_GATEWAY, gateway);
|
|
|
|
if (nameserver[0])
|
|
|
|
variable_set2(VAR_NAMESERVER, nameserver);
|
1995-05-17 12:09:11 +00:00
|
|
|
|
1995-05-26 08:41:52 +00:00
|
|
|
if (!devp->private)
|
1996-06-12 17:09:34 +00:00
|
|
|
devp->private = (DevInfo *)safe_malloc(sizeof(DevInfo));
|
1995-05-26 08:41:52 +00:00
|
|
|
di = devp->private;
|
|
|
|
strcpy(di->ipaddr, ipaddr);
|
|
|
|
strcpy(di->netmask, netmask);
|
|
|
|
strcpy(di->extras, extras);
|
|
|
|
|
|
|
|
sprintf(temp, "inet %s %s netmask %s", ipaddr, extras, netmask);
|
|
|
|
sprintf(ifn, "%s%s", VAR_IFCONFIG, devp->name);
|
|
|
|
variable_set2(ifn, temp);
|
1995-12-07 10:34:59 +00:00
|
|
|
ifaces = variable_get(VAR_INTERFACES);
|
1995-06-11 19:33:05 +00:00
|
|
|
if (!ifaces)
|
|
|
|
variable_set2(VAR_INTERFACES, ifaces = "lo0");
|
|
|
|
/* Only add it if it's not there already */
|
|
|
|
if (!strstr(ifaces, devp->name)) {
|
|
|
|
sprintf(ifn, "%s %s", devp->name, ifaces);
|
|
|
|
variable_set2(VAR_INTERFACES, ifn);
|
|
|
|
}
|
1995-05-26 19:28:06 +00:00
|
|
|
if (ipaddr[0])
|
|
|
|
variable_set2(VAR_IPADDR, ipaddr);
|
1996-04-23 01:29:35 +00:00
|
|
|
restorescr(save);
|
1996-04-13 13:32:15 +00:00
|
|
|
return DITEM_SUCCESS;
|
1995-05-16 11:37:27 +00:00
|
|
|
}
|
1996-04-23 01:29:35 +00:00
|
|
|
restorescr(save);
|
1996-04-13 13:32:15 +00:00
|
|
|
return DITEM_FAILURE;
|
1995-05-16 02:53:31 +00:00
|
|
|
}
|
1995-05-21 15:40:54 +00:00
|
|
|
|
|
|
|
static int
|
1996-04-13 13:32:15 +00:00
|
|
|
netHook(dialogMenuItem *self)
|
1995-05-21 15:40:54 +00:00
|
|
|
{
|
|
|
|
Device **devs;
|
|
|
|
|
1996-04-13 13:32:15 +00:00
|
|
|
devs = deviceFind(self->prompt, DEVICE_TYPE_NETWORK);
|
1995-05-26 08:41:52 +00:00
|
|
|
if (devs) {
|
1996-07-08 10:08:22 +00:00
|
|
|
if (DITEM_STATUS(tcpOpenDialog(devs[0])) != DITEM_FAILURE)
|
|
|
|
mediaDevice = devs[0];
|
|
|
|
else
|
|
|
|
devs = NULL;
|
1995-05-26 08:41:52 +00:00
|
|
|
}
|
1996-04-13 13:32:15 +00:00
|
|
|
return devs ? DITEM_LEAVE_MENU : DITEM_FAILURE;
|
1995-05-21 15:40:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get a network device */
|
1995-06-11 19:33:05 +00:00
|
|
|
Boolean
|
|
|
|
tcpDeviceSelect(void)
|
1995-05-21 15:40:54 +00:00
|
|
|
{
|
|
|
|
DMenu *menu;
|
1995-06-11 19:33:05 +00:00
|
|
|
Device **devs;
|
|
|
|
int cnt;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
devs = deviceFind(NULL, DEVICE_TYPE_NETWORK);
|
|
|
|
cnt = deviceCount(devs);
|
|
|
|
if (!cnt) {
|
|
|
|
msgConfirm("No network devices available!");
|
|
|
|
status = FALSE;
|
|
|
|
}
|
1996-06-13 17:07:41 +00:00
|
|
|
else if (cnt == 1 || (!RunningAsInit && !Fake)) {
|
1995-12-07 10:34:59 +00:00
|
|
|
/* If we're running in user mode, assume network already up */
|
1996-09-01 08:17:14 +00:00
|
|
|
if (!RunningAsInit) {
|
1996-07-08 10:08:22 +00:00
|
|
|
if (DITEM_STATUS(tcpOpenDialog(devs[0]) == DITEM_FAILURE))
|
|
|
|
return FALSE;
|
|
|
|
}
|
1996-04-28 00:37:38 +00:00
|
|
|
else
|
1996-05-21 15:57:21 +00:00
|
|
|
msgDebug("Running multi-user, assuming that the network is already up\n");
|
1995-06-11 19:33:05 +00:00
|
|
|
mediaDevice = devs[0];
|
|
|
|
status = TRUE;
|
|
|
|
}
|
|
|
|
else {
|
1996-04-13 13:32:15 +00:00
|
|
|
menu = deviceCreateMenu(&MenuNetworkDevice, DEVICE_TYPE_NETWORK, netHook, NULL);
|
1995-06-11 19:33:05 +00:00
|
|
|
if (!menu)
|
|
|
|
msgFatal("Unable to create network device menu! Argh!");
|
1996-07-02 01:03:55 +00:00
|
|
|
status = dmenuOpenSimple(menu, FALSE);
|
1995-06-11 19:33:05 +00:00
|
|
|
free(menu);
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
1995-05-21 15:40:54 +00:00
|
|
|
|
1995-06-11 19:33:05 +00:00
|
|
|
/* Do it from a menu that doesn't care about status */
|
|
|
|
int
|
1996-04-07 03:52:36 +00:00
|
|
|
tcpMenuSelect(dialogMenuItem *self)
|
1995-06-11 19:33:05 +00:00
|
|
|
{
|
|
|
|
(void)tcpDeviceSelect();
|
|
|
|
configResolv();
|
1996-04-28 00:37:38 +00:00
|
|
|
return DITEM_SUCCESS | DITEM_RECREATE | DITEM_RESTORE;
|
1995-05-21 15:40:54 +00:00
|
|
|
}
|