summary refs log tree commit diff
path: root/nis/nss_nis
diff options
context:
space:
mode:
Diffstat (limited to 'nis/nss_nis')
-rw-r--r--nis/nss_nis/nis-alias.c76
-rw-r--r--nis/nss_nis/nis-ethers.c75
-rw-r--r--nis/nss_nis/nis-grp.c256
-rw-r--r--nis/nss_nis/nis-hosts.c136
-rw-r--r--nis/nss_nis/nis-initgroups.c121
-rw-r--r--nis/nss_nis/nis-netgrp.c30
-rw-r--r--nis/nss_nis/nis-network.c115
-rw-r--r--nis/nss_nis/nis-proto.c60
-rw-r--r--nis/nss_nis/nis-publickey.c106
-rw-r--r--nis/nss_nis/nis-pwd.c350
-rw-r--r--nis/nss_nis/nis-rpc.c169
-rw-r--r--nis/nss_nis/nis-service.c254
-rw-r--r--nis/nss_nis/nis-spwd.c66
13 files changed, 776 insertions, 1038 deletions
diff --git a/nis/nss_nis/nis-alias.c b/nis/nss_nis/nis-alias.c
index 9286e36ba6..3b0887be04 100644
--- a/nis/nss_nis/nis-alias.c
+++ b/nis/nss_nis/nis-alias.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2002, 2003, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2002, 2003 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
 
