about summary refs log tree commit diff
path: root/nis/nss_nisplus
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2002-08-26 07:06:57 +0000
committerUlrich Drepper <drepper@redhat.com>2002-08-26 07:06:57 +0000
commit34816665b678a06e096a378303b68d35ff10a693 (patch)
tree471e49cf229dc64a80a72764e1d2db2c9c6e2818 /nis/nss_nisplus
parent40e15c4da81e899cbb4c6299fd4f48e1b1391115 (diff)
downloadglibc-34816665b678a06e096a378303b68d35ff10a693.tar.gz
glibc-34816665b678a06e096a378303b68d35ff10a693.tar.xz
glibc-34816665b678a06e096a378303b68d35ff10a693.zip
Update.
	* nss/getXXbyYY_r.c (REENTRANT_NAME): Return ENOENT if status is
	neither SUCCESS nor TRYAGAIN [PR libc/4259].
	* nss/nss_files/files-XXX.c (internal_getent): Don't set *errnop
	to ENOENT if no entry is found.
	* nis/nss_compat/compat-grp.c: Don't set errno in case of lookup
	failure.
	* nis/nss_compat/compat-initgroups.c: Likewise.
	* nis/nss_compat/compat-pwd.c: Likewise.
	* nis/nss_compat/compat-spwd.c: Likewise.
	* nis/nss_nis/nis-alias.c: Likewise.
	* nis/nss_nis/nis-ethers.c: Likewise.
	* nis/nss_nis/nis-grp.c: Likewise.
	* nis/nss_nis/nis-hosts.c: Likewise.
	* nis/nss_nis/nis-initgroups.c: Likewise.
	* nis/nss_nis/nis-netgrp.c: Likewise.
	* nis/nss_nis/nis-network.c: Likewise.
	* nis/nss_nis/nis-proto.c: Likewise.
	* nis/nss_nis/nis-publickey.c: Likewise.
	* nis/nss_nis/nis-pwd.c: Likewise.
	* nis/nss_nis/nis-rpc.c: Likewise.
	* nis/nss_nis/nis-service.c: Likewise.
	* nis/nss_nis/nis-spwd.c: Likewise.
	* resolv/nss_dns/dns-host.c: Likewise.
	* resolv/nss_dns/dns-network.c: Likewise.
	* nis/nss_nisplus/nisplus-alias.c: Save errno around NIS calls.
	* nis/nss_nisplus/nisplus-ethers.c: Likewise.
	* nis/nss_nisplus/nisplus-grp.c: Likewise.
	* nis/nss_nisplus/nisplus-hosts.c: Likewise.
	* nis/nss_nisplus/nisplus-network.c: Likewise.
	* nis/nss_nisplus/nisplus-proto.c: Likewise.
	* nis/nss_nisplus/nisplus-pwd.c: Likewise.
	* nis/nss_nisplus/nisplus-rpc.c: Likewise.
	* nis/nss_nisplus/nisplus-service.c: Likewise.
	* nis/nss_nisplus/nisplus-spwd.c: Likewise.
	* hesiod/nss_hesiod/hesiod-pwd.c (lookup): Preserve errno value.
	* hesiod/nss_hesiod/hesiod-proto.c (lookup): Likewise.
	* hesiod/nss_hesiod/hesiod-grp.c (lookup): Likewise.
	* hesiod/nss_hesiod/hesiod-service.c (lookup): Likewise.
Diffstat (limited to 'nis/nss_nisplus')
-rw-r--r--nis/nss_nisplus/nisplus-alias.c5
-rw-r--r--nis/nss_nisplus/nisplus-ethers.c5
-rw-r--r--nis/nss_nisplus/nisplus-grp.c13
-rw-r--r--nis/nss_nisplus/nisplus-hosts.c18
-rw-r--r--nis/nss_nisplus/nisplus-network.c18
-rw-r--r--nis/nss_nisplus/nisplus-proto.c18
-rw-r--r--nis/nss_nisplus/nisplus-pwd.c18
-rw-r--r--nis/nss_nisplus/nisplus-rpc.c15
-rw-r--r--nis/nss_nisplus/nisplus-service.c18
-rw-r--r--nis/nss_nisplus/nisplus-spwd.c10
10 files changed, 115 insertions, 23 deletions
diff --git a/nis/nss_nisplus/nisplus-alias.c b/nis/nss_nisplus/nisplus-alias.c
index 3b6888eae7..e05c5edda3 100644
--- a/nis/nss_nisplus/nisplus-alias.c
+++ b/nis/nss_nisplus/nisplus-alias.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
 
