Переглянути джерело

Add option to enable/disable WebDAV methods

bel2125 3 роки тому
батько
коміт
6386dd0983
2 змінених файлів з 10 додано та 3 видалено
  1. 5 0
      docs/UserManual.md
  2. 5 3
      src/civetweb.c

+ 5 - 0
docs/UserManual.md

@@ -320,6 +320,11 @@ but this configuration is redundant. In a future version, the keep\_alive
 configuration option might be removed and automatically set to `yes` if
 configuration option might be removed and automatically set to `yes` if
 a timeout > 0 is set.
 a timeout > 0 is set.
 
 
+### enable\_webdav `no`
+Set this configuration option to `yes` to handle WebDAV specific HTTP methods:
+PROPFIND, PROPPATCH, LOCK, UNLOCK, MOVE, COPY.
+These methods are not allowed if the configuration option is set to `no`.
+
 ### enable\_websocket\_ping\_pong `no`
 ### enable\_websocket\_ping\_pong `no`
 If this configuration value is set to `yes`, the server will send a
 If this configuration value is set to `yes`, the server will send a
 websocket PING message to a websocket client, once the timeout set by
 websocket PING message to a websocket client, once the timeout set by

+ 5 - 3
src/civetweb.c

@@ -1998,6 +1998,7 @@ enum {
 	ENABLE_AUTH_DOMAIN_CHECK,
 	ENABLE_AUTH_DOMAIN_CHECK,
 	SSI_EXTENSIONS,
 	SSI_EXTENSIONS,
 	ENABLE_DIRECTORY_LISTING,
 	ENABLE_DIRECTORY_LISTING,
+	ENABLE_WEBDAV,
 	GLOBAL_PASSWORDS_FILE,
 	GLOBAL_PASSWORDS_FILE,
 	INDEX_FILES,
 	INDEX_FILES,
 	ACCESS_CONTROL_LIST,
 	ACCESS_CONTROL_LIST,
@@ -2142,7 +2143,8 @@ static const struct mg_option config_options[] = {
     {"enable_auth_domain_check", MG_CONFIG_TYPE_BOOLEAN, "yes"},
     {"enable_auth_domain_check", MG_CONFIG_TYPE_BOOLEAN, "yes"},
     {"ssi_pattern", MG_CONFIG_TYPE_EXT_PATTERN, "**.shtml$|**.shtm$"},
     {"ssi_pattern", MG_CONFIG_TYPE_EXT_PATTERN, "**.shtml$|**.shtm$"},
     {"enable_directory_listing", MG_CONFIG_TYPE_BOOLEAN, "yes"},
     {"enable_directory_listing", MG_CONFIG_TYPE_BOOLEAN, "yes"},
-    {"global_auth_file", MG_CONFIG_TYPE_FILE, NULL},
+	{"enable_webdav", MG_CONFIG_TYPE_BOOLEAN, "no" },
+	{"global_auth_file", MG_CONFIG_TYPE_FILE, NULL},
     {"index_files",
     {"index_files",
      MG_CONFIG_TYPE_STRING_LIST,
      MG_CONFIG_TYPE_STRING_LIST,
 #if defined(USE_LUA)
 #if defined(USE_LUA)
@@ -14827,8 +14829,8 @@ handle_request(struct mg_connection *conn)
 	/* 5.3. A webdav request (PROPFIND/PROPPATCH/LOCK/UNLOCK) */
 	/* 5.3. A webdav request (PROPFIND/PROPPATCH/LOCK/UNLOCK) */
 	if (is_webdav_request) {
 	if (is_webdav_request) {
 		/* TODO: Do we need a config option? */
 		/* TODO: Do we need a config option? */
-		int webdav_not_allowed = 0;
-		if (webdav_not_allowed) {
+		const char *webdav_enable = conn->dom_ctx->config[ENABLE_WEBDAV];
+		if (webdav_enable[0]!='y') {
 			mg_send_http_error(conn,
 			mg_send_http_error(conn,
 			                   405,
 			                   405,
 			                   "%s method not allowed",
 			                   "%s method not allowed",