756255f
From 1bfa37818f5e6d8f4fe143084e81d0a102febcba Mon Sep 17 00:00:00 2001
756255f
From: Pavel Raiskup <praiskup@redhat.com>
756255f
Date: Mon, 20 Feb 2017 18:28:19 +0100
756255f
Subject: [PATCH] bsdcpio: ignore ENOENT for get{grg,pwu}id()
756255f
756255f
Starting from glibc 2.25, those calls set errno to ENOENT
756255f
when the requested id is not found.  So let's stop throwing
756255f
warning in this expected case.
756255f
756255f
Also rework the api of lookup_* functions so it is guaranteed that
756255f
lookup_name never returns NULL (unless ENOMEM).
756255f
---
756255f
 cpio/cpio.c | 46 ++++++++++++++++++++++------------------------
756255f
 1 file changed, 22 insertions(+), 24 deletions(-)
756255f
756255f
diff --git a/cpio/cpio.c b/cpio/cpio.c
756255f
index 6c20ee6..5961960 100644
756255f
--- a/cpio/cpio.c
756255f
+++ b/cpio/cpio.c
756255f
@@ -1344,23 +1344,23 @@ lookup_name(struct cpio *cpio, struct name_cache **name_cache_variable,
756255f
 		cache->cache[slot].name = NULL;
756255f
 	}
756255f
 
756255f
-	if (lookup_fn(cpio, &name, id) == 0) {
756255f
-		if (name == NULL || name[0] == '\0') {
756255f
-			/* If lookup failed, format it as a number. */
756255f
-			snprintf(asnum, sizeof(asnum), "%u", (unsigned)id);
756255f
-			name = asnum;
756255f
-		}
756255f
-		cache->cache[slot].name = strdup(name);
756255f
-		if (cache->cache[slot].name != NULL) {
756255f
-			cache->cache[slot].id = id;
756255f
-			return (cache->cache[slot].name);
756255f
-		}
756255f
-		/*
756255f
-		 * Conveniently, NULL marks an empty slot, so
756255f
-		 * if the strdup() fails, we've just failed to
756255f
-		 * cache it.  No recovery necessary.
756255f
-		 */
756255f
+	if (lookup_fn(cpio, &name, id)) {
756255f
+		/* If lookup failed, format it as a number. */
756255f
+		snprintf(asnum, sizeof(asnum), "%u", (unsigned)id);
756255f
+		name = asnum;
756255f
 	}
756255f
+
756255f
+	cache->cache[slot].name = strdup(name);
756255f
+	if (cache->cache[slot].name != NULL) {
756255f
+		cache->cache[slot].id = id;
756255f
+		return (cache->cache[slot].name);
756255f
+	}
756255f
+
756255f
+	/*
756255f
+	 * Conveniently, NULL marks an empty slot, so
756255f
+	 * if the strdup() fails, we've just failed to
756255f
+	 * cache it.  No recovery necessary.
756255f
+	 */
756255f
 	return (NULL);
756255f
 }
756255f
 
756255f
@@ -1381,15 +1381,14 @@ lookup_uname_helper(struct cpio *cpio, const char **name, id_t id)
756255f
 	errno = 0;
756255f
 	pwent = getpwuid((uid_t)id);
756255f
 	if (pwent == NULL) {
756255f
-		*name = NULL;
756255f
-		if (errno != 0 && errno != ENOENT)
756255f
+		if (errno && errno != ENOENT)
756255f
 			lafe_warnc(errno, "getpwuid(%s) failed",
756255f
 			    cpio_i64toa((int64_t)id));
756255f
-		return (errno);
756255f
+		return 1;
756255f
 	}
756255f
 
756255f
 	*name = pwent->pw_name;
756255f
-	return (0);
756255f
+	return 0;
756255f
 }
756255f
 
756255f
 static const char *
756255f
@@ -1409,15 +1408,14 @@ lookup_gname_helper(struct cpio *cpio, const char **name, id_t id)
756255f
 	errno = 0;
756255f
 	grent = getgrgid((gid_t)id);
756255f
 	if (grent == NULL) {
756255f
-		*name = NULL;
756255f
-		if (errno != 0)
756255f
+		if (errno && errno != ENOENT)
756255f
 			lafe_warnc(errno, "getgrgid(%s) failed",
756255f
 			    cpio_i64toa((int64_t)id));
756255f
-		return (errno);
756255f
+		return 1;
756255f
 	}
756255f
 
756255f
 	*name = grent->gr_name;
756255f
-	return (0);
756255f
+	return 0;
756255f
 }
756255f
 
756255f
 /*
756255f
-- 
756255f
2.9.3
756255f