diff --git a/patches/base/0025-uhttpd-backport-2-fixes.patch b/patches/base/0025-uhttpd-backport-2-fixes.patch new file mode 100644 index 000000000..5b4039e4e --- /dev/null +++ b/patches/base/0025-uhttpd-backport-2-fixes.patch @@ -0,0 +1,207 @@ +From 2238d38eca53468d8a52209478f801580a54c1ed Mon Sep 17 00:00:00 2001 +From: John Crispin +Date: Wed, 17 Aug 2022 16:31:37 +0200 +Subject: [PATCH] uhttpd: backport 2 fixes + +Signed-off-by: John Crispin +--- + .../services/uhttpd/patches/error.patch | 165 ++++++++++++++++++ + .../services/uhttpd/patches/path.patch | 14 ++ + 2 files changed, 179 insertions(+) + create mode 100644 package/network/services/uhttpd/patches/error.patch + create mode 100644 package/network/services/uhttpd/patches/path.patch + +diff --git a/package/network/services/uhttpd/patches/error.patch b/package/network/services/uhttpd/patches/error.patch +new file mode 100644 +index 0000000000..374aca0a51 +--- /dev/null ++++ b/package/network/services/uhttpd/patches/error.patch +@@ -0,0 +1,165 @@ ++From c5eac5d27fb3967d796fe3c75f4cc1bdcd18ed01 Mon Sep 17 00:00:00 2001 ++From: Jo-Philipp Wich ++Date: Wed, 10 Aug 2022 21:00:32 +0200 ++Subject: [PATCH] file: support using dynamic script handlers as error pages ++ ++Rework the current request handler code to not require an error page path ++to be an actual file system entity. ++ ++Signed-off-by: Jo-Philipp Wich ++--- ++ file.c | 42 ++++++++++++++++++++++++++---------------- ++ 1 file changed, 26 insertions(+), 16 deletions(-) ++ ++diff --git a/file.c b/file.c ++index 1548900..ac781c1 100644 ++--- a/file.c +++++ b/file.c ++@@ -49,6 +49,7 @@ struct deferred_request { ++ struct dispatch_handler *d; ++ struct client *cl; ++ struct path_info pi; +++ char *url; ++ bool called, path; ++ }; ++ ++@@ -631,7 +632,7 @@ 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 bool __handle_file_request(struct client *cl, char *url, bool is_error_handler); ++ ++ static void uh_file_request(struct client *cl, const char *url, ++ struct path_info *pi, struct blob_attr **tb) ++@@ -684,7 +685,7 @@ error: ++ 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)) +++ if (__handle_file_request(cl, error_handler, true)) ++ return; ++ } ++ ++@@ -728,10 +729,8 @@ dispatch_find(const char *url, struct path_info *pi) ++ } ++ ++ static void ++-uh_invoke_script(struct client *cl, struct dispatch_handler *d, struct path_info *pi) +++uh_invoke_script(struct client *cl, struct dispatch_handler *d, char *url, struct path_info *pi) ++ { ++- char *url = blobmsg_data(blob_data(cl->hdr.head)); ++- ++ n_requests++; ++ d->handle_request(cl, url, pi); ++ } ++@@ -752,7 +751,7 @@ static void uh_complete_request(struct client *cl) ++ cl = dr->cl; ++ dr->called = true; ++ cl->dispatch.data_blocked = false; ++- uh_invoke_script(cl, dr->d, dr->path ? &dr->pi : NULL); +++ uh_invoke_script(cl, dr->d, dr->url, dr->path ? &dr->pi : NULL); ++ client_poll_post_data(cl); ++ ustream_poll(cl->us); ++ } ++@@ -787,10 +786,10 @@ static int field_len(const char *ptr) ++ _field(query) ++ ++ static void ++-uh_defer_script(struct client *cl, struct dispatch_handler *d, struct path_info *pi) +++uh_defer_script(struct client *cl, struct dispatch_handler *d, char *url, struct path_info *pi) ++ { ++ struct deferred_request *dr; ++- char *_root, *_phys, *_name, *_info, *_query; +++ char *_url, *_root, *_phys, *_name, *_info, *_query; ++ ++ cl->dispatch.req_free = uh_free_pending_request; ++ ++@@ -798,7 +797,7 @@ uh_defer_script(struct client *cl, struct dispatch_handler *d, struct path_info ++ /* allocate enough memory to duplicate all path_info strings in one block */ ++ #undef _field ++ #define _field(_name) &_##_name, field_len(pi->_name), ++- dr = calloc_a(sizeof(*dr), path_info_fields NULL); +++ dr = calloc_a(sizeof(*dr), &_url, strlen(url), path_info_fields NULL); ++ ++ memcpy(&dr->pi, pi, sizeof(*pi)); ++ dr->path = true; ++@@ -808,11 +807,12 @@ uh_defer_script(struct client *cl, struct dispatch_handler *d, struct path_info ++ #define _field(_name) if (pi->_name) dr->pi._name = strcpy(_##_name, pi->_name); ++ path_info_fields ++ } else { ++- dr = calloc(1, sizeof(*dr)); +++ dr = calloc_a(sizeof(*dr), &_url, strlen(url), NULL); ++ } ++ ++ cl->dispatch.req_data = dr; ++ cl->dispatch.data_blocked = true; +++ dr->url = strcpy(_url, url); ++ dr->cl = cl; ++ dr->d = d; ++ list_add(&dr->list, &pending_requests); ++@@ -825,13 +825,13 @@ uh_invoke_handler(struct client *cl, struct dispatch_handler *d, char *url, stru ++ return d->handle_request(cl, url, pi); ++ ++ if (n_requests >= conf.max_script_requests) ++- return uh_defer_script(cl, d, pi); +++ return uh_defer_script(cl, d, url, pi); ++ ++ cl->dispatch.req_free = uh_complete_request; ++- uh_invoke_script(cl, d, pi); +++ uh_invoke_script(cl, d, url, pi); ++ } ++ ++-static bool __handle_file_request(struct client *cl, char *url) +++static bool __handle_file_request(struct client *cl, char *url, bool is_error_handler) ++ { ++ static const struct blobmsg_policy hdr_policy[__HDR_MAX] = { ++ [HDR_AUTHORIZATION] = { "authorization", BLOBMSG_TYPE_STRING }, ++@@ -846,6 +846,16 @@ static bool __handle_file_request(struct client *cl, char *url) ++ struct path_info *pi; ++ char *user, *pass, *auth; ++ +++ if (is_error_handler) { +++ d = dispatch_find(url, NULL); +++ +++ if (d) { +++ uh_invoke_handler(cl, d, url, NULL); +++ +++ return true; +++ } +++ } +++ ++ pi = uh_path_lookup(cl, url); ++ if (!pi) ++ return false; ++@@ -931,7 +941,7 @@ void uh_handle_request(struct client *cl) ++ if (d) ++ return uh_invoke_handler(cl, d, url, NULL); ++ ++- if (__handle_file_request(cl, url)) +++ if (__handle_file_request(cl, url, false)) ++ return; ++ ++ if (uh_handler_run(cl, &url, true)) { ++@@ -939,7 +949,7 @@ void uh_handle_request(struct client *cl) ++ return; ++ ++ uh_handler_run(cl, &url, false); ++- if (__handle_file_request(cl, url)) +++ if (__handle_file_request(cl, url, false)) ++ return; ++ } ++ ++@@ -947,7 +957,7 @@ void uh_handle_request(struct client *cl) ++ if (conf.error_handler) { ++ error_handler = alloca(strlen(conf.error_handler) + 1); ++ strcpy(error_handler, conf.error_handler); ++- if (__handle_file_request(cl, error_handler)) +++ if (__handle_file_request(cl, error_handler, true)) ++ return; ++ } ++ ++-- ++2.35.1 ++ ++ +diff --git a/package/network/services/uhttpd/patches/path.patch b/package/network/services/uhttpd/patches/path.patch +new file mode 100644 +index 0000000000..27eebb56d8 +--- /dev/null ++++ b/package/network/services/uhttpd/patches/path.patch +@@ -0,0 +1,14 @@ ++diff --git a/utils.c b/utils.c ++index 142a410..6502d94 100644 ++--- a/utils.c +++++ b/utils.c ++@@ -215,7 +215,7 @@ bool uh_path_match(const char *prefix, const char *url) ++ if (strncmp(url, prefix, len) != 0) ++ return false; ++ ++- return url[len] == '/' || url[len] == 0; +++ return url[len] == '/' || url[len] == '?' || url[len] == 0; ++ } ++ ++ char *uh_split_header(char *str) ++ +-- +2.25.1 + diff --git a/patches/base/0025-uhttpd-update-to-latest-HEAD.patch b/patches/base/0025-uhttpd-update-to-latest-HEAD.patch new file mode 100644 index 000000000..30a8f8777 --- /dev/null +++ b/patches/base/0025-uhttpd-update-to-latest-HEAD.patch @@ -0,0 +1,162 @@ +From 3cd6c3dc3cb38799bce6e728d3794d50b829678b Mon Sep 17 00:00:00 2001 +From: John Crispin +Date: Wed, 10 Aug 2022 09:50:13 +0200 +Subject: [PATCH] uhttpd: update to latest HEAD + +Signed-off-by: John Crispin +--- + package/network/services/uhttpd/Makefile | 44 ++++++++++++++----- + .../services/uhttpd/files/uhttpd.config | 8 ++++ + .../network/services/uhttpd/files/uhttpd.init | 15 +++++++ + 3 files changed, 57 insertions(+), 10 deletions(-) + +diff --git a/package/network/services/uhttpd/Makefile b/package/network/services/uhttpd/Makefile +index de666a480d..860b41f1a4 100644 +--- a/package/network/services/uhttpd/Makefile ++++ b/package/network/services/uhttpd/Makefile +@@ -8,19 +8,19 @@ + include $(TOPDIR)/rules.mk + + PKG_NAME:=uhttpd +-PKG_RELEASE:=2 ++PKG_RELEASE:=1 + + PKG_SOURCE_PROTO:=git + PKG_SOURCE_URL=$(PROJECT_GIT)/project/uhttpd.git +-PKG_SOURCE_DATE:=2021-03-21 +-PKG_SOURCE_VERSION:=15346de8d3ba422002496526ee24c62a3601ab8c +-PKG_MIRROR_HASH:=819424d071ed7c8888f9ca66f679907831becc59a67dd4a5ec521d5fba0a3171 ++PKG_SOURCE_DATE:=2022-06-01 ++PKG_SOURCE_VERSION:=d59d732a10a4a2b9f18af6dfc3facf696108f31e ++PKG_MIRROR_HASH:=31caa46ca025a1a7657bd5252d59d4a67d0f1c4b87c15a1bc94663ba3cc899ee + PKG_MAINTAINER:=Felix Fietkau + PKG_LICENSE:=ISC + + PKG_ASLR_PIE_REGULAR:=1 + PKG_BUILD_DEPENDS = ustream-ssl +-PKG_CONFIG_DEPENDS:= CONFIG_uhttpd_lua ++PKG_CONFIG_DEPENDS:= CONFIG_uhttpd_lua CONFIG_uhttpd_ucode + + include $(INCLUDE_DIR)/package.mk + include $(INCLUDE_DIR)/cmake.mk +@@ -49,8 +49,20 @@ define Package/uhttpd/config + depends on PACKAGE_uhttpd-mod-lua + bool "Enable Integrated Lua interpreter" + default y ++ ++ config uhttpd_ucode ++ depends on PACKAGE_uhttpd-mod-ucode ++ bool "Enable Integrated ucode interpreter" ++ default y + endef + ++define Package/uhttpd/conffiles ++/etc/config/uhttpd ++/etc/uhttpd.crt ++/etc/uhttpd.key ++endef ++ ++ + define Package/uhttpd-mod-lua + $(Package/uhttpd/default) + TITLE+= (Lua plugin) +@@ -73,19 +85,25 @@ define Package/uhttpd-mod-ubus/description + session.* namespace and procedures. + endef + +-define Package/uhttpd/conffiles +-/etc/config/uhttpd +-/etc/uhttpd.crt +-/etc/uhttpd.key ++ ++define Package/uhttpd-mod-ucode ++ $(Package/uhttpd/default) ++ TITLE+= (ucode plugin) ++ DEPENDS:=uhttpd +libucode ++endef ++ ++define Package/uhttpd-mod-ucode/description ++ The ucode plugin adds a CGI-like ucode runtime interface to uHTTPd. + endef + ++ + ifneq ($(CONFIG_USE_GLIBC),) + TARGET_CFLAGS += -D_DEFAULT_SOURCE + endif + + TARGET_LDFLAGS += -lcrypt + +-CMAKE_OPTIONS = -DTLS_SUPPORT=on ++CMAKE_OPTIONS += -DTLS_SUPPORT=on + + define Package/uhttpd/install + $(INSTALL_DIR) $(1)/etc/init.d +@@ -108,7 +126,13 @@ define Package/uhttpd-mod-ubus/install + $(INSTALL_DATA) ./files/ubus.default $(1)/etc/uci-defaults/00_uhttpd_ubus + endef + ++define Package/uhttpd-mod-ucode/install ++ $(INSTALL_DIR) $(1)/usr/lib ++ $(INSTALL_BIN) $(PKG_BUILD_DIR)/uhttpd_ucode.so $(1)/usr/lib/ ++endef ++ + + $(eval $(call BuildPackage,uhttpd)) + $(eval $(call BuildPackage,uhttpd-mod-lua)) + $(eval $(call BuildPackage,uhttpd-mod-ubus)) ++$(eval $(call BuildPackage,uhttpd-mod-ucode)) +diff --git a/package/network/services/uhttpd/files/uhttpd.config b/package/network/services/uhttpd/files/uhttpd.config +index 40ce67fd01..a9b8ff3d15 100644 +--- a/package/network/services/uhttpd/files/uhttpd.config ++++ b/package/network/services/uhttpd/files/uhttpd.config +@@ -57,6 +57,14 @@ config uhttpd main + # matches have precedence over the CGI prefix. + list lua_prefix "/cgi-bin/luci=/usr/lib/lua/luci/sgi/uhttpd.lua" + ++ # List of prefix->ucode handler mappings. ++ # Any request to an URL beneath the prefix ++ # will be dispatched to the associated ucode ++ # handler script. Ucode support is disabled when ++ # no handler mappings are specified. Ucode prefix ++ # matches have precedence over the CGI prefix. ++# list ucode_prefix "/ucode/example=/usr/share/example.uc" ++ + # Specify the ubus-rpc prefix and socket path. + # option ubus_prefix /ubus + # option ubus_socket /var/run/ubus/ubus.sock +diff --git a/package/network/services/uhttpd/files/uhttpd.init b/package/network/services/uhttpd/files/uhttpd.init +index 30fd7b4259..8dbc23f59c 100755 +--- a/package/network/services/uhttpd/files/uhttpd.init ++++ b/package/network/services/uhttpd/files/uhttpd.init +@@ -91,6 +91,18 @@ append_lua_prefix() { + fi + } + ++append_ucode_prefix() { ++ local v="$1" ++ local prefix="${v%%=*}" ++ local handler="${v#*=}" ++ ++ if [ "$prefix" != "$handler" ] && [ -n "$prefix" ] && [ -f "$handler" ]; then ++ procd_append_param command -o "$prefix" -O "$handler" ++ else ++ echo "Skipping invalid ucode prefix \"$v\"" >&2 ++ fi ++} ++ + start_instance() + { + UHTTPD_CERT="" +@@ -142,6 +154,9 @@ start_instance() + append_arg "$cfg" ubus_socket "-U" + append_bool "$cfg" ubus_cors "-X" 0 + } ++ [ -f /usr/lib/uhttpd_ucode.so ] && { ++ config_list_foreach "$cfg" ucode_prefix append_ucode_prefix ++ } + append_arg "$cfg" script_timeout "-t" + append_arg "$cfg" network_timeout "-T" + append_arg "$cfg" http_keepalive "-k" +-- +2.25.1 +