From 840bb5f90df3995ed4e12e3e37a680a8db9464c3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= <jws@sysret.de>
Date: Thu, 30 Nov 2023 21:25:54 +0000
Subject: [PATCH] lighttpd: enable mod_webdav module

genodelabs/genode#5093
---
 repos/ports/ports/lighttpd.hash               |  2 +-
 repos/ports/ports/lighttpd.port               |  2 +-
 repos/ports/src/app/lighttpd/mod_webdav.patch | 16 ++++++++++++++++
 repos/ports/src/app/lighttpd/plugin-static.h  |  1 +
 repos/ports/src/app/lighttpd/target.inc       |  2 +-
 5 files changed, 20 insertions(+), 3 deletions(-)
 create mode 100644 repos/ports/src/app/lighttpd/mod_webdav.patch

diff --git a/repos/ports/ports/lighttpd.hash b/repos/ports/ports/lighttpd.hash
index 67fbf00b0e..a1d1f50631 100644
--- a/repos/ports/ports/lighttpd.hash
+++ b/repos/ports/ports/lighttpd.hash
@@ -1 +1 @@
-38aa0f93ad7cf9e5c35da09ff2a7f3adbd6e7b5f
+6a9326a07968a5e7f637ec0720e7b4616e66149e
diff --git a/repos/ports/ports/lighttpd.port b/repos/ports/ports/lighttpd.port
index aea942e0ad..ac4749ad2c 100644
--- a/repos/ports/ports/lighttpd.port
+++ b/repos/ports/ports/lighttpd.port
@@ -6,4 +6,4 @@ URL(lighttpd) := http://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-$
 SHA(lighttpd) := 816cbec71e8d02d874f1d5c798d76d091a76d5acbeb6e017ba76aeb4263d6995
 DIR(lighttpd) := src/app/lighttpd
 
-PATCHES := $(addprefix src/app/lighttpd/,fd_cloexec.patch)
+PATCHES := $(addprefix src/app/lighttpd/,fd_cloexec.patch mod_webdav.patch)
diff --git a/repos/ports/src/app/lighttpd/mod_webdav.patch b/repos/ports/src/app/lighttpd/mod_webdav.patch
new file mode 100644
index 0000000000..e63a1db0a9
--- /dev/null
+++ b/repos/ports/src/app/lighttpd/mod_webdav.patch
@@ -0,0 +1,16 @@
+Disable usage of linkat and unlinkat which is not (yet) support
+in our libc.
+
+--- src/app/lighttpd/src/mod_webdav.c
++++ src/app/lighttpd/src/mod_webdav.c
+@@ -224,6 +224,10 @@
+ #endif
+ #endif
+ 
++#undef AT_FDCWD
++#undef _ATFILE_SOURCE
++
++
+ #ifndef AT_SYMLINK_NOFOLLOW
+ #define AT_SYMLINK_NOFOLLOW 0
+ #endif
diff --git a/repos/ports/src/app/lighttpd/plugin-static.h b/repos/ports/src/app/lighttpd/plugin-static.h
index 19849420da..368f0c158c 100644
--- a/repos/ports/src/app/lighttpd/plugin-static.h
+++ b/repos/ports/src/app/lighttpd/plugin-static.h
@@ -3,3 +3,4 @@ PLUGIN_INIT(mod_dirlisting)
 PLUGIN_INIT(mod_staticfile)
 PLUGIN_INIT(mod_access)
 PLUGIN_INIT(mod_openssl)
+PLUGIN_INIT(mod_webdav)
diff --git a/repos/ports/src/app/lighttpd/target.inc b/repos/ports/src/app/lighttpd/target.inc
index 78dd47aed3..5e16a6ab29 100644
--- a/repos/ports/src/app/lighttpd/target.inc
+++ b/repos/ports/src/app/lighttpd/target.inc
@@ -53,7 +53,6 @@ FILTER_OUT := lempar.c lighttpd-angel.c lemon.c \
               mod_vhostdb_ldap.c \
               mod_vhostdb_mysql.c \
               mod_vhostdb_pgsql.c \
-              mod_webdav.c \
               mod_wolfssl.c \
               mod_wstunnel.c
 SRC_C = $(filter-out $(FILTER_OUT),$(notdir $(wildcard $(LIGHTTPD_DIR)/src/*.c)))
@@ -81,6 +80,7 @@ CC_OPT += -DLIBRARY_DIR="\"/lib\""
 CC_OPT += -DLIGHTTPD_STATIC
 CC_OPT += -DHAVE_LIBSSL -DUSE_OPENSSL -DUSE_OPENSSL_CRYPTO
 
+CC_OPT += -DMOD_WEBDAV_BUILD_MINIMAL
 
 CC_WARN = -Wall -Wno-unused-variable -Wno-unused-function