예제 #1
0
static di_tree_node *di_tree_node_rotate (di_tree_node *node)
{
  di_tree_node_calculate (node);
  switch (node->balance)
  {
    case -2:
      switch (node->left->balance)
      {
        case -1:
        case 0:
          return di_tree_node_rotate_right (node);
        case 1:
          return di_tree_node_rotate_right_double (node);
      }
    case -1:
    case 0:
    case 1:
      return node;
    case 2:
      switch (node->right->balance)
      {
        case -1:
          return di_tree_node_rotate_left_double (node);
        case 0:
        case 1:
          return di_tree_node_rotate_left (node);
      }
  }
  di_error ("Internal error");
  return node;
}
예제 #2
0
/* 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
파일: nm-conf.c 프로젝트: prusso/ubiquity
/* Linux provides a lightweight facility that can generate UUIDs for us. */
static void get_uuid(char* target)
{
    FILE* fp = fopen("/proc/sys/kernel/random/uuid", "r");
    if (fgets(target, NM_MAX_LEN_UUID, fp) == NULL)
    {
        di_error("get_uuid() failed: %s", strerror(errno));
        exit(1);
    }
    target[NM_MAX_LEN_UUID-1] = '\0'; // clear the newline
    fclose(fp);
}
예제 #4
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);
}
예제 #5
0
파일: wpa.c 프로젝트: 27Paolo/ubiquity
static int start_wpa_daemon(struct debconfclient *client, const char *if_name)
{
    wpa_supplicant_pid = fork();

    if (wpa_supplicant_pid == 0) {
        fclose(client->out);
        if (execlp("wpa_supplicant", "wpa_supplicant", "-i", if_name, "-C",
                   WPASUPP_CTRL, "-P", WPAPID, "-B", NULL) == -1) {
            di_error("could not exec wpasupplicant: %s", strerror(errno));
            return 1;
        }
        else 
            return 0;
    }
    else {
        waitpid(wpa_supplicant_pid, NULL, 0);
        return 0;
    }
}
예제 #6
0
// 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;
}