diff options
| author | downsj <> | 1997-03-13 19:07:41 +0000 |
|---|---|---|
| committer | downsj <> | 1997-03-13 19:07:41 +0000 |
| commit | 05882f672fb3bf8797e68cc2d68f8406e1cb7b07 (patch) | |
| tree | f9cdfe48f1a2f821eb8d11d33976f3f19cd834db /src/lib/libc/net/res_comp.c | |
| parent | b0e0ca363d82adf8768f67857659b9590e0e6954 (diff) | |
| download | openbsd-05882f672fb3bf8797e68cc2d68f8406e1cb7b07.tar.gz openbsd-05882f672fb3bf8797e68cc2d68f8406e1cb7b07.tar.bz2 openbsd-05882f672fb3bf8797e68cc2d68f8406e1cb7b07.zip | |
Integrate BIND 4.9.5 resolver and associated routines.
Includes the DNS aware getnetby*() routines and IPv6 support.
Diffstat (limited to 'src/lib/libc/net/res_comp.c')
| -rw-r--r-- | src/lib/libc/net/res_comp.c | 174 |
1 files changed, 152 insertions, 22 deletions
diff --git a/src/lib/libc/net/res_comp.c b/src/lib/libc/net/res_comp.c index f64a81d7ce..2e98003b85 100644 --- a/src/lib/libc/net/res_comp.c +++ b/src/lib/libc/net/res_comp.c | |||
| @@ -1,7 +1,11 @@ | |||
| 1 | /*- | 1 | /* $OpenBSD: res_comp.c,v 1.4 1997/03/13 19:07:35 downsj Exp $ */ |
| 2 | |||
| 3 | /* | ||
| 4 | * ++Copyright++ 1985, 1993 | ||
| 5 | * - | ||
| 2 | * Copyright (c) 1985, 1993 | 6 | * Copyright (c) 1985, 1993 |
| 3 | * The Regents of the University of California. All rights reserved. | 7 | * The Regents of the University of California. All rights reserved. |
| 4 | * | 8 | * |
| 5 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions |
| 7 | * are met: | 11 | * are met: |
| @@ -12,12 +16,12 @@ | |||
| 12 | * documentation and/or other materials provided with the distribution. | 16 | * documentation and/or other materials provided with the distribution. |
| 13 | * 3. All advertising materials mentioning features or use of this software | 17 | * 3. All advertising materials mentioning features or use of this software |
| 14 | * must display the following acknowledgement: | 18 | * must display the following acknowledgement: |
| 15 | * This product includes software developed by the University of | 19 | * This product includes software developed by the University of |
| 16 | * California, Berkeley and its contributors. | 20 | * California, Berkeley and its contributors. |
| 17 | * 4. Neither the name of the University nor the names of its contributors | 21 | * 4. Neither the name of the University nor the names of its contributors |
| 18 | * may be used to endorse or promote products derived from this software | 22 | * may be used to endorse or promote products derived from this software |
| 19 | * without specific prior written permission. | 23 | * without specific prior written permission. |
| 20 | * | 24 | * |
| 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 25 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| @@ -52,19 +56,28 @@ | |||
| 52 | */ | 56 | */ |
| 53 | 57 | ||
| 54 | #if defined(LIBC_SCCS) && !defined(lint) | 58 | #if defined(LIBC_SCCS) && !defined(lint) |
| 55 | static char rcsid[] = "$OpenBSD: res_comp.c,v 1.3 1996/08/19 08:29:42 tholo Exp $"; | 59 | #if 0 |
| 60 | static char sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93"; | ||
| 61 | static char rcsid[] = "$From: res_comp.c,v 8.11 1996/12/02 09:17:22 vixie Exp $"; | ||
| 62 | #else | ||
| 63 | static char rcsid[] = "$OpenBSD: res_comp.c,v 1.4 1997/03/13 19:07:35 downsj Exp $"; | ||
| 64 | #endif | ||
| 56 | #endif /* LIBC_SCCS and not lint */ | 65 | #endif /* LIBC_SCCS and not lint */ |
| 57 | 66 | ||
| 67 | #include <sys/types.h> | ||
| 58 | #include <sys/param.h> | 68 | #include <sys/param.h> |
| 59 | #include <arpa/nameser.h> | ||
| 60 | #include <netinet/in.h> | 69 | #include <netinet/in.h> |
| 61 | #include <resolv.h> | 70 | #include <arpa/nameser.h> |
| 71 | |||
| 62 | #include <stdio.h> | 72 | #include <stdio.h> |
| 73 | #include <resolv.h> | ||
| 63 | #include <ctype.h> | 74 | #include <ctype.h> |
| 75 | |||
| 64 | #include <unistd.h> | 76 | #include <unistd.h> |
| 65 | #include <string.h> | 77 | #include <string.h> |
| 66 | 78 | ||
| 67 | static int dn_find __P((u_char *, u_char *, u_char **, u_char **)); | 79 | static int dn_find __P((u_char *exp_dn, u_char *msg, |
| 80 | u_char **dnptrs, u_char **lastdnptr)); | ||
| 68 | 81 | ||
| 69 | /* | 82 | /* |
| 70 | * Expand compressed domain name 'comp_dn' to full domain name. | 83 | * Expand compressed domain name 'comp_dn' to full domain name. |
| @@ -106,7 +119,7 @@ dn_expand(msg, eomorig, comp_dn, exp_dn, length) | |||
| 106 | return (-1); | 119 | return (-1); |
| 107 | checked += n + 1; | 120 | checked += n + 1; |
| 108 | while (--n >= 0) { | 121 | while (--n >= 0) { |
| 109 | if ((c = *cp++) == '.' || c == '\\') { | 122 | if (((c = *cp++) == '.') || (c == '\\')) { |
| 110 | if (dn + n + 2 >= eom) | 123 | if (dn + n + 2 >= eom) |
| 111 | return (-1); | 124 | return (-1); |
| 112 | *dn++ = '\\'; | 125 | *dn++ = '\\'; |
| @@ -138,9 +151,6 @@ dn_expand(msg, eomorig, comp_dn, exp_dn, length) | |||
| 138 | } | 151 | } |
| 139 | } | 152 | } |
| 140 | *dn = '\0'; | 153 | *dn = '\0'; |
| 141 | for (dn = exp_dn; (c = *dn) != '\0'; dn++) | ||
| 142 | if (isascii(c) && isspace(c)) | ||
| 143 | return (-1); | ||
| 144 | if (len < 0) | 154 | if (len < 0) |
| 145 | len = cp - comp_dn; | 155 | len = cp - comp_dn; |
| 146 | return (len); | 156 | return (len); |
| @@ -263,7 +273,7 @@ __dn_skipname(comp_dn, eom) | |||
| 263 | break; | 273 | break; |
| 264 | } | 274 | } |
| 265 | if (cp > eom) | 275 | if (cp > eom) |
| 266 | return -1; | 276 | return (-1); |
| 267 | return (cp - comp_dn); | 277 | return (cp - comp_dn); |
| 268 | } | 278 | } |
| 269 | 279 | ||
| @@ -330,14 +340,122 @@ dn_find(exp_dn, msg, dnptrs, lastdnptr) | |||
| 330 | } | 340 | } |
| 331 | 341 | ||
| 332 | /* | 342 | /* |
| 333 | * Routines to insert/extract short/long's. Must account for byte | 343 | * Verify that a domain name uses an acceptable character set. |
| 334 | * order and non-alignment problems. This code at least has the | ||
| 335 | * advantage of being portable. | ||
| 336 | * | ||
| 337 | * used by sendmail. | ||
| 338 | */ | 344 | */ |
| 339 | 345 | ||
| 340 | u_short | 346 | /* |
| 347 | * Note the conspicuous absence of ctype macros in these definitions. On | ||
| 348 | * non-ASCII hosts, we can't depend on string literals or ctype macros to | ||
| 349 | * tell us anything about network-format data. The rest of the BIND system | ||
| 350 | * is not careful about this, but for some reason, we're doing it right here. | ||
| 351 | */ | ||
| 352 | #define PERIOD 0x2e | ||
| 353 | #define hyphenchar(c) ((c) == 0x2d) | ||
| 354 | #define bslashchar(c) ((c) == 0x5c) | ||
| 355 | #define periodchar(c) ((c) == PERIOD) | ||
| 356 | #define asterchar(c) ((c) == 0x2a) | ||
| 357 | #define alphachar(c) (((c) >= 0x41 && (c) <= 0x5a) \ | ||
| 358 | || ((c) >= 0x61 && (c) <= 0x7a)) | ||
| 359 | #define digitchar(c) ((c) >= 0x30 && (c) <= 0x39) | ||
| 360 | |||
| 361 | #define borderchar(c) (alphachar(c) || digitchar(c)) | ||
| 362 | #define middlechar(c) (borderchar(c) || hyphenchar(c)) | ||
| 363 | #define domainchar(c) ((c) > 0x20 && (c) < 0x7f) | ||
| 364 | |||
| 365 | int | ||
| 366 | res_hnok(dn) | ||
| 367 | const char *dn; | ||
| 368 | { | ||
| 369 | int ppch = '\0', pch = PERIOD, ch = *dn++; | ||
| 370 | |||
| 371 | while (ch != '\0') { | ||
| 372 | int nch = *dn++; | ||
| 373 | |||
| 374 | if (periodchar(ch)) { | ||
| 375 | NULL; | ||
| 376 | } else if (periodchar(pch)) { | ||
| 377 | if (!borderchar(ch)) | ||
| 378 | return (0); | ||
| 379 | } else if (periodchar(nch) || nch == '\0') { | ||
| 380 | if (!borderchar(ch)) | ||
| 381 | return (0); | ||
| 382 | } else { | ||
| 383 | if (!middlechar(ch)) | ||
| 384 | return (0); | ||
| 385 | } | ||
| 386 | ppch = pch, pch = ch, ch = nch; | ||
| 387 | } | ||
| 388 | return (1); | ||
| 389 | } | ||
| 390 | |||
| 391 | /* | ||
| 392 | * hostname-like (A, MX, WKS) owners can have "*" as their first label | ||
| 393 | * but must otherwise be as a host name. | ||
| 394 | */ | ||
| 395 | int | ||
| 396 | res_ownok(dn) | ||
| 397 | const char *dn; | ||
| 398 | { | ||
| 399 | if (asterchar(dn[0])) { | ||
| 400 | if (periodchar(dn[1])) | ||
| 401 | return (res_hnok(dn+2)); | ||
| 402 | if (dn[1] == '\0') | ||
| 403 | return (1); | ||
| 404 | } | ||
| 405 | return (res_hnok(dn)); | ||
| 406 | } | ||
| 407 | |||
| 408 | /* | ||
| 409 | * SOA RNAMEs and RP RNAMEs can have any printable character in their first | ||
| 410 | * label, but the rest of the name has to look like a host name. | ||
| 411 | */ | ||
| 412 | int | ||
| 413 | res_mailok(dn) | ||
| 414 | const char *dn; | ||
| 415 | { | ||
| 416 | int ch, escaped = 0; | ||
| 417 | |||
| 418 | /* "." is a valid missing representation */ | ||
| 419 | if (*dn == '\0') | ||
| 420 | return(1); | ||
| 421 | |||
| 422 | /* otherwise <label>.<hostname> */ | ||
| 423 | while ((ch = *dn++) != '\0') { | ||
| 424 | if (!domainchar(ch)) | ||
| 425 | return (0); | ||
| 426 | if (!escaped && periodchar(ch)) | ||
| 427 | break; | ||
| 428 | if (escaped) | ||
| 429 | escaped = 0; | ||
| 430 | else if (bslashchar(ch)) | ||
| 431 | escaped = 1; | ||
| 432 | } | ||
| 433 | if (periodchar(ch)) | ||
| 434 | return (res_hnok(dn)); | ||
| 435 | return(0); | ||
| 436 | } | ||
| 437 | |||
| 438 | /* | ||
| 439 | * This function is quite liberal, since RFC 1034's character sets are only | ||
| 440 | * recommendations. | ||
| 441 | */ | ||
| 442 | int | ||
| 443 | res_dnok(dn) | ||
| 444 | const char *dn; | ||
| 445 | { | ||
| 446 | int ch; | ||
| 447 | |||
| 448 | while ((ch = *dn++) != '\0') | ||
| 449 | if (!domainchar(ch)) | ||
| 450 | return (0); | ||
| 451 | return (1); | ||
| 452 | } | ||
| 453 | |||
| 454 | /* | ||
| 455 | * Routines to insert/extract short/long's. | ||
| 456 | */ | ||
| 457 | |||
| 458 | u_int16_t | ||
| 341 | _getshort(msgp) | 459 | _getshort(msgp) |
| 342 | register const u_char *msgp; | 460 | register const u_char *msgp; |
| 343 | { | 461 | { |
| @@ -347,6 +465,18 @@ _getshort(msgp) | |||
| 347 | return (u); | 465 | return (u); |
| 348 | } | 466 | } |
| 349 | 467 | ||
| 468 | #ifdef NeXT | ||
| 469 | /* | ||
| 470 | * nExt machines have some funky library conventions, which we must maintain. | ||
| 471 | */ | ||
| 472 | u_int16_t | ||
| 473 | res_getshort(msgp) | ||
| 474 | register const u_char *msgp; | ||
| 475 | { | ||
| 476 | return (_getshort(msgp)); | ||
| 477 | } | ||
| 478 | #endif | ||
| 479 | |||
| 350 | u_int32_t | 480 | u_int32_t |
| 351 | _getlong(msgp) | 481 | _getlong(msgp) |
| 352 | register const u_char *msgp; | 482 | register const u_char *msgp; |
| @@ -359,7 +489,7 @@ _getlong(msgp) | |||
| 359 | 489 | ||
| 360 | void | 490 | void |
| 361 | #if defined(__STDC__) || defined(__cplusplus) | 491 | #if defined(__STDC__) || defined(__cplusplus) |
| 362 | __putshort(register u_int16_t s, register u_char *msgp) | 492 | __putshort(register u_int16_t s, register u_char *msgp) /* must match proto */ |
| 363 | #else | 493 | #else |
| 364 | __putshort(s, msgp) | 494 | __putshort(s, msgp) |
| 365 | register u_int16_t s; | 495 | register u_int16_t s; |
