mirror of
https://sourceware.org/git/glibc.git
synced 2025-08-08 17:42:12 +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:
@@ -18,6 +18,7 @@
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include "nsswitch.h"
|
||||
#include <resolv/resolv_context.h>
|
||||
|
||||
/* Set up NIP to run through the services. If ALL is zero, use NIP's
|
||||
current location if it's not nil. Return nonzero if there are no
|
||||
@@ -59,10 +60,15 @@ __nss_setent (const char *func_name, db_lookup_function lookup_fct,
|
||||
} fct;
|
||||
int no_more;
|
||||
|
||||
if (res && __res_maybe_init (&_res, 0) == -1)
|
||||
struct resolv_context *res_ctx = NULL;
|
||||
if (res)
|
||||
{
|
||||
__set_h_errno (NETDB_INTERNAL);
|
||||
return;
|
||||
res_ctx = __resolv_context_get ();
|
||||
if (res_ctx == NULL)
|
||||
{
|
||||
__set_h_errno (NETDB_INTERNAL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Cycle through the services and run their `setXXent' functions until
|
||||
@@ -95,6 +101,8 @@ __nss_setent (const char *func_name, db_lookup_function lookup_fct,
|
||||
*last_nip = *nip;
|
||||
}
|
||||
|
||||
__resolv_context_put (res_ctx);
|
||||
|
||||
if (stayopen_tmp)
|
||||
*stayopen_tmp = stayopen;
|
||||
}
|
||||
@@ -112,10 +120,15 @@ __nss_endent (const char *func_name, db_lookup_function lookup_fct,
|
||||
} fct;
|
||||
int no_more;
|
||||
|
||||
if (res && __res_maybe_init (&_res, 0) == -1)
|
||||
struct resolv_context *res_ctx = NULL;
|
||||
if (res)
|
||||
{
|
||||
__set_h_errno (NETDB_INTERNAL);
|
||||
return;
|
||||
res_ctx = __resolv_context_get ();
|
||||
if (res_ctx == NULL)
|
||||
{
|
||||
__set_h_errno (NETDB_INTERNAL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Cycle through all the services and run their endXXent functions. */
|
||||
@@ -132,6 +145,8 @@ __nss_endent (const char *func_name, db_lookup_function lookup_fct,
|
||||
no_more = __nss_next2 (nip, func_name, NULL, &fct.ptr, 0, 1);
|
||||
}
|
||||
*last_nip = *nip = NULL;
|
||||
|
||||
__resolv_context_put (res_ctx);
|
||||
}
|
||||
|
||||
|
||||
@@ -152,11 +167,16 @@ __nss_getent_r (const char *getent_func_name,
|
||||
int no_more;
|
||||
enum nss_status status;
|
||||
|
||||
if (res && __res_maybe_init (&_res, 0) == -1)
|
||||
struct resolv_context *res_ctx = NULL;
|
||||
if (res)
|
||||
{
|
||||
*h_errnop = NETDB_INTERNAL;
|
||||
*result = NULL;
|
||||
return errno;
|
||||
res_ctx = __resolv_context_get ();
|
||||
if (res_ctx == NULL)
|
||||
{
|
||||
*h_errnop = NETDB_INTERNAL;
|
||||
*result = NULL;
|
||||
return errno;
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialize status to return if no more functions are found. */
|
||||
@@ -227,6 +247,8 @@ __nss_getent_r (const char *getent_func_name,
|
||||
while (! no_more && status != NSS_STATUS_SUCCESS);
|
||||
}
|
||||
|
||||
__resolv_context_put (res_ctx);
|
||||
|
||||
*result = status == NSS_STATUS_SUCCESS ? resbuf : NULL;
|
||||
return (status == NSS_STATUS_SUCCESS ? 0
|
||||
: status != NSS_STATUS_TRYAGAIN ? ENOENT
|
||||
|
Reference in New Issue
Block a user