Skip to contentSkip to conversation

common: check user and group existence via id

PATCH In review Christian Brauner 1 participant 2 messages Sep 25, 2023 – Sep 26, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 common: check user and group existence via id

Newer machines support the creation of users that don't appear in /etc/passwd but are only available via nss or userdbd. Use the id binary which is portable and reliable.

With this change I can run xfstests on systems where the users are created via systemd-userdbd drop-ins. See the documentation in [1] and [2].

---
 common/rc | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
common/rc +4 -2
index 76a7e774..44c90f50 100644
@@ -2450,7 +2450,8 @@ _yp_active()
 _cat_passwd()
 {
 	[ $(_yp_active) -eq 0 ] && ypcat passwd
-	cat /etc/passwd
+	id -u "$1"
+	[ "$?" == "0" ] && echo "$user:"
 }
 
 # cat the group file
@@ -2458,7 +2459,8 @@ _cat_passwd()
 _cat_group()
 {
 	[ $(_yp_active) -eq 0 ] && ypcat group
-	cat /etc/group
+	id -g "$1"
+	[ "$?" == "0" ] && echo "$group:"
 }
 
 # check if a user exists in the system

---
base-commit: 2fddeb5c79ff16bf37e1f1d809bd94b360c27801
change-id: 20230925-fstests-check-user-5487ee9be2ef

#1 lore raw
Quoted 11 lines · Christian Brauner

Newer machines support the creation of users that don't appear in /etc/passwd but are only available via nss or userdbd. Use the id binary which is portable and reliable.

With this change I can run xfstests on systems where the users are created via systemd-userdbd drop-ins. See the documentation in [1] and [2].

---

I need to resend a fixed version. I only send half the patch.