コード例 #1
0
ファイル: wpa.c プロジェクト: 27Paolo/ubiquity
static int wpa_connect(const char *if_name)
{
    char *cfile;
    int flen, res;
    
    flen = (strlen(WPASUPP_CTRL) + strlen(if_name) + 2);
    
    cfile = malloc(flen);
    if (cfile == NULL) {
        di_info("Can't allocate memory for WPA control interface.");
        return 1;
    }    
        
    res = snprintf(cfile, flen, "%s/%s", WPASUPP_CTRL, if_name);
    if ((res < 0) || (res >= flen)) {
        free(cfile);
        return 1;
    }   
    ctrl = wpa_ctrl_open(cfile);
    free(cfile);
    
    if (ctrl == NULL) {
        di_info("Couldn't connect to wpasupplicant");
        return 1;
    }
    else
        return 0;
}
コード例 #2
0
ファイル: netcfg-common.c プロジェクト: GalliumOS/ubiquity
/* Returns non-zero if this interface has an enabled kill switch, otherwise
 * zero.
 */
int check_kill_switch(const char *if_name)
{
    char *temp, *linkbuf;
    const char *killname;
    char killstate;
    size_t len;
    int linklen, killlen;
    int fd = -1;
    int ret = 0;

    /* longest string we need */
    len = strlen(SYSCLASSNET) + strlen(if_name) + strlen("/device/rf_kill") + 1;

    temp = malloc(len);
    snprintf(temp, len, SYSCLASSNET "%s/driver", if_name);
    linkbuf = malloc(1024); /* probably OK ... I hate readlink() */
    linklen = readlink(temp, linkbuf, 1024);
    if (linklen < 0)
        goto out;

    if (strncmp(linkbuf + linklen - 8, "/ipw2100", 8) == 0)
        killname = "rf_kill";
    else if (strncmp(linkbuf + linklen - 8, "/ipw2200", 8) == 0)
        killname = "rf_kill";
    else
        goto out;

    snprintf(temp, len, SYSCLASSNET "%s/device/%s", if_name, killname);
    di_info("Checking RF kill switch: %s", temp);
    fd = open(temp, O_RDONLY);
    if (fd == -1)
        goto out;
    killlen = read(fd, &killstate, 1);
    if (killlen < 0) {
        di_error("Failed to read RF kill state: %s", strerror(errno));
        goto out;
    } else if (killlen == 0) {
        di_warning("RF kill state file empty");
        goto out;
    }

    if (killstate == '2') {
        di_info("RF kill switch enabled");
        ret = 1;
    }

 out:
    free(temp);
    free(linkbuf);

    if (fd != -1)
        close(fd);

    return ret;
}
コード例 #3
0
static uint32_t di_read(int reg)
{
	uint32_t val = os_read32(di->ioaddr + (reg));
	di_info("di_read(0x%02x) = 0x%08x\n", reg, val);

	return val;
}
コード例 #4
0
/*
 * print out a key in hex
 */
