summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/res_comp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/net/res_comp.c')
-rw-r--r--src/lib/libc/net/res_comp.c174
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)
55static char rcsid[] = "$OpenBSD: res_comp.c,v 1.3 1996/08/19 08:29:42 tholo Exp $"; 59#if 0
60static char sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93";
61static char rcsid[] = "$From: res_comp.c,v 8.11 1996/12/02 09:17:22 vixie Exp $";
62#else
63static 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
67static int dn_find __P((u_char *, u_char *, u_char **, u_char **)); 79static 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
340u_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
365int
366res_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 */
395int
396res_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 */
412int
413res_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 */
442int
443res_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
458u_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 */
472u_int16_t
473res_getshort(msgp)
474 register const u_char *msgp;
475{
476 return (_getshort(msgp));
477}
478#endif
479
350u_int32_t 480u_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
360void 490void
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;