diff options
author | pst <pst@FreeBSD.org> | 1994-09-25 02:12:49 +0000 |
---|---|---|
committer | pst <pst@FreeBSD.org> | 1994-09-25 02:12:49 +0000 |
commit | 4f0d0da86d54d2621713e7d8ccfd0507888f348b (patch) | |
tree | a71412a79b4754c5fb0d8868e5fb690fde4a7fbb /lib/libc/net/res_comp.c | |
parent | 860a10b12f94d28edf8ffa8a4df515be3e1d5f29 (diff) | |
download | FreeBSD-src-4f0d0da86d54d2621713e7d8ccfd0507888f348b.zip FreeBSD-src-4f0d0da86d54d2621713e7d8ccfd0507888f348b.tar.gz |
get* rework and new bind code
Diffstat (limited to 'lib/libc/net/res_comp.c')
-rw-r--r-- | lib/libc/net/res_comp.c | 70 |
1 files changed, 48 insertions, 22 deletions
diff --git a/lib/libc/net/res_comp.c b/lib/libc/net/res_comp.c index 66f37ba..1e76535 100644 --- a/lib/libc/net/res_comp.c +++ b/lib/libc/net/res_comp.c @@ -53,16 +53,22 @@ #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93"; -static char rcsid[] = "$Id: res_comp.c,v 4.9.1.1 1993/05/02 22:43:03 vixie Rel $"; +static char rcsid[] = "$Id: res_comp.c,v 4.9.1.11 1994/07/23 23:24:11 vixie Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> -#include <arpa/nameser.h> #include <netinet/in.h> -#include <resolv.h> +#include <arpa/nameser.h> + #include <stdio.h> +#include <resolv.h> +#include <ctype.h> -static int dn_find(); +#include <unistd.h> +#include <string.h> + +static int dn_find __P((u_char *exp_dn, u_char *msg, + u_char **dnptrs, u_char **lastdnptr)); /* * Expand compressed domain name 'comp_dn' to full domain name. @@ -71,23 +77,25 @@ static int dn_find(); * 'exp_dn' is a pointer to a buffer of size 'length' for the result. * Return size of compressed name or -1 if there was an error. */ +int dn_expand(msg, eomorig, comp_dn, exp_dn, length) const u_char *msg, *eomorig, *comp_dn; - u_char *exp_dn; + char *exp_dn; int length; { - register u_char *cp, *dn; + register const u_char *cp; + register char *dn; register int n, c; - u_char *eom; + char *eom; int len = -1, checked = 0; dn = exp_dn; - cp = (u_char *)comp_dn; + cp = comp_dn; eom = exp_dn + length; /* * fetch next label in domain name */ - while (n = *cp++) { + while ((n = *cp++)) { /* * Check for indirection */ @@ -116,7 +124,7 @@ dn_expand(msg, eomorig, comp_dn, exp_dn, length) case INDIR_MASK: if (len < 0) len = cp - comp_dn + 1; - cp = (u_char *)msg + (((n & 0x3f) << 8) | (*cp & 0xff)); + cp = msg + (((n & 0x3f) << 8) | (*cp & 0xff)); if (cp < msg || cp >= eomorig) /* out of range */ return(-1); checked += 2; @@ -134,6 +142,9 @@ dn_expand(msg, eomorig, comp_dn, exp_dn, length) } } *dn = '\0'; + for (dn = exp_dn; (c = *dn) != '\0'; dn++) + if (isascii(c) && isspace(c)) + return (-1); if (len < 0) len = cp - comp_dn; return (len); @@ -151,8 +162,9 @@ dn_expand(msg, eomorig, comp_dn, exp_dn, length) * If 'dnptr' is NULL, we don't try to compress names. If 'lastdnptr' * is NULL, we don't update the list. */ +int dn_comp(exp_dn, comp_dn, length, dnptrs, lastdnptr) - const u_char *exp_dn; + const char *exp_dn; u_char *comp_dn, **dnptrs, **lastdnptr; int length; { @@ -164,6 +176,7 @@ dn_comp(exp_dn, comp_dn, length, dnptrs, lastdnptr) dn = (u_char *)exp_dn; cp = comp_dn; eob = cp + length; + lpp = cpp = NULL; if (dnptrs != NULL) { if ((msg = *dnptrs++) != NULL) { for (cpp = dnptrs; *cpp != NULL; cpp++) @@ -229,31 +242,44 @@ dn_comp(exp_dn, comp_dn, length, dnptrs, lastdnptr) /* * Skip over a compressed domain name. Return the size or -1. */ +int __dn_skipname(comp_dn, eom) const u_char *comp_dn, *eom; { - register u_char *cp; + register const u_char *cp; register int n; - cp = (u_char *)comp_dn; + cp = comp_dn; while (cp < eom && (n = *cp++)) { /* * check for indirection */ switch (n & INDIR_MASK) { - case 0: /* normal case, n == len */ + case 0: /* normal case, n == len */ cp += n; continue; - default: /* illegal type */ - return (-1); case INDIR_MASK: /* indirection */ cp++; + break; + default: /* illegal type */ + return -1; } break; } + if (cp > eom) + return -1; return (cp - comp_dn); } +static int +mklower(ch) + register int ch; +{ + if (isascii(ch) && isupper(ch)) + return (tolower(ch)); + return (ch); +} + /* * Search for expanded name from a list of previously compressed names. * Return the offset from msg if found or -1. @@ -272,7 +298,7 @@ dn_find(exp_dn, msg, dnptrs, lastdnptr) for (cpp = dnptrs; cpp < lastdnptr; cpp++) { dn = exp_dn; sp = cp = *cpp; - while (n = *cp++) { + while ((n = *cp++)) { /* * check for indirection */ @@ -283,7 +309,7 @@ dn_find(exp_dn, msg, dnptrs, lastdnptr) goto next; if (*dn == '\\') dn++; - if (*dn++ != *cp++) + if (mklower(*dn++) != mklower(*cp++)) goto next; } if ((n = *dn++) == '\0' && *cp == '\0') @@ -314,9 +340,9 @@ dn_find(exp_dn, msg, dnptrs, lastdnptr) * used by sendmail. */ -u_short +u_int16_t _getshort(msgp) - register u_char *msgp; + register const u_char *msgp; { register u_int16_t u; @@ -326,7 +352,7 @@ _getshort(msgp) u_int32_t _getlong(msgp) - register u_char *msgp; + register const u_char *msgp; { register u_int32_t u; @@ -336,7 +362,7 @@ _getlong(msgp) void #if defined(__STDC__) || defined(__cplusplus) -__putshort(register u_short s, register u_char *msgp) +__putshort(register u_int16_t s, register u_char *msgp) /* must match proto */ #else __putshort(s, msgp) register u_int16_t s; |