summaryrefslogtreecommitdiff
path: root/debian/local/update_mc
blob: 0c0c2eadb5b207610df5635bc239e8a9572aa9dc (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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#!/bin/sh -e
#-----------------------------------------------------------------------------
#
# $Sendmail: update_mc,v 8.14.4 2010-10-16 19:38:59 cowboy Exp $
#
# Update Sendmail databases for Debian
#
# Copyright (c) 2000-2010 Richard Nelson.  All Rights Reserved.
#
# Notes (to all):
#	* assumes makemap dbtype /etc/mail/database < /etc/mail/database
#
# Notes (to self):
#	* changes made herein *must* be reflected in
#		parse_mc,update_mk,update_db,debian.m4
#
#-----------------------------------------------------------------------------
set -e;

changed=0;

# Path to other sendmail helpers
if [ -x ./update_sendmail ]; then
	sm_path='.';
elif [ -x $(dirname $0)/update_sendmail ]; then
	sm_path=$(dirname $0);
else
	sm_path=/usr/share/sendmail;
	fi;
# Bring in sendmail.conf for the network definitions
if [ ! -f /etc/mail/sendmail.conf ]; then
	if [ -x $sm_path/update_conf ]; then
		$sm_path/update_conf;
		fi;
	fi;
if [ -f /etc/mail/sendmail.conf ]; then
	. /etc/mail/sendmail.conf;
	fi;
if [ "$HANDS_OFF" != 'No' ]; then
	exit 0;
	fi;

new_mc () {
	chown root:smmsp /etc/mail/"$1".mc.new;
	chmod 0644 /etc/mail/"$1".mc.new;
	mv /etc/mail/"$1".mc.new /etc/mail/"$1".mc;
	changed=1;
	};	

#-----------------------------------------------------------------------------
# Move sendmail.{mc,cf} from /etc/ to /etc/mail
if [ ! -f /etc/mail/sendmail.mc ]; then
	if [ -f /etc/sendmail.mc ]; then
		echo "Moving /etc/sendmail.* to /etc/mail/";
		mv /etc/sendmail.mc /etc/mail/sendmail.mc.new;
		new_mc sendmail;
		fi;
	if [ -f /etc/sendmail.cf ]; then
		mv /etc/sendmail.cf /etc/mail/sendmail.cf;
		chown root:smmsp /etc/mail/sendmail.cf;
		chmod 0644 /etc/mail/sendmail.cf;
		changed=1;
		fi;
	fi;

#-----------------------------------------------------------------------------
# Create {submit,sendmail}.mc if needed
if [ ! -f /etc/mail/sendmail.mc ]; then
	cp -p /usr/share/sendmail/cf/debian/sendmail.mc \
		/etc/mail/sendmail.mc.new;
	if [ -f /etc/mailname ] && [ ! -z /etc/mailname ]; then
		masq=$(cat /etc/mailname);
		echo "dnl # Masquerading options" \
			>> /etc/mail/sendmail.mc.new;
		echo "FEATURE(\`always_add_domain')dnl" \
			>> /etc/mail/sendmail.mc.new;
		echo "MASQUERADE_AS(\`${masq}')dnl" \
			>> /etc/mail/sendmail.mc.new;
		echo "FEATURE(\`allmasquerade')dnl" \
			>> /etc/mail/sendmail.mc.new;
		echo "FEATURE(\`masquerade_envelope')dnl" \
			>> /etc/mail/sendmail.mc.new;
		fi;
	new_mc sendmail;
	fi;
if [ ! -f /etc/mail/submit.mc ]; then
	if [ -f /usr/share/sendmail/cf/debian/submit.mc ]; then
		cp -p /usr/share/sendmail/cf/debian/submit.mc \
			/etc/mail/submit.mc.new;
		new_mc submit;
		fi;
	fi;

#-----------------------------------------------------------------------------
# Make sure dialup support m4 files are extant
if [ ! -f /etc/mail/m4/dialup.m4 ]; then
	if [ -f /etc/mail/dialup.m4 ]; then
		mv /etc/mail/dialup.m4 /etc/mail/m4/dialup.m4;
	else
		touch /etc/mail/m4/dialup.m4;
		fi;
	chown root:smmsp /etc/mail/m4/dialup.m4;
	chmod 0640 /etc/mail/m4/dialup.m4;
	fi;
if [ ! -f /etc/mail/m4/provider.m4 ]; then
	if [ -f /etc/mail/provider.m4 ]; then
		mv /etc/mail/provider.m4 /etc/mail/m4/provider.m4;
	else
		touch /etc/mail/m4/provider.m4;
		fi;
	chown root:smmsp /etc/mail/m4/provider.m4;
	chmod 0640 /etc/mail/m4/provider.m4;
	fi;
if (grep -qEe "^[[:space:]]*include\(\`?/etc/mail/dialup.m4" \
		/etc/mail/sendmail.mc); then
	sed -e "s=^\([[:space:]]*\)include(\`\?/etc/mail/dialup\.m4.*$=include(\`/etc/mail/m4/dialup\.m4')dnl=" \
		/etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
	new_mc sendmail;
	fi;
if (grep -qEe "^[[:space:]]*include\(\`?/etc/mail/provider.m4" \
		/etc/mail/sendmail.mc); then
	sed -e "s=^\([[:space:]]*\)include(\`\?/etc/mail/provider\.m4.*$=include(\`/etc/mail/m4/provider\.m4')dnl=" \
		/etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
	new_mc sendmail;
	fi;

#-----------------------------------------------------------------------------
# Make sure not using text mailertable (it doesn't work)
if (grep -qEe "^[[:space:]]*FEATURE\(\`?mailertable'?, \`text /etc/mail/mailertable'\)" \
		/etc/mail/sendmail.mc); then
	echo "Correcting FEATURE(mailertable) in /etc/mail/sendmail.mc";
	sed -e "s=^\([[:space:]]*\)\(\`\?\)FEATURE(\`\?mailertable'\?, \`text /etc/mail/mailertable')\(dnl\)\?=\1\2FEATURE(\`mailertable')dnl=g" \
		 /etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
	new_mc sendmail;
	fi;

#-----------------------------------------------------------------------------
# Make sure smrsh points to the correct location
if (grep -qEe "^[[:space:]]*\`?FEATURE\(\`?smrsh'?[[:space:]]*,.*\)" \
	/etc/mail/sendmail.mc); then
	echo "Correcting FEATURE(smrsh) in /etc/mail/sendmail.mc";
	sed -e "s=\([[:space:]]*\)\(\`\?\)FEATURE(\`\?smrsh'\?[[:space:]]*,.*)\(dnl\)\?=\1\2FEATURE(\`smrsh')dnl=g" \
		/etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
	new_mc sendmail;
	fi;

#-----------------------------------------------------------------------------
# Convert FEATURE(nouucp) to FEATURE(nouucp,reject)
if (grep -qEe "^[[:space:]]*\`?FEATURE\(\`?nouucp'?\)" \
	/etc/mail/sendmail.mc); then
	echo "Correcting FEATURE(nouucp) in /etc/mail/sendmail.mc";
	sed -e "s=^\([[:space:]]*\)\(\`\?\)FEATURE(\`\?nouucp'\?)\(dnl\)\?=\1\2FEATURE(\`nouucp', \`reject')dnl=g" \
		/etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
	new_mc sendmail;
	fi;

#-----------------------------------------------------------------------------
# Convert FEATURE(dont_masquerade_local) to FEATURE(local_no_masquerade)
if [ -e /usr/share/sendmail/cf/feature/local_no_masquerade.m4 ]; then
	if (grep -qEe "^[[:space:]]*\`?FEATURE\(\`?dont_masquerade_local'?\)" \
		/etc/mail/sendmail.mc); then
		echo "Correcting FEATURE(dont_masquerade_local) in /etc/mail/sendmail.mc";
		sed -e "s=^\([[:space:]]*\)\(\`\?\)FEATURE(\`\?dont_masquerade_local'\?)\(dnl\)\?=\1\2FEATURE(\`local_no_masquerade')dnl=g" \
			/etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
		new_mc sendmail;
		fi;
	fi;

#-----------------------------------------------------------------------------
# Convert FEATURE(access_db,...) to FEATURE(access_db)
if (grep -qEe "^[[:space:]]*\`?FEATURE\(\`?access_db'?[[:space:]]*,.*\)" \
	/etc/mail/sendmail.mc); then
	sed -e "s=^\([[:space:]]*\)\(\`\?\)FEATURE(\`\?access_db'\?[[:space:]]*,[[:space:]]*\`\?hash[[:space:]]*\(-o\)\?[[:space:]]*/etc/mail/access.db'\?[[:space:]]*)\(dnl\)\?=\1\2FEATURE(\`access_db')dnl=g" \
	/etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
	new_mc sendmail;
	fi;

#-----------------------------------------------------------------------------
# change include(/usr/share/sendmail/sendmail.cf/m4/cf.m4)
if (grep -qEe "^[[:space:]]*\`?include\(\`?/usr/share/sendmail/sendmail.cf/m4/cf.m4'?\)" \
	/etc/mail/sendmail.mc); then
	sed -e "s=sendmail/sendmail.cf=sendmail/cf=g" \
		/etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
	new_mc sendmail;
	if [ -f /etc/mail/submit.mc ]; then
		sed -e "s=sendmail/sendmail.cf=sendmail/cf=g" \
			/etc/mail/submit.mc > /etc/mail/submit.mc.new;
		new_mc submit;
		fi;
	fi;

#-----------------------------------------------------------------------------
# Add include(/usr/share/sendmail/cf/m4/cf.m4)
if (grep -qEe "^[[:space:]]*\`?include\(\`?/usr/share/sendmail/cf/m4/cf.m4'?\)" \
	/etc/mail/sendmail.mc); then
	:;
else
	echo "Adding include(.../cf.m4) to /etc/mail/sendmail.mc";
	sed -e "s=^\([[:space:]]*\)\(\`\?\)VERSIONID(=\1\2include(\`/usr/share/sendmail/cf/m4/cf.m4')dnl\\
\1\2VERSIONID(=" \
		/etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
	new_mc sendmail;
	fi;

#-----------------------------------------------------------------------------
# Add define(`_USE_ETC_MAIL_')dnl
if (grep -qEe "^[[:space:]]*\`?define\(\`?_USE_ETC_MAIL_" \
	/etc/mail/sendmail.mc); then
	:;
else
	sed -e "s=^\([[:space:]]*\)\(\`\?\)include(\`\?/usr/share/sendmail/cf/m4/cf.m4'\?)\(dnl\)\?=\1\2define(\`_USE_ETC_MAIL_')dnl\\
include(\`/usr/share/sendmail/cf/m4/cf.m4')dnl=" \
		/etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
	new_mc sendmail;
	fi;

#-----------------------------------------------------------------------------
# Check for badness
if (grep -qEe "^[[:space:]]*\`?OSTYPE\(\`?linux'?\)" \
	/etc/mail/sendmail.mc); then
	sed -e 	"s=^\([[:space:]]*\)\(\`\?\)OSTYPE(\`\?linux'\?)\(dnl\)\?=\1\2OSTYPE(\`debian')dnl=" \
		/etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
		new_mc sendmail;
	fi;

#-----------------------------------------------------------------------------
# Add DOMAIN(debian-mta)
if (grep -qEe "^[[:space:]]*\`?DOMAIN\(\`?debian-mta'?\)" \
	/etc/mail/sendmail.mc); then
	:;
else
	echo "Adding DOMAIN(debian-mta) to /etc/mail/sendmail.mc";
	sed -e "s=^\([[:space:]]*\)\(\`\?\)OSTYPE(\`\?debian'\?)\(dnl\)\?=\1\2OSTYPE(\`debian')dnl\\
\1\2DOMAIN(\`debian-mta')dnl=" \
		/etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
	new_mc sendmail;
	fi;

#-----------------------------------------------------------------------------
# Add sendmail.conf customization area
if (grep -qEe "^dnl # Items controlled by /etc/mail/sendmail.conf" \
	/etc/mail/sendmail.mc); then
	:;
else
	echo "Adding sendmail.conf customization area to /etc/mail/sendmail.mc";
	sed -e "s=^\([[:space:]]*\)\(\`\?\)DOMAIN(\`\?debian-mta'\?)\(dnl\)\?=\1\2DOMAIN(\`debian-mta')dnl\\
dnl # Items controlled by /etc/mail/sendmail.conf - DO NOT TOUCH HERE \\
dnl undefine(\`confHOST_STATUS_DIRECTORY')dnl		#DAEMON_HOSTSTATS \\
dnl # Items controlled by /etc/mail/sendmail.conf - DO NOT TOUCH HERE=" \
	/etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
	new_mc sendmail;
	fi;

#-----------------------------------------------------------------------------
# Update items in sendmail.conf customization area
case "$DAEMON_HOSTSTATS" in
	[Nn]*)
		if (grep -qEe "^dnl undefine\(\`confHOST_STATUS_DIRECTORY'\)dnl" \
			/etc/mail/sendmail.mc); then
			echo "Turning off Host Status collection";
			sed -e "s=^dnl undefine(\`confHOST_STATUS_DIRECTORY')dnl=undefine(\`confHOST_STATUS_DIRECTORY')dnl=" \
			/etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
			new_mc sendmail;
			fi;
		;;
	[Yy]*)
		if (grep -qEe "^undefine\(\`confHOST_STATUS_DIRECTORY'\)dnl" \
			/etc/mail/sendmail.mc); then
			echo "Turning on Host Status collection";
			sed -e "s=^undefine(\`confHOST_STATUS_DIRECTORY')dnl=dnl undefine(\`confHOST_STATUS_DIRECTORY')dnl=" \
			/etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
			new_mc sendmail;
			fi;
	esac;

#-----------------------------------------------------------------------------
# Cleanup submit.mc
if [ -f /etc/mail/submit.mc ]; then
	sed -e "/^define(\`\?confRUN_AS_USER'\?,.*$/d" \
		-e "/^define(\`\?confTRUSTED_USER'\?,.*$/d" \
		/etc/mail/submit.mc > /etc/mail/submit.mc.new;
	new_mc submit;
	fi;

exit $changed;