]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - nss/getnssent_r.c
[powerpc] No need to enter "Ignore Exceptions Mode"
[thirdparty/glibc.git] / nss / getnssent_r.c
index 7545b80c4a11e91588b6c3d589fc4a5fd2b2e123..68dff7e92c6122e2deeb7360e7b1542554a37672 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000,02 Free Software Foundation, Inc.
+/* Copyright (C) 2000-2019 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
    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, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
 
 #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
@@ -30,7 +30,7 @@ setup (const char *func_name, db_lookup_function lookup_fct,
   int no_more;
   if (*startp == NULL)
     {
-      no_more = lookup_fct (nip, func_name, fctp);
+      no_more = lookup_fct (nip, func_name, NULL, fctp);
       *startp = no_more ? (service_user *) -1l : *nip;
     }
   else if (*startp == (service_user *) -1l)
@@ -42,7 +42,7 @@ setup (const char *func_name, db_lookup_function lookup_fct,
        /* Reset to the beginning of the service list.  */
        *nip = *startp;
       /* Look up the first function.  */
-      no_more = __nss_lookup (nip, func_name, fctp);
+      no_more = __nss_lookup (nip, func_name, NULL, fctp);
     }
   return no_more;
 }
@@ -60,11 +60,15 @@ __nss_setent (const char *func_name, db_lookup_function lookup_fct,
   } fct;
   int no_more;
 
-  if (res && (_res.options & RES_INIT) == 0
-      && __res_ninit (&_res) == -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
@@ -81,12 +85,24 @@ __nss_setent (const char *func_name, db_lookup_function lookup_fct,
       else
        status = DL_CALL_FCT (fct.f, (0));
 
-      no_more = __nss_next (nip, func_name, &fct.ptr,
-                           status, 0);
+
+      /* This is a special-case.  When [SUCCESS=merge] is in play,
+         _nss_next2() will skip to the next database.  Due to the
+         implementation of that function, we can't know whether we're
+         in an enumeration or an individual lookup, which behaves
+         differently with regards to merging.  We'll treat SUCCESS as
+         an indication to start the enumeration at this database. */
+      if (nss_next_action (*nip, status) == NSS_ACTION_MERGE)
+       no_more = 1;
+      else
+       no_more = __nss_next2 (nip, func_name, NULL, &fct.ptr, status, 0);
+
       if (is_last_nip)
        *last_nip = *nip;
     }
 
+  __resolv_context_put (res_ctx);
+
   if (stayopen_tmp)
     *stayopen_tmp = stayopen;
 }
@@ -104,11 +120,15 @@ __nss_endent (const char *func_name, db_lookup_function lookup_fct,
   } fct;
   int no_more;
 
-  if (res && (_res.options & RES_INIT) == 0
-      && __res_ninit (&_res) == -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.  */
@@ -122,9 +142,11 @@ __nss_endent (const char *func_name, db_lookup_function lookup_fct,
        /* We have processed all services which were used.  */
        break;
 
-      no_more = __nss_next (nip, func_name, &fct.ptr, 0, 1);
+      no_more = __nss_next2 (nip, func_name, NULL, &fct.ptr, 0, 1);
     }
   *last_nip = *nip = NULL;
+
+  __resolv_context_put (res_ctx);
 }
 
 
@@ -145,12 +167,16 @@ __nss_getent_r (const char *getent_func_name,
   int no_more;
   enum nss_status status;
 
-  if (res && (_res.options & RES_INIT) == 0
-      && __res_ninit (&_res) == -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.  */
@@ -168,7 +194,7 @@ __nss_getent_r (const char *getent_func_name,
       status = DL_CALL_FCT (fct.f,
                            (resbuf, buffer, buflen, &errno, &h_errno));
 
-      /* The the status is NSS_STATUS_TRYAGAIN and errno is ERANGE the
+      /* The status is NSS_STATUS_TRYAGAIN and errno is ERANGE the
         provided buffer is too small.  In this case we should give
         the user the possibility to enlarge the buffer and we should
         not simply go on with the next service (even if the TRYAGAIN
@@ -180,8 +206,18 @@ __nss_getent_r (const char *getent_func_name,
 
       do
        {
-         no_more = __nss_next (nip, getent_func_name, &fct.ptr,
-                               status, 0);
+        /* This is a special-case.  When [SUCCESS=merge] is in play,
+           _nss_next2() will skip to the next database.  Due to the
+           implementation of that function, we can't know whether we're
+           in an enumeration or an individual lookup, which behaves
+           differently with regards to merging.  We'll treat SUCCESS as
+           an indication to return the results here. */
+         if (status == NSS_STATUS_SUCCESS
+             && nss_next_action (*nip, status) == NSS_ACTION_MERGE)
+           no_more = 1;
+         else
+           no_more = __nss_next2 (nip, getent_func_name, NULL, &fct.ptr,
+                                  status, 0);
 
          if (is_last_nip)
            *last_nip = *nip;
@@ -195,8 +231,7 @@ __nss_getent_r (const char *getent_func_name,
                void *ptr;
              } sfct;
 
-             no_more = __nss_lookup (nip, setent_func_name,
-                                     &sfct.ptr);
+             no_more = __nss_lookup (nip, setent_func_name, NULL, &sfct.ptr);
 
              if (! no_more)
                {
@@ -212,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