fixed pathcheck behavior

Thu, 11 Jul 2013 14:21:23 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 11 Jul 2013 14:21:23 +0200
changeset 87
bdec069d2239
parent 86
49bb6c8ceb2b
child 88
73b3485e96f1

fixed pathcheck behavior

src/server/daemon/httplistener.c file | annotate | diff | comparison | revisions
src/server/daemon/httprequest.c file | annotate | diff | comparison | revisions
src/server/daemon/ldap_auth.c file | annotate | diff | comparison | revisions
src/server/daemon/log.c file | annotate | diff | comparison | revisions
src/server/daemon/protocol.c file | annotate | diff | comparison | revisions
src/server/daemon/vfs.c file | annotate | diff | comparison | revisions
src/server/public/nsapi.h file | annotate | diff | comparison | revisions
src/server/safs/objecttype.c file | annotate | diff | comparison | revisions
src/server/safs/pathcheck.c file | annotate | diff | comparison | revisions
src/server/safs/service.c file | annotate | diff | comparison | revisions
src/server/webdav/parser.c file | annotate | diff | comparison | revisions
src/server/webdav/parser.h file | annotate | diff | comparison | revisions
src/server/webdav/saxhandler.cpp file | annotate | diff | comparison | revisions
src/server/webdav/webdav.c file | annotate | diff | comparison | revisions
--- a/src/server/daemon/httplistener.c	Tue Jul 09 20:56:01 2013 +0200
+++ b/src/server/daemon/httplistener.c	Thu Jul 11 14:21:23 2013 +0200
@@ -251,6 +251,11 @@
 }
 
 void* acceptor_thread(Acceptor *acceptor) {
+    WS_ASSERT(acceptor);
+    WS_ASSERT(acceptor->listener);
+    WS_ASSERT(acceptor->listener->session_handler);
+    WS_ASSERT(acceptor->listener->session_handler->enqueue_connection);
+    
     HttpListener *listener = acceptor->listener;
 
     for (;;) {
--- a/src/server/daemon/httprequest.c	Tue Jul 09 20:56:01 2013 +0200
+++ b/src/server/daemon/httprequest.c	Thu Jul 11 14:21:23 2013 +0200
@@ -58,7 +58,7 @@
 
 int handle_request(HTTPRequest *request, threadpool_t *thrpool) {
     // handle nsapi request
-
+    
     // create pool
     pool_handle_t *pool = pool_create();
 
@@ -440,8 +440,8 @@
              * process this object at a later time
              */
             if(ret == REQ_PROCESSING) {
-                /* save nsapi context */
-                /* add +1 to start next round with next function */
+                // save nsapi context
+                // add +1 to start next round with next function
                 rq->context.dtable_index = i + 1;
             }
 
@@ -458,13 +458,13 @@
     //printf("nsapi_nametrans\n");
     httpd_objset *objset = objset_create(sn->sn.pool);
     rq->rq.os = objset;
-    /* first object in objconf is the default object  TODO: make sure it is */
+    // first object in objconf is the default object  TODO: make sure it is
     objset_add_object(sn->sn.pool, objset, objconf->objects[0]);
 
-    httpd_object *obj = objset->obj[0]; /* nametrans only in default object */
+    httpd_object *obj = objset->obj[0]; // nametrans only in default object
     dtable *dt = object_get_dtable(obj, NSAPINameTrans);
 
-    /* execute directives */
+    // execute directives
     int ret = rq->context.last_req_code;
     char *name = NULL;
     char *ppath = NULL;
@@ -474,11 +474,11 @@
             ret = nsapi_exec(d, sn, rq);
         }
 
-        /* check for name or ppath */
+        // check for name or ppath
         name = pblock_findkeyval(pb_key_name, rq->rq.vars);
         ppath = pblock_findkeyval(pb_key_ppath, rq->rq.vars);
 
-        /* add additional objects to the objset */
+        // add additional objects to the objset
         if(add_objects(objconf, objset, sn, rq, name, ppath) == REQ_ABORTED) {
             fprintf(stderr, "add_objects failed\n");
             return REQ_ABORTED;
@@ -490,8 +490,8 @@
              * process this object at a later time
              */
             if(ret == REQ_PROCESSING) {
-                /* save nsapi context */
-                /* add +1 to start next round with next function */
+                // save nsapi context
+                // add +1 to start next round with next function
                 rq->context.dtable_index = i + 1;
             }
 
@@ -499,14 +499,14 @@
         }
     }
 
-    /* if no function has set the ppath var, translate it to docroot */
+    // if no function has set the ppath var, translate it to docroot
     if(ret == REQ_NOACTION && ppath == NULL) {
         sstr_t docroot = rq->vs->document_root;
         if(docroot.length < 1) {
             printf("docroot too short\n");
             return REQ_ABORTED; /* docroot too short */
         }
-        /* if there is a trailing '/', remove it */
+        // if there is a trailing '/', remove it
         if(docroot.ptr[docroot.length - 1] == '/') {
             docroot.length--;
         }
@@ -543,17 +543,15 @@
 
         // execute directives
         for(int j=NCX_DI(rq);j<dt->ndir;j++) {
-            if(ret == REQ_NOACTION) {
+            if(ret == REQ_NOACTION || REQ_PROCEED) {
                 directive *d = dt->dirs[j];
                 ret = nsapi_exec(d, sn, rq);
-            }
-            
-            if(ret != REQ_NOACTION) {
+            } else {
                 if(ret == REQ_PROCESSING) {
-                    /* save nsapi context */
+                    // save nsapi context
                     rq->context.objset_index = i;
 
-                    /* add +1 to start next round with next function */
+                    // add +1 to start next round with next function
                     rq->context.dtable_index = j + 1;
                 }
 
@@ -570,7 +568,7 @@
     httpd_objset *objset = rq->rq.os;
 
     if(NCX_OI(rq) == -1) {
-        /* object index is undefined -> define correct object index */
+        // object index is undefined -> define correct object index
         NCX_OI(rq) = objset->pos - 1;
     }
 
@@ -598,10 +596,10 @@
                     return ret;
                 }
                 case REQ_PROCESSING: {
-                    /* save nsapi context */
+                    // save nsapi context
                     rq->context.objset_index = i;
 
-                    /* add +1 to start next round with next function */
+                    // add +1 to start next round with next function
                     rq->context.dtable_index = j + 1;
                     return ret;
                 }
@@ -624,7 +622,7 @@
     sstr_t path = sstr(pblock_findkeyval(pb_key_ppath, rq->rq.vars));
     sstr_t ct;
     if(path.ptr[path.length - 1] == '/') {
-        /* directory */
+        // directory
         ct = sstrn("internal/directory", 18);
     } else {
         ct = sstrn("text/plain", 10);
@@ -654,22 +652,22 @@
             if(ret == REQ_NOACTION) {
                 directive *d = dt->dirs[j];
 
-                /* check type parameter */           
+                // check type parameter          
                 char *dtp = pblock_findkeyval(pb_key_type, d->param);
                 if(dtp) {
-                    /* type parameter for directive */
+                    // type parameter for directive
                     if(!content_type) {
                         content_type = pblock_findkeyval(
                                 pb_key_content_type,
                                 rq->rq.srvhdrs);
                     }
-                    /* compare types */
+                    // compare types
                     if(strcmp(dtp, content_type) != 0) {
                         continue;
                     }
                 }
 
-                /* check method parameter */
+                // check method parameter
                 char *dmt = pblock_findkeyval(pb_key_method, d->param);
                 if(dmt) {
                     if(!method) {
@@ -681,7 +679,7 @@
                     }
                 }
 
-                /* execute the saf */
+                // execute the saf
                 ret = nsapi_exec(d, sn, rq);
             }
             
@@ -693,10 +691,10 @@
                      */
                     net_finish(sn->sn.csd);
                 } else if(ret == REQ_PROCESSING) {
-                    /* save nsapi context */
+                    // save nsapi context
                     rq->context.objset_index = i;
 
-                    /* add +1 to start next round with next function */
+                    // add +1 to start next round with next function
                     rq->context.dtable_index = j + 1;
                 }
 
@@ -730,10 +728,10 @@
             
             if(ret != REQ_NOACTION) {
                 if(ret == REQ_PROCESSING) {
-                    /* save nsapi context */
+                    // save nsapi context
                     rq->context.objset_index = i;
 
-                    /* add +1 to start next round with next function */
+                    // add +1 to start next round with next function
                     rq->context.dtable_index = j + 1;
                 }
 
--- a/src/server/daemon/ldap_auth.c	Tue Jul 09 20:56:01 2013 +0200
+++ b/src/server/daemon/ldap_auth.c	Thu Jul 11 14:21:23 2013 +0200
@@ -61,9 +61,12 @@
 #ifdef LINUX
     char *ldap_uri = NULL;
     asprintf(&ldap_uri, "ldap://%s:%d", config->hostname, config->port);
-    if(ldap_initialize(&ld, ldap_uri)) {
+    int init_ret = ldap_initialize(&ld, ldap_uri);
+    free(ldap_uri);
+    if(init_ret) {
         fprintf(stderr, "ldap_initialize failed\n");
     }
+    
 #else
     ld = ldap_init(config->hostname, config->port);
 #endif
--- a/src/server/daemon/log.c	Tue Jul 09 20:56:01 2013 +0200
+++ b/src/server/daemon/log.c	Thu Jul 11 14:21:23 2013 +0200
@@ -267,6 +267,17 @@
 }
 
 
+void ws_log_assert(const char *file, const char *func, int line) {
+    log_ereport(
+            LOG_CATASTROPHE,
+            "assertion failed: %s: %s:%d",
+            file,
+            func,
+            line);
+    exit(-1);
+}
+
+
 /*
  * access log
  * This source file only manages access log files. IO is performed directly
--- a/src/server/daemon/protocol.c	Tue Jul 09 20:56:01 2013 +0200
+++ b/src/server/daemon/protocol.c	Thu Jul 11 14:21:23 2013 +0200
@@ -57,6 +57,8 @@
  */
 NSAPI_PUBLIC const char * protocol_status_message (int code)
 {
+    WS_ASSERT(code > 0);
+    
     const char *r;
 
     switch (code)
--- a/src/server/daemon/vfs.c	Tue Jul 09 20:56:01 2013 +0200
+++ b/src/server/daemon/vfs.c	Thu Jul 11 14:21:23 2013 +0200
@@ -59,6 +59,8 @@
 }
 
 void vfs_add(char *name, VFS *vfs) {
+    WS_ASSERT(name);
+    
     if(!vfs_map) {
         vfs_init();
     }
@@ -66,6 +68,9 @@
 }
 
 VFSContext* vfs_request_context(Session *sn, Request *rq) {
+    WS_ASSERT(sn);
+    WS_ASSERT(rq);
+    
     VFSContext *ctx = pool_malloc(sn->pool, sizeof(VFSContext));
     ctx->sn = sn;
     ctx->rq = rq;
@@ -79,6 +84,8 @@
 }
 
 SYS_FILE vfs_open(VFSContext *ctx, char *path, int oflags) {
+    WS_ASSERT(path);
+    
     Session *sn;
     Request *rq;
     pool_handle_t *pool;
@@ -250,6 +257,8 @@
 }
 
 VFS_DIR vfs_opendir(VFSContext *ctx, char *path) {
+    WS_ASSERT(path);
+    
     Session *sn;
     Request *rq;
     pool_handle_t *pool;
--- a/src/server/public/nsapi.h	Tue Jul 09 20:56:01 2013 +0200
+++ b/src/server/public/nsapi.h	Thu Jul 11 14:21:23 2013 +0200
@@ -1447,6 +1447,18 @@
 threadpool_job* threadpool_get_job(threadpool_t *pool);
 void threadpool_run(threadpool_t *pool, job_callback_f func, void *data);
 
+
+// assert
+void ws_log_assert(const char *file, const char *func, int line);
+#ifdef _DEBUG
+#ifndef __FUNCTION__
+#define __FUNCTION__ __func__
+#endif 
+#define WS_ASSERT(c) if(!c) ws_log_assert(__FILE__, __FUNCTION__, __LINE__)
+#else
+#define WS_ASSERT(c)
+#endif
+
 /* end new macro and function definitions */
 
 #define SYS_STDERR STDERR_FILENO
--- a/src/server/safs/objecttype.c	Tue Jul 09 20:56:01 2013 +0200
+++ b/src/server/safs/objecttype.c	Thu Jul 11 14:21:23 2013 +0200
@@ -59,6 +59,11 @@
 
         // get the mime type for the ext from the server configuration
         ServerConfiguration *config = session_get_config(sn);
+        
+        WS_ASSERT(config);
+        WS_ASSERT(config->mimetypes);
+        WS_ASSERT(config->mimetypes->map);
+        
         char *type = ucx_map_sstr_get(config->mimetypes->map, ext);
         
         if(!type) {
--- a/src/server/safs/pathcheck.c	Tue Jul 09 20:56:01 2013 +0200
+++ b/src/server/safs/pathcheck.c	Thu Jul 11 14:21:23 2013 +0200
@@ -76,6 +76,8 @@
 int append_acl(pblock *pb, Session *sn, Request *rq) {
     const VirtualServer *vs = request_get_vs(rq);
     
+    WS_ASSERT(vs);
+    
     char *aclname = pblock_findval("acl", pb);
     if(aclname) {
         ACLList *acl = acl_get(vs->acls, aclname);
@@ -90,7 +92,7 @@
         acllist_append(sn, rq, acl);
     }
     
-    return REQ_NOACTION; // TODO: should return REQ_PROCEED, fix nsapi_pathcheck
+    return REQ_PROCEED;
 }
 
 
--- a/src/server/safs/service.c	Tue Jul 09 20:56:01 2013 +0200
+++ b/src/server/safs/service.c	Thu Jul 11 14:21:23 2013 +0200
@@ -115,7 +115,7 @@
         sfd.header = NULL;
         sfd.trailer = NULL;
         net_sendfile(sn->csd, &sfd);
-    }
+    } // else: status 302 set by prepare_service_file
     
     vfs_close(fd);
 
@@ -196,7 +196,7 @@
     pblock_nvinsert("allow", allow, rq->srvhdrs);
     pblock_nvinsert("dav", dav, rq->srvhdrs);
     pblock_nninsert("content-length", 0, rq->srvhdrs);
-    protocol_status(sn, rq, 200, NULL);
+    protocol_status(sn, rq, 204, NULL);
     http_start_response(sn, rq);
 
     return REQ_PROCEED;
--- a/src/server/webdav/parser.c	Tue Jul 09 20:56:01 2013 +0200
+++ b/src/server/webdav/parser.c	Thu Jul 11 14:21:23 2013 +0200
@@ -74,30 +74,21 @@
         return davrq;
     }
     
-    PropfindParser *parser = pool_malloc(sn->pool, sizeof(PropfindParser));
-    parser->pool = sn->pool;
-    parser->rq = davrq;
-    parser->property = NULL;
-    parser->davPropTag = 0;
+    PropfindParser parser;
+    parser.pool = sn->pool;
+    parser.rq = davrq;
+    parser.davPropTag = 0;
     
     while((r = xmlTextReaderRead(reader)) == 1) {
          int nodetype = xmlTextReaderNodeType(reader);
-         const xmlChar *name = xmlTextReaderConstLocalName(reader);
          if(nodetype == XML_READER_TYPE_ELEMENT) {
-             if(propfind_begin_elm(parser, reader)) {
-                 fprintf(stderr, "propfind xml error\n");
-                 break;
-             }
-         } else if(nodetype == XML_READER_TYPE_END_ELEMENT) {
-             if(propfind_end_elm(parser, reader)) {
+             if(propfind_begin_elm(&parser, reader)) {
                  fprintf(stderr, "propfind xml error\n");
                  break;
              }
          }
     }
     
-    pool_free(sn->pool, parser);
-    
     return davrq;
 }
 
@@ -105,31 +96,22 @@
     pool_handle_t *pool = p->pool;
     const xmlChar *ns = xmlTextReaderConstNamespaceUri(elm);
     const xmlChar *name = xmlTextReaderConstLocalName(elm);
+    int depth = xmlTextReaderDepth(elm);
     
-    if(ns == NULL) {
-        fprintf(stderr, "ERROR: namespace is null!\n");
-        return -1;
+    // check namespace
+    int dav_ns = 0;
+    if(ns) {
+        dav_ns = xstreq(ns, "DAV:") ? 1 : 0;
     }
     
-    int dav_ns = xstreq(ns, "DAV:") ? 1 : 0;
-    
-    if(dav_ns && xstreq(name, "allprop")) {
+    if(dav_ns && xstreq(name, "allprop") && depth == 1) {
         p->rq->allprop = 1;
-    } else if(dav_ns && xstreq(name, "prop")) {
+    } else if(dav_ns && xstreq(name, "prop") && depth == 1) {
         p->davPropTag = 1;
-    } else if(p->davPropTag && !p->property && !p->rq->allprop) {
+    } else if(p->davPropTag && !p->rq->allprop && depth == 2) {
         DavProperty *property = pool_malloc(pool, sizeof(DavProperty));
-        size_t nslen = strlen(ns);
-        size_t namelen = strlen(name);
-        if(nslen > 0) {
-            property->xmlns = xmlnsmap_put(p->rq->nsmap, (char*)ns);
-        } else {
-            property->xmlns = NULL;
-        }
-
-        property->name = pool_malloc(pool, namelen + 1);
-        property->name[namelen] = 0;
-        memcpy(property->name, name, namelen);
+        property->xmlns = xmlnsmap_put(p->rq->nsmap, (char*)ns);
+        property->name = pool_strdup(pool, name);
         
         // add property to DavRequest
         UcxDlist *elm = pool_malloc(pool, sizeof(UcxDlist));
@@ -142,17 +124,3 @@
     return 0;
 }
 
-int propfind_end_elm(PropfindParser *p, xmlTextReaderPtr elm) {
-    pool_handle_t *pool = p->pool;
-    const xmlChar *ns = xmlTextReaderConstNamespaceUri(elm);
-    const xmlChar *name = xmlTextReaderConstLocalName(elm);
-    
-    if(ns == NULL) {
-        fprintf(stderr, "ERROR: namespace is null!\n");
-        return -1;
-    }
-    
-    // nothing here yet
-    
-    return 0;
-}
--- a/src/server/webdav/parser.h	Tue Jul 09 20:56:01 2013 +0200
+++ b/src/server/webdav/parser.h	Thu Jul 11 14:21:23 2013 +0200
@@ -43,7 +43,6 @@
 typedef struct PropfindParser {
     PropfindRequest *rq;
     pool_handle_t   *pool;
-    DavProperty     *property;
     int             davPropTag;
 } PropfindParser;
     
@@ -55,7 +54,6 @@
         size_t len);
 
 int propfind_begin_elm(PropfindParser *parser, xmlTextReaderPtr elm);
-int propfind_end_elm(PropfindParser *parser, xmlTextReaderPtr elm);
 
 
 #ifdef	__cplusplus
--- a/src/server/webdav/saxhandler.cpp	Tue Jul 09 20:56:01 2013 +0200
+++ b/src/server/webdav/saxhandler.cpp	Thu Jul 11 14:21:23 2013 +0200
@@ -82,9 +82,6 @@
         davPropTag = true;
     } else if(davPropTag && property == NULL && !davrq->allprop) {
         property = (DavProperty*)pool_malloc(pool, sizeof(DavProperty));
-        //property = (DavProperty*)malloc(sizeof(DavProperty));
-        /* TODO: pool_malloc makes big mistakes!! */
-        // Fixed or not? It works
 
         size_t nslen = strlen(ns);
         size_t namelen = strlen(name);
--- a/src/server/webdav/webdav.c	Tue Jul 09 20:56:01 2013 +0200
+++ b/src/server/webdav/webdav.c	Thu Jul 11 14:21:23 2013 +0200
@@ -252,6 +252,10 @@
      * get requested properties and initialize some stuff
      */
     DavCollection *collection = rq->davCollection;
+    if(!collection) {
+        collection = pool_malloc(sn->pool, sizeof(DavCollection));
+        collection->mgr = ucx_map_cstr_get(pmgr_map, "default");
+    }
     
     PropfindRequest *davrq = dav_parse_propfind2(sn, rq, xml_body, xml_len);  
     davrq->sn = sn;
@@ -390,6 +394,10 @@
      * parse the xml request and create the proppatch object
      */
     DavCollection *collection = rq->davCollection;
+    if(!collection) {
+        collection = pool_malloc(sn->pool, sizeof(DavCollection));
+        collection->mgr = ucx_map_cstr_get(pmgr_map, "default");
+    }
     
     ProppatchRequest *davrq = dav_parse_proppatch(sn, rq, xml_body, xml_len);
     davrq->sn = sn;
@@ -668,6 +676,10 @@
 }
 
 XmlNs* xmlnsmap_put(XmlNsMap *map, char *ns) {
+    if(!ns) {
+        return NULL;
+    }
+    
     XmlNs *xmlns = xmlnsmap_get(map, ns);
     if(xmlns != NULL) {
         return xmlns;

mercurial