Re: [PATCH] common/rc: use getent when available

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]



On Mon, Mar 10, 2025 at 12:55:51PM -0500, Eric Sandeen wrote:
> Zorro noticed that on systems using nss-altfiles, some tests failed when
> trying to parse /etc/passwd directly. The "getent" command does the
> right thing in this case, so let's use it as long as it's available.
> 
> Signed-off-by: Eric Sandeen <sandeen@xxxxxxxxxx>
> ---

Hahah, you're so fast:) This's similar with what I'm doing, so it's good to me.

Reviewed-by: Zorro Lang <zlang@xxxxxxxxxx>

I tend to use getent too, if anyone has any better idea, please feel free to
share.

Thanks,
Zorro

> 
> diff --git a/common/rc b/common/rc
> index 6592c835..50312331 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -2621,7 +2621,11 @@ _yp_active()
>  _cat_passwd()
>  {
>  	[ $(_yp_active) -eq 0 ] && ypcat passwd
> -	cat /etc/passwd
> +	if type getent &>/dev/null; then
> +		getent passwd
> +	else
> +		cat /etc/passwd
> +	fi
>  }
>  
>  # cat the group file
> @@ -2629,7 +2633,11 @@ _cat_passwd()
>  _cat_group()
>  {
>  	[ $(_yp_active) -eq 0 ] && ypcat group
> -	cat /etc/group
> +	if type getent &>/dev/null; then
> +		getent group
> +	else
> +		cat /etc/group
> +	fi
>  }
>  
>  # check if a user exists in the system
> 
> 





[Index of Archives]     [Linux Filesystems Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux