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"
55 if [ "$DISABLE_ASYNC_IO" -eq 1 ]; then
56 printf "\taio read size = 0\n"
57 printf "\taio write size = 0\n"
58 # sendfile bug: https://bugzilla.samba.org/show_bug.cgi?id=14095
59 printf "\tuse sendfile = no\n"
62 if [ "$ALLOW_LEGACY_PROTOCOLS" -eq 1 ]; then
63 logger
-p daemon.info
-t 'samba4-server' "Legacy Protocols allowed, don't use this option for secure environments!"
64 printf "\tserver min protocol = NT1\n"
65 printf "\tlanman auth = yes\n"
66 printf "\tntlm auth = ntlmv1-permitted\n"
68 } >> /var
/etc
/smb.conf
70 [ -e /etc
/samba
/smb.conf
] ||
ln -nsf /var
/etc
/smb.conf
/etc
/samba
/smb.conf
72 if [ ! -L /etc
/samba
/smb.conf
]; then
73 logger
-p daemon.warn
-t 'samba4-server' "Local custom /etc/samba/smb.conf file detected, all luci/config settings are ignored!"
92 local timemachine_maxsize
97 config_get name
$1 name
98 config_get path
$1 path
99 config_get users
$1 users
100 config_get create_mask
$1 create_mask
101 config_get dir_mask
$1 dir_mask
102 config_get browseable
$1 browseable
103 config_get read_only
$1 read_only
104 config_get writeable
$1 writeable
105 config_get guest_ok
$1 guest_ok
106 config_get guest_only
$1 guest_only
107 config_get inherit_owner
$1 inherit_owner
108 config_get vfs_objects
$1 vfs_objects
109 config_get_bool timemachine
$1 timemachine
0
110 config_get timemachine_maxsize
$1 timemachine_maxsize
111 config_get_bool force_root
$1 force_root
0
112 config_get write_list
$1 write_list
113 config_get read_list
$1 read_list
115 [ -z "$name" ] ||
[ -z "$path" ] && return
118 printf "\n[$name]\n\tpath = %s\n" "$path"
120 if [ "$force_root" -eq 1 ]; then
121 printf "\tforce user = root\n"
122 printf "\tforce group = root\n"
124 [ -n "$users" ] && printf "\tvalid users = %s\n" "$users"
127 [ -n "$create_mask" ] && printf "\tcreate mask = %s\n" "$create_mask"
128 [ -n "$dir_mask" ] && printf "\tdirectory mask = %s\n" "$dir_mask"
130 [ -n "$browseable" ] && printf "\tbrowseable = %s\n" "$browseable"
131 [ -n "$read_only" ] && printf "\tread only = %s\n" "$read_only"
132 [ -n "$writeable" ] && printf "\twriteable = %s\n" "$writeable"
133 [ -n "$guest_ok" ] && printf "\tguest ok = %s\n" "$guest_ok"
134 [ -n "$guest_only" ] && printf "\tguest only = %s\n" "$guest_only"
135 [ -n "$inherit_owner" ] && printf "\tinherit owner = %s\n" "$inherit_owner"
137 [ -n "$write_list" ] && printf "\twrite list = %s\n" "$write_list"
138 [ -n "$read_list" ] && printf "\tread list = %s\n" "$read_list"
140 if [ "$MACOS" -eq 1 ]; then
141 vfs_objects
="catia fruit streams_xattr $vfs_objects"
142 printf "\tfruit:encoding = native\n"
143 printf "\tfruit:metadata = stream\n"
144 printf "\tfruit:veto_appledouble = no\n"
145 # avoid mixed shares order for aapl
146 if [ "$timemachine" -eq 1 ]; then
147 printf "\tfruit:time machine = yes\n"
148 [ -n "$timemachine_maxsize" ] && printf "\tfruit:time machine max size = %sG\n" "${timemachine_maxsize}"
152 [ -n "$vfs_objects" ] && printf "\tvfs objects = %s\n" "$vfs_objects"
153 } >> /var
/etc
/smb.conf
158 [ -d /var
/lib
/samba
] || mkdir
-p /var
/lib
/samba
159 [ -d /var
/cache
/samba
] || mkdir
-p /var
/cache
/samba
160 [ -d /var
/run
/samba
] || mkdir
-p /var
/run
/samba
161 [ -d /var
/log
/samba
] || mkdir
-p /var
/log
/samba
162 [ -d /var
/lock
] || mkdir
-p /var
/lock
166 config_foreach smb_header samba
167 config_foreach smb_add_share sambashare
171 # PROCD_RELOAD_DELAY=1000
173 procd_add_reload_trigger
"dhcp" "system" "samba4"
176 for i
in $SAMBA_IFACE; do
177 procd_add_reload_interface_trigger
$i
184 if [ ! -e /etc
/samba
/smb.conf
]; then
185 logger
-p daemon.error
-t 'samba4-server' "missing config /etc/samba/smb.conf!"
190 config_get nice_value extra samba_nice
0
192 # start main AD-DC daemon, will spawn (smbd,nmbd,winbindd) as needed/configured.
193 if [ "$DISABLE_AD_DC" -ne 1 ] && [ -x /usr
/sbin
/samba
]; then
195 procd_set_param
command /usr
/sbin
/samba
-F
196 procd_set_param nice
$nice_value
197 procd_set_param respawn
198 procd_set_param
file /etc
/samba
/smb.conf
199 procd_set_param limits nofile
=16384
202 # start fileserver daemon
204 procd_set_param
command /usr
/sbin
/smbd
-F
205 procd_set_param nice
$nice_value
206 procd_set_param respawn
207 procd_set_param
file /etc
/samba
/smb.conf
208 procd_set_param limits nofile
=16384
211 # start netbios daemon
212 if [ "$DISABLE_NETBIOS" -ne 1 ] && [ -x /usr
/sbin
/nmbd
]; then
214 procd_set_param
command /usr
/sbin
/nmbd
-F
215 procd_set_param nice
$nice_value
216 procd_set_param respawn
217 procd_set_param
file /etc
/samba
/smb.conf
220 # start winbind daemon
221 if [ "$DISABLE_WINBIND" -ne 1 ] && [ -x /usr
/sbin
/winbindd
]; then
223 procd_set_param
command /usr
/sbin
/winbindd
-F
224 procd_set_param nice
$nice_value
225 procd_set_param respawn
226 procd_set_param
file /etc
/samba
/smb.conf