--- a/src/server/safs/pathcheck.c Tue Dec 27 11:16:39 2016 +0100 +++ b/src/server/safs/pathcheck.c Tue Dec 27 13:12:32 2016 +0100 @@ -108,3 +108,52 @@ return REQ_PROCEED; } + +int find_index(pblock *pb, Session *sn, Request *rq) { + char *inames = pblock_findval("index-names", pb); + if(!inames) { + log_ereport( + LOG_MISCONFIG, + "find-index: index-names parameter missing"); + return REQ_ABORTED; + } + + ssize_t ni = 0; + sstr_t *names = sstrsplit(sstr(inames), S(","), &ni); + if(ni <= 0) { + log_ereport( + LOG_MISCONFIG, + "find-index: no files specified in index-names parameter"); + return REQ_ABORTED; + } + + int ret = REQ_NOACTION; + + char *path = pblock_findkeyval(pb_key_path, rq->vars); + size_t pathlen = strlen(path); + sstr_t p = sstrn(path, pathlen); + if(path[pathlen-1] == '/') { + for(int i=0;i<ni;i++) { + sstr_t newpath = sstrcat(2, p, sstrtrim(names[i])); + struct stat s; + if(!stat(newpath.ptr, &s)) { + pblock_kvinsert( + pb_key_path, + newpath.ptr, + newpath.length, + rq->vars); + free(newpath.ptr); + ret = REQ_PROCEED; + } else { + free(newpath.ptr); + } + } + } + + for(int i=0;i<ni;i++) { + free(names[i].ptr); + } + free(names); + + return ret; +}