#!/usr/bin/perl -w # User verification Routine # 03/12/1999 acs use strict; use English; use Getopt::Std; use constant TRUE => 1; use constant FALSE => 0; use constant SEP => ':'; sub Usage { printf STDERR ("\nUsage: %s [-q] [-u] user1 [user2 ...]\n\n", $PROGRAM_NAME); printf STDERR ("-q - quiet return result code only; 0 for valid user.\n"); printf STDERR ("-u - Print this usage message and exit.\n"); printf STDERR ("If -q is not used, a list of passwd fields is output for\n"); printf STDERR ("user, one line per user:\n\n"); printf STDERR ("The fields are: Name, passwd, uid, gid, passwd age, comment, gecos,\n"); printf STDERR ("home directory, and shell separated by '%s'\n",SEP); return(1); } # Usage sub Problem { printf STDERR ("\n%s: %s (%d)\n",$PROGRAM_NAME,$_[0],$_[1]); return($_[1]); } # Problem my $quiet = FALSE; our ($opt_u,$opt_q); if (!(getopts('uq'))) { Usage(); exit(Problem('Invalid argument',252)); } if (defined($opt_u)) { if ($opt_u != 0) { Usage(); exit(1); } } if (defined($opt_q)) { $quiet = TRUE; } my $i = 0; my $cc = ($#ARGV >= 0) ? 0 : 1; while ($i <= $#ARGV && $cc == 0) { my ($pw_name,$pw_passwd,$pw_uid,$pw_gid,$pw_age,$pw_comment, $pw_gecos,$pw_dir,$pw_shell) = getpwnam($ARGV[$i]); if (defined($pw_name)) { if (!($quiet)) { printf("%s%s%s%s%d%s%d",$pw_name,SEP,$pw_passwd,SEP, $pw_uid,SEP,$pw_gid); printf("%s%s%s%s%s%s",SEP,$pw_age,SEP,$pw_comment,SEP,$pw_gecos); printf("%s%s%s%s\n",SEP,$pw_dir,SEP,$pw_shell); } } else { $cc = 2; } ++$i; } exit($cc);