#!/usr/bin/perl ############################################################################################ # Anastasios Monachos - anastasiosm@gmail.com # # Takes as input a unix-like passwd file and a label eg server13 # # root:5I25ESdPMj6rhc:0:1:Operator:/:/bin/csh # sys:*:2:2::/:/bin/csh # bin:*:3:3::/bin: # tas:323f2n8TQ:1052:8026:Tas Harris,081347,8006x33d:/home/sunclass1/ths:/bin/csh # com:458cfh8TQ:1059:8006: Shit Mc Cann , , ,:/home/sunclass1/ths:/bin/csh # # And gives for output a file in the format, that displays only the non-service accounts # # root:Operator::server13 # dao:Debbie:Ortiz:server13 # tas:Tas:Harris:server13 # com:Shit:McCann:server13 ########################################################################################### $USAGE = "Usage is:\n\n ./uextract password_file domain_tag\n\n"; $INPUTFILE = $ARGV[0]; $TAG = $ARGV[1]; open (PASSFILE, $INPUTFILE || die $USAGE); open(FILEOUTPUT,">>$INPUTFILE.$TAG") or die "Could not write to filesystem: $!\n"; while ($line = ) { chomp $line; ($username, $xpassword, $uid, $gid, $fullname, $homedir, $command_shell) = split(':',$line); if (($xpassword ne '*') && ($xpassword ne 'NoLoginAllowed')) #if it is not a service and is not the nobody/cannot login { #The fullname field has 3 commas(therefore 4 sections) ($section1ofFullname, $section2ofFullname, $section3ofFullname, $section4ofFullname) = split(',', $fullname); #Section1ofFullname has elements seperated by spaces ($first, $middle, $second) = split(' ', $section1ofFullname); print $username .":". $first .":". $middle.$second .":". $TAG ."\n"; # Write results to inputfile.tag print FILEOUTPUT $username .":". $first .":". $middle.$second .":". $TAG ."\n"; } } close(FILEOUTPUT); print "\n\nOutput is written to file: ".$INPUTFILE.".".$TAG; close(PASSFILE);