2 # $Header: /var/cvs/uClibc/extra/scripts/getent,v 1.2 2005/02/02 14:18:01 solar Exp $
4 # Closely (not perfectly) emulate the behavior of glibc's getent utility
6 #passwd|shadow|group|aliases|hosts|networks|ethers|netgroup|protocols|services|rpc
7 # only returns the first match (by design)
8 # dns based search is not supported (hosts,networks)
9 # case-insensitive matches not supported (ethers; others?)
10 # may return false-positives (hosts,protocols,rpc,services,ethers)
12 # Taken from uClibc 0.9.33.
14 export PATH="${PATH}:/bin:/usr/bin"
19 match="^$2:\|^[^:]*:[^:]*:$2:" ;;
23 match="^[[:space:]]*$2\>" ;;
24 hosts|protocols|rpc|services|ethers)
27 match="^[[:space:]]*$2[[:space:]]*:" ;;
29 echo "USAGE: $0 database [key]"
32 echo "$0: Unknown database: $1" 1>&2
36 if [ ! -f "$file" ] ; then
37 echo "$0: Could not find database file for $1" 1>&2
41 if [ $# -eq 1 ] ; then
44 sed "s/#.*//; /$match/q; d" "$file" | grep . || exit 2