X-Git-Url: http://www.dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fdirplex%2Fdirplex.c;h=ee7f650fb3d1ea1705dca2bebfbc919ace0bebcb;hb=HEAD;hp=65f09f715209c948f1fe723560e53501c246b8a2;hpb=a0b6c27cdb8e49868ec70fb276b3eb963c5852dd;p=ashd.git diff --git a/src/dirplex/dirplex.c b/src/dirplex/dirplex.c index 65f09f7..ee7f650 100644 --- a/src/dirplex/dirplex.c +++ b/src/dirplex/dirplex.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -131,6 +132,27 @@ static void handlefile(struct hthead *req, int fd, char *path) handle(req, fd, path, pat); } +static int checkaccess(char *path, char *name) +{ + int i, o; + struct config **cfs; + + if(*name == '.') { + cfs = getconfigs(sprintf3("%s/", path)); + for(i = 0; cfs[i] != NULL; i++) { + if(cfs[i]->dotallow != NULL) { + for(o = 0; cfs[i]->dotallow[o] != NULL; o++) { + if(!fnmatch(cfs[i]->dotallow[o], name, 0)) + return(1); + } + break; + } + } + return(0); + } + return(1); +} + static char *findfile(char *path, char *name, struct stat *sb) { DIR *dir; @@ -155,12 +177,20 @@ static char *findfile(char *path, char *name, struct stat *sb) continue; if(strncmp(dent->d_name, name, strlen(name))) continue; - fp = sprintf3("%s/%s", path, dent->d_name); - if(stat(fp, sb)) + fp = sprintf2("%s/%s", path, dent->d_name); + if(stat(fp, sb)) { + free(fp); continue; - if(!S_ISREG(sb->st_mode)) + } + if(!S_ISREG(sb->st_mode)) { + free(fp); continue; - ret = sstrdup(fp); + } + if(!checkaccess(path, dent->d_name)) { + free(fp); + continue; + } + ret = fp; break; } closedir(dir); @@ -216,9 +246,9 @@ static int checkentry(struct hthead *req, int fd, char *path, char *rest, char * char *newpath; int rv; - if(*el == '.') - return(0); if(!stat(sprintf3("%s/%s", path, el), &sb)) { + if(!checkaccess(path, el)) + return(0); if(S_ISDIR(sb.st_mode)) { if(!*rest) { stdredir(req, fd, 301, sprintf3("%s/", el)); @@ -249,9 +279,11 @@ static int checkentry(struct hthead *req, int fd, char *path, char *rest, char * static int checkdir(struct hthead *req, int fd, char *path, char *rest) { - char *cpath; + char *cpath, *newpath; struct config *cf, *ccf; struct child *ch; + struct stat sb; + int rv; cf = getconfig(path); if((cf->capture != NULL) && (cf->caproot || !cf->path || strcmp(cf->path, "."))) { @@ -270,6 +302,22 @@ static int checkdir(struct hthead *req, int fd, char *path, char *rest) childerror(req, fd); return(1); } + if(cf->reparse != NULL) { + newpath = (cf->reparse[0] == '/')?sstrdup(cf->reparse):sprintf2("%s/%s", path, cf->reparse); + rv = stat(newpath, &sb); + if(!rv && S_ISDIR(sb.st_mode)) { + rv = checkpath(req, fd, newpath, rest, !cf->parsecomb); + } else if(!rv && S_ISREG(sb.st_mode)) { + replrest(req, rest); + handlefile(req, fd, newpath); + rv = 1; + } else { + rv = !cf->parsecomb; + } + free(newpath); + if(rv) + return(rv); + } return(0); }