static void print_key(const char *tag, uint8_t *key, int bits)
{
	int bytes = (bits + 7) / 8;

	di_info("%s", tag);
	while (bytes--)
		os_printk("%02x", *key++);
	os_printk("\n");
}
コード例 #5
0
ファイル: wpa.c プロジェクト: 27Paolo/ubiquity
int init_wpa_supplicant_support(struct netcfg_interface *interface)
{
    if (access("/sbin/wpa_supplicant", F_OK) == 0)
        interface->wpa_supplicant_status = WPA_OK;
    else {
        interface->wpa_supplicant_status = WPA_UNAVAIL;
        di_info("Wpasupplicant not found on the system. Disabling WPA options");
    }
    return 0;
}
コード例 #6
0
ファイル: nm-conf.c プロジェクト: prusso/ubiquity
/* Write Network Manager config file. */
void nm_write_configuration(struct nm_config_info nmconf)
{
    FILE    *config_file;
    char    buffer[NM_MAX_LEN_BUF];

    /* Create the directory for the config file and clear any possible
     * previous files found there. */
    sprintf(buffer, "mkdir -p %s", NM_CONFIG_FILE_PATH);
    di_exec_shell(buffer);

    /* If the directory exist mkdir will do nothing, so just remove every file
     * there. Rely on the fact that for now netcfg only does config for one
     * interface. */
    sprintf(buffer, "rm %s/*", NM_CONFIG_FILE_PATH);
    di_exec_shell(buffer);

    /* Open file using its full path. */
    sprintf(buffer, "%s/%s", NM_CONFIG_FILE_PATH, nmconf.connection.id);
    config_file = fopen(buffer, "w");

    if (config_file == NULL) {
        di_info("Unable to open file for writing network-manager "
                "configuration. The connection id (%s) might not be "
                "set to a proper value.", nmconf.connection.id);
        return;
    }

    if (fchmod(fileno(config_file), 0600) != 0) {
        di_error("network-manager connection file cannot be protected "
                 "from reading: %s", strerror(errno));
        exit(1);
    }

    nm_write_connection(config_file, nmconf.connection);

    if (nmconf.connection.type == WIRED) {
        nm_write_wired_specific_options(config_file, &nmconf);
    }
#ifdef WIRELESS
    else {
        nm_write_wireless_specific_options(config_file, &nmconf);
        if (nmconf.wireless.is_secured) {
            nm_write_wireless_security(config_file, nmconf.wireless_security);
        }
    }
#endif

    nm_write_ipv4(config_file, nmconf.ipv4);
    nm_write_ipv6(config_file, nmconf.ipv6);

    fclose(config_file);

    nm_write_connection_type(nmconf);
}
コード例 #7
0
ファイル: wpa.c プロジェクト: 27Paolo/ubiquity
static int wpa_status(void)
{
    int ret;
    size_t len;
    char buf[2048];
    const char *success = "wpa_state=COMPLETED";
    
    len = sizeof(buf) -1;
    ret = wpa_ctrl_request(ctrl, "STATUS", 7, buf, &len, NULL);

    if (ret == 0) {
        buf[len] = '\0';
        di_info("buf = %s", buf);
    }
    else
        return 1;
        
    if (strstr(buf, success) == NULL)
        return 1;
    else {
        di_info("success");
        return 0;
    }
}
コード例 #8
0
ファイル: wpa.c プロジェクト: 27Paolo/ubiquity
static int netcfg_wpa_cmd (char *cmd)
{
    char buf[256];
    size_t len;
    int ret;
    
    len = sizeof(buf) -1;
    ret = wpa_ctrl_request(ctrl, cmd, strlen(cmd), buf, &len, NULL);
    
    if (ret < 0) {
        di_info("Sending %s to wpasupplicant failed", cmd);
        return 1;
    }
    
    return 0;
}
コード例 #9
0
ファイル: wpa.c プロジェクト: 27Paolo/ubiquity
static int wpa_set_ssid (char *ssid)
{
    int ret, res;
    size_t len;
    char cmd[256];
    char buf[256];
    
    res = snprintf(cmd, sizeof(cmd), "SET_NETWORK 0 %s \"%s\"", "ssid", ssid);
    if (res < 0)
        return 1;
        
    len = sizeof(buf) -1;
    ret = wpa_ctrl_request(ctrl, cmd, sizeof(cmd), buf, &len, NULL);
    if (ret != 0) {
        di_info("Failed to set the ssid with wpasupplicant");
        return 1;
    }
    return 0;
}
コード例 #10
0
ファイル: write_interface.c プロジェクト: GalliumOS/ubiquity
/* The main function for writing things to INTERFACES_FILE (aka
 * /etc/network/interfaces).
 *
 * In principle, this function is very simple: just examine the interface
 * we've been passed, and call out to the relevant private helper function. 
 * In practice...
 *
 * Takes the interface struct to write out.  If you pass NULL, the file gets
 * deleted and a helpful comment header gets written.
 *
 * Returns a true/false boolean representing "did everything go OK"; if 0 is
 * returned, the interfaces file will not have been modified, and errno will
 * contain the details.
 */
