getent 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/sh
  2. # $Header: /var/cvs/uClibc/extra/scripts/getent,v 1.1 2004/11/11 14:50:52 vapier Exp $
  3. search_entry() {
  4. if [ -e "$1" ] ; then
  5. /bin/egrep -v "^#" $1 | /bin/sed 's/#.*$//' | /bin/egrep "${string}" | /bin/sed -n 1p
  6. retval=$?
  7. [ "$retval" = 0 ] || retval=2
  8. else
  9. retval=2
  10. fi
  11. }
  12. file="/etc/$1"
  13. string="dummy"
  14. #aliases|ethers|group|hosts|netgroup|networks|passwd|protocols|rpc|services|shadow)
  15. # dns based search is not supported for hosts|networks
  16. # networks searches ^string
  17. # protocols|rpc|services searches string anywhere
  18. # ethers|netgroup ?
  19. # it returns only the first match
  20. case $1 in
  21. group|passwd|shadow)
  22. string="^\<$2\>:"
  23. ;;
  24. aliases)
  25. if [ -f /etc/postfix/aliases ] ; then
  26. file="/etc/postfix/aliases"
  27. elif [ -f /etc/mail/aliases ] ; then
  28. file="/etc/mail/aliases"
  29. fi
  30. string="^\<$2\>:"
  31. ;;
  32. networks)
  33. string="^\<$2\>"
  34. ;;
  35. hosts|protocol|rpc|services)
  36. string="\<$2\>"
  37. ;;
  38. *)
  39. echo "Unknown database: $1"
  40. exit 1
  41. ;;
  42. esac
  43. search_entry $file $2
  44. exit $retval