1#!/bin/sh 2# $Header: /var/cvs/uClibc/extra/scripts/getent,v 1.2 2005/02/02 14:18:01 solar Exp $ 3# 4# Closely (not perfectly) emulate the behavior of glibc's getent utility 5# 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) 11# 12# Taken from uClibc 0.9.33. 13 14export PATH="${PATH}:/bin:/usr/bin" 15 16file="/etc/$1" 17case $1 in 18 passwd|group) 19 match="^$2:\|^[^:]*:[^:]*:$2:" ;; 20 shadow) 21 match="^$2:" ;; 22 networks|netgroup) 23 match="^[[:space:]]*$2\>" ;; 24 hosts|protocols|rpc|services|ethers) 25 match="\<$2\>" ;; 26 aliases) 27 match="^[[:space:]]*$2[[:space:]]*:" ;; 28 ""|-h|--help) 29 echo "USAGE: $0 database [key]" 30 exit 0 ;; 31 *) 32 echo "$0: Unknown database: $1" 1>&2 33 exit 1 ;; 34esac 35 36if [ ! -f "$file" ] ; then 37 echo "$0: Could not find database file for $1" 1>&2 38 exit 1 39fi 40 41if [ $# -eq 1 ] ; then 42 exec cat "$file" 43else 44 sed "s/#.*//; /$match/q; d" "$file" | grep . || exit 2 45fi 46