Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Cache pw result to avoid over reloading nssswitch.conf
Baptiste Daroussin committed 9 years ago
commit 6731b7b6dbef1721917908c7785003c447399b45
parent 8e19491
1 file changed +22 -8
modified libpkg/pkg_add.c
@@ -183,28 +183,42 @@ attempt_to_merge(int rootfd, struct pkg_config_file *rcf, struct pkg *local,
static uid_t
get_uid_from_archive(struct archive_entry *ae)
{
-
	char buffer[128];
-
	struct passwd pwent, *result;
-

-
	if ((getpwnam_r(archive_entry_uname(ae), &pwent, buffer, sizeof(buffer),
+
	static char user_buffer[128];
+
	const char *user;
+
	static struct passwd pwent;
+
	struct passwd *result;
+

+
	user = archive_entry_uname(ae);
+
	if (pwent.pw_name != NULL && strcmp(user, pwent.pw_name) == 0)
+
		goto out;
+
	pwent.pw_name = NULL;
+
	if ((getpwnam_r(user, &pwent, user_buffer, sizeof(user_buffer),
	    &result)) < 0)
		return (0);
	if (result == NULL)
		return (0);
+
out:
	return (pwent.pw_uid);
}

static gid_t
get_gid_from_archive(struct archive_entry *ae)
{
-
	char buffer[128];
-
	struct group grent, *result;
-

-
	if ((getgrnam_r(archive_entry_gname(ae), &grent, buffer, sizeof(buffer),
+
	static char group_buffer[128];
+
	static struct group grent;
+
	struct group *result;
+
	const char *group;
+

+
	group = archive_entry_gname(ae);
+
	if (grent.gr_name != NULL && strcmp(group, grent.gr_name) == 0)
+
		goto out;
+
	grent.gr_name = NULL;
+
	if ((getgrnam_r(group, &grent, group_buffer, sizeof(group_buffer),
	    &result)) < 0)
		return (0);
	if (result == NULL)
		return (0);
+
out:
	return (grent.gr_gid);
}