X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fdirplex.c;h=063fbb4135812c8a95e8ca1474fd0682d397e73f;hb=bac8c1f95369efe4802bd9b41a7deba9468d1dd4;hp=45d8a1191a910f18593654339a4c5290c3bd4517;hpb=54cefabaa47acc0536805ee5ff2e6dda3df4b043;p=ashd.git diff --git a/src/dirplex.c b/src/dirplex.c index 45d8a11..063fbb4 100644 --- a/src/dirplex.c +++ b/src/dirplex.c @@ -34,6 +34,7 @@ #include #include #include +#include #define CH_SOCKET 0 #define CH_FORK 1 @@ -149,7 +150,7 @@ static struct rule *newrule(struct pattern *pat) for(i = 0; pat->rules[i]; i++); pat->rules = srealloc(pat->rules, sizeof(*pat->rules) * (i + 2)); - rule = pat->rules[i] = smalloc(sizeof(*rule)); + rule = pat->rules[i] = szmalloc(sizeof(*rule)); pat->rules[i + 1] = NULL; return(rule); } @@ -180,9 +181,10 @@ static struct config *readconfig(char *path) struct rule *rule; struct stat sb; - if(stat(path, &sb)) + p = sprintf3("%s/.htrc", path); + if(stat(p, &sb)) return(NULL); - if((s = fopen(sprintf3("%s/.htrc", path), "r")) == NULL) + if((s = fopen(p, "r")) == NULL) return(NULL); omalloc(cf); cf->mtime = sb.st_mtime; @@ -331,7 +333,7 @@ static struct config *getconfig(char *path) for(cf = cflist; cf != NULL; cf = cf->next) { if(!strcmp(cf->path, path)) { - if(stat(path, &sb)) + if(stat(sprintf3("%s/.htrc", path), &sb)) return(NULL); if(sb.st_mtime != cf->mtime) { freeconfig(cf); @@ -453,8 +455,8 @@ static void handlefile(struct hthead *req, int fd, char *path) return; } if((ch = findchild(path, pat->childnm)) == NULL) { - /* XXX: Send a 500 error. */ flog(LOG_ERR, "child %s requested, but was not declared", pat->childnm); + simpleerror(fd, 500, "Configuration Error", "The server is erroneously configured. Handler %s was requested, but not declared.", pat->childnm); return; } @@ -467,6 +469,8 @@ static void handlefile(struct hthead *req, int fd, char *path) static void handledir(struct hthead *req, int fd, char *path) { + /* XXX: Todo */ + simpleerror(fd, 403, "Not Authorized", "Will not send directory listings or indices yet"); } static int checkdir(struct hthead *req, int fd, char *path) @@ -494,15 +498,19 @@ static void serve(struct hthead *req, int fd) if(p2 == NULL) { if(stat(path, &sb)) { flog(LOG_WARNING, "failed to stat previously stated directory %s: %s", path, strerror(errno)); + simpleerror(fd, 500, "Internal Server Error", "The server encountered an unexpected condition."); goto fail; } break; } else { + simpleerror(fd, 404, "Not Found", "The requested URL has no corresponding resource."); goto fail; } } - if(*p == '.') + if(*p == '.') { + simpleerror(fd, 404, "Not Found", "The requested URL has no corresponding resource."); goto fail; + } getconfig(path); @@ -528,6 +536,7 @@ static void serve(struct hthead *req, int fd) free(tmp); break; } + simpleerror(fd, 404, "Not Found", "The requested URL has no corresponding resource."); goto fail; } @@ -555,6 +564,7 @@ static void serve(struct hthead *req, int fd) break; } + simpleerror(fd, 404, "Not Found", "The requested URL has no corresponding resource."); goto fail; next: @@ -573,12 +583,13 @@ static void serve(struct hthead *req, int fd) } else if(S_ISREG(sb.st_mode)) { handlefile(req, fd, path); } else { + simpleerror(fd, 404, "Not Found", "The requested URL has no corresponding resource."); goto fail; } goto out; fail: - /* XXX: Send error report. */ + /* No special handling, for now at least. */ out: free(path); }