summaryrefslogtreecommitdiffstats
path: root/extra/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'extra/scripts')
-rwxr-xr-xextra/scripts/getent92
-rwxr-xr-xextra/scripts/relinfo.pl78
2 files changed, 109 insertions, 61 deletions
diff --git a/extra/scripts/getent b/extra/scripts/getent
index 03b5f28a9..30d515b7e 100755
--- a/extra/scripts/getent
+++ b/extra/scripts/getent
@@ -1,73 +1,43 @@
#!/bin/sh
+# $Header: /var/cvs/uClibc/extra/scripts/getent,v 1.2 2005/02/02 14:18:01 solar Exp $
#
-# Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+# Closely (not perfectly) emulate the behavior of glibc's getent utility
#
-# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
-#
-
-# Script to replicate the `getent` binary that comes with glibc
+#passwd|shadow|group|aliases|hosts|networks|ethers|netgroup|protocols|services|rpc
+# only returns the first match (by design)
+# dns based search is not supported (hosts,networks)
+# case-insensitive matches not supported (ethers; others?)
+# may return false-positives (hosts,protocols,rpc,services,ethers)
-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
-}
-
-if [ -z "$1" ] ; then
- echo "getent: wrong number of arguments" 1>&2
- exit 1
-fi
+export PATH="${PATH}:/bin:/usr/bin"
file="/etc/$1"
-string="dummy"
+case $1 in
+ passwd|group)
+ match="^$2:\|^[^:]*:[^:]*:$2:" ;;
+ shadow)
+ match="^$2:" ;;
+ networks|netgroup)
+ match="^[[:space:]]*$2\>" ;;
+ hosts|protocols|rpc|services|ethers)
+ match="\<$2\>" ;;
+ aliases)
+ match="^[[:space:]]*$2[[:space:]]*:" ;;
+ ""|-h|--help)
+ echo "USAGE: $0 database [key]"
+ exit 0 ;;
+ *)
+ echo "$0: Unknown database: $1" 1>&2
+ exit 1 ;;
+esac
if [ ! -f "$file" ] ; then
- echo "Unknown database: $1" 1>&2
- exit 1
+ echo "$0: Could not find database file for $1" 1>&2
+ exit 1
fi
-#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 match
-case $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
- ;;
-esac
-
-if [ -z "$2" ] ; then
- exec cat $file
+if [ $# -eq 1 ] ; then
+ exec cat "$file"
else
- search_entry "$file" "$2"
+ sed "s/#.*//; /$match/q; d" "$file" | grep . || exit 2
fi
-
-exit $retval
diff --git a/extra/scripts/relinfo.pl b/extra/scripts/relinfo.pl
new file mode 100755
index 000000000..ec4a5df13
--- /dev/null
+++ b/extra/scripts/relinfo.pl
@@ -0,0 +1,78 @@
+#! /usr/bin/perl
+eval "exec /usr/bin/perl -S $0 $*"
+ if 0;
+# Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Red Hat, Inc.
+# Written by Ulrich Drepper <drepper@redhat.com>, 2000.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+for ($cnt = 0; $cnt <= $#ARGV; ++$cnt) {
+ $relent = 0;
+ $relsz = 0;
+ $relcount = 0;
+ $pltrelsz = 0;
+ $extplt = 0;
+ $users = 0;
+
+ open (READLINK, "readlink -f $ARGV[$cnt] |") || die "cannot open readlink";
+ while (<READLINK>) {
+ chop;
+ $fullpath = $_;
+ }
+ close (READLINK);
+
+ open (READELF, "eu-readelf -d $ARGV[$cnt] |") || die "cannot open $ARGV[$cnt]";
+ while (<READELF>) {
+ chop;
+ if (/.* RELA?ENT *([0-9]*).*/) {
+ $relent = $1 + 0;
+ } elsif (/.* RELA?SZ *([0-9]*).*/) {
+ $relsz = $1 + 0;
+ } elsif (/.* RELA?COUNT *([0-9]*).*/) {
+ $relcount = $1 + 0;
+ } elsif (/.* PLTRELSZ *([0-9]*).*/) {
+ $pltrelsz = $1 + 0;
+ }
+ }
+ close (READELF);
+
+ open (READELF, "eu-readelf -r $ARGV[$cnt] | sed '/'.gnu.conflict'/,/^\$/d' |") || die "cannot open $ARGV[$cnt]";
+ while (<READELF>) {
+ chop;
+ if (/.*JU?MP_SLOT *0+ .*/) {
+ ++$extplt;
+ }
+ }
+ close (READELF);
+
+ if (open (PRELINK, "/usr/sbin/prelink -p 2>/dev/null | fgrep \"$fullpath\" |")) {
+ while (<PRELINK>) {
+ ++$users;
+ }
+ close(PRELINK);
+ } else {
+ $users = -1;
+ }
+
+ printf ("%s: %d relocations, %d relative (%d%%), %d PLT entries, %d for local syms (%d%%)",
+ $ARGV[$cnt], $relent == 0 ? 0 : $relsz / $relent, $relcount,
+ $relent == 0 ? 0 : ($relcount * 100) / ($relsz / $relent),
+ $relent == 0 ? 0 : $pltrelsz / $relent,
+ $relent == 0 ? 0 : $pltrelsz / $relent - $extplt,
+ $relent == 0 ? 0 : (($pltrelsz / $relent - $extplt) * 100) / ($pltrelsz / $relent));
+ if ($users >= 0) {
+ printf(", %d users", $users);
+ }
+ printf("\n");
+}