int netcfg_write_interface(const struct netcfg_interface *interface)
{
	FILE *fd;
	int rv;
	struct stat stat_buf;
	
	if (!interface) {
		di_debug("No interface given; clearing " INTERFACES_FILE);
		rv = unlink(INTERFACES_FILE);
		if (rv < 0 && errno != ENOENT) {
			di_info("Error clearing %s: %s", INTERFACES_FILE, strerror(errno));
			return 0;
		}
	}
	
	fd = file_open(INTERFACES_FILE ".tmp", "w");
	if (!fd) {
		di_warning("Failed to open %s.tmp: %s", INTERFACES_FILE, strerror(errno));
		return 0;
	}

	/* All of this code is to handle the apparently simple task of
	 * copying the existing interfaces file to the tmpfile (if it exists)
	 * so we can add our new stuff to it.  Bloody longwinded way of doing
	 * it, I'm sure you'll agree.
	 */
	rv = stat(INTERFACES_FILE, &stat_buf);
	if (rv < 0 && errno != ENOENT) {
		di_warning("Failed to stat %s: %s", INTERFACES_FILE, strerror(errno));
		unlink(INTERFACES_FILE ".tmp");
		return 0;
	}
	if (rv == 0) {
		char *tmpbuf = malloc(stat_buf.st_size + 1);
		int origfd;
		origfd = open(INTERFACES_FILE, O_RDONLY);
		if (origfd < 0) {
			di_warning("Failed to open %s: %s", INTERFACES_FILE, strerror(errno));
			fclose(fd);
			unlink(INTERFACES_FILE ".tmp");
			free(tmpbuf);
			return 0;
		}
		rv = read(origfd, tmpbuf, stat_buf.st_size);
		if (rv < 0) {
			di_warning("Failed to read %s: %s", INTERFACES_FILE, strerror(errno));
			fclose(fd);
			unlink(INTERFACES_FILE ".tmp");
			free(tmpbuf);
			close(origfd);
			return 0;
		}
		if (rv != stat_buf.st_size) {
			di_warning("Short read on %s", INTERFACES_FILE);
			fclose(fd);
			unlink(INTERFACES_FILE ".tmp");
			free(tmpbuf);
			close(origfd);
			return 0;
		}
		rv = fwrite(tmpbuf, sizeof(char), stat_buf.st_size, fd);
		if (rv != (int)stat_buf.st_size) {
			di_warning("Short write on %s.tmp", INTERFACES_FILE);
			fclose(fd);
			unlink(INTERFACES_FILE ".tmp");
			free(tmpbuf);
			close(origfd);
			return 0;
		}
		free(tmpbuf);
		close(origfd);
	}
		
	
	/* Thank $DEITY all that's out of the way... now we can write a
	 * freaking interfaces file entry */
	rv = 1;

	if (!interface) {
		di_debug("Writing informative header");
		rv = nc_wi_header(fd);
	} else if (interface->loopback == 1) {
		di_debug("Writing loopback interface");
		rv = nc_wi_loopback(interface, fd);
	} else if (interface->dhcp == 1 || interface->slaac == 1) {
		if (interface->dhcp == 1) {
			di_debug("Writing DHCP stanza for %s", interface->name);
			rv = nc_wi_dhcp(interface, fd);
		}
		if (interface->slaac == 1) {
			di_debug("Writing SLAAC stanza for %s", interface->name);
			rv = nc_wi_slaac(interface, fd);
		}
	} else if (interface->address_family == AF_INET) {
		di_debug("Writing static IPv4 stanza for %s", interface->name);
		rv = nc_wi_static_ipv4(interface, fd);
	} else if (interface->address_family == AF_INET6) {
		di_debug("Writing static IPv6 stanza for %s", interface->name);
		rv = nc_wi_static_ipv6(interface, fd);
	}
	if (rv && interface && interface->parentif) {
		di_debug("Writing VLAN: %s", interface->name);
		rv = nc_wi_vlan(interface, fd);
	}
	if (rv && interface && is_wireless_iface(interface->name)) {
		di_debug("Writing wireless options for %s", interface->name);
		rv = nc_wi_wireless_options(interface, fd);
	}

	if (rv) {
		di_debug("Success!");
		rename(INTERFACES_FILE ".tmp", INTERFACES_FILE);
	}

	fclose(fd);
	unlink(INTERFACES_FILE ".tmp");
	return rv;
}
コード例 #11
0
ファイル: wireless.c プロジェクト: prusso/ubiquity
int netcfg_wireless_choose_essid_manually(struct debconfclient *client,
        struct netcfg_interface *interface, char *question)
{
    wireless_config wconf;

