summaryrefslogtreecommitdiff
path: root/extra
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2004-11-11 14:50:52 +0000
committerMike Frysinger <vapier@gentoo.org>2004-11-11 14:50:52 +0000
commit56a4f3265fccc26e7141e38153815c635ad3a153 (patch)
tree853e3ba889f6ab8c7bfcd24a67c45c58541c089f /extra
parentc74b1ccbd8512116ddb967632b14d7566de21c4d (diff)
move getent to extra/scripts/ out of docs/
Diffstat (limited to 'extra')
-rwxr-xr-xextra/scripts/getent49
1 files changed, 49 insertions, 0 deletions
diff --git a/extra/scripts/getent b/extra/scripts/getent
new file mode 100755
index 000000000..4cbe2876f
--- /dev/null
+++ b/extra/scripts/getent
@@ -0,0 +1,49 @@
+#!/bin/sh
+# $Header: /var/cvs/uClibc/extra/scripts/getent,v 1.1 2004/11/11 14:50:52 vapier Exp $
+
+search_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
+}
+
+file="/etc/$1"
+string="dummy"
+
+#aliases|ethers|group|hosts|netgroup|networks|passwd|protocols|rpc|services|shadow)
+# dns based search is not supported for hosts|networks
+# networks searches ^string
+# protocols|rpc|services searches string anywhere
+# ethers|netgroup ?
+# it returns only the first match
+case $1 in
+ group|passwd|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|protocol|rpc|services)
+ string="\<$2\>"
+ ;;
+ *)
+ echo "Unknown database: $1"
+ exit 1
+ ;;
+esac
+
+search_entry $file $2
+
+exit $retval