summaryrefslogtreecommitdiff
path: root/nss/digits_dots.c
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2017-06-30 21:10:23 +0200
committerFlorian Weimer <fweimer@redhat.com>2017-07-03 20:52:59 +0200
commit352f4ff9a268b81ef5d4b2413f582565806e4790 (patch)
treefb27056dfdeafe43c021f6127c9544c016e78019 /nss/digits_dots.c
parent4e45d83c92dbb5b8dc20654f32395108d18cf739 (diff)
downloadglibc-352f4ff9a268b81ef5d4b2413f582565806e4790.tar.gz
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.
Diffstat (limited to 'nss/digits_dots.c')
-rw-r--r--nss/digits_dots.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/nss/digits_dots.c b/nss/digits_dots.c
index 8dcbf9eb0a..0c1fa97e39 100644
--- a/nss/digits_dots.c
+++ b/nss/digits_dots.c
@@ -23,6 +23,7 @@
#include <ctype.h>
#include <wctype.h>
#include <resolv/resolv-internal.h>
+#include <resolv/resolv_context.h>
#include <netdb.h>
#include <arpa/inet.h>
#include "nsswitch.h"
@@ -38,11 +39,10 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
size_t buflen, struct hostent **result,
enum nss_status *status, int af, int *h_errnop)
{
- int save;
-
/* We have to test for the use of IPv6 which can only be done by
examining `_res'. */
- if (__res_maybe_init (&_res, 0) == -1)
+ struct resolv_context *ctx = __resolv_context_get ();
+ if (ctx == NULL)
{
if (h_errnop)
*h_errnop = NETDB_INTERNAL;
@@ -52,6 +52,21 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
*result = NULL;
return -1;
}
+ int ret = __nss_hostname_digits_dots_context
+ (ctx, name, resbuf, buffer, buffer_size, buflen,
+ result, status, af, h_errnop);
+ __resolv_context_put (ctx);
+ return ret;
+}
+
+int
+__nss_hostname_digits_dots_context (struct resolv_context *ctx,
+ const char *name, struct hostent *resbuf,
+ char **buffer, size_t *buffer_size,
+ size_t buflen, struct hostent **result,
+ enum nss_status *status, int af, int *h_errnop)
+{
+ int save;
/*
* disallow names consisting only of digits/dots, unless