/* Write out a static IPv4 config stanza for the given interface */ static int nc_wi_static_ipv4(const struct netcfg_interface *interface, FILE *fd) { char network[INET_ADDRSTRLEN]; char broadcast[INET_ADDRSTRLEN]; char netmask[INET_ADDRSTRLEN]; netcfg_network_address(interface, network); netcfg_broadcast_address(interface, broadcast); inet_mtop(AF_INET, interface->masklen, netmask, INET_ADDRSTRLEN); fprintf(fd, "\n# The primary network interface\n"); fprintf(fd, "auto %s\n", interface->name); fprintf(fd, "iface %s inet static\n", interface->name); fprintf(fd, "\taddress %s\n", interface->ipaddress); fprintf(fd, "\tnetmask %s\n", empty_str(interface->pointopoint) ? netmask : "255.255.255.255"); fprintf(fd, "\tnetwork %s\n", network); fprintf(fd, "\tbroadcast %s\n", broadcast); if (!empty_str(interface->gateway)) fprintf(fd, "\tgateway %s\n", empty_str(interface->pointopoint) ? interface->gateway : interface->pointopoint); if (!empty_str(interface->pointopoint)) fprintf(fd, "\tpointopoint %s\n", interface->pointopoint); return 1; }
static void grab_location(struct debuggee* dbg, struct location* loc, int addr_idx, int name_idx, int src_idx, int line_idx, int module_idx) { loc->address = (addr_idx != -1) ? (void*)to_num(dbg, addr_idx) : NULL; if (name_idx != -1) { int pos = rm[name_idx].rm_eo; size_t len = rm[name_idx].rm_eo - rm[name_idx].rm_so; char* end; while (pos-- > rm[name_idx].rm_so) { if (dbg->cl.buf_ptr[pos] == '+') { len = pos - rm[name_idx].rm_so; break; } } if ((loc->name = malloc(len + 1))) { memcpy(loc->name, &dbg->cl.buf_ptr[rm[name_idx].rm_so], len); loc->name[len] = '\0'; } loc->offset = (pos > rm[name_idx].rm_so) ? strtoul(&dbg->cl.buf_ptr[pos], &end, 16) : 0; } else { loc->name = empty_str(); loc->offset = 0; } loc->srcfile = (src_idx != -1) ? to_string(dbg, src_idx) : empty_str(); loc->lineno = (line_idx != -1) ? to_num(dbg, line_idx) : 0; loc->module = (module_idx != -1) ? to_string(dbg, module_idx) : empty_str(); }
string query_hit_string(void) { if (empty_str(hit_string)) { set_hit_string("hit"); } return hit_string; }
int query_command_not_found_in_history(string str) { if (empty_str(str)) { return 0; } return NO_SUCH_CMD == str; }
/* convert a netmask string (eg 255.255.255.0 or ffff:ff::) in +src+ into * the length (24) in +dst+. Return 0 if some sort of failure, or 1 on * success. */ int inet_ptom (int af, const char *src, unsigned int *dst) { union inX_addr addr; if (!empty_str(src)) { if (inet_pton (af, src, &addr) < 0) { *dst = 0; return 0; } } if (af == AF_INET) { *dst = count_bits(ntohl(addr.in4.s_addr)); return 1; } else if (af == AF_INET6) { int i, count; for (i = 0, *dst = 0; i < 4; i++) { count = count_bits(htonl(addr.in6.s6_addr32[i])); *dst += count; if (count != 32) break; /* Don't go any further if the mask has finished */ } return 1; } else { *dst = 0; return 0; } }
TEST(lagi_cajun, ReaderParserErrors) { json::UnknownElement ue; std::istringstream missing_comma("[1 2]"); EXPECT_THROW(json::Reader::Read(ue, missing_comma), json::Exception); std::istringstream garbage_after_number("123!"); EXPECT_THROW(json::Reader::Read(ue, garbage_after_number), json::Exception); std::istringstream unexpected_eof("["); EXPECT_THROW(json::Reader::Read(ue, unexpected_eof), json::Exception); std::istringstream bad_initial_token("]"); EXPECT_THROW(json::Reader::Read(ue, bad_initial_token), json::Exception); std::istringstream garbage_after_end("[]a"); EXPECT_THROW(json::Reader::Read(ue, garbage_after_end), json::Exception); std::istringstream empty_str(""); EXPECT_THROW(json::Reader::Read(ue, empty_str), json::Exception); std::istringstream dupe_keys("{\"a\": [], \"a\": 0}"); EXPECT_THROW(json::Reader::Read(ue, dupe_keys), json::Exception); std::istringstream unique_keys("{\"a\": [], \"b\": 0}"); EXPECT_NO_THROW(json::Reader::Read(ue, unique_keys)); }
int netcfg_wireless_set_wep (struct debconfclient * client, struct netcfg_interface *interface) { wireless_config wconf; char* rv = NULL; int ret, keylen, err = 0; unsigned char buf [IW_ENCODING_TOKEN_MAX + 1]; struct iwreq wrq; iw_get_basic_config (wfd, interface->name, &wconf); debconf_subst(client, "netcfg/wireless_wep", "iface", interface->name); debconf_input (client, "high", "netcfg/wireless_wep"); ret = debconf_go(client); if (ret == CMD_GOBACK) return GO_BACK; debconf_get(client, "netcfg/wireless_wep"); rv = client->value; if (empty_str(rv)) { unset_wep_key (interface->name); if (interface->wepkey != NULL) { free(interface->wepkey); interface->wepkey = NULL; } return 0; } while ((keylen = iw_in_key (rv, buf)) == -1) { debconf_subst(client, "netcfg/invalid_wep", "wepkey", rv); debconf_input(client, "critical", "netcfg/invalid_wep"); debconf_go(client); debconf_input (client, "high", "netcfg/wireless_wep"); ret = debconf_go(client); if (ret == CMD_GOBACK) return GO_BACK; debconf_get(client, "netcfg/wireless_wep"); rv = client->value; } /* Now rv is safe to store since it parsed fine */ interface->wepkey = strdup(rv); wrq.u.data.pointer = buf; wrq.u.data.flags = 0; wrq.u.data.length = keylen; if ((err = iw_set_ext(skfd, interface->name, SIOCSIWENCODE, &wrq)) < 0) { di_warning("setting WEP key on %s failed with code %d", interface->name, err); return -1; } return 0; }
int listen_cmd(string str) { if (!empty_str(str) && (str == "gulls" || str == "to the gulls")) { this_player()->simple_action("$N $vlisten to the gulls' cries in the distance."); return 1; } return 0; }
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; }
/* Write out a DHCP stanza for the given interface */ static int nc_wi_dhcp(const struct netcfg_interface *interface, FILE *fd) { fprintf(fd, "\n# The primary network interface\n"); fprintf(fd, "auto %s\n", interface->name); fprintf(fd, "iface %s inet dhcp\n", interface->name); if (!empty_str(interface->dhcp_hostname)) { fprintf(fd, "\thostname %s\n", interface->dhcp_hostname); } return 1; }
void print_over_test_str_nl_( #if defined(OS_WINDOWS) unsigned long level, #else long level, #endif char *str) { unsigned long len; if(level < 0) level = 0; if(level > strlen(_empt_str)/4) level = strlen(_empt_str)/4; len = strlen(str); if(len <= strlen(test_str(level)) - 4) printf("%s%s%s\n", empty_str(level), str, &(test_str(level)[len])); else printf("%s%s... \n", empty_str(level), str); }
/* Write out a static IPv6 config stanza for the given interface */ static int nc_wi_static_ipv6(const struct netcfg_interface *interface, FILE *fd) { fprintf(fd, "\n# The primary network interface\n"); fprintf(fd, "auto %s\n", interface->name); fprintf(fd, "iface %s inet6 static\n", interface->name); fprintf(fd, "\taddress %s\n", interface->ipaddress); fprintf(fd, "\tnetmask %i\n", interface->masklen); if (!empty_str(interface->gateway)) fprintf(fd, "\tgateway %s\n", interface->gateway); return 1; }
/* Write out a DHCP stanza for the given interface */ static int nc_wi_dhcp(const struct netcfg_interface *interface, FILE *fd) { /*if (!iface_is_hotpluggable(interface->name) && !find_in_stab(interface->name)) fprintf(fd, "auto %s\n", interface->name); else*/ fprintf(fd, "allow-hotplug %s\n", interface->name); fprintf(fd, "iface %s inet dhcp\n", interface->name); if (!empty_str(interface->dhcp_hostname)) { fprintf(fd, "\thostname %s\n", interface->dhcp_hostname); } return 1; }
void nm_write_static_ipvX(FILE *config_file, nm_ipvX ipvx) { char buffer[NM_MAX_LEN_BUF], addr[NM_MAX_LEN_IPV4]; int i; /* Get DNS in printable format. */ memset(buffer, 0, NM_MAX_LEN_BUF); for (i = 0; (i < NETCFG_NAMESERVERS_MAX) && (!empty_str(ipvx.nameservers[i])); i++) { strcat(buffer, ipvx.nameservers[i]); strcat(buffer, ";"); } if (strcmp(buffer, "")) { fprintf(config_file, "dns=%s\n", buffer); } /* Get addresses in printable format. */ memset(buffer, 0, NM_MAX_LEN_BUF); /* Write IP address to the buffer. */ strcat(buffer, ipvx.ip_address); strcat(buffer, "/"); /* Write netmask to the buffer. */ sprintf(addr, "%d", ipvx.masklen); strcat(buffer, addr); /* Write gateway address to the buffer. */ if (!empty_str(ipvx.gateway)) { strcat(buffer, ","); strcat(buffer, ipvx.gateway); } /* Write config to the configuration file. */ fprintf(config_file, "address1=%s\n", buffer); }
/* Write out a static IPv6 config stanza for the given interface */ static int nc_wi_static_ipv6(const struct netcfg_interface *interface, FILE *fd) { /*fprintf(fd, "\n# The primary network interface\n"); if (!iface_is_hotpluggable(interface->name) && !find_in_stab(interface->name)) fprintf(fd, "auto %s\n", interface->name); else*/ fprintf(fd, "allow-hotplug %s\n", interface->name); fprintf(fd, "iface %s inet6 static\n", interface->name); fprintf(fd, "\taddress %s\n", interface->ipaddress); fprintf(fd, "\tnetmask %i\n", interface->masklen); if (!empty_str(interface->gateway)) fprintf(fd, "\tgateway %s\n", interface->gateway); return 1; }
int test1(struct debconfclient *client) { int rv = 0; debconf_capb(client, ""); debconf_subst(client, "netcfg/write_wireless_config", "iface", "eht1"); debconf_subst(client, "netcfg/write_wireless_config", "interfaces_file", "some_file"); debconf_input(client, "medium", "netcfg/write_wireless_config"); debconf_go(client); debconf_get(client, "netcfg/write_wireless_config"); fprintf(stderr, "%s\n", client->value); if (!empty_str(client->value) && strcmp(client->value, "true") == 0) { rv = 1; } debconf_capb(client, "backup"); return rv; }
int cmd_put_relic_in_orb(string str) { string what, msg; object *inv; object potion; int i, dim; if (empty_str(str)) { return 0; } sscanf(str, "%s in orb", what); inv = this_player()->query_inventory(); dim = sizeof(inv); for (i = 0; i < dim; i++) { if (inv[i]->is_id(what) && inv[i]->property(ANCIENT_RELIC_PROP) == 1) { potion = clone_object(NOKICLIFFS_REJUV_POTION); potion->setup(); msg = "$N $vput an ancient relic into the " + "orb. The orb's activity increases dramatically " + "for a moment as it accepts the offering. " + "A moment before the orb settles and returns " + "to normal a rejuvination potion pops out and " + "settles gently on the pedestal."; this_player()->targeted_action(msg, this_player()); inv[i]->destruct(); potion->move(query_environment()); return 1; } } this_player()->message_orig( "That is not an appropriate offering to the Ancient One.\n"); return 1; }
/*********************************************************************************** * * ReadL * * @param currsection - * @param searchengines - PrefsFile to read from * @param store - where is it read from (default is search.ini from PACKAGE) * * @return TRUE if Deleted is set on this searchTemplate in search.ini * ***********************************************************************************/ BOOL SearchTemplate::ReadL(const OpStringC8& currsection, PrefsFile* searchengines, SearchStore store) { m_store = store; INT32 temp_id = searchengines->ReadIntL(currsection, "ID", -1); OpStringC empty_str(UNI_L("")); searchengines->ReadStringL(currsection, "UNIQUEID", m_guid, empty_str); // If the ID is -1 this means that the file loaded is // the old format which doesn't have IDs so we need to set a special // flag to make the merging work properly if (temp_id == -1 && !m_guid.HasContent()) { m_no_id = TRUE; // Will get a generated guid below } // check if this is a default search, and if so, get the guid from the mapping if (!m_guid.HasContent() && !m_no_id) { m_guid.Set(g_searchEngineManager->GetGUIDByOldId(temp_id)); } if (!m_guid.HasContent())// generate the GUID { OpString guid; if (OpStatus::IsSuccess(StringUtils::GenerateClientID(guid))) { SetUniqueGUID(guid.CStr()); OP_ASSERT(GetUniqueGUID().HasContent()); } } searchengines->ReadStringL(currsection, "Name", m_stringname, empty_str); m_format_id = Str::LocaleString(searchengines->ReadIntL(currsection, "Verbtext", Str::SI_IDSTR_SEARCH_FORMAT_WITH)); searchengines->ReadStringL(currsection, "URL", m_url, empty_str); searchengines->ReadStringL(currsection, "Default Tracking Code", m_default_tracking_code, empty_str); searchengines->ReadStringL(currsection, "SpeedDial Tracking Code", m_speeddial_tracking_code, empty_str); searchengines->ReadStringL(currsection, "ICON", m_icon_url, empty_str); searchengines->ReadStringL(currsection, "Query", m_query, empty_str); searchengines->ReadStringL(currsection, "Key", m_key, empty_str); m_is_post = searchengines->ReadIntL(currsection, "Is post", 0) ? TRUE : FALSE; m_use_tld = searchengines->ReadIntL(currsection, "UseTLD", 0) ? TRUE : FALSE; m_seperator_after = searchengines->ReadIntL(currsection, "Has endseparator", 0); searchengines->ReadStringL(currsection, "Encoding", m_encoding, UNI_L("iso-8859-1")); m_type = (SearchType)searchengines->ReadIntL(currsection, "Search Type", SEARCH_TYPE_GOOGLE); m_pbar_pos = searchengines->ReadIntL(currsection, "Position", -1); m_name = Str::LocaleString(searchengines->ReadIntL(currsection, "Nameid", Str::NOT_A_STRING)); // This string is used to makeover the final URL string using keys 'URL', and 'Default Tracking Code' and 'SpeedDial Tracking Code' m_tmp_url_with_tracking_code.Set(m_url); // ** Suggest Protocol - The protocol used for search suggestions, if available. See below. // ** Suggest URL - The url used for search suggestions. See below. OpString tmp; m_suggest_protocol = SearchTemplate::SUGGEST_NONE; searchengines->ReadStringL(currsection, "Suggest Protocol", tmp, empty_str); if(!tmp.CompareI("JSON")) { m_suggest_protocol = SearchTemplate::SUGGEST_JSON; } if(m_suggest_protocol != SearchTemplate::SUGGEST_NONE) { searchengines->ReadStringL(currsection, "Suggest URL", m_suggest_url, empty_str); if(!m_suggest_url.HasContent()) { m_suggest_protocol = SearchTemplate::SUGGEST_NONE; } } // Return if this is a deleted search or not return searchengines->ReadIntL(currsection, "Deleted", 0) ? TRUE : FALSE; }
int netcfg_wireless_show_essids(struct debconfclient *client, char *iface, char *priority) { wireless_scan_head network_list; wireless_config wconf; char *buffer; int couldnt_associate = 0; int essid_list_len = 1; iw_get_basic_config (wfd, iface, &wconf); network_list.retry = 1; if (iw_process_scan(wfd, iface, iw_get_kernel_we_version(), &network_list) >= 0 ) { wireless_scan *network, *old; /* Determine the actual length of the buffer. */ for (network = network_list.result; network; network = network->next) { essid_list_len += strlen(network->b.essid); } /* Buffer initialization. */ buffer = malloc(essid_list_len * sizeof(char)); if (buffer == NULL) { /* Error in memory allocation. */ return -1; } strcpy(buffer, ""); /* Create list of available ESSIDs. */ for (network = network_list.result; network; network = network->next) { strcat(buffer, network->b.essid); if (network->next) { strcat(buffer, ", "); } } /* Asking the user. */ debconf_reset(client, "netcfg/wireless_show_essids"); debconf_capb(client, "backup"); strcpy(buffer, ""); debconf_subst(client, "netcfg/wireless_show_essids", "essid_list", buffer); debconf_input(client, priority ? priority : "high", "netcfg/wireless_show_essids"); int ret = debconf_go(client); if (ret == 30) { return GO_BACK; } debconf_get(client, "netcfg/wireless_show_essids"); /* Question not asked or we're succesfully associated. */ if (!empty_str(wconf.essid) || empty_str(client->value)) { /* TODO Go to automatic... */ if (netcfg_wireless_auto_connect(client, iface, &wconf, &couldnt_associate) == 0) { return 0; } return couldnt_associate; } /* User wants to enter an ESSID manually. */ if (strcmp(client->value, enter_manually) == 0) { return ENTER_MANUALLY; } /* User has chosen a network from the list, need to find which one and * get its cofiguration. */ for (network = network_list.result; network; network = network->next) { if (strcmp(network->b.essid, client->value) == 0) { wconf = network->b; essid = strdup(network->b.essid); break; } } /* Free the network list. */ for (network = network_list.result; network; ) { old = network; network = network->next; free(old); } free(buffer); } iw_set_basic_config(wfd, iface, &wconf); return 0; }
int netcfg_wireless_choose_essid_manually(struct debconfclient *client, char *iface) { /* Priority here should be high, since user had already chosen to * enter an ESSID, he wants to see this question. */ 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_reset(client, "netcfg/wireless_essid"); debconf_reset(client, "netcfg/wireless_essid_again"); 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, "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, "high", "netcfg/wireless_essid"); if (debconf_go(client) == 30) return GO_BACK; debconf_get(client, "netcfg/wireless_essid"); tf = strdup(client->value); automatic: /* User doesn't care or we're successfully associated. */ if (!empty_str(wconf.essid) || empty_str(client->value)) { if (netcfg_wireless_auto_connect(client, iface, &wconf, &couldnt_associate) == 0) { return 0; } } /* 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? */ if (ret == 30) /* maybe netcfg/wireless_essid was preseeded; if so, give up */ break; 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; }
int main(int argc, char *argv[]) { int num_interfaces = 0; enum { BACKUP, GET_INTERFACE, GET_HOSTNAME_ONLY, GET_METHOD, GET_DHCP, GET_STATIC, WCONFIG, WCONFIG_ESSID, WCONFIG_SECURITY_TYPE, WCONFIG_WEP, WCONFIG_WPA, START_WPA, QUIT } state = GET_INTERFACE; static struct debconfclient *client; static int requested_wireless_tools = 0; char **ifaces; char *defiface = NULL, *defwireless = NULL; response_t res; struct netcfg_interface interface; #ifdef NM struct nm_config_info nmconf; #endif /* initialize libd-i */ di_system_init("netcfg"); netcfg_interface_init(&interface); if (strcmp(basename(argv[0]), "ptom") != 0) di_info("Starting netcfg v.%s", NETCFG_VERSION); parse_args (argc, argv); reap_old_files (); open_sockets(); /* initialize debconf */ client = debconfclient_new(); debconf_capb(client, "backup"); /* Check to see if netcfg should be run at all */ debconf_get(client, "netcfg/enable"); if (!strcmp(client->value, "false")) { netcfg_get_hostname(client, "netcfg/get_hostname", hostname, 0); netcfg_write_common("", hostname, NULL); return 0; } /* always always always default back to autoconfig, unless you've specified * disable_autoconfig on the command line. */ debconf_get(client, "netcfg/disable_autoconfig"); if (!strcmp(client->value, "true")) debconf_set(client, "netcfg/use_autoconfig", "false"); else debconf_set(client, "netcfg/use_autoconfig", "true"); /* also support disable_dhcp for compatibility */ debconf_get(client, "netcfg/disable_dhcp"); if (!strcmp(client->value, "true")) debconf_set(client, "netcfg/use_autoconfig", "false"); for (;;) { switch(state) { case BACKUP: return RETURN_TO_MAIN; case GET_INTERFACE: /* If we have returned from outside of netcfg and want to * reconfigure networking, check to see if wpasupplicant is * running, and kill it if it is. If left running when * the interfaces are taken up and down, it appears to * leave it in an inconsistant state */ kill_wpa_supplicant(); /* Choose a default by looking for link */ if (get_all_ifs(1, &ifaces) > 1) { while (*ifaces) { struct netcfg_interface link_interface; if (check_kill_switch(*ifaces)) { debconf_subst(client, "netcfg/kill_switch_enabled", "iface", *ifaces); debconf_input(client, "high", "netcfg/kill_switch_enabled"); if (debconf_go(client) == CMD_GOBACK) { state = BACKUP; break; } /* Is it still enabled? */ if (check_kill_switch(*ifaces)) { ifaces++; continue; } } interface_up(*ifaces); netcfg_interface_init(&link_interface); link_interface.name = strdup(*ifaces); if (netcfg_detect_link (client, &link_interface) == 1) /* CONNECTED */ { /* CONNECTED */ di_info("found link on interface %s, making it the default.", *ifaces); defiface = strdup(*ifaces); free(link_interface.name); break; } else { #ifdef WIRELESS struct wireless_config wc; #endif /* WIRELESS */ di_info("found no link on interface %s.", *ifaces); #ifdef WIRELESS if (iw_get_basic_config(wfd, *ifaces, &wc) == 0) { wc.essid[0] = '\0'; wc.essid_on = 0; iw_set_basic_config(wfd, *ifaces, &wc); sleep(1); iw_get_basic_config(wfd, *ifaces, &wc); if (!empty_str(wc.essid)) { di_info("%s is associated with %s. Selecting as default", *ifaces, wc.essid); defiface = strdup(*ifaces); interface_down(*ifaces); break; } else { di_info("%s is not associated. Relegating to defwireless", *ifaces); if (defwireless != NULL) free (defwireless); defwireless = strdup(*ifaces); } } else di_info("%s is not a wireless interface. Continuing.", *ifaces); interface_down(*ifaces); #endif } free(link_interface.name); interface_down(*ifaces); ifaces++; } } if (state == BACKUP) break; if (!defiface && defwireless) defiface = defwireless; if(netcfg_get_interface(client, &(interface.name), &num_interfaces, defiface)) state = BACKUP; else if (! interface.name || ! num_interfaces) state = GET_HOSTNAME_ONLY; else { if (is_wireless_iface (interface.name)) state = WCONFIG; else state = GET_METHOD; } break; case GET_HOSTNAME_ONLY: if(netcfg_get_hostname(client, "netcfg/get_hostname", hostname, 0)) state = BACKUP; else { netcfg_write_common("", hostname, NULL); state = QUIT; } break; case GET_METHOD: if ((res = netcfg_get_method(client)) == GO_BACK) state = (num_interfaces == 1) ? BACKUP : GET_INTERFACE; else { if (netcfg_method == DHCP) state = GET_DHCP; else state = GET_STATIC; } break; case GET_DHCP: switch (netcfg_activate_dhcp(client, &interface)) { case 0: state = QUIT; break; case RETURN_TO_MAIN: /* * It doesn't make sense to go back to GET_METHOD because * the user has already been asked whether they want to * try an alternate method. */ state = (num_interfaces == 1) ? BACKUP : GET_INTERFACE; break; case CONFIGURE_MANUALLY: state = GET_STATIC; break; default: return 1; } break; case GET_STATIC: { int ret; /* Misnomer - this should actually take care of activation */ if ((ret = netcfg_get_static(client, &interface)) == RETURN_TO_MAIN) state = GET_INTERFACE; else if (ret) state = GET_METHOD; else state = QUIT; break; } case WCONFIG: if (requested_wireless_tools == 0) { di_exec_shell_log("apt-install iw wireless-tools"); requested_wireless_tools = 1; } state = WCONFIG_ESSID; break; case WCONFIG_ESSID: if (netcfg_wireless_set_essid(client, &interface) == GO_BACK) state = BACKUP; else { init_wpa_supplicant_support(&interface); if (interface.wpa_supplicant_status == WPA_UNAVAIL) state = WCONFIG_WEP; else state = WCONFIG_SECURITY_TYPE; } break; case WCONFIG_SECURITY_TYPE: { int ret; ret = wireless_security_type(client, interface.name); if (ret == GO_BACK) state = WCONFIG_ESSID; else if (ret == REPLY_WPA) { state = WCONFIG_WPA; interface.wifi_security = REPLY_WPA; } else { state = WCONFIG_WEP; interface.wifi_security = REPLY_WEP; } break; } case WCONFIG_WEP: if (netcfg_wireless_set_wep(client, &interface) == GO_BACK) if (interface.wpa_supplicant_status == WPA_UNAVAIL) state = WCONFIG_ESSID; else state = WCONFIG_SECURITY_TYPE; else state = GET_METHOD; break; case WCONFIG_WPA: if (interface.wpa_supplicant_status == WPA_OK) { di_exec_shell_log("apt-install wpasupplicant"); interface.wpa_supplicant_status = WPA_QUEUED; } if (netcfg_set_passphrase(client, &interface) == GO_BACK) state = WCONFIG_SECURITY_TYPE; else state = START_WPA; break; case START_WPA: if (wpa_supplicant_start(client, &interface) == GO_BACK) state = WCONFIG_ESSID; else state = GET_METHOD; break; case QUIT: #ifdef NM if (num_interfaces > 0) { nm_get_configuration(&interface, &nmconf); nm_write_configuration(nmconf); } #endif netcfg_update_entropy(); return 0; } } }
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; }