Created
January 31, 2014 01:30
-
-
Save RonaldJerez/8725012 to your computer and use it in GitHub Desktop.
Rewrote the samba implementation in OpenWRT to allow all of the options available in a samba configuration. The included template file is no longer used. Note that you must used an _ (underscore) in place of where Samba uses a space in the options.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh /etc/rc.common | |
# Copyright (C) 2008-2012 OpenWrt.org | |
# Copyright (C) 2014 Ronald Jerez | |
START=60 | |
SMB_CONF="/var/etc/smb.conf" | |
SMB_LINK="/etc/samba/smb.conf" | |
# keep track which config we currently on so we can save | |
# a list of available option per config | |
CURRENT_CONF= | |
config_cb() { | |
local type="$1" | |
local name="$2" | |
if [ "$type" == "samba" ]; then | |
CURRENT_CONF="SAMBA_OPTIONS_global" | |
elif [ "$type" == "share" ]; then | |
CURRENT_CONF="SAMBA_OPTIONS_$name" | |
else | |
CURRENT_CONF="SAMBA_OPTIONS_UNKNOW" | |
fi | |
} | |
option_cb() { | |
local name="$1" | |
append $CURRENT_CONF $name | |
#eval "echo $CURRENT_CONF=\$$CURRENT_CONF" | |
} | |
smb_header() { | |
local name | |
config_get name global name | |
echo "[global]" > $SMB_CONF | |
if [ -n "$name" ]; then | |
echo -e "\tnetbios name = $name" >> $SMB_CONF | |
fi | |
local interface= | |
config_get interface global interface "loopback lan" | |
# resolve interfaces | |
local interfaces=$( | |
. /lib/functions/network.sh | |
local net | |
for net in $interface; do | |
local device | |
network_get_device device "$net" && { | |
local subnet | |
network_get_subnet subnet "$net" && echo -n "$subnet " | |
network_get_subnet6 subnet "$net" && echo -n "$subnet " | |
} | |
echo -n "${device:-$net} " | |
done | |
) | |
# replace the interaces on the config | |
config_set global interface "$interfaces" | |
# print out the options | |
smb_options global | |
} | |
smb_share() { | |
local share=$1 | |
local name | |
local path | |
config_get name $share name | |
config_get path $share path | |
if [ -z "$name" -o -z "$path" ]; then | |
echo "skipping invalid share [$share], name and path required." | |
return | |
fi | |
echo -e "\n[$name]\n\tpath = $path" >> $SMB_CONF | |
smb_options $share | |
} | |
smb_options() { | |
local config=$1 | |
[ -z "$config" ] && return | |
local options | |
eval "options=\$SAMBA_OPTIONS_$config" | |
local val | |
for option in $options; do | |
[ "$option" == "name" -o "$option" == "path" ] && continue | |
config_get val $config $option | |
echo -e "\t${option//_/ } = $val" >> $SMB_CONF | |
done | |
} | |
start() { | |
if [ ! -f $SMB_CONF ]; then | |
reload | |
return 0 | |
fi | |
echo 'Starting SAMBA server' | |
service_start /usr/sbin/smbd -D | |
service_start /usr/sbin/nmbd -D | |
} | |
stop() { | |
echo 'Stoping SAMBA server' | |
service_stop /usr/sbin/smbd | |
service_stop /usr/sbin/nmbd | |
} | |
reload() { | |
echo 'Loading SAMBA UCI config file' | |
mkdir -p $(dirname $SMB_CONF) | |
config_load samba | |
smb_header | |
config_foreach smb_share share | |
[ -L $SMB_LINK ] || ln -nsf $SMB_CONF $SMB_LINK | |
restart | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
config samba | |
option name 'SambaNAS' | |
option workgroup 'WORKGROUP' | |
option description 'Samba Server on OpenWrt server' | |
option create_mask '0660' | |
option directory_mask '0770' | |
option read_only 'no' | |
option guest_ok 'yes' | |
option interface 'loopback lan vpn' | |
option wins_support 'yes' | |
option default_service 'Public' | |
option deadtime '30' | |
option domain_master 'yes' | |
option enable_core_files 'no' | |
option invalid_users 'root' | |
option load_printers 'no' | |
option map_to_guest 'Bad User' | |
option max_protocol 'SMB2' | |
option min_receivefile_size '16384' | |
option null_passwords 'yes' | |
option obey_pam_restrictions 'yes' | |
option passdb_backend 'smbpasswd' | |
option preferred_master 'yes' | |
option security 'user' | |
option smb_encrypt 'disabled' | |
option smb_passwd_file '/etc/samba/smbpasswd' | |
option socket_options 'TCP_NODELAY IPTOS_LOWDELAY' | |
option syslog '2' | |
option use_sendfile 'yes' | |
config share backup | |
option name 'Backups' | |
option path '/mnt/disk2/backups' | |
option admin_users 'admin' | |
option valid_users 'admin ronald' | |
option read_only 'yes' | |
config share | |
option name 'Ronald' | |
option path '/mnt/disk2/ronald' | |
option admin_users 'admin' | |
option valid_users 'admin ronald' | |
option hide_dot_files 'no' | |
option wide_links 'yes' | |
config share | |
option name 'Jaimie' | |
option path '/mnt/disk2/jaimie' | |
option valid_users '@users' | |
config share | |
option name 'Public' | |
option path '/mnt/disk2/public' | |
option guest_ok 'yes' | |
option create_mask '0666' | |
option directory_mask '0777' | |
option force_user 'nobody' | |
option force_group 'nogroup' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment