about summary refs log tree commit diff
path: root/src/passwd/getspnam_r.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/passwd/getspnam_r.c')
-rw-r--r--src/passwd/getspnam_r.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/passwd/getspnam_r.c b/src/passwd/getspnam_r.c
index 541206fa..1b95dbb6 100644
--- a/src/passwd/getspnam_r.c
+++ b/src/passwd/getspnam_r.c
@@ -67,6 +67,7 @@ int getspnam_r(const char *name, struct spwd *sp, char *buf, size_t size, struct
 	size_t k, l = strlen(name);
 	int skip = 0;
 	int cs;
+	int orig_errno = errno;
 
 	*res = 0;
 
@@ -94,7 +95,11 @@ int getspnam_r(const char *name, struct spwd *sp, char *buf, size_t size, struct
 		}
 	} else {
 		f = fopen("/etc/shadow", "rbe");
-		if (!f) return errno;
+		if (!f) {
+			if (errno != ENOENT && errno != ENOTDIR)
+				return errno;
+			return 0;
+		}
 	}
 
 	pthread_cleanup_push(cleanup, f);
@@ -113,6 +118,6 @@ int getspnam_r(const char *name, struct spwd *sp, char *buf, size_t size, struct
 		break;
 	}
 	pthread_cleanup_pop(1);
-	if (rv) errno = rv;
+	errno = rv ? rv : orig_errno;
 	return rv;
 }