Mailing List Archive

Configure patch to bad extraction of domain from /etc/hosts
> I haven't had a chance to trace this down exactly, but when Configure tries
> to figure out hostname and domain, it gets some wierd results.

Try the appended patch.


Whoever made the module to figure out host/domain, please tell:
* Why was not `ypmatch' tried before `ypcat'? I've added it.
* Is there an `ypmatch' equivalent for `nidump hosts .' ?
I don't know the `nidump' format either, but I've assumed it's the
same as in /etc/hosts or `ypcat hosts`.
* Any reason why you used
egrep '^domain' | $sed 's/domain../.../'
instead of plain
$sed -n 's/^domain.../.../p'
? I removed it.


Problem:

The Configure fragment below fails when the *end* of the initial part of
a hostname matches $myhostname, or if more than one host matches
$myhostname, or if the hostname appears several times with different
domains on the same line, or if $myhostname appears in a comment.

$hostcat >hosts
dflt=.`$awk "/[0-9].*$myhostname/ {for(i=2; i<=NF;i++) print \\\$i}" \
hosts | $sort | $uniq | \
$sed -n -e "s/$myhostname\.\([a-zA-Z_.]\)/\1/p"`
case "$dflt" in
.) echo "(You do not have fully-qualified names in /etc/hosts)"

For example, try the fragment above on this 'hosts' file (ypcat format)
with myhostname=wups:

1.2.3.4 wups wups.ac wups.uk # wups.uk--a strange host
5.6.7.8 foreign-wups.no # just to be nasty

Result:

dflt=".foreign-no
ac
uk
uk--"


Regards,

Hallvard


--- perl5.002beta1/Configure~ Mon Nov 20 16:00:33 1995
+++ perl5.002beta1/Configure Thu Nov 23 12:21:06 1995
@@ -6697,14 +6697,37 @@
*) case "$mydomain" in
'')
- $hostcat >hosts
- dflt=.`$awk "/[0-9].*$myhostname/ {for(i=2; i<=NF;i++) print \\\$i}" \
+ {
+ : If we use NIS, try ypmatch.
+ : Is there some reason why this was not done before?
+ test "X$hostcat" = "Xypcat hosts" &&
+ ypmatch "$myhostname" hosts 2>/dev/null |\
+ $sed -e 's/$/ /' > hosts &&
+ $test -s hosts
+ } || {
+ : Extract only the relevant hosts, reducing file size,
+ : remove comments, insert trailing space for later use.
+ $hostcat | $sed -n -e "s/[ ]*#.*//; s/\$/ /
+ /[ ]$myhostname[ . ]/p" > hosts
+ }
+ tmp_re="[ . ]"
+ $test x`$awk "/[0-9].*[ ]$myhostname$tmp_re/ { sum++ }
+ END { print sum }" hosts` = x1 || tmp_re="[ ]"
+ dflt=.`$awk "/[0-9].*[ ]$myhostname$tmp_re/ {for(i=2; i<=NF;i++) print \\\$i}" \
hosts | $sort | $uniq | \
$sed -n -e "s/$myhostname\.\([a-zA-Z_.]\)/\1/p"`
- case "$dflt" in
+ case `$echo X$dflt` in
+ X*\ *) echo "(Several hosts in /etc/hosts matched hostname)"
+ dflt=.
+ ;;
.) echo "(You do not have fully-qualified names in /etc/hosts)"
+ ;;
+ esac
+ case "$dflt" in
+ .)
tans=`./loc resolv.conf X /etc /usr/etc`
if $test -f "$tans"; then
echo "(Attempting domain name extraction from $tans)"
- dflt=.`egrep '^domain' $tans | $sed 's/domain[ ]*\(.*\)/\1/' \
+ : Why was there an Egrep here, when Sed works?
+ dflt=.`$sed -n -e 's/^domain[ ]*\(.*\)/\1/p' $tans \
| ./tr '[A-Z]' '[a-z]' 2>/dev/null`
fi
Re: Configure patch to bad extraction of domain from /etc/hosts [ In reply to ]
>: I don't know the `nidump' format either, but I've assumed it's the
>: same as in /etc/hosts or `ypcat hosts`.
>
>I have no idea. That bit was contributed by Graham Stoney (the author
>of the famous c2man).

That is part of the command line interface to NetInfo, not part of the
Sun specific Yellow Pages / NIS at all. Although I think there is
a version of it for Sun's at this point. Don't use them anymore myself.
Re: Configure patch to bad extraction of domain from /etc/hosts [ In reply to ]
Quoting Hallvard B Furuseth:
:Whoever made the module to figure out host/domain, please tell:
: * Why was not `ypmatch' tried before `ypcat'? I've added it.

Well, because I probably did not know about ypmatch by then (1991).
I don't remember really... ypcat was working on my machine, that's
probably the reason why I did not try something else.

: * Is there an `ypmatch' equivalent for `nidump hosts .' ?
: I don't know the `nidump' format either, but I've assumed it's the
: same as in /etc/hosts or `ypcat hosts`.

I have no idea. That bit was contributed by Graham Stoney (the author
of the famous c2man).

: * Any reason why you used
: egrep '^domain' | $sed 's/domain../.../'
: instead of plain
: $sed -n 's/^domain.../.../p'
: ? I removed it.

I don't remember who contributed that bit, offhand. Sorry.

:The Configure fragment below fails when the *end* of the initial part of
:a hostname matches $myhostname, or if more than one host matches
:$myhostname, or if the hostname appears several times with different
:domains on the same line, or if $myhostname appears in a comment.

Although in this case it does not matter much, patching Configure is
no good. You have to patch the corresponding metaconfig unit(s) since
Configure is automatically generated.

I'll have to see how well your changes fit in the myhostname.U unit
and will integrate as much as I can. Thank you!

Raphael
Re: Configure patch to bad extraction of domain from /etc/hosts [ In reply to ]
A little patch to the patch: Some hostnames contain numbers or hyphens.
Also, I don't really know that output from `ypmatch ... hosts' always is
without comments. `ypmatch ... hosts.byaddr' does output comments at
our site.

--- Configure~ Thu Nov 23 12:21:06 1995
+++ Configure Sat Nov 25 10:46:22 1995
@@ -6703,3 +6702,3 @@
ypmatch "$myhostname" hosts 2>/dev/null |\
- $sed -e 's/$/ /' > hosts &&
+ $sed -e 's/[ ]*#.*//; s/$/ /' > hosts && \
$test -s hosts
@@ -6716,3 +6715,3 @@
hosts | $sort | $uniq | \
- $sed -n -e "s/$myhostname\.\([a-zA-Z_.]\)/\1/p"`
+ $sed -n -e "s/$myhostname\.\([-a-zA-Z0-9_.]\)/\1/p"`
case `$echo X$dflt` in


Regards,

Hallvard