1 #!/bin/sh /etc/rc.common
9 config_get SAMBA_IFACE
$1 interface
"lan"
14 .
/lib
/functions
/network.sh
17 for net
in $SAMBA_IFACE; do
19 network_is_up
$net ||
continue
20 network_get_device device
"$net"
21 printf "%s " "${device:-$net}"
25 local workgroup description charset
26 # we dont use netbios anymore as default and wsd/avahi is dns based
28 hostname
="$(cat /proc/sys/kernel/hostname)"
30 config_get workgroup
$1 workgroup
"WORKGROUP"
31 config_get description
$1 description
"Samba on OpenWrt"
32 config_get charset
$1 charset
"UTF-8"
34 config_get_bool MACOS
$1 macos
0
35 config_get_bool DISABLE_NETBIOS
$1 disable_netbios
0
36 config_get_bool DISABLE_AD_DC
$1 disable_ad_dc
0
37 config_get_bool DISABLE_WINBIND
$1 disable_winbind
0
38 config_get_bool DISABLE_ASYNC_IO
$1 disable_async_io
0
39 config_get_bool ALLOW_LEGACY_PROTOCOLS
$1 allow_legacy_protocols
0
42 sed -e "s#|NAME|#$hostname#g" \
43 -e "s#|WORKGROUP|#$workgroup#g" \
44 -e "s#|DESCRIPTION|#$description#g" \
45 -e "s#|INTERFACES|#$interfaces#g" \
46 -e "s#|CHARSET|#$charset#g" \
47 /etc
/samba
/smb.conf.template
> /var
/etc
/smb.conf
50 printf "\n######### Dynamic written config options #########\n"
51 if [ "$DISABLE_NETBIOS" -eq 1 ] ||
[ ! -x /usr
/sbin
/nmbd
]; then
52 printf "\tdisable netbios = yes\n"
53 # note: samba opens port 139 even if netbios is disabled via option above, so adjust listening ports
54 printf "\tsmb ports = 445\n"
57 if [ "$DISABLE_ASYNC_IO" -eq 1 ]; then
58 printf "\taio read size = 0\n"
59 printf "\taio write size = 0\n"
60 # sendfile bug: https://bugzilla.samba.org/show_bug.cgi?id=14095
61 printf "\tuse sendfile = no\n"
64 if [ "$ALLOW_LEGACY_PROTOCOLS" -eq 1 ]; then
65 logger
-p daemon.info
-t 'samba4-server' "Legacy Protocols allowed, don't use this option for secure environments!"
66 printf "\tserver min protocol = NT1\n"
67 printf "\tlanman auth = yes\n"
68 printf "\tntlm auth = ntlmv1-permitted\n"
70 } >> /var
/etc
/smb.conf
72 [ -e /etc
/samba
/smb.conf
] ||
ln -nsf /var
/etc
/smb.conf
/etc
/samba
/smb.conf
74 if [ ! -L /etc
/samba
/smb.conf
]; then
75 logger
-p daemon.warn
-t 'samba4-server' "Local custom /etc/samba/smb.conf file detected, all luci/config settings are ignored!"
94 local timemachine_maxsize
99 config_get name
$1 name
100 config_get path
$1 path
101 config_get users
$1 users
102 config_get create_mask
$1 create_mask
103 config_get dir_mask
$1 dir_mask
104 config_get browseable
$1 browseable
105 config_get read_only
$1 read_only
106 config_get writeable
$1 writeable
107 config_get guest_ok
$1 guest_ok
108 config_get guest_only
$1 guest_only
109 config_get inherit_owner
$1 inherit_owner
110 config_get vfs_objects
$1 vfs_objects
111 config_get_bool timemachine
$1 timemachine
0
112 config_get timemachine_maxsize
$1 timemachine_maxsize
113 config_get_bool force_root
$1 force_root
0
114 config_get write_list
$1 write_list
115 config_get read_list
$1 read_list
117 [ -z "$name" ] ||
[ -z "$path" ] && return
120 printf "\n[$name]\n\tpath = %s\n" "$path"
122 if [ "$force_root" -eq 1 ]; then
123 printf "\tforce user = root\n"
124 printf "\tforce group = root\n"
126 [ -n "$users" ] && printf "\tvalid users = %s\n" "$users"
129 [ -n "$create_mask" ] && printf "\tcreate mask = %s\n" "$create_mask"
130 [ -n "$dir_mask" ] && printf "\tdirectory mask = %s\n" "$dir_mask"
132 [ -n "$browseable" ] && printf "\tbrowseable = %s\n" "$browseable"
133 [ -n "$read_only" ] && printf "\tread only = %s\n" "$read_only"
134 [ -n "$writeable" ] && printf "\twriteable = %s\n" "$writeable"
135 [ -n "$guest_ok" ] && printf "\tguest ok = %s\n" "$guest_ok"
136 [ -n "$guest_only" ] && printf "\tguest only = %s\n" "$guest_only"
137 [ -n "$inherit_owner" ] && printf "\tinherit owner = %s\n" "$inherit_owner"
139 [ -n "$write_list" ] && printf "\twrite list = %s\n" "$write_list"
140 [ -n "$read_list" ] && printf "\tread list = %s\n" "$read_list"
142 if [ "$MACOS" -eq 1 ]; then
143 vfs_objects
="catia fruit streams_xattr $vfs_objects"
144 printf "\tfruit:encoding = native\n"
145 printf "\tfruit:metadata = stream\n"
146 printf "\tfruit:veto_appledouble = no\n"
147 # avoid mixed shares order for aapl
148 if [ "$timemachine" -eq 1 ]; then
149 printf "\tfruit:time machine = yes\n"
150 [ -n "$timemachine_maxsize" ] && printf "\tfruit:time machine max size = %sG\n" "${timemachine_maxsize}"
154 [ -n "$vfs_objects" ] && printf "\tvfs objects = %s\n" "$vfs_objects"
155 } >> /var
/etc
/smb.conf
160 [ -d /var
/lib
/samba
] || mkdir
-p /var
/lib
/samba
161 [ -d /var
/cache
/samba
] || mkdir
-p /var
/cache
/samba
162 [ -d /var
/run
/samba
] || mkdir
-p /var
/run
/samba
163 [ -d /var
/log
/samba
] || mkdir
-p /var
/log
/samba
164 [ -d /var
/lock
] || mkdir
-p /var
/lock
168 config_foreach smb_header samba
169 config_foreach smb_add_share sambashare
173 # PROCD_RELOAD_DELAY=1000
175 procd_add_reload_trigger
"dhcp" "system" "samba4"
178 for i
in $SAMBA_IFACE; do
179 procd_add_reload_interface_trigger
$i
186 if [ ! -e /etc
/samba
/smb.conf
]; then
187 logger
-p daemon.error
-t 'samba4-server' "missing config /etc/samba/smb.conf!"
192 config_get nice_value extra samba_nice
0
194 # start main AD-DC daemon, will spawn (smbd,nmbd,winbindd) as needed/configured.
195 if [ "$DISABLE_AD_DC" -ne 1 ] && [ -x /usr
/sbin
/samba
]; then
197 procd_set_param
command /usr
/sbin
/samba
-F
198 procd_set_param nice
$nice_value
199 procd_set_param respawn
200 procd_set_param
file /etc
/samba
/smb.conf
201 procd_set_param limits nofile
=16384
204 # start fileserver daemon
206 procd_set_param
command /usr
/sbin
/smbd
-F
207 procd_set_param nice
$nice_value
208 procd_set_param respawn
209 procd_set_param
file /etc
/samba
/smb.conf
210 procd_set_param limits nofile
=16384
213 # start netbios daemon
214 if [ "$DISABLE_NETBIOS" -ne 1 ] && [ -x /usr
/sbin
/nmbd
]; then
216 procd_set_param
command /usr
/sbin
/nmbd
-F
217 procd_set_param nice
$nice_value
218 procd_set_param respawn
219 procd_set_param
file /etc
/samba
/smb.conf
222 # start winbind daemon
223 if [ "$DISABLE_WINBIND" -ne 1 ] && [ -x /usr
/sbin
/winbindd
]; then
225 procd_set_param
command /usr
/sbin
/winbindd
-F
226 procd_set_param nice
$nice_value
227 procd_set_param respawn
228 procd_set_param
file /etc
/samba
/smb.conf