forked from openwrt/openwrt
-
Notifications
You must be signed in to change notification settings - Fork 3
/
samba4.patch
264 lines (262 loc) · 6.47 KB
/
samba4.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
diff --git a/net/samba4/Config.in b/net/samba4/Config.in
index 988c05f..d373a2c 100644
--- a/net/samba4/Config.in
+++ b/net/samba4/Config.in
@@ -51,3 +51,10 @@ config SAMBA4_SERVER_AD_DC
HINT: see section (# Using the Domain Controller as a File Server)
NOTE: Extroot is recommend for this setup, as it is not optimized to run completely from RAM/tempfs!
default n
+
+config SAMBA4_SERVER_HOTPLUG
+ bool "enable HOTPLUG support"
+ depends on PACKAGE_samba4-server
+ help
+ Provide hotplug support.
+ default y
diff --git a/net/samba4/Makefile b/net/samba4/Makefile
index f846be3..07f51a3 100644
--- a/net/samba4/Makefile
+++ b/net/samba4/Makefile
@@ -29,6 +29,7 @@ PKG_CONFIG_DEPENDS:= \
CONFIG_SAMBA4_SERVER_VFS \
CONFIG_SAMBA4_SERVER_VFSX \
CONFIG_SAMBA4_SERVER_AD_DC \
+ CONFIG_SAMBA4_SERVER_HOTPLUG \
CONFIG_PACKAGE_kmod-fs-btrfs \
CONFIG_PACKAGE_kmod-fs-xfs
@@ -410,6 +410,12 @@ endif
$(INSTALL_CONF) ./files/samba.config $(1)/etc/config/samba4
$(INSTALL_DATA) ./files/smb.conf.template $(1)/etc/samba
$(INSTALL_BIN) ./files/samba.init $(1)/etc/init.d/samba4
+ifeq ($(CONFIG_SAMBA4_SERVER_HOTPLUG),y)
+ $(INSTALL_DIR) $(1)/lib/samba
+ $(INSTALL_DATA) ./files/samba.sh $(1)/lib/samba/samba.sh
+ $(INSTALL_DIR) $(1)/etc/hotplug.d/block
+ $(INSTALL_DATA) ./files/samba.hotplug $(1)/etc/hotplug.d/block/60-samba
+endif
endef
define Package/samba4-server/conffiles
diff --git a/net/samba4/files/samba.hotplug b/net/samba4/files/samba.hotplug
new file mode 100644
index 0000000..111f0cd
--- /dev/null
+++ b/net/samba4/files/samba.hotplug
@@ -0,0 +1,11 @@
+. /lib/samba/samba.sh
+
+samba_dev_filter $DEVNAME
+[ "$FLAG_DEV_TYPE" = "not-mtd" ] || exit
+
+config_load samba4
+case $ACTION in
+ add) samba_add_section $DEVNAME;;
+ remove) samba_delete_section $DEVNAME;;
+esac
+uci commit samba4
diff --git a/net/samba4/files/samba.sh b/net/samba4/files/samba.sh
new file mode 100644
index 0000000..5416cbc
--- /dev/null
+++ b/net/samba4/files/samba.sh
@@ -0,0 +1,89 @@
+#!/bin/sh
+#
+# Copyright (C) 2018 OpenWrt.org
+# Copyright (C) 2018 [email protected]
+#
+
+. /lib/functions.sh
+
+FLAG_DEV_TYPE=
+FLAG_DEV_MOPT=
+FLAG_HAS_SECT=
+
+samba_dev_filter() { # <devname> <[path,/dev/]>
+ case $1 in
+ ${2}mtdblock*|\
+ ${2}ubi*)
+ FLAG_DEV_TYPE="mtd"
+ ;;
+ ${2}loop*|\
+ ${2}mmcblk*|\
+ ${2}sd*|\
+ ${2}hd*|\
+ ${2}md*|\
+ ${2}nvme*|\
+ ${2}vd*|\
+ ${2}xvd*)
+ FLAG_DEV_TYPE="not-mtd"
+ ;;
+ *)
+ [ -b ${2}${1} ] && FLAG_DEV_TYPE="not-mtd"
+ [ -b /dev/mapper/$1 ] && FLAG_DEV_TYPE="not-mtd"
+ ;;
+ esac
+}
+
+samba_cfg_lookup() { # <section> <name>
+ config_get name $1 name
+ [ "$name" = "$2" ] || return
+ FLAG_HAS_SECT=y
+}
+
+samba_cfg_delete() { # <section> <name>
+ config_get name $1 name
+ [ "$name" = "$2" ] || return
+ uci -q delete samba4.$1
+}
+
+samba_find_mount_point() { # <devname>
+ # search mount point in /proc/mounts
+ while read l; do
+ local d=$(echo $l | awk '/^\/dev/ {print $1}')
+ [ "$d" = "/dev/$1" ] || continue
+
+ FLAG_DEV_MOPT=$(echo $l | awk '/^\/dev/ {print $2}')
+ break
+ done < /proc/mounts
+}
+
+_samba_add_section() { # <devname> <mount point>
+ uci -q batch <<-EOF
+ add samba4 sambashare
+ set samba4.@sambashare[-1].browseable='yes'
+ set samba4.@sambashare[-1].name='$1'
+ set samba4.@sambashare[-1].path='$2'
+ set samba4.@sambashare[-1].users='root'
+ set samba4.@sambashare[-1].read_only='no'
+ set samba4.@sambashare[-1].guest_ok='yes'
+ set samba4.@sambashare[-1].create_mask='0755'
+ set samba4.@sambashare[-1].dir_mask='0755'
+ EOF
+}
+
+samba_add_section() { # <devname> [<mount point>]
+ FLAG_HAS_SECT=
+ FLAG_DEV_MOPT=
+
+ config_foreach samba_cfg_lookup sambashare $1
+ [ -z "$FLAG_HAS_SECT" ] || return
+
+ samba_find_mount_point $1
+ [ -n "$FLAG_DEV_MOPT" ] || return
+
+ [ -n "$2" -a "$2" = "$FLAG_DEV_MOPT" ] || \
+ _samba_add_section $1 $FLAG_DEV_MOPT
+}
+
+samba_delete_section() { # <devname>
+ config_foreach samba_cfg_delete sambashare $1
+}
diff --git a/net/samba4/samba4-libs/etc/hotplug.d/block/60-samba b/net/samba4/samba4-libs/etc/hotplug.d/block/60-samba
new file mode 100644
index 0000000..111f0cd
--- /dev/null
+++ b/net/samba4/samba4-libs/etc/hotplug.d/block/60-samba
@@ -0,0 +1,11 @@
+. /lib/samba/samba.sh
+
+samba_dev_filter $DEVNAME
+[ "$FLAG_DEV_TYPE" = "not-mtd" ] || exit
+
+config_load samba4
+case $ACTION in
+ add) samba_add_section $DEVNAME;;
+ remove) samba_delete_section $DEVNAME;;
+esac
+uci commit samba4
diff --git a/net/samba4/samba4-libs/lib/samba/samba.sh b/net/samba4/samba4-libs/lib/samba/samba.sh
new file mode 100644
index 0000000..5416cbc
--- /dev/null
+++ b/net/samba4/samba4-libs/lib/samba/samba.sh
@@ -0,0 +1,89 @@
+#!/bin/sh
+#
+# Copyright (C) 2018 OpenWrt.org
+# Copyright (C) 2018 [email protected]
+#
+
+. /lib/functions.sh
+
+FLAG_DEV_TYPE=
+FLAG_DEV_MOPT=
+FLAG_HAS_SECT=
+
+samba_dev_filter() { # <devname> <[path,/dev/]>
+ case $1 in
+ ${2}mtdblock*|\
+ ${2}ubi*)
+ FLAG_DEV_TYPE="mtd"
+ ;;
+ ${2}loop*|\
+ ${2}mmcblk*|\
+ ${2}sd*|\
+ ${2}hd*|\
+ ${2}md*|\
+ ${2}nvme*|\
+ ${2}vd*|\
+ ${2}xvd*)
+ FLAG_DEV_TYPE="not-mtd"
+ ;;
+ *)
+ [ -b ${2}${1} ] && FLAG_DEV_TYPE="not-mtd"
+ [ -b /dev/mapper/$1 ] && FLAG_DEV_TYPE="not-mtd"
+ ;;
+ esac
+}
+
+samba_cfg_lookup() { # <section> <name>
+ config_get name $1 name
+ [ "$name" = "$2" ] || return
+ FLAG_HAS_SECT=y
+}
+
+samba_cfg_delete() { # <section> <name>
+ config_get name $1 name
+ [ "$name" = "$2" ] || return
+ uci -q delete samba4.$1
+}
+
+samba_find_mount_point() { # <devname>
+ # search mount point in /proc/mounts
+ while read l; do
+ local d=$(echo $l | awk '/^\/dev/ {print $1}')
+ [ "$d" = "/dev/$1" ] || continue
+
+ FLAG_DEV_MOPT=$(echo $l | awk '/^\/dev/ {print $2}')
+ break
+ done < /proc/mounts
+}
+
+_samba_add_section() { # <devname> <mount point>
+ uci -q batch <<-EOF
+ add samba4 sambashare
+ set samba4.@sambashare[-1].browseable='yes'
+ set samba4.@sambashare[-1].name='$1'
+ set samba4.@sambashare[-1].path='$2'
+ set samba4.@sambashare[-1].users='root'
+ set samba4.@sambashare[-1].read_only='no'
+ set samba4.@sambashare[-1].guest_ok='yes'
+ set samba4.@sambashare[-1].create_mask='0755'
+ set samba4.@sambashare[-1].dir_mask='0755'
+ EOF
+}
+
+samba_add_section() { # <devname> [<mount point>]
+ FLAG_HAS_SECT=
+ FLAG_DEV_MOPT=
+
+ config_foreach samba_cfg_lookup sambashare $1
+ [ -z "$FLAG_HAS_SECT" ] || return
+
+ samba_find_mount_point $1
+ [ -n "$FLAG_DEV_MOPT" ] || return
+
+ [ -n "$2" -a "$2" = "$FLAG_DEV_MOPT" ] || \
+ _samba_add_section $1 $FLAG_DEV_MOPT
+}
+
+samba_delete_section() { # <devname>
+ config_foreach samba_cfg_delete sambashare $1
+}