1 #include <stdio.h>
  2 #include <stdlib.h>
  3 #include <fcntl.h>
  4 #include <unistd.h>
  5 #include "config.h"
  6 #include "client.h"
  7 #include "server.h"
  8 #include "rh_string.h"
  9 #include "handler.h"
 10 #include "http_request.h"
 11 #include "rh_chunk.h"
 12 
 13 
 14 
 15 /*
 16  *
 17  * autoindex
 18  *
 19  *
 20  * generates directory indexes
 21  *
 22  * problems:
 23  *      - readdir()
 24  *      - sorting
 25  *      - generating html output / html encoding
 26  *
 27  * doing that on EVERY request is sensless:
 28  *      - mostly directory contents for autoindexing dont change
 29  *
 30  * caching:
 31  *      - generate the content into a file of the form
 32  *              /cache/dir/DEVICE-INODE.html
 33  *
 34  *              device and inode are the numbers from the requested directory
 35  *
 36  *              this is security relevant:
 37  *              - may write files that are ownt by somebody else
 38  *              - may hold other informations than the directory index
 39  *                (eg. somebody may copy importend informations into this
 40  *                 file)
 41  *              
 42  *
 43  *      - change the mtime of this file with utimes()
 44  *        to the mtime of the requested directory
 45  *
 46  *        this can be used as the "Last Modified" time of that
 47  *        directory
 48  *
 49  *      - rh_stat() this cached html file AND the directory.
 50  *        this stat should never expire
 51  *
 52  * 
 53  * change:
 54  *      - if there comes inotifys for the html file or the directory
 55  *        unlink the file
 56  *        on next request it will be generated again
 57  *        but what if there are currently transfers with that file?
 58  *
 59  * cache hits:
 60  *      
 61  *      - rh_stat(requested directory)
 62  *
 63  *      - rh_stat(cached file)
 64  *
 65  *      - rewrite filename
 66  *      
 67  *      - handler_file writes the data to the client
 68  *        (remember: conditionals, partial requests, etc..)
 69  *
 70  * cache failures, without inotify:
 71  * 
 72  *      - in some cases (i forgot which) the mtime of a directory
 73  *        is not changed
 74  */
 75 
 76 #define TEST(_call)     if (0 != _call) return HANDLER_FAILURE
 77 
 78 
 79 
 80 DECLARE_HANDLER_FUNCTION (autoindex,exec)
 81 {
 82         http_request_t          *request;
 83         
 84 #ifdef RHTTPD_DUMP_HANDLER_CALL
 85         printf ("%s(%p)\n", __FUNCTION__, (void*)handler);
 86 #endif
 87 
 88         request = handler->base->request;
 89 
 90         if (NULL == request->st)
 91                 return HANDLER_FAILURE;
 92 #if 1
 93         if (!RH_STAT_ISDIR(request->st))
 94                 return HANDLER_SUCCESS;
 95 #endif
 96                 
 97         request->header_out.status = 403;
 98         
 99         return HANDLER_FAILURE;
100 }
101 
102 
103 DECLARE_HANDLER_BEGIN (autoindex, CONTENT)
104         .DECLARE_HANDLER_NULL   (autoindex, setup),
105         .DECLARE_HANDLER_NULL   (autoindex, init),
106         .DECLARE_HANDLER_NULL   (autoindex, init_global),
107         .DECLARE_HANDLER_NULL   (autoindex, free),
108         .DECLARE_HANDLER_NULL   (autoindex, free_global),
109         .DECLARE_HANDLER_SYMBOL (autoindex, exec),
110 DECLARE_HANDLER_END


syntax highlighted by Code2HTML, v. 0.9.1