From e23080b25f06c8205f62c00049ae80b89d8a7819 Mon Sep 17 00:00:00 2001 From: thib Date: Tue, 10 Jul 2001 10:52:59 +0000 Subject: [PATCH] Initial revision --- script/has_usrgrp.pl | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 script/has_usrgrp.pl diff --git a/script/has_usrgrp.pl b/script/has_usrgrp.pl new file mode 100755 index 0000000..63d73de --- /dev/null +++ b/script/has_usrgrp.pl @@ -0,0 +1,32 @@ +#!/usr/bin/perl + +# call getpwnam() or getgrnam() to check if user or group (given as arg) exists +# on the system (getpwnam() and getgrnam() use nsswitch.conf, so it works +# even if NYS (or similar) is used) + +if ( $#ARGV < 1 || $#ARGV > 2) { + print "usage:\n has_usrgrp.pl [-user user|-group group] [-printgid]\n"; + exit 1; +} + +if ( $ARGV[0] eq "-user" ) { + ($name, $passwd, $uid, $gid, $quota, $comment, + $gcos, $dir, $shell, $expire) = getpwnam($ARGV[1]); +} +elsif ( $ARGV[0] eq "-group" ) { + ($name, $passwd, $gid, $members) = getgrnam($ARGV[1]); +} +else { + print "usage:\n has_usrgrp.pl [-user user|-group group] [-printgid]\n"; + exit 1; +} + +if ($name) { + if ( $#ARGV == 2 && $ARGV[2] eq "-printgid" ) { + print $gid, "\n"; + } + exit 0; +} +else { + exit 1; +} -- 2.40.0