    iw_get_basic_config (wfd, interface->name, &wconf);

    debconf_subst(client, question, "iface", interface->name);
    debconf_subst(client, "netcfg/wireless_adhoc_managed", "iface", interface->name);

    if (debconf_go(client) == CMD_GOBACK) {
        debconf_fset(client, question, "seen", "false");
        return GO_BACK;
    }

    debconf_get(client, "netcfg/wireless_adhoc_managed");

    if (!strcmp(client->value, "Ad-hoc network (Peer to peer)")) {
        interface->mode = ADHOC;
    }

    wconf.has_mode = 1;
    wconf.mode = interface->mode;

get_essid:
    debconf_input(client, "high", question);

    if (debconf_go(client) == CMD_GOBACK) {
        return GO_BACK;
    }

    debconf_get(client, question);

    if (client->value && strlen(client->value) > IW_ESSID_MAX_SIZE) {
        char max_len_string[5];
        sprintf(max_len_string, "%d", IW_ESSID_MAX_SIZE);
        debconf_capb(client, "");
        debconf_subst(client, "netcfg/invalid_essid", "essid", client->value);
        debconf_subst(client, "netcfg/invalid_essid", "max_essid_len",
                      max_len_string);
        debconf_input(client, "critical", "netcfg/invalid_essid");
        debconf_go(client);

        debconf_fset(client, question, "seen", "false");
        debconf_capb(client, "backup");
        goto get_essid;
    }

    interface->essid = strdup(client->value);

    memset(wconf.essid, 0, IW_ESSID_MAX_SIZE + 1);
    snprintf(wconf.essid, IW_ESSID_MAX_SIZE + 1, "%s", interface->essid);
    wconf.has_essid = 1;
    wconf.essid_on = 1;

    iw_set_basic_config(wfd, interface->name, &wconf);

    di_info("Network chosen: %s. Proceeding to connect.", interface->essid);