@@ -125,53 +125,52 @@ internal_nis_getaliasent_r (struct aliasent *alias, char *buffer,
 			    size_t buflen, int *errnop)
 {
   char *domain;
+  char *result;
+  int len;
+  char *outkey;
+  int keylen;
+  char *p;
+  int parse_res;
 
-  if (__builtin_expect (yp_get_default_domain (&domain), 0))
+  if (yp_get_default_domain (&domain))
     return NSS_STATUS_UNAVAIL;
 
   alias->alias_local = 0;
 
   /* Get the next entry until we found a correct one. */
-  int parse_res;
   do
     {
-      char *result;
-      int len;
-      char *outkey;
-      int keylen;
-      int yperr;
+      enum nss_status retval;
 
       if (new_start)
-        yperr = yp_first (domain, "mail.aliases", &outkey, &keylen, &result,
-			  &len);
+        retval = yperr2nss (yp_first (domain, "mail.aliases",
+				      &outkey, &keylen, &result, &len));
       else
-        yperr = yp_next (domain, "mail.aliases", oldkey, oldkeylen, &outkey,
-			 &keylen, &result, &len);
-
-      if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+        retval = yperr2nss ( yp_next (domain, "mail.aliases", oldkey,
+				      oldkeylen, &outkey, &keylen,
+				      &result, &len));
+      if (retval != NSS_STATUS_SUCCESS)
 	{
-	  enum nss_status retval = yperr2nss (yperr);
-
 	  if (retval == NSS_STATUS_TRYAGAIN)
             *errnop = errno;
           return retval;
         }
 
-      if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+      if ((size_t) (len + 1) > buflen)
         {
 	  free (result);
           *errnop = ERANGE;
           return NSS_STATUS_TRYAGAIN;
         }
-      char *p = strncpy (buffer, result, len);
+      p = strncpy (buffer, result, len);
       buffer[len] = '\0';
       while (isspace (*p))
         ++p;
       free (result);
 
-      parse_res = _nss_nis_parse_aliasent (outkey, p, alias, buffer,
-					   buflen, errnop);
-      if (__builtin_expect (parse_res == -1, 0))
+      parse_res = _nss_nis_parse_aliasent (outkey, p, alias, buffer, buflen,
+					   errnop);
+      if (parse_res == -1)
 	{
 	  free (outkey);
 	  *errnop = ERANGE;
@@ -207,55 +206,56 @@ enum nss_status
 _nss_nis_getaliasbyname_r (const char *name, struct aliasent *alias,
 			   char *buffer, size_t buflen, int *errnop)
 {
+  enum nss_status retval;
+  int parse_res;
+  char *domain;
+  char *result;
+  int len;
+  char *p;
+  size_t namlen = strlen (name);
+  char name2[namlen + 1];
+  size_t i;
+
   if (name == NULL)
     {
       *errnop = EINVAL;
       return NSS_STATUS_UNAVAIL;
     }
 
-  size_t namlen = strlen (name);
-  char name2[namlen + 1];
-
-  char *domain;
-  if (__builtin_expect (yp_get_default_domain (&domain), 0))
+  if (yp_get_default_domain (&domain))
     return NSS_STATUS_UNAVAIL;
 
   /* Convert name to lowercase.  */
-  size_t i;
   for (i = 0; i < namlen; ++i)
     name2[i] = _tolower (name[i]);
   name2[i] = '\0';
 
-  char *result;
-  int len;
-  int yperr = yp_match (domain, "mail.aliases", name2, namlen, &result, &len);
+  retval = yperr2nss (yp_match (domain, "mail.aliases", name2, namlen,
+				&result, &len));
 
-  if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+  if (retval != NSS_STATUS_SUCCESS)
     {
-      enum nss_status retval = yperr2nss (yperr);
-
       if (retval == NSS_STATUS_TRYAGAIN)
 	*errnop = errno;
       return retval;
     }
 
-  if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+  if ((size_t) (len + 1) > buflen)
     {
       free (result);
       *errnop = ERANGE;
       return NSS_STATUS_TRYAGAIN;
     }
 
-  char *p = strncpy (buffer, result, len);
+  p = strncpy (buffer, result, len);
   buffer[len] = '\0';
   while (isspace (*p))
     ++p;
   free (result);
 
   alias->alias_local = 0;
-  int parse_res = _nss_nis_parse_aliasent (name, p, alias, buffer, buflen,
-					   errnop);
-  if (__builtin_expect (parse_res < 1, 0))
+  parse_res = _nss_nis_parse_aliasent (name, p, alias, buffer, buflen, errnop);
+  if (parse_res < 1)
     {
       if (parse_res == -1)
 	return NSS_STATUS_TRYAGAIN;
diff --git a/nis/nss_nis/nis-ethers.c b/nis/nss_nis/nis-ethers.c
index a3064282ab..def4c22510 100644
--- a/nis/nss_nis/nis-ethers.c
+++ b/nis/nss_nis/nis-ethers.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2003, 2004, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2003, 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
 
@@ -182,46 +182,45 @@ enum nss_status
 _nss_nis_gethostton_r (const char *name, struct etherent *eth,
 		       char *buffer, size_t buflen, int *errnop)
 {
+  struct parser_data *data = (void *) buffer;
+  enum nss_status retval;
+  char *domain, *result, *p;
+  int len, parse_res;
+
   if (name == NULL)
     {
       *errnop = EINVAL;
       return NSS_STATUS_UNAVAIL;
     }
 
-  char *domain;
-  if (__builtin_expect (yp_get_default_domain (&domain), 0))
+  if (yp_get_default_domain (&domain))
     return NSS_STATUS_UNAVAIL;
 
-  char *result;
-  int len;
-  int yperr = yp_match (domain, "ethers.byname", name, strlen (name), &result,
-			&len);
+  retval = yperr2nss (yp_match (domain, "ethers.byname", name,
+				strlen (name), &result, &len));
 
-  if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+  if (retval != NSS_STATUS_SUCCESS)
     {
-      enum nss_status retval = yperr2nss (yperr);
-
       if (retval == NSS_STATUS_TRYAGAIN)
         *errnop = errno;
       return retval;
     }
 
-  if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+  if ((size_t) (len + 1) > buflen)
     {
       free (result);
       *errnop = ERANGE;
       return NSS_STATUS_TRYAGAIN;
     }
 
-  char *p = strncpy (buffer, result, len);
+  p = strncpy (buffer, result, len);
   buffer[len] = '\0';
   while (isspace (*p))
     ++p;
   free (result);
 
-  int parse_res = _nss_files_parse_etherent (p, eth, (void *) buffer, buflen,
-					     errnop);
-  if (__builtin_expect (parse_res < 1, 0))
+  parse_res = _nss_files_parse_etherent (p, eth, data, buflen, errnop);
+  if (parse_res < 1)
     {
       if (parse_res == -1)
 	return NSS_STATUS_TRYAGAIN;
@@ -235,54 +234,54 @@ enum nss_status
 _nss_nis_getntohost_r (const struct ether_addr *addr, struct etherent *eth,
 		       char *buffer, size_t buflen, int *errnop)
 {
+  struct parser_data *data = (void *) buffer;
+  enum nss_status retval;
+  char *domain, *result, *p;
+  int len, nlen, parse_res;
+  char buf[33];
+
   if (addr == NULL)
     {
       *errnop = EINVAL;
       return NSS_STATUS_UNAVAIL;
     }
 
-  char *domain;
-  if (__builtin_expect (yp_get_default_domain (&domain), 0))
+  if (yp_get_default_domain (&domain))
     return NSS_STATUS_UNAVAIL;
 
-  char buf[33];
-  int nlen = snprintf (buf, sizeof (buf), "%x:%x:%x:%x:%x:%x",
-		      (int) addr->ether_addr_octet[0],
-		      (int) addr->ether_addr_octet[1],
-		      (int) addr->ether_addr_octet[2],
-		      (int) addr->ether_addr_octet[3],
-		      (int) addr->ether_addr_octet[4],
-		      (int) addr->ether_addr_octet[5]);
-
-  char *result;
-  int len;
-  int yperr = yp_match (domain, "ethers.byaddr", buf, nlen, &result, &len);
-
-  if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
-    {
-      enum nss_status retval = yperr2nss (yperr);
+  nlen = sprintf (buf, "%x:%x:%x:%x:%x:%x",
+		  (int) addr->ether_addr_octet[0],
+		  (int) addr->ether_addr_octet[1],
+		  (int) addr->ether_addr_octet[2],
+		  (int) addr->ether_addr_octet[3],
+		  (int) addr->ether_addr_octet[4],
+		  (int) addr->ether_addr_octet[5]);
 
+  retval = yperr2nss (yp_match (domain, "ethers.byaddr", buf,
+				nlen, &result, &len));
+
+  if (retval != NSS_STATUS_SUCCESS)
+    {
       if (retval == NSS_STATUS_TRYAGAIN)
         *errnop = errno;
       return retval;
     }
 
-  if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+  if ((size_t) (len + 1) > buflen)
     {
       free (result);
       *errnop = ERANGE;
       return NSS_STATUS_TRYAGAIN;
     }
 
-  char *p = strncpy (buffer, result, len);
+  p = strncpy (buffer, result, len);
   buffer[len] = '\0';
   while (isspace (*p))
     ++p;
   free (result);
 
-  int parse_res = _nss_files_parse_etherent (p, eth, (void *) buffer, buflen,
-					     errnop);
-  if (__builtin_expect (parse_res < 1, 0))
+  parse_res = _nss_files_parse_etherent (p, eth, data, buflen, errnop);
+  if (parse_res < 1)
     {
       if (parse_res == -1)
 	return NSS_STATUS_TRYAGAIN;
diff --git a/nis/nss_nis/nis-grp.c b/nis/nss_nis/nis-grp.c
index 6e36cf828f..8be7332515 100644
--- a/nis/nss_nis/nis-grp.c
+++ b/nis/nss_nis/nis-grp.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-1999, 2001-2004, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1996-1999, 2001-2003, 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
 
@@ -17,17 +17,20 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
 
+#include <nss.h>
+/* The following is an ugly trick to avoid a prototype declaration for
+   _nss_nis_endgrent.  */
+#define _nss_nis_endgrent _nss_nis_endgrent_XXX
+#include <grp.h>
+#undef _nss_nis_endgrent
 #include <ctype.h>
 #include <errno.h>
-#include <grp.h>
-#include <nss.h>
 #include <string.h>
 #include <bits/libc-lock.h>
 #include <rpcsvc/yp.h>
 #include <rpcsvc/ypclnt.h>
 
 #include "nss-nis.h"
-#include <libnsl.h>
 
 /* Get the declaration of the parser function.  */
 #define ENTNAME grent
@@ -41,12 +44,12 @@ __libc_lock_define_initialized (static, lock)
 static bool_t new_start = 1;
 static char *oldkey;
 static int oldkeylen;
-static intern_t intern;
-
 
-static void
-internal_nis_endgrent (void)
+enum nss_status
+_nss_nis_setgrent (int stayopen)
 {
+  __libc_lock_lock (lock);
+
   new_start = 1;
   if (oldkey != NULL)
     {
@@ -55,186 +58,72 @@ internal_nis_endgrent (void)
       oldkeylen = 0;
     }
 
-  struct response_t *curr = intern.next;
-
-  while (curr != NULL)
-    {
-      struct response_t *last = curr;
-      curr = curr->next;
-      free (last);
-    }
-
-  intern.next = intern.start = NULL;
-}
-
-
-enum nss_status
-_nss_nis_endgrent (void)
-{
-  __libc_lock_lock (lock);
-
-  internal_nis_endgrent ();
-
   __libc_lock_unlock (lock);
 
   return NSS_STATUS_SUCCESS;
 }
-
-
-enum nss_status
-internal_nis_setgrent (void)
-{
-  /* We have to read all the data now.  */
-  char *domain;
-  if (__builtin_expect (yp_get_default_domain (&domain), 0))
-    return NSS_STATUS_UNAVAIL;
-
-  struct ypall_callback ypcb;
-
-  ypcb.foreach = _nis_saveit;
-  ypcb.data = (char *) &intern;
-  enum nss_status status = yperr2nss (yp_all (domain, "group.byname", &ypcb));
-
-
-  /* Mark the last buffer as full.  */
-  if (intern.next != NULL)
-    intern.next->size = intern.offset;
-
-  intern.next = intern.start;
-  intern.offset = 0;
-
-  return status;
-}
-
-
-enum nss_status
-_nss_nis_setgrent (int stayopen)
-{
-  enum nss_status result = NSS_STATUS_SUCCESS;
-
-  __libc_lock_lock (lock);
-
-  internal_nis_endgrent ();
-
-  if (_nsl_default_nss () & NSS_FLAG_SETENT_BATCH_READ)
-    result = internal_nis_setgrent ();
-
-  __libc_lock_unlock (lock);
-
-  return result;
-}
-
+/* Make _nss_nis_endgrent an alias of _nss_nis_setgrent.  We do this
+   even though the prototypes don't match.  The argument of setgrent
+   is not used so this makes no difference.  */
+strong_alias (_nss_nis_setgrent, _nss_nis_endgrent)
 
 static enum nss_status
 internal_nis_getgrent_r (struct group *grp, char *buffer, size_t buflen,
 			 int *errnop)
 {
-  /* If we read the entire database at setpwent time we just iterate
-     over the data we have in memory.  */
-  bool batch_read = intern.start != NULL;
+  struct parser_data *data = (void *) buffer;
+  char *domain, *result, *outkey;
+  int len, keylen, parse_res;
 
-  char *domain = NULL;
-  if (!batch_read && __builtin_expect (yp_get_default_domain (&domain), 0))
+  if (yp_get_default_domain (&domain))
     return NSS_STATUS_UNAVAIL;
 
   /* Get the next entry until we found a correct one. */
-  int parse_res;
   do
     {
-      char *result;
-      char *outkey;
-      int len;
-      int keylen;
-
-      if (batch_read)
-	{
-	  struct response_t *bucket;
-
-	handle_batch_read:
-	  bucket = intern.next;
-
-	  if (__builtin_expect (intern.offset >= bucket->size, 0))
-	    {
-	      if (bucket->next == NULL)
-		return NSS_STATUS_NOTFOUND;
-
-	      /* We look at all the content in the current bucket.  Go on
-		 to the next.  */
-	      bucket = intern.next = bucket->next;
-	      intern.offset = 0;
-	    }
-
-	  for (result = &bucket->mem[intern.offset]; isspace (*result);
-	       ++result)
-	    ++intern.offset;
+      enum nss_status retval;
+      char *p;
 
-	  len = strlen (result);
-	}
+      if (new_start)
+        retval = yperr2nss (yp_first (domain, "group.byname",
+                                      &outkey, &keylen, &result, &len));
       else
-	{
-	  int yperr;
-
-	  if (new_start)
-	    {
-	      /* Maybe we should read the database in one piece.  */
-	      if ((_nsl_default_nss () & NSS_FLAG_SETENT_BATCH_READ)
-		  && internal_nis_setgrent () == NSS_STATUS_SUCCESS
-		  && intern.start != NULL)
-		{
-		  batch_read = true;
-		  goto handle_batch_read;
-		}
-
-	      yperr = yp_first (domain, "group.byname", &outkey, &keylen,
-				&result, &len);
-	    }
-	  else
-	    yperr = yp_next (domain, "group.byname", oldkey, oldkeylen,
-			     &outkey, &keylen, &result, &len);
-
-	  if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
-	    {
-	      enum nss_status retval = yperr2nss (yperr);
-
-	      if (retval == NSS_STATUS_TRYAGAIN)
-		*errnop = errno;
-	      return retval;
-	    }
-	}
+        retval = yperr2nss ( yp_next (domain, "group.byname",
+                                      oldkey, oldkeylen,
+                                      &outkey, &keylen, &result, &len));
 
-      if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+      if (retval != NSS_STATUS_SUCCESS)
+        {
+          if (retval == NSS_STATUS_TRYAGAIN)
+            *errnop = errno;
+          return retval;
+        }
+
+      if ((size_t) (len + 1) > buflen)
         {
           free (result);
           *errnop = ERANGE;
           return NSS_STATUS_TRYAGAIN;
         }
 
-      char *p = strncpy (buffer, result, len);
+      p = strncpy (buffer, result, len);
       buffer[len] = '\0';
       while (isspace (*p))
         ++p;
-      if (!batch_read)
-	free (result);
+      free (result);
 
-      parse_res = _nss_files_parse_grent (p, grp, (void *) buffer, buflen,
-					  errnop);
-      if (__builtin_expect (parse_res == -1, 0))
+      parse_res = _nss_files_parse_grent (p, grp, data, buflen, errnop);
+      if (parse_res == -1)
 	{
-	  if (!batch_read)
-	    free (outkey);
+	  free (outkey);
 	  *errnop = ERANGE;
 	  return NSS_STATUS_TRYAGAIN;
 	}
 
-      if (batch_read)
-	intern.offset += len + 1;
-      else
-	{
-	  free (oldkey);
-	  oldkey = outkey;
-	  oldkeylen = keylen;
-	  new_start = 0;
-	}
+      free (oldkey);
+      oldkey = outkey;
+      oldkeylen = keylen;
+      new_start = 0;
     }
   while (parse_res < 1);
 
@@ -260,46 +149,45 @@ enum nss_status
 _nss_nis_getgrnam_r (const char *name, struct group *grp,
 		     char *buffer, size_t buflen, int *errnop)
 {
+  struct parser_data *data = (void *) buffer;
+  enum nss_status retval;
+  char *domain, *result, *p;
+  int len, parse_res;
+
   if (name == NULL)
     {
       *errnop = EINVAL;
       return NSS_STATUS_UNAVAIL;
     }
 
-  char *domain;
-  if (__builtin_expect (yp_get_default_domain (&domain), 0))
+  if (yp_get_default_domain (&domain))
     return NSS_STATUS_UNAVAIL;
 
-  char *result;
-  int len;
-  int yperr = yp_match (domain, "group.byname", name, strlen (name), &result,
-			&len);
+  retval = yperr2nss (yp_match (domain, "group.byname", name,
+				strlen (name), &result, &len));
 
-  if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+  if (retval != NSS_STATUS_SUCCESS)
     {
-      enum nss_status retval = yperr2nss (yperr);
-
       if (retval == NSS_STATUS_TRYAGAIN)
         *errnop = errno;
       return retval;
     }
 
-  if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+  if ((size_t) (len + 1) > buflen)
     {
       free (result);
       *errnop = ERANGE;
       return NSS_STATUS_TRYAGAIN;
     }
 
-  char *p = strncpy (buffer, result, len);
+  p = strncpy (buffer, result, len);
   buffer[len] = '\0';
   while (isspace (*p))
     ++p;
   free (result);
 
-  int parse_res = _nss_files_parse_grent (p, grp, (void *) buffer, buflen,
-					  errnop);
-  if (__builtin_expect  (parse_res < 1, 0))
+  parse_res = _nss_files_parse_grent (p, grp, data, buflen, errnop);
+  if (parse_res < 1)
     {
       if (parse_res == -1)
 	return NSS_STATUS_TRYAGAIN;
@@ -313,42 +201,42 @@ enum nss_status
 _nss_nis_getgrgid_r (gid_t gid, struct group *grp,
 		     char *buffer, size_t buflen, int *errnop)
 {
-  char *domain;
-  if (__builtin_expect (yp_get_default_domain (&domain), 0))
+  struct parser_data *data = (void *) buffer;
+  enum nss_status retval;
+  char *domain, *result, *p;
+  int len, nlen, parse_res;
+  char buf[32];
+
+  if (yp_get_default_domain (&domain))
     return NSS_STATUS_UNAVAIL;
 
-  char buf[32];
-  int nlen = sprintf (buf, "%lu", (unsigned long int) gid);
+  nlen = sprintf (buf, "%lu", (unsigned long int) gid);
 
-  char *result;
-  int len;
-  int yperr = yp_match (domain, "group.bygid", buf, nlen, &result, &len);
+  retval = yperr2nss (yp_match (domain, "group.bygid", buf,
+				nlen, &result, &len));
 
-  if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+  if (retval != NSS_STATUS_SUCCESS)
     {
-      enum nss_status retval = yperr2nss (yperr);
-
       if (retval == NSS_STATUS_TRYAGAIN)
         *errnop = errno;
       return retval;
     }
 
-  if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+  if ((size_t) (len + 1) > buflen)
     {
       free (result);
       *errnop = ERANGE;
       return NSS_STATUS_TRYAGAIN;
     }
 
-  char *p = strncpy (buffer, result, len);
+  p = strncpy (buffer, result, len);
   buffer[len] = '\0';
   while (isspace (*p))
     ++p;
   free (result);
 
-  int parse_res = _nss_files_parse_grent (p, grp, (void *) buffer, buflen,
-					  errnop);
-  if (__builtin_expect (parse_res < 1, 0))
+  parse_res = _nss_files_parse_grent (p, grp, data, buflen, errnop);
+  if (parse_res < 1)
     {
       if (parse_res == -1)
 	return NSS_STATUS_TRYAGAIN;
diff --git a/nis/nss_nis/nis-hosts.c b/nis/nss_nis/nis-hosts.c
index bde0a3291f..58a9064f14 100644
--- a/nis/nss_nis/nis-hosts.c
+++ b/nis/nss_nis/nis-hosts.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2000, 2002, 2003, 2006, 2007 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2000, 2002, 2003 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
 
@@ -131,42 +131,39 @@ internal_nis_gethostent_r (struct hostent *host, char *buffer,
 			   int af, int flags)
 {
   char *domain;
-  if (__builtin_expect (yp_get_default_domain (&domain), 0))
-    return NSS_STATUS_UNAVAIL;
+  char *result;
+  int len, parse_res;
+  char *outkey;
+  int keylen;
+  struct parser_data *data = (void *) buffer;
+  size_t linebuflen = buffer + buflen - data->linebuffer;
 
-  uintptr_t pad = -(uintptr_t) buffer % __alignof__ (struct parser_data);
-  buffer += pad;
+  if (yp_get_default_domain (&domain))
+    return NSS_STATUS_UNAVAIL;
 
-  struct parser_data *data = (void *) buffer;
-  if (__builtin_expect (buflen < sizeof *data + 1 + pad, 0))
+  if (buflen < sizeof *data + 1)
     {
       *errnop = ERANGE;
       *h_errnop = NETDB_INTERNAL;
       return NSS_STATUS_TRYAGAIN;
     }
-  buflen -= pad;
 
   /* Get the next entry until we found a correct one. */
-  const size_t linebuflen = buffer + buflen - data->linebuffer;
-  int parse_res;
   do
     {
-      char *result;
-      int len;
-      char *outkey;
-      int keylen;
-      int yperr;
+      enum nss_status retval;
+      char *p;
+
       if (new_start)
-        yperr = yp_first (domain, "hosts.byname", &outkey, &keylen, &result,
-			  &len);
+        retval = yperr2nss (yp_first (domain, "hosts.byname",
+                                      &outkey, &keylen, &result, &len));
       else
-        yperr = yp_next (domain, "hosts.byname", oldkey, oldkeylen, &outkey,
-			 &keylen, &result, &len);
+        retval = yperr2nss ( yp_next (domain, "hosts.byname",
+                                      oldkey, oldkeylen,
+                                      &outkey, &keylen, &result, &len));
 
-      if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+      if (retval != NSS_STATUS_SUCCESS)
         {
-	  enum nss_status retval = yperr2nss (yperr);
-
 	  switch (retval)
 	    {
 	    case NSS_STATUS_TRYAGAIN:
@@ -183,7 +180,7 @@ internal_nis_gethostent_r (struct hostent *host, char *buffer,
 	  return retval;
 	}
 
-      if (__builtin_expect ((size_t) (len + 1) > linebuflen, 0))
+      if ((size_t) (len + 1) > linebuflen)
         {
           free (result);
 	  *h_errnop = NETDB_INTERNAL;
@@ -191,14 +188,14 @@ internal_nis_gethostent_r (struct hostent *host, char *buffer,
           return NSS_STATUS_TRYAGAIN;
         }
 
-      char *p = strncpy (data->linebuffer, result, len);
+      p = strncpy (data->linebuffer, result, len);
       data->linebuffer[len] = '\0';
       while (isspace (*p))
 	++p;
       free (result);
 
       parse_res = parse_line (p, host, data, buflen, errnop, af, flags);
-      if (__builtin_expect (parse_res == -1, 0))
+      if (parse_res == -1)
 	{
 	  free (outkey);
 	  *h_errnop = NETDB_INTERNAL;
@@ -238,10 +235,11 @@ internal_gethostbyname2_r (const char *name, int af, struct hostent *host,
 			   char *buffer, size_t buflen, int *errnop,
 			   int *h_errnop, int flags)
 {
-  uintptr_t pad = -(uintptr_t) buffer % __alignof__ (struct parser_data);
-  buffer += pad;
-
+  enum nss_status retval;
+  char *domain, *result, *p;
+  int len, parse_res;
   struct parser_data *data = (void *) buffer;
+  size_t linebuflen = buffer + buflen - data->linebuffer;
 
   if (name == NULL)
     {
@@ -249,35 +247,33 @@ internal_gethostbyname2_r (const char *name, int af, struct hostent *host,
       return NSS_STATUS_UNAVAIL;
     }
 
-  char *domain;
   if (yp_get_default_domain (&domain))
     return NSS_STATUS_UNAVAIL;
 
-  if (buflen < sizeof *data + 1 + pad)
+  if (buflen < sizeof *data + 1)
     {
       *h_errnop = NETDB_INTERNAL;
       *errnop = ERANGE;
       return NSS_STATUS_TRYAGAIN;
     }
-  buflen -= pad;
+  else
+    {
+      /* Convert name to lowercase.  */
+      size_t namlen = strlen (name);
+      char name2[namlen + 1];
+      size_t i;
 
-  /* Convert name to lowercase.  */
-  size_t namlen = strlen (name);
-  char name2[namlen + 1];
-  size_t i;
+      for (i = 0; i < namlen; ++i)
+	name2[i] = tolower (name[i]);
+      name2[i] = '\0';
 
-  for (i = 0; i < namlen; ++i)
-    name2[i] = tolower (name[i]);
-  name2[i] = '\0';
+      retval = yperr2nss (yp_match (domain, "hosts.byname", name2,
+				    namlen, &result, &len));
 
-  char *result;
-  int len;
-  int yperr = yp_match (domain, "hosts.byname", name2, namlen, &result, &len);
+    }
 
-  if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+  if (retval != NSS_STATUS_SUCCESS)
     {
-      enum nss_status retval = yperr2nss (yperr);
-
       if (retval == NSS_STATUS_TRYAGAIN)
 	{
 	  *h_errnop = TRY_AGAIN;
@@ -288,8 +284,7 @@ internal_gethostbyname2_r (const char *name, int af, struct hostent *host,
       return retval;
     }
 
-  const size_t linebuflen = buffer + buflen - data->linebuffer;
-  if (__builtin_expect ((size_t) (len + 1) > linebuflen, 0))
+  if ((size_t) (len + 1) > linebuflen)
     {
       free (result);
       *h_errnop = NETDB_INTERNAL;
@@ -297,15 +292,15 @@ internal_gethostbyname2_r (const char *name, int af, struct hostent *host,
       return NSS_STATUS_TRYAGAIN;
     }
 
-  char *p = strncpy (data->linebuffer, result, len);
+  p = strncpy (data->linebuffer, result, len);
   data->linebuffer[len] = '\0';
   while (isspace (*p))
     ++p;
   free (result);
 
-  int parse_res = parse_line (p, host, data, buflen, errnop, af, flags);
+  parse_res = parse_line (p, host, data, buflen, errnop, af, flags);
 
-  if (__builtin_expect (parse_res < 1 || host->h_addrtype != af, 0))
+  if (parse_res < 1 || host->h_addrtype != af)
     {
       if (parse_res == -1)
 	{
@@ -356,46 +351,42 @@ _nss_nis_gethostbyaddr_r (const void *addr, socklen_t addrlen, int af,
 			  struct hostent *host, char *buffer, size_t buflen,
 			  int *errnop, int *h_errnop)
 {
-  char *domain;
-  if (__builtin_expect (yp_get_default_domain (&domain), 0))
-    return NSS_STATUS_UNAVAIL;
+  enum nss_status retval;
+  char *domain, *result, *p;
+  int len, parse_res;
+  char *buf;
+  struct parser_data *data = (void *) buffer;
+  size_t linebuflen = buffer + buflen - data->linebuffer;
 
-  uintptr_t pad = -(uintptr_t) buffer % __alignof__ (struct parser_data);
-  buffer += pad;
+  if (yp_get_default_domain (&domain))
+    return NSS_STATUS_UNAVAIL;
 
-  struct parser_data *data = (void *) buffer;
-  if (__builtin_expect (buflen < sizeof *data + 1 + pad, 0))
+  if (buflen < sizeof *data + 1)
     {
       *errnop = ERANGE;
       *h_errnop = NETDB_INTERNAL;
       return NSS_STATUS_TRYAGAIN;
     }
-  buflen -= pad;
 
-  char *buf = inet_ntoa (*(const struct in_addr *) addr);
+  buf = inet_ntoa (*(const struct in_addr *) addr);
 
-  char *result;
-  int len;
-  int yperr = yp_match (domain, "hosts.byaddr", buf, strlen (buf), &result,
-			&len);
+  retval = yperr2nss (yp_match (domain, "hosts.byaddr", buf,
+                                strlen (buf), &result, &len));
 
-  if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+  if (retval != NSS_STATUS_SUCCESS)
     {
-      enum nss_status retval = yperr2nss (yperr);
-
       if (retval == NSS_STATUS_TRYAGAIN)
 	{
 	  *h_errnop = TRY_AGAIN;
 	  *errnop = errno;
 	}
-      else if (retval == NSS_STATUS_NOTFOUND)
+      if (retval == NSS_STATUS_NOTFOUND)
 	*h_errnop = HOST_NOT_FOUND;
 
       return retval;
     }
 
-  const size_t linebuflen = buffer + buflen - data->linebuffer;
-  if (__builtin_expect ((size_t) (len + 1) > linebuflen, 0))
+  if ((size_t) (len + 1) > linebuflen)
     {
       free (result);
       *errnop = ERANGE;
@@ -403,16 +394,15 @@ _nss_nis_gethostbyaddr_r (const void *addr, socklen_t addrlen, int af,
       return NSS_STATUS_TRYAGAIN;
     }
 
-  char *p = strncpy (data->linebuffer, result, len);
+  p = strncpy (data->linebuffer, result, len);
   data->linebuffer[len] = '\0';
   while (isspace (*p))
     ++p;
   free (result);
 
-  int parse_res = parse_line (p, host, data, buflen, errnop, af,
-			      ((_res.options & RES_USE_INET6)
-			       ? AI_V4MAPPED : 0));
-  if (__builtin_expect (parse_res < 1, 0))
+  parse_res = parse_line (p, host, data, buflen, errnop, af,
+			  ((_res.options & RES_USE_INET6) ? AI_V4MAPPED : 0));
+  if (parse_res < 1)
     {
       if (parse_res == -1)
 	{
diff --git a/nis/nss_nis/nis-initgroups.c b/nis/nss_nis/nis-initgroups.c
index a5a3ba6144..33a9662b4c 100644
--- a/nis/nss_nis/nis-initgroups.c
+++ b/nis/nss_nis/nis-initgroups.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998-2000,2002,2003,2004,2006 Free Software Foundation, Inc.
+/* Copyright (C) 1998-2000, 2002, 2003, 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
 
@@ -30,7 +30,6 @@
 #include <sys/param.h>
 
 #include "nss-nis.h"
-#include <libnsl.h>
 
 /* Get the declaration of the parser function.  */
 #define ENTNAME grent
@@ -38,6 +37,47 @@
 #define EXTERN_PARSER
 #include <nss/nss_files/files-parse.c>
 
+struct response_t
+{
+  struct response_t *next;
+  char val[0];
+};
+
+struct intern_t
+{
+  struct response_t *start;
+  struct response_t *next;
+};
+typedef struct intern_t intern_t;
+
+static int
+saveit (int instatus, char *inkey, int inkeylen, char *inval,
+        int invallen, char *indata)
+{
+  intern_t *intern = (intern_t *) indata;
+
+  if (instatus != YP_TRUE)
+    return 1;
+
+  if (inkey && inkeylen > 0 && inval && invallen > 0)
+    {
+      struct response_t *newp = malloc (sizeof (struct response_t)
+					+ invallen + 1);
+      if (newp == NULL)
+	return 1; /* We have no error code for out of memory */
+
+      if (intern->start == NULL)
+	intern->start = newp;
+      else
+	intern->next->next = newp;
+      intern->next = newp;
+
+      newp->next = NULL;
+      *((char *) mempcpy (newp->val, inval, invallen)) = '\0';
+    }
+
+  return 0;
+}
 
 static enum nss_status
 internal_setgrent (char *domainname, intern_t *intern)
@@ -45,72 +85,41 @@ internal_setgrent (char *domainname, intern_t *intern)
   struct ypall_callback ypcb;
   enum nss_status status;
 
-  ypcb.foreach = _nis_saveit;
+  intern->start = NULL;
+
+  ypcb.foreach = saveit;
   ypcb.data = (char *) intern;
   status = yperr2nss (yp_all (domainname, "group.byname", &ypcb));
-
-  /* Mark the last buffer as full.  */
-  if (intern->next != NULL)
-    intern->next->size = intern->offset;
-
   intern->next = intern->start;
-  intern->offset = 0;
 
   return status;
 }
 
-
 static enum nss_status
 internal_getgrent_r (struct group *grp, char *buffer, size_t buflen,
 		     int *errnop, intern_t *intern)
 {
+  struct parser_data *data = (void *) buffer;
+  int parse_res;
+  char *p;
+
   if (intern->start == NULL)
     return NSS_STATUS_NOTFOUND;
 
   /* Get the next entry until we found a correct one. */
-  int parse_res;
   do
     {
-      struct response_t *bucket = intern->next;
-
-      if (__builtin_expect (intern->offset >= bucket->size, 0))
-	{
-	  if (bucket->next == NULL)
-	    return NSS_STATUS_NOTFOUND;
-
-	  /* We look at all the content in the current bucket.  Go on
-	     to the next.  */
-	  bucket = intern->next = bucket->next;
-	  intern->offset = 0;
-	}
-
-      char *p;
-      for (p = &bucket->mem[intern->offset]; isspace (*p); ++p)
-        ++intern->offset;
+      if (intern->next == NULL)
+	return NSS_STATUS_NOTFOUND;
 
-      size_t len = strlen (p) + 1;
-      if (__builtin_expect (len > buflen, 0))
-	{
-	  *errnop = ERANGE;
-	  return NSS_STATUS_TRYAGAIN;
-	}
+      p = strncpy (buffer, intern->next->val, buflen);
+      while (isspace (*p))
+        ++p;
 
-      /* We unfortunately have to copy the data in the user-provided
-	 buffer because that buffer might be around for a very long
-	 time and the servent structure must remain valid.  If we would
-	 rely on the BUCKET memory the next 'setservent' or 'endservent'
-	 call would destroy it.
-
-	 The important thing is that it is a single NUL-terminated
-	 string.  This is what the parsing routine expects.  */
-      p = memcpy (buffer, &bucket->mem[intern->offset], len);
-
-      parse_res = _nss_files_parse_grent (p, grp, (void *) buffer, buflen,
-					  errnop);
-      if (__builtin_expect (parse_res == -1, 0))
+      parse_res = _nss_files_parse_grent (p, grp, data, buflen, errnop);
+      if (parse_res == -1)
         return NSS_STATUS_TRYAGAIN;
-
-      intern->offset += len;
+      intern->next = intern->next->next;
     }
   while (!parse_res);
 
@@ -157,12 +166,13 @@ initgroups_netid (uid_t uid, gid_t group, long int *start, long int *size,
   ssize_t keylen = snprintf (key, sizeof (key), "unix.%lu@%s",
 			     (unsigned long int) uid, domainname);
 
+  enum nss_status retval;
   char *result;
   int reslen;
-  int yperr = yp_match (domainname, "netid.byname", key, keylen, &result,
-			&reslen);
-  if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
-    return yperr2nss (yperr);
+  retval = yperr2nss (yp_match (domainname, "netid.byname", key, keylen,
+				&result, &reslen));
+  if (retval != NSS_STATUS_SUCCESS)
+    return retval;
 
   /* Parse the result: following the colon is a comma separated list of
      group IDs.  */
@@ -197,6 +207,7 @@ initgroups_netid (uid_t uid, gid_t group, long int *start, long int *size,
       if (*start == *size)
 	{
 	  /* Need a bigger buffer.  */
+	  gid_t *newgroups;
 	  long int newsize;
 
 	  if (limit > 0 && *size == limit)
@@ -208,7 +219,7 @@ initgroups_netid (uid_t uid, gid_t group, long int *start, long int *size,
 	  else
 	    newsize = MIN (limit, 2 * *size);
 
-	  gid_t *newgroups = realloc (groups, newsize * sizeof (*groups));
+	  newgroups = realloc (groups, newsize * sizeof (*groups));
 	  if (newgroups == NULL)
 	    goto errout;
 	  *groupsp = groups = newgroups;
@@ -236,7 +247,7 @@ _nss_nis_initgroups_dyn (const char *user, gid_t group, long int *start,
     return NSS_STATUS_UNAVAIL;
 
   /* Check whether we are supposed to use the netid.byname map.  */
-  if (_nsl_default_nss () & NSS_FLAG_NETID_AUTHORITATIVE)
+  if (_nis_default_nss () & NSS_FLAG_NETID_AUTHORITATIVE)
     {
       /* We need the user ID.  */
       uid_t uid;
@@ -251,7 +262,7 @@ _nss_nis_initgroups_dyn (const char *user, gid_t group, long int *start,
   size_t buflen = sysconf (_SC_GETPW_R_SIZE_MAX);
   char *tmpbuf;
   enum nss_status status;
-  intern_t intern = { NULL, NULL, 0 };
+  intern_t intern = { NULL, NULL };
   gid_t *groups = *groupsp;
 
   status = internal_setgrent (domainname, &intern);
diff --git a/nis/nss_nis/nis-netgrp.c b/nis/nss_nis/nis-netgrp.c
index 5a88b72d9c..d339dd5097 100644
--- a/nis/nss_nis/nis-netgrp.c
+++ b/nis/nss_nis/nis-netgrp.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996,1997,1999,2000,2002,2003,2004,2005,2006
+/* Copyright (C) 1996,1997,1999,2000,2002,2003,2004
    Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
@@ -41,37 +41,41 @@ _nss_netgroup_parseline (char **cursor, struct __netgrent *netgrp,
 static void
 internal_nis_endnetgrent (struct __netgrent *netgrp)
 {
-  free (netgrp->data);
-  netgrp->data = NULL;
-  netgrp->data_size = 0;
-  netgrp->cursor = NULL;
+  if (netgrp->data != NULL)
+    {
+      free (netgrp->data);
+      netgrp->data = NULL;
+      netgrp->data_size = 0;
+      netgrp->cursor = NULL;
+    }
 }
 
-
 enum nss_status
 _nss_nis_setnetgrent (const char *group, struct __netgrent *netgrp)
 {
+  char *domain;
   int len;
   enum nss_status status;
 
   status = NSS_STATUS_SUCCESS;
 
-  if (__builtin_expect (group == NULL || group[0] == '\0', 0))
+  if (group == NULL || group[0] == '\0')
     return NSS_STATUS_UNAVAIL;
 
-  char *domain;
-  if (__builtin_expect (yp_get_default_domain (&domain), 0))
+  if (yp_get_default_domain (&domain))
     return NSS_STATUS_UNAVAIL;
 
+  internal_nis_endnetgrent (netgrp);
+
   status = yperr2nss (yp_match (domain, "netgroup", group, strlen (group),
 				&netgrp->data, &len));
-  if (__builtin_expect (status == NSS_STATUS_SUCCESS, 1))
+  if (status == NSS_STATUS_SUCCESS)
     {
       /* Our implementation of yp_match already allocates a buffer
 	 which is one byte larger than the value in LEN specifies
 	 and the last byte is filled with NUL.  So we can simply
 	 use that buffer.  */
-      assert (len >= 0);
+      assert (len > 0);
       assert (malloc_usable_size (netgrp->data) >= len + 1);
       assert (netgrp->data[len] == '\0');
 
@@ -91,11 +95,13 @@ _nss_nis_endnetgrent (struct __netgrent *netgrp)
   return NSS_STATUS_SUCCESS;
 }
 
-
 enum nss_status
 _nss_nis_getnetgrent_r (struct __netgrent *result, char *buffer, size_t buflen,
 			int *errnop)
 {
+  if (result->cursor == NULL)
+    return NSS_STATUS_NOTFOUND;
+
   return _nss_netgroup_parseline (&result->cursor, result, buffer, buflen,
 				  errnop);
 }
diff --git a/nis/nss_nis/nis-network.c b/nis/nss_nis/nis-network.c
index 9b02302e0b..ed8439c814 100644
--- a/nis/nss_nis/nis-network.c
+++ b/nis/nss_nis/nis-network.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2003, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2000, 2001, 2002, 2003 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
 
@@ -73,32 +73,28 @@ internal_nis_getnetent_r (struct netent *net, char *buffer, size_t buflen,
 			  int *errnop, int *herrnop)
 {
   struct parser_data *data = (void *) buffer;
+  char *domain, *result, *outkey;
+  int len, keylen, parse_res;
 
-  char *domain;
-  if (__builtin_expect (yp_get_default_domain (&domain), 0))
+  if (yp_get_default_domain (&domain))
     return NSS_STATUS_UNAVAIL;
 
   /* Get the next entry until we found a correct one. */
-  int parse_res;
   do
     {
-      char *result;
-      char *outkey;
-      int len;
-      int keylen;
-      int yperr;
+      enum nss_status retval;
+      char *p;
 
       if (new_start)
-        yperr = yp_first (domain, "networks.byname", &outkey, &keylen, &result,
-			  &len);
+        retval = yperr2nss (yp_first (domain, "networks.byname",
+                                      &outkey, &keylen, &result, &len));
       else
-        yperr = yp_next (domain, "networks.byname", oldkey, oldkeylen, &outkey,
-			 &keylen, &result, &len);
+        retval = yperr2nss ( yp_next (domain, "networks.byname",
+                                      oldkey, oldkeylen,
+                                      &outkey, &keylen, &result, &len));
 
-      if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+      if (retval != NSS_STATUS_SUCCESS)
         {
-	  enum nss_status retval = yperr2nss (yperr);
-
           if (retval == NSS_STATUS_TRYAGAIN)
 	    {
 	      *herrnop = NETDB_INTERNAL;
@@ -107,7 +103,7 @@ internal_nis_getnetent_r (struct netent *net, char *buffer, size_t buflen,
           return retval;
         }
 
-      if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+      if ((size_t) (len + 1) > buflen)
         {
           free (result);
 	  *errnop = ERANGE;
@@ -115,14 +111,14 @@ internal_nis_getnetent_r (struct netent *net, char *buffer, size_t buflen,
           return NSS_STATUS_TRYAGAIN;
         }
 
-      char *p = strncpy (buffer, result, len);
+      p = strncpy (buffer, result, len);
       buffer[len] = '\0';
       while (isspace (*p))
         ++p;
       free (result);
 
       parse_res = _nss_files_parse_netent (p, net, data, buflen, errnop);
-      if (__builtin_expect (parse_res == -1, 0))
+      if (parse_res == -1)
 	{
 	  free (outkey);
 	  *herrnop = NETDB_INTERNAL;
@@ -159,6 +155,11 @@ enum nss_status
 _nss_nis_getnetbyname_r (const char *name, struct netent *net, char *buffer,
 			 size_t buflen, int *errnop, int *herrnop)
 {
+  enum nss_status retval;
+  struct parser_data *data = (void *) buffer;
+  char *domain, *result, *p;
+  int len, parse_res;
+
   if (name == NULL)
     {
       *errnop = EINVAL;
@@ -166,36 +167,33 @@ _nss_nis_getnetbyname_r (const char *name, struct netent *net, char *buffer,
       return NSS_STATUS_UNAVAIL;
     }
 
-  char *domain;
-  if (__builtin_expect (yp_get_default_domain (&domain), 0))
+  if (yp_get_default_domain (&domain))
     return NSS_STATUS_UNAVAIL;
 
-  struct parser_data *data = (void *) buffer;
   if (buflen < sizeof *data + 1)
     {
       *herrnop = NETDB_INTERNAL;
       *errnop = ERANGE;
       return NSS_STATUS_TRYAGAIN;
     }
+  else
+    {
+      /* Convert name to lowercase.  */
+      size_t namlen = strlen (name);
+      char name2[namlen + 1];
+      size_t i;
 
-  /* Convert name to lowercase.  */
-  size_t namlen = strlen (name);
-  char name2[namlen + 1];
-  size_t i;
+      for (i = 0; i < namlen; ++i)
+	name2[i] = _tolower (name[i]);
+      name2[i] = '\0';
 
-  for (i = 0; i < namlen; ++i)
-    name2[i] = _tolower (name[i]);
-  name2[i] = '\0';
+      retval = yperr2nss (yp_match (domain, "networks.byname", name2,
+				    namlen, &result, &len));
+    }
 
-  char *result;
-  int len;
-  int yperr = yp_match (domain, "networks.byname", name2, namlen, &result,
-			&len);
 
-  if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+  if (retval != NSS_STATUS_SUCCESS)
     {
-      enum nss_status retval = yperr2nss (yperr);
-
       if (retval == NSS_STATUS_TRYAGAIN)
 	{
 	  *errnop = errno;
@@ -204,7 +202,7 @@ _nss_nis_getnetbyname_r (const char *name, struct netent *net, char *buffer,
       return retval;
     }
 
-  if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+  if ((size_t) (len + 1) > buflen)
     {
       free (result);
       *errnop = ERANGE;
@@ -212,15 +210,15 @@ _nss_nis_getnetbyname_r (const char *name, struct netent *net, char *buffer,
       return NSS_STATUS_TRYAGAIN;
     }
 
-  char *p = strncpy (buffer, result, len);
+  p = strncpy (buffer, result, len);
   buffer[len] = '\0';
   while (isspace (*p))
     ++p;
   free (result);
 
-  int parse_res = _nss_files_parse_netent (p, net, data, buflen, errnop);
+  parse_res = _nss_files_parse_netent (p, net, data, buflen, errnop);
 
-  if (__builtin_expect (parse_res < 1, 0))
+  if (parse_res < 1)
     {
       *herrnop = NETDB_INTERNAL;
       if (parse_res == -1)
@@ -237,26 +235,32 @@ _nss_nis_getnetbyaddr_r (uint32_t addr, int type, struct netent *net,
 			 char *buffer, size_t buflen, int *errnop,
 			 int *herrnop)
 {
+  struct parser_data *data = (void *) buffer;
   char *domain;
-  if (__builtin_expect (yp_get_default_domain (&domain), 0))
+  char *result;
+  int len;
+  char buf[256];
+  int blen;
+  struct in_addr in;
+  char *p;
+
+  if (yp_get_default_domain (&domain))
     return NSS_STATUS_UNAVAIL;
 
-  struct in_addr in = inet_makeaddr (addr, 0);
-  char *buf = inet_ntoa (in);
-  size_t blen = strlen (buf);
+  in = inet_makeaddr (addr, 0);
+  strcpy (buf, inet_ntoa (in));
+  blen = strlen (buf);
 
   while (1)
     {
-      char *result;
-      int len;
+      enum nss_status retval;
+      int parse_res;
 
-      int yperr = yp_match (domain, "networks.byaddr", buf, blen, &result,
-			    &len);
+      retval = yperr2nss (yp_match (domain, "networks.byaddr", buf,
+				    strlen (buf), &result, &len));
 
-      if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+	if (retval != NSS_STATUS_SUCCESS)
 	  {
-	    enum nss_status retval = yperr2nss (yperr);
-
 	    if (retval == NSS_STATUS_NOTFOUND)
 	      {
 		if (buf[blen - 2] == '.' && buf[blen - 1] == '0')
@@ -278,7 +282,7 @@ _nss_nis_getnetbyaddr_r (uint32_t addr, int type, struct netent *net,
 	      }
 	  }
 
-      if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+      if ((size_t) (len + 1) > buflen)
 	{
 	  free (result);
 	  *errnop = ERANGE;
@@ -286,16 +290,15 @@ _nss_nis_getnetbyaddr_r (uint32_t addr, int type, struct netent *net,
 	  return NSS_STATUS_TRYAGAIN;
 	}
 
-        char *p = strncpy (buffer, result, len);
+        p = strncpy (buffer, result, len);
 	buffer[len] = '\0';
 	while (isspace (*p))
 	  ++p;
 	free (result);
 
-	int parse_res = _nss_files_parse_netent (p, net, (void *) buffer,
-						 buflen, errnop);
+	parse_res = _nss_files_parse_netent (p, net, data, buflen, errnop);
 
-	if (__builtin_expect (parse_res < 1, 0))
+	if (parse_res < 1)
 	  {
 	    *herrnop = NETDB_INTERNAL;
 	    if (parse_res == -1)
diff --git a/nis/nss_nis/nis-proto.c b/nis/nss_nis/nis-proto.c
index 1480a928b5..f1069283ab 100644
--- a/nis/nss_nis/nis-proto.c
+++ b/nis/nss_nis/nis-proto.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-1998, 2000-2004, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1996-1998, 2000-2003, 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
 
@@ -179,46 +179,45 @@ enum nss_status
 _nss_nis_getprotobyname_r (const char *name, struct protoent *proto,
 			   char *buffer, size_t buflen, int *errnop)
 {
+  struct parser_data *data = (void *) buffer;
+  enum nss_status retval;
+  char *domain, *result, *p;
+  int len, parse_res;
+
   if (name == NULL)
     {
       *errnop = EINVAL;
       return NSS_STATUS_UNAVAIL;
     }
 
-  char *domain;
-  if (__builtin_expect (yp_get_default_domain (&domain), 0))
+  if (yp_get_default_domain (&domain))
     return NSS_STATUS_UNAVAIL;
 
-  char *result;
-  int len;
-  int yperr = yp_match (domain, "protocols.byname", name, strlen (name),
-			&result, &len);
+  retval = yperr2nss (yp_match (domain, "protocols.byname", name,
+                                strlen (name), &result, &len));
 
-  if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+  if (retval != NSS_STATUS_SUCCESS)
     {
-      enum nss_status retval = yperr2nss (yperr);
-
       if (retval == NSS_STATUS_TRYAGAIN)
 	*errnop = errno;
       return retval;
     }
 
-  if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+  if ((size_t) (len + 1) > buflen)
     {
       free (result);
       *errnop = ERANGE;
       return NSS_STATUS_TRYAGAIN;
     }
 
-  char *p = strncpy (buffer, result, len);
+  p = strncpy (buffer, result, len);
   buffer[len] = '\0';
   while (isspace (*p))
     ++p;
   free (result);
 
-  int parse_res = _nss_files_parse_protoent (p, proto, (void *) buffer, buflen,
-					     errnop);
-  if (__builtin_expect (parse_res < 1, 0))
+  parse_res = _nss_files_parse_protoent (p, proto, data, buflen, errnop);
+  if (parse_res < 1)
     {
       if (parse_res == -1)
 	return NSS_STATUS_TRYAGAIN;
@@ -232,43 +231,42 @@ enum nss_status
 _nss_nis_getprotobynumber_r (int number, struct protoent *proto,
 			     char *buffer, size_t buflen, int *errnop)
 {
-  char *domain;
-  if (__builtin_expect (yp_get_default_domain (&domain), 0))
+  struct parser_data *data = (void *) buffer;
+  enum nss_status retval;
+  char *domain, *result, *p;
+  int len, nlen, parse_res;
+  char buf[32];
+
+  if (yp_get_default_domain (&domain))
     return NSS_STATUS_UNAVAIL;
 
-  char buf[32];
-  int nlen = snprintf (buf, sizeof (buf), "%d", number);
+  nlen = sprintf (buf, "%d", number);
 
-  char *result;
-  int len;
-  int yperr = yp_match (domain, "protocols.bynumber", buf, nlen, &result,
-			&len);
+  retval = yperr2nss (yp_match (domain, "protocols.bynumber", buf,
+                                nlen, &result, &len));
 
-  if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+  if (retval != NSS_STATUS_SUCCESS)
     {
-      enum nss_status retval = yperr2nss (yperr);
-
       if (retval == NSS_STATUS_TRYAGAIN)
 	*errnop = errno;
       return retval;
     }
 
-  if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+  if ((size_t) (len + 1) > buflen)
     {
       free (result);
       *errnop = ERANGE;
       return NSS_STATUS_TRYAGAIN;
     }
 
-  char *p = strncpy (buffer, result, len);
+  p = strncpy (buffer, result, len);
   buffer[len] = '\0';
   while (isspace (*p))
     ++p;
   free (result);
 
-  int parse_res = _nss_files_parse_protoent (p, proto, (void *) buffer, buflen,
-					     errnop);
-  if (__builtin_expect (parse_res < 1, 0))
+  parse_res = _nss_files_parse_protoent (p, proto, data, buflen, errnop);
+  if (parse_res < 1)
     {
       if (parse_res == -1)
 	return NSS_STATUS_TRYAGAIN;
diff --git a/nis/nss_nis/nis-publickey.c b/nis/nss_nis/nis-publickey.c
index f58eb154ad..6e92112d11 100644
--- a/nis/nss_nis/nis-publickey.c
+++ b/nis/nss_nis/nis-publickey.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-1999,2001,2002,2005,2006 Free Software Foundation, Inc.
+/* Copyright (C) 1996,1997,1998,1999,2001,2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
 
@@ -36,6 +36,10 @@ extern int xdecrypt (char *, char *);
 enum nss_status
 _nss_nis_getpublickey (const char *netname, char *pkey, int *errnop)
 {
+  enum nss_status retval;
+  char *domain, *result;
+  int len;
+
   pkey[0] = 0;
 
   if (netname == NULL)
@@ -44,23 +48,19 @@ _nss_nis_getpublickey (const char *netname, char *pkey, int *errnop)
       return NSS_STATUS_UNAVAIL;
     }
 
-  char *domain = strchr (netname, '@');
-  if (domain == NULL)
+  domain = strchr (netname, '@');
+  if (!domain)
     {
       *errnop = EINVAL;
       return NSS_STATUS_UNAVAIL;
     }
   ++domain;
 
-  char *result;
-  int len;
-  int yperr = yp_match (domain, "publickey.byname", netname, strlen (netname),
-			&result, &len);
+  retval = yperr2nss (yp_match (domain, "publickey.byname", netname,
+				strlen (netname), &result, &len));
 
-  if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+  if (retval != NSS_STATUS_SUCCESS)
     {
-      enum nss_status retval = yperr2nss (yperr);
-
       if (retval == NSS_STATUS_TRYAGAIN)
 	*errnop = errno;
       return retval;
@@ -73,7 +73,6 @@ _nss_nis_getpublickey (const char *netname, char *pkey, int *errnop)
 	*p = 0;
       strncpy (pkey, result, HEXKEYBYTES + 1);
       pkey[HEXKEYBYTES] = '\0';
-      free (result);
     }
   return NSS_STATUS_SUCCESS;
 }
@@ -82,6 +81,11 @@ enum nss_status
 _nss_nis_getsecretkey (const char *netname, char *skey, char *passwd,
 		       int *errnop)
 {
+  enum nss_status retval;
+  char buf[2 * (HEXKEYBYTES + 1)];
+  char *domain, *result;
+  int len;
+
   skey[0] = 0;
 
   if (netname == NULL || passwd == NULL)
@@ -90,23 +94,19 @@ _nss_nis_getsecretkey (const char *netname, char *skey, char *passwd,
       return NSS_STATUS_UNAVAIL;
     }
 
-  char *domain = strchr (netname, '@');
-  if (domain == NULL)
+  domain = strchr (netname, '@');
+  if (!domain)
     {
       *errnop = EINVAL;
       return NSS_STATUS_UNAVAIL;
     }
   ++domain;
 
-  char *result;
-  int len;
-  int yperr = yp_match (domain, "publickey.byname", netname, strlen (netname),
-			&result, &len);
+  retval = yperr2nss (yp_match (domain, "publickey.byname", netname,
+				strlen (netname), &result, &len));
 
-  if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+  if (retval != NSS_STATUS_SUCCESS)
     {
-      enum nss_status retval = yperr2nss (yperr);
-
       if (retval == NSS_STATUS_TRYAGAIN)
 	*errnop = errno;
       return retval;
@@ -115,22 +115,20 @@ _nss_nis_getsecretkey (const char *netname, char *skey, char *passwd,
   if (result != NULL)
     {
       char *p = strchr (result, ':');
-      if (p != NULL)
-	{
-	  char buf[2 * (HEXKEYBYTES + 1)];
-
-	  ++p;
-	  strncpy (buf, p, 2 * (HEXKEYBYTES + 1));
-	  buf[2 * HEXKEYBYTES + 1] = '\0';
-	  if (xdecrypt (buf, passwd)
-	      && memcmp (buf, &(buf[HEXKEYBYTES]), KEYCHECKSUMSIZE) == 0)
-	    {
-	      buf[HEXKEYBYTES] = '\0';
-	      strcpy (skey, buf);
-	    }
-	}
-
-      free (result);
+      if (p == NULL)
+	return NSS_STATUS_SUCCESS;
+
+      ++p;
+      strncpy (buf, p, 2 * (HEXKEYBYTES + 1));
+      buf[2 * (HEXKEYBYTES + 1)] = '\0';
+      if (!xdecrypt (buf, passwd))
+	return NSS_STATUS_SUCCESS;
+
+      if (memcmp (buf, &(buf[HEXKEYBYTES]), KEYCHECKSUMSIZE) != 0)
+	return NSS_STATUS_SUCCESS;
+
+      buf[HEXKEYBYTES] = '\0';
+      strcpy (skey, buf);
     }
   return NSS_STATUS_SUCCESS;
 }
@@ -196,8 +194,13 @@ enum nss_status
 _nss_nis_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp,
 		       gid_t *gidp, int *gidlenp, gid_t *gidlist, int *errnop)
 {
-  char *domain = strchr (netname, '@');
-  if (domain == NULL)
+  char *domain;
+  int yperr;
+  char *lookup;
+  int len;
+
+  domain = strchr (netname, '@');
+  if (!domain)
     {
       *errnop = EINVAL;
       return NSS_STATUS_UNAVAIL;
@@ -205,10 +208,9 @@ _nss_nis_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp,
 
   /* Point past the '@' character */
   ++domain;
-  char *lookup = NULL;
-  int len;
-  int yperr = yp_match (domain, "netid.byname", netname, strlen (netname),
-			&lookup, &len);
+  lookup = NULL;
+  yperr = yp_match (domain, "netid.byname", netname, strlen (netname),
+		    &lookup, &len);
   switch (yperr)
     {
     case YPERR_SUCCESS:
@@ -221,15 +223,17 @@ _nss_nis_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp,
       return NSS_STATUS_UNAVAIL;
     }
 
-  if (lookup == NULL)
-    return NSS_STATUS_NOTFOUND;
-
-
-  lookup[len] = '\0';
-
-  enum nss_status err = parse_netid_str (lookup, uidp, gidp, gidlenp, gidlist);
+  if (lookup)
+    {
+      enum nss_status err;
 
-  free (lookup);
+      lookup[len] = '\0';
+      err = parse_netid_str (lookup, uidp, gidp, gidlenp, gidlist);
+      free (lookup);
+      return err;
+    }
+  else
+    return NSS_STATUS_NOTFOUND;
 
-  return err;
+  return NSS_STATUS_SUCCESS;
 }
diff --git a/nis/nss_nis/nis-pwd.c b/nis/nss_nis/nis-pwd.c
index 1b5206ad6d..0f56ced014 100644
--- a/nis/nss_nis/nis-pwd.c
+++ b/nis/nss_nis/nis-pwd.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-1998,2001,2002,2003,2006 Free Software Foundation, Inc.
+/* Copyright (C) 1996-1998, 2001, 2002, 2003 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
 
@@ -17,18 +17,20 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
 
-#include <assert.h>
-#include <ctype.h>
-#include <errno.h>
 #include <nss.h>
+/* The following is an ugly trick to avoid a prototype declaration for
+   _nss_nis_endpwent.  */
+#define _nss_nis_endpwent _nss_nis_endpwent_XXX
 #include <pwd.h>
+#undef _nss_nis_endpwent
+#include <ctype.h>
+#include <errno.h>
 #include <string.h>
 #include <bits/libc-lock.h>
 #include <rpcsvc/yp.h>
 #include <rpcsvc/ypclnt.h>
 
 #include "nss-nis.h"
-#include <libnsl.h>
 
 /* Get the declaration of the parser function.  */
 #define ENTNAME pwent
@@ -42,72 +44,12 @@ __libc_lock_define_initialized (static, lock)
 static bool_t new_start = 1;
 static char *oldkey;
 static int oldkeylen;
-static intern_t intern;
 
-
-int
-_nis_saveit (int instatus, char *inkey, int inkeylen, char *inval,
-	     int invallen, char *indata)
+enum nss_status
+_nss_nis_setpwent (int stayopen)
 {
-  intern_t *intern = (intern_t *) indata;
-
-  if (instatus != YP_TRUE)
-    return 1;
-
-  if (inkey && inkeylen > 0 && inval && invallen > 0)
-    {
-      struct response_t *bucket = intern->next;
-
-      if (__builtin_expect (bucket == NULL, 0))
-	{
-#define MINSIZE 4096 - 4 * sizeof (void *)
-	  const size_t minsize = MAX (MINSIZE, 2 * (invallen + 1));
-	  bucket = malloc (sizeof (struct response_t) + minsize);
-	  if (bucket == NULL)
-	    /* We have no error code for out of memory.  */
-	    return 1;
-
-	  bucket->next = NULL;
-	  bucket->size = minsize;
-	  intern->start = intern->next = bucket;
-	  intern->offset = 0;
-	}
-      else if (__builtin_expect (invallen + 1 > bucket->size - intern->offset,
-				 0))
-	{
-	  /* We need a new (larger) buffer.  */
-	  const size_t newsize = 2 * MAX (bucket->size, invallen + 1);
-	  struct response_t *newp = malloc (sizeof (struct response_t)
-					    + newsize);
-	  if (newp == NULL)
-	    /* We have no error code for out of memory.  */
-	    return 1;
-
-	  /* Mark the old bucket as full.  */
-	  bucket->size = intern->offset;
-
-	  newp->next = NULL;
-	  newp->size = newsize;
-	  bucket = intern->next = bucket->next = newp;
-	  intern->offset = 0;
-	}
-
-      char *p = mempcpy (&bucket->mem[intern->offset], inval, invallen);
-      if (__builtin_expect (p[-1] != '\0', 0))
-	{
-	  *p = '\0';
-	  ++invallen;
-	}
-      intern->offset += invallen;
-    }
-
-  return 0;
-}
-
+  __libc_lock_lock (lock);
 
-static void
-internal_nis_endpwent (void)
-{
   new_start = 1;
   if (oldkey != NULL)
     {
@@ -116,159 +58,52 @@ internal_nis_endpwent (void)
       oldkeylen = 0;
     }
 
-  struct response_t *curr = intern.next;
-
-  while (curr != NULL)
-    {
-      struct response_t *last = curr;
-      curr = curr->next;
-      free (last);
-    }
-
-  intern.next = intern.start = NULL;
-}
-
-
-enum nss_status
-_nss_nis_endpwent (void)
-{
-  __libc_lock_lock (lock);
-
-  internal_nis_endpwent ();
-
   __libc_lock_unlock (lock);
 
   return NSS_STATUS_SUCCESS;
 }
-
-
-enum nss_status
-internal_nis_setpwent (void)
-{
-  /* We have to read all the data now.  */
-  char *domain;
-  if (__builtin_expect (yp_get_default_domain (&domain), 0))
-    return NSS_STATUS_UNAVAIL;
-
-  struct ypall_callback ypcb;
-
-  ypcb.foreach = _nis_saveit;
-  ypcb.data = (char *) &intern;
-  enum nss_status status = yperr2nss (yp_all (domain, "passwd.byname", &ypcb));
-
-
-  /* Mark the last buffer as full.  */
-  if (intern.next != NULL)
-    intern.next->size = intern.offset;
-
-  intern.next = intern.start;
-  intern.offset = 0;
-
-  return status;
-}
-
-
-enum nss_status
-_nss_nis_setpwent (int stayopen)
-{
-  enum nss_status result = NSS_STATUS_SUCCESS;
-
-  __libc_lock_lock (lock);
-
-  internal_nis_endpwent ();
-
-  if (_nsl_default_nss () & NSS_FLAG_SETENT_BATCH_READ)
-    result = internal_nis_setpwent ();
-
-  __libc_lock_unlock (lock);
-
-  return result;
-}
-
+/* Make _nss_nis_endpwent an alias of _nss_nis_setpwent.  We do this
+   even though the prototypes don't match.  The argument of setpwent
+   is not used so this makes no difference.  */
+strong_alias (_nss_nis_setpwent, _nss_nis_endpwent)
 
 static enum nss_status
 internal_nis_getpwent_r (struct passwd *pwd, char *buffer, size_t buflen,
 			 int *errnop)
 {
-  /* If we read the entire database at setpwent time we just iterate
-     over the data we have in memory.  */
-  bool batch_read = intern.start != NULL;
+  struct parser_data *data = (void *) buffer;
+  char *domain;
+  int parse_res;
 
-  char *domain = NULL;
-  if (!batch_read && __builtin_expect (yp_get_default_domain (&domain), 0))
+  if (yp_get_default_domain (&domain))
     return NSS_STATUS_UNAVAIL;
 
   /* Get the next entry until we found a correct one. */
-  int parse_res;
   do
     {
-      char *result;
-      char *outkey;
-      int len;
-      int keylen;
-
-      if (batch_read)
-	{
-	  struct response_t *bucket;
-
-	handle_batch_read:
-	  bucket = intern.next;
-
-	  if (__builtin_expect (intern.offset >= bucket->size, 0))
-	    {
-	      if (bucket->next == NULL)
-		return NSS_STATUS_NOTFOUND;
-
-	      /* We look at all the content in the current bucket.  Go on
-		 to the next.  */
-	      bucket = intern.next = bucket->next;
-	      intern.offset = 0;
-	    }
-
-	  for (result = &bucket->mem[intern.offset]; isspace (*result);
-	       ++result)
-	    ++intern.offset;
+      enum nss_status retval;
+      char *result, *outkey, *result2, *p;
+      int len, keylen, len2;
+      size_t namelen;
 
-	  len = strlen (result);
-	}
+      if (new_start)
+        retval = yperr2nss (yp_first (domain, "passwd.byname",
+                                      &outkey, &keylen, &result, &len));
       else
-	{
-	  int yperr;
+        retval = yperr2nss ( yp_next (domain, "passwd.byname",
+                                      oldkey, oldkeylen,
+                                      &outkey, &keylen, &result, &len));
 
-	  if (new_start)
-	    {
-	      /* Maybe we should read the database in one piece.  */
-	      if ((_nsl_default_nss () & NSS_FLAG_SETENT_BATCH_READ)
-		  && internal_nis_setpwent () == NSS_STATUS_SUCCESS
-		  && intern.start != NULL)
-		{
-		  batch_read = true;
-		  goto handle_batch_read;
-		}
-
-	      yperr = yp_first (domain, "passwd.byname", &outkey, &keylen,
-				&result, &len);
-	    }
-	  else
-	    yperr = yp_next (domain, "passwd.byname", oldkey, oldkeylen,
-			     &outkey, &keylen, &result, &len);
-
-	  if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
-	    {
-	      enum nss_status retval = yperr2nss (yperr);
-
-	      if (retval == NSS_STATUS_TRYAGAIN)
-		*errnop = errno;
-	      return retval;
-	    }
-	}
+      if (retval != NSS_STATUS_SUCCESS)
+        {
+          if (retval == NSS_STATUS_TRYAGAIN)
+            *errnop = errno;
+          return retval;
+        }
 
       /* Check for adjunct style secret passwords.  They can be
 	 recognized by a password starting with "##".  */
-      char *p = strchr (result, ':');
-      size_t namelen;
-      char *result2;
-      int len2;
+      p = strchr (result, ':');
       if (p != NULL	/* This better should be true in all cases.  */
 	  && p[1] == '#' && p[2] == '#'
 	  && (namelen = p - result,
@@ -293,8 +128,7 @@ internal_nis_getpwent_r (struct passwd *pwd, char *buffer, size_t buflen,
 	    }
 
 	  restlen = len - (p - result);
-	  if (__builtin_expect ((size_t) (namelen + (endp - encrypted)
-					  + restlen + 2) > buflen, 0))
+	  if ((size_t) (namelen + (endp - encrypted) + restlen + 2) > buflen)
 	    {
 	      free (result2);
 	      free (result);
@@ -302,10 +136,10 @@ internal_nis_getpwent_r (struct passwd *pwd, char *buffer, size_t buflen,
 	      return NSS_STATUS_TRYAGAIN;
 	    }
 
-	  mempcpy (mempcpy (mempcpy (mempcpy (buffer, result, namelen),
-				     ":", 1),
-			    encrypted, endp - encrypted),
-		   p, restlen + 1);
+	  __mempcpy (__mempcpy (__mempcpy (__mempcpy (buffer, result, namelen),
+					   ":", 1),
+				encrypted, endp - encrypted),
+		     p, restlen + 1);
 	  p = buffer;
 
 	  free (result2);
@@ -313,41 +147,33 @@ internal_nis_getpwent_r (struct passwd *pwd, char *buffer, size_t buflen,
       else
 	{
 	non_adjunct:
-	  if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+	  if ((size_t) (len + 1) > buflen)
 	    {
 	      free (result);
 	      *errnop = ERANGE;
 	      return NSS_STATUS_TRYAGAIN;
 	    }
 
-	  p = buffer;
-	  *((char *) mempcpy (buffer, result, len)) = '\0';
+	  p = strncpy (buffer, result, len);
+	  buffer[len] = '\0';
 	}
 
       while (isspace (*p))
         ++p;
-      if (!batch_read)
-	free (result);
+      free (result);
 
-      parse_res = _nss_files_parse_pwent (p, pwd, (void *) buffer, buflen,
-					  errnop);
-      if (__builtin_expect (parse_res == -1, 0))
+      parse_res = _nss_files_parse_pwent (p, pwd, data, buflen, errnop);
+      if (parse_res == -1)
 	{
-	  if (!batch_read)
-	    free (outkey);
+	  free (outkey);
 	  *errnop = ERANGE;
 	  return NSS_STATUS_TRYAGAIN;
 	}
 
-      if (batch_read)
-	intern.offset += len + 1;
-      else
-	{
-	  free (oldkey);
-	  oldkey = outkey;
-	  oldkeylen = keylen;
-	  new_start = 0;
-	}
+      free (oldkey);
+      oldkey = outkey;
+      oldkeylen = keylen;
+      new_start = 0;
     }
   while (parse_res < 1);
 
@@ -373,26 +199,28 @@ enum nss_status
 _nss_nis_getpwnam_r (const char *name, struct passwd *pwd,
 		     char *buffer, size_t buflen, int *errnop)
 {
+  struct parser_data *data = (void *) buffer;
+  enum nss_status retval;
+  char *domain, *result, *result2, *p;
+  int len, len2, parse_res;
+  size_t namelen;
+
   if (name == NULL)
     {
       *errnop = EINVAL;
       return NSS_STATUS_UNAVAIL;
     }
 
-  char *domain;
-  if (__builtin_expect (yp_get_default_domain (&domain), 0))
+  if (yp_get_default_domain (&domain))
     return NSS_STATUS_UNAVAIL;
 
-  size_t namelen = strlen (name);
+  namelen = strlen (name);
 
-  char *result;
-  int len;
-  int yperr = yp_match (domain, "passwd.byname", name, namelen, &result, &len);
+  retval = yperr2nss (yp_match (domain, "passwd.byname", name,
+				namelen, &result, &len));
 
-  if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+  if (retval != NSS_STATUS_SUCCESS)
     {
-      enum nss_status retval = yperr2nss (yperr);
-
       if (retval == NSS_STATUS_TRYAGAIN)
 	*errnop = errno;
       return retval;
@@ -400,9 +228,7 @@ _nss_nis_getpwnam_r (const char *name, struct passwd *pwd,
 
   /* Check for adjunct style secret passwords.  They can be recognized
      by a password starting with "##".  */
-  char *result2;
-  int len2;
-  char *p = strchr (result, ':');
+  p = strchr (result, ':');
   if (p != NULL	/* This better should be true in all cases.  */
       && p[1] == '#' && p[2] == '#'
       && yp_match (domain, "passwd.adjunct.byname", name, namelen,
@@ -412,6 +238,7 @@ _nss_nis_getpwnam_r (const char *name, struct passwd *pwd,
 	 therein into original result.  */
       char *encrypted = strchr (result2, ':');
       char *endp;
+      size_t restlen;
 
       if (encrypted == NULL
 	  || (endp = strchr (++encrypted, ':')) == NULL
@@ -424,9 +251,8 @@ _nss_nis_getpwnam_r (const char *name, struct passwd *pwd,
 	  goto non_adjunct;
 	}
 
-      size_t restlen = len - (p - result);
-      if (__builtin_expect ((size_t) (namelen + (endp - encrypted)
-				      + restlen + 2) > buflen, 0))
+      restlen = len - (p - result);
+      if ((size_t) (namelen + (endp - encrypted) + restlen + 2) > buflen)
 	{
 	  free (result2);
 	  free (result);
@@ -445,7 +271,7 @@ _nss_nis_getpwnam_r (const char *name, struct passwd *pwd,
   else
     {
     non_adjunct:
-      if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+      if ((size_t) (len + 1) > buflen)
 	{
 	  free (result);
 	  *errnop = ERANGE;
@@ -460,9 +286,8 @@ _nss_nis_getpwnam_r (const char *name, struct passwd *pwd,
     ++p;
   free (result);
 
-  int parse_res = _nss_files_parse_pwent (p, pwd, (void *) buffer, buflen,
-					  errnop);
-  if (__builtin_expect (parse_res < 1, 0))
+  parse_res = _nss_files_parse_pwent (p, pwd, data, buflen, errnop);
+  if (parse_res < 1)
     {
       if (parse_res == -1)
         return NSS_STATUS_TRYAGAIN;
@@ -477,21 +302,23 @@ enum nss_status
 _nss_nis_getpwuid_r (uid_t uid, struct passwd *pwd,
 		     char *buffer, size_t buflen, int *errnop)
 {
-  char *domain;
-  if (__builtin_expect (yp_get_default_domain (&domain), 0))
+  struct parser_data *data = (void *) buffer;
+  enum nss_status retval;
+  char *domain, *result, *p, *result2;
+  int len, nlen, parse_res, len2;
+  char buf[32];
+  size_t namelen;
+
+  if (yp_get_default_domain (&domain))
     return NSS_STATUS_UNAVAIL;
 
-  char buf[32];
-  int nlen = snprintf (buf, sizeof (buf), "%lu", (unsigned long int) uid);
+  nlen = sprintf (buf, "%lu", (unsigned long int) uid);
 
-  char *result;
-  int len;
-  int yperr = yp_match (domain, "passwd.byuid", buf, nlen, &result, &len);
+  retval = yperr2nss (yp_match (domain, "passwd.byuid", buf,
+				nlen, &result, &len));
 
-  if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+  if (retval != NSS_STATUS_SUCCESS)
     {
-      enum nss_status retval = yperr2nss (yperr);
-
       if (retval == NSS_STATUS_TRYAGAIN)
 	*errnop = errno;
       return retval;
@@ -499,10 +326,7 @@ _nss_nis_getpwuid_r (uid_t uid, struct passwd *pwd,
 
   /* Check for adjunct style secret passwords.  They can be recognized
      by a password starting with "##".  */
-  char *result2;
-  int len2;
-  size_t namelen;
-  char *p = strchr (result, ':');
+  p = strchr (result, ':');
   if (p != NULL	/* This better should be true in all cases.  */
       && p[1] == '#' && p[2] == '#'
       && (namelen = p - result,
@@ -527,8 +351,7 @@ _nss_nis_getpwuid_r (uid_t uid, struct passwd *pwd,
 	}
 
       restlen = len - (p - result);
-      if (__builtin_expect ((size_t) (namelen + (endp - encrypted)
-				      + restlen + 2) > buflen, 0))
+      if ((size_t) (namelen + (endp - encrypted) + restlen + 2) > buflen)
 	{
 	  free (result2);
 	  free (result);
@@ -547,7 +370,7 @@ _nss_nis_getpwuid_r (uid_t uid, struct passwd *pwd,
   else
     {
     non_adjunct:
-      if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+      if ((size_t) (len + 1) > buflen)
 	{
 	  free (result);
 	  *errnop = ERANGE;
@@ -562,9 +385,8 @@ _nss_nis_getpwuid_r (uid_t uid, struct passwd *pwd,
     ++p;
   free (result);
 
-  int parse_res = _nss_files_parse_pwent (p, pwd, (void *) buffer, buflen,
-					  errnop);
-  if (__builtin_expect (parse_res < 1, 0))
+  parse_res = _nss_files_parse_pwent (p, pwd, data, buflen, errnop);
+  if (parse_res < 1)
     {
       if (parse_res == -1)
         return NSS_STATUS_TRYAGAIN;
diff --git a/nis/nss_nis/nis-rpc.c b/nis/nss_nis/nis-rpc.c
index 2fdb16ddde..d1ab94371a 100644
--- a/nis/nss_nis/nis-rpc.c
+++ b/nis/nss_nis/nis-rpc.c
@@ -1,5 +1,4 @@
-/* Copyright (C) 1996-1998,2000,2002,2003,2004,2006
-   Free Software Foundation, Inc.
+/* Copyright (C) 1996-1998,2000,2002,2003,2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
 
@@ -36,22 +35,59 @@
 
 __libc_lock_define_initialized (static, lock)
 
-static intern_t intern;
+struct response_t
+{
+  struct response_t *next;
+  char val[0];
+};
 
+struct intern_t
+{
+  struct response_t *start;
+  struct response_t *next;
+};
+typedef struct intern_t intern_t;
 
-static void
-internal_nis_endrpcent (intern_t *intern)
+static intern_t intern = {NULL, NULL};
+
+static int
+saveit (int instatus, char *inkey, int inkeylen, char *inval,
+        int invallen, char *indata)
 {
-  struct response_t *curr = intern->next;
+  intern_t *intern = (intern_t *)indata;
+
+  if (instatus != YP_TRUE)
+    return 1;
 
-  while (curr != NULL)
+  if (inkey && inkeylen > 0 && inval && invallen > 0)
     {
-      struct response_t *last = curr;
-      curr = curr->next;
-      free (last);
+      struct response_t *newp = malloc (sizeof (struct response_t)
+					+ invallen + 1);
+      if (newp == NULL)
+	return 1; /* We have no error code for out of memory */
+
+      if (intern->start == NULL)
+	intern->start = newp;
+      else
+	intern->next->next = newp;
+      intern->next = newp;
+
+      newp->next = NULL;
+      *((char *) mempcpy (newp->val, inval, invallen)) = '\0';
     }
 
-  intern->next = intern->start = NULL;
+  return 0;
+}
+
+static void
+internal_nis_endrpcent (intern_t *intern)
+{
+  while (intern->start != NULL)
+    {
+      intern->next = intern->start;
+      intern->start = intern->start->next;
+      free (intern->next);
+    }
 }
 
 static enum nss_status
@@ -66,16 +102,10 @@ internal_nis_setrpcent (intern_t *intern)
 
   internal_nis_endrpcent (intern);
 
-  ypcb.foreach = _nis_saveit;
-  ypcb.data = (char *) intern;
-  status = yperr2nss (yp_all (domainname, "rpc.bynumber", &ypcb));
-
-  /* Mark the last buffer as full.  */
-  if (intern->next != NULL)
-    intern->next->size = intern->offset;
-
+  ypcb.foreach = saveit;
+  ypcb.data = (char *)intern;
+  status = yperr2nss (yp_all(domainname, "rpc.bynumber", &ypcb));
   intern->next = intern->start;
-  intern->offset = 0;
 
   return status;
 }
@@ -108,60 +138,29 @@ _nss_nis_endrpcent (void)
 
 static enum nss_status
 internal_nis_getrpcent_r (struct rpcent *rpc, char *buffer, size_t buflen,
-			  int *errnop, intern_t *intern)
+			  int *errnop, intern_t *data)
 {
   struct parser_data *pdata = (void *) buffer;
   int parse_res;
   char *p;
 
-  if (intern->start == NULL)
-    internal_nis_setrpcent (intern);
-
-  if (intern->next == NULL)
-    /* Not one entry in the map.  */
-    return NSS_STATUS_NOTFOUND;
+  if (data->start == NULL)
+    internal_nis_setrpcent (data);
 
   /* Get the next entry until we found a correct one. */
   do
     {
-      struct response_t *bucket = intern->next;
-
-      if (__builtin_expect (intern->offset >= bucket->size, 0))
-	{
-	  if (bucket->next == NULL)
-	    return NSS_STATUS_NOTFOUND;
-
-	  /* We look at all the content in the current bucket.  Go on
-	     to the next.  */
-	  bucket = intern->next = bucket->next;
-	  intern->offset = 0;
-	}
-
-      for (p = &bucket->mem[intern->offset]; isspace (*p); ++p)
-        ++intern->offset;
-
-      size_t len = strlen (p) + 1;
-      if (__builtin_expect (len > buflen, 0))
-	{
-	  *errnop = ERANGE;
-	  return NSS_STATUS_TRYAGAIN;
-	}
-
-      /* We unfortunately have to copy the data in the user-provided
-	 buffer because that buffer might be around for a very long
-	 time and the servent structure must remain valid.  If we would
-	 rely on the BUCKET memory the next 'setservent' or 'endservent'
-	 call would destroy it.
+      if (data->next == NULL)
+	return NSS_STATUS_NOTFOUND;
 
-	 The important thing is that it is a single NUL-terminated
-	 string.  This is what the parsing routine expects.  */
-      p = memcpy (buffer, &bucket->mem[intern->offset], len);
+      p = strncpy (buffer, data->next->val, buflen);
+      while (isspace (*p))
+        ++p;
 
       parse_res = _nss_files_parse_rpcent (p, rpc, pdata, buflen, errnop);
-      if (__builtin_expect (parse_res == -1, 0))
+      if (parse_res == -1)
 	return NSS_STATUS_TRYAGAIN;
-
-      intern->offset += len;
+      data->next = data->next->next;
     }
   while (!parse_res);
 
@@ -187,18 +186,21 @@ enum nss_status
 _nss_nis_getrpcbyname_r (const char *name, struct rpcent *rpc,
 			 char *buffer, size_t buflen, int *errnop)
 {
+  intern_t data = {NULL, NULL};
+  enum nss_status status;
+  int found;
+
   if (name == NULL)
     {
       *errnop = EINVAL;
       return NSS_STATUS_UNAVAIL;
     }
 
-  intern_t data = { NULL, NULL, 0 };
-  enum nss_status status = internal_nis_setrpcent (&data);
-  if (__builtin_expect (status != NSS_STATUS_SUCCESS, 0))
+  status = internal_nis_setrpcent (&data);
+  if (status != NSS_STATUS_SUCCESS)
     return status;
 
-  int found = 0;
+  found = 0;
   while (!found &&
          ((status = internal_nis_getrpcent_r (rpc, buffer, buflen, errnop,
 					      &data)) == NSS_STATUS_SUCCESS))
@@ -224,52 +226,53 @@ _nss_nis_getrpcbyname_r (const char *name, struct rpcent *rpc,
 
   internal_nis_endrpcent (&data);
 
-  if (__builtin_expect (!found && status == NSS_STATUS_SUCCESS, 0))
+  if (!found && status == NSS_STATUS_SUCCESS)
     return NSS_STATUS_NOTFOUND;
-
-  return status;
+  else
+    return status;
 }
 
 enum nss_status
 _nss_nis_getrpcbynumber_r (int number, struct rpcent *rpc,
 			   char *buffer, size_t buflen, int *errnop)
 {
-  char *domain;
-  if (__builtin_expect (yp_get_default_domain (&domain), 0))
+  struct parser_data *data = (void *) buffer;
+  enum nss_status retval;
+  char *domain, *result, *p;
+  int len, nlen, parse_res;
+  char buf[32];
+
+  if (yp_get_default_domain (&domain))
     return NSS_STATUS_UNAVAIL;
 
-  char buf[32];
-  int nlen = snprintf (buf, sizeof (buf), "%d", number);
+  nlen = sprintf (buf, "%d", number);
 
-  char *result;
-  int len;
-  int yperr = yp_match (domain, "rpc.bynumber", buf, nlen, &result, &len);
+  retval = yperr2nss (yp_match (domain, "rpc.bynumber", buf,
+				 nlen, &result, &len));
 
-  if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+  if (retval != NSS_STATUS_SUCCESS)
     {
-      enum nss_status retval = yperr2nss (yperr);
-
       if (retval == NSS_STATUS_TRYAGAIN)
 	*errnop = errno;
       return retval;
     }
 
-  if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+  if ((size_t) (len + 1) > buflen)
     {
       free (result);
       *errnop = ERANGE;
       return NSS_STATUS_TRYAGAIN;
     }
 
-  char *p = strncpy (buffer, result, len);
+  p = strncpy (buffer, result, len);
   buffer[len] = '\0';
   while (isspace (*p))
     ++p;
   free (result);
 
-  int parse_res = _nss_files_parse_rpcent (p, rpc, (void  *) buffer, buflen,
-					   errnop);
-  if (__builtin_expect (parse_res < 1, 0))
+  parse_res = _nss_files_parse_rpcent (p, rpc, data, buflen, errnop);
+
+  if (parse_res < 1)
     {
       if (parse_res == -1)
 	return NSS_STATUS_TRYAGAIN;
diff --git a/nis/nss_nis/nis-service.c b/nis/nss_nis/nis-service.c
index 59a598f296..1e879d04e3 100644
--- a/nis/nss_nis/nis-service.c
+++ b/nis/nss_nis/nis-service.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2004, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2001, 2002, 2003, 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
 
@@ -27,7 +27,6 @@
 #include <rpcsvc/ypclnt.h>
 
 #include "nss-nis.h"
-#include <libnsl.h>
 
 
 /* Get the declaration of the parser function.  */
@@ -37,7 +36,20 @@
 
 __libc_lock_define_initialized (static, lock)
 
-static intern_t intern;
+struct response_t
+{
+  struct response_t *next;
+  char val[0];
+};
+
+struct intern_t
+{
+  struct response_t *start;
+  struct response_t *next;
+};
+typedef struct intern_t intern_t;
+
+static intern_t intern = { NULL, NULL };
 
 struct search_t
 {
@@ -52,31 +64,63 @@ struct search_t
 };
 
 static int
+saveit (int instatus, char *inkey, int inkeylen, char *inval,
+        int invallen, char *indata)
+{
+  intern_t *intern = (intern_t *) indata;
+
+  if (instatus != YP_TRUE)
+    return 1;
+
+  if (inkey && inkeylen > 0 && inval && invallen > 0)
+    {
+      struct response_t *newp = malloc (sizeof (struct response_t)
+					+ invallen + 1);
+      if (newp == NULL)
+	return 1; /* We have no error code for out of memory */
+
+      if (intern->start == NULL)
+	intern->start = newp;
+      else
+	intern->next->next = newp;
+      intern->next = newp;
+
+      newp->next = NULL;
+      *((char *) mempcpy (newp->val, inval, invallen)) = '\0';
+    }
+
+  return 0;
+}
+
+static int
 dosearch (int instatus, char *inkey, int inkeylen, char *inval,
 	  int invallen, char *indata)
 {
   struct search_t *req = (struct search_t *) indata;
 
-  if (__builtin_expect (instatus != YP_TRUE, 0))
+  if (instatus != YP_TRUE)
     return 1;
 
   if (inkey && inkeylen > 0 && inval && invallen > 0)
     {
-      if (__builtin_expect ((size_t) (invallen + 1) > req->buflen, 0))
+      struct parser_data *pdata = (void *) req->buffer;
+      int parse_res;
+      char *p;
+
+      if ((size_t) (invallen + 1) > req->buflen)
 	{
 	  *req->errnop = ERANGE;
 	  req->status = NSS_STATUS_TRYAGAIN;
 	  return 1;
 	}
 
-      char *p = strncpy (req->buffer, inval, invallen);
+      p = strncpy (req->buffer, inval, invallen);
       req->buffer[invallen] = '\0';
       while (isspace (*p))
         ++p;
 
-      int parse_res = _nss_files_parse_servent (p, req->serv,
-						(void *) req->buffer,
-						req->buflen, req->errnop);
+      parse_res = _nss_files_parse_servent (p, req->serv, pdata, req->buflen,
+					    req->errnop);
       if (parse_res == -1)
 	{
 	  req->status = NSS_STATUS_TRYAGAIN;
@@ -110,35 +154,35 @@ dosearch (int instatus, char *inkey, int inkeylen, char *inval,
   return 0;
 }
 
-static void
-internal_nis_endservent (void)
+static enum nss_status
+internal_nis_endservent (intern_t * intern)
 {
-  struct response_t *curr = intern.next;
-
-  while (curr != NULL)
+  while (intern->start != NULL)
     {
-      struct response_t *last = curr;
-      curr = curr->next;
-      free (last);
+      intern->next = intern->start;
+      intern->start = intern->start->next;
+      free (intern->next);
     }
 
-  intern.next = intern.start = NULL;
+  return NSS_STATUS_SUCCESS;
 }
 
 enum nss_status
 _nss_nis_endservent (void)
 {
+  enum nss_status status;
+
   __libc_lock_lock (lock);
 
-  internal_nis_endservent ();
+  status = internal_nis_endservent (&intern);
 
   __libc_lock_unlock (lock);
 
-  return NSS_STATUS_SUCCESS;
+  return status;
 }
 
 static enum nss_status
-internal_nis_setservent (void)
+internal_nis_setservent (intern_t *intern)
 {
   char *domainname;
   struct ypall_callback ypcb;
@@ -147,18 +191,12 @@ internal_nis_setservent (void)
   if (yp_get_default_domain (&domainname))
     return NSS_STATUS_UNAVAIL;
 
-  internal_nis_endservent ();
+  (void) internal_nis_endservent (intern);
 
-  ypcb.foreach = _nis_saveit;
-  ypcb.data = (char *) &intern;
+  ypcb.foreach = saveit;
+  ypcb.data = (char *) intern;
   status = yperr2nss (yp_all (domainname, "services.byname", &ypcb));
-
-  /* Mark the last buffer as full.  */
-  if (intern.next != NULL)
-    intern.next->size = intern.offset;
-
-  intern.next = intern.start;
-  intern.offset = 0;
+  intern->next = intern->start;
 
   return status;
 }
@@ -170,7 +208,7 @@ _nss_nis_setservent (int stayopen)
 
   __libc_lock_lock (lock);
 
-  status = internal_nis_setservent ();
+  status = internal_nis_setservent (&intern);
 
   __libc_lock_unlock (lock);
 
@@ -179,60 +217,29 @@ _nss_nis_setservent (int stayopen)
 
 static enum nss_status
 internal_nis_getservent_r (struct servent *serv, char *buffer,
-			   size_t buflen, int *errnop)
+			   size_t buflen, int *errnop, intern_t *data)
 {
   struct parser_data *pdata = (void *) buffer;
   int parse_res;
   char *p;
 
-  if (intern.start == NULL)
-    internal_nis_setservent ();
+  if (data->start == NULL)
+    internal_nis_setservent (data);
 
-  if (intern.next == NULL)
-    /* Not one entry in the map.  */
-    return NSS_STATUS_NOTFOUND;
-
-  /* Get the next entry until we found a correct one.  */
+  /* Get the next entry until we found a correct one. */
   do
     {
-      struct response_t *bucket = intern.next;
+      if (data->next == NULL)
+	return NSS_STATUS_NOTFOUND;
 
-      if (__builtin_expect (intern.offset >= bucket->size, 0))
-	{
-	  if (bucket->next == NULL)
-	    return NSS_STATUS_NOTFOUND;
-
-	  /* We look at all the content in the current bucket.  Go on
-	     to the next.  */
-	  bucket = intern.next = bucket->next;
-	  intern.offset = 0;
-	}
-
-      for (p = &bucket->mem[intern.offset]; isspace (*p); ++p)
-        ++intern.offset;
-
-      size_t len = strlen (p) + 1;
-      if (__builtin_expect (len > buflen, 0))
-	{
-	  *errnop = ERANGE;
-	  return NSS_STATUS_TRYAGAIN;
-	}
-
-      /* We unfortunately have to copy the data in the user-provided
-	 buffer because that buffer might be around for a very long
-	 time and the servent structure must remain valid.  If we would
-	 rely on the BUCKET memory the next 'setservent' or 'endservent'
-	 call would destroy it.
-
-	 The important thing is that it is a single NUL-terminated
-	 string.  This is what the parsing routine expects.  */
-      p = memcpy (buffer, &bucket->mem[intern.offset], len);
+      p = strncpy (buffer, data->next->val, buflen);
+      while (isspace (*p))
+        ++p;
 
       parse_res = _nss_files_parse_servent (p, serv, pdata, buflen, errnop);
-      if (__builtin_expect (parse_res == -1, 0))
+      if (parse_res == -1)
         return NSS_STATUS_TRYAGAIN;
-
-      intern.offset += len;
+      data->next = data->next->next;
     }
   while (!parse_res);
 
@@ -247,7 +254,7 @@ _nss_nis_getservent_r (struct servent *serv, char *buffer, size_t buflen,
 
   __libc_lock_lock (lock);
 
-  status = internal_nis_getservent_r (serv, buffer, buflen, errnop);
+  status = internal_nis_getservent_r (serv, buffer, buflen, errnop, &intern);
 
   __libc_lock_unlock (lock);
 
@@ -259,55 +266,60 @@ _nss_nis_getservbyname_r (const char *name, const char *protocol,
 			  struct servent *serv, char *buffer, size_t buflen,
 			  int *errnop)
 {
+  enum nss_status status;
+  char *domain;
+
   if (name == NULL)
     {
       *errnop = EINVAL;
       return NSS_STATUS_UNAVAIL;
     }
 
-  char *domain;
-  if (__builtin_expect (yp_get_default_domain (&domain), 0))
+  if (yp_get_default_domain (&domain))
     return NSS_STATUS_UNAVAIL;
 
   /* If the protocol is given, we could try if our NIS server knows
      about services.byservicename map. If yes, we only need one query.  */
-  size_t keylen = strlen (name) + (protocol ? 1 + strlen (protocol) : 0);
-  char key[keylen + 1];
+  char key[strlen (name) + (protocol ? strlen (protocol) : 0) + 2];
+  char *cp, *result;
+  size_t keylen, len;
+  int int_len;
 
   /* key is: "name/proto" */
-  char *cp = stpcpy (key, name);
-  if (protocol != NULL)
+  cp = stpcpy (key, name);
+  if (protocol)
     {
       *cp++ = '/';
       strcpy (cp, protocol);
     }
-
-  char *result;
-  int int_len;
-  int status = yp_match (domain, "services.byservicename", key,
-			 keylen, &result, &int_len);
-  size_t len = int_len;
+  keylen = strlen (key);
+  status = yperr2nss (yp_match (domain, "services.byservicename", key,
+				keylen, &result, &int_len));
+  len = int_len;
 
   /* If we found the key, it's ok and parse the result. If not,
      fall through and parse the complete table. */
-  if (__builtin_expect (status == YPERR_SUCCESS, 1))
+  if (status == NSS_STATUS_SUCCESS)
     {
-      if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+      struct parser_data *pdata = (void *) buffer;
+      int parse_res;
+      char *p;
+
+      if ((size_t) (len + 1) > buflen)
 	{
 	  free (result);
 	  *errnop = ERANGE;
 	  return NSS_STATUS_TRYAGAIN;
 	}
 
-      char *p = strncpy (buffer, result, len);
+      p = strncpy (buffer, result, len);
       buffer[len] = '\0';
       while (isspace (*p))
 	++p;
       free (result);
-
-      int parse_res = _nss_files_parse_servent (p, serv, (void *) buffer,
-						buflen, errnop);
-      if (__builtin_expect (parse_res < 0, 0))
+      parse_res = _nss_files_parse_servent (p, serv, pdata,
+					    buflen, errnop);
+      if (parse_res < 0)
 	{
 	  if (parse_res == -1)
 	    return NSS_STATUS_TRYAGAIN;
@@ -319,8 +331,8 @@ _nss_nis_getservbyname_r (const char *name, const char *protocol,
     }
 
   /* Check if it is safe to rely on services.byservicename.  */
-  if (_nsl_default_nss () & NSS_FLAG_SERVICES_AUTHORITATIVE)
-    return yperr2nss (status);
+  if (_nis_default_nss () & NSS_FLAG_SERVICES_AUTHORITATIVE)
+    return status;
 
   struct ypall_callback ypcb;
   struct search_t req;
@@ -335,10 +347,10 @@ _nss_nis_getservbyname_r (const char *name, const char *protocol,
   req.buflen = buflen;
   req.errnop = errnop;
   req.status = NSS_STATUS_NOTFOUND;
-  status = yp_all (domain, "services.byname", &ypcb);
+  status = yperr2nss (yp_all (domain, "services.byname", &ypcb));
 
-  if (__builtin_expect (status != YPERR_SUCCESS, 0))
-    return yperr2nss (status);
+  if (status != NSS_STATUS_SUCCESS)
+    return status;
 
   return req.status;
 }
@@ -348,8 +360,10 @@ _nss_nis_getservbyport_r (int port, const char *protocol,
 			  struct servent *serv, char *buffer,
 			  size_t buflen, int *errnop)
 {
+  enum nss_status status;
   char *domain;
-  if (__builtin_expect (yp_get_default_domain (&domain), 0))
+
+  if (yp_get_default_domain (&domain))
     return NSS_STATUS_UNAVAIL;
 
   /* If the protocol is given, we only need one query.
@@ -358,44 +372,48 @@ _nss_nis_getservbyport_r (int port, const char *protocol,
   const char *proto = protocol != NULL ? protocol : "tcp";
   do
     {
-      /* key is: "port/proto" */
       char key[sizeof (int) * 3 + strlen (proto) + 2];
-      size_t keylen = snprintf (key, sizeof (key), "%d/%s", ntohs (port),
-				proto);
-
       char *result;
+      size_t keylen, len;
       int int_len;
-      int status = yp_match (domain, "services.byname", key, keylen, &result,
-			     &int_len);
-      size_t len = int_len;
+
+      /* key is: "port/proto" */
+      keylen = snprintf (key, sizeof (key), "%d/%s", ntohs (port), proto);
+      status = yperr2nss (yp_match (domain, "services.byname", key,
+				    keylen, &result, &int_len));
+      len = int_len;
 
       /* If we found the key, it's ok and parse the result. If not,
 	 fall through and parse the complete table. */
-      if (__builtin_expect (status == YPERR_SUCCESS, 1))
+      if (status == NSS_STATUS_SUCCESS)
 	{
-	  if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+	  struct parser_data *pdata = (void *) buffer;
+	  int parse_res;
+	  char *p;
+
+	  if ((size_t) (len + 1) > buflen)
 	    {
 	      free (result);
 	      *errnop = ERANGE;
 	      return NSS_STATUS_TRYAGAIN;
 	    }
 
-	  char  *p = strncpy (buffer, result, len);
+	  p = strncpy (buffer, result, len);
 	  buffer[len] = '\0';
 	  while (isspace (*p))
 	    ++p;
 	  free (result);
-	  int parse_res = _nss_files_parse_servent (p, serv, (void *) buffer,
-						    buflen, errnop);
-	  if (__builtin_expect (parse_res < 0, 0))
+	  parse_res = _nss_files_parse_servent (p, serv, pdata,
+						buflen, errnop);
+	  if (parse_res < 0)
 	    {
 	      if (parse_res == -1)
 		return NSS_STATUS_TRYAGAIN;
 	      else
 		return NSS_STATUS_NOTFOUND;
 	    }
-
-	  return NSS_STATUS_SUCCESS;
+	  else
+	    return NSS_STATUS_SUCCESS;
 	}
     }
   while (protocol == NULL && (proto[0] == 't' ? (proto = "udp") : NULL));
@@ -416,10 +434,10 @@ _nss_nis_getservbyport_r (int port, const char *protocol,
   req.buflen = buflen;
   req.errnop = errnop;
   req.status = NSS_STATUS_NOTFOUND;
-  int status = yp_all (domain, "services.byname", &ypcb);
+  status = yperr2nss (yp_all (domain, "services.byname", &ypcb));
 
-  if (__builtin_expect (status != YPERR_SUCCESS, 0))
-    return yperr2nss (status);
+  if (status != NSS_STATUS_SUCCESS)
+    return status;
 
   return req.status;
 }
diff --git a/nis/nss_nis/nis-spwd.c b/nis/nss_nis/nis-spwd.c
index 0fc4e17c42..99a9ed5f48 100644
--- a/nis/nss_nis/nis-spwd.c
+++ b/nis/nss_nis/nis-spwd.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-1998,2001,2002,2003,2006 Free Software Foundation, Inc.
+/* Copyright (C) 1996-1998, 2001, 2002, 2003 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
 
@@ -68,52 +68,49 @@ static enum nss_status
 internal_nis_getspent_r (struct spwd *sp, char *buffer, size_t buflen,
 			 int *errnop)
 {
-  char *domain;
-  if (__builtin_expect (yp_get_default_domain (&domain), 0))
+  struct parser_data *data = (void *) buffer;
+  char *domain, *result, *outkey;
+  int len, keylen, parse_res;
+
+  if (yp_get_default_domain (&domain))
     return NSS_STATUS_UNAVAIL;
 
   /* Get the next entry until we found a correct one. */
-  int parse_res;
   do
     {
-      char *result;
-      char *outkey;
-      int len;
-      int keylen;
-      int yperr;
+      enum nss_status retval;
+      char *p;
 
       if (new_start)
-        yperr = yp_first (domain, "shadow.byname", &outkey, &keylen, &result,
-			  &len);
+        retval = yperr2nss (yp_first (domain, "shadow.byname",
+                                      &outkey, &keylen, &result, &len));
       else
-        yperr = yp_next (domain, "shadow.byname", oldkey, oldkeylen, &outkey,
-			 &keylen, &result, &len);
+        retval = yperr2nss ( yp_next (domain, "shadow.byname",
+                                      oldkey, oldkeylen,
+                                      &outkey, &keylen, &result, &len));
 
-      if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+      if (retval != NSS_STATUS_SUCCESS)
         {
-	  enum nss_status retval = yperr2nss (yperr);
-
 	  if (retval == NSS_STATUS_TRYAGAIN)
 	    *errnop = errno;
           return retval;
         }
 
-      if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+      if ((size_t) (len + 1) > buflen)
         {
           free (result);
 	  *errnop = ERANGE;
           return NSS_STATUS_TRYAGAIN;
         }
 
-      char *p = strncpy (buffer, result, len);
+      p = strncpy (buffer, result, len);
       buffer[len] = '\0';
       while (isspace (*p))
         ++p;
       free (result);
 
-      parse_res = _nss_files_parse_spent (p, sp, (void *) buffer, buflen,
-					  errnop);
-      if (__builtin_expect  (parse_res == -1, 0))
+      parse_res = _nss_files_parse_spent (p, sp, data, buflen, errnop);
+      if (parse_res == -1)
 	{
 	  free (outkey);
 	  *errnop = ERANGE;
@@ -149,46 +146,45 @@ enum nss_status
 _nss_nis_getspnam_r (const char *name, struct spwd *sp,
 		     char *buffer, size_t buflen, int *errnop)
 {
+  struct parser_data *data = (void *) buffer;
+  enum nss_status retval;
+  char *domain, *result, *p;
+  int len, parse_res;
+
   if (name == NULL)
     {
       *errnop = EINVAL;
       return NSS_STATUS_UNAVAIL;
     }
 
-  char *domain;
-  if (__builtin_expect (yp_get_default_domain (&domain), 0))
+  if (yp_get_default_domain (&domain))
     return NSS_STATUS_UNAVAIL;
 
-  char *result;
-  int len;
-  int yperr = yp_match (domain, "shadow.byname", name, strlen (name), &result,
-			&len);
+  retval = yperr2nss (yp_match (domain, "shadow.byname", name,
+				strlen (name), &result, &len));
 
-  if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+  if (retval != NSS_STATUS_SUCCESS)
     {
-      enum nss_status retval = yperr2nss (yperr);
-
       if (retval == NSS_STATUS_TRYAGAIN)
 	*errnop = errno;
       return retval;
     }
 
-  if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+  if ((size_t) (len + 1) > buflen)
     {
       free (result);
       *errnop = ERANGE;
       return NSS_STATUS_TRYAGAIN;
     }
 
-  char *p = strncpy (buffer, result, len);
+  p = strncpy (buffer, result, len);
   buffer[len] = '\0';
   while (isspace (*p))
     ++p;
   free (result);
 
-  int parse_res = _nss_files_parse_spent (p, sp, (void *) buffer, buflen,
-					  errnop);
-  if (__builtin_expect (parse_res < 1, 0))
+  parse_res = _nss_files_parse_spent (p, sp, data, buflen, errnop);
+  if (parse_res < 1)
     {
       if (parse_res == -1)
 	return NSS_STATUS_TRYAGAIN;