author | John Beck <John.Beck@Oracle.COM> |
Wed, 26 Apr 2017 16:46:20 -0700 | |
changeset 7951 | 3b581304cb26 |
parent 3649 | 4006eaaa7d29 |
permissions | -rw-r--r-- |
3649
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
1 |
#!/bin/sh -- |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
2 |
# |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
3 |
# CDDL HEADER START |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
4 |
# |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
5 |
# The contents of this file are subject to the terms of the |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
6 |
# Common Development and Distribution License (the "License"). |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
7 |
# You may not use this file except in compliance with the License. |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
8 |
# |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
9 |
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
10 |
# or http://www.opensolaris.org/os/licensing. |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
11 |
# See the License for the specific language governing permissions |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
12 |
# and limitations under the License. |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
13 |
# |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
14 |
# When distributing Covered Code, include this CDDL HEADER in each |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
15 |
# file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
16 |
# If applicable, add the following below this CDDL HEADER, with the |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
17 |
# fields enclosed by brackets "[]" replaced with your own identifying |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
18 |
# information: Portions Copyright [yyyy] [name of copyright owner] |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
19 |
# |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
20 |
# CDDL HEADER END |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
21 |
# |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
22 |
|
7951
3b581304cb26
25960002 check-hostname should exit 1 when unhappy
John Beck <John.Beck@Oracle.COM>
parents:
3649
diff
changeset
|
23 |
# |
3649
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
24 |
# Check hostname configuration as per the sendmail code. |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
25 |
# |
7951
3b581304cb26
25960002 check-hostname should exit 1 when unhappy
John Beck <John.Beck@Oracle.COM>
parents:
3649
diff
changeset
|
26 |
|
3649
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
27 |
# |
7951
3b581304cb26
25960002 check-hostname should exit 1 when unhappy
John Beck <John.Beck@Oracle.COM>
parents:
3649
diff
changeset
|
28 |
# Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved. |
3649
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
29 |
# |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
30 |
|
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
31 |
PATH=/bin:/usr/sbin |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
32 |
|
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
33 |
# If $1 has a ".", accept it and exit. |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
34 |
|
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
35 |
accept_if_fully_qualified() { |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
36 |
case $1 in |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
37 |
*.*) |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
38 |
echo "Hostname $myhostname OK: fully qualified as $1" |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
39 |
exit 0 |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
40 |
;; |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
41 |
esac |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
42 |
} |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
43 |
|
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
44 |
# Check the `getent hosts $1` output, skipping the 1st entry (IP address). |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
45 |
|
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
46 |
check_gethostbyname() { |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
47 |
for host in `getent hosts $1 | awk '{for (f=2; f <= NF; f++) print $f}'` |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
48 |
do |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
49 |
accept_if_fully_qualified $host |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
50 |
done |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
51 |
} |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
52 |
|
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
53 |
# Parse /etc/hosts, looking for $1 as an entry by itself, and try to find |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
54 |
# a long name on the same line. First kill all comments, then check for |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
55 |
# $1 as a word by itself, then take just the first such line, then skip |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
56 |
# its first entry (IP address). |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
57 |
|
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
58 |
check_hosts_file() { |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
59 |
for entry in `sed -e 's/#.*$//' /etc/hosts | \ |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
60 |
awk '/[ ]'$1'([ ]|$)/ \ |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
61 |
{for (f=2; f <= NF; f++) print $f; exit}'` |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
62 |
do |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
63 |
accept_if_fully_qualified $entry |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
64 |
done |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
65 |
} |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
66 |
|
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
67 |
# Parse the output of `nslookup $1`, checking the Name and Aliases. |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
68 |
|
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
69 |
check_dns() { |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
70 |
for host in `nslookup $1 2>/dev/null | \ |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
71 |
awk '$1 == "Name:" || $1 == "Aliases:"{print $2}'` |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
72 |
do |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
73 |
accept_if_fully_qualified $host |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
74 |
done |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
75 |
} |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
76 |
|
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
77 |
# Check the `ypmatch $1 hosts` output, skipping the 1st entry (IP address). |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
78 |
|
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
79 |
check_nis() { |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
80 |
for hst in `ypmatch $1 hosts | awk '{for (f=2; f <= NF; f++) print $f}'` |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
81 |
do |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
82 |
accept_if_fully_qualified $hst |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
83 |
done |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
84 |
} |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
85 |
|
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
86 |
# Recommend how to reconfigure to get $1.$2 as the FQHN. |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
87 |
# $3 is the first entry for hosts in /etc/nsswitch.conf . |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
88 |
|
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
89 |
suggest_fix_and_exit() { |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
90 |
myhost=$1 |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
91 |
suggested_domain=$2 |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
92 |
fhe=$3 |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
93 |
myipaddr=`getent hosts $myhost | head -1 | awk '{print $1}'` |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
94 |
|
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
95 |
# aliases: skip the 1st & 2nd entries: IP address & canonical name |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
96 |
|
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
97 |
set -- '' '' '[ aliases ... ]' |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
98 |
set -- `grep "^$myipaddr[ ]" /etc/hosts 2>/dev/null` |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
99 |
result=$? |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
100 |
shift 2 |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
101 |
echo "We recommend \c" |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
102 |
if [ "x$fhe" != "xfiles" ] ; then |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
103 |
echo "listing files first for hosts in /etc/nsswitch.conf" |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
104 |
echo "and then \c" |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
105 |
fi |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
106 |
if [ $result = 0 ] ; then |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
107 |
echo "changing the /etc/hosts entry:\n" |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
108 |
echo "$myipaddr $myhost $*\n" |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
109 |
echo "to:\n" |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
110 |
else |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
111 |
echo "adding the /etc/hosts entry:\n" |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
112 |
fi |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
113 |
echo "$myipaddr $myhost $myhost.$suggested_domain $*" |
7951
3b581304cb26
25960002 check-hostname should exit 1 when unhappy
John Beck <John.Beck@Oracle.COM>
parents:
3649
diff
changeset
|
114 |
exit 1 |
3649
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
115 |
} |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
116 |
|
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
117 |
# Fall back to the NIS domain, minus the first label. If it is non-null, |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
118 |
# use it but recommend against it. $2 is just informative, indicating whether |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
119 |
# we're checking the NIS domain. $3 is to pass on. |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
120 |
|
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
121 |
check_nis_domain() { |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
122 |
nisdomain=`domainname` |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
123 |
realdomain=`echo $nisdomain | sed 's/[^.]*\.//'` |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
124 |
if [ "x$realdomain" != "x" ] ; then |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
125 |
echo "Hostname $1 can be fully qualified using NIS$2 domain" |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
126 |
echo " $nisdomain" |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
127 |
echo "resulting in the name" |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
128 |
echo " $1.$realdomain" |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
129 |
echo "but this is bad practice.\n" |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
130 |
suggest_fix_and_exit $1 $realdomain $3 |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
131 |
fi |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
132 |
} |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
133 |
|
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
134 |
# Goal: try to fully qualify `hostname` as sendmail would. |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
135 |
# Algorithm (stop as soon as a name with a dot is found): |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
136 |
# 1. gethostbyname (simulate with getent hosts) |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
137 |
# 2. fall back to individual hosts: methods in nsswitch.conf, using |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
138 |
# only those that are configured, in their configured order |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
139 |
# * files (parse /etc/hosts directly) |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
140 |
# * dns (parse nslookup output) |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
141 |
# * nis (parse ypmatch output) |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
142 |
# 3. fall back to the NIS domain name. |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
143 |
# If none of the above succeed, give up. Recommend: |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
144 |
# a. the domain entry in /etc/resolv.conf, if one exists |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
145 |
# b. "pick.some.domain" |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
146 |
|
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
147 |
myhostname=`hostname` |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
148 |
|
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
149 |
check_gethostbyname $myhostname |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
150 |
|
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
151 |
hosts_line=`sed -n -e 's/^hosts:\([^#]*\).*/\1/p' /etc/nsswitch.conf` |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
152 |
first_hosts_entry=`echo $hosts_line | awk '{print $1}'` |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
153 |
nis_domains="" |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
154 |
|
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
155 |
for entry in $hosts_line |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
156 |
do |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
157 |
case $entry in |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
158 |
files) |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
159 |
check_hosts_file $myhostname |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
160 |
;; |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
161 |
dns) |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
162 |
check_dns $myhostname |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
163 |
;; |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
164 |
nis) |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
165 |
check_nis $myhostname |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
166 |
nis_domains="$nis_domains nis" |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
167 |
;; |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
168 |
esac |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
169 |
done |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
170 |
|
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
171 |
for entry in $nis_domains |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
172 |
do |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
173 |
case $entry in |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
174 |
nis) |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
175 |
check_nis_domain $myhostname "" $first_hosts_entry |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
176 |
;; |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
177 |
esac |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
178 |
done |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
179 |
|
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
180 |
realdomain=`awk '$1 ~ /^domain/ {print $2}' 2>/dev/null < /etc/resolv.conf` |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
181 |
case $realdomain in |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
182 |
*.*) |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
183 |
# OK |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
184 |
;; |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
185 |
*) |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
186 |
realdomain="pick.some.domain" |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
187 |
;; |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
188 |
esac |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
189 |
|
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
190 |
echo "Hostname $myhostname could not be fully qualified." |
4006eaaa7d29
20355401 add sendmail to Userland
John Beck <John.Beck@Oracle.COM>
parents:
diff
changeset
|
191 |
suggest_fix_and_exit $myhostname $realdomain $first_hosts_entry |