| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 | #!/bin/sh## Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>## Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.## Script to replicate the `getent` binary that comes with glibcsearch_entry() {  if [ -e "$1" ] ; then    /bin/egrep -v "^#" $1 | /bin/sed 's/#.*$//' | /bin/egrep "${string}" | /bin/sed -n 1p    retval=$?    [ "$retval" = 0 ] || retval=2  else    retval=2  fi}if [ -z "$1" ] ; then  echo "getent: wrong number of arguments" 1>&2  exit 1fifile="/etc/$1"string="dummy"if [ ! -f "$file" ] ; then  echo "Unknown database: $1" 1>&2  exit 1fi#aliases|ethers|group|hosts|netgroup|networks|passwd|protocols|rpc|services|shadow)# dns based search is not supported for hosts|networks# ethers|netgroup (not done, needed)?# it returns only the first matchcase $1 in  passwd)    string="(^\<$2\>:|^.*:.*:\<$2\>:.*:.*:.*:.*)"    ;;  group)    string="(^|:)\<$2\>:"    ;;  shadow)    string="^\<$2\>:"    ;;  aliases)    if [ -f /etc/postfix/aliases ] ; then      file="/etc/postfix/aliases"    elif [ -f /etc/mail/aliases ] ; then      file="/etc/mail/aliases"    fi    string="^\<$2\>:"    ;;  networks)    string="^\<$2\>"    ;;  hosts|protocols|rpc|services)    string="\<$2\>"    ;;  *)    echo "Unknown database: $1"    exit 1    ;;esacif [ -z "$2" ] ; then  exec cat $fileelse  search_entry "$file" "$2"fiexit $retval
 |