file: invoke error handler in 403 case as well
authorJo-Philipp Wich <jow@openwrt.org>
Thu, 13 Feb 2014 19:43:43 +0000 (19:43 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Wed, 3 Sep 2014 12:03:56 +0000 (14:03 +0200)
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
file.c

diff --git a/file.c b/file.c
index f16b893d4d1fe229d3ee9a8e9dbfaecc12536515..055035eb7f715cd636918c2be75738c8338cb818 100644 (file)
--- a/file.c
+++ b/file.c
@@ -598,10 +598,14 @@ static void uh_file_data(struct client *cl, struct path_info *pi, int fd)
        file_write_cb(cl);
 }
 
+static bool __handle_file_request(struct client *cl, char *url);
+
 static void uh_file_request(struct client *cl, const char *url,
                            struct path_info *pi, struct blob_attr **tb)
 {
        int fd;
+       struct http_request *req = &cl->request;
+       char *error_handler;
 
        if (!(pi->stat.st_mode & S_IROTH))
                goto error;
@@ -626,6 +630,16 @@ static void uh_file_request(struct client *cl, const char *url,
        }
 
 error:
+       /* check for a previously set 403 redirect status to prevent infinite
+          recursion when the error page itself lacks sufficient permissions */
+       if (conf.error_handler && req->redirect_status != 403) {
+               req->redirect_status = 403;
+               error_handler = alloca(strlen(conf.error_handler) + 1);
+               strcpy(error_handler, conf.error_handler);
+               if (__handle_file_request(cl, error_handler))
+                       return;
+       }
+
        uh_client_error(cl, 403, "Forbidden",
                        "You don't have permission to access %s on this server.",
                        url);