]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
hesiod: Always use thread-local resolver state [BZ #19573]
authorFlorian Weimer <fweimer@redhat.com>
Mon, 2 May 2016 13:25:20 +0000 (15:25 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Mon, 2 May 2016 13:25:20 +0000 (15:25 +0200)
The Hesiod implementation imported into glibc was enhanced
to support caller-supplied resolver states.  But its only
consumer is nss_hesiod, and it supplies the thread-local
resolver state.  Therefore, this commit changes the Hesiod
implementation to use the thread-local resolver state (_res)
directly.  This fixes bug 19573 because the Hesiod
implementation no longer has to initialize and free any
resolver state.

To avoid any risk of interposition of ABI-incompatible Hesiod
function implementations, this commit marks the Hesiod functions
as hidden.  (They were already hidden using a linker version
script.)

ChangeLog
hesiod/Makefile
hesiod/hesiod.c
hesiod/hesiod.h
hesiod/hesiod_p.h
hesiod/nss_hesiod/hesiod-grp.c
hesiod/nss_hesiod/hesiod-init.c [deleted file]
hesiod/nss_hesiod/hesiod-proto.c
hesiod/nss_hesiod/hesiod-pwd.c
hesiod/nss_hesiod/hesiod-service.c
hesiod/nss_hesiod/nss_hesiod.h [deleted file]

index a92df7310f53524f1f76432a36476ae88a4c18ef..1149fd30e26d2499f67e49958871b88f5e909dc6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2016-05-02  Florian Weimer  <fweimer@redhat.com>
+
+       [BZ #19573]
+       * hesiod/Makefile (libnss_hesiod-routines): Remove hesiod-init.
+       * hesiod/nss_hesiod/hesiod-init.c: Remove file.
+       * hesiod/nss_hesiod/nss_hesiod.h: Likewise.
+       * hesiod/hesiod.h (__hesiod_res_get, __hesiod_res_set): Remove.
+       (hesiod_init, hesiod_end, hesiod_to_bind, hesiod_resolve)
+       (hesiod_free_list): Mark as hidden.
+       * hesiod/hesiod_p (struct hesiod_p): Remove res, free_res,
+       res_set, res_get.
+       * hesiod/hesiod.c: Remove unnecessary forward declarations.
+       (init, __hesiod_res_get, __hesiod_res_set): Remove.
+       (hesiod_init): Remove obsolete res_ninit call.
+       (hesiod_end): Do not free resolver state.  Do not invoke callback.
+       (hesiod_bind): Do not call init.
+       (get_txt_records): Use res_mkquery, res_send instead of
+       res_nmkquery, res_nsend.
+       * hesiod/nss_hesiod/hesiod-grp.c (lookup): Call hesiod_init
+       instead of _nss_hesiod_init.
+       (_nss_hesiod_initgroups_dyn): Likewise.
+       * hesiod/nss_hesiod/hesiod-proto.c (lookup): Likewise.
+       * hesiod/nss_hesiod/hesiod-pwd.c (lookup): Likewise.
+       * hesiod/nss_hesiod/hesiod-service.c (lookup): Likewise.
+
 2016-05-02  Florian Weimer  <fweimer@redhat.com>
 
        * hesiod/hesiod_p.h (DEF_RHS): Remove.
index d68a8597b35edf1972aa6ee315fe4311f79583a7..2d1966c393cbb00210d2922a75f46932a0526fb9 100644 (file)
@@ -28,7 +28,7 @@ extra-libs-others = $(extra-libs)
 subdir-dirs = nss_hesiod
 vpath %.c nss_hesiod
 
-libnss_hesiod-routines := hesiod hesiod-grp hesiod-init hesiod-proto \
+libnss_hesiod-routines := hesiod hesiod-grp hesiod-proto \
                           hesiod-pwd hesiod-service
 # Build only shared library
 libnss_hesiod-inhibit-o        = $(filter-out .os,$(object-suffixes))
index 1869e528af1e1ffe1db9a7ccc5183209f92baab1..6ecbad11cc726727af4caa075ea1dac79525cd45 100644 (file)
@@ -1,3 +1,20 @@
+/* Copyright (C) 1997-2016 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
 /*
  * Copyright (c) 1996,1999 by Internet Software Consortium.
  *
 
 /* Forward */
 
-int            hesiod_init(void **context);
-void           hesiod_end(void *context);
-char *         hesiod_to_bind(void *context, const char *name,
-                              const char *type);
-char **                hesiod_resolve(void *context, const char *name,
-                              const char *type);
-void           hesiod_free_list(void *context, char **list);
-
 static int     parse_config_file(struct hesiod_p *ctx, const char *filename);
 static char ** get_txt_records(struct hesiod_p *ctx, int class,
                                const char *name);
-static int     init(struct hesiod_p *ctx);
 
 /* Public */
 
@@ -77,7 +85,6 @@ hesiod_init(void **context) {
 
        ctx->LHS = NULL;
        ctx->RHS = NULL;
-       ctx->res = NULL;
        /* Set default query classes. */
        ctx->classes[0] = C_IN;
        ctx->classes[1] = C_HS;
@@ -114,11 +121,6 @@ hesiod_init(void **context) {
                goto cleanup;
        }
 
-#if 0
-       if (res_ninit(ctx->res) < 0)
-               goto cleanup;
-#endif
-
        *context = ctx;
        return (0);
 
@@ -135,12 +137,8 @@ hesiod_end(void *context) {
        struct hesiod_p *ctx = (struct hesiod_p *) context;
        int save_errno = errno;
 
-       if (ctx->res)
-               res_nclose(ctx->res);
        free(ctx->RHS);
        free(ctx->LHS);
-       if (ctx->res && ctx->free_res)
-               (*ctx->free_res)(ctx->res);
        free(ctx);
        __set_errno(save_errno);
 }
@@ -215,10 +213,6 @@ hesiod_resolve(void *context, const char *name, const char *type) {
 
        if (bindname == NULL)
                return (NULL);
-       if (init(ctx) == -1) {
-               free(bindname);
-               return (NULL);
-       }
 
        retvec = get_txt_records(ctx, ctx->classes[0], bindname);
 
@@ -348,13 +342,13 @@ get_txt_records(struct hesiod_p *ctx, int class, const char *name) {
        /*
         * Construct the query and send it.
         */
-       n = res_nmkquery(ctx->res, QUERY, name, class, T_TXT, NULL, 0,
+       n = res_mkquery(QUERY, name, class, T_TXT, NULL, 0,
                         NULL, qbuf, MAX_HESRESP);
        if (n < 0) {
                __set_errno(EMSGSIZE);
                return (NULL);
        }
-       n = res_nsend(ctx->res, qbuf, n, abuf, MAX_HESRESP);
+       n = res_send(qbuf, n, abuf, MAX_HESRESP);
        if (n < 0) {
                __set_errno(ECONNREFUSED);
                return (NULL);
@@ -447,44 +441,3 @@ get_txt_records(struct hesiod_p *ctx, int class, const char *name) {
        free(list);
        return (NULL);
 }
-
-struct __res_state *
-__hesiod_res_get(void *context) {
-       struct hesiod_p *ctx = context;
-
-       if (!ctx->res) {
-               struct __res_state *res;
-               res = (struct __res_state *)calloc(1, sizeof *res);
-               if (res == NULL)
-                       return (NULL);
-               __hesiod_res_set(ctx, res, free);
-       }
-
-       return (ctx->res);
-}
-
-void
-__hesiod_res_set(void *context, struct __res_state *res,
-                void (*free_res)(void *)) {
-       struct hesiod_p *ctx = context;
-
-       if (ctx->res && ctx->free_res) {
-               res_nclose(ctx->res);
-               (*ctx->free_res)(ctx->res);
-       }
-
-       ctx->res = res;
-       ctx->free_res = free_res;
-}
-
-static int
-init(struct hesiod_p *ctx) {
-
-       if (!ctx->res && !__hesiod_res_get(ctx))
-               return (-1);
-
-       if (__res_maybe_init (ctx->res, 0) == -1)
-               return (-1);
-
-       return (0);
-}
index cb742b0717394350998192e79ca4e9bcd813605c..c4f5356a9fe7454f7f898e1446f9916c798092f8 100644 (file)
@@ -1,3 +1,20 @@
+/* Copyright (C) 1997-2016 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
 /*
  * Copyright (c) 1996,1999 by Internet Software Consortium.
  *
 #ifndef _HESIOD_H_INCLUDED
 #define _HESIOD_H_INCLUDED
 
-int            hesiod_init (void **context);
-void           hesiod_end (void *context);
+int            hesiod_init (void **context) attribute_hidden;
+void           hesiod_end (void *context) attribute_hidden;
 char *         hesiod_to_bind (void *context, const char *name,
-                               const char *type);
+                               const char *type) attribute_hidden;
 char **                hesiod_resolve (void *context, const char *name,
-                               const char *type);
-void           hesiod_free_list (void *context, char **list);
-struct __res_state * __hesiod_res_get (void *context);
-void           __hesiod_res_set (void *context, struct __res_state *,
-                                 void (*)(void *));
+                               const char *type) attribute_hidden;
+void           hesiod_free_list (void *context, char **list) attribute_hidden;
 
 #endif /*_HESIOD_H_INCLUDED*/
index 0c00c58538e2645fa4a7ee738496c2c4bdfa0299..859a8df0828355e3911316dd8ceb2384fb413863 100644 (file)
@@ -1,3 +1,20 @@
+/* Copyright (C) 1997-2016 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
 /*
  * Copyright (c) 1996,1999 by Internet Software Consortium.
  *
 struct hesiod_p {
        char *          LHS;            /* normally ".ns" */
        char *          RHS;            /* AKA the default hesiod domain */
-       struct __res_state * res;       /* resolver context */
-       void            (*free_res)(void *);
-       void            (*res_set)(struct hesiod_p *, struct __res_state *,
-                                  void (*)(void *));
-       struct __res_state * (*res_get)(struct hesiod_p *);
        int             classes[2];     /* The class search order. */
 };
 
index 7e4ecb4906fcf3e8e760047441e5bd703c785612..944e5e067e8bc0e773c15ec397edac8614856a15 100644 (file)
@@ -26,8 +26,6 @@
 #include <string.h>
 #include <sys/param.h>
 
-#include "nss_hesiod.h"
-
 /* Get the declaration of the parser function.  */
 #define ENTNAME grent
 #define STRUCTURE group
@@ -58,8 +56,7 @@ lookup (const char *name, const char *type, struct group *grp,
   size_t len;
   int olderr = errno;
 
-  context = _nss_hesiod_init ();
-  if (context == NULL)
+  if (hesiod_init (&context) < 0)
     return NSS_STATUS_UNAVAIL;
 
   list = hesiod_resolve (context, name, type);
@@ -179,8 +176,7 @@ _nss_hesiod_initgroups_dyn (const char *user, gid_t group, long int *start,
   gid_t *groups = *groupsp;
   int save_errno;
 
-  context = _nss_hesiod_init ();
-  if (context == NULL)
+  if (hesiod_init (&context) < 0)
     return NSS_STATUS_UNAVAIL;
 
   list = hesiod_resolve (context, user, "grplist");
diff --git a/hesiod/nss_hesiod/hesiod-init.c b/hesiod/nss_hesiod/hesiod-init.c
deleted file mode 100644 (file)
index 2315040..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/* Copyright (C) 2000-2016 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 2000.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <sys/cdefs.h>         /* Needs to come before <hesiod.h>.  */
-#include <hesiod.h>
-#include <resolv.h>
-#include <stddef.h>
-
-#include "nss_hesiod.h"
-
-void *
-_nss_hesiod_init (void)
-{
-  void *context;
-
-  if (hesiod_init (&context) == -1)
-    return NULL;
-
-  /* Use the default (per-thread) resolver state.  */
-  __hesiod_res_set (context, &_res, NULL);
-
-  return context;
-}
index 3c59e731ab4814a82e3a65b9910d0d084dc8b3fc..8a13bba094127a11a2199b7117d03897dd86512a 100644 (file)
@@ -25,8 +25,6 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "nss_hesiod.h"
-
 /* Declare a parser for Hesiod protocol entries.  Although the format
    of the entries is identical to those in /etc/protocols, here is no
    predefined parser for us to use.  */
@@ -68,8 +66,7 @@ lookup (const char *name, const char *type, struct protoent *proto,
   int found;
   int olderr = errno;
 
-  context = _nss_hesiod_init ();
-  if (context == NULL)
+  if (hesiod_init (&context) < 0)
     return NSS_STATUS_UNAVAIL;
 
   list = hesiod_resolve (context, name, type);
index 1ddf3e3c9fa952b2945d160039ad58b665bda7d4..c11916781b20e1bb39fe05571308e40e74dd5767 100644 (file)
@@ -24,8 +24,6 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "nss_hesiod.h"
-
 /* Get the declaration of the parser function.  */
 #define ENTNAME pwent
 #define STRUCTURE passwd
@@ -56,8 +54,7 @@ lookup (const char *name, const char *type, struct passwd *pwd,
   size_t len;
   int olderr = errno;
 
-  context = _nss_hesiod_init ();
-  if (context == NULL)
+  if (hesiod_init (&context) < 0)
     return NSS_STATUS_UNAVAIL;
 
   list = hesiod_resolve (context, name, type);
index 756345f04ea4629d8706fe1607f2e32f35b032c8..2df9cbb0c052551e6e6da2d0f9b37d54418630d7 100644 (file)
@@ -25,8 +25,6 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "nss_hesiod.h"
-
 /* Hesiod uses a format for service entries that differs from the
    traditional format.  We therefore declare our own parser.  */
 
@@ -69,8 +67,7 @@ lookup (const char *name, const char *type, const char *protocol,
   int found;
   int olderr = errno;
 
-  context = _nss_hesiod_init ();
-  if (context == NULL)
+  if (hesiod_init (&context) < 0)
     return NSS_STATUS_UNAVAIL;
 
   list = hesiod_resolve (context, name, type);
diff --git a/hesiod/nss_hesiod/nss_hesiod.h b/hesiod/nss_hesiod/nss_hesiod.h
deleted file mode 100644 (file)
index a6ed8ee..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-/* Copyright (C) 2000-2016 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 2000.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-/* Initialize a Hesiod context.  */
-extern void *_nss_hesiod_init (void);