add apply_location_config SAF

Sun, 23 Nov 2025 13:45:55 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 23 Nov 2025 13:45:55 +0100
changeset 638
14ae3d8c01ae
parent 637
85721a583f39
child 639
1e8416350254

add apply_location_config SAF

src/server/daemon/acl.c file | annotate | diff | comparison | revisions
src/server/daemon/ws-fn.c file | annotate | diff | comparison | revisions
src/server/public/acl.h 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/acl.c	Sun Nov 23 13:27:13 2025 +0100
+++ b/src/server/daemon/acl.c	Sun Nov 23 13:45:55 2025 +0100
@@ -39,20 +39,26 @@
 
 #define AUTH_TYPE_BASIC "basic"
 
-void acllist_createhandle(Session *sn, Request *rq) {
+int acllist_createhandle(Session *sn, Request *rq) {
     ACLListHandle *handle = pool_malloc(sn->pool, sizeof(ACLListHandle));
+    if(!handle) {
+        return 1;
+    }
     handle->defaultauthdb = NULL;
     handle->listhead = NULL;
     handle->listtail = NULL;
     rq->acllist = handle;
+    return 0;
 }
 
 /*
  * append or prepend an ACL
  */
-void acllist_add(Session *sn, Request *rq, ACLList *acl, int append) {
+int acllist_add(Session *sn, Request *rq, ACLList *acl, int append) {
     if(!rq->acllist) {
-        acllist_createhandle(sn, rq);
+        if(acllist_createhandle(sn, rq)) {
+            return 1;
+        }
     }
     ACLListHandle *list = rq->acllist;
 
@@ -61,6 +67,9 @@
     }
 
     ACLListElm *elm = pool_malloc(sn->pool, sizeof(ACLListElm));
+    if(!elm) {
+        return 1;
+    }
     elm->acl = acl;
     elm->next = NULL;
     if(list->listhead == NULL) {
@@ -75,14 +84,15 @@
             list->listhead = elm;
         }
     }
+    return 0;
 }
 
-void acllist_append(Session *sn, Request *rq, ACLList *acl) {
-    acllist_add(sn, rq, acl, 1);
+int acllist_append(Session *sn, Request *rq, ACLList *acl) {
+    return acllist_add(sn, rq, acl, 1);
 }
 
-void acllist_prepend(Session *sn, Request *rq, ACLList *acl) {
-    acllist_add(sn, rq, acl, 0);
+int acllist_prepend(Session *sn, Request *rq, ACLList *acl) {
+    return acllist_add(sn, rq, acl, 0);
 }
 
 uint32_t acl_oflag2mask(int oflags) {
--- a/src/server/daemon/ws-fn.c	Sun Nov 23 13:27:13 2025 +0100
+++ b/src/server/daemon/ws-fn.c	Sun Nov 23 13:45:55 2025 +0100
@@ -67,6 +67,7 @@
     { "find-pathinfo", pcheck_find_path, NULL, NULL, 0},
     { "append-acl", append_acl, NULL, NULL, 0},
     { "check-acl", check_acl, NULL, NULL, 0},
+    { "apply-location-config", apply_location_config, NULL, NULL, 0 },
     { "find-index", find_index, NULL, NULL, 0},
     { "dir-redirect", dir_redirect, NULL, NULL, 0},
     { "print-message", print_message, NULL, NULL, 0},
--- a/src/server/public/acl.h	Sun Nov 23 13:27:13 2025 +0100
+++ b/src/server/public/acl.h	Sun Nov 23 13:45:55 2025 +0100
@@ -145,8 +145,8 @@
  */
 
 // list
-void acllist_append(Session *sn, Request *rq, ACLList *acl);
-void acllist_prepend(Session *sn, Request *rq, ACLList *acl);
+int acllist_append(Session *sn, Request *rq, ACLList *acl);
+int acllist_prepend(Session *sn, Request *rq, ACLList *acl);
 
 /*
  * gets a access mask from open flags
--- a/src/server/safs/pathcheck.c	Sun Nov 23 13:27:13 2025 +0100
+++ b/src/server/safs/pathcheck.c	Sun Nov 23 13:45:55 2025 +0100
@@ -36,6 +36,7 @@
 #include "../daemon/acldata.h"
 #include "../daemon/session.h"
 #include "../daemon/vserver.h"
+#include "../daemon/request.h"
 
 #include "../daemon/vfs.h"
 
@@ -89,23 +90,25 @@
     return REQ_PROCEED;
 }
 
-int append_acl(pblock *pb, Session *sn, Request *rq) {
+static int add_acl(Session *sn, Request *rq, const char *aclname) {
     const VirtualServer *vs = request_get_vs(rq);
-    
-    WS_ASSERT(vs);
-    
+    ACLList *acl = acl_get(vs->acls, aclname);
+    if(!acl) {
+        log_ereport(
+                    LOG_MISCONFIG,
+                    "append-acl: acl %s not found", aclname);
+        return 1;
+    }
+    return acllist_append(sn, rq, acl);
+}
+
+int append_acl(pblock *pb, Session *sn, Request *rq) {
     char *aclname = pblock_findval("acl", pb);
     if(aclname) {
-        ACLList *acl = acl_get(vs->acls, aclname);
-        if(!acl) {
-            log_ereport(
-                    LOG_MISCONFIG,
-                    "append-acl: acl %s not found", aclname);
+        if(add_acl(sn, rq, aclname)) {
             protocol_status(sn, rq, 500, NULL);
             return REQ_ABORTED;
         }
-        
-        acllist_append(sn, rq, acl);
     }
     
     return REQ_PROCEED;
@@ -208,3 +211,24 @@
     
     return REQ_PROCEED;
 }
+
+int apply_location_config(pblock *pb, Session *sn, Request *rq) {
+    NSAPIRequest *req = (NSAPIRequest*)rq;
+    WSLocationConfig *config = req->location;
+    if(!config) {
+        return REQ_NOACTION;
+    }
+    
+    if(config->set_forcetls && config->forcetls) {
+        // TODO
+    }  
+    
+    CxIterator i = cxListIterator(config->acls);
+    cx_foreach(char*, aclname, i) {
+        if(add_acl(sn, rq, aclname)) {
+            return REQ_ABORTED;
+        }
+    }
+    
+    return REQ_PROCEED;
+}
--- a/src/server/safs/pathcheck.h	Sun Nov 23 13:27:13 2025 +0100
+++ b/src/server/safs/pathcheck.h	Sun Nov 23 13:45:55 2025 +0100
@@ -47,6 +47,8 @@
 
 int dir_redirect(pblock *pb, Session *sn, Request *rq);
 
+int apply_location_config(pblock *pb, Session *sn, Request *rq);
+
 #ifdef	__cplusplus
 }
 #endif

mercurial