@@ -274,6 +274,7 @@ _nss_nisplus_getaliasbyname_r (const char *name, struct aliasent *alias,
     {
       nis_result *result;
       char buf[strlen (name) + 30 + tablename_len];
+      int olderr = errno;
 
       sprintf (buf, "[name=%s],%s", name, tablename_val);
 
@@ -286,6 +287,8 @@ _nss_nisplus_getaliasbyname_r (const char *name, struct aliasent *alias,
 					       buffer, buflen, errnop);
       if (parse_res < 1)
 	{
+	  __set_errno (olderr);
+
 	  if (parse_res == -1)
 	    return NSS_STATUS_TRYAGAIN;
 	  else
diff --git a/nis/nss_nisplus/nisplus-ethers.c b/nis/nss_nisplus/nisplus-ethers.c
index 94b433abd2..2fd152dfdb 100644
--- a/nis/nss_nisplus/nisplus-ethers.c
+++ b/nis/nss_nisplus/nisplus-ethers.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998, 2000, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 2000, 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
 
@@ -231,6 +231,7 @@ _nss_nisplus_gethostton_r (const char *name, struct etherent *eth,
     {
       nis_result *result;
       char buf[strlen (name) + 40 + tablename_len];
+      int olderr = errno;
 
       sprintf (buf, "[name=%s],%s", name, tablename_val);
 
@@ -247,6 +248,8 @@ _nss_nisplus_gethostton_r (const char *name, struct etherent *eth,
 					       buflen, errnop);
       if (parse_res < 1)
 	{
+	  __set_errno (olderr);
+
 	  if (parse_res == -1)
 	    {
 	      nis_freeresult (result);
diff --git a/nis/nss_nisplus/nisplus-grp.c b/nis/nss_nisplus/nisplus-grp.c
index 84bc6746a5..f66c14f8ed 100644
--- a/nis/nss_nisplus/nisplus-grp.c
+++ b/nis/nss_nisplus/nisplus-grp.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
 
@@ -180,6 +180,7 @@ _nss_nisplus_getgrnam_r (const char *name, struct group *gr,
     {
       nis_result *result;
       char buf[strlen (name) + 24 + tablename_len];
+      int olderr = errno;
 
       sprintf (buf, "[name=%s],%s", name, tablename_val);
 
@@ -204,7 +205,10 @@ _nss_nisplus_getgrnam_r (const char *name, struct group *gr,
 	      return NSS_STATUS_TRYAGAIN;
 	    }
 	  else
-	    return NSS_STATUS_NOTFOUND;
+	    {
+	      __set_errno (olderr);
+	      return NSS_STATUS_NOTFOUND;
+	    }
 	}
       return NSS_STATUS_SUCCESS;
     }
@@ -226,6 +230,7 @@ _nss_nisplus_getgrgid_r (const gid_t gid, struct group *gr,
     int parse_res;
     nis_result *result;
     char buf[36 + tablename_len];
+    int olderr = errno;
 
     sprintf (buf, "[gid=%lu],%s", (unsigned long int) gid, tablename_val);
 
@@ -235,6 +240,8 @@ _nss_nisplus_getgrgid_r (const gid_t gid, struct group *gr,
       {
 	enum nss_status status = niserr2nss (result->status);
 
+	__set_errno (olderr);
+
 	nis_freeresult (result);
 	return status;
       }
@@ -245,6 +252,8 @@ _nss_nisplus_getgrgid_r (const gid_t gid, struct group *gr,
     nis_freeresult (result);
     if (parse_res < 1)
       {
+	__set_errno (olderr);
+
 	if (parse_res == -1)
 	  {
 	    *errnop = ERANGE;
diff --git a/nis/nss_nisplus/nisplus-hosts.c b/nis/nss_nisplus/nisplus-hosts.c
index 6fc208a202..b8c9fdf228 100644
--- a/nis/nss_nisplus/nisplus-hosts.c
+++ b/nis/nss_nisplus/nisplus-hosts.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1997,1998,1999,2000,2001,2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
 
@@ -354,6 +354,7 @@ internal_gethostbyname2_r (const char *name, int af, struct hostent *host,
     {
       nis_result *result;
       char buf[strlen (name) + 255 + tablename_len];
+      int olderr = errno;
 
       /* Search at first in the alias list, and use the correct name
 	 for the next search */
@@ -383,6 +384,8 @@ internal_gethostbyname2_r (const char *name, int af, struct hostent *host,
 	      *errnop = errno;
               *herrnop = NETDB_INTERNAL;
             }
+	  else
+	    __set_errno (olderr);
 	  nis_freeresult (result);
           return retval;
         }
@@ -402,7 +405,10 @@ internal_gethostbyname2_r (const char *name, int af, struct hostent *host,
 	  return NSS_STATUS_TRYAGAIN;
 	}
       else
-	return NSS_STATUS_NOTFOUND;
+	{
+	  __set_errno (olderr);
+	  return NSS_STATUS_NOTFOUND;
+	}
     }
 }
 
@@ -467,6 +473,7 @@ _nss_nisplus_gethostbyaddr_r (const void *addr, socklen_t addrlen, int af,
       nis_result *result;
       char buf[255 + tablename_len];
       int retval, parse_res;
+      int olderr = errno;
 
       sprintf (buf, "[addr=%s],%s",
 	       inet_ntoa (*(const struct in_addr *) addr), tablename_val);
@@ -480,6 +487,8 @@ _nss_nisplus_gethostbyaddr_r (const void *addr, socklen_t addrlen, int af,
 	      *errnop = errno;
               *herrnop = NETDB_INTERNAL;
             }
+	  else
+	    __set_errno (olderr);
 	  nis_freeresult (result);
           return retval;
         }
@@ -499,6 +508,9 @@ _nss_nisplus_gethostbyaddr_r (const void *addr, socklen_t addrlen, int af,
 	  return NSS_STATUS_TRYAGAIN;
 	}
       else
-	return NSS_STATUS_NOTFOUND;
+	{
+	  __set_errno (olderr);
+	  return NSS_STATUS_NOTFOUND;
+	}
     }
 }
diff --git a/nis/nss_nisplus/nisplus-network.c b/nis/nss_nisplus/nisplus-network.c
index 201c154769..d99bf76ca4 100644
--- a/nis/nss_nisplus/nisplus-network.c
+++ b/nis/nss_nisplus/nisplus-network.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998, 2000, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 2000, 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
 
@@ -312,6 +312,7 @@ _nss_nisplus_getnetbyname_r (const char *name, struct netent *network,
     {
       nis_result *result;
       char buf[strlen (name) + 255 + tablename_len];
+      int olderr = errno;
 
       /* Search at first in the alias list, and use the correct name
 	 for the next search */
@@ -341,6 +342,8 @@ _nss_nisplus_getnetbyname_r (const char *name, struct netent *network,
 	      *errnop = errno;
 	      *herrnop = NETDB_INTERNAL;
 	    }
+	  else
+	    __set_errno (olderr);
 	  nis_freeresult (result);
 	  return retval;
 	}
@@ -360,7 +363,10 @@ _nss_nisplus_getnetbyname_r (const char *name, struct netent *network,
 	  return NSS_STATUS_TRYAGAIN;
 	}
       else
-	return NSS_STATUS_NOTFOUND;
+	{
+	  __set_errno (olderr);
+	  return NSS_STATUS_NOTFOUND;
+	}
     }
 }
 
@@ -385,6 +391,7 @@ _nss_nisplus_getnetbyaddr_r (uint32_t addr, const int type,
     struct in_addr in;
     char buf2[256];
     int b2len;
+    int olderr = errno;
 
     in = inet_makeaddr (addr, 0);
     strcpy (buf2, inet_ntoa (in));
@@ -414,6 +421,8 @@ _nss_nisplus_getnetbyaddr_r (uint32_t addr, const int type,
 		*errnop = errno;
 		*herrnop = NETDB_INTERNAL;
 	      }
+	    else
+	      __set_errno (olderr);
 	    nis_freeresult (result);
 	    return retval;
 	  }
@@ -433,7 +442,10 @@ _nss_nisplus_getnetbyaddr_r (uint32_t addr, const int type,
 	    return NSS_STATUS_TRYAGAIN;
 	  }
 	else
-	  return NSS_STATUS_NOTFOUND;
+	  {
+	    __set_errno (olderr);
+	    return NSS_STATUS_NOTFOUND;
+	  }
       }
   }
 }
diff --git a/nis/nss_nisplus/nisplus-proto.c b/nis/nss_nisplus/nisplus-proto.c
index 6613f53d3d..10f9a38e67 100644
--- a/nis/nss_nisplus/nisplus-proto.c
+++ b/nis/nss_nisplus/nisplus-proto.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
 
@@ -289,6 +289,7 @@ _nss_nisplus_getprotobyname_r (const char *name, struct protoent *proto,
     {
       nis_result *result;
       char buf[strlen (name) + 255 + tablename_len];
+      int olderr = errno;
 
       /* Search at first in the alias list, and use the correct name
          for the next search */
@@ -314,6 +315,8 @@ _nss_nisplus_getprotobyname_r (const char *name, struct protoent *proto,
 	{
 	  enum nss_status status = niserr2nss (result->status);
 
+	  __set_errno (olderr);
+
 	  nis_freeresult (result);
 	  return status;
 	}
@@ -331,7 +334,10 @@ _nss_nisplus_getprotobyname_r (const char *name, struct protoent *proto,
 	      return NSS_STATUS_TRYAGAIN;
 	    }
 	  else
-	    return NSS_STATUS_NOTFOUND;
+	    {
+	      __set_errno (olderr);
+	      return NSS_STATUS_NOTFOUND;
+	    }
 	}
       return NSS_STATUS_SUCCESS;
     }
@@ -353,6 +359,7 @@ _nss_nisplus_getprotobynumber_r (const int number, struct protoent *proto,
     int parse_res;
     nis_result *result;
     char buf[46 + tablename_len];
+    int olderr = errno;
 
     sprintf (buf, "[number=%d],%s", number, tablename_val);
 
@@ -362,6 +369,8 @@ _nss_nisplus_getprotobynumber_r (const int number, struct protoent *proto,
       {
 	enum nss_status status = niserr2nss (result->status);
 
+	__set_errno (olderr);
+
 	nis_freeresult (result);
 	return status;
       }
@@ -379,7 +388,10 @@ _nss_nisplus_getprotobynumber_r (const int number, struct protoent *proto,
 	    return NSS_STATUS_TRYAGAIN;
 	  }
 	else
-	  return NSS_STATUS_NOTFOUND;
+	  {
+	    __set_errno (olderr);
+	    return NSS_STATUS_NOTFOUND;
+	  }
       }
     return NSS_STATUS_SUCCESS;
   }
diff --git a/nis/nss_nisplus/nisplus-pwd.c b/nis/nss_nisplus/nisplus-pwd.c
index f7bc8321bd..a4beb7af14 100644
--- a/nis/nss_nisplus/nisplus-pwd.c
+++ b/nis/nss_nisplus/nisplus-pwd.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1999, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1999, 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
 
@@ -186,6 +186,7 @@ _nss_nisplus_getpwnam_r (const char *name, struct passwd *pw,
     {
       nis_result *result;
       char buf[strlen (name) + 24 + tablename_len];
+      int olderr = errno;
 
       sprintf (buf, "[name=%s],%s", name, tablename_val);
 
@@ -195,6 +196,8 @@ _nss_nisplus_getpwnam_r (const char *name, struct passwd *pw,
 	{
 	  enum nss_status status =  niserr2nss (result->status);
 
+	  __set_errno (olderr);
+
 	  nis_freeresult (result);
 	  return status;
 	}
@@ -212,7 +215,10 @@ _nss_nisplus_getpwnam_r (const char *name, struct passwd *pw,
 	      return NSS_STATUS_TRYAGAIN;
 	    }
 	  else
-	    return NSS_STATUS_NOTFOUND;
+	    {
+	      __set_errno (olderr);
+	      return NSS_STATUS_NOTFOUND;
+	    }
 	}
       return NSS_STATUS_SUCCESS;
     }
@@ -234,6 +240,7 @@ _nss_nisplus_getpwuid_r (const uid_t uid, struct passwd *pw,
     int parse_res;
     nis_result *result;
     char buf[100 + tablename_len];
+    int olderr = errno;
 
     sprintf (buf, "[uid=%lu],%s", (unsigned long int) uid, tablename_val);
 
@@ -243,6 +250,8 @@ _nss_nisplus_getpwuid_r (const uid_t uid, struct passwd *pw,
       {
 	enum nss_status status = niserr2nss (result->status);
 
+	__set_errno (olderr);
+
 	nis_freeresult (result);
 	return status;
       }
@@ -259,7 +268,10 @@ _nss_nisplus_getpwuid_r (const uid_t uid, struct passwd *pw,
 	    return NSS_STATUS_TRYAGAIN;
 	  }
 	else
-	  return NSS_STATUS_NOTFOUND;
+	  {
+	    __set_errno (olderr);
+	    return NSS_STATUS_NOTFOUND;
+	  }
       }
     return NSS_STATUS_SUCCESS;
   }
diff --git a/nis/nss_nisplus/nisplus-rpc.c b/nis/nss_nisplus/nisplus-rpc.c
index e35d846ed3..8e661baedb 100644
--- a/nis/nss_nisplus/nisplus-rpc.c
+++ b/nis/nss_nisplus/nisplus-rpc.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
 
@@ -283,6 +283,7 @@ _nss_nisplus_getrpcbyname_r (const char *name, struct rpcent *rpc,
     {
       nis_result *result;
       char buf[strlen (name) + 255 + tablename_len];
+      int olderr = errno;
 
       /* Search at first in the alias list, and use the correct name
          for the next search */
@@ -308,6 +309,8 @@ _nss_nisplus_getrpcbyname_r (const char *name, struct rpcent *rpc,
 	{
 	  enum nss_status status = niserr2nss (result->status);
 
+	  __set_errno (olderr);
+
 	  nis_freeresult (result);
 	  return status;
 	}
@@ -324,6 +327,8 @@ _nss_nisplus_getrpcbyname_r (const char *name, struct rpcent *rpc,
 	      *errnop = ERANGE;
 	      return NSS_STATUS_TRYAGAIN;
 	    }
+
+	  __set_errno (olderr);
 	  return NSS_STATUS_NOTFOUND;
 	}
       return NSS_STATUS_SUCCESS;
@@ -346,6 +351,7 @@ _nss_nisplus_getrpcbynumber_r (const int number, struct rpcent *rpc,
     int parse_res;
     nis_result *result;
     char buf[100 + tablename_len];
+    int olderr = errno;
 
     sprintf (buf, "[number=%d],%s", number, tablename_val);
 
@@ -355,6 +361,8 @@ _nss_nisplus_getrpcbynumber_r (const int number, struct rpcent *rpc,
       {
 	enum nss_status status = niserr2nss (result->status);
 
+	__set_errno (olderr);
+
 	nis_freeresult (result);
 	return status;
       }
@@ -372,7 +380,10 @@ _nss_nisplus_getrpcbynumber_r (const int number, struct rpcent *rpc,
 	    return NSS_STATUS_TRYAGAIN;
 	  }
 	else
-	  return NSS_STATUS_NOTFOUND;
+	  {
+	    __set_errno (olderr);
+	    return NSS_STATUS_NOTFOUND;
+	  }
       }
     return NSS_STATUS_SUCCESS;
   }
diff --git a/nis/nss_nisplus/nisplus-service.c b/nis/nss_nisplus/nisplus-service.c
index 5560da5ea0..a010f44da8 100644
--- a/nis/nss_nisplus/nisplus-service.c
+++ b/nis/nss_nisplus/nisplus-service.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998, 1999, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 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>, 1997.
 
@@ -297,6 +297,7 @@ _nss_nisplus_getservbyname_r (const char *name, const char *protocol,
     {
       nis_result *result;
       char buf[strlen (name) + 255 + tablename_len];
+      int olderr = errno;
 
       /* Search at first in the alias list, and use the correct name
          for the next search */
@@ -324,6 +325,8 @@ _nss_nisplus_getservbyname_r (const char *name, const char *protocol,
 	{
 	  enum nss_status status = niserr2nss (result->status);
 
+	  __set_errno (olderr);
+
 	  nis_freeresult (result);
 	  return status;
 	}
@@ -340,7 +343,10 @@ _nss_nisplus_getservbyname_r (const char *name, const char *protocol,
 	      return NSS_STATUS_TRYAGAIN;
 	    }
 	  else
-	    return NSS_STATUS_NOTFOUND;
+	    {
+	      __set_errno (olderr);
+	      return NSS_STATUS_NOTFOUND;
+	    }
 	}
       return NSS_STATUS_SUCCESS;
     }
@@ -369,6 +375,7 @@ _nss_nisplus_getservbyport_r (const int number, const char *protocol,
       int parse_res;
       nis_result *result;
       char buf[60 + strlen (protocol) + tablename_len];
+      int olderr = errno;
 
       sprintf (buf, "[port=%d,proto=%s],%s",
 	       number, protocol, tablename_val);
@@ -379,6 +386,8 @@ _nss_nisplus_getservbyport_r (const int number, const char *protocol,
 	{
 	  enum nss_status status = niserr2nss (result->status);
 
+	  __set_errno (olderr);
+
 	  nis_freeresult (result);
 	  return status;
 	}
@@ -395,7 +404,10 @@ _nss_nisplus_getservbyport_r (const int number, const char *protocol,
 	      return NSS_STATUS_TRYAGAIN;
 	    }
 	  else
-	    return NSS_STATUS_NOTFOUND;
+	    {
+	      __set_errno (olderr);
+	      return NSS_STATUS_NOTFOUND;
+	    }
 	}
       return NSS_STATUS_SUCCESS;
     }
diff --git a/nis/nss_nisplus/nisplus-spwd.c b/nis/nss_nisplus/nisplus-spwd.c
index 7d549f4b00..5cff1b7850 100644
--- a/nis/nss_nisplus/nisplus-spwd.c
+++ b/nis/nss_nisplus/nisplus-spwd.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
 
@@ -186,6 +186,7 @@ _nss_nisplus_getspnam_r (const char *name, struct spwd *sp,
     {
       nis_result *result;
       char buf[strlen (name) + 24 + tablename_len];
+      int olderr = errno;
 
       sprintf (buf, "[name=%s],%s", name, tablename_val);
 
@@ -195,6 +196,8 @@ _nss_nisplus_getspnam_r (const char *name, struct spwd *sp,
 	{
 	  enum nss_status status = niserr2nss (result->status);
 
+	  __set_errno (olderr);
+
 	  nis_freeresult (result);
 	  return status;
 	}
@@ -211,7 +214,10 @@ _nss_nisplus_getspnam_r (const char *name, struct spwd *sp,
 	      return NSS_STATUS_TRYAGAIN;
 	    }
 	  else
-	    return NSS_STATUS_NOTFOUND;
+	    {
+	      __set_errno (olderr);
+	      return NSS_STATUS_NOTFOUND;
+	    }
 	}
       return NSS_STATUS_SUCCESS;
     }