File:  [LON-CAPA] / loncom / pwchange
Revision 1.10: download - view: text, annotated - select for diffs
Fri Jul 17 02:20:59 2009 UTC (14 years, 8 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_9_X, version_2_9_99_0, version_2_9_1, version_2_9_0, version_2_8_99_1, version_2_8_99_0, version_2_12_X, version_2_11_X, version_2_11_4_uiuc, version_2_11_4_msu, version_2_11_4, version_2_11_3_uiuc, version_2_11_3_msu, version_2_11_3, version_2_11_2_uiuc, version_2_11_2_msu, version_2_11_2_educog, version_2_11_2, version_2_11_1, version_2_11_0_RC3, version_2_11_0_RC2, version_2_11_0_RC1, version_2_11_0, version_2_10_X, version_2_10_1, version_2_10_0_RC2, version_2_10_0_RC1, version_2_10_0, loncapaMITrelate_1, language_hyphenation_merge, language_hyphenation, bz6209-base, bz6209, bz2851, PRINT_INCOMPLETE_base, PRINT_INCOMPLETE, HEAD, GCI_3, GCI_2, BZ4492-merge, BZ4492-feature_horizontal_radioresponse, BZ4492-feature_Support_horizontal_radioresponse, BZ4492-Support_horizontal_radioresponse
--stdin option not available with system passwd command in debian/ubuntu
 - use system call to usermod instead.

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

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