#!/usr/local/bin/perl -w #-*-perl-*- # use strict; use vars qw ( %UserInfo %CallerUserInfo $OPasswd ); use Win32; use Win32::NetAdmin; use Term::ReadKey; use Win32API::Net; use File::Spec; my ($VERSION) = '$Revision: 1.0 $' =~ /([.\d]+)/; my $warnings = 0; # Print a usuage message on a unknown option. $SIG {__WARN__} = sub { if (substr ($_ [0], 0, 14) eq "Unknown option") {die "Usage"}; require File::Basename; $0 = File::Basename::basename ($0); $warnings = 1; warn "$0: @_"; }; $SIG {__DIE__} = sub { require File::Basename; $0 = File::Basename::basename ($0); if (substr ($_ [0], 0, 5) eq "Usage") { die <splitpath( $0 ) )[2]; CheckUser(); print "Changing password for $UserName\n"; ( $OPasswd, $UserInfo{password} ) = PasswordPrompt(); if ( $CallerPriv < "2" ) { Win32API::Net::UserChangePassword ( $Server, $UserName, $OPasswd, $UserInfo{password} ) or die "\n$^E\n"; } if ( $CallerPriv == "2" ) { Win32API::Net::UserSetInfo ( $Server, $UserName, $Level, \%UserInfo, $Error ) or die "\n$^E\n"; } print "\n$Executable: all authentication tokens updated successfully\n"; sub GetCallerPriv { my $Caller = getlogin; Win32API::Net::UserGetInfo ( $Server, $Caller, "11", \%CallerUserInfo ); return $CallerUserInfo{priv}; } sub PasswordPrompt { my ( $OldPassword, $NewPassword1 ); unless ( $CallerPriv == 2 ) { print "(current) login password: "; ReadMode 'noecho'; $OldPassword = ReadLine 0; chomp $OldPassword; print "\n"; } for ( my $Accumulator = 0; $Accumulator < 3; $Accumulator++ ) { print "New login password: "; ReadMode 'noecho'; my $NewPassword0 = ReadLine 0; chomp $NewPassword0; print "\nRetype new login password: "; ReadMode 'noecho'; $NewPassword1 = ReadLine 0; chomp $NewPassword1; last if $NewPassword0 eq $NewPassword1; print "\npasswords do not match\n"; if ( $Accumulator >= "3" ) { print "exiting ...\n"; die; } } return $OldPassword, $NewPassword1; } sub CheckUser { die "$Executable: unknown username \'$UserName\'\n" if ! Win32::NetAdmin::UsersExist ( $Server, $UserName ); } __END__ =pod =head1 NAME B -- change login password. =head1 SYNOPSIS B [ I ] [ -h ] =head1 DESCRIPTION B changes the password or lists password attributes associated with the user's login name (userid). When used to change a password, B prompts everyone for their old password, if any. It then prompts for the new password twice. If executed by a user with USER_PRIV_ADMIN() privilege flag (i.e. super-user), the old password prompt does not appear. Passwords must be constructed to meet the operating system requirements =head2 OPTIONS B accepts the options described below. =over 4 =item B The userid to perform a password reset. If null, the current user's password will be reset. =item B<-h> Display syntax. =back =head1 ENVIRONMENT The working of B is not influenced by any environment variables. =head1 BUGS B does not work will in a Samba domain controller environment (so far). =head1 STANDARDS It does not make sense to talk about standards in a B manual page. =head1 REVISION HISTORY passwd Revision 1.0 2000/06/22 09:00:34 idnopheq Initial revision =head1 AUTHOR The Perl implementation of B was written by Dexter Coffin, I. =head1 COPYRIGHT and LICENSE This program is copyright by Dexter Coffin 2000. This program is free and open software. You may use, copy, modify, distribute, and sell this program (and any modified variants) in any way you wish, provided you do not restrict others from doing the same. =head1 SEE ALSO =head1 NEXT TOPIC =cut