adds find-index saf

Tue, 27 Dec 2016 13:12:32 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 27 Dec 2016 13:12:32 +0100
changeset 131
70010b94bda5
parent 130
198ad9d8cec1
child 132
e9afb5387007

adds find-index saf

src/server/daemon/ws-fn.c file | annotate | diff | comparison | revisions
src/server/safs/pathcheck.c file | annotate | diff | comparison | revisions
src/server/safs/pathcheck.h file | annotate | diff | comparison | revisions
--- a/src/server/daemon/ws-fn.c	Tue Dec 27 11:16:39 2016 +0100
+++ b/src/server/daemon/ws-fn.c	Tue Dec 27 13:12:32 2016 +0100
@@ -62,6 +62,7 @@
     { "find-pathinfo", pcheck_find_path, NULL, NULL, 0},
     { "append-acl", append_acl, NULL, NULL, 0},
     { "check-acl", check_acl, NULL, NULL, 0},
+    { "find-index", find_index, NULL, NULL, 0},
     { "print-message", print_message, NULL, NULL, 0},
     { "common-log", common_log, NULL, NULL, 0},
     { "send-cgi", send_cgi, NULL, NULL, 0},
--- 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;
+}
--- a/src/server/safs/pathcheck.h	Tue Dec 27 11:16:39 2016 +0100
+++ b/src/server/safs/pathcheck.h	Tue Dec 27 13:12:32 2016 +0100
@@ -43,6 +43,8 @@
 
 int check_acl(pblock *pb, Session *sn, Request *rq);
 
+int find_index(pblock *pb, Session *sn, Request *rq);
+
 #ifdef	__cplusplus
 }
 #endif

mercurial