mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-10 07:44:50 +01:00
161 lines
4 KiB
Bash
161 lines
4 KiB
Bash
#!/bin/sh /etc/rc.common
|
|
|
|
START=90
|
|
USE_PROCD=1
|
|
PROG=/usr/sbin/cifsd
|
|
USER_DB=/etc/cifs/cifsdpwd.db
|
|
CIFS_ADMIN=cifsadmin
|
|
|
|
EXTRA_COMMANDS="users"
|
|
EXTRA_HELP=" users Show list of users created by cifsadmin"
|
|
|
|
users() {
|
|
[ -f "$USER_DB" ] && cut -d ':' $USER_DB -f1 || \
|
|
printf "No users available.\n"
|
|
}
|
|
|
|
validate_cifsd_global() {
|
|
uci_validate_section cifsd global global \
|
|
'server_string:string' \
|
|
'workgroup:string' \
|
|
'netbios_name:string' \
|
|
'interface:string' \
|
|
'ipc_timeout:uinteger'
|
|
}
|
|
|
|
validate_cifsd_share() {
|
|
uci_validate_section cifsd share "${1}" \
|
|
'name:string' \
|
|
'comment:string' \
|
|
'path:string' \
|
|
'guest_ok:bool' \
|
|
'read_only:bool' \
|
|
'allow_hosts:list' \
|
|
'deny_hosts:list' \
|
|
'users:string' \
|
|
'invalid_users:string' \
|
|
'create_mask:string' \
|
|
'dir_mask:string' \
|
|
'max_connections:uinteger' \
|
|
'veto_files:list'
|
|
}
|
|
|
|
validate_cifsd_users() {
|
|
uci_validate_section cifsd users "${1}" \
|
|
'user:string' \
|
|
'password:string' \
|
|
'desc:string'
|
|
}
|
|
|
|
load_cifsd_global() {
|
|
local server_string
|
|
local workgroup
|
|
local netbios_name
|
|
local ipc_timeout
|
|
|
|
validate_cifsd_global
|
|
|
|
echo -e "[global]" >> /var/etc/cifsd.conf
|
|
[ -n "$server_string" ] && echo -e "\tserver string = $server_string" >> /var/etc/cifsd.conf
|
|
[ -n "$workgroup" ] && echo -e "\tworkgroup = $workgroup" >> /var/etc/cifsd.conf
|
|
[ -n "$netbios_name" ] && echo -e "\tnetbios name = $netbios_name" >> /var/etc/cifsd.conf
|
|
[ -n "$ipc_timeout" ] && echo -e "\tipc timeout name = $ipc_timeout" >> /var/etc/cifsd.conf || \
|
|
echo -e "\tipc timeout name = 8" >> /var/etc/cifsd.conf
|
|
}
|
|
|
|
load_cifsd_share() {
|
|
local name
|
|
local comment
|
|
local path
|
|
local guest_ok
|
|
local allow_hosts
|
|
local deny_hosts
|
|
local users
|
|
local invalid_users
|
|
local max_connections
|
|
local veto_files
|
|
local dir_mask
|
|
local create_mask
|
|
local read_only
|
|
|
|
validate_cifsd_share ${1}
|
|
|
|
if [ -z "$name" -o -z "$path" ]; then
|
|
logread -t ${0} "Missing name or path."
|
|
return
|
|
fi
|
|
|
|
echo -e "\n[$name]\n\tpath = $path" >> /var/etc/cifsd.conf
|
|
[ -n "$comment" ] && echo -e "\tcomment = $comment" >> /var/etc/cifsd.conf
|
|
[ -n "$guest_ok" ] && echo -e "\tguest ok = $guest_ok" >> /var/etc/cifsd.conf
|
|
[ -n "$allow_hosts" ] && echo -e "\tallow hosts = $allow_hosts" >> /var/etc/cifsd.conf
|
|
[ -n "$deny_hosts" ] && echo -e "\tdeny hosts = $deny_hosts" >> /var/etc/cifsd.conf
|
|
[ -n "$users" ] && echo -e "\tvalid users = $users" >> /var/etc/cifsd.conf
|
|
[ -n "$invalid_users" ] && echo -e "\tinvalid users = $invalid_users" >> /var/etc/cifsd.conf
|
|
[ -n "$max_connections" ] && echo -e "\tmax connections = $max_connections" >> /var/etc/cifsd.conf
|
|
[ -n "$create_mask" ] && echo -e "\tcreate mask = $create_mask" >> /var/etc/cifsd.conf
|
|
[ -n "$dir_mask" ] && echo -e "\tdirectory mask = $dir_mask" >> /var/etc/cifsd.conf
|
|
|
|
if [ -n "$read_only" ]; then
|
|
echo -e "\tread only = $read_only" >> /var/etc/cifsd.conf
|
|
if [ "${read_only}" -eq "0" ]; then
|
|
echo -e "\twrite ok = 1" >> /var/etc/cifsd.conf
|
|
fi
|
|
else
|
|
echo -e "\twrite ok = 1" >> /var/etc/cifsd.conf
|
|
fi
|
|
|
|
[ -n "$veto_files" ] && echo -e "\tveto files = $veto_files" >> /var/etc/cifsd.conf
|
|
}
|
|
|
|
load_cifsd_users() {
|
|
local user
|
|
local password
|
|
local desc
|
|
|
|
validate_cifsd_users ${1}
|
|
[ $(which ${CIFS_ADMIN}) ] || {
|
|
logread -t ${0} "${CIFS_ADMIN} tools is not available"
|
|
return;
|
|
}
|
|
|
|
cifsadmin -a "${user}" -p "${password}"
|
|
if [ "$?" -ne 0 ]; then
|
|
logread -t ${0} "Failed to create/update ${user}"
|
|
fi
|
|
}
|
|
|
|
service_triggers()
|
|
{
|
|
procd_add_config_trigger "config.change" "cifsd" /etc/init.d/cifsd restart
|
|
}
|
|
|
|
init_config() {
|
|
[ -f "/var/etc/cifsd.conf" ] && rm /var/etc/cifsd.conf
|
|
|
|
config_load cifsd
|
|
load_cifsd_global
|
|
|
|
# Delete existing users
|
|
[ -f "${USER_DB}" ] && {
|
|
rm -f "${USER_DB}"
|
|
}
|
|
config_foreach load_cifsd_users users
|
|
config_foreach load_cifsd_share share
|
|
}
|
|
|
|
start_service() {
|
|
. /lib/functions.sh
|
|
init_config
|
|
|
|
[ ! "$(grep cifsd /proc/modules)" ] && modprobe cifsd
|
|
procd_open_instance
|
|
procd_set_param command /usr/bin/env LANG=en_US.UTF-8 $PROG -c /var/etc/cifsd.conf
|
|
procd_set_param respawn
|
|
procd_close_instance
|
|
}
|
|
|
|
stop_service() {
|
|
killall cifsd
|
|
# IPC timeout will kill the remaining processes.
|
|
}
|