File:  [LON-CAPA] / loncom / pwchange
Revision 1.7: download - view: text, annotated - select for diffs
Mon Sep 16 13:27:40 2002 UTC (21 years, 7 months ago) by foxr
Branches: MAIN
CVS tags: HEAD
Bug 701 - added additional $noprint conditionalized deubgging.
    In lcpasswd, removed code too put a dummy entry at the end of
    /etc/smbpasswd (it's not the right file anyway), and added the -a
   switch to the smbpasswd command invocation.

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

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