From: Fredrik Tolf Date: Mon, 23 Jan 2012 07:01:53 +0000 (+0100) Subject: dirplex: Match pathname directives relative to the config path. X-Git-Tag: 0.11~30 X-Git-Url: http://www.dolda2000.com/gitweb/?p=ashd.git;a=commitdiff_plain;h=edcd094e7e9c1f018f0664f78cf7d6c625e1f476 dirplex: Match pathname directives relative to the config path. --- diff --git a/doc/dirplex.doc b/doc/dirplex.doc index fb4b7e7..fce3565 100644 --- a/doc/dirplex.doc +++ b/doc/dirplex.doc @@ -224,11 +224,13 @@ The following rules are recognized: *pathname* 'PATTERN'...:: - Matches if the entire path (relative as considered from the - root directory being served) of the file under consideration + Matches if the entire path of the file under consideration matches any of the 'PATTERNs'. A 'PATTERN' is an ordinary glob pattern, except that slashes are not matched by wildcards. See - *fnmatch*(3) for more information. + *fnmatch*(3) for more information. If a *pathname* rule is + specified in a `.htrc` file, the path will be examined as + relative to the directory containing the `.htrc` file, rather + than to the root directory being served. *default*:: diff --git a/src/dirplex/conf.c b/src/dirplex/conf.c index 10d501f..84c035d 100644 --- a/src/dirplex/conf.c +++ b/src/dirplex/conf.c @@ -374,7 +374,7 @@ struct child *findchild(char *file, char *name, struct config **cf) struct pattern *findmatch(char *file, int trydefault, int dir) { int i, o, c; - char *bn; + char *bn, *ln; struct config **cfs; struct pattern *pat; struct rule *rule; @@ -386,6 +386,15 @@ struct pattern *findmatch(char *file, int trydefault, int dir) bn = file; cfs = getconfigs(file); for(c = 0; cfs[c] != NULL; c++) { + if(cfs[c]->path == NULL) { + ln = file; + } else { + pl = strlen(cfs[c]->path); + if((strlen(file) > pl) && !strncmp(file, cfs[c]->path, pl) && (file[pl] == '/')) + ln = file + pl + 1; + else + ln = file; /* This should only happen in the base directory. */ + } for(pat = cfs[c]->patterns; pat != NULL; pat = pat->next) { if(!dir && (pat->type == PT_DIR)) continue; @@ -401,7 +410,7 @@ struct pattern *findmatch(char *file, int trydefault, int dir) break; } else if(rule->type == PAT_PATHNAME) { for(o = 0; rule->patterns[o] != NULL; o++) { - if(!fnmatch(rule->patterns[o], file, FNM_PATHNAME)) + if(!fnmatch(rule->patterns[o], ln, FNM_PATHNAME)) break; } if(rule->patterns[o] == NULL) @@ -411,10 +420,7 @@ struct pattern *findmatch(char *file, int trydefault, int dir) if(!trydefault) break; } else if(rule->type == PAT_LOCAL) { - if(cfs[c]->path == NULL) - break; - pl = strlen(cfs[c]->path); - if(!((strlen(file) > pl) && !strncmp(file, cfs[c]->path, pl) && (file[pl] == '/') && !strchr(file + pl + 1, '/'))) + if(strchr(ln, '/')) break; } }