diff options
author | Ulrich Drepper <drepper@redhat.com> | 2002-10-17 21:51:21 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2002-10-17 21:51:21 +0000 |
commit | 0420d8885a4889dca3b874c934fd5f42f2e99e5f (patch) | |
tree | dd8aecefe9a5f21d26df11cbc7f9c1dc6f2f5fd9 /resolv/nss_dns | |
parent | d025fe269abcab6903b3973d193a8678228301e8 (diff) | |
download | glibc-0420d8885a4889dca3b874c934fd5f42f2e99e5f.tar glibc-0420d8885a4889dca3b874c934fd5f42f2e99e5f.tar.gz glibc-0420d8885a4889dca3b874c934fd5f42f2e99e5f.tar.bz2 glibc-0420d8885a4889dca3b874c934fd5f42f2e99e5f.zip |
Update.
2002-10-15 Jakub Jelinek <jakub@redhat.com>
* include/resolv.h (__libc_res_nquery, __libc_res_nsearch,
__libc_res_nsend): New prototypes.
* resolv/res_query.c (QUERYSIZE): Define.
(__libc_res_nquery): Renamed from res_nquery. Added answerp
argument. Allocate only QUERYSIZE bytes first, if res_nmkquery
fails use MAXPACKET buffer. Call __libc_res_nsend instead of
res_nsend, pass answerp.
(res_nquery): Changed into wrapper around __libc_res_nquery.
(__libc_res_nsearch): Renamed from res_nsearch. Added answerp
argument. Call __libc_res_nquerydomain and __libc_res_nquery
instead of the non-__libc_ variants, pass them answerp.
(res_nsearch): Changed into wrapper around __libc_res_nsearch.
(__libc_res_nquerydomain): Renamed from res_nquerydomain.
Added answerp argument. Call __libc_res_nquery instead of
res_nquery, pass answerp.
(res_nquerydomain): Changed into wrapper around
__libc_res_nquerydomain.
* resolv/res_send.c: Include sys/ioctl.h.
(MAXPACKET): Define.
(send_vc): Change arguments. Reallocate answer buffer if it is
too small.
(send_dg): Likewise.
(__libc_res_nsend): Renamed from res_nsend. Added ansp argument.
Reallocate answer buffer if it is too small and hooks are in use.
Adjust calls to send_vc and send_dg.
(res_nsend): Changed into wrapper around __libc_res_nsend.
* resolv/nss_dns/dns-host.c (_nss_dns_gethostbyname2_r): Allocate
just 1K answer buffer on the stack, use __libc_res_nsearch instead
of res_nsearch.
(_nss_dns_gethostbyaddr_r): Similarly with __libc_res_nquery.
* resolv/nss_dns/dns-network.c (_nss_dns_getnetbyaddr_r): Likewise.
(_nss_dns_getnetbyname_r): Similarly with __libc_res_nsearch.
* resolv/gethnamaddr.c (gethostbyname2): Likewise.
(gethostbyaddr): Similarly with __libc_res_nquery.
* resolv/Versions (libresolv): Export __libc_res_nquery and
__libc_res_nsearch at GLIBC_PRIVATE.
Diffstat (limited to 'resolv/nss_dns')
-rw-r--r-- | resolv/nss_dns/dns-host.c | 60 | ||||
-rw-r--r-- | resolv/nss_dns/dns-network.c | 50 |
2 files changed, 34 insertions, 76 deletions
diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c index 39eccabbdf..b01dc54993 100644 --- a/resolv/nss_dns/dns-host.c +++ b/resolv/nss_dns/dns-host.c @@ -132,11 +132,11 @@ _nss_dns_gethostbyname2_r (const char *name, int af, struct hostent *result, char *buffer, size_t buflen, int *errnop, int *h_errnop) { - querybuf *host_buffer; + querybuf *host_buffer, *orig_host_buffer; char tmp[NS_MAXDNAME]; int size, type, n; const char *cp; - int map = 0, use_malloc = 0; + int map = 0; int olderr = errno; enum nss_status status; @@ -170,21 +170,10 @@ _nss_dns_gethostbyname2_r (const char *name, int af, struct hostent *result, && (cp = res_hostalias (&_res, name, tmp, sizeof (tmp))) != NULL) name = cp; - if (!__libc_use_alloca (MAXPACKET)) - { - host_buffer = (querybuf *) malloc (sizeof (querybuf)); - if (host_buffer == NULL) - { - *errnop = ENOMEM; - return NSS_STATUS_UNAVAIL; - } - use_malloc = 1; - } - else - host_buffer = (querybuf *) alloca (sizeof (querybuf)); + host_buffer = orig_host_buffer = (querybuf *) alloca (1024); - n = res_nsearch (&_res, name, C_IN, type, host_buffer->buf, - sizeof (host_buffer->buf)); + n = __libc_res_nsearch (&_res, name, C_IN, type, host_buffer->buf, + 1024, (u_char **) &host_buffer); if (n < 0) { enum nss_status status = (errno == ECONNREFUSED @@ -199,12 +188,13 @@ _nss_dns_gethostbyname2_r (const char *name, int af, struct hostent *result, by having the RES_USE_INET6 bit in _res.options set, we try another lookup. */ if (af == AF_INET6 && (_res.options & RES_USE_INET6)) - n = res_nsearch (&_res, name, C_IN, T_A, host_buffer->buf, - sizeof (host_buffer->buf)); + n = __libc_res_nsearch (&_res, name, C_IN, T_A, host_buffer->buf, + host_buffer != orig_host_buffer + ? MAXPACKET : 1024, (u_char **) &host_buffer); if (n < 0) { - if (use_malloc) + if (host_buffer != orig_host_buffer) free (host_buffer); return status; } @@ -217,7 +207,7 @@ _nss_dns_gethostbyname2_r (const char *name, int af, struct hostent *result, status = getanswer_r (host_buffer, n, name, type, result, buffer, buflen, errnop, h_errnop, map); - if (use_malloc) + if (host_buffer != orig_host_buffer) free (host_buffer); return status; } @@ -257,10 +247,10 @@ _nss_dns_gethostbyaddr_r (const void *addr, socklen_t len, int af, char *h_addr_ptrs[MAX_NR_ADDRS + 1]; char linebuffer[0]; } *host_data = (struct host_data *) buffer; - querybuf *host_buffer; + querybuf *host_buffer, *orig_host_buffer; char qbuf[MAXDNAME+1], *qp = NULL; size_t size; - int n, status, use_malloc = 0; + int n, status; int olderr = errno; if ((_res.options & RES_INIT) == 0 && __res_ninit (&_res) == -1) @@ -315,39 +305,29 @@ _nss_dns_gethostbyaddr_r (const void *addr, socklen_t len, int af, break; } - if (!__libc_use_alloca (MAXPACKET)) - { - host_buffer = (querybuf *) malloc (sizeof (querybuf)); - if (host_buffer == NULL) - { - *errnop = ENOMEM; - return NSS_STATUS_UNAVAIL; - } - use_malloc = 1; - } - else - host_buffer = (querybuf *) alloca (sizeof (querybuf)); + host_buffer = orig_host_buffer = (querybuf *) alloca (1024); - n = res_nquery (&_res, qbuf, C_IN, T_PTR, host_buffer->buf, - sizeof (host_buffer->buf)); + n = __libc_res_nquery (&_res, qbuf, C_IN, T_PTR, host_buffer->buf, + 1024, (u_char **) &host_buffer); if (n < 0 && af == AF_INET6) { strcpy (qp, "ip6.int"); - n = res_nquery (&_res, qbuf, C_IN, T_PTR, host_buffer->buf, - sizeof (host_buffer->buf)); + n = __libc_res_nquery (&_res, qbuf, C_IN, T_PTR, host_buffer->buf, + host_buffer != orig_host_buffer + ? MAXPACKET : 1024, (u_char **) &host_buffer); } if (n < 0) { *h_errnop = h_errno; __set_errno (olderr); - if (use_malloc) + if (host_buffer != orig_host_buffer) free (host_buffer); return errno == ECONNREFUSED ? NSS_STATUS_UNAVAIL : NSS_STATUS_NOTFOUND; } status = getanswer_r (host_buffer, n, qbuf, T_PTR, result, buffer, buflen, errnop, h_errnop, 0 /* XXX */); - if (use_malloc) + if (host_buffer != orig_host_buffer) free (host_buffer); if (status != NSS_STATUS_SUCCESS) { diff --git a/resolv/nss_dns/dns-network.c b/resolv/nss_dns/dns-network.c index 9a366aca65..5956c84382 100644 --- a/resolv/nss_dns/dns-network.c +++ b/resolv/nss_dns/dns-network.c @@ -110,8 +110,8 @@ _nss_dns_getnetbyname_r (const char *name, struct netent *result, int *herrnop) { /* Return entry for network with NAME. */ - querybuf *net_buffer; - int anslen, use_malloc = 0; + querybuf *net_buffer, *orig_net_buffer; + int anslen; char *qbuf; enum nss_status status; @@ -120,26 +120,15 @@ _nss_dns_getnetbyname_r (const char *name, struct netent *result, qbuf = strdupa (name); - if (!__libc_use_alloca (MAXPACKET)) - { - net_buffer = (querybuf *) malloc (sizeof (querybuf)); - if (net_buffer == NULL) - { - *errnop = ENOMEM; - return NSS_STATUS_UNAVAIL; - } - use_malloc = 1; - } - else - net_buffer = (querybuf *) alloca (sizeof (querybuf)); + net_buffer = orig_net_buffer = (querybuf *) alloca (1024); - anslen = res_nsearch (&_res, qbuf, C_IN, T_PTR, net_buffer->buf, - sizeof (net_buffer->buf)); + anslen = __libc_res_nsearch (&_res, qbuf, C_IN, T_PTR, net_buffer->buf, + 1024, (u_char **) &net_buffer); if (anslen < 0) { /* Nothing found. */ *errnop = errno; - if (use_malloc) + if (net_buffer != orig_net_buffer) free (net_buffer); return (errno == ECONNREFUSED || errno == EPFNOSUPPORT @@ -148,7 +137,7 @@ _nss_dns_getnetbyname_r (const char *name, struct netent *result, } status = getanswer_r (net_buffer, anslen, result, buffer, buflen, BYNAME); - if (use_malloc) + if (net_buffer != orig_net_buffer) free (net_buffer); return status; } @@ -161,10 +150,10 @@ _nss_dns_getnetbyaddr_r (uint32_t net, int type, struct netent *result, { /* Return entry for network with NAME. */ enum nss_status status; - querybuf *net_buffer; + querybuf *net_buffer, *orig_net_buffer; unsigned int net_bytes[4]; char qbuf[MAXDNAME]; - int cnt, anslen, use_malloc = 0; + int cnt, anslen; u_int32_t net2; int olderr = errno; @@ -201,27 +190,16 @@ _nss_dns_getnetbyaddr_r (uint32_t net, int type, struct netent *result, break; } - if (!__libc_use_alloca (MAXPACKET)) - { - net_buffer = (querybuf *) malloc (sizeof (querybuf)); - if (net_buffer == NULL) - { - *errnop = ENOMEM; - return NSS_STATUS_UNAVAIL; - } - use_malloc = 1; - } - else - net_buffer = (querybuf *) alloca (sizeof (querybuf)); + net_buffer = orig_net_buffer = (querybuf *) alloca (1024); - anslen = res_nquery (&_res, qbuf, C_IN, T_PTR, net_buffer->buf, - sizeof (net_buffer->buf)); + anslen = __libc_res_nquery (&_res, qbuf, C_IN, T_PTR, net_buffer->buf, + 1024, (u_char **) &net_buffer); if (anslen < 0) { /* Nothing found. */ int err = errno; __set_errno (olderr); - if (use_malloc) + if (net_buffer != orig_net_buffer) free (net_buffer); return (err == ECONNREFUSED || err == EPFNOSUPPORT @@ -230,7 +208,7 @@ _nss_dns_getnetbyaddr_r (uint32_t net, int type, struct netent *result, } status = getanswer_r (net_buffer, anslen, result, buffer, buflen, BYADDR); - if (use_malloc) + if (net_buffer != orig_net_buffer) free (net_buffer); if (status == NSS_STATUS_SUCCESS) { |