Provide an alias to _obstack_free
[uclibc-ng.git] / extra / scripts / getent
blob5c482a0719d8e2a11e25c54ceee21f6a32eb079f
1 #!/bin/sh
3 # Closely (not perfectly) emulate the behavior of glibc's getent utility
5 #passwd|shadow|group|aliases|hosts|networks|ethers|netgroup|protocols|services|rpc
6 # only returns the first match (by design)
7 # dns based search is not supported (hosts,networks)
8 # case-insensitive matches not supported (ethers; others?)
9 # may return false-positives (hosts,protocols,rpc,services,ethers)
11 [ -z "$PATH" ] && PATH="/bin:/usr/bin" || PATH="${PATH}:/bin:/usr/bin"
12 export PATH
14 file="/etc/$1"
15 case $1 in
16 passwd|group)
17 match="^$2:\|^[^:]*:[^:]*:$2:" ;;
18 shadow)
19 match="^$2:" ;;
20 networks|netgroup)
21 match="^[[:space:]]*$2\>" ;;
22 hosts|protocols|rpc|services|ethers)
23 match="\<$2\>" ;;
24 aliases)
25 match="^[[:space:]]*$2[[:space:]]*:" ;;
26 ""|-h|--help)
27 echo "USAGE: $0 database [key]"
28 exit 0 ;;
30 echo "$0: Unknown database: $1" 1>&2
31 exit 1 ;;
32 esac
34 if [ ! -f "$file" ] ; then
35 echo "$0: Could not find database file for $1" 1>&2
36 exit 1
39 if [ $# -eq 1 ] ; then
40 exec cat "$file"
41 else
42 sed "s/#.*//; /$match/q; d" "$file" | grep . || exit 2