diff options
| author | marc <> | 2003-01-28 04:58:00 +0000 |
|---|---|---|
| committer | marc <> | 2003-01-28 04:58:00 +0000 |
| commit | 547ebab319b228b064cf5dcb3ff0ae1bf23d24a2 (patch) | |
| tree | f57454716593fb3b68672505c6dccab6438498f1 /src | |
| parent | 98a78d57b176408b5aca87705f9681c5b155b47c (diff) | |
| download | openbsd-547ebab319b228b064cf5dcb3ff0ae1bf23d24a2.tar.gz openbsd-547ebab319b228b064cf5dcb3ff0ae1bf23d24a2.tar.bz2 openbsd-547ebab319b228b064cf5dcb3ff0ae1bf23d24a2.zip | |
thread safer libc (note: safer, not safe)
Access to the global _res structure replaced by pointers to a
per thread instance. If unthreaded the pointer is to the
global structure.
Also replaced a 64k stack array with malloc-ed memory so
threaded aps (with a default 64k stack) have a chance at working.
ok deraadt@
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libc/include/thread_private.h | 11 | ||||
| -rw-r--r-- | src/lib/libc/net/getaddrinfo.c | 76 | ||||
| -rw-r--r-- | src/lib/libc/net/gethostnamadr.c | 60 | ||||
| -rw-r--r-- | src/lib/libc/net/getnameinfo.c | 9 | ||||
| -rw-r--r-- | src/lib/libc/net/getnetnamadr.c | 20 | ||||
| -rw-r--r-- | src/lib/libc/net/getrrsetbyname.c | 13 | ||||
| -rw-r--r-- | src/lib/libc/net/res_debug.c | 51 | ||||
| -rw-r--r-- | src/lib/libc/net/res_init.c | 187 | ||||
| -rw-r--r-- | src/lib/libc/net/res_mkquery.c | 22 | ||||
| -rw-r--r-- | src/lib/libc/net/res_query.c | 42 | ||||
| -rw-r--r-- | src/lib/libc/net/res_send.c | 109 | ||||
| -rw-r--r-- | src/lib/libc/net/sethostent.c | 13 |
12 files changed, 348 insertions, 265 deletions
diff --git a/src/lib/libc/include/thread_private.h b/src/lib/libc/include/thread_private.h index 0b0be6cb38..4212e7dcb2 100644 --- a/src/lib/libc/include/thread_private.h +++ b/src/lib/libc/include/thread_private.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: thread_private.h,v 1.14 2002/11/05 22:19:55 marc Exp $ */ | 1 | /* $OpenBSD: thread_private.h,v 1.15 2003/01/28 04:58:00 marc Exp $ */ |
| 2 | 2 | ||
| 3 | #ifndef _THREAD_PRIVATE_H_ | 3 | #ifndef _THREAD_PRIVATE_H_ |
| 4 | #define _THREAD_PRIVATE_H_ | 4 | #define _THREAD_PRIVATE_H_ |
| @@ -87,6 +87,15 @@ void * _libc_private_storage(volatile struct _thread_private_key_struct *, | |||
| 87 | &(storage), sizeof (storage), error) | 87 | &(storage), sizeof (storage), error) |
| 88 | 88 | ||
| 89 | /* | 89 | /* |
| 90 | * Keys used to access the per thread instances of resolver global data. | ||
| 91 | * These are not static as they are referenced in several places. | ||
| 92 | */ | ||
| 93 | extern volatile struct _thread_private_key_struct __THREAD_KEY_NAME(_res); | ||
| 94 | #ifdef INET6 | ||
| 95 | extern volatile struct _thread_private_key_struct __THREAD_KEY_NAME(_res_ext); | ||
| 96 | #endif | ||
| 97 | |||
| 98 | /* | ||
| 90 | * File descriptor locking definitions. | 99 | * File descriptor locking definitions. |
| 91 | */ | 100 | */ |
| 92 | #define FD_READ 0x1 | 101 | #define FD_READ 0x1 |
diff --git a/src/lib/libc/net/getaddrinfo.c b/src/lib/libc/net/getaddrinfo.c index 915286a404..7406f10714 100644 --- a/src/lib/libc/net/getaddrinfo.c +++ b/src/lib/libc/net/getaddrinfo.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: getaddrinfo.c,v 1.43 2002/08/27 08:53:13 itojun Exp $ */ | 1 | /* $OpenBSD: getaddrinfo.c,v 1.44 2003/01/28 04:58:00 marc Exp $ */ |
| 2 | /* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */ | 2 | /* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */ |
| 3 | 3 | ||
| 4 | /* | 4 | /* |
| @@ -499,8 +499,6 @@ getaddrinfo(hostname, servname, hints, res) | |||
| 499 | * FQDN hostname, DNS lookup | 499 | * FQDN hostname, DNS lookup |
| 500 | */ | 500 | */ |
| 501 | 501 | ||
| 502 | _THREAD_PRIVATE_MUTEX(getaddrinfo_explore_fqdn); | ||
| 503 | |||
| 504 | static int | 502 | static int |
| 505 | explore_fqdn(pai, hostname, servname, res) | 503 | explore_fqdn(pai, hostname, servname, res) |
| 506 | const struct addrinfo *pai; | 504 | const struct addrinfo *pai; |
| @@ -508,13 +506,13 @@ explore_fqdn(pai, hostname, servname, res) | |||
| 508 | const char *servname; | 506 | const char *servname; |
| 509 | struct addrinfo **res; | 507 | struct addrinfo **res; |
| 510 | { | 508 | { |
| 509 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 511 | struct addrinfo *result; | 510 | struct addrinfo *result; |
| 512 | struct addrinfo *cur; | 511 | struct addrinfo *cur; |
| 513 | int error = 0; | 512 | int error = 0; |
| 514 | char lookups[MAXDNSLUS]; | 513 | char lookups[MAXDNSLUS]; |
| 515 | int i; | 514 | int i; |
| 516 | 515 | _THREAD_PRIVATE_MUTEX(_explore_mutex); | |
| 517 | _THREAD_PRIVATE_MUTEX_LOCK(getaddrinfo_explore_fqdn); | ||
| 518 | 516 | ||
| 519 | result = NULL; | 517 | result = NULL; |
| 520 | 518 | ||
| @@ -525,7 +523,6 @@ explore_fqdn(pai, hostname, servname, res) | |||
| 525 | * XXX does not handle PF_UNSPEC case, should filter final result | 523 | * XXX does not handle PF_UNSPEC case, should filter final result |
| 526 | */ | 524 | */ |
| 527 | if ((pai->ai_flags & AI_ADDRCONFIG) != 0 && !addrconfig(pai)) { | 525 | if ((pai->ai_flags & AI_ADDRCONFIG) != 0 && !addrconfig(pai)) { |
| 528 | _THREAD_PRIVATE_MUTEX_UNLOCK(getaddrinfo_explore_fqdn); | ||
| 529 | return 0; | 526 | return 0; |
| 530 | } | 527 | } |
| 531 | #endif | 528 | #endif |
| @@ -534,18 +531,22 @@ explore_fqdn(pai, hostname, servname, res) | |||
| 534 | * if the servname does not match socktype/protocol, ignore it. | 531 | * if the servname does not match socktype/protocol, ignore it. |
| 535 | */ | 532 | */ |
| 536 | if (get_portmatch(pai, servname) != 0) { | 533 | if (get_portmatch(pai, servname) != 0) { |
| 537 | _THREAD_PRIVATE_MUTEX_UNLOCK(getaddrinfo_explore_fqdn); | ||
| 538 | return 0; | 534 | return 0; |
| 539 | } | 535 | } |
| 540 | 536 | ||
| 541 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) | 537 | if ((_resp->options & RES_INIT) == 0 && res_init() == -1) |
| 542 | strlcpy(lookups, "f", sizeof lookups); | 538 | strlcpy(lookups, "f", sizeof lookups); |
| 543 | else { | 539 | else { |
| 544 | bcopy(_res.lookups, lookups, sizeof lookups); | 540 | bcopy(_resp->lookups, lookups, sizeof lookups); |
| 545 | if (lookups[0] == '\0') | 541 | if (lookups[0] == '\0') |
| 546 | strlcpy(lookups, "bf", sizeof lookups); | 542 | strlcpy(lookups, "bf", sizeof lookups); |
| 547 | } | 543 | } |
| 548 | 544 | ||
| 545 | /* | ||
| 546 | * The yp/dns/files getaddrinfo functions are not thread safe. | ||
| 547 | * Protect them with a mutex. | ||
| 548 | */ | ||
| 549 | _THREAD_PRIVATE_MUTEX_LOCK(_explore_mutex); | ||
| 549 | for (i = 0; i < MAXDNSLUS && result == NULL && lookups[i]; i++) { | 550 | for (i = 0; i < MAXDNSLUS && result == NULL && lookups[i]; i++) { |
| 550 | switch (lookups[i]) { | 551 | switch (lookups[i]) { |
| 551 | #ifdef YP | 552 | #ifdef YP |
| @@ -561,13 +562,13 @@ explore_fqdn(pai, hostname, servname, res) | |||
| 561 | break; | 562 | break; |
| 562 | } | 563 | } |
| 563 | } | 564 | } |
| 565 | _THREAD_PRIVATE_MUTEX_UNLOCK(_explore_mutex); | ||
| 564 | if (result) { | 566 | if (result) { |
| 565 | for (cur = result; cur; cur = cur->ai_next) { | 567 | for (cur = result; cur; cur = cur->ai_next) { |
| 566 | GET_PORT(cur, servname); | 568 | GET_PORT(cur, servname); |
| 567 | /* canonname should be filled already */ | 569 | /* canonname should be filled already */ |
| 568 | } | 570 | } |
| 569 | *res = result; | 571 | *res = result; |
| 570 | _THREAD_PRIVATE_MUTEX_UNLOCK(getaddrinfo_explore_fqdn); | ||
| 571 | return 0; | 572 | return 0; |
| 572 | } else { | 573 | } else { |
| 573 | /* translate error code */ | 574 | /* translate error code */ |
| @@ -599,7 +600,6 @@ explore_fqdn(pai, hostname, servname, res) | |||
| 599 | free: | 600 | free: |
| 600 | if (result) | 601 | if (result) |
| 601 | freeaddrinfo(result); | 602 | freeaddrinfo(result); |
| 602 | _THREAD_PRIVATE_MUTEX_UNLOCK(getaddrinfo_explore_fqdn); | ||
| 603 | return error; | 603 | return error; |
| 604 | } | 604 | } |
| 605 | 605 | ||
| @@ -867,6 +867,7 @@ get_port(ai, servname, matchonly) | |||
| 867 | struct servent *sp; | 867 | struct servent *sp; |
| 868 | int port; | 868 | int port; |
| 869 | int allownumeric; | 869 | int allownumeric; |
| 870 | _THREAD_PRIVATE_MUTEX(serv_mutex); | ||
| 870 | 871 | ||
| 871 | if (servname == NULL) | 872 | if (servname == NULL) |
| 872 | return 0; | 873 | return 0; |
| @@ -914,7 +915,10 @@ get_port(ai, servname, matchonly) | |||
| 914 | break; | 915 | break; |
| 915 | } | 916 | } |
| 916 | 917 | ||
| 917 | if ((sp = getservbyname(servname, proto)) == NULL) | 918 | _THREAD_PRIVATE_MUTEX_LOCK(serv_mutex); |
| 919 | sp = getservbyname(servname, proto); | ||
| 920 | _THREAD_PRIVATE_MUTEX_UNLOCK(serv_mutex); | ||
| 921 | if (sp == NULL) | ||
| 918 | return EAI_SERVICE; | 922 | return EAI_SERVICE; |
| 919 | port = sp->s_port; | 923 | port = sp->s_port; |
| 920 | } | 924 | } |
| @@ -1563,18 +1567,26 @@ res_queryN(name, target) | |||
| 1563 | const char *name; /* domain name */ | 1567 | const char *name; /* domain name */ |
| 1564 | struct res_target *target; | 1568 | struct res_target *target; |
| 1565 | { | 1569 | { |
| 1566 | u_char buf[MAXPACKET]; | 1570 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); |
| 1571 | u_char *buf; | ||
| 1567 | HEADER *hp; | 1572 | HEADER *hp; |
| 1568 | int n; | 1573 | int n; |
| 1569 | struct res_target *t; | 1574 | struct res_target *t; |
| 1570 | int rcode; | 1575 | int rcode; |
| 1571 | int ancount; | 1576 | int ancount; |
| 1572 | 1577 | ||
| 1578 | buf = malloc(MAXPACKET); | ||
| 1579 | if (buf == NULL) { | ||
| 1580 | h_errno = NETDB_INTERNAL; | ||
| 1581 | return (-1); | ||
| 1582 | } | ||
| 1583 | |||
| 1573 | rcode = NOERROR; | 1584 | rcode = NOERROR; |
| 1574 | ancount = 0; | 1585 | ancount = 0; |
| 1575 | 1586 | ||
| 1576 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) { | 1587 | if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { |
| 1577 | h_errno = NETDB_INTERNAL; | 1588 | h_errno = NETDB_INTERNAL; |
| 1589 | free(buf); | ||
| 1578 | return (-1); | 1590 | return (-1); |
| 1579 | } | 1591 | } |
| 1580 | 1592 | ||
| @@ -1592,30 +1604,32 @@ res_queryN(name, target) | |||
| 1592 | answer = t->answer; | 1604 | answer = t->answer; |
| 1593 | anslen = t->anslen; | 1605 | anslen = t->anslen; |
| 1594 | #ifdef DEBUG | 1606 | #ifdef DEBUG |
| 1595 | if (_res.options & RES_DEBUG) | 1607 | if (_resp->options & RES_DEBUG) |
| 1596 | printf(";; res_query(%s, %d, %d)\n", name, class, type); | 1608 | printf(";; res_query(%s, %d, %d)\n", name, class, type); |
| 1597 | #endif | 1609 | #endif |
| 1598 | 1610 | ||
| 1599 | n = res_mkquery(QUERY, name, class, type, NULL, 0, NULL, | 1611 | n = res_mkquery(QUERY, name, class, type, NULL, 0, NULL, |
| 1600 | buf, sizeof(buf)); | 1612 | buf, MAXPACKET); |
| 1601 | if (n > 0 && (_res.options & RES_USE_EDNS0) != 0) | 1613 | if (n > 0 && (_resp->options & RES_USE_EDNS0) != 0) |
| 1602 | n = res_opt(n, buf, sizeof(buf), anslen); | 1614 | n = res_opt(n, buf, MAXPACKET, anslen); |
| 1603 | if (n <= 0) { | 1615 | if (n <= 0) { |
| 1604 | #ifdef DEBUG | 1616 | #ifdef DEBUG |
| 1605 | if (_res.options & RES_DEBUG) | 1617 | if (_resp->options & RES_DEBUG) |
| 1606 | printf(";; res_query: mkquery failed\n"); | 1618 | printf(";; res_query: mkquery failed\n"); |
| 1607 | #endif | 1619 | #endif |
| 1608 | h_errno = NO_RECOVERY; | 1620 | h_errno = NO_RECOVERY; |
| 1621 | free(buf); | ||
| 1609 | return (n); | 1622 | return (n); |
| 1610 | } | 1623 | } |
| 1611 | n = res_send(buf, n, answer, anslen); | 1624 | n = res_send(buf, n, answer, anslen); |
| 1612 | #if 0 | 1625 | #if 0 |
| 1613 | if (n < 0) { | 1626 | if (n < 0) { |
| 1614 | #ifdef DEBUG | 1627 | #ifdef DEBUG |
| 1615 | if (_res.options & RES_DEBUG) | 1628 | if (_resp->options & RES_DEBUG) |
| 1616 | printf(";; res_query: send error\n"); | 1629 | printf(";; res_query: send error\n"); |
| 1617 | #endif | 1630 | #endif |
| 1618 | h_errno = TRY_AGAIN; | 1631 | h_errno = TRY_AGAIN; |
| 1632 | free(buf); | ||
| 1619 | return (n); | 1633 | return (n); |
| 1620 | } | 1634 | } |
| 1621 | #endif | 1635 | #endif |
| @@ -1623,7 +1637,7 @@ res_queryN(name, target) | |||
| 1623 | if (n < 0 || hp->rcode != NOERROR || ntohs(hp->ancount) == 0) { | 1637 | if (n < 0 || hp->rcode != NOERROR || ntohs(hp->ancount) == 0) { |
| 1624 | rcode = hp->rcode; /* record most recent error */ | 1638 | rcode = hp->rcode; /* record most recent error */ |
| 1625 | #ifdef DEBUG | 1639 | #ifdef DEBUG |
| 1626 | if (_res.options & RES_DEBUG) | 1640 | if (_resp->options & RES_DEBUG) |
| 1627 | printf(";; rcode = %u, ancount=%u\n", hp->rcode, | 1641 | printf(";; rcode = %u, ancount=%u\n", hp->rcode, |
| 1628 | ntohs(hp->ancount)); | 1642 | ntohs(hp->ancount)); |
| 1629 | #endif | 1643 | #endif |
| @@ -1653,8 +1667,10 @@ res_queryN(name, target) | |||
| 1653 | h_errno = NO_RECOVERY; | 1667 | h_errno = NO_RECOVERY; |
| 1654 | break; | 1668 | break; |
| 1655 | } | 1669 | } |
| 1670 | free(buf); | ||
| 1656 | return (-1); | 1671 | return (-1); |
| 1657 | } | 1672 | } |
| 1673 | free(buf); | ||
| 1658 | return (ancount); | 1674 | return (ancount); |
| 1659 | } | 1675 | } |
| 1660 | 1676 | ||
| @@ -1669,13 +1685,14 @@ res_searchN(name, target) | |||
| 1669 | const char *name; /* domain name */ | 1685 | const char *name; /* domain name */ |
| 1670 | struct res_target *target; | 1686 | struct res_target *target; |
| 1671 | { | 1687 | { |
| 1688 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 1672 | const char *cp, * const *domain; | 1689 | const char *cp, * const *domain; |
| 1673 | HEADER *hp = (HEADER *)(void *)target->answer; /*XXX*/ | 1690 | HEADER *hp = (HEADER *)(void *)target->answer; /*XXX*/ |
| 1674 | u_int dots; | 1691 | u_int dots; |
| 1675 | int trailing_dot, ret, saved_herrno; | 1692 | int trailing_dot, ret, saved_herrno; |
| 1676 | int got_nodata = 0, got_servfail = 0, tried_as_is = 0; | 1693 | int got_nodata = 0, got_servfail = 0, tried_as_is = 0; |
| 1677 | 1694 | ||
| 1678 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) { | 1695 | if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { |
| 1679 | h_errno = NETDB_INTERNAL; | 1696 | h_errno = NETDB_INTERNAL; |
| 1680 | return (-1); | 1697 | return (-1); |
| 1681 | } | 1698 | } |
| @@ -1700,7 +1717,7 @@ res_searchN(name, target) | |||
| 1700 | * 'as is'. The threshold can be set with the "ndots" option. | 1717 | * 'as is'. The threshold can be set with the "ndots" option. |
| 1701 | */ | 1718 | */ |
| 1702 | saved_herrno = -1; | 1719 | saved_herrno = -1; |
| 1703 | if (dots >= _res.ndots) { | 1720 | if (dots >= _resp->ndots) { |
| 1704 | ret = res_querydomainN(name, NULL, target); | 1721 | ret = res_querydomainN(name, NULL, target); |
| 1705 | if (ret > 0) | 1722 | if (ret > 0) |
| 1706 | return (ret); | 1723 | return (ret); |
| @@ -1714,11 +1731,11 @@ res_searchN(name, target) | |||
| 1714 | * - there is at least one dot, there is no trailing dot, | 1731 | * - there is at least one dot, there is no trailing dot, |
| 1715 | * and RES_DNSRCH is set. | 1732 | * and RES_DNSRCH is set. |
| 1716 | */ | 1733 | */ |
| 1717 | if ((!dots && (_res.options & RES_DEFNAMES)) || | 1734 | if ((!dots && (_resp->options & RES_DEFNAMES)) || |
| 1718 | (dots && !trailing_dot && (_res.options & RES_DNSRCH))) { | 1735 | (dots && !trailing_dot && (_resp->options & RES_DNSRCH))) { |
| 1719 | int done = 0; | 1736 | int done = 0; |
| 1720 | 1737 | ||
| 1721 | for (domain = (const char * const *)_res.dnsrch; | 1738 | for (domain = (const char * const *)_resp->dnsrch; |
| 1722 | *domain && !done; | 1739 | *domain && !done; |
| 1723 | domain++) { | 1740 | domain++) { |
| 1724 | 1741 | ||
| @@ -1766,7 +1783,7 @@ res_searchN(name, target) | |||
| 1766 | * if we got here for some reason other than DNSRCH, | 1783 | * if we got here for some reason other than DNSRCH, |
| 1767 | * we only wanted one iteration of the loop, so stop. | 1784 | * we only wanted one iteration of the loop, so stop. |
| 1768 | */ | 1785 | */ |
| 1769 | if (!(_res.options & RES_DNSRCH)) | 1786 | if (!(_resp->options & RES_DNSRCH)) |
| 1770 | done++; | 1787 | done++; |
| 1771 | } | 1788 | } |
| 1772 | } | 1789 | } |
| @@ -1808,16 +1825,17 @@ res_querydomainN(name, domain, target) | |||
| 1808 | const char *name, *domain; | 1825 | const char *name, *domain; |
| 1809 | struct res_target *target; | 1826 | struct res_target *target; |
| 1810 | { | 1827 | { |
| 1828 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 1811 | char nbuf[MAXDNAME]; | 1829 | char nbuf[MAXDNAME]; |
| 1812 | const char *longname = nbuf; | 1830 | const char *longname = nbuf; |
| 1813 | size_t n, d; | 1831 | size_t n, d; |
| 1814 | 1832 | ||
| 1815 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) { | 1833 | if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { |
| 1816 | h_errno = NETDB_INTERNAL; | 1834 | h_errno = NETDB_INTERNAL; |
| 1817 | return (-1); | 1835 | return (-1); |
| 1818 | } | 1836 | } |
| 1819 | #ifdef DEBUG | 1837 | #ifdef DEBUG |
| 1820 | if (_res.options & RES_DEBUG) | 1838 | if (_resp->options & RES_DEBUG) |
| 1821 | printf(";; res_querydomain(%s, %s)\n", | 1839 | printf(";; res_querydomain(%s, %s)\n", |
| 1822 | name, domain?domain:"<Nil>"); | 1840 | name, domain?domain:"<Nil>"); |
| 1823 | #endif | 1841 | #endif |
diff --git a/src/lib/libc/net/gethostnamadr.c b/src/lib/libc/net/gethostnamadr.c index 909ce573b7..5211f423c6 100644 --- a/src/lib/libc/net/gethostnamadr.c +++ b/src/lib/libc/net/gethostnamadr.c | |||
| @@ -52,7 +52,7 @@ | |||
| 52 | */ | 52 | */ |
| 53 | 53 | ||
| 54 | #if defined(LIBC_SCCS) && !defined(lint) | 54 | #if defined(LIBC_SCCS) && !defined(lint) |
| 55 | static char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.53 2002/08/27 08:53:13 itojun Exp $"; | 55 | static char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.54 2003/01/28 04:58:00 marc Exp $"; |
| 56 | #endif /* LIBC_SCCS and not lint */ | 56 | #endif /* LIBC_SCCS and not lint */ |
| 57 | 57 | ||
| 58 | #include <sys/param.h> | 58 | #include <sys/param.h> |
| @@ -160,6 +160,7 @@ getanswer(answer, anslen, qname, qtype) | |||
| 160 | const char *qname; | 160 | const char *qname; |
| 161 | int qtype; | 161 | int qtype; |
| 162 | { | 162 | { |
| 163 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 163 | register const HEADER *hp; | 164 | register const HEADER *hp; |
| 164 | register const u_char *cp; | 165 | register const u_char *cp; |
| 165 | register int n; | 166 | register int n; |
| @@ -339,7 +340,7 @@ getanswer(answer, anslen, qname, qtype) | |||
| 339 | break; | 340 | break; |
| 340 | #else | 341 | #else |
| 341 | host.h_name = bp; | 342 | host.h_name = bp; |
| 342 | if (_res.options & RES_USE_INET6) { | 343 | if (_resp->options & RES_USE_INET6) { |
| 343 | n = strlen(bp) + 1; /* for the \0 */ | 344 | n = strlen(bp) + 1; /* for the \0 */ |
| 344 | bp += n; | 345 | bp += n; |
| 345 | map_v4v6_hostent(&host, &bp, ep); | 346 | map_v4v6_hostent(&host, &bp, ep); |
| @@ -379,7 +380,7 @@ getanswer(answer, anslen, qname, qtype) | |||
| 379 | 380 | ||
| 380 | if (bp + n >= &hostbuf[sizeof hostbuf]) { | 381 | if (bp + n >= &hostbuf[sizeof hostbuf]) { |
| 381 | #ifdef DEBUG | 382 | #ifdef DEBUG |
| 382 | if (_res.options & RES_DEBUG) | 383 | if (_resp->options & RES_DEBUG) |
| 383 | printf("size (%d) too big\n", n); | 384 | printf("size (%d) too big\n", n); |
| 384 | #endif | 385 | #endif |
| 385 | had_error++; | 386 | had_error++; |
| @@ -388,7 +389,7 @@ getanswer(answer, anslen, qname, qtype) | |||
| 388 | if (hap >= &h_addr_ptrs[MAXADDRS-1]) { | 389 | if (hap >= &h_addr_ptrs[MAXADDRS-1]) { |
| 389 | if (!toobig++) | 390 | if (!toobig++) |
| 390 | #ifdef DEBUG | 391 | #ifdef DEBUG |
| 391 | if (_res.options & RES_DEBUG) | 392 | if (_resp->options & RES_DEBUG) |
| 392 | printf("Too many addresses (%d)\n", MAXADDRS); | 393 | printf("Too many addresses (%d)\n", MAXADDRS); |
| 393 | #endif | 394 | #endif |
| 394 | cp += n; | 395 | cp += n; |
| @@ -411,7 +412,7 @@ getanswer(answer, anslen, qname, qtype) | |||
| 411 | * in its return structures - should give it the "best" | 412 | * in its return structures - should give it the "best" |
| 412 | * address in that case, not some random one | 413 | * address in that case, not some random one |
| 413 | */ | 414 | */ |
| 414 | if (_res.nsort && haveanswer > 1 && qtype == T_A) | 415 | if (_resp->nsort && haveanswer > 1 && qtype == T_A) |
| 415 | addrsort(h_addr_ptrs, haveanswer); | 416 | addrsort(h_addr_ptrs, haveanswer); |
| 416 | # endif /*RESOLVSORT*/ | 417 | # endif /*RESOLVSORT*/ |
| 417 | if (!host.h_name) { | 418 | if (!host.h_name) { |
| @@ -422,7 +423,7 @@ getanswer(answer, anslen, qname, qtype) | |||
| 422 | host.h_name = bp; | 423 | host.h_name = bp; |
| 423 | bp += n; | 424 | bp += n; |
| 424 | } | 425 | } |
| 425 | if (_res.options & RES_USE_INET6) | 426 | if (_resp->options & RES_USE_INET6) |
| 426 | map_v4v6_hostent(&host, &bp, ep); | 427 | map_v4v6_hostent(&host, &bp, ep); |
| 427 | h_errno = NETDB_SUCCESS; | 428 | h_errno = NETDB_SUCCESS; |
| 428 | return (&host); | 429 | return (&host); |
| @@ -484,27 +485,24 @@ gethostbyaddr_r(addr, len, af, he, buf, buflen, errorp) | |||
| 484 | /* XXX RFC2133 expects a gethostbyname2_r() -- unimplemented */ | 485 | /* XXX RFC2133 expects a gethostbyname2_r() -- unimplemented */ |
| 485 | #endif | 486 | #endif |
| 486 | 487 | ||
| 487 | _THREAD_PRIVATE_MUTEX(gethostnamadr); | ||
| 488 | |||
| 489 | struct hostent * | 488 | struct hostent * |
| 490 | gethostbyname(name) | 489 | gethostbyname(name) |
| 491 | const char *name; | 490 | const char *name; |
| 492 | { | 491 | { |
| 492 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 493 | struct hostent *hp; | 493 | struct hostent *hp; |
| 494 | extern struct hostent *_gethtbyname2(); | 494 | extern struct hostent *_gethtbyname2(); |
| 495 | 495 | ||
| 496 | _THREAD_PRIVATE_MUTEX_LOCK(gethostnamadr); | 496 | if ((_resp->options & RES_INIT) == 0 && res_init() == -1) |
| 497 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) | ||
| 498 | hp = _gethtbyname2(name, AF_INET); | 497 | hp = _gethtbyname2(name, AF_INET); |
| 499 | 498 | ||
| 500 | else if (_res.options & RES_USE_INET6) { | 499 | else if (_resp->options & RES_USE_INET6) { |
| 501 | hp = gethostbyname2(name, AF_INET6); | 500 | hp = gethostbyname2(name, AF_INET6); |
| 502 | if (hp == NULL) | 501 | if (hp == NULL) |
| 503 | hp = gethostbyname2(name, AF_INET); | 502 | hp = gethostbyname2(name, AF_INET); |
| 504 | } | 503 | } |
| 505 | else | 504 | else |
| 506 | hp = gethostbyname2(name, AF_INET); | 505 | hp = gethostbyname2(name, AF_INET); |
| 507 | _THREAD_PRIVATE_MUTEX_UNLOCK(gethostnamadr); | ||
| 508 | return hp; | 506 | return hp; |
| 509 | } | 507 | } |
| 510 | 508 | ||
| @@ -513,6 +511,7 @@ gethostbyname2(name, af) | |||
| 513 | const char *name; | 511 | const char *name; |
| 514 | int af; | 512 | int af; |
| 515 | { | 513 | { |
| 514 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 516 | querybuf *buf; | 515 | querybuf *buf; |
| 517 | register const char *cp; | 516 | register const char *cp; |
| 518 | char *bp, *ep; | 517 | char *bp, *ep; |
| @@ -521,7 +520,7 @@ gethostbyname2(name, af) | |||
| 521 | register struct hostent *hp; | 520 | register struct hostent *hp; |
| 522 | char lookups[MAXDNSLUS]; | 521 | char lookups[MAXDNSLUS]; |
| 523 | 522 | ||
| 524 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) | 523 | if ((_resp->options & RES_INIT) == 0 && res_init() == -1) |
| 525 | return (_gethtbyname2(name, af)); | 524 | return (_gethtbyname2(name, af)); |
| 526 | 525 | ||
| 527 | switch (af) { | 526 | switch (af) { |
| @@ -577,7 +576,7 @@ gethostbyname2(name, af) | |||
| 577 | h_addr_ptrs[0] = (char *)host_addr; | 576 | h_addr_ptrs[0] = (char *)host_addr; |
| 578 | h_addr_ptrs[1] = NULL; | 577 | h_addr_ptrs[1] = NULL; |
| 579 | host.h_addr_list = h_addr_ptrs; | 578 | host.h_addr_list = h_addr_ptrs; |
| 580 | if (_res.options & RES_USE_INET6) | 579 | if (_resp->options & RES_USE_INET6) |
| 581 | map_v4v6_hostent(&host, &bp, ep); | 580 | map_v4v6_hostent(&host, &bp, ep); |
| 582 | h_errno = NETDB_SUCCESS; | 581 | h_errno = NETDB_SUCCESS; |
| 583 | return (&host); | 582 | return (&host); |
| @@ -616,7 +615,7 @@ gethostbyname2(name, af) | |||
| 616 | break; | 615 | break; |
| 617 | } | 616 | } |
| 618 | 617 | ||
| 619 | bcopy(_res.lookups, lookups, sizeof lookups); | 618 | bcopy(_resp->lookups, lookups, sizeof lookups); |
| 620 | if (lookups[0] == '\0') | 619 | if (lookups[0] == '\0') |
| 621 | strlcpy(lookups, "bf", sizeof lookups); | 620 | strlcpy(lookups, "bf", sizeof lookups); |
| 622 | 621 | ||
| @@ -638,7 +637,7 @@ gethostbyname2(name, af) | |||
| 638 | sizeof(buf->buf))) < 0) { | 637 | sizeof(buf->buf))) < 0) { |
| 639 | free(buf); | 638 | free(buf); |
| 640 | #ifdef DEBUG | 639 | #ifdef DEBUG |
| 641 | if (_res.options & RES_DEBUG) | 640 | if (_resp->options & RES_DEBUG) |
| 642 | printf("res_search failed\n"); | 641 | printf("res_search failed\n"); |
| 643 | #endif | 642 | #endif |
| 644 | break; | 643 | break; |
| @@ -660,6 +659,7 @@ gethostbyaddr(addr, len, af) | |||
| 660 | const char *addr; /* XXX should have been def'd as u_char! */ | 659 | const char *addr; /* XXX should have been def'd as u_char! */ |
| 661 | int len, af; | 660 | int len, af; |
| 662 | { | 661 | { |
| 662 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 663 | const u_char *uaddr = (const u_char *)addr; | 663 | const u_char *uaddr = (const u_char *)addr; |
| 664 | int n, size, i; | 664 | int n, size, i; |
| 665 | querybuf *buf; | 665 | querybuf *buf; |
| @@ -669,10 +669,8 @@ gethostbyaddr(addr, len, af) | |||
| 669 | char lookups[MAXDNSLUS]; | 669 | char lookups[MAXDNSLUS]; |
| 670 | struct hostent *res; | 670 | struct hostent *res; |
| 671 | 671 | ||
| 672 | _THREAD_PRIVATE_MUTEX_LOCK(gethostnamadr); | 672 | if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { |
| 673 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) { | ||
| 674 | res = _gethtbyaddr(addr, len, af); | 673 | res = _gethtbyaddr(addr, len, af); |
| 675 | _THREAD_PRIVATE_MUTEX_UNLOCK(gethostnamadr); | ||
| 676 | return (res); | 674 | return (res); |
| 677 | } | 675 | } |
| 678 | 676 | ||
| @@ -701,13 +699,11 @@ gethostbyaddr(addr, len, af) | |||
| 701 | default: | 699 | default: |
| 702 | errno = EAFNOSUPPORT; | 700 | errno = EAFNOSUPPORT; |
| 703 | h_errno = NETDB_INTERNAL; | 701 | h_errno = NETDB_INTERNAL; |
| 704 | _THREAD_PRIVATE_MUTEX_UNLOCK(gethostnamadr); | ||
| 705 | return (NULL); | 702 | return (NULL); |
| 706 | } | 703 | } |
| 707 | if (size != len) { | 704 | if (size != len) { |
| 708 | errno = EINVAL; | 705 | errno = EINVAL; |
| 709 | h_errno = NETDB_INTERNAL; | 706 | h_errno = NETDB_INTERNAL; |
| 710 | _THREAD_PRIVATE_MUTEX_UNLOCK(gethostnamadr); | ||
| 711 | return (NULL); | 707 | return (NULL); |
| 712 | } | 708 | } |
| 713 | switch (af) { | 709 | switch (af) { |
| @@ -725,7 +721,7 @@ gethostbyaddr(addr, len, af) | |||
| 725 | break; | 721 | break; |
| 726 | } | 722 | } |
| 727 | 723 | ||
| 728 | bcopy(_res.lookups, lookups, sizeof lookups); | 724 | bcopy(_resp->lookups, lookups, sizeof lookups); |
| 729 | if (lookups[0] == '\0') | 725 | if (lookups[0] == '\0') |
| 730 | strlcpy(lookups, "bf", sizeof lookups); | 726 | strlcpy(lookups, "bf", sizeof lookups); |
| 731 | 727 | ||
| @@ -755,7 +751,7 @@ gethostbyaddr(addr, len, af) | |||
| 755 | if (n < 0) { | 751 | if (n < 0) { |
| 756 | free(buf); | 752 | free(buf); |
| 757 | #ifdef DEBUG | 753 | #ifdef DEBUG |
| 758 | if (_res.options & RES_DEBUG) | 754 | if (_resp->options & RES_DEBUG) |
| 759 | printf("res_query failed\n"); | 755 | printf("res_query failed\n"); |
| 760 | #endif | 756 | #endif |
| 761 | break; | 757 | break; |
| @@ -770,7 +766,7 @@ gethostbyaddr(addr, len, af) | |||
| 770 | bcopy(addr, host_addr, len); | 766 | bcopy(addr, host_addr, len); |
| 771 | h_addr_ptrs[0] = (char *)host_addr; | 767 | h_addr_ptrs[0] = (char *)host_addr; |
| 772 | h_addr_ptrs[1] = NULL; | 768 | h_addr_ptrs[1] = NULL; |
| 773 | if (af == AF_INET && (_res.options & RES_USE_INET6)) { | 769 | if (af == AF_INET && (_resp->options & RES_USE_INET6)) { |
| 774 | map_v4v6_address((char*)host_addr, | 770 | map_v4v6_address((char*)host_addr, |
| 775 | (char*)host_addr); | 771 | (char*)host_addr); |
| 776 | hp->h_addrtype = AF_INET6; | 772 | hp->h_addrtype = AF_INET6; |
| @@ -783,7 +779,6 @@ gethostbyaddr(addr, len, af) | |||
| 783 | break; | 779 | break; |
| 784 | } | 780 | } |
| 785 | } | 781 | } |
| 786 | _THREAD_PRIVATE_MUTEX_UNLOCK(gethostnamadr); | ||
| 787 | /* XXX h_errno not correct in all cases... */ | 782 | /* XXX h_errno not correct in all cases... */ |
| 788 | return (hp); | 783 | return (hp); |
| 789 | } | 784 | } |
| @@ -811,6 +806,7 @@ _endhtent() | |||
| 811 | struct hostent * | 806 | struct hostent * |
| 812 | _gethtent() | 807 | _gethtent() |
| 813 | { | 808 | { |
| 809 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 814 | char *p; | 810 | char *p; |
| 815 | register char *cp, **q; | 811 | register char *cp, **q; |
| 816 | int af; | 812 | int af; |
| @@ -842,7 +838,7 @@ _gethtent() | |||
| 842 | af = AF_INET6; | 838 | af = AF_INET6; |
| 843 | len = IN6ADDRSZ; | 839 | len = IN6ADDRSZ; |
| 844 | } else if (inet_pton(AF_INET, p, host_addr) > 0) { | 840 | } else if (inet_pton(AF_INET, p, host_addr) > 0) { |
| 845 | if (_res.options & RES_USE_INET6) { | 841 | if (_resp->options & RES_USE_INET6) { |
| 846 | map_v4v6_address((char*)host_addr, (char*)host_addr); | 842 | map_v4v6_address((char*)host_addr, (char*)host_addr); |
| 847 | af = AF_INET6; | 843 | af = AF_INET6; |
| 848 | len = IN6ADDRSZ; | 844 | len = IN6ADDRSZ; |
| @@ -880,7 +876,7 @@ _gethtent() | |||
| 880 | *cp++ = '\0'; | 876 | *cp++ = '\0'; |
| 881 | } | 877 | } |
| 882 | *q = NULL; | 878 | *q = NULL; |
| 883 | if (_res.options & RES_USE_INET6) { | 879 | if (_resp->options & RES_USE_INET6) { |
| 884 | char *bp = hostbuf; | 880 | char *bp = hostbuf; |
| 885 | char *ep = hostbuf + sizeof hostbuf; | 881 | char *ep = hostbuf + sizeof hostbuf; |
| 886 | 882 | ||
| @@ -894,10 +890,11 @@ struct hostent * | |||
| 894 | _gethtbyname(name) | 890 | _gethtbyname(name) |
| 895 | const char *name; | 891 | const char *name; |
| 896 | { | 892 | { |
| 893 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 897 | extern struct hostent *_gethtbyname2(); | 894 | extern struct hostent *_gethtbyname2(); |
| 898 | struct hostent *hp; | 895 | struct hostent *hp; |
| 899 | 896 | ||
| 900 | if (_res.options & RES_USE_INET6) { | 897 | if (_resp->options & RES_USE_INET6) { |
| 901 | hp = _gethtbyname2(name, AF_INET6); | 898 | hp = _gethtbyname2(name, AF_INET6); |
| 902 | if (hp) | 899 | if (hp) |
| 903 | return (hp); | 900 | return (hp); |
| @@ -1136,6 +1133,7 @@ addrsort(ap, num) | |||
| 1136 | char **ap; | 1133 | char **ap; |
| 1137 | int num; | 1134 | int num; |
| 1138 | { | 1135 | { |
| 1136 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 1139 | int i, j; | 1137 | int i, j; |
| 1140 | char **p; | 1138 | char **p; |
| 1141 | short aval[MAXADDRS]; | 1139 | short aval[MAXADDRS]; |
| @@ -1143,9 +1141,9 @@ addrsort(ap, num) | |||
| 1143 | 1141 | ||
| 1144 | p = ap; | 1142 | p = ap; |
| 1145 | for (i = 0; i < num; i++, p++) { | 1143 | for (i = 0; i < num; i++, p++) { |
| 1146 | for (j = 0 ; (unsigned)j < _res.nsort; j++) | 1144 | for (j = 0 ; (unsigned)j < _resp->nsort; j++) |
| 1147 | if (_res.sort_list[j].addr.s_addr == | 1145 | if (_resp->sort_list[j].addr.s_addr == |
| 1148 | (((struct in_addr *)(*p))->s_addr & _res.sort_list[j].mask)) | 1146 | (((struct in_addr *)(*p))->s_addr & _resp->sort_list[j].mask)) |
| 1149 | break; | 1147 | break; |
| 1150 | aval[i] = j; | 1148 | aval[i] = j; |
| 1151 | if (needsort == 0 && i > 0 && j < aval[i-1]) | 1149 | if (needsort == 0 && i > 0 && j < aval[i-1]) |
diff --git a/src/lib/libc/net/getnameinfo.c b/src/lib/libc/net/getnameinfo.c index 2311eba7a0..d3a9678cbd 100644 --- a/src/lib/libc/net/getnameinfo.c +++ b/src/lib/libc/net/getnameinfo.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: getnameinfo.c,v 1.25 2002/06/27 09:24:28 itojun Exp $ */ | 1 | /* $OpenBSD: getnameinfo.c,v 1.26 2003/01/28 04:58:00 marc Exp $ */ |
| 2 | /* $KAME: getnameinfo.c,v 1.45 2000/09/25 22:43:56 itojun Exp $ */ | 2 | /* $KAME: getnameinfo.c,v 1.45 2000/09/25 22:43:56 itojun Exp $ */ |
| 3 | 3 | ||
| 4 | /* | 4 | /* |
| @@ -59,6 +59,8 @@ | |||
| 59 | #include <string.h> | 59 | #include <string.h> |
| 60 | #include <stddef.h> | 60 | #include <stddef.h> |
| 61 | 61 | ||
| 62 | #include "thread_private.h" | ||
| 63 | |||
| 62 | static const struct afd { | 64 | static const struct afd { |
| 63 | int a_af; | 65 | int a_af; |
| 64 | int a_addrlen; | 66 | int a_addrlen; |
| @@ -106,6 +108,7 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) | |||
| 106 | int h_error; | 108 | int h_error; |
| 107 | char numserv[512]; | 109 | char numserv[512]; |
| 108 | char numaddr[512]; | 110 | char numaddr[512]; |
| 111 | _THREAD_PRIVATE_MUTEX(serv_mutex); | ||
| 109 | 112 | ||
| 110 | if (sa == NULL) | 113 | if (sa == NULL) |
| 111 | return EAI_FAIL; | 114 | return EAI_FAIL; |
| @@ -140,8 +143,10 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) | |||
| 140 | if (flags & NI_NUMERICSERV) | 143 | if (flags & NI_NUMERICSERV) |
| 141 | sp = NULL; | 144 | sp = NULL; |
| 142 | else { | 145 | else { |
| 146 | _THREAD_PRIVATE_MUTEX_LOCK(serv_mutex); | ||
| 143 | sp = getservbyport(port, | 147 | sp = getservbyport(port, |
| 144 | (flags & NI_DGRAM) ? "udp" : "tcp"); | 148 | (flags & NI_DGRAM) ? "udp" : "tcp"); |
| 149 | _THREAD_PRIVATE_MUTEX_UNLOCK(serv_mutex); | ||
| 145 | } | 150 | } |
| 146 | if (sp) { | 151 | if (sp) { |
| 147 | if (strlen(sp->s_name) + 1 > servlen) | 152 | if (strlen(sp->s_name) + 1 > servlen) |
| @@ -228,7 +233,9 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) | |||
| 228 | break; | 233 | break; |
| 229 | } | 234 | } |
| 230 | } else { | 235 | } else { |
| 236 | _THREAD_PRIVATE_MUTEX_LOCK(serv_mutex); | ||
| 231 | hp = gethostbyaddr(addr, afd->a_addrlen, afd->a_af); | 237 | hp = gethostbyaddr(addr, afd->a_addrlen, afd->a_af); |
| 238 | _THREAD_PRIVATE_MUTEX_UNLOCK(serv_mutex); | ||
| 232 | h_error = h_errno; | 239 | h_error = h_errno; |
| 233 | 240 | ||
| 234 | if (hp) { | 241 | if (hp) { |
diff --git a/src/lib/libc/net/getnetnamadr.c b/src/lib/libc/net/getnetnamadr.c index f183fbe3fe..75a75243ef 100644 --- a/src/lib/libc/net/getnetnamadr.c +++ b/src/lib/libc/net/getnetnamadr.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: getnetnamadr.c,v 1.19 2002/11/14 02:48:00 millert Exp $ */ | 1 | /* $OpenBSD: getnetnamadr.c,v 1.20 2003/01/28 04:58:00 marc Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Copyright (c) 1997, Jason Downs. All rights reserved. | 4 | * Copyright (c) 1997, Jason Downs. All rights reserved. |
| @@ -77,7 +77,7 @@ static char sccsid[] = "@(#)getnetbyaddr.c 8.1 (Berkeley) 6/4/93"; | |||
| 77 | static char sccsid_[] = "from getnetnamadr.c 1.4 (Coimbra) 93/06/03"; | 77 | static char sccsid_[] = "from getnetnamadr.c 1.4 (Coimbra) 93/06/03"; |
| 78 | static char rcsid[] = "$From: getnetnamadr.c,v 8.7 1996/08/05 08:31:35 vixie Exp $"; | 78 | static char rcsid[] = "$From: getnetnamadr.c,v 8.7 1996/08/05 08:31:35 vixie Exp $"; |
| 79 | #else | 79 | #else |
| 80 | static char rcsid[] = "$OpenBSD: getnetnamadr.c,v 1.19 2002/11/14 02:48:00 millert Exp $"; | 80 | static char rcsid[] = "$OpenBSD: getnetnamadr.c,v 1.20 2003/01/28 04:58:00 marc Exp $"; |
| 81 | #endif | 81 | #endif |
| 82 | #endif /* LIBC_SCCS and not lint */ | 82 | #endif /* LIBC_SCCS and not lint */ |
| 83 | 83 | ||
| @@ -96,6 +96,8 @@ static char rcsid[] = "$OpenBSD: getnetnamadr.c,v 1.19 2002/11/14 02:48:00 mille | |||
| 96 | #include <string.h> | 96 | #include <string.h> |
| 97 | #include <stdlib.h> | 97 | #include <stdlib.h> |
| 98 | 98 | ||
| 99 | #include "thread_private.h" | ||
| 100 | |||
| 99 | extern int h_errno; | 101 | extern int h_errno; |
| 100 | 102 | ||
| 101 | struct netent *_getnetbyaddr(in_addr_t net, int type); | 103 | struct netent *_getnetbyaddr(in_addr_t net, int type); |
| @@ -262,6 +264,7 @@ getnetbyaddr(net, net_type) | |||
| 262 | register in_addr_t net; | 264 | register in_addr_t net; |
| 263 | register int net_type; | 265 | register int net_type; |
| 264 | { | 266 | { |
| 267 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 265 | unsigned int netbr[4]; | 268 | unsigned int netbr[4]; |
| 266 | int nn, anslen; | 269 | int nn, anslen; |
| 267 | querybuf *buf; | 270 | querybuf *buf; |
| @@ -271,10 +274,10 @@ getnetbyaddr(net, net_type) | |||
| 271 | char lookups[MAXDNSLUS]; | 274 | char lookups[MAXDNSLUS]; |
| 272 | int i; | 275 | int i; |
| 273 | 276 | ||
| 274 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) | 277 | if ((_resp->options & RES_INIT) == 0 && res_init() == -1) |
| 275 | return(_getnetbyaddr(net, net_type)); | 278 | return(_getnetbyaddr(net, net_type)); |
| 276 | 279 | ||
| 277 | bcopy(_res.lookups, lookups, sizeof lookups); | 280 | bcopy(_resp->lookups, lookups, sizeof lookups); |
| 278 | if (lookups[0] == '\0') | 281 | if (lookups[0] == '\0') |
| 279 | strlcpy(lookups, "bf", sizeof lookups); | 282 | strlcpy(lookups, "bf", sizeof lookups); |
| 280 | 283 | ||
| @@ -320,7 +323,7 @@ getnetbyaddr(net, net_type) | |||
| 320 | if (anslen < 0) { | 323 | if (anslen < 0) { |
| 321 | free(buf); | 324 | free(buf); |
| 322 | #ifdef DEBUG | 325 | #ifdef DEBUG |
| 323 | if (_res.options & RES_DEBUG) | 326 | if (_resp->options & RES_DEBUG) |
| 324 | printf("res_query failed\n"); | 327 | printf("res_query failed\n"); |
| 325 | #endif | 328 | #endif |
| 326 | break; | 329 | break; |
| @@ -352,6 +355,7 @@ struct netent * | |||
| 352 | getnetbyname(net) | 355 | getnetbyname(net) |
| 353 | register const char *net; | 356 | register const char *net; |
| 354 | { | 357 | { |
| 358 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 355 | int anslen; | 359 | int anslen; |
| 356 | querybuf *buf; | 360 | querybuf *buf; |
| 357 | char qbuf[MAXDNAME]; | 361 | char qbuf[MAXDNAME]; |
| @@ -359,10 +363,10 @@ getnetbyname(net) | |||
| 359 | char lookups[MAXDNSLUS]; | 363 | char lookups[MAXDNSLUS]; |
| 360 | int i; | 364 | int i; |
| 361 | 365 | ||
| 362 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) | 366 | if ((_resp->options & RES_INIT) == 0 && res_init() == -1) |
| 363 | return (_getnetbyname(net)); | 367 | return (_getnetbyname(net)); |
| 364 | 368 | ||
| 365 | bcopy(_res.lookups, lookups, sizeof lookups); | 369 | bcopy(_resp->lookups, lookups, sizeof lookups); |
| 366 | if (lookups[0] == '\0') | 370 | if (lookups[0] == '\0') |
| 367 | strlcpy(lookups, "bf", sizeof lookups); | 371 | strlcpy(lookups, "bf", sizeof lookups); |
| 368 | 372 | ||
| @@ -383,7 +387,7 @@ getnetbyname(net) | |||
| 383 | if (anslen < 0) { | 387 | if (anslen < 0) { |
| 384 | free(buf); | 388 | free(buf); |
| 385 | #ifdef DEBUG | 389 | #ifdef DEBUG |
| 386 | if (_res.options & RES_DEBUG) | 390 | if (_resp->options & RES_DEBUG) |
| 387 | printf("res_query failed\n"); | 391 | printf("res_query failed\n"); |
| 388 | #endif | 392 | #endif |
| 389 | break; | 393 | break; |
diff --git a/src/lib/libc/net/getrrsetbyname.c b/src/lib/libc/net/getrrsetbyname.c index 1ec60486b3..e4bd9a936e 100644 --- a/src/lib/libc/net/getrrsetbyname.c +++ b/src/lib/libc/net/getrrsetbyname.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: getrrsetbyname.c,v 1.5 2002/09/07 20:54:04 jakob Exp $ */ | 1 | /* $OpenBSD: getrrsetbyname.c,v 1.6 2003/01/28 04:58:00 marc Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Copyright (c) 2001 Jakob Schlyter. All rights reserved. | 4 | * Copyright (c) 2001 Jakob Schlyter. All rights reserved. |
| @@ -51,6 +51,8 @@ | |||
| 51 | #include <stdlib.h> | 51 | #include <stdlib.h> |
| 52 | #include <string.h> | 52 | #include <string.h> |
| 53 | 53 | ||
| 54 | #include "thread_private.h" | ||
| 55 | |||
| 54 | #define ANSWER_BUFFER_SIZE 1024*64 | 56 | #define ANSWER_BUFFER_SIZE 1024*64 |
| 55 | 57 | ||
| 56 | struct dns_query { | 58 | struct dns_query { |
| @@ -95,6 +97,7 @@ getrrsetbyname(const char *hostname, unsigned int rdclass, | |||
| 95 | unsigned int rdtype, unsigned int flags, | 97 | unsigned int rdtype, unsigned int flags, |
| 96 | struct rrsetinfo **res) | 98 | struct rrsetinfo **res) |
| 97 | { | 99 | { |
| 100 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 98 | int result; | 101 | int result; |
| 99 | struct rrsetinfo *rrset = NULL; | 102 | struct rrsetinfo *rrset = NULL; |
| 100 | struct dns_response *response; | 103 | struct dns_response *response; |
| @@ -122,19 +125,19 @@ getrrsetbyname(const char *hostname, unsigned int rdclass, | |||
| 122 | } | 125 | } |
| 123 | 126 | ||
| 124 | /* initialize resolver */ | 127 | /* initialize resolver */ |
| 125 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) { | 128 | if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { |
| 126 | result = ERRSET_FAIL; | 129 | result = ERRSET_FAIL; |
| 127 | goto fail; | 130 | goto fail; |
| 128 | } | 131 | } |
| 129 | 132 | ||
| 130 | #ifdef DEBUG | 133 | #ifdef DEBUG |
| 131 | _res.options |= RES_DEBUG; | 134 | _resp->options |= RES_DEBUG; |
| 132 | #endif /* DEBUG */ | 135 | #endif /* DEBUG */ |
| 133 | 136 | ||
| 134 | #ifdef RES_USE_DNSSEC | 137 | #ifdef RES_USE_DNSSEC |
| 135 | /* turn on DNSSEC if EDNS0 is configured */ | 138 | /* turn on DNSSEC if EDNS0 is configured */ |
| 136 | if (_res.options & RES_USE_EDNS0) | 139 | if (_resp->options & RES_USE_EDNS0) |
| 137 | _res.options |= RES_USE_DNSSEC; | 140 | _resp->options |= RES_USE_DNSSEC; |
| 138 | #endif /* RES_USE_DNSEC */ | 141 | #endif /* RES_USE_DNSEC */ |
| 139 | 142 | ||
| 140 | /* make query */ | 143 | /* make query */ |
diff --git a/src/lib/libc/net/res_debug.c b/src/lib/libc/net/res_debug.c index 2ea9173fe9..f4e4c271ed 100644 --- a/src/lib/libc/net/res_debug.c +++ b/src/lib/libc/net/res_debug.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: res_debug.c,v 1.14 2002/07/25 21:55:30 deraadt Exp $ */ | 1 | /* $OpenBSD: res_debug.c,v 1.15 2003/01/28 04:58:00 marc Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * ++Copyright++ 1985, 1990, 1993 | 4 | * ++Copyright++ 1985, 1990, 1993 |
| @@ -82,7 +82,7 @@ | |||
| 82 | static char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93"; | 82 | static char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93"; |
| 83 | static char rcsid[] = "$From: res_debug.c,v 8.19 1996/11/26 10:11:23 vixie Exp $"; | 83 | static char rcsid[] = "$From: res_debug.c,v 8.19 1996/11/26 10:11:23 vixie Exp $"; |
| 84 | #else | 84 | #else |
| 85 | static char rcsid[] = "$OpenBSD: res_debug.c,v 1.14 2002/07/25 21:55:30 deraadt Exp $"; | 85 | static char rcsid[] = "$OpenBSD: res_debug.c,v 1.15 2003/01/28 04:58:00 marc Exp $"; |
| 86 | #endif | 86 | #endif |
| 87 | #endif /* LIBC_SCCS and not lint */ | 87 | #endif /* LIBC_SCCS and not lint */ |
| 88 | 88 | ||
| @@ -102,6 +102,8 @@ static char rcsid[] = "$OpenBSD: res_debug.c,v 1.14 2002/07/25 21:55:30 deraadt | |||
| 102 | #include <stdlib.h> | 102 | #include <stdlib.h> |
| 103 | #include <string.h> | 103 | #include <string.h> |
| 104 | 104 | ||
| 105 | #include "thread_private.h" | ||
| 106 | |||
| 105 | extern const char *_res_opcodes[]; | 107 | extern const char *_res_opcodes[]; |
| 106 | extern const char *_res_resultcodes[]; | 108 | extern const char *_res_resultcodes[]; |
| 107 | 109 | ||
| @@ -200,19 +202,20 @@ do_rrset(msg, len, cp, cnt, pflag, file, hs) | |||
| 200 | const char *hs; | 202 | const char *hs; |
| 201 | FILE *file; | 203 | FILE *file; |
| 202 | { | 204 | { |
| 205 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 203 | int n; | 206 | int n; |
| 204 | int sflag; | 207 | int sflag; |
| 205 | 208 | ||
| 206 | /* | 209 | /* |
| 207 | * Print answer records. | 210 | * Print answer records. |
| 208 | */ | 211 | */ |
| 209 | sflag = (_res.pfcode & pflag); | 212 | sflag = (_resp->pfcode & pflag); |
| 210 | if ((n = ntohs(cnt))) { | 213 | if ((n = ntohs(cnt))) { |
| 211 | if ((!_res.pfcode) || | 214 | if ((!_resp->pfcode) || |
| 212 | ((sflag) && (_res.pfcode & RES_PRF_HEAD1))) | 215 | ((sflag) && (_resp->pfcode & RES_PRF_HEAD1))) |
| 213 | fprintf(file, "%s", hs); | 216 | fprintf(file, "%s", hs); |
| 214 | while (--n >= 0) { | 217 | while (--n >= 0) { |
| 215 | if ((!_res.pfcode) || sflag) { | 218 | if ((!_resp->pfcode) || sflag) { |
| 216 | cp = p_rr(cp, msg, file); | 219 | cp = p_rr(cp, msg, file); |
| 217 | } else { | 220 | } else { |
| 218 | unsigned int dlen; | 221 | unsigned int dlen; |
| @@ -227,8 +230,8 @@ do_rrset(msg, len, cp, cnt, pflag, file, hs) | |||
| 227 | if ((cp - msg) > len) | 230 | if ((cp - msg) > len) |
| 228 | return (NULL); | 231 | return (NULL); |
| 229 | } | 232 | } |
| 230 | if ((!_res.pfcode) || | 233 | if ((!_resp->pfcode) || |
| 231 | ((sflag) && (_res.pfcode & RES_PRF_HEAD1))) | 234 | ((sflag) && (_resp->pfcode & RES_PRF_HEAD1))) |
| 232 | putc('\n', file); | 235 | putc('\n', file); |
| 233 | } | 236 | } |
| 234 | return (cp); | 237 | return (cp); |
| @@ -271,11 +274,12 @@ __fp_nquery(msg, len, file) | |||
| 271 | int len; | 274 | int len; |
| 272 | FILE *file; | 275 | FILE *file; |
| 273 | { | 276 | { |
| 277 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 274 | register const u_char *cp, *endMark; | 278 | register const u_char *cp, *endMark; |
| 275 | register const HEADER *hp; | 279 | register const HEADER *hp; |
| 276 | register int n; | 280 | register int n; |
| 277 | 281 | ||
| 278 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) | 282 | if ((_resp->options & RES_INIT) == 0 && res_init() == -1) |
| 279 | return; | 283 | return; |
| 280 | 284 | ||
| 281 | #define TruncTest(x) if (x > endMark) goto trunc | 285 | #define TruncTest(x) if (x > endMark) goto trunc |
| @@ -287,16 +291,16 @@ __fp_nquery(msg, len, file) | |||
| 287 | hp = (HEADER *)msg; | 291 | hp = (HEADER *)msg; |
| 288 | cp = msg + HFIXEDSZ; | 292 | cp = msg + HFIXEDSZ; |
| 289 | endMark = msg + len; | 293 | endMark = msg + len; |
| 290 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX) || hp->rcode) { | 294 | if ((!_resp->pfcode) || (_resp->pfcode & RES_PRF_HEADX) || hp->rcode) { |
| 291 | fprintf(file, ";; ->>HEADER<<- opcode: %s, status: %s, id: %u", | 295 | fprintf(file, ";; ->>HEADER<<- opcode: %s, status: %s, id: %u", |
| 292 | _res_opcodes[hp->opcode], | 296 | _res_opcodes[hp->opcode], |
| 293 | _res_resultcodes[hp->rcode], | 297 | _res_resultcodes[hp->rcode], |
| 294 | ntohs(hp->id)); | 298 | ntohs(hp->id)); |
| 295 | putc('\n', file); | 299 | putc('\n', file); |
| 296 | } | 300 | } |
| 297 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX)) | 301 | if ((!_resp->pfcode) || (_resp->pfcode & RES_PRF_HEADX)) |
| 298 | putc(';', file); | 302 | putc(';', file); |
| 299 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD2)) { | 303 | if ((!_resp->pfcode) || (_resp->pfcode & RES_PRF_HEAD2)) { |
| 300 | fprintf(file, "; flags:"); | 304 | fprintf(file, "; flags:"); |
| 301 | if (hp->qr) | 305 | if (hp->qr) |
| 302 | fprintf(file, " qr"); | 306 | fprintf(file, " qr"); |
| @@ -315,13 +319,13 @@ __fp_nquery(msg, len, file) | |||
| 315 | if (hp->cd) | 319 | if (hp->cd) |
| 316 | fprintf(file, " cd"); | 320 | fprintf(file, " cd"); |
| 317 | } | 321 | } |
| 318 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD1)) { | 322 | if ((!_resp->pfcode) || (_resp->pfcode & RES_PRF_HEAD1)) { |
| 319 | fprintf(file, "; Ques: %u", ntohs(hp->qdcount)); | 323 | fprintf(file, "; Ques: %u", ntohs(hp->qdcount)); |
| 320 | fprintf(file, ", Ans: %u", ntohs(hp->ancount)); | 324 | fprintf(file, ", Ans: %u", ntohs(hp->ancount)); |
| 321 | fprintf(file, ", Auth: %u", ntohs(hp->nscount)); | 325 | fprintf(file, ", Auth: %u", ntohs(hp->nscount)); |
| 322 | fprintf(file, ", Addit: %u", ntohs(hp->arcount)); | 326 | fprintf(file, ", Addit: %u", ntohs(hp->arcount)); |
| 323 | } | 327 | } |
| 324 | if ((!_res.pfcode) || (_res.pfcode & | 328 | if ((!_resp->pfcode) || (_resp->pfcode & |
| 325 | (RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) { | 329 | (RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) { |
| 326 | putc('\n',file); | 330 | putc('\n',file); |
| 327 | } | 331 | } |
| @@ -329,13 +333,13 @@ __fp_nquery(msg, len, file) | |||
| 329 | * Print question records. | 333 | * Print question records. |
| 330 | */ | 334 | */ |
| 331 | if ((n = ntohs(hp->qdcount))) { | 335 | if ((n = ntohs(hp->qdcount))) { |
| 332 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) | 336 | if ((!_resp->pfcode) || (_resp->pfcode & RES_PRF_QUES)) |
| 333 | fprintf(file, ";; QUESTIONS:\n"); | 337 | fprintf(file, ";; QUESTIONS:\n"); |
| 334 | while (--n >= 0) { | 338 | while (--n >= 0) { |
| 335 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) | 339 | if ((!_resp->pfcode) || (_resp->pfcode & RES_PRF_QUES)) |
| 336 | fprintf(file, ";;\t"); | 340 | fprintf(file, ";;\t"); |
| 337 | TruncTest(cp); | 341 | TruncTest(cp); |
| 338 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) | 342 | if ((!_resp->pfcode) || (_resp->pfcode & RES_PRF_QUES)) |
| 339 | cp = p_cdnname(cp, msg, len, file); | 343 | cp = p_cdnname(cp, msg, len, file); |
| 340 | else { | 344 | else { |
| 341 | int n; | 345 | int n; |
| @@ -349,16 +353,16 @@ __fp_nquery(msg, len, file) | |||
| 349 | } | 353 | } |
| 350 | ErrorTest(cp); | 354 | ErrorTest(cp); |
| 351 | TruncTest(cp); | 355 | TruncTest(cp); |
| 352 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) | 356 | if ((!_resp->pfcode) || (_resp->pfcode & RES_PRF_QUES)) |
| 353 | fprintf(file, ", type = %s", | 357 | fprintf(file, ", type = %s", |
| 354 | __p_type(_getshort((u_char*)cp))); | 358 | __p_type(_getshort((u_char*)cp))); |
| 355 | cp += INT16SZ; | 359 | cp += INT16SZ; |
| 356 | TruncTest(cp); | 360 | TruncTest(cp); |
| 357 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) | 361 | if ((!_resp->pfcode) || (_resp->pfcode & RES_PRF_QUES)) |
| 358 | fprintf(file, ", class = %s\n", | 362 | fprintf(file, ", class = %s\n", |
| 359 | __p_class(_getshort((u_char*)cp))); | 363 | __p_class(_getshort((u_char*)cp))); |
| 360 | cp += INT16SZ; | 364 | cp += INT16SZ; |
| 361 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) | 365 | if ((!_resp->pfcode) || (_resp->pfcode & RES_PRF_QUES)) |
| 362 | putc('\n', file); | 366 | putc('\n', file); |
| 363 | } | 367 | } |
| 364 | } | 368 | } |
| @@ -478,6 +482,7 @@ __p_rr(cp, msg, file) | |||
| 478 | const u_char *cp, *msg; | 482 | const u_char *cp, *msg; |
| 479 | FILE *file; | 483 | FILE *file; |
| 480 | { | 484 | { |
| 485 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 481 | int type, class, dlen, n, c; | 486 | int type, class, dlen, n, c; |
| 482 | struct in_addr inaddr; | 487 | struct in_addr inaddr; |
| 483 | const u_char *cp1, *cp2; | 488 | const u_char *cp1, *cp2; |
| @@ -487,7 +492,7 @@ __p_rr(cp, msg, file) | |||
| 487 | char rrname[MAXDNAME]; /* The fqdn of this RR */ | 492 | char rrname[MAXDNAME]; /* The fqdn of this RR */ |
| 488 | char base64_key[MAX_KEY_BASE64]; | 493 | char base64_key[MAX_KEY_BASE64]; |
| 489 | 494 | ||
| 490 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) { | 495 | if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { |
| 491 | h_errno = NETDB_INTERNAL; | 496 | h_errno = NETDB_INTERNAL; |
| 492 | return (NULL); | 497 | return (NULL); |
| 493 | } | 498 | } |
| @@ -505,9 +510,9 @@ __p_rr(cp, msg, file) | |||
| 505 | dlen = _getshort((u_char*)cp); | 510 | dlen = _getshort((u_char*)cp); |
| 506 | cp += INT16SZ; | 511 | cp += INT16SZ; |
| 507 | cp1 = cp; | 512 | cp1 = cp; |
| 508 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_TTLID)) | 513 | if ((!_resp->pfcode) || (_resp->pfcode & RES_PRF_TTLID)) |
| 509 | fprintf(file, "\t%lu", (u_long)tmpttl); | 514 | fprintf(file, "\t%lu", (u_long)tmpttl); |
| 510 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_CLASS)) | 515 | if ((!_resp->pfcode) || (_resp->pfcode & RES_PRF_CLASS)) |
| 511 | fprintf(file, "\t%s", __p_class(class)); | 516 | fprintf(file, "\t%s", __p_class(class)); |
| 512 | fprintf(file, "\t%s", __p_type(type)); | 517 | fprintf(file, "\t%s", __p_type(type)); |
| 513 | /* | 518 | /* |
diff --git a/src/lib/libc/net/res_init.c b/src/lib/libc/net/res_init.c index c55c7763a4..a1d69f57b5 100644 --- a/src/lib/libc/net/res_init.c +++ b/src/lib/libc/net/res_init.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: res_init.c,v 1.27 2002/07/25 21:13:45 deraadt Exp $ */ | 1 | /* $OpenBSD: res_init.c,v 1.28 2003/01/28 04:58:00 marc Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * ++Copyright++ 1985, 1989, 1993 | 4 | * ++Copyright++ 1985, 1989, 1993 |
| @@ -64,7 +64,7 @@ | |||
| 64 | static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93"; | 64 | static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93"; |
| 65 | static char rcsid[] = "$From: res_init.c,v 8.7 1996/09/28 06:51:07 vixie Exp $"; | 65 | static char rcsid[] = "$From: res_init.c,v 8.7 1996/09/28 06:51:07 vixie Exp $"; |
| 66 | #else | 66 | #else |
| 67 | static char rcsid[] = "$OpenBSD: res_init.c,v 1.27 2002/07/25 21:13:45 deraadt Exp $"; | 67 | static char rcsid[] = "$OpenBSD: res_init.c,v 1.28 2003/01/28 04:58:00 marc Exp $"; |
| 68 | #endif | 68 | #endif |
| 69 | #endif /* LIBC_SCCS and not lint */ | 69 | #endif /* LIBC_SCCS and not lint */ |
| 70 | 70 | ||
| @@ -86,6 +86,8 @@ static char rcsid[] = "$OpenBSD: res_init.c,v 1.27 2002/07/25 21:13:45 deraadt E | |||
| 86 | #include <netdb.h> | 86 | #include <netdb.h> |
| 87 | #endif /* INET6 */ | 87 | #endif /* INET6 */ |
| 88 | 88 | ||
| 89 | #include "thread_private.h" | ||
| 90 | |||
| 89 | /*-------------------------------------- info about "sortlist" -------------- | 91 | /*-------------------------------------- info about "sortlist" -------------- |
| 90 | * Marc Majka 1994/04/16 | 92 | * Marc Majka 1994/04/16 |
| 91 | * Allan Nathanson 1994/10/29 (BIND 4.9.3.x) | 93 | * Allan Nathanson 1994/10/29 (BIND 4.9.3.x) |
| @@ -120,6 +122,9 @@ static u_int32_t net_mask(struct in_addr); | |||
| 120 | /* | 122 | /* |
| 121 | * Resolver state default settings. | 123 | * Resolver state default settings. |
| 122 | */ | 124 | */ |
| 125 | volatile struct _thread_private_key_struct __THREAD_KEY_NAME(_res) = { | ||
| 126 | PTHREAD_ONCE_INIT, 0 | ||
| 127 | }; | ||
| 123 | 128 | ||
| 124 | struct __res_state _res | 129 | struct __res_state _res |
| 125 | # if defined(__BIND_RES_TEXT) | 130 | # if defined(__BIND_RES_TEXT) |
| @@ -127,6 +132,10 @@ struct __res_state _res | |||
| 127 | # endif | 132 | # endif |
| 128 | ; | 133 | ; |
| 129 | #ifdef INET6 | 134 | #ifdef INET6 |
| 135 | volatile struct _thread_private_key_struct __THREAD_KEY_NAME(_res_ext) = { | ||
| 136 | PTHREAD_ONCE_INIT, 0 | ||
| 137 | }; | ||
| 138 | |||
| 130 | struct __res_state_ext _res_ext; | 139 | struct __res_state_ext _res_ext; |
| 131 | #endif /* INET6 */ | 140 | #endif /* INET6 */ |
| 132 | 141 | ||
| @@ -154,6 +163,11 @@ struct __res_state_ext _res_ext; | |||
| 154 | int | 163 | int |
| 155 | res_init() | 164 | res_init() |
| 156 | { | 165 | { |
| 166 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 167 | #ifdef INET6 | ||
| 168 | struct __res_state_ext *_res_extp = _THREAD_PRIVATE(_res_ext, _res_ext, | ||
| 169 | &_res_ext); | ||
| 170 | #endif | ||
| 157 | register FILE *fp; | 171 | register FILE *fp; |
| 158 | register char *cp, **pp; | 172 | register char *cp, **pp; |
| 159 | register int n; | 173 | register int n; |
| @@ -189,33 +203,33 @@ res_init() | |||
| 189 | * set in RES_DEFAULT). Our solution is to declare such applications | 203 | * set in RES_DEFAULT). Our solution is to declare such applications |
| 190 | * "broken". They could fool us by setting RES_INIT but none do (yet). | 204 | * "broken". They could fool us by setting RES_INIT but none do (yet). |
| 191 | */ | 205 | */ |
| 192 | if (!_res.retrans) | 206 | if (!_resp->retrans) |
| 193 | _res.retrans = RES_TIMEOUT; | 207 | _resp->retrans = RES_TIMEOUT; |
| 194 | if (!_res.retry) | 208 | if (!_resp->retry) |
| 195 | _res.retry = 4; | 209 | _resp->retry = 4; |
| 196 | if (!(_res.options & RES_INIT)) | 210 | if (!(_resp->options & RES_INIT)) |
| 197 | _res.options = RES_DEFAULT; | 211 | _resp->options = RES_DEFAULT; |
| 198 | 212 | ||
| 199 | #ifdef USELOOPBACK | 213 | #ifdef USELOOPBACK |
| 200 | _res.nsaddr.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1); | 214 | _resp->nsaddr.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1); |
| 201 | #else | 215 | #else |
| 202 | _res.nsaddr.sin_addr.s_addr = INADDR_ANY; | 216 | _resp->nsaddr.sin_addr.s_addr = INADDR_ANY; |
| 203 | #endif | 217 | #endif |
| 204 | _res.nsaddr.sin_family = AF_INET; | 218 | _resp->nsaddr.sin_family = AF_INET; |
| 205 | _res.nsaddr.sin_port = htons(NAMESERVER_PORT); | 219 | _resp->nsaddr.sin_port = htons(NAMESERVER_PORT); |
| 206 | _res.nsaddr.sin_len = sizeof(struct sockaddr_in); | 220 | _resp->nsaddr.sin_len = sizeof(struct sockaddr_in); |
| 207 | #ifdef INET6 | 221 | #ifdef INET6 |
| 208 | if (sizeof(_res_ext.nsaddr) >= _res.nsaddr.sin_len) | 222 | if (sizeof(_res_extp->nsaddr) >= _resp->nsaddr.sin_len) |
| 209 | memcpy(&_res_ext.nsaddr, &_res.nsaddr, _res.nsaddr.sin_len); | 223 | memcpy(&_res_extp->nsaddr, &_resp->nsaddr, _resp->nsaddr.sin_len); |
| 210 | #endif | 224 | #endif |
| 211 | _res.nscount = 1; | 225 | _resp->nscount = 1; |
| 212 | _res.ndots = 1; | 226 | _resp->ndots = 1; |
| 213 | _res.pfcode = 0; | 227 | _resp->pfcode = 0; |
| 214 | strlcpy(_res.lookups, "f", sizeof _res.lookups); | 228 | strlcpy(_resp->lookups, "f", sizeof _resp->lookups); |
| 215 | 229 | ||
| 216 | /* Allow user to override the local domain definition */ | 230 | /* Allow user to override the local domain definition */ |
| 217 | if (issetugid() == 0 && (cp = getenv("LOCALDOMAIN")) != NULL) { | 231 | if (issetugid() == 0 && (cp = getenv("LOCALDOMAIN")) != NULL) { |
| 218 | strlcpy(_res.defdname, cp, sizeof(_res.defdname)); | 232 | strlcpy(_resp->defdname, cp, sizeof(_resp->defdname)); |
| 219 | haveenv++; | 233 | haveenv++; |
| 220 | 234 | ||
| 221 | /* | 235 | /* |
| @@ -225,10 +239,10 @@ res_init() | |||
| 225 | * one that they want to use as an individual (even more | 239 | * one that they want to use as an individual (even more |
| 226 | * important now that the rfc1535 stuff restricts searches) | 240 | * important now that the rfc1535 stuff restricts searches) |
| 227 | */ | 241 | */ |
| 228 | cp = _res.defdname; | 242 | cp = _resp->defdname; |
| 229 | pp = _res.dnsrch; | 243 | pp = _resp->dnsrch; |
| 230 | *pp++ = cp; | 244 | *pp++ = cp; |
| 231 | for (n = 0; *cp && pp < _res.dnsrch + MAXDNSRCH; cp++) { | 245 | for (n = 0; *cp && pp < _resp->dnsrch + MAXDNSRCH; cp++) { |
| 232 | if (*cp == '\n') /* silly backwards compat */ | 246 | if (*cp == '\n') /* silly backwards compat */ |
| 233 | break; | 247 | break; |
| 234 | else if (*cp == ' ' || *cp == '\t') { | 248 | else if (*cp == ' ' || *cp == '\t') { |
| @@ -253,7 +267,7 @@ res_init() | |||
| 253 | line[sizeof(name) - 1] == '\t')) | 267 | line[sizeof(name) - 1] == '\t')) |
| 254 | 268 | ||
| 255 | if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) { | 269 | if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) { |
| 256 | strlcpy(_res.lookups, "bf", sizeof _res.lookups); | 270 | strlcpy(_resp->lookups, "bf", sizeof _resp->lookups); |
| 257 | 271 | ||
| 258 | /* read the config file */ | 272 | /* read the config file */ |
| 259 | buf[0] = '\0'; | 273 | buf[0] = '\0'; |
| @@ -277,8 +291,8 @@ res_init() | |||
| 277 | cp++; | 291 | cp++; |
| 278 | if ((*cp == '\0') || (*cp == '\n')) | 292 | if ((*cp == '\0') || (*cp == '\n')) |
| 279 | continue; | 293 | continue; |
| 280 | strlcpy(_res.defdname, cp, sizeof(_res.defdname)); | 294 | strlcpy(_resp->defdname, cp, sizeof(_resp->defdname)); |
| 281 | if ((cp = strpbrk(_res.defdname, " \t\n")) != NULL) | 295 | if ((cp = strpbrk(_resp->defdname, " \t\n")) != NULL) |
| 282 | *cp = '\0'; | 296 | *cp = '\0'; |
| 283 | havesearch = 0; | 297 | havesearch = 0; |
| 284 | continue; | 298 | continue; |
| @@ -287,7 +301,7 @@ res_init() | |||
| 287 | if (MATCH(buf, "lookup")) { | 301 | if (MATCH(buf, "lookup")) { |
| 288 | char *sp = NULL; | 302 | char *sp = NULL; |
| 289 | 303 | ||
| 290 | bzero(_res.lookups, sizeof _res.lookups); | 304 | bzero(_resp->lookups, sizeof _resp->lookups); |
| 291 | cp = buf + sizeof("lookup") - 1; | 305 | cp = buf + sizeof("lookup") - 1; |
| 292 | for (n = 0;; cp++) { | 306 | for (n = 0;; cp++) { |
| 293 | if (n == MAXDNSLUS) | 307 | if (n == MAXDNSLUS) |
| @@ -295,14 +309,14 @@ res_init() | |||
| 295 | if ((*cp == '\0') || (*cp == '\n')) { | 309 | if ((*cp == '\0') || (*cp == '\n')) { |
| 296 | if (sp) { | 310 | if (sp) { |
| 297 | if (*sp=='y' || *sp=='b' || *sp=='f') | 311 | if (*sp=='y' || *sp=='b' || *sp=='f') |
| 298 | _res.lookups[n++] = *sp; | 312 | _resp->lookups[n++] = *sp; |
| 299 | sp = NULL; | 313 | sp = NULL; |
| 300 | } | 314 | } |
| 301 | break; | 315 | break; |
| 302 | } else if ((*cp == ' ') || (*cp == '\t') || (*cp == ',')) { | 316 | } else if ((*cp == ' ') || (*cp == '\t') || (*cp == ',')) { |
| 303 | if (sp) { | 317 | if (sp) { |
| 304 | if (*sp=='y' || *sp=='b' || *sp=='f') | 318 | if (*sp=='y' || *sp=='b' || *sp=='f') |
| 305 | _res.lookups[n++] = *sp; | 319 | _resp->lookups[n++] = *sp; |
| 306 | sp = NULL; | 320 | sp = NULL; |
| 307 | } | 321 | } |
| 308 | } else if (sp == NULL) | 322 | } else if (sp == NULL) |
| @@ -319,17 +333,17 @@ res_init() | |||
| 319 | cp++; | 333 | cp++; |
| 320 | if ((*cp == '\0') || (*cp == '\n')) | 334 | if ((*cp == '\0') || (*cp == '\n')) |
| 321 | continue; | 335 | continue; |
| 322 | strlcpy(_res.defdname, cp, sizeof(_res.defdname)); | 336 | strlcpy(_resp->defdname, cp, sizeof(_resp->defdname)); |
| 323 | if ((cp = strchr(_res.defdname, '\n')) != NULL) | 337 | if ((cp = strchr(_resp->defdname, '\n')) != NULL) |
| 324 | *cp = '\0'; | 338 | *cp = '\0'; |
| 325 | /* | 339 | /* |
| 326 | * Set search list to be blank-separated strings | 340 | * Set search list to be blank-separated strings |
| 327 | * on rest of line. | 341 | * on rest of line. |
| 328 | */ | 342 | */ |
| 329 | cp = _res.defdname; | 343 | cp = _resp->defdname; |
| 330 | pp = _res.dnsrch; | 344 | pp = _resp->dnsrch; |
| 331 | *pp++ = cp; | 345 | *pp++ = cp; |
| 332 | for (n = 0; *cp && pp < _res.dnsrch + MAXDNSRCH; cp++) { | 346 | for (n = 0; *cp && pp < _resp->dnsrch + MAXDNSRCH; cp++) { |
| 333 | if (*cp == ' ' || *cp == '\t') { | 347 | if (*cp == ' ' || *cp == '\t') { |
| 334 | *cp = 0; | 348 | *cp = 0; |
| 335 | n = 1; | 349 | n = 1; |
| @@ -375,19 +389,19 @@ res_init() | |||
| 375 | res = NULL; | 389 | res = NULL; |
| 376 | if (getaddrinfo(cp, pbuf, &hints, &res) == 0 && | 390 | if (getaddrinfo(cp, pbuf, &hints, &res) == 0 && |
| 377 | res->ai_next == NULL) { | 391 | res->ai_next == NULL) { |
| 378 | if (res->ai_addrlen <= sizeof(_res_ext.nsaddr_list[nserv])) { | 392 | if (res->ai_addrlen <= sizeof(_res_extp->nsaddr_list[nserv])) { |
| 379 | memcpy(&_res_ext.nsaddr_list[nserv], res->ai_addr, | 393 | memcpy(&_res_extp->nsaddr_list[nserv], res->ai_addr, |
| 380 | res->ai_addrlen); | 394 | res->ai_addrlen); |
| 381 | } else { | 395 | } else { |
| 382 | memset(&_res_ext.nsaddr_list[nserv], 0, | 396 | memset(&_res_extp->nsaddr_list[nserv], 0, |
| 383 | sizeof(_res_ext.nsaddr_list[nserv])); | 397 | sizeof(_res_extp->nsaddr_list[nserv])); |
| 384 | } | 398 | } |
| 385 | if (res->ai_addrlen <= sizeof(_res.nsaddr_list[nserv])) { | 399 | if (res->ai_addrlen <= sizeof(_resp->nsaddr_list[nserv])) { |
| 386 | memcpy(&_res.nsaddr_list[nserv], res->ai_addr, | 400 | memcpy(&_resp->nsaddr_list[nserv], res->ai_addr, |
| 387 | res->ai_addrlen); | 401 | res->ai_addrlen); |
| 388 | } else { | 402 | } else { |
| 389 | memset(&_res.nsaddr_list[nserv], 0, | 403 | memset(&_resp->nsaddr_list[nserv], 0, |
| 390 | sizeof(_res.nsaddr_list[nserv])); | 404 | sizeof(_resp->nsaddr_list[nserv])); |
| 391 | } | 405 | } |
| 392 | nserv++; | 406 | nserv++; |
| 393 | } | 407 | } |
| @@ -395,11 +409,11 @@ res_init() | |||
| 395 | freeaddrinfo(res); | 409 | freeaddrinfo(res); |
| 396 | #else /* INET6 */ | 410 | #else /* INET6 */ |
| 397 | if ((*cp != '\0') && (*cp != '\n') && inet_aton(cp, &a)) { | 411 | if ((*cp != '\0') && (*cp != '\n') && inet_aton(cp, &a)) { |
| 398 | _res.nsaddr_list[nserv].sin_addr = a; | 412 | _resp->nsaddr_list[nserv].sin_addr = a; |
| 399 | _res.nsaddr_list[nserv].sin_family = AF_INET; | 413 | _resp->nsaddr_list[nserv].sin_family = AF_INET; |
| 400 | _res.nsaddr_list[nserv].sin_port = | 414 | _resp->nsaddr_list[nserv].sin_port = |
| 401 | htons(NAMESERVER_PORT); | 415 | htons(NAMESERVER_PORT); |
| 402 | _res.nsaddr_list[nserv].sin_len = | 416 | _resp->nsaddr_list[nserv].sin_len = |
| 403 | sizeof(struct sockaddr_in); | 417 | sizeof(struct sockaddr_in); |
| 404 | nserv++; | 418 | nserv++; |
| 405 | } | 419 | } |
| @@ -428,7 +442,7 @@ res_init() | |||
| 428 | n = *cp; | 442 | n = *cp; |
| 429 | *cp = 0; | 443 | *cp = 0; |
| 430 | if (inet_aton(net, &a)) { | 444 | if (inet_aton(net, &a)) { |
| 431 | _res.sort_list[nsort].addr = a; | 445 | _resp->sort_list[nsort].addr = a; |
| 432 | if (ISSORTMASK(n)) { | 446 | if (ISSORTMASK(n)) { |
| 433 | *cp++ = n; | 447 | *cp++ = n; |
| 434 | net = cp; | 448 | net = cp; |
| @@ -438,29 +452,29 @@ res_init() | |||
| 438 | n = *cp; | 452 | n = *cp; |
| 439 | *cp = 0; | 453 | *cp = 0; |
| 440 | if (inet_aton(net, &a)) { | 454 | if (inet_aton(net, &a)) { |
| 441 | _res.sort_list[nsort].mask = a.s_addr; | 455 | _resp->sort_list[nsort].mask = a.s_addr; |
| 442 | } else { | 456 | } else { |
| 443 | _res.sort_list[nsort].mask = | 457 | _resp->sort_list[nsort].mask = |
| 444 | net_mask(_res.sort_list[nsort].addr); | 458 | net_mask(_resp->sort_list[nsort].addr); |
| 445 | } | 459 | } |
| 446 | } else { | 460 | } else { |
| 447 | _res.sort_list[nsort].mask = | 461 | _resp->sort_list[nsort].mask = |
| 448 | net_mask(_res.sort_list[nsort].addr); | 462 | net_mask(_resp->sort_list[nsort].addr); |
| 449 | } | 463 | } |
| 450 | #ifdef INET6 | 464 | #ifdef INET6 |
| 451 | _res_ext.sort_list[nsort].af = AF_INET; | 465 | _res_extp->sort_list[nsort].af = AF_INET; |
| 452 | _res_ext.sort_list[nsort].addr.ina = | 466 | _res_extp->sort_list[nsort].addr.ina = |
| 453 | _res.sort_list[nsort].addr; | 467 | _resp->sort_list[nsort].addr; |
| 454 | _res_ext.sort_list[nsort].mask.ina.s_addr = | 468 | _res_extp->sort_list[nsort].mask.ina.s_addr = |
| 455 | _res.sort_list[nsort].mask; | 469 | _resp->sort_list[nsort].mask; |
| 456 | #endif /* INET6 */ | 470 | #endif /* INET6 */ |
| 457 | nsort++; | 471 | nsort++; |
| 458 | } | 472 | } |
| 459 | #ifdef INET6 | 473 | #ifdef INET6 |
| 460 | else if (inet_pton(AF_INET6, net, &a6) == 1) { | 474 | else if (inet_pton(AF_INET6, net, &a6) == 1) { |
| 461 | _res_ext.sort_list[nsort].af = AF_INET6; | 475 | _res_extp->sort_list[nsort].af = AF_INET6; |
| 462 | _res_ext.sort_list[nsort].addr.in6a = a6; | 476 | _res_extp->sort_list[nsort].addr.in6a = a6; |
| 463 | u = (u_char *)&_res_ext.sort_list[nsort].mask.in6a; | 477 | u = (u_char *)&_res_extp->sort_list[nsort].mask.in6a; |
| 464 | *cp++ = n; | 478 | *cp++ = n; |
| 465 | net = cp; | 479 | net = cp; |
| 466 | while (*cp && *cp != ';' && | 480 | while (*cp && *cp != ';' && |
| @@ -510,33 +524,33 @@ res_init() | |||
| 510 | } | 524 | } |
| 511 | } | 525 | } |
| 512 | if (nserv > 1) | 526 | if (nserv > 1) |
| 513 | _res.nscount = nserv; | 527 | _resp->nscount = nserv; |
| 514 | #ifdef RESOLVSORT | 528 | #ifdef RESOLVSORT |
| 515 | _res.nsort = nsort; | 529 | _resp->nsort = nsort; |
| 516 | #endif | 530 | #endif |
| 517 | (void) fclose(fp); | 531 | (void) fclose(fp); |
| 518 | } | 532 | } |
| 519 | if (_res.defdname[0] == 0 && | 533 | if (_resp->defdname[0] == 0 && |
| 520 | gethostname(buf, sizeof(_res.defdname) - 1) == 0 && | 534 | gethostname(buf, sizeof(_resp->defdname) - 1) == 0 && |
| 521 | (cp = strchr(buf, '.')) != NULL) | 535 | (cp = strchr(buf, '.')) != NULL) |
| 522 | { | 536 | { |
| 523 | strlcpy(_res.defdname, cp + 1, | 537 | strlcpy(_resp->defdname, cp + 1, |
| 524 | sizeof(_res.defdname)); | 538 | sizeof(_resp->defdname)); |
| 525 | } | 539 | } |
| 526 | 540 | ||
| 527 | /* find components of local domain that might be searched */ | 541 | /* find components of local domain that might be searched */ |
| 528 | if (havesearch == 0) { | 542 | if (havesearch == 0) { |
| 529 | pp = _res.dnsrch; | 543 | pp = _resp->dnsrch; |
| 530 | *pp++ = _res.defdname; | 544 | *pp++ = _resp->defdname; |
| 531 | *pp = NULL; | 545 | *pp = NULL; |
| 532 | 546 | ||
| 533 | #ifndef RFC1535 | 547 | #ifndef RFC1535 |
| 534 | dots = 0; | 548 | dots = 0; |
| 535 | for (cp = _res.defdname; *cp; cp++) | 549 | for (cp = _resp->defdname; *cp; cp++) |
| 536 | dots += (*cp == '.'); | 550 | dots += (*cp == '.'); |
| 537 | 551 | ||
| 538 | cp = _res.defdname; | 552 | cp = _resp->defdname; |
| 539 | while (pp < _res.dnsrch + MAXDFLSRCH) { | 553 | while (pp < _resp->dnsrch + MAXDFLSRCH) { |
| 540 | if (dots < LOCALDOMAINPARTS) | 554 | if (dots < LOCALDOMAINPARTS) |
| 541 | break; | 555 | break; |
| 542 | cp = strchr(cp, '.') + 1; /* we know there is one */ | 556 | cp = strchr(cp, '.') + 1; /* we know there is one */ |
| @@ -545,9 +559,9 @@ res_init() | |||
| 545 | } | 559 | } |
| 546 | *pp = NULL; | 560 | *pp = NULL; |
| 547 | #ifdef DEBUG | 561 | #ifdef DEBUG |
| 548 | if (_res.options & RES_DEBUG) { | 562 | if (_resp->options & RES_DEBUG) { |
| 549 | printf(";; res_init()... default dnsrch list:\n"); | 563 | printf(";; res_init()... default dnsrch list:\n"); |
| 550 | for (pp = _res.dnsrch; *pp; pp++) | 564 | for (pp = _resp->dnsrch; *pp; pp++) |
| 551 | printf(";;\t%s\n", *pp); | 565 | printf(";;\t%s\n", *pp); |
| 552 | printf(";;\t..END..\n"); | 566 | printf(";;\t..END..\n"); |
| 553 | } | 567 | } |
| @@ -556,10 +570,10 @@ res_init() | |||
| 556 | } | 570 | } |
| 557 | 571 | ||
| 558 | if (issetugid()) | 572 | if (issetugid()) |
| 559 | _res.options |= RES_NOALIASES; | 573 | _resp->options |= RES_NOALIASES; |
| 560 | else if ((cp = getenv("RES_OPTIONS")) != NULL) | 574 | else if ((cp = getenv("RES_OPTIONS")) != NULL) |
| 561 | res_setoptions(cp, "env"); | 575 | res_setoptions(cp, "env"); |
| 562 | _res.options |= RES_INIT; | 576 | _resp->options |= RES_INIT; |
| 563 | return (0); | 577 | return (0); |
| 564 | } | 578 | } |
| 565 | 579 | ||
| @@ -568,12 +582,13 @@ static void | |||
| 568 | res_setoptions(options, source) | 582 | res_setoptions(options, source) |
| 569 | char *options, *source; | 583 | char *options, *source; |
| 570 | { | 584 | { |
| 585 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 571 | char *cp = options; | 586 | char *cp = options; |
| 572 | char *endp; | 587 | char *endp; |
| 573 | long l; | 588 | long l; |
| 574 | 589 | ||
| 575 | #ifdef DEBUG | 590 | #ifdef DEBUG |
| 576 | if (_res.options & RES_DEBUG) | 591 | if (_resp->options & RES_DEBUG) |
| 577 | printf(";; res_setoptions(\"%s\", \"%s\")...\n", | 592 | printf(";; res_setoptions(\"%s\", \"%s\")...\n", |
| 578 | options, source); | 593 | options, source); |
| 579 | #endif | 594 | #endif |
| @@ -588,31 +603,31 @@ res_setoptions(options, source) | |||
| 588 | if (l >= 0 && endp != p && | 603 | if (l >= 0 && endp != p && |
| 589 | (*endp = '\0' || isspace(*endp))) { | 604 | (*endp = '\0' || isspace(*endp))) { |
| 590 | if (l <= RES_MAXNDOTS) | 605 | if (l <= RES_MAXNDOTS) |
| 591 | _res.ndots = l; | 606 | _resp->ndots = l; |
| 592 | else | 607 | else |
| 593 | _res.ndots = RES_MAXNDOTS; | 608 | _resp->ndots = RES_MAXNDOTS; |
| 594 | #ifdef DEBUG | 609 | #ifdef DEBUG |
| 595 | if (_res.options & RES_DEBUG) | 610 | if (_resp->options & RES_DEBUG) |
| 596 | printf(";;\tndots=%u\n", _res.ndots); | 611 | printf(";;\tndots=%u\n", _resp->ndots); |
| 597 | #endif | 612 | #endif |
| 598 | } | 613 | } |
| 599 | } else if (!strncmp(cp, "debug", sizeof("debug") - 1)) { | 614 | } else if (!strncmp(cp, "debug", sizeof("debug") - 1)) { |
| 600 | #ifdef DEBUG | 615 | #ifdef DEBUG |
| 601 | if (!(_res.options & RES_DEBUG)) { | 616 | if (!(_resp->options & RES_DEBUG)) { |
| 602 | printf(";; res_setoptions(\"%s\", \"%s\")..\n", | 617 | printf(";; res_setoptions(\"%s\", \"%s\")..\n", |
| 603 | options, source); | 618 | options, source); |
| 604 | _res.options |= RES_DEBUG; | 619 | _resp->options |= RES_DEBUG; |
| 605 | } | 620 | } |
| 606 | printf(";;\tdebug\n"); | 621 | printf(";;\tdebug\n"); |
| 607 | #endif | 622 | #endif |
| 608 | } else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) { | 623 | } else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) { |
| 609 | _res.options |= RES_USE_INET6; | 624 | _resp->options |= RES_USE_INET6; |
| 610 | } else if (!strncmp(cp, "insecure1", sizeof("insecure1") - 1)) { | 625 | } else if (!strncmp(cp, "insecure1", sizeof("insecure1") - 1)) { |
| 611 | _res.options |= RES_INSECURE1; | 626 | _resp->options |= RES_INSECURE1; |
| 612 | } else if (!strncmp(cp, "insecure2", sizeof("insecure2") - 1)) { | 627 | } else if (!strncmp(cp, "insecure2", sizeof("insecure2") - 1)) { |
| 613 | _res.options |= RES_INSECURE2; | 628 | _resp->options |= RES_INSECURE2; |
| 614 | } else if (!strncmp(cp, "edns0", sizeof("edns0") - 1)) { | 629 | } else if (!strncmp(cp, "edns0", sizeof("edns0") - 1)) { |
| 615 | _res.options |= RES_USE_EDNS0; | 630 | _resp->options |= RES_USE_EDNS0; |
| 616 | } else { | 631 | } else { |
| 617 | /* XXX - print a warning here? */ | 632 | /* XXX - print a warning here? */ |
| 618 | } | 633 | } |
diff --git a/src/lib/libc/net/res_mkquery.c b/src/lib/libc/net/res_mkquery.c index 6cd6a00dbe..bb8f1f0725 100644 --- a/src/lib/libc/net/res_mkquery.c +++ b/src/lib/libc/net/res_mkquery.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: res_mkquery.c,v 1.12 2002/08/28 03:19:38 itojun Exp $ */ | 1 | /* $OpenBSD: res_mkquery.c,v 1.13 2003/01/28 04:58:00 marc Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * ++Copyright++ 1985, 1993 | 4 | * ++Copyright++ 1985, 1993 |
| @@ -60,7 +60,7 @@ | |||
| 60 | static char sccsid[] = "@(#)res_mkquery.c 8.1 (Berkeley) 6/4/93"; | 60 | static char sccsid[] = "@(#)res_mkquery.c 8.1 (Berkeley) 6/4/93"; |
| 61 | static char rcsid[] = "$From: res_mkquery.c,v 8.5 1996/08/27 08:33:28 vixie Exp $"; | 61 | static char rcsid[] = "$From: res_mkquery.c,v 8.5 1996/08/27 08:33:28 vixie Exp $"; |
| 62 | #else | 62 | #else |
| 63 | static char rcsid[] = "$OpenBSD: res_mkquery.c,v 1.12 2002/08/28 03:19:38 itojun Exp $"; | 63 | static char rcsid[] = "$OpenBSD: res_mkquery.c,v 1.13 2003/01/28 04:58:00 marc Exp $"; |
| 64 | #endif | 64 | #endif |
| 65 | #endif /* LIBC_SCCS and not lint */ | 65 | #endif /* LIBC_SCCS and not lint */ |
| 66 | 66 | ||
| @@ -74,6 +74,8 @@ static char rcsid[] = "$OpenBSD: res_mkquery.c,v 1.12 2002/08/28 03:19:38 itojun | |||
| 74 | #include <resolv.h> | 74 | #include <resolv.h> |
| 75 | #include <string.h> | 75 | #include <string.h> |
| 76 | 76 | ||
| 77 | #include "thread_private.h" | ||
| 78 | |||
| 77 | /* | 79 | /* |
| 78 | * Form all types of queries. | 80 | * Form all types of queries. |
| 79 | * Returns the size of the result or -1. | 81 | * Returns the size of the result or -1. |
| @@ -90,17 +92,18 @@ res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen) | |||
| 90 | u_char *buf; /* buffer to put query */ | 92 | u_char *buf; /* buffer to put query */ |
| 91 | int buflen; /* size of buffer */ | 93 | int buflen; /* size of buffer */ |
| 92 | { | 94 | { |
| 95 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 93 | register HEADER *hp; | 96 | register HEADER *hp; |
| 94 | register u_char *cp, *ep; | 97 | register u_char *cp, *ep; |
| 95 | register int n; | 98 | register int n; |
| 96 | u_char *dnptrs[20], **dpp, **lastdnptr; | 99 | u_char *dnptrs[20], **dpp, **lastdnptr; |
| 97 | 100 | ||
| 98 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) { | 101 | if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { |
| 99 | h_errno = NETDB_INTERNAL; | 102 | h_errno = NETDB_INTERNAL; |
| 100 | return (-1); | 103 | return (-1); |
| 101 | } | 104 | } |
| 102 | #ifdef DEBUG | 105 | #ifdef DEBUG |
| 103 | if (_res.options & RES_DEBUG) | 106 | if (_resp->options & RES_DEBUG) |
| 104 | printf(";; res_mkquery(%d, %s, %d, %d)\n", | 107 | printf(";; res_mkquery(%d, %s, %d, %d)\n", |
| 105 | op, dname, class, type); | 108 | op, dname, class, type); |
| 106 | #endif | 109 | #endif |
| @@ -116,10 +119,10 @@ res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen) | |||
| 116 | return (-1); | 119 | return (-1); |
| 117 | bzero(buf, HFIXEDSZ); | 120 | bzero(buf, HFIXEDSZ); |
| 118 | hp = (HEADER *) buf; | 121 | hp = (HEADER *) buf; |
| 119 | _res.id = res_randomid(); | 122 | _resp->id = res_randomid(); |
| 120 | hp->id = htons(_res.id); | 123 | hp->id = htons(_resp->id); |
| 121 | hp->opcode = op; | 124 | hp->opcode = op; |
| 122 | hp->rd = (_res.options & RES_RECURSE) != 0; | 125 | hp->rd = (_resp->options & RES_RECURSE) != 0; |
| 123 | hp->rcode = NOERROR; | 126 | hp->rcode = NOERROR; |
| 124 | cp = buf + HFIXEDSZ; | 127 | cp = buf + HFIXEDSZ; |
| 125 | ep = buf + buflen; | 128 | ep = buf + buflen; |
| @@ -203,6 +206,7 @@ res_opt(n0, buf, buflen, anslen) | |||
| 203 | int buflen; /* size of buffer */ | 206 | int buflen; /* size of buffer */ |
| 204 | int anslen; /* answer buffer length */ | 207 | int anslen; /* answer buffer length */ |
| 205 | { | 208 | { |
| 209 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 206 | register HEADER *hp; | 210 | register HEADER *hp; |
| 207 | register u_char *cp, *ep; | 211 | register u_char *cp, *ep; |
| 208 | 212 | ||
| @@ -223,9 +227,9 @@ res_opt(n0, buf, buflen, anslen) | |||
| 223 | cp += INT16SZ; | 227 | cp += INT16SZ; |
| 224 | *cp++ = NOERROR; /* extended RCODE */ | 228 | *cp++ = NOERROR; /* extended RCODE */ |
| 225 | *cp++ = 0; /* EDNS version */ | 229 | *cp++ = 0; /* EDNS version */ |
| 226 | if (_res.options & RES_USE_DNSSEC) { | 230 | if (_resp->options & RES_USE_DNSSEC) { |
| 227 | #ifdef DEBUG | 231 | #ifdef DEBUG |
| 228 | if (_res.options & RES_DEBUG) | 232 | if (_resp->options & RES_DEBUG) |
| 229 | printf(";; res_opt()... ENDS0 DNSSEC OK\n"); | 233 | printf(";; res_opt()... ENDS0 DNSSEC OK\n"); |
| 230 | #endif /* DEBUG */ | 234 | #endif /* DEBUG */ |
| 231 | __putshort(DNS_MESSAGEEXTFLAG_DO, cp); /* EDNS Z field */ | 235 | __putshort(DNS_MESSAGEEXTFLAG_DO, cp); /* EDNS Z field */ |
diff --git a/src/lib/libc/net/res_query.c b/src/lib/libc/net/res_query.c index 9c1aef1218..1e949e8efa 100644 --- a/src/lib/libc/net/res_query.c +++ b/src/lib/libc/net/res_query.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: res_query.c,v 1.19 2002/06/27 09:55:49 itojun Exp $ */ | 1 | /* $OpenBSD: res_query.c,v 1.20 2003/01/28 04:58:00 marc Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * ++Copyright++ 1988, 1993 | 4 | * ++Copyright++ 1988, 1993 |
| @@ -60,7 +60,7 @@ | |||
| 60 | static char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93"; | 60 | static char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93"; |
| 61 | static char rcsid[] = "$From: res_query.c,v 8.9 1996/09/22 00:13:28 vixie Exp $"; | 61 | static char rcsid[] = "$From: res_query.c,v 8.9 1996/09/22 00:13:28 vixie Exp $"; |
| 62 | #else | 62 | #else |
| 63 | static char rcsid[] = "$OpenBSD: res_query.c,v 1.19 2002/06/27 09:55:49 itojun Exp $"; | 63 | static char rcsid[] = "$OpenBSD: res_query.c,v 1.20 2003/01/28 04:58:00 marc Exp $"; |
| 64 | #endif | 64 | #endif |
| 65 | #endif /* LIBC_SCCS and not lint */ | 65 | #endif /* LIBC_SCCS and not lint */ |
| 66 | 66 | ||
| @@ -79,6 +79,8 @@ static char rcsid[] = "$OpenBSD: res_query.c,v 1.19 2002/06/27 09:55:49 itojun E | |||
| 79 | #include <string.h> | 79 | #include <string.h> |
| 80 | #include <unistd.h> | 80 | #include <unistd.h> |
| 81 | 81 | ||
| 82 | #include "thread_private.h" | ||
| 83 | |||
| 82 | #if PACKETSZ > 1024 | 84 | #if PACKETSZ > 1024 |
| 83 | #define MAXPACKET PACKETSZ | 85 | #define MAXPACKET PACKETSZ |
| 84 | #else | 86 | #else |
| @@ -106,31 +108,32 @@ res_query(name, class, type, answer, anslen) | |||
| 106 | u_char *answer; /* buffer to put answer */ | 108 | u_char *answer; /* buffer to put answer */ |
| 107 | int anslen; /* size of answer buffer */ | 109 | int anslen; /* size of answer buffer */ |
| 108 | { | 110 | { |
| 111 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 109 | u_char buf[MAXPACKET]; | 112 | u_char buf[MAXPACKET]; |
| 110 | register HEADER *hp = (HEADER *) answer; | 113 | register HEADER *hp = (HEADER *) answer; |
| 111 | int n; | 114 | int n; |
| 112 | 115 | ||
| 113 | hp->rcode = NOERROR; /* default */ | 116 | hp->rcode = NOERROR; /* default */ |
| 114 | 117 | ||
| 115 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) { | 118 | if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { |
| 116 | h_errno = NETDB_INTERNAL; | 119 | h_errno = NETDB_INTERNAL; |
| 117 | return (-1); | 120 | return (-1); |
| 118 | } | 121 | } |
| 119 | #ifdef DEBUG | 122 | #ifdef DEBUG |
| 120 | if (_res.options & RES_DEBUG) | 123 | if (_resp->options & RES_DEBUG) |
| 121 | printf(";; res_query(%s, %d, %d)\n", name, class, type); | 124 | printf(";; res_query(%s, %d, %d)\n", name, class, type); |
| 122 | #endif | 125 | #endif |
| 123 | 126 | ||
| 124 | n = res_mkquery(QUERY, name, class, type, NULL, 0, NULL, | 127 | n = res_mkquery(QUERY, name, class, type, NULL, 0, NULL, |
| 125 | buf, sizeof(buf)); | 128 | buf, sizeof(buf)); |
| 126 | if (n > 0 && ((_res.options & RES_USE_EDNS0) || | 129 | if (n > 0 && ((_resp->options & RES_USE_EDNS0) || |
| 127 | (_res.options & RES_USE_DNSSEC))) { | 130 | (_resp->options & RES_USE_DNSSEC))) { |
| 128 | n = res_opt(n, buf, sizeof(buf), anslen); | 131 | n = res_opt(n, buf, sizeof(buf), anslen); |
| 129 | } | 132 | } |
| 130 | 133 | ||
| 131 | if (n <= 0) { | 134 | if (n <= 0) { |
| 132 | #ifdef DEBUG | 135 | #ifdef DEBUG |
| 133 | if (_res.options & RES_DEBUG) | 136 | if (_resp->options & RES_DEBUG) |
| 134 | printf(";; res_query: mkquery failed\n"); | 137 | printf(";; res_query: mkquery failed\n"); |
| 135 | #endif | 138 | #endif |
| 136 | h_errno = NO_RECOVERY; | 139 | h_errno = NO_RECOVERY; |
| @@ -139,7 +142,7 @@ res_query(name, class, type, answer, anslen) | |||
| 139 | n = res_send(buf, n, answer, anslen); | 142 | n = res_send(buf, n, answer, anslen); |
| 140 | if (n < 0) { | 143 | if (n < 0) { |
| 141 | #ifdef DEBUG | 144 | #ifdef DEBUG |
| 142 | if (_res.options & RES_DEBUG) | 145 | if (_resp->options & RES_DEBUG) |
| 143 | printf(";; res_query: send error\n"); | 146 | printf(";; res_query: send error\n"); |
| 144 | #endif | 147 | #endif |
| 145 | h_errno = TRY_AGAIN; | 148 | h_errno = TRY_AGAIN; |
| @@ -148,7 +151,7 @@ res_query(name, class, type, answer, anslen) | |||
| 148 | 151 | ||
| 149 | if (hp->rcode != NOERROR || ntohs(hp->ancount) == 0) { | 152 | if (hp->rcode != NOERROR || ntohs(hp->ancount) == 0) { |
| 150 | #ifdef DEBUG | 153 | #ifdef DEBUG |
| 151 | if (_res.options & RES_DEBUG) | 154 | if (_resp->options & RES_DEBUG) |
| 152 | printf(";; rcode = %u, ancount=%u\n", hp->rcode, | 155 | printf(";; rcode = %u, ancount=%u\n", hp->rcode, |
| 153 | ntohs(hp->ancount)); | 156 | ntohs(hp->ancount)); |
| 154 | #endif | 157 | #endif |
| @@ -188,12 +191,13 @@ res_search(name, class, type, answer, anslen) | |||
| 188 | int anslen; /* size of answer */ | 191 | int anslen; /* size of answer */ |
| 189 | { | 192 | { |
| 190 | register const char *cp, * const *domain; | 193 | register const char *cp, * const *domain; |
| 194 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 191 | HEADER *hp = (HEADER *) answer; | 195 | HEADER *hp = (HEADER *) answer; |
| 192 | u_int dots; | 196 | u_int dots; |
| 193 | int trailing_dot, ret, saved_herrno; | 197 | int trailing_dot, ret, saved_herrno; |
| 194 | int got_nodata = 0, got_servfail = 0, tried_as_is = 0; | 198 | int got_nodata = 0, got_servfail = 0, tried_as_is = 0; |
| 195 | 199 | ||
| 196 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) { | 200 | if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { |
| 197 | h_errno = NETDB_INTERNAL; | 201 | h_errno = NETDB_INTERNAL; |
| 198 | return (-1); | 202 | return (-1); |
| 199 | } | 203 | } |
| @@ -217,7 +221,7 @@ res_search(name, class, type, answer, anslen) | |||
| 217 | * 'as is'. The threshold can be set with the "ndots" option. | 221 | * 'as is'. The threshold can be set with the "ndots" option. |
| 218 | */ | 222 | */ |
| 219 | saved_herrno = -1; | 223 | saved_herrno = -1; |
| 220 | if (dots >= _res.ndots) { | 224 | if (dots >= _resp->ndots) { |
| 221 | ret = res_querydomain(name, NULL, class, type, answer, anslen); | 225 | ret = res_querydomain(name, NULL, class, type, answer, anslen); |
| 222 | if (ret > 0) | 226 | if (ret > 0) |
| 223 | return (ret); | 227 | return (ret); |
| @@ -231,11 +235,11 @@ res_search(name, class, type, answer, anslen) | |||
| 231 | * - there is at least one dot, there is no trailing dot, | 235 | * - there is at least one dot, there is no trailing dot, |
| 232 | * and RES_DNSRCH is set. | 236 | * and RES_DNSRCH is set. |
| 233 | */ | 237 | */ |
| 234 | if ((!dots && (_res.options & RES_DEFNAMES)) || | 238 | if ((!dots && (_resp->options & RES_DEFNAMES)) || |
| 235 | (dots && !trailing_dot && (_res.options & RES_DNSRCH))) { | 239 | (dots && !trailing_dot && (_resp->options & RES_DNSRCH))) { |
| 236 | int done = 0; | 240 | int done = 0; |
| 237 | 241 | ||
| 238 | for (domain = (const char * const *)_res.dnsrch; | 242 | for (domain = (const char * const *)_resp->dnsrch; |
| 239 | *domain && !done; | 243 | *domain && !done; |
| 240 | domain++) { | 244 | domain++) { |
| 241 | 245 | ||
| @@ -284,7 +288,7 @@ res_search(name, class, type, answer, anslen) | |||
| 284 | /* if we got here for some reason other than DNSRCH, | 288 | /* if we got here for some reason other than DNSRCH, |
| 285 | * we only wanted one iteration of the loop, so stop. | 289 | * we only wanted one iteration of the loop, so stop. |
| 286 | */ | 290 | */ |
| 287 | if (!(_res.options & RES_DNSRCH)) | 291 | if (!(_resp->options & RES_DNSRCH)) |
| 288 | done++; | 292 | done++; |
| 289 | } | 293 | } |
| 290 | } | 294 | } |
| @@ -326,16 +330,17 @@ res_querydomain(name, domain, class, type, answer, anslen) | |||
| 326 | u_char *answer; /* buffer to put answer */ | 330 | u_char *answer; /* buffer to put answer */ |
| 327 | int anslen; /* size of answer */ | 331 | int anslen; /* size of answer */ |
| 328 | { | 332 | { |
| 333 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 329 | char nbuf[MAXDNAME*2+1+1]; | 334 | char nbuf[MAXDNAME*2+1+1]; |
| 330 | const char *longname = nbuf; | 335 | const char *longname = nbuf; |
| 331 | int n; | 336 | int n; |
| 332 | 337 | ||
| 333 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) { | 338 | if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { |
| 334 | h_errno = NETDB_INTERNAL; | 339 | h_errno = NETDB_INTERNAL; |
| 335 | return (-1); | 340 | return (-1); |
| 336 | } | 341 | } |
| 337 | #ifdef DEBUG | 342 | #ifdef DEBUG |
| 338 | if (_res.options & RES_DEBUG) | 343 | if (_resp->options & RES_DEBUG) |
| 339 | printf(";; res_querydomain(%s, %s, %d, %d)\n", | 344 | printf(";; res_querydomain(%s, %s, %d, %d)\n", |
| 340 | name, domain?domain:"<Nil>", class, type); | 345 | name, domain?domain:"<Nil>", class, type); |
| 341 | #endif | 346 | #endif |
| @@ -361,6 +366,7 @@ const char * | |||
| 361 | hostalias(name) | 366 | hostalias(name) |
| 362 | register const char *name; | 367 | register const char *name; |
| 363 | { | 368 | { |
| 369 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 364 | register char *cp1, *cp2; | 370 | register char *cp1, *cp2; |
| 365 | FILE *fp; | 371 | FILE *fp; |
| 366 | char *file; | 372 | char *file; |
| @@ -368,7 +374,7 @@ hostalias(name) | |||
| 368 | static char abuf[MAXDNAME]; | 374 | static char abuf[MAXDNAME]; |
| 369 | size_t len; | 375 | size_t len; |
| 370 | 376 | ||
| 371 | if (_res.options & RES_NOALIASES) | 377 | if (_resp->options & RES_NOALIASES) |
| 372 | return (NULL); | 378 | return (NULL); |
| 373 | file = getenv("HOSTALIASES"); | 379 | file = getenv("HOSTALIASES"); |
| 374 | if (issetugid() != 0 || file == NULL || (fp = fopen(file, "r")) == NULL) | 380 | if (issetugid() != 0 || file == NULL || (fp = fopen(file, "r")) == NULL) |
diff --git a/src/lib/libc/net/res_send.c b/src/lib/libc/net/res_send.c index b043e7c9fb..282675a533 100644 --- a/src/lib/libc/net/res_send.c +++ b/src/lib/libc/net/res_send.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: res_send.c,v 1.12 2002/09/06 18:35:12 deraadt Exp $ */ | 1 | /* $OpenBSD: res_send.c,v 1.13 2003/01/28 04:58:00 marc Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * ++Copyright++ 1985, 1989, 1993 | 4 | * ++Copyright++ 1985, 1989, 1993 |
| @@ -64,7 +64,7 @@ | |||
| 64 | static char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93"; | 64 | static char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93"; |
| 65 | static char rcsid[] = "$From: res_send.c,v 8.12 1996/10/08 04:51:06 vixie Exp $"; | 65 | static char rcsid[] = "$From: res_send.c,v 8.12 1996/10/08 04:51:06 vixie Exp $"; |
| 66 | #else | 66 | #else |
| 67 | static char rcsid[] = "$OpenBSD: res_send.c,v 1.12 2002/09/06 18:35:12 deraadt Exp $"; | 67 | static char rcsid[] = "$OpenBSD: res_send.c,v 1.13 2003/01/28 04:58:00 marc Exp $"; |
| 68 | #endif | 68 | #endif |
| 69 | #endif /* LIBC_SCCS and not lint */ | 69 | #endif /* LIBC_SCCS and not lint */ |
| 70 | 70 | ||
| @@ -96,6 +96,8 @@ static char rcsid[] = "$OpenBSD: res_send.c,v 1.12 2002/09/06 18:35:12 deraadt E | |||
| 96 | #include <string.h> | 96 | #include <string.h> |
| 97 | #include <unistd.h> | 97 | #include <unistd.h> |
| 98 | 98 | ||
| 99 | #include "thread_private.h" | ||
| 100 | |||
| 99 | static int s = -1; /* socket used for communications */ | 101 | static int s = -1; /* socket used for communications */ |
| 100 | static int connected = 0; /* is the socket connected */ | 102 | static int connected = 0; /* is the socket connected */ |
| 101 | static int vc = 0; /* is the socket a virtual ciruit? */ | 103 | static int vc = 0; /* is the socket a virtual ciruit? */ |
| @@ -136,9 +138,10 @@ static void Perror(FILE *, char *, int); | |||
| 136 | int error; | 138 | int error; |
| 137 | struct sockaddr *address; | 139 | struct sockaddr *address; |
| 138 | { | 140 | { |
| 141 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 139 | int save = errno; | 142 | int save = errno; |
| 140 | 143 | ||
| 141 | if (_res.options & RES_DEBUG) { | 144 | if (_resp->options & RES_DEBUG) { |
| 142 | if (getnameinfo(address, address->sa_len, abuf, sizeof(abuf), | 145 | if (getnameinfo(address, address->sa_len, abuf, sizeof(abuf), |
| 143 | pbuf, sizeof(pbuf), | 146 | pbuf, sizeof(pbuf), |
| 144 | NI_NUMERICHOST|NI_NUMERICSERV|NI_WITHSCOPEID) != 0) { | 147 | NI_NUMERICHOST|NI_NUMERICSERV|NI_WITHSCOPEID) != 0) { |
| @@ -156,9 +159,10 @@ static void Perror(FILE *, char *, int); | |||
| 156 | char *string; | 159 | char *string; |
| 157 | int error; | 160 | int error; |
| 158 | { | 161 | { |
| 162 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 159 | int save = errno; | 163 | int save = errno; |
| 160 | 164 | ||
| 161 | if (_res.options & RES_DEBUG) { | 165 | if (_resp->options & RES_DEBUG) { |
| 162 | fprintf(file, "res_send: %s: %s\n", | 166 | fprintf(file, "res_send: %s: %s\n", |
| 163 | string, strerror(error)); | 167 | string, strerror(error)); |
| 164 | } | 168 | } |
| @@ -195,30 +199,33 @@ static struct sockaddr * | |||
| 195 | get_nsaddr(n) | 199 | get_nsaddr(n) |
| 196 | size_t n; | 200 | size_t n; |
| 197 | { | 201 | { |
| 202 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 203 | struct __res_state_ext *_res_extp = _THREAD_PRIVATE(_res_ext, _res_ext, | ||
| 204 | &_res_ext); | ||
| 198 | 205 | ||
| 199 | if (!_res.nsaddr_list[n].sin_family) { | 206 | if (!_resp->nsaddr_list[n].sin_family) { |
| 200 | /* | 207 | /* |
| 201 | * - _res_ext.nsaddr_list[n] holds an address that is larger | 208 | * - _res_extp->nsaddr_list[n] holds an address that is larger |
| 202 | * than struct sockaddr, and | 209 | * than struct sockaddr, and |
| 203 | * - user code did not update _res.nsaddr_list[n]. | 210 | * - user code did not update _resp->nsaddr_list[n]. |
| 204 | */ | 211 | */ |
| 205 | return (struct sockaddr *)&_res_ext.nsaddr_list[n]; | 212 | return (struct sockaddr *)&_res_extp->nsaddr_list[n]; |
| 206 | } else { | 213 | } else { |
| 207 | /* | 214 | /* |
| 208 | * - user code updated _res.nsaddr_list[n], or | 215 | * - user code updated _res.nsaddr_list[n], or |
| 209 | * - _res.nsaddr_list[n] has the same content as | 216 | * - _resp->nsaddr_list[n] has the same content as |
| 210 | * _res_ext.nsaddr_list[n]. | 217 | * _res_extp->nsaddr_list[n]. |
| 211 | */ | 218 | */ |
| 212 | return (struct sockaddr *)&_res.nsaddr_list[n]; | 219 | return (struct sockaddr *)&_resp->nsaddr_list[n]; |
| 213 | } | 220 | } |
| 214 | } | 221 | } |
| 215 | #else | 222 | #else |
| 216 | #define get_nsaddr(n) ((struct sockaddr *)&_res.nsaddr_list[(n)]) | 223 | #define get_nsaddr(n) ((struct sockaddr *)&_resp->nsaddr_list[(n)]) |
| 217 | #endif | 224 | #endif |
| 218 | 225 | ||
| 219 | /* int | 226 | /* int |
| 220 | * res_isourserver(ina) | 227 | * res_isourserver(ina) |
| 221 | * looks up "ina" in _res.ns_addr_list[] | 228 | * looks up "ina" in _resp->ns_addr_list[] |
| 222 | * returns: | 229 | * returns: |
| 223 | * 0 : not found | 230 | * 0 : not found |
| 224 | * >0 : found | 231 | * >0 : found |
| @@ -229,6 +236,7 @@ int | |||
| 229 | res_isourserver(inp) | 236 | res_isourserver(inp) |
| 230 | const struct sockaddr_in *inp; | 237 | const struct sockaddr_in *inp; |
| 231 | { | 238 | { |
| 239 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 232 | #ifdef INET6 | 240 | #ifdef INET6 |
| 233 | const struct sockaddr_in6 *in6p = (const struct sockaddr_in6 *)inp; | 241 | const struct sockaddr_in6 *in6p = (const struct sockaddr_in6 *)inp; |
| 234 | const struct sockaddr_in6 *srv6; | 242 | const struct sockaddr_in6 *srv6; |
| @@ -240,7 +248,7 @@ res_isourserver(inp) | |||
| 240 | switch (inp->sin_family) { | 248 | switch (inp->sin_family) { |
| 241 | #ifdef INET6 | 249 | #ifdef INET6 |
| 242 | case AF_INET6: | 250 | case AF_INET6: |
| 243 | for (ns = 0; ns < _res.nscount; ns++) { | 251 | for (ns = 0; ns < _resp->nscount; ns++) { |
| 244 | srv6 = (struct sockaddr_in6 *)get_nsaddr(ns); | 252 | srv6 = (struct sockaddr_in6 *)get_nsaddr(ns); |
| 245 | if (srv6->sin6_family == in6p->sin6_family && | 253 | if (srv6->sin6_family == in6p->sin6_family && |
| 246 | srv6->sin6_port == in6p->sin6_port && | 254 | srv6->sin6_port == in6p->sin6_port && |
| @@ -255,7 +263,7 @@ res_isourserver(inp) | |||
| 255 | break; | 263 | break; |
| 256 | #endif | 264 | #endif |
| 257 | case AF_INET: | 265 | case AF_INET: |
| 258 | for (ns = 0; ns < _res.nscount; ns++) { | 266 | for (ns = 0; ns < _resp->nscount; ns++) { |
| 259 | srv = (struct sockaddr_in *)get_nsaddr(ns); | 267 | srv = (struct sockaddr_in *)get_nsaddr(ns); |
| 260 | if (srv->sin_family == inp->sin_family && | 268 | if (srv->sin_family == inp->sin_family && |
| 261 | srv->sin_port == inp->sin_port && | 269 | srv->sin_port == inp->sin_port && |
| @@ -351,19 +359,20 @@ res_send(buf, buflen, ans, anssiz) | |||
| 351 | u_char *ans; | 359 | u_char *ans; |
| 352 | int anssiz; | 360 | int anssiz; |
| 353 | { | 361 | { |
| 362 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 354 | HEADER *hp = (HEADER *) buf; | 363 | HEADER *hp = (HEADER *) buf; |
| 355 | HEADER *anhp = (HEADER *) ans; | 364 | HEADER *anhp = (HEADER *) ans; |
| 356 | int gotsomewhere, connreset, terrno, try, v_circuit, resplen, ns; | 365 | int gotsomewhere, connreset, terrno, try, v_circuit, resplen, ns; |
| 357 | register int n; | 366 | register int n; |
| 358 | u_int badns; /* XXX NSMAX can't exceed #/bits in this var */ | 367 | u_int badns; /* XXX NSMAX can't exceed #/bits in this var */ |
| 359 | 368 | ||
| 360 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) { | 369 | if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { |
| 361 | /* errno should have been set by res_init() in this case. */ | 370 | /* errno should have been set by res_init() in this case. */ |
| 362 | return (-1); | 371 | return (-1); |
| 363 | } | 372 | } |
| 364 | DprintQ((_res.options & RES_DEBUG) || (_res.pfcode & RES_PRF_QUERY), | 373 | DprintQ((_resp->options & RES_DEBUG) || (_resp->pfcode & RES_PRF_QUERY), |
| 365 | (stdout, ";; res_send()\n"), buf, buflen); | 374 | (stdout, ";; res_send()\n"), buf, buflen); |
| 366 | v_circuit = (_res.options & RES_USEVC) || buflen > PACKETSZ; | 375 | v_circuit = (_resp->options & RES_USEVC) || buflen > PACKETSZ; |
| 367 | gotsomewhere = 0; | 376 | gotsomewhere = 0; |
| 368 | connreset = 0; | 377 | connreset = 0; |
| 369 | terrno = ETIMEDOUT; | 378 | terrno = ETIMEDOUT; |
| @@ -372,8 +381,8 @@ res_send(buf, buflen, ans, anssiz) | |||
| 372 | /* | 381 | /* |
| 373 | * Send request, RETRY times, or until successful | 382 | * Send request, RETRY times, or until successful |
| 374 | */ | 383 | */ |
| 375 | for (try = 0; try < _res.retry; try++) { | 384 | for (try = 0; try < _resp->retry; try++) { |
| 376 | for (ns = 0; ns < _res.nscount; ns++) { | 385 | for (ns = 0; ns < _resp->nscount; ns++) { |
| 377 | struct sockaddr *nsap = get_nsaddr(ns); | 386 | struct sockaddr *nsap = get_nsaddr(ns); |
| 378 | socklen_t salen; | 387 | socklen_t salen; |
| 379 | 388 | ||
| @@ -425,7 +434,7 @@ res_send(buf, buflen, ans, anssiz) | |||
| 425 | } while (!done); | 434 | } while (!done); |
| 426 | } | 435 | } |
| 427 | 436 | ||
| 428 | Dprint((_res.options & RES_DEBUG) && | 437 | Dprint((_resp->options & RES_DEBUG) && |
| 429 | getnameinfo(nsap, salen, abuf, sizeof(abuf), | 438 | getnameinfo(nsap, salen, abuf, sizeof(abuf), |
| 430 | NULL, 0, NI_NUMERICHOST | NI_WITHSCOPEID) == 0, | 439 | NULL, 0, NI_NUMERICHOST | NI_WITHSCOPEID) == 0, |
| 431 | (stdout, ";; Querying server (# %d) address = %s\n", | 440 | (stdout, ";; Querying server (# %d) address = %s\n", |
| @@ -441,7 +450,7 @@ res_send(buf, buflen, ans, anssiz) | |||
| 441 | * Use virtual circuit; | 450 | * Use virtual circuit; |
| 442 | * at most one attempt per server. | 451 | * at most one attempt per server. |
| 443 | */ | 452 | */ |
| 444 | try = _res.retry; | 453 | try = _resp->retry; |
| 445 | truncated = 0; | 454 | truncated = 0; |
| 446 | if ((s < 0) || (!vc) || (af != nsap->sa_family)) { | 455 | if ((s < 0) || (!vc) || (af != nsap->sa_family)) { |
| 447 | if (s >= 0) | 456 | if (s >= 0) |
| @@ -520,7 +529,7 @@ read_len: | |||
| 520 | } | 529 | } |
| 521 | resplen = _getshort(ans); | 530 | resplen = _getshort(ans); |
| 522 | if (resplen > anssiz) { | 531 | if (resplen > anssiz) { |
| 523 | Dprint(_res.options & RES_DEBUG, | 532 | Dprint(_resp->options & RES_DEBUG, |
| 524 | (stdout, ";; response truncated\n") | 533 | (stdout, ";; response truncated\n") |
| 525 | ); | 534 | ); |
| 526 | truncated = 1; | 535 | truncated = 1; |
| @@ -566,8 +575,8 @@ read_len: | |||
| 566 | * wait for the correct one. | 575 | * wait for the correct one. |
| 567 | */ | 576 | */ |
| 568 | if (hp->id != anhp->id) { | 577 | if (hp->id != anhp->id) { |
| 569 | DprintQ((_res.options & RES_DEBUG) || | 578 | DprintQ((_resp->options & RES_DEBUG) || |
| 570 | (_res.pfcode & RES_PRF_REPLY), | 579 | (_resp->pfcode & RES_PRF_REPLY), |
| 571 | (stdout, ";; old answer (unexpected):\n"), | 580 | (stdout, ";; old answer (unexpected):\n"), |
| 572 | ans, (resplen>anssiz)?anssiz:resplen); | 581 | ans, (resplen>anssiz)?anssiz:resplen); |
| 573 | goto read_len; | 582 | goto read_len; |
| @@ -625,8 +634,8 @@ read_len: | |||
| 625 | * as we wish to receive answers from the first | 634 | * as we wish to receive answers from the first |
| 626 | * server to respond. | 635 | * server to respond. |
| 627 | */ | 636 | */ |
| 628 | if (!(_res.options & RES_INSECURE1) && | 637 | if (!(_resp->options & RES_INSECURE1) && |
| 629 | (_res.nscount == 1 || (try == 0 && ns == 0))) { | 638 | (_resp->nscount == 1 || (try == 0 && ns == 0))) { |
| 630 | /* | 639 | /* |
| 631 | * Connect only if we are sure we won't | 640 | * Connect only if we are sure we won't |
| 632 | * receive a response from another server. | 641 | * receive a response from another server. |
| @@ -673,7 +682,7 @@ read_len: | |||
| 673 | goto bad_dg_sock; | 682 | goto bad_dg_sock; |
| 674 | (void) dup2(s1, s); | 683 | (void) dup2(s1, s); |
| 675 | (void) close(s1); | 684 | (void) close(s1); |
| 676 | Dprint(_res.options & RES_DEBUG, | 685 | Dprint(_resp->options & RES_DEBUG, |
| 677 | (stdout, ";; new DG socket\n")) | 686 | (stdout, ";; new DG socket\n")) |
| 678 | #endif | 687 | #endif |
| 679 | #ifdef IPV6_MINMTU | 688 | #ifdef IPV6_MINMTU |
| @@ -699,9 +708,9 @@ read_len: | |||
| 699 | /* | 708 | /* |
| 700 | * Wait for reply | 709 | * Wait for reply |
| 701 | */ | 710 | */ |
| 702 | timeout.tv_sec = (_res.retrans << try); | 711 | timeout.tv_sec = (_resp->retrans << try); |
| 703 | if (try > 0) | 712 | if (try > 0) |
| 704 | timeout.tv_sec /= _res.nscount; | 713 | timeout.tv_sec /= _resp->nscount; |
| 705 | if ((long) timeout.tv_sec <= 0) | 714 | if ((long) timeout.tv_sec <= 0) |
| 706 | timeout.tv_sec = 1; | 715 | timeout.tv_sec = 1; |
| 707 | timeout.tv_usec = 0; | 716 | timeout.tv_usec = 0; |
| @@ -727,7 +736,7 @@ read_len: | |||
| 727 | /* | 736 | /* |
| 728 | * timeout | 737 | * timeout |
| 729 | */ | 738 | */ |
| 730 | Dprint(_res.options & RES_DEBUG, | 739 | Dprint(_resp->options & RES_DEBUG, |
| 731 | (stdout, ";; timeout\n")); | 740 | (stdout, ";; timeout\n")); |
| 732 | gotsomewhere = 1; | 741 | gotsomewhere = 1; |
| 733 | res_close(); | 742 | res_close(); |
| @@ -749,28 +758,28 @@ read_len: | |||
| 749 | * XXX - potential security hazard could | 758 | * XXX - potential security hazard could |
| 750 | * be detected here. | 759 | * be detected here. |
| 751 | */ | 760 | */ |
| 752 | DprintQ((_res.options & RES_DEBUG) || | 761 | DprintQ((_resp->options & RES_DEBUG) || |
| 753 | (_res.pfcode & RES_PRF_REPLY), | 762 | (_resp->pfcode & RES_PRF_REPLY), |
| 754 | (stdout, ";; old answer:\n"), | 763 | (stdout, ";; old answer:\n"), |
| 755 | ans, (resplen>anssiz)?anssiz:resplen); | 764 | ans, (resplen>anssiz)?anssiz:resplen); |
| 756 | goto wait; | 765 | goto wait; |
| 757 | } | 766 | } |
| 758 | #if CHECK_SRVR_ADDR | 767 | #if CHECK_SRVR_ADDR |
| 759 | if (!(_res.options & RES_INSECURE1) && | 768 | if (!(_resp->options & RES_INSECURE1) && |
| 760 | !res_isourserver((struct sockaddr_in *)&from)) { | 769 | !res_isourserver((struct sockaddr_in *)&from)) { |
| 761 | /* | 770 | /* |
| 762 | * response from wrong server? ignore it. | 771 | * response from wrong server? ignore it. |
| 763 | * XXX - potential security hazard could | 772 | * XXX - potential security hazard could |
| 764 | * be detected here. | 773 | * be detected here. |
| 765 | */ | 774 | */ |
| 766 | DprintQ((_res.options & RES_DEBUG) || | 775 | DprintQ((_resp->options & RES_DEBUG) || |
| 767 | (_res.pfcode & RES_PRF_REPLY), | 776 | (_resp->pfcode & RES_PRF_REPLY), |
| 768 | (stdout, ";; not our server:\n"), | 777 | (stdout, ";; not our server:\n"), |
| 769 | ans, (resplen>anssiz)?anssiz:resplen); | 778 | ans, (resplen>anssiz)?anssiz:resplen); |
| 770 | goto wait; | 779 | goto wait; |
| 771 | } | 780 | } |
| 772 | #endif | 781 | #endif |
| 773 | if (!(_res.options & RES_INSECURE2) && | 782 | if (!(_resp->options & RES_INSECURE2) && |
| 774 | !res_queriesmatch(buf, buf + buflen, | 783 | !res_queriesmatch(buf, buf + buflen, |
| 775 | ans, ans + anssiz)) { | 784 | ans, ans + anssiz)) { |
| 776 | /* | 785 | /* |
| @@ -778,8 +787,8 @@ read_len: | |||
| 778 | * XXX - potential security hazard could | 787 | * XXX - potential security hazard could |
| 779 | * be detected here. | 788 | * be detected here. |
| 780 | */ | 789 | */ |
| 781 | DprintQ((_res.options & RES_DEBUG) || | 790 | DprintQ((_resp->options & RES_DEBUG) || |
| 782 | (_res.pfcode & RES_PRF_REPLY), | 791 | (_resp->pfcode & RES_PRF_REPLY), |
| 783 | (stdout, ";; wrong query name:\n"), | 792 | (stdout, ";; wrong query name:\n"), |
| 784 | ans, (resplen>anssiz)?anssiz:resplen); | 793 | ans, (resplen>anssiz)?anssiz:resplen); |
| 785 | goto wait; | 794 | goto wait; |
| @@ -787,33 +796,33 @@ read_len: | |||
| 787 | if (anhp->rcode == SERVFAIL || | 796 | if (anhp->rcode == SERVFAIL || |
| 788 | anhp->rcode == NOTIMP || | 797 | anhp->rcode == NOTIMP || |
| 789 | anhp->rcode == REFUSED) { | 798 | anhp->rcode == REFUSED) { |
| 790 | DprintQ(_res.options & RES_DEBUG, | 799 | DprintQ(_resp->options & RES_DEBUG, |
| 791 | (stdout, "server rejected query:\n"), | 800 | (stdout, "server rejected query:\n"), |
| 792 | ans, (resplen>anssiz)?anssiz:resplen); | 801 | ans, (resplen>anssiz)?anssiz:resplen); |
| 793 | badns |= (1 << ns); | 802 | badns |= (1 << ns); |
| 794 | res_close(); | 803 | res_close(); |
| 795 | /* don't retry if called from dig */ | 804 | /* don't retry if called from dig */ |
| 796 | if (!_res.pfcode) | 805 | if (!_resp->pfcode) |
| 797 | goto next_ns; | 806 | goto next_ns; |
| 798 | } | 807 | } |
| 799 | if (!(_res.options & RES_IGNTC) && anhp->tc) { | 808 | if (!(_resp->options & RES_IGNTC) && anhp->tc) { |
| 800 | /* | 809 | /* |
| 801 | * get rest of answer; | 810 | * get rest of answer; |
| 802 | * use TCP with same server. | 811 | * use TCP with same server. |
| 803 | */ | 812 | */ |
| 804 | Dprint(_res.options & RES_DEBUG, | 813 | Dprint(_resp->options & RES_DEBUG, |
| 805 | (stdout, ";; truncated answer\n")); | 814 | (stdout, ";; truncated answer\n")); |
| 806 | v_circuit = 1; | 815 | v_circuit = 1; |
| 807 | res_close(); | 816 | res_close(); |
| 808 | goto same_ns; | 817 | goto same_ns; |
| 809 | } | 818 | } |
| 810 | } /*if vc/dg*/ | 819 | } /*if vc/dg*/ |
| 811 | Dprint((_res.options & RES_DEBUG) || | 820 | Dprint((_resp->options & RES_DEBUG) || |
| 812 | ((_res.pfcode & RES_PRF_REPLY) && | 821 | ((_resp->pfcode & RES_PRF_REPLY) && |
| 813 | (_res.pfcode & RES_PRF_HEAD1)), | 822 | (_resp->pfcode & RES_PRF_HEAD1)), |
| 814 | (stdout, ";; got answer:\n")); | 823 | (stdout, ";; got answer:\n")); |
| 815 | DprintQ((_res.options & RES_DEBUG) || | 824 | DprintQ((_resp->options & RES_DEBUG) || |
| 816 | (_res.pfcode & RES_PRF_REPLY), | 825 | (_resp->pfcode & RES_PRF_REPLY), |
| 817 | (stdout, "%s", ""), | 826 | (stdout, "%s", ""), |
| 818 | ans, (resplen>anssiz)?anssiz:resplen); | 827 | ans, (resplen>anssiz)?anssiz:resplen); |
| 819 | /* | 828 | /* |
| @@ -824,8 +833,8 @@ read_len: | |||
| 824 | * or if we haven't been asked to keep a socket open, | 833 | * or if we haven't been asked to keep a socket open, |
| 825 | * close the socket. | 834 | * close the socket. |
| 826 | */ | 835 | */ |
| 827 | if ((v_circuit && (!(_res.options & RES_USEVC) || ns != 0)) || | 836 | if ((v_circuit && (!(_resp->options & RES_USEVC) || ns != 0)) || |
| 828 | !(_res.options & RES_STAYOPEN)) { | 837 | !(_resp->options & RES_STAYOPEN)) { |
| 829 | res_close(); | 838 | res_close(); |
| 830 | } | 839 | } |
| 831 | if (Rhook) { | 840 | if (Rhook) { |
diff --git a/src/lib/libc/net/sethostent.c b/src/lib/libc/net/sethostent.c index 5392a2f11b..40a5a80962 100644 --- a/src/lib/libc/net/sethostent.c +++ b/src/lib/libc/net/sethostent.c | |||
| @@ -32,7 +32,7 @@ | |||
| 32 | */ | 32 | */ |
| 33 | 33 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | static char rcsid[] = "$OpenBSD: sethostent.c,v 1.4 1997/03/15 21:53:50 pefo Exp $"; | 35 | static char rcsid[] = "$OpenBSD: sethostent.c,v 1.5 2003/01/28 04:58:00 marc Exp $"; |
| 36 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
| 37 | 37 | ||
| 38 | #include <sys/param.h> | 38 | #include <sys/param.h> |
| @@ -41,20 +41,25 @@ static char rcsid[] = "$OpenBSD: sethostent.c,v 1.4 1997/03/15 21:53:50 pefo Exp | |||
| 41 | #include <netdb.h> | 41 | #include <netdb.h> |
| 42 | #include <resolv.h> | 42 | #include <resolv.h> |
| 43 | 43 | ||
| 44 | #include "thread_private.h" | ||
| 45 | |||
| 44 | void | 46 | void |
| 45 | sethostent(stayopen) | 47 | sethostent(stayopen) |
| 46 | int stayopen; | 48 | int stayopen; |
| 47 | { | 49 | { |
| 50 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 48 | 51 | ||
| 49 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) | 52 | if ((_resp->options & RES_INIT) == 0 && res_init() == -1) |
| 50 | return; | 53 | return; |
| 51 | if (stayopen) | 54 | if (stayopen) |
| 52 | _res.options |= RES_STAYOPEN | RES_USEVC; | 55 | _resp->options |= RES_STAYOPEN | RES_USEVC; |
| 53 | } | 56 | } |
| 54 | 57 | ||
| 55 | void | 58 | void |
| 56 | endhostent() | 59 | endhostent() |
| 57 | { | 60 | { |
| 58 | _res.options &= ~(RES_STAYOPEN | RES_USEVC); | 61 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); |
| 62 | |||
| 63 | _resp->options &= ~(RES_STAYOPEN | RES_USEVC); | ||
| 59 | res_close(); | 64 | res_close(); |
| 60 | } | 65 | } |
