blob: 8eeb0eccac7bfb66f007e0aae0cabe452a57b173 (
plain)
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
|
#!/bin/sh
#
# $FreeBSD: head/net/samba43/files/samba_server.in 402642 2015-11-30 01:35:36Z timur $
#
# PROVIDE: samba_server
# REQUIRE: NETWORKING SERVERS DAEMON ldconfig resolv ntpd %%SAMBA4_SERVICES%%
# BEFORE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
#samba_server_enable="YES"
#
# You can disable/enable any of the Samba daemons by specifying:
#samba_enable="NO"
#nmbd_enable="NO"
#smbd_enable="NO"
# You need to enable winbindd separately, by adding:
#winbindd_enable="YES"
# Configuration file can be set with:
#samba_server_config="%%SAMBA4_CONFDIR%%/%%SAMBA4_CONFIG%%"
#
. /etc/rc.subr
name="samba_server"
rcvar=${name}_enable
# Defaults
samba_server_config_default="%%SAMBA4_CONFDIR%%/%%SAMBA4_CONFIG%%"
smbcontrol_command="%%PREFIX%%/bin/smbcontrol"
# Custom commands
extra_commands="reload status configtest"
start_precmd="samba_server_prestart"
restart_precmd="samba_server_checkconfig"
reload_precmd="samba_server_checkconfig"
start_cmd="samba_server_cmd"
stop_cmd="samba_server_cmd"
status_cmd="samba_server_cmd"
configtest_cmd="samba_server_checkconfig"
reload_cmd="samba_server_reload_cmd"
rcvar_cmd="samba_server_rcvar_cmd"
samba_server_checkconfig() {
echo -n "Performing sanity check on Samba configuration: "
if ${testparm_command} >/dev/null 2>&1; then
echo "OK"
else
echo "FAILED"
return 1
fi
}
samba_server_prestart() {
# Make sure we have our RUNDIR, even if it's on a tmpfs
if [ -d "${samba_server_piddir}" -o ! -e "${samba_server_piddir}" ]; then
install -d -m 0755 "${samba_server_piddir}"
fi
# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=200186
if [ -d "${samba_server_privatedir}" -o ! -e "${samba_server_privatedir}" ]; then
install -d -m 0700 "${samba_server_privatedir}"
fi
samba_server_checkconfig
}
samba_server_rcvar_cmd() {
local name rcvar
rcvar=${name}_enable
# Prevent recursive calling
unset "${rc_arg}_cmd" "${rc_arg}_precmd" "${rc_arg}_postcmd"
# Check master variable
run_rc_command "${_rc_prefix}${rc_arg}" ${rc_extra_args}
# Check dependent variables
for name in ${samba_daemons}; do
# XXX
rcvars=''; v=''
rcvar=${name}_enable
run_rc_command "${_rc_prefix}${rc_arg}" ${rc_extra_args}
done
}
samba_server_reload_cmd() {
local name rcvar command pidfile force_run
# Prevent recursive calling
unset "${rc_arg}_cmd" "${rc_arg}_precmd" "${rc_arg}_postcmd"
# Ignore rcvar and run command
if [ -n "${_rc_prefix}" -a "${_rc_prefix}" = "one" ] || [ -n "${rc_force}" ] || [ -n "${rc_fast}" ]; then
force_run=yes
fi
# Apply to all daemons
for name in ${samba_daemons}; do
rcvar=${name}_enable
command="%%PREFIX%%/sbin/${name}"
pidfile="${samba_server_piddir}/${name}.pid"
# Daemon should be enabled and running
if ( [ -n "${rcvar}" ] && checkyesno "${rcvar}" ) || [ -n "$force_run" ]; then
if [ -n "$(check_pidfile "${pidfile}" "${command}")" ]; then
debug "reloading ${name} configuration"
echo "Reloading ${name}."
${smbcontrol_command} "${name}" 'reload-config' ${command_args} >/dev/null 2>&1
fi
fi
done
}
samba_server_cmd() {
local name rcvar rcvars v command pidfile samba_daemons result force_run
# Prevent recursive calling
unset "${rc_arg}_cmd" "${rc_arg}_precmd" "${rc_arg}_postcmd"
# Stop processes in the reverse order
if [ "${rc_arg}" = "stop" ] ; then
samba_daemons=$(reverse_list ${samba_daemons})
fi
# Ignore rcvar and run command
if [ -n "${_rc_prefix}" -a "${_rc_prefix}" = "one" ] || [ -n "${rc_force}" ] || [ -n "${rc_fast}" ]; then
force_run=yes
fi
# Assume success
result=0
# Apply to all daemons
for name in ${samba_daemons}; do
# XXX
rcvars=''; v=''
rcvar=${name}_enable
command="%%PREFIX%%/sbin/${name}"
pidfile="${samba_server_piddir}/${name}.pid"
# Daemon should be enabled and running
if ( [ -n "${rcvar}" ] && checkyesno "${rcvar}" ) || [ -n "$force_run" ]; then
run_rc_command "${_rc_prefix}${rc_arg}" ${rc_extra_args}
# If any of the commands failed, take it as a global result
result=$((${result} || $?))
fi
done
return ${result}
}
samba_server_config_init() {
local name
# Load configuration
load_rc_config "${name}"
# Defaults
samba_server_enable=${samba_server_enable:=NO}
samba_server_config=${samba_server_config=${samba_server_config_default}}
samba_server_configfile_arg=${samba_server_config:+--configfile="${samba_server_config}"} #"
#testparm_command="%%PREFIX%%/bin/samba-tool testparm --suppress-prompt --verbose ${samba_server_configfile_arg}"
testparm_command="%%PREFIX%%/bin/testparm --suppress-prompt --verbose ${samba_server_config}"
# Determine what daemons are necessary to run Samba in the current role
samba_server_role=$(${testparm_command} --parameter-name='server role' 2>/dev/null)
case "${samba_server_role}" in
active\ directory\ domain\ controller)
samba_daemons="samba"
;;
auto|*)
samba_daemons="nmbd smbd winbindd"
;;
esac
# Load daemons configuration
for name in ${samba_daemons}; do
load_rc_config "${name}"
# If samba_server_enable is 'YES'
if [ -n "${rcvar}" ] && checkyesno "${rcvar}"; then
if [ "${name}" != "winbindd" ]; then
# Set variable to 'YES' only if it is unset
eval ${name}_enable=\${${name}_enable-YES}
else
# Winbindd
samba_server_idmap=$(${testparm_command} --parameter-name='idmap uid' 2>/dev/null)
if [ -n "${samba_server_idmap}" ]; then
winbindd_enable="YES"
fi
fi
fi
# If variable is empty, set it to 'NO'
eval ${name}_enable=\${${name}_enable:-NO}
done
# Fetch parameters from configuration file
samba_server_lockdir="$(${testparm_command} --parameter-name='lock directory' 2>/dev/null)"
samba_server_lockdir=${samba_server_lockdir:=%%SAMBA4_LOCKDIR%%}
samba_server_piddir="$(${testparm_command} --parameter-name='pid directory' 2>/dev/null)"
samba_server_piddir=${samba_server_piddir:=%%SAMBA4_RUNDIR%%}
samba_server_privatedir="$(${testparm_command} --parameter-name='private dir' 2>/dev/null)"
samba_server_privatedir=${samba_server_privatedir:=%%SAMBA4_PRIVATEDIR%%}
}
# Load configuration variables
samba_server_config_init
# Common flags
command_args=${samba_server_configfile_arg}
samba_flags=${samba_flags="--daemon"}
nmbd_flags=${nmbd_flags="--daemon"}
smbd_flags=${smbd_flags="--daemon"}
winbindd_flags=${winbindd_flags="--daemon"}
# Requirements
required_files="${samba_server_config}"
required_dirs="${samba_server_lockdir}"
run_rc_command "$1"
|