Return to BSD News archive
Newsgroups: comp.bugs.2bsd
Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.mel.connect.com.au!munnari.OZ.AU!uunet!in2.uu.net!newsfeed.internetmci.com!salliemae!europa.chnt.gtegsc.com!wlbr!sms
From: sms@wlv.iipo.gtegsc.com (Steven M. Schultz)
Subject: mkhosts(8) does not handle mixed upper + lower case (#270)
Sender: news@wlbr.iipo.gtegsc.com (System Administrator)
Organization: GTE Government Systems, Thousand Oaks CA USA
Message-ID: <DnMFrD.34s@wlbr.iipo.gtegsc.com>
X-Nntp-Posting-Host: wlv.iipo.gtegsc.com
Date: Sat, 2 Mar 1996 03:45:12 GMT
Lines: 189
Subject: mkhosts(8) does not handle mixed upper + lower case (#270)
Index: etc/mkhosts.c 2.11BSD
Description:
The mkhosts(8) program used to build the dbm hosts file
does not handle upper case characters in hostnames correctly.
Repeat-By:
Have an entry like this:
127.0.0.1 LocalHost.domain
in the /etc/hosts file and run "/etc/mkhosts /etc/hosts". Programs
which use 'gethostbyname(3)' will not be able to find the host
"localhost".
Fix:
Systems which are attached to the Internet should use the
resolver routines to talk to a host running a DNS server. Hosts
which are connected only by uucp (or not connected to the Internet
at all) are likely to use hosts files - this fix will allow those
systems to use mixed case names.
The change to mkhosts was simply to force the 'key' used to write
records into the dbm database files to be lower case. This is
what the gethost*() do when looking up hostnames. The 'content'
of each record written is left exactly as given in /etc/hosts.
Cut where indicated and save to a file (/tmp/270). Then
patch -p0 < /tmp/270
If you are not using host files then you need not (in fact you can
not) recompile mkhosts. If you are using host files then:
cd /usr/src/etc
make mkhosts
install -s -m 755 mkhosts /etc/mkhosts
/etc/mkhosts /etc/hosts
NOTE: The location of the 2.11BSD patch archive has moved from its
old home of 192.26.147.1 (wlv.iipo.gtegsc.com) to a new
system FTP.IIPO.GTEGSC.COM (199.107.240.66). All 2.11
updates are still located in /pub/2.11BSD.
========================cut here===================
*** /usr/src/etc/mkhosts.c.old Thu Oct 5 14:17:40 1989
--- /usr/src/etc/mkhosts.c Fri Aug 18 21:00:16 1995
***************
*** 4,25 ****
* specifies the terms and conditions for redistribution.
*/
! #ifndef lint
char copyright[] =
"@(#) Copyright (c) 1980 Regents of the University of California.\n\
All rights reserved.\n";
- #endif not lint
- #ifndef lint
/* static char sccsid[] = "@(#)mkhosts.c 5.1 (Berkeley) 5/28/85"; */
! static char sccsid[] = "@(#)mkhosts.c 1.1 (2.10BSD) 10/04/89";
! #endif not lint
#include <sys/file.h>
#include <stdio.h>
#include <netdb.h>
#include <ndbm.h>
char buf[BUFSIZ];
main(argc, argv)
--- 4,26 ----
* specifies the terms and conditions for redistribution.
*/
! #if !defined(lint) && defined(DOSCCS)
char copyright[] =
"@(#) Copyright (c) 1980 Regents of the University of California.\n\
All rights reserved.\n";
/* static char sccsid[] = "@(#)mkhosts.c 5.1 (Berkeley) 5/28/85"; */
! static char sccsid[] = "@(#)mkhosts.c 1.2 (2.11BSD) 1995/08/17";
! #endif
+ #include <ctype.h>
+ #include <sys/param.h>
#include <sys/file.h>
#include <stdio.h>
#include <netdb.h>
#include <ndbm.h>
+ void keylower();
char buf[BUFSIZ];
main(argc, argv)
***************
*** 34,39 ****
--- 35,41 ----
int naliases, naddrs;
int verbose = 0, entries = 0, maxlen = 0, error = 0;
char tempname[BUFSIZ], newname[BUFSIZ];
+ char lowname[MAXHOSTNAMELEN + 1];
if (argc > 1 && strcmp(argv[1], "-v") == 0) {
verbose++;
***************
*** 65,72 ****
;
nap = (int *)cp;
cp += sizeof (int);
! key.dptr = hp->h_name;
! key.dsize = strlen(hp->h_name);
hp2 = (struct hostent *)fetchhost(dp, key);
if (hp2) {
merge(hp, hp2);
--- 67,80 ----
;
nap = (int *)cp;
cp += sizeof (int);
!
! keylower(lowname, hp->h_name);
! key.dptr = lowname;
! key.dsize = strlen(lowname);
! /*
! key.dptr = hp->h_name;
! key.dsize = strlen(hp->h_name);
! */
hp2 = (struct hostent *)fetchhost(dp, key);
if (hp2) {
merge(hp, hp2);
***************
*** 98,105 ****
goto err;
}
for (sp = hp->h_aliases; *sp; sp++) {
! key.dptr = *sp;
! key.dsize = strlen(*sp);
if (dbm_store(dp, key, content, DBM_REPLACE) < 0) {
perror(*sp);
goto err;
--- 106,118 ----
goto err;
}
for (sp = hp->h_aliases; *sp; sp++) {
! keylower(lowname, *sp);
! key.dptr = lowname;
! key.dsize = strlen(lowname);
! /*
! key.dptr = *sp;
! key.dsize = strlen(*sp);
! */
if (dbm_store(dp, key, content, DBM_REPLACE) < 0) {
perror(*sp);
goto err;
***************
*** 231,233 ****
--- 244,261 ----
}
}
}
+
+ void
+ keylower(out, in)
+ register char *out, *in;
+ {
+
+ while (*in)
+ {
+ if (isupper(*in))
+ *out++ = tolower(*in++);
+ else
+ *out++ = *in++;
+ }
+ *out++ = '\0';
+ }
*** /VERSION.old Mon Jul 24 20:28:31 1995
--- /VERSION Sat Aug 12 00:13:20 1995
***************
*** 1,4 ****
! Current Patch Level: 269
2.11 BSD
============
--- 1,4 ----
! Current Patch Level: 270
2.11 BSD
============