Exemple #1
0
static int allowed_env(const char* pathname, const char* envvar) {
    const char* okpath = getenv(envvar);
    if (okpath == NULL) {
       errno = EINVAL;
       return 0;
    }

    // Check file name first
    if (allowed_match(pathname, okpath)) return 1;

    // Check directory name
    char* dirpathbuf = strdup(pathname);
    char* dirpath = dirname(dirpathbuf);
    int dir_ok = allowed_match(dirpath, okpath);
    free(dirpathbuf);

    return dir_ok;
}
Exemple #2
0
static int allowed_env(const char* pathname, const char* envvar) {
    const char* okpath = getenv(envvar);
    if (okpath == NULL) {
       errno = EINVAL;
       return 0;
    }
    const char* denypath = getenv("DENIED");
    if (denypath == NULL) denypath = "";

    int debug = getenv("PRELOAD_DEBUG") ? 1 : 0;

    // Check file name first
    if (allowed_match(pathname, okpath, denypath, debug)) return 1;

    // Check directory name
    char* dirpathbuf = strdup(pathname);
    char* dirpath = dirname(dirpathbuf);
    int dir_ok = allowed_match(dirpath, okpath, denypath, debug);
    free(dirpathbuf);

    return dir_ok;
}