summaryrefslogtreecommitdiff
path: root/packaging/Debian/debian/samba.prerm
blob: acd6d087b5c4fc85bca9c0f4f3e94a3a642f522e (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
#!/bin/sh
#
# Pre-removal script for the Samba package for Debian GNU/Linux.
#
# Written by Eloy A. Paris for the Debian project.
#

DEBIAN_CONFIG=/etc/samba/debian_config

NMBDPID=/var/state/samba/nmbd.pid
SMBDPID=/var/state/samba/smbd.pid

# The most important thing the prerm script must do is to stop the Samba
#	daemons (nmbd and smbd). Note that this can be tricky since Samba
#	can be running from the inetd meta-daemon or as daemons (it's a 
#	user choice).

# Before we stop Samba we need to know how it is running (from inetd
#	or as daemons). We could source in the debian_config file but it
#	is safer to grep /etc/inetd.conf.
if grep -q '^netbios-ns' /etc/inetd.conf; then
	# Samba is running from inetd. We need to disable the Samba daemons
	#	in /etc/inetd.conf before we stop the daemons. Otherwise traffic
	#	in the NetBIOS ports will make inetd start them again.
	#
	# Note: user preferences regarding the mode he/she wants Samba to
	#	be run (inetd or daemons) will be lost next. In the postinst
	#	we depend on the information present in the debian_config
	#	file to restore everything back to the way it was.
	update-inetd --disable netbios-ssn
	update-inetd --disable netbios-ns

	# Now it is safe to stop the daemons...

	# I have just recalled that old versions of nmbd and smbd did not store
	#	their PID's in /var/samba/state/ (or whatever directory
	#	was used for this purpose in configure), so I can't use
	#	--pidfile in start-stop-daemon to stop nmbd or smbd. I 
	#	will handle this by testing first whether the PID file exists.
	if [ -f $NMBDPID ]; then
		start-stop-daemon --stop --oknodo --user root --name nmbd --quiet --pidfile $NMBDPID
	else
		start-stop-daemon --stop --oknodo --user root --name nmbd --quiet
	fi

	# nmbd must be dead by now, now it's smbd's turn
	if [ -f $SMBDPID ]; then
		start-stop-daemon --stop --oknodo --user root --name smbd --quiet --pidfile $SMBDPID
	else
		start-stop-daemon --stop --oknodo --user root --name smbd --quiet
	fi
elif [ -x /etc/init.d/samba ]; then	# Old Samba packages didn't have a
					#	/etc/init.d/samba so we better 
					#	check first.
	# Samba is running as daemons. No problem here, just stop Samba...
	/etc/init.d/samba stop
fi

if [ \( "$1" = "upgrade" -o "$1" = "remove" \) -a -L /usr/doc/samba ]; then
	rm -f /usr/doc/samba
fi

# Make sure there are no nmbd or smbd daemons running (security check)
# (as you see this code is commented out - so far I haven't had the need
#	to do this sanity check - peloy, Aug. 23, 1998)
#ps -ax | grep nmbd
#if [ $? ... ]; then
#	killall -9 nmbd
#fi

#ps -ax | grep smbd
#if [ $? ... ]; then
#	killall -9 smbd
#fi