Ejemplo n.º 1
0
/*!
 * Remove hexencoded dots and slashes (":2e" and ":2f")
 */
static int ad_conv_dehex(const char *path, const struct stat *sp, const struct vol *vol, const char **newpathp)
{
    EC_INIT;
    static char buf[MAXPATHLEN];
    const char *adpath, *p;
    int adflags = S_ISDIR(sp->st_mode) ? ADFLAGS_DIR : 0;
    bstring newpath = NULL;

    LOG(log_debug, logtype_default,"ad_conv_dehex(\"%s\"): BEGIN", fullpathname(path));

    *newpathp = NULL;

    if ((p = strchr(path, ':')) == NULL)
        goto EC_CLEANUP;

    EC_NULL( newpath = bfromcstr(path) );

    EC_ZERO( bfindreplace(newpath, bfromcstr(":2e"), bfromcstr("."), 0) );
    EC_ZERO( bfindreplace(newpath, bfromcstr(":2f"), bfromcstr(":"), 0) );
    
    become_root();
    if (adflags != ADFLAGS_DIR)
        rename(vol->ad_path(path, 0), vol->ad_path(bdata(newpath), 0));
    rename(path, bdata(newpath));
    unbecome_root();

    strlcpy(buf, bdata(newpath), sizeof(buf));
    *newpathp = buf;

EC_CLEANUP:
    if (newpath)
        bdestroy(newpath);
    EC_EXIT;
}
Ejemplo n.º 2
0
static int ad_conv_v22ea(const char *path, const struct stat *sp, const struct vol *vol)
{
    EC_INIT;
    const char *adpath;
    int adflags = S_ISDIR(sp->st_mode) ? ADFLAGS_DIR : 0;

    become_root();

    EC_ZERO( ad_conv_v22ea_hf(path, sp, vol) );
    EC_ZERO( ad_conv_v22ea_rf(path, sp, vol) );

    EC_NULL( adpath = ad_path(path, adflags) );
    LOG(log_debug, logtype_default,"ad_conv_v22ea_hf(\"%s\"): deleting adouble:v2 file: \"%s\"",
        path, fullpathname(adpath));

    unlink(adpath);

EC_CLEANUP:
    if (errno == ENOENT)
        EC_STATUS(0);

    unbecome_root();

    EC_EXIT;
}
Ejemplo n.º 3
0
/*!
 * Return number on entries in a directory
 *
 * @param path   (r) path to dir
 * @return           number of entries, -1 on error
 */
static long long int get_tm_bands(const char *path)
{
    EC_INIT;
    long long int count = 0;
    DIR *dir = NULL;
    const struct dirent *entry;

    EC_NULL( dir = opendir(path) );

    while ((entry = readdir(dir)) != NULL)
        count++;
    count -= 2; /* All OSens I'm aware of return "." and "..", so just substract them, avoiding string comparison in loop */
        
EC_CLEANUP:
    if (dir)
        closedir(dir);
    if (ret != 0)
        return -1;
    return count;
}
Ejemplo n.º 4
0
/*!
 * Tokenize IP(4/6) addresses with an optional port into address and port
 *
 * @param ipurl    (r) IP URL string
 * @param address  (w) IP address
 * @param port     (w) IP port
 *
 * @returns 0 on success, -1 on failure
 *
 * Tokenize IPv4, IPv4:port, IPv6, [IPv6] or [IPv6:port] URL into address and
 * port and return two allocated strings with the address and the port.
 *
 * If the function returns 0, then address point to a newly allocated
 * valid address string, port may either be NULL or point to a newly
 * allocated port number.
 *
 * If the function returns -1, then the contents of address and port are
 * undefined.
 */
int tokenize_ip_port(const char *ipurl, char **address, char **port)
{
    EC_INIT;
    char *p = NULL;
    char *s;

    AFP_ASSERT(ipurl && address && port);
    EC_NULL( p = strdup(ipurl));

    /* Either ipv4, ipv4:port, ipv6, [ipv6] or [ipv6]:port */

    if (!strchr(p, ':')) {
        /* IPv4 address without port */
        *address = p;
        p = NULL;  /* prevent free() */
        *port = NULL;
        EC_EXIT_STATUS(0);
    }

    /* Either ipv4:port, ipv6, [ipv6] or [ipv6]:port */

    if (strchr(p, '.')) {
        /* ipv4:port */
        *address = p;
        p = strchr(p, ':');
        *p = '\0';
        EC_NULL( *port = strdup(p + 1));
        p = NULL; /* prevent free() */
        EC_EXIT_STATUS(0);
    }

    /* Either ipv6, [ipv6] or [ipv6]:port */

    if (p[0] != '[') {
        /* ipv6 */
        *address = p;
        p = NULL;  /* prevent free() */
        *port = NULL;
        EC_EXIT_STATUS(0);
    }

    /* [ipv6] or [ipv6]:port */

    EC_NULL( *address = strdup(p + 1) );

    if ((s = strchr(*address, ']')) == NULL) {
        LOG(log_error, logtype_dsi, "tokenize_ip_port: malformed ipv6 address %s\n", ipurl);
        EC_FAIL;
    }
    *s = '\0';
    /* address now points to the ipv6 address without [] */

    if (s[1] == ':') {
        /* [ipv6]:port */
        EC_NULL( *port = strdup(s + 2) );
    } else {
        /* [ipv6] */
        *port = NULL;
    }

EC_CLEANUP:
    if (p)
        free(p);
    EC_EXIT;
}