file: remove unused "auth" member from struct path_info
[project/uhttpd.git] / file.c
diff --git a/file.c b/file.c
index 2a94818..a4d9b1d 100644 (file)
--- a/file.c
+++ b/file.c
@@ -734,14 +734,13 @@ static int field_len(const char *ptr)
        _field(phys) \
        _field(name) \
        _field(info) \
-       _field(query) \
-       _field(auth)
+       _field(query)
 
 static void
 uh_defer_script(struct client *cl, struct dispatch_handler *d, struct path_info *pi)
 {
        struct deferred_request *dr;
-       char *_root, *_phys, *_name, *_info, *_query, *_auth;
+       char *_root, *_phys, *_name, *_info, *_query;
 
        cl->dispatch.req_free = uh_free_pending_request;
 
@@ -795,6 +794,7 @@ static bool __handle_file_request(struct client *cl, char *url)
        struct dispatch_handler *d;
        struct blob_attr *tb[__HDR_MAX];
        struct path_info *pi;
+       char *user, *pass;
 
        pi = uh_path_lookup(cl, url);
        if (!pi)
@@ -804,11 +804,15 @@ static bool __handle_file_request(struct client *cl, char *url)
                return true;
 
        blobmsg_parse(hdr_policy, __HDR_MAX, tb, blob_data(cl->hdr.head), blob_len(cl->hdr.head));
-       if (tb[HDR_AUTHORIZATION])
-               pi->auth = blobmsg_data(tb[HDR_AUTHORIZATION]);
+       if (tb[HDR_AUTHORIZATION]) {
+               if (!uh_auth_check(cl, pi->name, blobmsg_data(tb[HDR_AUTHORIZATION]), &user, &pass))
+                       return true;
 
-       if (!uh_auth_check(cl, pi))
-               return true;
+               if (user && pass) {
+                       blobmsg_add_string(&cl->hdr, "http-auth-user", user);
+                       blobmsg_add_string(&cl->hdr, "http-auth-pass", pass);
+               }
+       }
 
        d = dispatch_find(url, pi);
        if (d)
@@ -879,9 +883,14 @@ void uh_handle_request(struct client *cl)
        if (__handle_file_request(cl, url))
                return;
 
-       if (uh_handler_run(cl, &url, true) &&
-           (!url || __handle_file_request(cl, url)))
-               return;
+       if (uh_handler_run(cl, &url, true)) {
+               if (!url)
+                       return;
+
+               uh_handler_run(cl, &url, false);
+               if (__handle_file_request(cl, url))
+                       return;
+       }
 
        req->redirect_status = 404;
        if (conf.error_handler) {