Commit 5f629511 authored by Sergey Lyubka's avatar Sergey Lyubka Committed by rojer

Runtime DAV auth disable. Implement MOVE

    PUBLISHED_FROM=aec49928891972ecd6af9999fe3e1cb5ef00f24c
parent 2207e87c
...@@ -4641,10 +4641,8 @@ void mg_send_head(struct mg_connection *c, int status_code, ...@@ -4641,10 +4641,8 @@ void mg_send_head(struct mg_connection *c, int status_code,
static void send_http_error(struct mg_connection *nc, int code, static void send_http_error(struct mg_connection *nc, int code,
const char *reason) { const char *reason) {
if (reason == NULL) { (void) reason;
reason = ""; mg_send_head(nc, code, 0, NULL);
}
mg_printf(nc, "HTTP/1.1 %d %s\r\nContent-Length: 0\r\n\r\n", code, reason);
} }
#ifndef MG_DISABLE_SSI #ifndef MG_DISABLE_SSI
...@@ -5513,18 +5511,28 @@ static int remove_directory(const struct mg_serve_http_opts *opts, ...@@ -5513,18 +5511,28 @@ static int remove_directory(const struct mg_serve_http_opts *opts,
return 1; return 1;
} }
static void handle_move(struct mg_connection *nc, static void handle_move(struct mg_connection *c,
const struct mg_serve_http_opts *opts, const char *path, const struct mg_serve_http_opts *opts, const char *path,
struct http_message *hm) { struct http_message *hm) {
/* const struct mg_str *dest = mg_get_http_header(hm, "Destination");
* This method is not implemented now, but at least if (dest == NULL) {
* we have to send error 501 send_http_error(c, 411, NULL);
*/ } else {
(void) nc; const char *p = (char *) memchr(dest->p, '/', dest->len);
(void) opts; if (p != NULL && p[1] == '/' &&
(void) path; (p = (char *) memchr(p + 2, '/', dest->p + dest->len - p)) != NULL) {
(void) hm; char buf[MAX_PATH_SIZE];
send_http_error(nc, 501, "Not implemented"); snprintf(buf, sizeof(buf), "%s%.*s", opts->dav_document_root,
(int) (dest->p + dest->len - p), p);
if (rename(path, buf) == 0) {
send_http_error(c, 200, NULL);
} else {
send_http_error(c, 418, NULL);
}
} else {
send_http_error(c, 500, NULL);
}
}
} }
static void handle_delete(struct mg_connection *nc, static void handle_delete(struct mg_connection *nc,
...@@ -5545,10 +5553,10 @@ static void handle_delete(struct mg_connection *nc, ...@@ -5545,10 +5553,10 @@ static void handle_delete(struct mg_connection *nc,
/* Return -1 on error, 1 on success. */ /* Return -1 on error, 1 on success. */
static int create_itermediate_directories(const char *path) { static int create_itermediate_directories(const char *path) {
const char *s = path; const char *s;
/* Create intermediate directories if they do not exist */ /* Create intermediate directories if they do not exist */
while (*s) { for (s = path + 1; *s != '\0'; s++) {
if (*s == '/') { if (*s == '/') {
char buf[MAX_PATH_SIZE]; char buf[MAX_PATH_SIZE];
cs_stat_t st; cs_stat_t st;
...@@ -5558,7 +5566,6 @@ static int create_itermediate_directories(const char *path) { ...@@ -5558,7 +5566,6 @@ static int create_itermediate_directories(const char *path) {
return -1; return -1;
} }
} }
s++;
} }
return 1; return 1;
...@@ -6287,8 +6294,9 @@ void mg_send_http_file(struct mg_connection *nc, char *path, ...@@ -6287,8 +6294,9 @@ void mg_send_http_file(struct mg_connection *nc, char *path,
#ifndef MG_DISABLE_DAV_AUTH #ifndef MG_DISABLE_DAV_AUTH
} else if (is_dav && } else if (is_dav &&
(opts->dav_auth_file == NULL || (opts->dav_auth_file == NULL ||
!is_authorized(hm, path, is_directory, opts->auth_domain, (strcmp(opts->dav_auth_file, "-") != 0 &&
opts->dav_auth_file, 1))) { !is_authorized(hm, path, is_directory, opts->auth_domain,
opts->dav_auth_file, 1)))) {
mg_send_digest_auth_request(nc, opts->auth_domain); mg_send_digest_auth_request(nc, opts->auth_domain);
#endif #endif
} else if (!mg_vcmp(&hm->method, "MKCOL")) { } else if (!mg_vcmp(&hm->method, "MKCOL")) {
......
...@@ -1874,7 +1874,10 @@ struct mg_serve_http_opts { ...@@ -1874,7 +1874,10 @@ struct mg_serve_http_opts {
/* DAV document root. If NULL, DAV requests are going to fail. */ /* DAV document root. If NULL, DAV requests are going to fail. */
const char *dav_document_root; const char *dav_document_root;
/* DAV passwords file. If NULL, DAV requests are going to fail. */ /*
* DAV passwords file. If NULL, DAV requests are going to fail.
* If passwords file is set to "-", then DAV auth is disabled.
*/
const char *dav_auth_file; const char *dav_auth_file;
/* Glob pattern for the files to hide. */ /* Glob pattern for the files to hide. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment