Annotation of loncom/pwchange, revision 1.8

1.1       harris41    1: #!/usr/bin/perl
                      2: 
1.4       harris41    3: # The Learning Online Network with CAPA
1.2       harris41    4: #
                      5: # pwchange - setuid script to change unix passwords
                      6: #
                      7: # YEAR=2001
                      8: # 10/23,11/13,11/15 Scott Harrison
                      9: #
1.6       matthew    10: # YEAR=2002
                     11: # 02/19 Matthew Hall
                     12: #
1.7       foxr       13: # $Id: pwchange,v 1.6 2002/02/19 21:51:09 matthew Exp $
1.2       harris41   14: ###
                     15: 
1.1       harris41   16: use strict;
1.7       foxr       17: my $noprint = 1;
1.2       harris41   18: 
1.8     ! foxr       19: 
        !            20: 
        !            21: print "In pwchange\n" unless $noprint;
        !            22: print "Real uid = $< effective uid = $> \n" unless $noprint;
1.2       harris41   23: # ------------------------------------------------------------------ Untainting
1.1       harris41   24: $ENV{'PATH'}='/bin:/usr/bin'; # Nullify path information.
1.2       harris41   25: delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; # nullify potential taints
1.1       harris41   26: 
1.5       harris41   27: # ---------------------------- Make sure this process is running from user=root
1.8     ! foxr       28: 
        !            29: if (0 != $<) {
        !            30:     print "Username not root" unless $noprint;
1.2       harris41   31:    exit 1;
                     32: }
                     33: # ----------------------------------------------- If not running setuid as root
1.1       harris41   34: if ($>!=0) {
1.7       foxr       35:     print "Not setuid to root" unless $noprint;
1.1       harris41   36:     exit 1;
                     37: }
                     38: 
1.2       harris41   39: # ----------------------------------------------- Make sure arguments are valid
1.1       harris41   40: my $user=shift @ARGV;
                     41: $user=~/^(\w+)$/;
                     42: my $safe=$1;
1.7       foxr       43: print "Save user = $safe" unless $noprint;
                     44: 
1.1       harris41   45: my $pword=<>;
                     46: chomp $pword;
                     47: unless (length($safe) and ($user eq $safe) and ($safe=~/^[A-Za-z]/)) {
                     48:     exit 2;
                     49: }
1.7       foxr       50: print "Password = $pword" unless $noprint;
1.1       harris41   51: my $pbad=0;
1.6       matthew    52: foreach (split(//,$pword)) {if ((ord($_)<32)||(ord($_)>126)){$pbad=1;}} 
1.1       harris41   53: exit 3 if $pbad;
                     54: 
1.2       harris41   55: # --------------------------------------------------------- Call system command
1.1       harris41   56: open OUT,"|passwd --stdin $safe >/dev/null";
                     57: print OUT $pword;
                     58: print OUT "\n";
                     59: close OUT;
                     60: 
1.2       harris41   61: # --------------------------------------- exit with status of command execution
1.1       harris41   62: exit $?/256;
1.2       harris41   63: 
                     64: =head1 NAME
                     65: 
                     66: pwchange - setuid script to change unix passwords
                     67: 
                     68: =head1 DESCRIPTION
                     69: 
                     70: Setuid script to change unix passwords.
                     71: 
                     72: =head1 README
                     73: 
                     74: Setuid script to change unix passwords.
                     75: 
                     76: =head1 PREREQUISITES
                     77: 
                     78: =head1 COREQUISITES
                     79: 
                     80: =pod OSNAMES
                     81: 
                     82: linux
                     83: 
                     84: =pod SCRIPT CATEGORIES
                     85: 
                     86: LONCAPA/Administrative
                     87: 
                     88: =cut

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>