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
|
#!/bin/sh
#
# This script is called when dhcp connects to the network.
#
# Here is where we'll start sendmail if needed, and will
# run the queue in either case.
#
# Written By Richard Nelson <cowboy@debian.org>
#
# NOTE: The following lines (without the #) must be in /etc/mail/sendmail.mc:
# include(`/etc/mail/dialup.m4')dnl
# include(`/etc/mail/provider.m4')dnl
#
# NOTE: The dhcp DNS name is used as the peer name in /etc/mail/peers.
#
# Exit by default, check for validity before commenting out the next line:
exit 0;
provider_m4='/etc/mail/provider.m4';
#provider_m4='provider.m4';
dialup_m4='/etc/mail/dialup.m4';
#dialup_m4='dialup.m4';
update_sendmail() {
# Build a new sendmail.cf from sendmail.mc, including our address.
m4 /etc/mail/sendmail.mc \
> /etc/mail/sendmail.cf.pnew;
chmod 0644 /etc/mail/sendmail.cf.pnew;
chown mail:mail /etc/mail/sendmail.cf.pnew;
mv -f /etc/mail/sendmail.cf.pnew /etc/mail/sendmail.cf;
# Purge any latent host status that might cause us to *NOT* send mail
AM='-Am';
if [ ! -f /usr/share/sendmail/cf/feature/msp.m4 ]; then
AM='';
fi;
sendmail $AM -bH -O Timeout.hoststatus=1s;
# Start/reload sendmail as needed
/etc/init.d/sendmail reload; # may be up, or down
# Process the sendmail queue
# (background so as to not defer other ip-up work)
runq &
};
update_provider() {
# Add smarthost information (if any)...
# But not if provider.m4 is a link !
local domain;
domain="$1";
if [ -f /etc/mail/peers/$domain -a ! -L $provider_m4 ]; then
cat <<-EOT > $provider_m4;
LOCAL_CONFIG
#------------------------------------------------------------
#
# Dynamic provider updates from $0
#
# NOTE: the following line *MUST* be in /etc/mail/sendmail.mc
dnl include(\`/etc/mail/provider.m4')dnl
#
# Provider information from /etc/mail/peers/$domain
EOT
cat /etc/mail/peers/$domain >> $provider_m4;
cat <<-EOT >> $provider_m4;
#------------------------------------------------------------
EOT
fi;
};
find_host() {
# Determine our fqdn from our ISP
local addr;
addr="$1";
maxloop=20;
cntr=0;
host='';
until (test ! -z "$host"); do
cntr=$(($cntr+1));
rev=$(host $addr);
host=$(echo "$rev" | grep '^Name:' | awk '{print $2}');
if [ -z "$host" ]; then
host=${rev##*domain name pointer };
host=${host%.};
fi;
test=$(echo $host | cut -d ' ' -f 1);
if [ "$host" != "**" ]; then
break;
elif (($cntr > $maxloop)); then
host='';
break;
fi;
done;
echo "addr=$addr, name=$host";
};
update_host() {
local host ip;
ip="$1";
find_host "$ip";
if [ ! -z "$host" ]; then
cat <<-EOT > $dialup_m4;
LOCAL_CONFIG
#------------------------------------------------------------
#
# Dynamic host/ip updates from $0
#
# NOTE: the following line *MUST* be in /etc/mail/sendmail.mc
dnl include(\`/etc/mail/dialup.m4')dnl
#
# Chose one of the following two options:
# * Add our true hostname as a Virtual Host (we'll accept
# mail for it, but keep our local name for SMTP AUTH, etc)
C{VirtHost}$host
#
# * Define our true hostname (from our ISP) - becomes \$j
dnl define(\`confDOMAIN_NAME', \`$host')dnl
#
# Make sure we accept mail as this name (for bounces, etc)
Cw$host
Cw$ip
# Add our hostname to class G for genericstable support
CG$host
#------------------------------------------------------------
EOT
fi;
};
# No need to continue if we're called with an unsupported option
if [ "$reason" != BOUND ] && [ "$reason" != RENEW ] \
&& [ "$reason" != REBIND ] && [ "$reason" != REBOOT ] \
&& [ "$reason" != EXPIRE ] && [ "$reason" != FAIL ]
then
return;
fi;
# Flag to denote changed have been made;
changed=0;
# If the domain name has changed, update the provider information
if [ "$new_domain_name" != "$old_domain_name" ]; then
changed=1;
update_provider "$new_domain_name";
fi;
# If the ip address has changed, update the host information
if [ "$new_ip_address" != "$oldnew_ip_address" ]; then
changed=1;
update_host "$new_ip_address";
fi;
# If anything has been changed, update sendmail.cf and reload
if [ $changed -eq 1 ]; then
update_sendmail;
fi;
exit 0;
|