mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-28 00:21:52 +03:00
resolv: Introduce struct resolv_context [BZ #21668]
struct resolv_context objects provide a temporary resolver context which does not change during a name lookup operation. Only when the outmost context is created, the stub resolver configuration is verified to be current (at present, only against previous res_init calls). Subsequent attempts to obtain the context will reuse the result of the initial verification operation. struct resolv_context can also be extended in the future to store data which needs to be deallocated during thread cancellation.
This commit is contained in:
@ -67,6 +67,8 @@
|
||||
#include "nsswitch.h"
|
||||
#include <arpa/inet.h>
|
||||
#include <arpa/nameser.h>
|
||||
#include <resolv/resolv-internal.h>
|
||||
#include <resolv/resolv_context.h>
|
||||
|
||||
/* Maximum number of aliases we allow. */
|
||||
#define MAX_NR_ALIASES 48
|
||||
@ -115,7 +117,8 @@ _nss_dns_getnetbyname_r (const char *name, struct netent *result,
|
||||
int anslen;
|
||||
enum nss_status status;
|
||||
|
||||
if (__res_maybe_init (&_res, 0) == -1)
|
||||
struct resolv_context *ctx = __resolv_context_get ();
|
||||
if (ctx == NULL)
|
||||
{
|
||||
*errnop = errno;
|
||||
*herrnop = NETDB_INTERNAL;
|
||||
@ -124,14 +127,16 @@ _nss_dns_getnetbyname_r (const char *name, struct netent *result,
|
||||
|
||||
net_buffer.buf = orig_net_buffer = (querybuf *) alloca (1024);
|
||||
|
||||
anslen = __libc_res_nsearch (&_res, name, C_IN, T_PTR, net_buffer.buf->buf,
|
||||
1024, &net_buffer.ptr, NULL, NULL, NULL, NULL);
|
||||
anslen = __res_context_search
|
||||
(ctx, name, C_IN, T_PTR, net_buffer.buf->buf,
|
||||
1024, &net_buffer.ptr, NULL, NULL, NULL, NULL);
|
||||
if (anslen < 0)
|
||||
{
|
||||
/* Nothing found. */
|
||||
*errnop = errno;
|
||||
if (net_buffer.buf != orig_net_buffer)
|
||||
free (net_buffer.buf);
|
||||
__resolv_context_put (ctx);
|
||||
return (errno == ECONNREFUSED
|
||||
|| errno == EPFNOSUPPORT
|
||||
|| errno == EAFNOSUPPORT)
|
||||
@ -142,6 +147,7 @@ _nss_dns_getnetbyname_r (const char *name, struct netent *result,
|
||||
errnop, herrnop, BYNAME);
|
||||
if (net_buffer.buf != orig_net_buffer)
|
||||
free (net_buffer.buf);
|
||||
__resolv_context_put (ctx);
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -169,7 +175,8 @@ _nss_dns_getnetbyaddr_r (uint32_t net, int type, struct netent *result,
|
||||
if (type != AF_INET)
|
||||
return NSS_STATUS_UNAVAIL;
|
||||
|
||||
if (__res_maybe_init (&_res, 0) == -1)
|
||||
struct resolv_context *ctx = __resolv_context_get ();
|
||||
if (ctx == NULL)
|
||||
{
|
||||
*errnop = errno;
|
||||
*herrnop = NETDB_INTERNAL;
|
||||
@ -204,8 +211,8 @@ _nss_dns_getnetbyaddr_r (uint32_t net, int type, struct netent *result,
|
||||
|
||||
net_buffer.buf = orig_net_buffer = (querybuf *) alloca (1024);
|
||||
|
||||
anslen = __libc_res_nquery (&_res, qbuf, C_IN, T_PTR, net_buffer.buf->buf,
|
||||
1024, &net_buffer.ptr, NULL, NULL, NULL, NULL);
|
||||
anslen = __res_context_query (ctx, qbuf, C_IN, T_PTR, net_buffer.buf->buf,
|
||||
1024, &net_buffer.ptr, NULL, NULL, NULL, NULL);
|
||||
if (anslen < 0)
|
||||
{
|
||||
/* Nothing found. */
|
||||
@ -213,6 +220,7 @@ _nss_dns_getnetbyaddr_r (uint32_t net, int type, struct netent *result,
|
||||
__set_errno (olderr);
|
||||
if (net_buffer.buf != orig_net_buffer)
|
||||
free (net_buffer.buf);
|
||||
__resolv_context_put (ctx);
|
||||
return (err == ECONNREFUSED
|
||||
|| err == EPFNOSUPPORT
|
||||
|| err == EAFNOSUPPORT)
|
||||
@ -233,6 +241,7 @@ _nss_dns_getnetbyaddr_r (uint32_t net, int type, struct netent *result,
|
||||
result->n_net = u_net;
|
||||
}
|
||||
|
||||
__resolv_context_put (ctx);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user