int netcfg_wireless_auto_connect(struct debconfclient *client, char *iface, wireless_config *wconf, int *couldnt_associate) { int i, success = 0; /* Default to any AP */ wconf->essid[0] = '\0'; wconf->essid_on = 0; iw_set_basic_config (wfd, iface, wconf); /* Wait for association.. (MAX_SECS seconds)*/ #ifndef MAX_SECS #define MAX_SECS 3 #endif debconf_capb(client, "backup progresscancel"); debconf_progress_start(client, 0, MAX_SECS, "netcfg/wifi_progress_title"); if (debconf_progress_info(client, "netcfg/wifi_progress_info") == 30) goto stop; netcfg_progress_displayed = 1; for (i = 0; i <= MAX_SECS; i++) { int progress_ret; interface_up(iface); sleep (1); iw_get_basic_config (wfd, iface, wconf); if (!empty_str(wconf->essid)) { /* Save for later */ debconf_set(client, "netcfg/wireless_essid", wconf->essid); debconf_progress_set(client, MAX_SECS); success = 1; break; } progress_ret = debconf_progress_step(client, 1); interface_down(iface); if (progress_ret == 30) break; } stop: debconf_progress_stop(client); debconf_capb(client, "backup"); netcfg_progress_displayed = 0; if (success) return 0; *couldnt_associate = 1; return *couldnt_associate; }
int poll_wpa_supplicant(struct debconfclient *client) { int wpa_timeout = 60; int seconds_slept = 0; int state = 1; debconf_capb(client, "backup progresscancel"); debconf_progress_start(client, 0, wpa_timeout, "netcfg/wpa_progress"); for (seconds_slept = 0; seconds_slept <= wpa_timeout; seconds_slept++) { if (debconf_progress_info(client, "netcfg/wpa_progress_note") == CMD_PROGRESSCANCELLED) goto stop; if (debconf_progress_step(client, 1) == CMD_PROGRESSCANCELLED) goto stop; sleep(1); if ((seconds_slept <= wpa_timeout) && (seconds_slept % 5) == 0) { if (!wpa_status()) { debconf_progress_set(client, wpa_timeout); debconf_progress_info(client, "netcfg/wpa_success_note"); state = 0; sleep(2); goto stop; } } if (seconds_slept == wpa_timeout) { debconf_progress_stop(client); debconf_capb(client, "backup"); debconf_capb(client, ""); debconf_input(client, "critical", "netcfg/wpa_supplicant_failed"); debconf_go(client); debconf_capb(client, "backup"); return 1; } } stop: debconf_progress_stop(client); debconf_capb(client, "backup"); if (!state) return 0; else return 1; }
/* * Using the current debconf settings for a mirror, figure out which suite * to use from the mirror and set mirror/suite. * * This is accomplished by downloading the Release file from the mirror. * Suite selection tries each suite in turn, and stops at the first one that * seems usable. * * If no Release file is found, returns false. That probably means the * mirror is broken or unreachable. */ int find_suite (void) { char *command; FILE *f = NULL; char *hostname, *directory; int nbr_suites = sizeof(suites)/SUITE_LENGTH; int i; int ret = 0; char buf[SUITE_LENGTH]; if (show_progress) { debconf_progress_start(debconf, 0, 1, DEBCONF_BASE "checking_title"); debconf_progress_info(debconf, DEBCONF_BASE "checking_download"); } hostname = add_protocol("hostname"); debconf_get(debconf, hostname); free(hostname); hostname = strdup(debconf->value); directory = add_protocol("directory"); debconf_get(debconf, directory); free(directory); directory = strdup(debconf->value); /* Try each suite in turn until one is found that works. */ for (i=0; i <= nbr_suites && ! ret; i++) { char *suite; if (i == 0) { /* First check for a preseeded suite. */ debconf_get(debconf, DEBCONF_BASE "suite"); if (strlen(debconf->value) > 0) { suite = strdup(debconf->value); } else { /* Read this file to find the default suite * to use. */ f = fopen("/etc/default-release", "r"); if (f != NULL) { if (fgets(buf, SUITE_LENGTH - 1, f)) { if (buf[strlen(buf) - 1] == '\n') buf[strlen(buf) - 1] = '\0'; suite = strdup(buf); fclose(f); } else { fclose(f); continue; } } else { continue; } } } else { suite = strdup(suites[i - 1]); } asprintf(&command, "wget -q %s://%s%s/dists/%s/Release -O - | grep ^Suite: | cut -d' ' -f 2", protocol, hostname, directory, suite); di_log(DI_LOG_LEVEL_DEBUG, "command: %s", command); f = popen(command, "r"); free(command); if (f != NULL) { if (fgets(buf, SUITE_LENGTH - 1, f)) { if (buf[strlen(buf) - 1] == '\n') buf[strlen(buf) - 1] = '\0'; debconf_set(debconf, DEBCONF_BASE "suite", buf); ret = 1; } } pclose(f); free(suite); } free(hostname); free(directory); if (show_progress) { debconf_progress_step(debconf, 1); debconf_progress_stop(debconf); } return ret; }
int netcfg_wireless_set_essid (struct debconfclient * client, char *iface, char* priority) { int ret, couldnt_associate = 0; wireless_config wconf; char* tf = NULL, *user_essid = NULL, *ptr = wconf.essid; iw_get_basic_config (wfd, iface, &wconf); debconf_subst(client, "netcfg/wireless_essid", "iface", iface); debconf_subst(client, "netcfg/wireless_essid_again", "iface", iface); debconf_subst(client, "netcfg/wireless_adhoc_managed", "iface", iface); debconf_input(client, priority ? priority : "low", "netcfg/wireless_adhoc_managed"); if (debconf_go(client) == 30) return GO_BACK; debconf_get(client, "netcfg/wireless_adhoc_managed"); if (!strcmp(client->value, "Ad-hoc network (Peer to peer)")) mode = ADHOC; wconf.has_mode = 1; wconf.mode = mode; debconf_input(client, priority ? priority : "low", "netcfg/wireless_essid"); if (debconf_go(client) == 30) return GO_BACK; debconf_get(client, "netcfg/wireless_essid"); tf = strdup(client->value); automatic: /* question not asked or user doesn't care or we're successfully associated */ if (!empty_str(wconf.essid) || empty_str(client->value)) { int i, success = 0; /* Default to any AP */ wconf.essid[0] = '\0'; wconf.essid_on = 0; iw_set_basic_config (wfd, iface, &wconf); /* Wait for association.. (MAX_SECS seconds)*/ #define MAX_SECS 3 debconf_capb(client, "backup progresscancel"); debconf_progress_start(client, 0, MAX_SECS, "netcfg/wifi_progress_title"); if (debconf_progress_info(client, "netcfg/wifi_progress_info") == 30) goto stop; netcfg_progress_displayed = 1; for (i = 0; i <= MAX_SECS; i++) { int progress_ret; interface_up(iface); sleep (1); iw_get_basic_config (wfd, iface, &wconf); if (!empty_str(wconf.essid)) { /* Save for later */ debconf_set(client, "netcfg/wireless_essid", wconf.essid); debconf_progress_set(client, MAX_SECS); success = 1; break; } progress_ret = debconf_progress_step(client, 1); interface_down(iface); if (progress_ret == 30) break; } stop: debconf_progress_stop(client); debconf_capb(client, "backup"); netcfg_progress_displayed = 0; if (success) return 0; couldnt_associate = 1; } /* yes, wants to set an essid by himself */ if (strlen(tf) <= IW_ESSID_MAX_SIZE) /* looks ok, let's use it */ user_essid = tf; while (!user_essid || empty_str(user_essid) || strlen(user_essid) > IW_ESSID_MAX_SIZE) { /* Misnomer of a check. Basically, if we went through autodetection, * we want to enter this loop, but we want to suppress anything that * relied on the checking of tf/user_essid (i.e. "", in most cases.) */ if (!couldnt_associate) { debconf_subst(client, "netcfg/invalid_essid", "essid", user_essid); debconf_input(client, "high", "netcfg/invalid_essid"); debconf_go(client); } if (couldnt_associate) ret = debconf_input(client, "critical", "netcfg/wireless_essid_again"); else ret = debconf_input(client, "low", "netcfg/wireless_essid"); /* we asked the question once, why can't we ask it again? */ assert (ret != 30); if (debconf_go(client) == 30) /* well, we did, but he wants to go back */ return GO_BACK; if (couldnt_associate) debconf_get(client, "netcfg/wireless_essid_again"); else debconf_get(client, "netcfg/wireless_essid"); if (empty_str(client->value)) { if (couldnt_associate) /* we've already tried the empty string here, so give up */ break; else goto automatic; } /* But now we'd not like to suppress any MORE errors */ couldnt_associate = 0; free(user_essid); user_essid = strdup(client->value); } essid = user_essid; memset(ptr, 0, IW_ESSID_MAX_SIZE + 1); snprintf(wconf.essid, IW_ESSID_MAX_SIZE + 1, "%s", essid); wconf.has_essid = 1; wconf.essid_on = 1; iw_set_basic_config (wfd, iface, &wconf); return 0; }
static int find_releases(void) { int nbr_suites = sizeof(suites)/SUITE_LENGTH; int i, r = 0; int bad_mirror = 0, have_default = 0; struct release_t release; char *default_suite; default_suite = get_default_suite(); if (default_suite == NULL) di_log(DI_LOG_LEVEL_ERROR, "no default release specified"); if (show_progress) { debconf_progress_start(debconf, 0, nbr_suites, DEBCONF_BASE "checking_title"); debconf_progress_info(debconf, DEBCONF_BASE "checking_download"); } /* Initialize releases; also ensures NULL termination of the array */ memset(&releases, 0, sizeof(releases)); /* Try to get Release files for all suites. */ if (! base_on_cd) { for (i=0; i < nbr_suites && r < MAXRELEASES; i++) { memset(&release, 0, sizeof(release)); if (get_release(&release, suites[i])) { if (release.status & IS_VALID) { if (strcmp(release.name, default_suite) == 0 || strcmp(release.suite, default_suite) == 0) { release.status |= IS_DEFAULT; have_default = 1; } /* Only list oldstable if it's the default */ if (strcmp(suites[i], "oldstable") != 0 || (release.status & IS_DEFAULT)) releases[r++] = release; } else { bad_mirror = 1; break; } } if (show_progress) debconf_progress_step(debconf, 1); } if (r == MAXRELEASES) di_log(DI_LOG_LEVEL_ERROR, "array overflow: more releases than allowed by MAXRELEASES"); if (! bad_mirror && r == 0) di_log(DI_LOG_LEVEL_INFO, "mirror does not have any suite symlinks"); } /* Try to get Release file using the default "suite". */ if (! bad_mirror && (base_on_cd || ! have_default)) { memset(&release, 0, sizeof(release)); if (get_release(&release, default_suite)) { if (release.status & IS_VALID) { release.status |= IS_DEFAULT; releases[r++] = release; have_default = 1; } else { bad_mirror = 1; } } else { di_log(DI_LOG_LEVEL_WARNING, "mirror does not support the specified release (%s)", default_suite); } if (r == MAXRELEASES) di_log(DI_LOG_LEVEL_ERROR, "array overflow: more releases than allowed by MAXRELEASES"); } if (show_progress) { debconf_progress_set(debconf, nbr_suites); debconf_progress_stop(debconf); } if (r == 0 || bad_mirror) { unset_seen_flags(); free(default_suite); free(release.name); free(release.suite); debconf_input(debconf, "critical", DEBCONF_BASE "bad"); if (debconf_go(debconf) == 30) exit(10); /* back up to menu */ else return 1; /* back to beginning of questions */ } if (! base_on_cd && ! have_default) { unset_seen_flags(); debconf_subst(debconf, DEBCONF_BASE "no-default", "RELEASE", default_suite); free(default_suite); debconf_input(debconf, "critical", DEBCONF_BASE "no-default"); if (debconf_go(debconf) == 30) { exit(10); /* back up to menu */ } else { debconf_get(debconf, DEBCONF_BASE "no-default"); if (strcmp(debconf->value, "false")) return 1; /* back to beginning of questions */ } } else { free(default_suite); } return 0; }