Browse Source

I was handling the debconf substitution wrong, the result of splitting static and dhcp up, but not doing it properly. removed support for dhcpcd since it is no longer with us.

r348
master
David Whedon 22 years ago
parent
commit
aba0cb9c0d
  1. 50
      netcfg-dhcp.c
  2. 20
      netcfg-static.c
  3. 87
      netcfg.c
  4. 8
      netcfg.h

50
netcfg-dhcp.c

@ -22,7 +22,7 @@ static char *interface = NULL;
static char *hostname = NULL;
static char *domain = NULL;
static u_int32_t ipaddress = 0;
static u_int32_t nameservers[4] = { 0 };
static u_int32_t nameserver_array[4] = { 0 };
static struct debconfclient *client;
@ -49,7 +49,11 @@ netcfg_get_dhcp ()
client->command (client, "get", "netcfg/dhcp_hostname", NULL);
if (client->value)
dhcp_hostname = strdup (client->value);
dhcp_hostname = strdup (client->value);
client->command (client, "subst", "netcfg/confirm_dhcp",
"dhcp_hostname",
(dhcp_hostname ? dhcp_hostname : "<none>"), NULL);
}
@ -66,18 +70,7 @@ netcfg_write_dhcp ()
fprintf (fp, "iface %s inet dhcp\n", interface);
fclose (fp);
}
#ifdef DHCPCD
netcfg_mkdir (DHCPCD_DIR);
if ((fp = file_open (DHCPCD_FILE)))
{
fprintf (fp,
"\n# dhcpcd configuration: created during the Debian installation\n");
fprintf (fp, "IFACE=%s\n", interface);
if (dhcp_hostname)
fprintf (fp, "OPTIONS='-h %s'\n", dhcp_hostname);
fclose (fp);
}
#elif defined PUMP
#if defined PUMP
/* nothing to do */
#elif defined DHCLIENT
@ -105,16 +98,7 @@ netcfg_activate_dhcp ()
execlog ("/sbin/ifconfig lo 127.0.0.1");
ptr = buf;
#ifdef DHCPCD
ptr += snprintf (buf, sizeof (buf), "/sbin/dhcpcd-2.2.x");
if (dhcp_hostname)
ptr +=
snprintf (ptr, sizeof (buf) - (ptr - buf), " -h %s", dhcp_hostname);
ptr += snprintf (ptr, sizeof (buf) - (ptr - buf), " %s", interface);
#elif defined PUMP
#if defined PUMP
ptr += snprintf (buf, sizeof (buf), "/sbin/pump -i %s", interface);
if (dhcp_hostname)
@ -139,23 +123,31 @@ int
main (int argc, char *argv[])
{
char *ptr;
char *nameservers=NULL;
int finished = 1;
client = debconfclient_new ();
client->command (client, "title", "DHCP Network Configuration", NULL);
do
{
netcfg_get_common (client, interface, hostname, domain, nameservers);
netcfg_get_dhcp ();
netcfg_get_common (client, &interface, &hostname, &domain, &nameservers);
client->command (client, "subst", "netcfg/confirm_dhcp", "interface",
interface, NULL);
client->command (client, "subst", "netcfg/confirm_dhcp", "hostname",
hostname, NULL);
client->command (client, "subst", "netcfg/confirm_dhcp", "domain",
(domain ? domain : "<none>"), NULL);
netcfg_nameservers_to_array(nameservers, nameserver_array);
client->command (client, "subst", "netcfg/confirm_dhcp",
"dhcp_hostname",
(dhcp_hostname ? dhcp_hostname : "<none>"), NULL);
"nameservers", (nameservers ? nameservers : "<none>"), NULL);
netcfg_get_dhcp ();
ptr = debconf_input ("medium", "netcfg/confirm_dhcp");
if (strstr (ptr, "true"))
@ -164,7 +156,7 @@ main (int argc, char *argv[])
while (!finished);
netcfg_write_dhcp ();
netcfg_write_common (ipaddress, domain, hostname, nameservers);
netcfg_write_common (ipaddress, domain, hostname, nameserver_array);
debconf_input ("medium", "netcfg/do_dhcp");
netcfg_activate_dhcp ();

20
netcfg-static.c

@ -23,7 +23,7 @@ static char *interface = NULL;
static char *hostname = NULL;
static char *domain = NULL;
static u_int32_t ipaddress = 0;
static u_int32_t nameservers[4] = { 0 };
static u_int32_t nameserver_array[4] = { 0 };
static u_int32_t network = 0;
static u_int32_t broadcast = 0;
static u_int32_t netmask = 0;
@ -77,7 +77,6 @@ netcfg_get_static ()
broadcast = (network | ~netmask);
}
@ -148,19 +147,30 @@ main (int argc, char *argv[])
{
int finished = 0;
char *ptr;
char *nameservers=NULL;
client = debconfclient_new ();
client->command (client, "title", "Static Network Configuration", NULL);
do
{
netcfg_get_common (client, interface, hostname, domain, nameservers);
netcfg_get_common (client, &interface, &hostname, &domain, &nameservers);
client->command (client, "subst", "netcfg/confirm_static", "interface",
interface, NULL);
client->command (client, "subst", "netcfg/confirm_static",
"hostname", hostname, NULL);
client->command (client, "subst", "netcfg/confirm_static", "domain",
(domain ? domain : "<none>"), NULL);
netcfg_nameservers_to_array(nameservers, nameserver_array);
client->command (client, "subst", "netcfg/confirm_static",
"nameservers", (nameservers ? nameservers : "<none>") , NULL);
netcfg_get_static ();
ptr = debconf_input ("medium", "netcfg/confirm_static");
if (strstr (ptr, "true"))
@ -169,7 +179,7 @@ main (int argc, char *argv[])
}
while (!finished);
netcfg_write_common (ipaddress, domain, hostname, nameservers);
netcfg_write_common (ipaddress, domain, hostname, nameserver_array);
netcfg_write_static ();
netcfg_activate_static ();

87
netcfg.c

@ -272,7 +272,7 @@ netcfg_die (struct debconfclient *client)
static void
netcfg_get_interface (struct debconfclient *client, char *interface)
netcfg_get_interface (struct debconfclient *client, char **interface)
{
char *inter;
int len;
@ -280,10 +280,10 @@ netcfg_get_interface (struct debconfclient *client, char *interface)
char *ptr;
int num_interfaces = 0;
if (interface)
if (*interface)
{
free (interface);
interface = NULL;
free (*interface);
*interface = NULL;
}
if (!(ptr = malloc (128)))
@ -329,15 +329,13 @@ netcfg_get_interface (struct debconfclient *client, char *interface)
inter = ptr;
/* grab just the interface name, not the description too */
interface = inter;
*interface = inter;
ptr = strchr (inter, ':');
if (ptr == NULL)
goto error;
*ptr = '\0';
interface = strdup (interface);
client->command (client, "subst", "netcfg/confirm_static", "interface",
interface, NULL);
*interface = strdup (*interface);
return;
@ -350,61 +348,64 @@ error:
void
netcfg_get_common (struct debconfclient *client, char *interface,
char *hostname, char *domain, u_int32_t nameservers[])
netcfg_get_common (struct debconfclient *client, char **interface,
char **hostname, char **domain, char **nameservers)
{
char *ptr, *ns;
char *ptr;
netcfg_get_interface (client, interface);
if (hostname)
if (*hostname)
{
free (hostname);
free (*hostname);
hostname = NULL;
}
hostname = strdup (debconf_input (client, "medium", "netcfg/get_hostname"));
*hostname = strdup (debconf_input (client, "medium", "netcfg/get_hostname"));
if (domain)
if (*domain)
{
free (domain);
domain = NULL;
free (*domain);
*domain = NULL;
}
if ((ptr = debconf_input (client, "medium", "netcfg/get_domain")))
domain = strdup (ptr);
*domain = strdup (ptr);
ptr = debconf_input (client, "medium", "netcfg/get_nameservers");
*nameservers = debconf_input (client, "medium", "netcfg/get_nameservers");
if (ptr)
{
char *save;
save = ptr = strdup (ptr);
#ifdef DHCP
client->command (client, "subst", "netcfg/confirm_dhcp",
"nameservers", ptr, NULL);
#else
client->command (client, "subst", "netcfg/confirm_static",
"nameservers", ptr, NULL);
#endif
ns = strtok_r (ptr, " ", &ptr);
dot2num (&nameservers[0], ns);
ns = strtok_r (NULL, " ", &ptr);
dot2num (&nameservers[1], ns);
ns = strtok_r (NULL, " ", &ptr);
dot2num (&nameservers[2], ns);
free (save);
}
else
nameservers[0] = 0;
}
void
netcfg_nameservers_to_array(char *nameservers, u_int32_t array[]){
char *save, *ptr, *ns;
if (nameservers)
{
save = ptr = strdup (ptr);
ns = strtok_r (ptr, " ", &ptr);
dot2num (&array[0], ns);
ns = strtok_r (NULL, " ", &ptr);
dot2num (&array[1], ns);
ns = strtok_r (NULL, " ", &ptr);
dot2num (&array[2], ns);
array[3]=0;
free (save);
}
else
nameservers[0] = 0;
}
void
netcfg_write_common (u_int32_t ipaddress, char *domain, char *hostname,
u_int32_t nameservers[])

8
netcfg.h

@ -33,11 +33,13 @@ extern char *num2dot (u_int32_t num);
extern void netcfg_die (struct debconfclient *client);
extern void netcfg_get_common (struct debconfclient *client, char *interface,
char *hostname, char *domain,
u_int32_t nameservers[]);
extern void netcfg_get_common (struct debconfclient *client, char **interface,
char **hostname, char **domain,
char **nameservers);
extern void netcfg_write_common (u_int32_t ipaddress, char *domain,
char *hostname, u_int32_t nameservers[]);
void netcfg_nameservers_to_array(char *nameservers, u_int32_t array[]);
#endif /* _NETCFG_H_ */

Loading…
Cancel
Save