![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Script to Check for Unix/Linux Passwords | lucknowm | Shell Programming and Scripting | 1 | 05-29-2008 10:08 PM |
| idea for script - cheking passwords | bullz26 | Shell Programming and Scripting | 5 | 03-21-2008 06:11 AM |
| changing passwords remotely on sun boxes | Terrible | Shell Programming and Scripting | 0 | 08-07-2006 09:13 AM |
| Changing Users Passwords Via Script? | PJolliffe | UNIX for Advanced & Expert Users | 3 | 04-10-2002 09:54 AM |
| passwords changing | viperws | UNIX for Dummies Questions & Answers | 1 | 01-02-2002 10:43 PM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Perl script - changing passwords
Just wanted options of this - first 'real' Perl script and I'm not positive of all the quirks in Perl. Any suggestions are welcome.
Especially since I'm messing with /etc/shadow! Running Solaris 2.6, Perl 5.005.03 #!/u/bin/perl # # Change the user's old password to the new in /etc/shadow # Expects userID, old password, new password # Will only change ftp users passwords - # HOG 04/25/02 It's Alive! # ==================================================================== # Set up variables ------------ $user = "$ARGV[0]"; $oldpass = "$ARGV[1]"; $newpass = "$ARGV[2]"; $oldshadow = "/etc/shadow"; $newshadow = "/etc/.newshadow"; # # ==== Check that there is only one of user ===== $useramount = `/usr/bin/grep -c $user /etc/shadow`; if ($useramount != 1) { die "More or less than one"; } # $userinfo = `/usr/bin/grep $user /etc/shadow`; ($user1, $passwd, $epoch, $passextra) = split(/:/, $userinfo, 4); $salt = substr($passwd,0,2); $newsalt = join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]; # # Put testing junk here (print variables) # if (crypt($oldpass, $salt) ne $passwd) { # =========== FAILED - write to messages file - return error ========= system("/usr/bin/echo \" progserver chgpwd: ERROR changing $user passwor d\" >> /var/adm/messages"); die ""; } else { $newcrypt = crypt($newpass, $newsalt); $nowepoch = (time () /60 /60 /24 ) + 35; ($newepoch, $junk) = split(/\./, $nowepoch, 2); chomp($userinfo1 = "$user1:$newcrypt:$newepoch:$passextra"); # Make a backup copy if none exists - done nightly in another script if (!-e "/etc/.oldshadow") { `/usr/bin/cp /etc/shadow /etc/.oldshadow` } &create_newfile; `/usr/bin/cp $newshadow $oldshadow`; # } sub create_newfile { open NEWSHAD, ">$newshadow" or die "Can not open new shadow\n"; open OLDSHAD, "<$oldshadow" or die "Can not open old shadow\n"; while (<OLDSHAD>) { ($usertmp, $everythingelse) = split(/:/, $_, 2); if ("$usertmp" eq "$user") { print NEWSHAD "$userinfo1\n"; } else { print NEWSHAD "$_"; } } close OLDSHAD; close NEWSHAD; } |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|