From 438672ae1d6f499b72b26a36a29de5557e24f558 Mon Sep 17 00:00:00 2001 From: Joshua Kwan Date: Wed, 12 May 2004 16:21:06 +0000 Subject: [PATCH] write ask_dhcp_retry, and destroy my_debconf_input r15228 --- TODO | 4 +-- dhcp.c | 26 ++++++++++++++++- netcfg-common.c | 42 +++++++++++++------------- netcfg.h | 2 -- static.c | 78 +++++++++++++++++++++++++++++++++---------------- wireless.c | 19 +++++++++--- 6 files changed, 116 insertions(+), 55 deletions(-) diff --git a/TODO b/TODO index 94c2d37e..feca02fc 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -* do other sorts of network configurations (pcmcia, ppp) +* do other sorts of network configurations (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. @@ -10,5 +10,3 @@ or retry DHCP without sacrificing UI usability * rewrite the whole getif() mess without static buffers - -* stop using my_debconf_input diff --git a/dhcp.c b/dhcp.c index 7b558951..36f44dc7 100644 --- a/dhcp.c +++ b/dhcp.c @@ -206,7 +206,30 @@ int poll_dhcp_client (struct debconfclient *client) int ask_dhcp_retry (struct debconfclient *client) { - return 0; + int ret; + + /* critical, we don't want to enter a loop */ + debconf_input(client, "critical", "netcfg/dhcp_retry"); + ret = debconf_go(client); + + if (ret == 30) + return GO_BACK; + + debconf_get(client, "netcfg/dhcp_retry"); + + /* strcmp sucks */ + if (client->value[0] == 'R') + { + /* with DHCP hostnam_e_ */ + if (client->value[strlen(client->value) - 1] == 'e') + return 1; + else + return 0; + } + else if (client->value[0] == 'C') + return 2; /* manual */ + else + return 3; /* no config */ } /* Here comes another Satan machine. */ @@ -236,6 +259,7 @@ int netcfg_activate_dhcp (struct debconfclient *client) /* ooh, now it's a select */ switch (ask_dhcp_retry (client)) { + case GO_BACK: exit(10); /* XXX */ case 0: state = POLL; break; case 1: state = DHCP_HOSTNAME; break; case 2: state = STATIC; break; diff --git a/netcfg-common.c b/netcfg-common.c index 55a2ccd5..da435024 100644 --- a/netcfg-common.c +++ b/netcfg-common.c @@ -51,17 +51,6 @@ int have_domain = 0; pid_t dhcp_pid = -1; -int my_debconf_input(struct debconfclient *client, char *priority, - char *template, char **p) -{ - int ret = 0; - debconf_input(client, priority, template); - ret = debconf_go(client); - debconf_get(client, template); - *p = client->value; - return ret; -} - int is_interface_up(char *inter) { struct ifreq ifr; @@ -333,8 +322,15 @@ int netcfg_get_interface(struct debconfclient *client, char **interface, debconf_subst(client, "netcfg/choose_interface", "ifchoices", ptr); free(ptr); - ret = my_debconf_input(client, "high", - "netcfg/choose_interface", &inter); + + debconf_input(client, "high", "netcfg/choose_interface"); + ret = debconf_go(client); + + if (ret) + return ret; + + debconf_get(client, "netcfg/choose_interface"); + inter = client->value; if (ret) return ret; @@ -374,15 +370,20 @@ int netcfg_get_hostname(struct debconfclient *client, char *template, char **hos "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-."; size_t len; int ret; - char *p, *s; + char *s; do { have_domain = 0; - ret = my_debconf_input(client, "high", template, &p); + debconf_input(client, "high", template); + ret = debconf_go(client); + if (ret == 30) /* backup */ - return ret; + return ret; + + debconf_get(client, template); + free(*hostname); - *hostname = strdup(p); + *hostname = strdup(client->value); len = strlen(*hostname); /* Check the hostname for RFC 1123 compliance. */ @@ -575,14 +576,15 @@ void seed_hostname_from_dns (struct debconfclient * client) }; struct addrinfo *res; char ip[16]; /* 255.255.255.255 + 1 */ + int err; /* convert ipaddress into a char* */ inet_ntop(AF_INET, (void*)&ipaddress, ip, 16); /* attempt resolution */ - getaddrinfo(ip, NULL, &hints, &res); + err = getaddrinfo(ip, NULL, &hints, &res); - /* got it */ - if (res->ai_canonname && !empty_str(res->ai_canonname)) + /* got it? */ + if (!err && res->ai_canonname && !empty_str(res->ai_canonname)) debconf_set(client, "netcfg/get_hostname", res->ai_canonname); } diff --git a/netcfg.h b/netcfg.h index 755ae3c9..df687549 100644 --- a/netcfg.h +++ b/netcfg.h @@ -83,8 +83,6 @@ extern int kill_dhcp_client(void); extern int ask_dhcp_retry (struct debconfclient *client); extern int netcfg_activate_static(struct debconfclient *client); -extern int my_debconf_input(struct debconfclient *client, char *priority, char *template, char **result); - extern void netcfg_write_common (const char *prebaseconfig, struct in_addr ipaddress, char *hostname, char *domain); diff --git a/static.c b/static.c index 34af5237..529ec295 100644 --- a/static.c +++ b/static.c @@ -21,17 +21,19 @@ struct in_addr pointopoint = { 0 }; int netcfg_get_ipaddress(struct debconfclient *client) { int ret, ok = 0; - char *ptr; old_ipaddress = ipaddress; while (!ok) { - ret = my_debconf_input(client,"critical", "netcfg/get_ipaddress", &ptr); + debconf_input (client, "critical", "netcfg/get_ipaddress"); + ret = debconf_go (client); + if (ret) - return ret; + return ret; - ok = inet_pton (AF_INET, ptr, &ipaddress); + debconf_get(client, "netcfg/get_ipaddress"); + ok = inet_pton (AF_INET, client->value, &ipaddress); if (!ok) { @@ -46,21 +48,24 @@ int netcfg_get_ipaddress(struct debconfclient *client) int netcfg_get_pointopoint(struct debconfclient *client) { int ret, ok = 0; - char *ptr; while (!ok) { - ret = my_debconf_input(client,"critical", "netcfg/get_pointopoint", &ptr); - if (ret) - return ret; + debconf_input(client, "critical", "netcfg/get_pointopoint"); + ret = debconf_go(client); + + if (ret) + return ret; - if (empty_str(ptr)) /* No P-P is ok */ + debconf_get(client, "netcfg/get_pointopoint"); + + if (empty_str(client->value)) /* No P-P is ok */ { memset(&pointopoint, 0, sizeof(struct in_addr)); return 0; } - ok = inet_pton (AF_INET, ptr, &pointopoint); + ok = inet_pton (AF_INET, client->value, &pointopoint); if (!ok) { @@ -79,17 +84,20 @@ int netcfg_get_pointopoint(struct debconfclient *client) int netcfg_get_netmask(struct debconfclient *client) { int ret, ok = 0; - char *ptr, ptr1[INET_ADDRSTRLEN]; + char ptr1[INET_ADDRSTRLEN]; struct in_addr old_netmask = netmask; while (!ok) { - ret = my_debconf_input(client,"critical", "netcfg/get_netmask", &ptr); + debconf_input (client, "critical", "netcfg/get_netmask"); + ret = debconf_go(client); if (ret) - return ret; + return ret; + + debconf_get (client, "netcfg/get_netmask"); - ok = inet_pton (AF_INET, ptr, &netmask); + ok = inet_pton (AF_INET, client->value, &netmask); if (!ok) { @@ -120,7 +128,6 @@ int netcfg_get_netmask(struct debconfclient *client) int netcfg_get_domain(struct debconfclient *client, char **domain) { int ret; - char *ptr; if (have_domain == 1) { @@ -131,15 +138,20 @@ int netcfg_get_domain(struct debconfclient *client, char **domain) *domain = strdup(client->value); return 0; } - - ret = my_debconf_input(client, "high", "netcfg/get_domain", &ptr); + + debconf_input (client, "high", "netcfg/get_domain"); + ret = debconf_go(client); + if (ret) - return ret; + return ret; + + debconf_get (client, "netcfg/get_domain"); + if (*domain) free(*domain); *domain = NULL; - if (ptr && ptr[0]) - *domain = strdup(ptr); + if (!empty_str(client->value)) + *domain = strdup(client->value); return 0; } @@ -150,10 +162,15 @@ int netcfg_get_gateway(struct debconfclient *client) while (!ok) { - ret = my_debconf_input(client, "critical", "netcfg/get_gateway", &ptr); + debconf_input (client, "critical", "netcfg/get_gateway"); + ret = debconf_go(client); + if (ret) return ret; + debconf_get(client, "netcfg/get_gateway"); + ptr = client->value; + if (empty_str(ptr)) /* No gateway, that's fine */ { /* clear existing gateway setting */ @@ -189,7 +206,15 @@ int netcfg_get_nameservers (struct debconfclient *client, char **nameservers) ptr = ""; debconf_set(client, "netcfg/get_nameservers", ptr); - ret = my_debconf_input(client, "high", "netcfg/get_nameservers", &ptr); + debconf_input(client, "high", "netcfg/get_nameservers"); + ret = debconf_go(client); + + if (ret) + return ret; + + debconf_get(client, "netcfg/get_nameservers"); + ptr = client->value; + if (*nameservers) free(*nameservers); *nameservers = NULL; @@ -353,7 +378,7 @@ int netcfg_activate_static(struct debconfclient *client) int netcfg_get_static(struct debconfclient *client) { char *nameservers = NULL; - char *ptr, ptr1[INET_ADDRSTRLEN]; + char ptr1[INET_ADDRSTRLEN]; char *none; enum { BACKUP, GET_IPADDRESS, GET_POINTOPOINT, GET_NETMASK, GET_GATEWAY, @@ -436,8 +461,11 @@ int netcfg_get_static(struct debconfclient *client) netcfg_nameservers_to_array(nameservers, nameserver_array); debconf_capb(client); /* Turn off backup for yes/no confirmation */ - my_debconf_input(client, "medium", "netcfg/confirm_static", &ptr); - state = strstr(ptr, "true") ? QUIT : GET_IPADDRESS; + + debconf_input(client, "medium", "netcfg/confirm_static"); + debconf_go(client); + debconf_get(client, "netcfg/confirm_static"); + state = strstr(client->value, "true") ? QUIT : GET_IPADDRESS; debconf_capb(client, "backup"); break; case QUIT: diff --git a/wireless.c b/wireless.c index f7922bba..4ad91e0f 100644 --- a/wireless.c +++ b/wireless.c @@ -190,10 +190,14 @@ int netcfg_wireless_set_wep (struct debconfclient * client, char* iface) iw_get_basic_config (wfd, iface, &wconf); debconf_subst(client, "netcfg/wireless_wep", "iface", iface); - ret = my_debconf_input (client, "high", "netcfg/wireless_wep", &rv); - + debconf_input (client, "high", "netcfg/wireless_wep"); + ret = debconf_go(client); + if (ret == 30) return GO_BACK; + + debconf_get(client, "netcfg/wireless_wep"); + rv = client->value; if (empty_str(rv)) { @@ -211,10 +215,17 @@ int netcfg_wireless_set_wep (struct debconfclient * client, char* iface) while ((keylen = iw_in_key (rv, buf)) == -1) { debconf_subst(client, "netcfg/invalid_wep", "wepkey", rv); - debconf_input(client, "high", "netcfg/invalid_wep"); + debconf_input(client, "critical", "netcfg/invalid_wep"); debconf_go(client); - ret = my_debconf_input (client, "high", "netcfg/wireless_wep", &rv); + debconf_input (client, "high", "netcfg/wireless_wep"); + ret = debconf_go(client); + + if (ret == 30) + return GO_BACK; + + debconf_get(client, "netcfg/wireless_wep"); + rv = client->value; } wconf.has_key = 1;