    return 0;
}
コード例 #12
0
ファイル: wireless.c プロジェクト: prusso/ubiquity
int netcfg_wireless_show_essids(struct debconfclient *client, struct netcfg_interface *interface)
{
    wireless_scan_head network_list;
    wireless_config wconf;
    char *buffer;
    int essid_list_len = 1;

    iw_get_basic_config (wfd, interface->name, &wconf);
    interface_up(interface->name);

    if (iw_scan(wfd, interface->name, iw_get_kernel_we_version(),
                &network_list) >= 0 ) {
        wireless_scan *network;

        di_info("Scan of wireless interface %s succeeded.", interface->name);

        /* Determine the actual length of the buffer. */
        for (network = network_list.result; network; network =
                    network->next) {
            if (!exists_in_network_list(network_list, network)) {
                essid_list_len += (strlen(network->b.essid) + 2);
            }
        }
        /* Buffer initialization. */
        buffer = malloc(essid_list_len * sizeof(char));
        if (buffer == NULL) {
            /* Error in memory allocation. */
            di_warning("Unable to allocate memory for network list buffer.");
            return ENTER_MANUALLY;
        }
        strcpy(buffer, "");

        /* Create list of available ESSIDs. */
        for (network = network_list.result; network; network = network->next) {
            if (!exists_in_network_list(network_list, network)) {
                strcat(buffer, network->b.essid);
                strcat(buffer, ", ");
            }
        }

        /* Asking the user. */
        debconf_capb(client, "backup");
        debconf_subst(client, "netcfg/wireless_show_essids", "essid_list", buffer);
        debconf_fset(client, "netcfg/wireless_show_essids", "seen", "false");
        debconf_input(client, "high", "netcfg/wireless_show_essids");

        if (debconf_go(client) == CMD_GOBACK) {
            debconf_fset(client, "netcfg/wireless_show_essids", "seen",
                         "false");
            free_network_list(&network_list.result);
            free(buffer);

            return GO_BACK;
        }

        debconf_get(client, "netcfg/wireless_show_essids");

        /* User wants to enter an ESSID manually. */
        if (strcmp(client->value, "manual") == 0) {
            free_network_list(&network_list.result);
            free(buffer);

            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;
                interface->essid = strdup(network->b.essid);
                break;
            }
        }

        /* Free the network list. */
        free_network_list(&network_list.result);
        free(buffer);
    }
    else {
        /* Go directly to choosing manually, use the wireless_essid_again
         * question. */
        if (netcfg_wireless_choose_essid_manually(client, interface,
                "netcfg/wireless_essid_again") == GO_BACK) {

            return GO_BACK;
        }

        return 0;
    }

    iw_set_basic_config(wfd, interface->name, &wconf);
    interface_down(interface->name);

    di_info("Network chosen: %s. Proceeding to connect.", interface->essid);

    return 0;
}
コード例 #13
0
ファイル: netcfg.c プロジェクト: vipullinux/DebianInstaller
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;
        }
    }
}
コード例 #14
0
ファイル: netcfg-common.c プロジェクト: GalliumOS/ubiquity
// Layer 3 qeth on s390(x) cannot do arping to test gateway reachability.
int is_layer3_qeth(const struct netcfg_interface *interface)
{
    const int bufsize = 1024;
    int retval = 0;
    char* path;
    char* buf;
    size_t len;
    ssize_t slen;
    char* driver;
    int fd;
    char* iface;

    if (interface->parentif)
        iface = interface->parentif;
    else
        iface = interface->name;

    // This is sufficient for both /driver and /layer2.
    len = strlen(SYSCLASSNET) + strlen(iface) + strlen("/device/driver") + 1;

    path = malloc(len);
    snprintf(path, len, SYSCLASSNET "%s/device/driver", iface);

    // lstat() on sysfs symlinks does not provide size information.
    buf = malloc(bufsize);
    slen = readlink(path, buf, bufsize - 1);

    if (slen < 0) {
        di_error("Symlink %s cannot be resolved: %s", path, strerror(errno));
        goto out;
    }

    buf[slen] = '\0';

    driver = strrchr(buf, '/') + 1;
    if (strcmp(driver, "qeth") != 0) {
        di_info("no qeth found: %s", driver);
        goto out;
    }

    snprintf(path, len, SYSCLASSNET "%s/device/layer2", iface);

    fd = open(path, O_RDONLY);
    if (fd == -1) {
        di_error("%s cannot be opened: %s", path, strerror(errno));
        goto out;
    }

    slen = read(fd, buf, 1);
    if (slen == -1) {
        di_error("Read from %s failed: %s", path, strerror(errno));
        close(fd);
        goto out;
    }

    if (buf[0] == '0') {
        // driver == 'qeth' && layer2 == 0
        retval = 1;
    }

    close(fd);

out:
    free(buf);
    free(path);
    return retval;
}
コード例 #15
0
ファイル: netcfg-static.c プロジェクト: 27Paolo/ubiquity
int main(int argc, char** argv)
{
    int num_interfaces = 0;
    static struct debconfclient *client;
    static int requested_wireless_tools = 0;
    struct netcfg_interface interface;

    enum { BACKUP, GET_INTERFACE, GET_HOSTNAME_ONLY, GET_STATIC, WCONFIG, WCONFIG_ESSID, WCONFIG_WEP, QUIT} state = GET_INTERFACE;

    /* initialize libd-i */
    di_system_init("netcfg-static");
    if (strcmp(basename(argv[0]), "ptom") != 0)
	di_info("Starting netcfg v.%s (built %s)", NETCFG_VERSION, NETCFG_BUILD_DATE);

    parse_args(argc, argv);
    reap_old_files();
    open_sockets();

    /* initialize debconf */
    client = debconfclient_new();
    debconf_capb(client, "backup");

    while (1) {
        switch(state) {
        case BACKUP:
            return 10;
        case GET_INTERFACE:
            if (netcfg_get_interface(client, &(interface.name), &num_interfaces, NULL))
                state = BACKUP;
            else if (! interface.name || ! num_interfaces)
                state = GET_HOSTNAME_ONLY;
            else {
                if (is_wireless_iface(interface.name))
                    state = WCONFIG;
                else
                    state = GET_STATIC;
            }
            break;
        case GET_HOSTNAME_ONLY:
            if(netcfg_get_hostname(client, "netcfg/get_hostname", hostname, 0))
                state = BACKUP;
            else {
                netcfg_write_common("", hostname, NULL);
                return 0;
            }
            break;
        case GET_STATIC:
            if (netcfg_get_static(client, &interface))
                state = (num_interfaces == 1) ? BACKUP : GET_INTERFACE;
            else
                state = QUIT;
            break;

        case WCONFIG:
            if (requested_wireless_tools == 0) {
                requested_wireless_tools = 1;
                di_exec_shell("apt-install wireless-tools");
            }
            state = WCONFIG_ESSID;
            break;

        case WCONFIG_ESSID:
            if (netcfg_wireless_set_essid (client, &interface, NULL))
                state = BACKUP;
            else
                state = WCONFIG_WEP;
            break;

        case WCONFIG_WEP:
            if (netcfg_wireless_set_wep (client, &interface))
                state = WCONFIG_ESSID;
            else
                state = GET_STATIC;
            break;

        case QUIT:
            netcfg_update_entropy();
            return 0;
        }
    }

    return 0;
}
コード例 #16
0
static void di_write(uint32_t val, int reg)
{
	di_info("dryice_write_reg(0x%08x, 0x%02x)\n", val, reg);
	os_write32(di->ioaddr + (reg), val);
}
コード例 #17
0
/*
 * print out the contents of the dryice status register
 * with all the bits decoded
 */
