diff options
author | brian <brian@FreeBSD.org> | 1999-04-09 01:54:10 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 1999-04-09 01:54:10 +0000 |
commit | 040921481a09e7431faf10969c11dfce638fbeda (patch) | |
tree | c41d7b9736ccd4da3835e9e0bb68c307bd702820 /lib/libutil/logwtmp.c | |
parent | 2dbfcc3870c83de97f28288eb29f4274983dcd28 (diff) | |
download | FreeBSD-src-040921481a09e7431faf10969c11dfce638fbeda.zip FreeBSD-src-040921481a09e7431faf10969c11dfce638fbeda.tar.gz |
If given host.domain:nn[.nn], trimdomain() now reduces it to
host:nn[.nn] (if the domain is the same as the local one).
Diffstat (limited to 'lib/libutil/logwtmp.c')
-rw-r--r-- | lib/libutil/logwtmp.c | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/lib/libutil/logwtmp.c b/lib/libutil/logwtmp.c index a3cd87e..ad9a86e 100644 --- a/lib/libutil/logwtmp.c +++ b/lib/libutil/logwtmp.c @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 6/4/93"; #else static const char rcsid[] = - "$Id: logwtmp.c,v 1.10 1999/04/07 14:03:31 brian Exp $"; + "$Id: logwtmp.c,v 1.11 1999/04/08 08:00:06 brian Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -59,7 +59,9 @@ trimdomain(char *fullhost, int hostsize) { static char domain[MAXHOSTNAMELEN]; static int first = 1; - char *s; + static size_t dlen; + char *s, *end; + int spn, ok; if (first) { first = 0; @@ -68,17 +70,39 @@ trimdomain(char *fullhost, int hostsize) memmove(domain, s + 1, strlen(s + 1) + 1); else domain[0] = '\0'; + dlen = strlen(domain); } if (domain[0] != '\0') { s = fullhost; - while ((fullhost = strchr(fullhost, '.')) != NULL) - if (!strcasecmp(fullhost + 1, domain)) { - if (fullhost - s <= hostsize) - *fullhost = '\0'; /* hit it and acceptable size*/ - break; - } else - fullhost++; + end = s + hostsize + 1; + for (; (s = memchr(s, '.', end - s)) != NULL; s++) + if (!strncasecmp(s + 1, domain, dlen)) { + if (s[dlen + 1] == '\0') { + *s = '\0'; /* Found - lose the domain */ + break; + } else if (s[dlen + 1] == ':') { /* $DISPLAY ? */ + ok = dlen + 2; + spn = strspn(s + ok, "0123456789"); + if (spn > 0 && ok + spn - dlen <= end - s) { + ok += spn; + if (s[ok] == '\0') { + /* host.domain:nn */ + memmove(s, s + dlen + 1, ok - dlen); + break; + } else if (s[ok] == '.') { + ok++; + spn = strspn(s + ok, "0123456789"); + if (spn > 0 && s[ok + spn] == '\0' && + ok + spn - dlen <= end - s) { + /* host.domain:nn.nn */ + memmove(s, s + dlen + 1, ok + spn - dlen); + break; + } + } + } + } + } } } |