#include <time.h>
#include <strings.h>
#include <dirent.h>
+#include <stdint.h>
#include <libubox/blobmsg.h>
static const char * uh_file_mktag(struct stat *s, char *buf, int len)
{
- snprintf(buf, len, "\"%x-%x-%x\"",
- (unsigned int) s->st_ino,
- (unsigned int) s->st_size,
- (unsigned int) s->st_mtime);
+ snprintf(buf, len, "\"%" PRIx64 "-%" PRIx64 "-%" PRIx64 "\"",
+ s->st_ino, s->st_size, s->st_mtime);
return buf;
}
bool dir = !!(files[i]->d_type & DT_DIR);
if (name[0] == '.' && name[1] == 0)
- continue;
+ goto next;
sprintf(file, "%s", name);
if (stat(local_path, &s))
- continue;
+ goto next;
if (!dir) {
suffix = "";
}
if (!(s.st_mode & mode))
- continue;
+ goto next;
uh_chunk_printf(cl,
"<li><strong><a href='%s%s%s'>%s</a>%s"
type, s.st_size / 1024.0);
*file = 0;
+next:
free(files[i]);
}
}
!uh_file_if_range(cl, &pi->stat) ||
!uh_file_if_unmodified_since(cl, &pi->stat) ||
!uh_file_if_none_match(cl, &pi->stat)) {
- ustream_printf(cl->us, "Content-Length: 0\r\n");
ustream_printf(cl->us, "\r\n");
uh_request_done(cl);
close(fd);
ustream_printf(cl->us, "Content-Type: %s\r\n",
uh_file_mime_lookup(pi->name));
- ustream_printf(cl->us, "Content-Length: %i\r\n\r\n",
+ ustream_printf(cl->us, "Content-Length: %" PRIu64 "\r\n\r\n",
pi->stat.st_size);
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;
}
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);