static void show_dsr(const char *heading)
{
	uint32_t dsr = di_read(DSR);

	di_info("%s\n", heading);
	if (dsr & DSR_TAMPER_BITS) {
		if (dsr & DSR_WTD)
			di_info("Wire-mesh Tampering Detected\n");
		if (dsr & DSR_ETBD)
			di_info("External Tampering B Detected\n");
		if (dsr & DSR_ETAD)
			di_info("External Tampering A Detected\n");
		if (dsr & DSR_EBD)
			di_info("External Boot Detected\n");
		if (dsr & DSR_SAD)
			di_info("Security Alarm Detected\n");
		if (dsr & DSR_TTD)
			di_info("Temperature Tampering Detected\n");
		if (dsr & DSR_CTD)
			di_info("Clock Tampering Detected\n");
		if (dsr & DSR_VTD)
			di_info("Voltage Tampering Detected\n");
		if (dsr & DSR_MCO)
			di_info("Monotonic Counter Overflow\n");
		if (dsr & DSR_TCO)
			di_info("Time Counter Overflow\n");
	} else
		di_info("No Tamper Events Detected\n");

	di_info("%d Key Busy Flag\n",           !!(dsr & DSR_KBF));
	di_info("%d Write Busy Flag\n",         !!(dsr & DSR_WBF));
	di_info("%d Write Next Flag\n",         !!(dsr & DSR_WNF));
	di_info("%d Write Complete Flag\n",     !!(dsr & DSR_WCF));
	di_info("%d Write Error Flag\n",        !!(dsr & DSR_WEF));
	di_info("%d Random Key Error\n",        !!(dsr & DSR_RKE));
	di_info("%d Random Key Valid\n",        !!(dsr & DSR_RKV));
	di_info("%d Clock Alarm Flag\n",        !!(dsr & DSR_CAF));
	di_info("%d Non-Valid Flag\n",          !!(dsr & DSR_NVF));
	di_info("%d Security Violation Flag\n", !!(dsr & DSR_SVF));
}