Exemple #1
0
/* parse_resvconf()
 *
 * inputs - NONE
 * output - -1 if failure 0 if success
 * side effects - fills in irc_nsaddr_list
 */
static int
parse_resvconf(void)
{
  char *p;
  char *opt;
  char *arg;
  char input[DNS_MAXLINE];
  FILE *file;

  /* XXX "/etc/resolv.conf" should be from a define in setup.h perhaps
   * for cygwin support etc. this hardcodes it to unix for now -db
   */
  if ((file = fopen("/etc/resolv.conf", "r")) == NULL)
    return -1;

  while (fgets(input, sizeof(input), file) != NULL)
  {
    /* blow away any newline */
    if ((p = strpbrk(input, "\r\n")) != NULL)
      *p = '\0';

    p = input;
    /* skip until something thats not a space is seen */
    while (isspace(*p))
      p++;
    /* if at this point, have a '\0' then continue */
    if (*p == '\0')
      continue;

    /* Ignore comment lines immediately */
    if (*p == '#' || *p == ';')
      continue;

    /* skip until a space is found */
    opt = p;
    while (!isspace(*p) && *p != '\0')
      p++;
    if (*p == '\0')
      continue;  /* no arguments?.. ignore this line */
    /* blow away the space character */
    *p++ = '\0';

    /* skip these spaces that are before the argument */
    while (isspace(*p))
      p++;
    /* Now arg should be right where p is pointing */
    arg = p;
    if ((p = strpbrk(arg, " \t")) != NULL)
      *p = '\0';  /* take the first word */

    if (rb_strcasecmp(opt, "domain") == 0)
      rb_strlcpy(irc_domain, arg, sizeof(irc_domain));
    else if (rb_strcasecmp(opt, "nameserver") == 0)
      add_nameserver(arg);
  }

  fclose(file);
  return 0;
}
Exemple #2
0
int rb_mkdir(int volume, const char *name)
{
    RB_DIR *dir;
    char namecopy[MAX_PATH];
    char* end;
    char *basename;
    char *parent;
    struct rb_dirent *entry;
    struct fat_dir newdir;
    int rc;

    if ( name[0] != '/' ) {
        DEBUGF("mkdir: Only absolute paths supported right now\n");
        return -1;
    }

    strlcpy(namecopy, name, sizeof(namecopy));

    /* Split the base name and the path */
    end = strrchr(namecopy, '/');
    *end = 0;
    basename = end+1;

    if(namecopy == end) /* Root dir? */
        parent = "/";
    else
        parent = namecopy;
        
    DEBUGF("mkdir: parent: %s, name: %s\n", parent, basename);

    dir = rb_opendir(volume, parent);
    
    if(!dir) {
        DEBUGF("mkdir: can't open parent dir\n");
        return -2;
    }    

    if(basename[0] == 0) {
        DEBUGF("mkdir: Empty dir name\n");
        errno = EINVAL;
        return -3;
    }
    
    /* Now check if the name already exists */
    while ((entry = rb_readdir(dir))) {
        if ( !rb_strcasecmp(basename, entry->d_name) ) {
            DEBUGF("mkdir error: file exists\n");
            errno = EEXIST;
            rb_closedir(dir);
            return - 4;
        }
    }

    memset(&newdir, 0, sizeof(struct fat_dir));
    
    rc = fat_create_dir(basename, &newdir, &(dir->fatdir));
    rb_closedir(dir);
    
    return rc;
}
Exemple #3
0
RB_DIR* rb_opendir(int volume, const char* name)
{
    char namecopy[MAX_PATH];
    char* part;
    char* end;
    struct fat_direntry entry;
    int dd;
    RB_DIR* pdir = opendirs;

    if ( name[0] != '/' ) {
        DEBUGF("Only absolute paths supported right now\n");
        return NULL;
    }

    /* find a free dir descriptor */
    for ( dd=0; dd<MAX_OPEN_DIRS; dd++, pdir++)
        if ( !pdir->busy )
            break;

    if ( dd == MAX_OPEN_DIRS ) {
        DEBUGF("Too many dirs open\n");
        errno = EMFILE;
        return NULL;
    }

    pdir->busy = true;

    strlcpy(namecopy, name, sizeof(namecopy)); /* just copy */

    if ( fat_opendir(IF_MV2(volume,) &pdir->fatdir, 0, NULL) < 0 ) {
        DEBUGF("Failed opening root dir\n");
        pdir->busy = false;
        return NULL;
    }

    for ( part = strtok_r(namecopy, "/", &end); part;
          part = strtok_r(NULL, "/", &end)) {
        /* scan dir for name */
        while (1) {
            if ((fat_getnext(&pdir->fatdir,&entry) < 0) ||
                (!entry.name[0])) {
                pdir->busy = false;
                return NULL;
            }
            if ( (entry.attr & FAT_ATTR_DIRECTORY) &&
                 (!rb_strcasecmp(part, entry.name)) ) {
                /* In reality, the parent_dir parameter of fat_opendir seems
                 * useless because it's sole purpose it to have a way to
                 * update the file metadata, but here we are only reading
                 * a directory so there's no need for that kind of stuff.
                 * However, the rmdir function uses a ugly hack to
                 * avoid opening a directory twice when deleting it and thus
                 * needs those information. That's why we pass pdir->fatdir both
                 * as the parent directory and the resulting one (this is safe,
                 * in doubt, check fat_open(dir) code) which will allow this kind of
                 * (ugly) things */
                if ( fat_opendir(IF_MV2(volume,)
                                 &pdir->fatdir,
                                 entry.firstcluster,
                                 &pdir->fatdir) < 0 ) {
                    DEBUGF("Failed opening dir '%s' (%ld)\n",
                           part, entry.firstcluster);
                    pdir->busy = false;
                    return NULL;
                }

				break;
            }
        }
    }

    return pdir;
}