#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
# Check hostname configuration as per the sendmail code.
#
# See http://www.sendmail.org/sun-specific/migration.html#FQHN for details.
#
# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# If $1 has a ".", accept it and exit.
case $1 in
*.*)
echo "Hostname $myhostname OK: fully qualified as $1"
exit 0
;;
esac
}
# Check the `getent hosts $1` output, skipping the 1st entry (IP address).
do
done
}
# a long name on the same line. First kill all comments, then check for
# $1 as a word by itself, then take just the first such line, then skip
# its first entry (IP address).
{for (f=2; f <= NF; f++) print $f; exit}'`
do
done
}
# Parse the output of `nslookup $1`, checking the Name and Aliases.
do
done
}
# Check the `ypmatch $1 hosts` output, skipping the 1st entry (IP address).
do
done
}
# Recommend how to reconfigure to get $1.$2 as the FQHN.
# $3 is the first entry for hosts in /etc/nsswitch.conf .
myhost=$1
fhe=$3
# aliases: skip the 1st & 2nd entries: IP address & canonical name
set -- '' '' '[ aliases ... ]'
result=$?
shift 2
echo "We recommend \c"
echo "listing files first for hosts in /etc/nsswitch.conf"
echo "and then \c"
fi
if [ $result = 0 ] ; then
echo "to:\n"
else
fi
echo "$myipaddr $myhost $myhost.$suggested_domain $*"
exit 0
}
# Fall back to the NIS domain, minus the first label. If it is non-null,
# use it but recommend against it. $2 is just informative, indicating whether
# we're checking the NIS domain. $3 is to pass on.
echo "Hostname $1 can be fully qualified using NIS$2 domain"
echo " $nisdomain"
echo "resulting in the name"
echo " $1.$realdomain"
echo "but this is bad practice.\n"
fi
}
# Goal: try to fully qualify `hostname` as sendmail would.
# Algorithm (stop as soon as a name with a dot is found):
# 1. gethostbyname (simulate with getent hosts)
# 2. fall back to individual hosts: methods in nsswitch.conf, using
# only those that are configured, in their configured order
# * dns (parse nslookup output)
# * nis (parse ypmatch output)
# 3. fall back to the NIS domain name.
# If none of the above succeed, give up. Recommend:
# a. the domain entry in /etc/resolv.conf, if one exists
# b. "pick.some.domain"
nis_domains=""
do
;;
dns)
;;
nis)
nis_domains="$nis_domains nis"
;;
esac
done
do
nis)
;;
esac
done
case $realdomain in
*.*)
# OK
;;
*)
;;
esac
echo "Hostname $myhostname could not be fully qualified."