summaryrefslogtreecommitdiff
path: root/debian/examples/dhcp/dhclient-exit-hooks.d
diff options
context:
space:
mode:
authorRichard A Nelson (Rick) <cowboy@debian.org>2010-11-03 22:05:00 +0000
committerAndreas Beckmann <debian@abeckmann.de>2012-10-01 20:07:50 +0200
commitcb1b9d89c5278ac97b3fee2d39f9219bbda5180f (patch)
tree6a88bbe1d2b1f10e0763a6992ace4d6c4bc05da6 /debian/examples/dhcp/dhclient-exit-hooks.d
parente253e5b372f6123431d41466fc6e33e357d98b57 (diff)
downloadsendmail-debian/8.14.4-2.tar.gz
Imported Debian patch 8.14.4-2debian/8.14.4-2
Diffstat (limited to 'debian/examples/dhcp/dhclient-exit-hooks.d')
-rw-r--r--debian/examples/dhcp/dhclient-exit-hooks.d/sendmail49
-rw-r--r--debian/examples/dhcp/dhclient-exit-hooks.d/sendmail.1.old158
-rw-r--r--debian/examples/dhcp/dhclient-exit-hooks.d/sendmail.in49
-rw-r--r--debian/examples/dhcp/dhclient-exit-hooks.d/sendmail.md5sum1
4 files changed, 257 insertions, 0 deletions
diff --git a/debian/examples/dhcp/dhclient-exit-hooks.d/sendmail b/debian/examples/dhcp/dhclient-exit-hooks.d/sendmail
new file mode 100644
index 0000000..7135a80
--- /dev/null
+++ b/debian/examples/dhcp/dhclient-exit-hooks.d/sendmail
@@ -0,0 +1,49 @@
+#!/bin/sh
+#
+# This script is called when a dhcp event occurs.
+#
+# Here is where we'll start/stop sendmail if needed.
+#
+# 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.
+#
+
+# No need to continue if we're called with an unsupported option
+case "$reason" in
+ EXPIRE|FAIL|RELEASE|STOP) #down... and TIMEOUT too ???
+ ;;
+ BOUND|RENEW|REBIND|REBOOT|TIMEOUT) #up... why TIMEOUT here ???
+ ;;
+ *)
+ return;
+ ;;
+ esac;
+
+# Bring in some script functions to handle dynamic configuration
+. /usr/share/sendmail/dynamic;
+
+# Note the interface that just changed
+update_interface "$interface" "$reason";
+
+# If the domain name has changed, update the provider information
+if [ "$new_domain_name" != "$old_domain_name" ]; then
+ update_provider "$new_domain_name";
+ fi;
+
+# If the ip address has changed, update the host information
+if [ "$new_ip_address" != "$oldnew_ip_address" ]; then
+ update_host "$new_ip_address";
+ fi;
+
+# If anything has been changed, update sendmail.cf and reload
+# Actually, we'll delay the reload because we'll be hit in a moment
+# to handle the change by /etc/network/if-up.d/sendmail
+update_sendmail "dhcp" Delayed;
+
+return;
+
diff --git a/debian/examples/dhcp/dhclient-exit-hooks.d/sendmail.1.old b/debian/examples/dhcp/dhclient-exit-hooks.d/sendmail.1.old
new file mode 100644
index 0000000..ba6b98c
--- /dev/null
+++ b/debian/examples/dhcp/dhclient-exit-hooks.d/sendmail.1.old
@@ -0,0 +1,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;
+
diff --git a/debian/examples/dhcp/dhclient-exit-hooks.d/sendmail.in b/debian/examples/dhcp/dhclient-exit-hooks.d/sendmail.in
new file mode 100644
index 0000000..c517033
--- /dev/null
+++ b/debian/examples/dhcp/dhclient-exit-hooks.d/sendmail.in
@@ -0,0 +1,49 @@
+#!/bin/sh
+#
+# This script is called when a dhcp event occurs.
+#
+# Here is where we'll start/stop sendmail if needed.
+#
+# 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.
+#
+
+# No need to continue if we're called with an unsupported option
+case "$reason" in
+ EXPIRE|FAIL|RELEASE|STOP) #down... and TIMEOUT too ???
+ ;;
+ BOUND|RENEW|REBIND|REBOOT|TIMEOUT) #up... why TIMEOUT here ???
+ ;;
+ *)
+ return;
+ ;;
+ esac;
+
+# Bring in some script functions to handle dynamic configuration
+. @datadir@/sendmail/dynamic;
+
+# Note the interface that just changed
+update_interface "$interface" "$reason";
+
+# If the domain name has changed, update the provider information
+if [ "$new_domain_name" != "$old_domain_name" ]; then
+ update_provider "$new_domain_name";
+ fi;
+
+# If the ip address has changed, update the host information
+if [ "$new_ip_address" != "$oldnew_ip_address" ]; then
+ update_host "$new_ip_address";
+ fi;
+
+# If anything has been changed, update sendmail.cf and reload
+# Actually, we'll delay the reload because we'll be hit in a moment
+# to handle the change by /etc/network/if-up.d/sendmail
+update_sendmail "dhcp" Delayed;
+
+return;
+
diff --git a/debian/examples/dhcp/dhclient-exit-hooks.d/sendmail.md5sum b/debian/examples/dhcp/dhclient-exit-hooks.d/sendmail.md5sum
new file mode 100644
index 0000000..d18e257
--- /dev/null
+++ b/debian/examples/dhcp/dhclient-exit-hooks.d/sendmail.md5sum
@@ -0,0 +1 @@
+2adc5e32474fb128ee6c7b4425d06a58 sendmail