Browse Source

check hostname to make sure it is valid

some cleanups

r930
master
David Whedon 21 years ago
parent
commit
5c8bf698f1
  1. 5
      Makefile
  2. 22
      TODO
  3. 6
      debian/template/netcfg-common.templates.en
  4. 2
      debian/template/netcfg-dhcp.templates.en
  5. 1
      netcfg-dhcp.c
  6. 1
      netcfg-static.c
  7. 65
      netcfg.c

5
Makefile

@ -21,14 +21,9 @@ all: $(TARGETS)
netcfg-dhcp netcfg-static: netcfg-dhcp.c netcfg.o
$(CC) $(CFLAGS) $@.c -o $@ $(INCS) $(LDOPTS) netcfg.o
$(STRIP) $@
size $@
netcfg.o: netcfg.c
$(CC) -c $(CFLAGS) netcfg.c -o $@ $(INCS)
test: netcfg.o
cc -g test.c netcfg.o -o test
clean:
rm -f netcfg-dhcp netcfg-static *.o

22
TODO

@ -1,7 +1,19 @@
* put in checks so the user can't enter data that is clearly invalid (perhaps this will be done through debconf.
* try to do dhcp first without asking for a specific DHCP hostname, just ask for
the hostname that will be written to /etc/hosts. If DHCP fails then have a
dialog indicating that some cable modem providers require you to specify a
special DHCP hostname. You can enter that here now if you want.
* Nameserver and domain are in the common configuration? Should they be?
* we should send a dhcp hostname
* put in checks so the user can't enter data that is clearly invalid (perhaps
this will be done through debconf.
* do other sorts of network configurations (pcmcia, ppp)
* pppconfig would be a good starting point for the ppp udeb. There is also an example in there of how to use pppd to detect a modem.
* netcfg-dhcp : when we use dhclient if we don't obtain a lease, dhclient goes
into the background and the installer thinks that it succeeded. This isn't
right.
* pppconfig would be a good starting point for the ppp udeb. There is also an
example in there of how to use pppd to detect a modem.

6
debian/template/netcfg-common.templates.en

@ -37,6 +37,12 @@ Description: Enter the system's hostname.
your network administrator. If you are setting up your own home
network, you can make something up here.
Template: netcfg/invalid_hostname
Type: note
Description: The hostname "${hostname}" is invalid.
A valid hostname may contain only alphanumeric characters and the minus sign,
be between 2 and 63 characters long, and cannot begin or end with a minus sign.
Template: netcfg/error
Type: note
Description: An error occured and I cannot continue.

2
debian/template/netcfg-dhcp.templates.en

@ -3,7 +3,7 @@ Type: string
Description: What is your dhcp hostname?
In some situations, you may need to supply a DHCP host name. These
situations are rare. Most commonly, it applies to cable modem users.
If you are a cable modem user, you might often need to specify an
If you are a cable modem user, you might need to specify an
account number here. Otherwise, you can just leave this blank.
Template: netcfg/confirm_dhcp

1
netcfg-dhcp.c

@ -1,6 +1,5 @@
/*
netcfg-dhcp.c - Configure a network via dhcp for the debian-installer
Author - David Kimdon
Copyright (C) 2000-2002 David Kimdon <dwhedon@debian.org>

1
netcfg-static.c

@ -1,6 +1,5 @@
/*
netcfg-static.c - Configure a static network for the debian-installer
Author - David Kimdon
Copyright (C) 2000-2002 David Kimdon <dwhedon@debian.org>

65
netcfg.c

@ -1,7 +1,6 @@
/*
netcfg.c - Shared functions used to configure the network for
the debian-installer.
Author - David Kimdon
Copyright (C) 2000-2002 David Kimdon <dwhedon@debian.org>
@ -18,6 +17,7 @@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <ctype.h>
@ -323,28 +323,49 @@ netcfg_get_common(struct debconfclient *client, char **interface,
char **hostname, char **domain, char **nameservers)
{
char *ptr;
static const char *valid_chars =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-";
size_t len;
netcfg_get_interface(client, interface);
if (*hostname) {
free(*hostname);
*hostname = NULL;
}
*hostname =
strdup(debconf_input(client, "medium", "netcfg/get_hostname"));
if (*domain) {
free(*domain);
}
*domain = NULL;
if ((ptr = debconf_input(client, "medium", "netcfg/get_domain")))
do {
free(*hostname);
*hostname =
strdup(debconf_input
(client, "medium", "netcfg/get_hostname"));
len = strlen(*hostname);
/* Check the hostname for RFC 1123 compliance. */
if ((len < 2) ||
(len > 63) ||
(strspn(*hostname, valid_chars) != len) ||
(*hostname[len - 1] == '-') ||
(*hostname[0] == '-')) {
client->command(client, "subst", "netcfg/invalid_hostname",
"hostname", *hostname, NULL);
client->command(client, "input", "high",
"netcfg/invalid_hostname", NULL);
client->command(client, "go", NULL);
free(*hostname);
*hostname = NULL;
}
} while (!hostname);
free(*domain);
*domain = NULL;
if ((ptr = debconf_input(client, "medium", "netcfg/get_domain")))
*domain = strdup(ptr);
if (*nameservers) {
free(*nameservers);
}
*nameservers = NULL;
free(*nameservers);
*nameservers = NULL;
if ((ptr =
debconf_input(client, "medium", "netcfg/get_nameservers")))
*nameservers = strdup(ptr);
@ -378,8 +399,8 @@ void netcfg_nameservers_to_array(char *nameservers, u_int32_t array[])
void
netcfg_write_common(u_int32_t ipaddress, char *domain, char *hostname,
u_int32_t nameservers[])
netcfg_write_common(u_int32_t ipaddress, char *domain, char *hostname,
u_int32_t nameservers[])
{
FILE *fp;
@ -390,10 +411,10 @@ netcfg_write_common(u_int32_t ipaddress, char *domain, char *hostname,
if (domain)
fprintf(fp, "%s\t%s.%s\t%s\n",
num2dot(ipaddress), hostname,
domain, hostname);
domain, hostname);
else
fprintf(fp, "%s\t%s\n", num2dot(ipaddress),
hostname);
hostname);
}
fclose(fp);

Loading…
Cancel
Save