🎨 Sync 2026-10-12 21:43:19

This commit is contained in:
github-actions[bot] committed 2026-10-12 21:43:19 +08:00
1 parent 3a82c347ab
commit bfe30ffbef
51 files changed
+8523 -149

No files matched your search

+119
View File
@@ -0,0 +1,119 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=ksmbd-tools
PKG_VERSION:=3.5.7
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://github.com/cifsd-team/ksmbd-tools/releases/download/$(PKG_VERSION)
PKG_HASH:=skip
PKG_LICENSE:=GPL-2.0-or-later
PKG_LICENSE_FILES:=COPYING
PKG_BUILD_DEPENDS:=glib2
PKG_BUILD_FLAGS:=gc-sections
include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/nls.mk
include $(INCLUDE_DIR)/meson.mk
define Package/ksmbd-tools/Default
SECTION:=net
CATEGORY:=Network
SUBMENU:=Filesystem
TITLE:=Kernel SMB
URL:=https://github.com/cifsd-team/ksmbd-tools
DEPENDS:= $(ICONV_DEPENDS) $(INTL_DEPENDS)
endef
define Package/ksmbd-tools/Default/description
Userspace tools to manage the SMB kernel fileserver (ksmbd.ko).
The config file location is /etc/ksmbd/ksmbd.conf
endef
define Package/ksmbd-server
$(call Package/ksmbd-tools/Default)
TITLE+= server
DEPENDS+= +(LINUX_5_4||LINUX_5_10||LINUX_6_6):kmod-fs-cifsd +!(LINUX_5_4||LINUX_5_10||LINUX_6_6):kmod-fs-ksmbd +libnl-core +libnl-genl +umdns +flock
endef
define Package/ksmbd-server/description
installs: ksmbd.mountd
This provides the basic fileserver service and is the minimum needed to serve 'guest only' file shares or use a existing user database file ksmbdpwd.db.
endef
define Package/ksmbd-server/config
select PACKAGE_wsdd2
endef
define Package/ksmbd-avahi-service
$(call Package/ksmbd-tools/Default)
TITLE+= (Avahi service)
DEPENDS:= +avahi-daemon
endef
define Package/ksmbd-avahi-service/description
installs: smb.service
This package contains the service definition for announcing the
Ksmbd (smb/445) Daemon service via mDNS/DNS-SD.
endef
define Package/ksmbd-hotplug
$(call Package/ksmbd-tools/Default)
TITLE+= hotplug script for auto sharing
DEPENDS:=+blockd
endef
MESON_ARGS += \
-Db_lto=true \
-Dkrb5=disabled
TARGET_LDFLAGS += -Wl,--as-needed
define Package/ksmbd-server/install
$(INSTALL_DIR) $(1)/usr/libexec
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/libexec/ksmbd.tools $(1)/usr/libexec/
$(INSTALL_DIR) $(1)/usr/sbin
$(CP) $(PKG_INSTALL_DIR)/usr/sbin/ksmbd.addshare $(1)/usr/sbin/
$(CP) $(PKG_INSTALL_DIR)/usr/sbin/ksmbd.adduser $(1)/usr/sbin/
$(CP) $(PKG_INSTALL_DIR)/usr/sbin/ksmbd.control $(1)/usr/sbin/
$(CP) $(PKG_INSTALL_DIR)/usr/sbin/ksmbd.mountd $(1)/usr/sbin/
$(INSTALL_DIR) $(1)/etc/config $(1)/etc/ksmbd $(1)/etc/init.d
$(INSTALL_CONF) ./files/ksmbd.config $(1)/etc/config/ksmbd
$(INSTALL_DATA) ./files/ksmbd.conf.template $(1)/etc/ksmbd/
$(INSTALL_BIN) ./files/ksmbd.init $(1)/etc/init.d/ksmbd
$(INSTALL_DIR) $(1)/etc/sysctl.d
$(INSTALL_CONF) ./files/ksmbd.sysctl $(1)/etc/sysctl.d/90-ksmbd.conf
$(INSTALL_DATA) ./files/shares.sh $(1)/etc/ksmbd/
# copy examples until we have a wiki page
$(INSTALL_DATA) ./files/ksmbd.config.example $(1)/etc/ksmbd/
endef
define Package/ksmbd-avahi-service/install
$(INSTALL_DIR) $(1)/etc/avahi/services
$(INSTALL_DATA) ./files/smb.service $(1)/etc/avahi/services/
endef
define Package/ksmbd-hotplug/install
$(INSTALL_DIR) $(1)/etc/hotplug.d/mount
$(INSTALL_CONF) ./files/ksmbd.hotplug $(1)/etc/hotplug.d/mount/60-ksmbd
endef
define Package/ksmbd-server/conffiles
/etc/config/ksmbd
/etc/ksmbd/ksmbd.conf.template
/etc/ksmbd/ksmbd.conf
/etc/ksmbd/ksmbdpwd.db
/etc/sysctl.d/90-ksmbd.conf
endef
define Package/ksmbd-avahi-service/conffiles
/etc/avahi/services/smb.service
endef
$(eval $(call BuildPackage,ksmbd-server))
$(eval $(call BuildPackage,ksmbd-avahi-service))
$(eval $(call BuildPackage,ksmbd-hotplug))
+15
View File
@@ -0,0 +1,15 @@
[global]
netbios name = |NAME|
server string = |DESCRIPTION|
workgroup = |WORKGROUP|
interfaces = |INTERFACES|
bind interfaces only = yes
ipc timeout = 20
deadtime = 15
map to guest = Bad User
server max protocol = SMB3_11
smb2 max read = 1MB
smb2 max write = 1MB
smb2 max trans = 1MB
cache read buffers = no
cache trans buffers = no
+9
View File
@@ -0,0 +1,9 @@
config globals
option enabled '0'
option 'workgroup' 'WORKGROUP'
option 'description' 'Ksmbd on OpenWrt'
option interface 'lan'
option allow_legacy_protocols '1'
option allow_guest_ipc '1'
option homes '0'
option autoshare '1'
+11
View File
@@ -0,0 +1,11 @@
config globals
option 'description' 'Ksmbd on OpenWrt'
config share
option name 'testshare'
option path '/tmp'
option read_only 'no'
option guest_ok 'yes'
option create_mask '0666'
option dir_mask '0777'
option force_root '1'
+18
View File
@@ -0,0 +1,18 @@
#!/bin/sh
. /lib/functions.sh
case "$ACTION" in add|remove) ;; *) exit 0;; esac
/etc/init.d/ksmbd enabled || exit 0
enabled=0
autoshare=1
ksmbd_settings() {
config_get_bool enabled "$1" enabled 0
config_get_bool autoshare "$1" autoshare 1
}
config_load ksmbd
config_foreach ksmbd_settings globals
[ "$enabled" -eq 1 ] && [ "$autoshare" -eq 1 ] || exit 0
# Synchronize automatic UCI shares and rebuild from current mounts.
/etc/init.d/ksmbd reload
+211
View File
@@ -0,0 +1,211 @@
#!/bin/sh /etc/rc.common
START=98
STOP=05
USE_PROCD=1
SMBD_IFACE=""
KSMBD_ENABLED=0
KSMBD_HOMES=0
KSMBD_AUTOSHARE=1
config_get_sane()
{
config_get "$@"
set -- "$(echo "$1" | tr -d '<>[]{};%?=#\n')"
}
smb_header()
{
config_get_bool KSMBD_ENABLED "$1" enabled 0
config_get_bool KSMBD_HOMES "$1" homes 0
config_get_bool KSMBD_AUTOSHARE "$1" autoshare 1
config_get_sane SMBD_IFACE "$1" interface "lan"
# resolve interfaces
interfaces=$(
. /lib/functions/network.sh
for net in $SMBD_IFACE; do
network_is_up "$net" || continue
network_get_device device "$net"
printf "%s " "${device:-$net}"
done
)
config_get hostname "$1" name
case "$hostname" in
''|*[!a-zA-Z0-9_.-]*)
hostname="$(sed 's/\..*//' /proc/sys/kernel/hostname | tr -cd 'a-zA-Z0-9_-')"
;;
esac
config_get_sane workgroup "$1" workgroup "WORKGROUP"
config_get_sane description "$1" description "Ksmbd on OpenWrt"
config_get_bool ALLOW_LEGACY_PROTOCOLS "$1" allow_legacy_protocols 1
config_get_bool ALLOW_GUEST_IPC "$1" allow_guest_ipc 1
sed -e "s#|NAME|#$hostname#g" \
-e "s#|WORKGROUP|#$workgroup#g" \
-e "s#|DESCRIPTION|#$description#g" \
-e "s#|INTERFACES|#$interfaces#g" \
/etc/ksmbd/ksmbd.conf.template > /var/etc/ksmbd/ksmbd.conf
{
printf "\n######### Dynamic written config options #########\n"
if [ "$ALLOW_LEGACY_PROTOCOLS" -eq 1 ]; then
logger -p daemon.info -t 'ksmbd' "Legacy Protocols allowed, don't use this option for secure environments!"
printf "\tserver min protocol = NT1\n"
printf "\tserver signing = disabled\n"
fi
printf "\n[IPC$]\n\tguest ok = %s\n" "$( [ "$ALLOW_GUEST_IPC" -eq 1 ] && echo yes || echo no )"
} >> /var/etc/ksmbd/ksmbd.conf
[ -e /etc/ksmbd/ksmbd.conf ] || ln -nsf /var/etc/ksmbd/ksmbd.conf /etc/ksmbd/ksmbd.conf
if [ ! -L /etc/ksmbd/ksmbd.conf ]; then
logger -p daemon.warn -t 'ksmbd' "Local custom /etc/ksmbd/ksmbd.conf file detected, all UCI/Luci config settings are ignored!"
fi
}
smb_add_share()
{
config_get_sane name "$1" name
config_get_sane path "$1" path
config_get_sane comment "$1" comment
config_get_sane users "$1" users
config_get_sane create_mask "$1" create_mask 0666
config_get_sane dir_mask "$1" dir_mask 0777
config_get_sane browseable "$1" browseable yes
config_get_sane read_only "$1" read_only no
config_get_sane writeable "$1" writeable
config_get_sane guest_ok "$1" guest_ok yes
config_get_bool force_root "$1" force_root 1
config_get_sane write_list "$1" write_list
config_get_sane read_list "$1" read_list
config_get_sane hide_dot_files "$1" hide_dot_files yes
config_get_sane veto_files "$1" veto_files
config_get_sane inherit_owner "$1" inherit_owner
config_get_sane force_create_mode "$1" force_create_mode
config_get_sane force_directory_mode "$1" force_directory_mode
[ -z "$name" ] || [ -z "$path" ] && return
{
printf "\n[%s]\n\tpath = %s\n" "$name" "$path"
[ -n "$comment" ] && printf "\tcomment = %s\n" "$comment"
if [ "$force_root" -eq 1 ]; then
printf "\tforce user = %s\n" "root"
printf "\tforce group = %s\n" "root"
fi
[ -n "$users" ] && printf "\tvalid users = %s\n" "$users"
[ -n "$create_mask" ] && printf "\tcreate mask = %s\n" "$create_mask"
[ -n "$dir_mask" ] && printf "\tdirectory mask = %s\n" "$dir_mask"
[ -n "$force_create_mode" ] && printf "\tforce create mode = %s\n" "$force_create_mode"
[ -n "$force_directory_mode" ] && printf "\tforce directory mode = %s\n" "$force_directory_mode"
[ -n "$browseable" ] && printf "\tbrowseable = %s\n" "$browseable"
[ -n "$read_only" ] && printf "\tread only = %s\n" "$read_only"
[ -n "$writeable" ] && printf "\twriteable = %s\n" "$writeable"
[ -n "$guest_ok" ] && printf "\tguest ok = %s\n" "$guest_ok"
[ -n "$inherit_owner" ] && printf "\tinherit owner = %s\n" "$inherit_owner"
[ -n "$write_list" ] && printf "\twrite list = %s\n" "$write_list"
[ -n "$read_list" ] && printf "\tread list = %s\n" "$read_list"
[ -n "$hide_dot_files" ] && printf "\thide dot files = %s\n" "$hide_dot_files"
[ -n "$veto_files" ] && printf "\tveto files = %s\n" "$veto_files"
} >> /var/etc/ksmbd/ksmbd.conf
}
init_config()
{
flock -x 9 || return 1
mkdir -p /var/etc/ksmbd
config_load ksmbd
config_foreach smb_header globals
. /etc/ksmbd/shares.sh
ksmbd_sync_mounts || return 1
config_load ksmbd
config_foreach smb_add_share share
[ "$KSMBD_HOMES" -eq 1 ] && ksmbd_add_homes
return 0
} 9>/var/lock/ksmbd-config.lock
service_triggers()
{
# PROCD_RELOAD_DELAY=1000
procd_add_reload_trigger "dhcp" "system" "ksmbd"
for i in $SMBD_IFACE; do
procd_add_reload_interface_trigger "$i"
done
}
kill_server()
{
if [ -e /sys/module/ksmbd ]; then
if [ -e /sys/class/ksmbd-control/kill_server ]; then
logger -p daemon.info -t 'ksmbd' "triggering kill_server"
echo hard > /sys/class/ksmbd-control/kill_server
fi
fi
}
start_service()
{
init_config || return 1
if [ "$KSMBD_ENABLED" -ne 1 ]; then
stop_service
return 0
fi
if [ ! -e /etc/ksmbd/ksmbd.conf ]; then
logger -p daemon.error -t 'ksmbd' "missing config /etc/ksmbd/ksmbd.conf!"
exit 1
fi
# NOTE: We don't do a soft-reload via signal, since [global] ksmbd.conf setting changes will be ignored, so always reset hard.
[ -e /sys/module/ksmbd ] && stop_service
[ ! -e /sys/module/ksmbd ] && modprobe ksmbd 2> /dev/null
if [ ! -e /sys/module/ksmbd ]; then
logger -p daemon.error -t 'ksmbd' "modprobe of ksmbd module failed, can\'t start ksmbd!"
exit 1
fi
logger -p daemon.notice -t 'ksmbd' "Starting Ksmbd userspace service."
procd_open_instance
procd_add_mdns "smb" "tcp" "445" "daemon=ksmbd"
procd_set_param command /usr/sbin/ksmbd.mountd --n
procd_set_param file /etc/ksmbd/ksmbd.conf
procd_set_param limits nofile=16384
procd_close_instance
}
stop_service()
{
logger -p daemon.notice -t 'ksmbd' "Stopping Ksmbd userspace service."
killall ksmbd.mountd > /dev/null 2>&1
[ -e /sys/module/ksmbd ] && rmmod ksmbd > /dev/null 2>&1
# kill server if we cant rmmod
[ -e /sys/module/ksmbd ] && kill_server
# next try
[ -e /sys/module/ksmbd ] && rmmod ksmbd > /dev/null 2>&1
if [ -e /sys/module/ksmbd ]; then
logger -p daemon.error -t 'ksmbd' "module still loaded after kill_server?"
fi
[ -f /tmp/ksmbd.lock ] && rm /tmp/ksmbd.lock
}
# reload_service() {
# restart "$@"
# }
+5
View File
@@ -0,0 +1,5 @@
# Bound buffered-write backlog to smooth sustained uploads on flash storage.
# These VM limits apply system-wide, including writers other than ksmbd.
# /etc/sysctl.conf is loaded afterwards and can override these values.
vm.dirty_background_bytes=4194304
vm.dirty_bytes=16777216
+127
View File
@@ -0,0 +1,127 @@
#!/bin/sh
# Home shares remain private runtime entries; mount shares are stored in UCI.
ksmbd_share_exists()
{
KSMBD_SHARE_NAME="$1" KSMBD_SHARE_PATH="$2" awk '
/^\[/ { name = substr($0, 2, length($0)-2); if (tolower(name) == tolower(ENVIRON["KSMBD_SHARE_NAME"])) found=1 }
/^[ \t]*path[ \t]*=/ { path=$0; sub(/^[ \t]*path[ \t]*=[ \t]*/, "", path); if (path == ENVIRON["KSMBD_SHARE_PATH"]) found=1 }
END { exit !found }' /var/etc/ksmbd/ksmbd.conf
}
ksmbd_add_homes()
{
local user password uid gid gecos home shell
[ -r /etc/ksmbd/ksmbdpwd.db ] || return 0
while IFS=: read -r user password uid gid gecos home shell; do
case "$user" in ''|*[!a-zA-Z0-9_.-]*) continue;; esac
case "$home" in /|/var|/tmp|/dev|/proc|/sys|'') continue;; /*) ;; *) continue;; esac
[ -d "$home" ] || continue
# Private homes are only generated for registered SMB users.
awk -F: -v user="$user" '$1 == user { found=1 } END { exit !found }' /etc/ksmbd/ksmbdpwd.db || continue
ksmbd_share_exists "$user" "$home" && continue
{
printf '\n[%s]\n\tpath = %s\n' "$user" "$home"
printf '\tcomment = Home Directories\n\tvalid users = %s\n' "$user"
printf '\tbrowseable = no\n\tguest ok = no\n\tread only = no\n'
printf '\tcreate mask = 0750\n\tdirectory mask = 0750\n'
} >> /var/etc/ksmbd/ksmbd.conf
done < /etc/passwd
}
# Use a private delta directory so commits do not include pending LuCI edits.
ksmbd_mount_uci()
{
uci ${UCI_CONFIG_DIR:+-c "$UCI_CONFIG_DIR"} -t "$ksmbd_delta" -q "$@"
}
ksmbd_prune_mount()
{
local section="$1" path auto_path fingerprint
config_get path "$section" path
config_get auto_path "$section" auto_path
[ -n "$auto_path" ] || return 0
if [ "$path" != "$auto_path" ]; then
# Editing the path converts an automatic share into a manual share.
ksmbd_mount_uci delete "ksmbd.$section.auto_path"
elif [ "$KSMBD_AUTOSHARE" -ne 1 ] || ! grep -Fxq "$path" "$ksmbd_mounts"; then
ksmbd_mount_uci delete "ksmbd.$section"
else
# Only remove identical generated entries; differing permissions are
# intentional configuration and must not be silently discarded.
fingerprint="$(ksmbd_mount_uci show "ksmbd.$section" |
sed '1d; s/^ksmbd\.[^.]*\.//' | LC_ALL=C sort | md5sum | cut -d ' ' -f 1)"
if grep -Fxq "$fingerprint" "$ksmbd_delta/seen"; then
ksmbd_mount_uci delete "ksmbd.$section"
else
printf '%s\n' "$fingerprint" >> "$ksmbd_delta/seen"
fi
fi
return 0
}
ksmbd_find_mount()
{
local section="$1" share_name share_path
config_get share_name "$section" name
config_get share_path "$section" path
if [ "$share_path" = "$target" ] ||
[ "$(printf '%s' "$share_name" | tr 'A-Z' 'a-z')" = "$(printf '%s' "$name" | tr 'A-Z' 'a-z')" ]; then
ksmbd_found=1
fi
}
ksmbd_scan_mounts()
{
local device target fstype options rest name
while read -r device target fstype options rest; do
case "$device" in /dev/sd*|/dev/hd*|/dev/mmcblk*|/dev/nvme*|/dev/md*) ;; *) continue;; esac
# Firmware images and other read-only mounts are not automatic shares.
case "$fstype" in squashfs|erofs|cramfs|romfs|iso9660) continue;; esac
case ",$options," in *,ro,*) continue;; esac
target="$(printf '%b' "$target")"
case "$target" in /|/rom|/overlay|/boot|/boot/*|/tmp|/tmp/*|/dev|/dev/*|/proc|/proc/*|/sys|/sys/*) continue;; esac
case "$target" in *'
'*|*' '*) continue;; esac
[ -d "$target" ] || continue
name="${target##*/}"
case "$name" in ''|*'['*|*']'*|*';'*|*'%'*) name="${device##*/}";; esac
printf '%s\t%s\tno\n' "$target" "$name"
done < /proc/mounts
}
ksmbd_sync_mounts()
(
local ksmbd_delta ksmbd_mounts target name readonly section ksmbd_found
flock -x 8 || return 1
# The caller's snapshot can predate another hotplug worker's commit.
config_load ksmbd
ksmbd_delta="$(mktemp -d /tmp/ksmbd-uci.XXXXXX)" || return 1
trap 'rm -rf "$ksmbd_delta"' EXIT
: > "$ksmbd_delta/seen"
ksmbd_mounts="$ksmbd_delta/paths"
ksmbd_scan_mounts > "$ksmbd_delta/mounts"
cut -f1 "$ksmbd_delta/mounts" > "$ksmbd_mounts"
config_foreach ksmbd_prune_mount share
if [ -n "$(ksmbd_mount_uci changes ksmbd)" ]; then
ksmbd_mount_uci commit ksmbd || return 1
fi
[ "$KSMBD_AUTOSHARE" -eq 1 ] || return 0
config_load ksmbd
while IFS="$(printf '\t')" read -r target name readonly; do
ksmbd_found=0
config_foreach ksmbd_find_mount share
[ "$ksmbd_found" -eq 0 ] || continue
section="$(ksmbd_mount_uci add ksmbd share)" || return 1
ksmbd_mount_uci set "ksmbd.$section.name=$name"
ksmbd_mount_uci set "ksmbd.$section.path=$target"
ksmbd_mount_uci set "ksmbd.$section.auto_path=$target"
ksmbd_mount_uci set "ksmbd.$section.browseable=yes"
ksmbd_mount_uci set "ksmbd.$section.guest_ok=yes"
ksmbd_mount_uci set "ksmbd.$section.read_only=$readonly"
ksmbd_mount_uci set "ksmbd.$section.force_root=1"
ksmbd_mount_uci set "ksmbd.$section.create_mask=0666"
ksmbd_mount_uci set "ksmbd.$section.dir_mask=0777"
ksmbd_mount_uci commit ksmbd || return 1
config_load ksmbd
done < "$ksmbd_delta/mounts"
) 8>/var/lock/ksmbd-autoshare.lock
+9
View File
@@ -0,0 +1,9 @@
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">%h</name>
<service>
<type>_smb._tcp</type>
<port>445</port>
</service>
</service-group>
+14
View File
@@ -0,0 +1,14 @@
Subject: [PATCH] Link glib statically for OpenWrt
Signed-off-by: coolsnowwolf <coolsnowwolf@gmail.com>
--- a/meson.build
+++ b/meson.build
@@ -21,6 +21,7 @@
glib_dep = dependency(
'glib-2.0',
version: '>= 2.58',
+ static: true,
)
libnl_dep = dependency(
'libnl-genl-3.0',