Diff for /loncom/lcpasswd between versions 1.4 and 1.5

version 1.4, 2000/10/27 23:32:24 version 1.5, 2000/10/28 18:25:47
Line 13  use strict; Line 13  use strict;
 # both the /etc/passwd and the /etc/smbpasswd  # both the /etc/passwd and the /etc/smbpasswd
 # files.  # files.
   
   # This script works under the same process control mechanism
   # as lcuseradd and lcpasswd, to make sure that only one of these
   # processes is running at any one time on the system.
   
 # Standard input usage  # Standard input usage
 # First line is USERNAME  # First line is USERNAME
 # Second line is CURRENT PASSWORD  # Second line is CURRENT PASSWORD
Line 23  use strict; Line 27  use strict;
 # and this is only supported to allow perl-system calls.  # and this is only supported to allow perl-system calls.
   
 # Usage within code  # Usage within code
 # Note: NEVER run as system("NAME OLDPWD NEWPWD")  # Note: NEVER run as system("/home/httpd/perl/lcpasswd NAME OLDPWD NEWPWD")
 #  #
 # $exitcode=system("NAME","OLDPWD","NEWPWD")/256;  # $exitcode=system("/home/httpd/perl/lcpasswd","NAME","OLDPWD","NEWPWD")/256;
 # print "uh-oh" if $exitcode;  # print "uh-oh" if $exitcode;
   
 # These are the exit codes.  # These are the exit codes.
Line 48  if (@ARGV) { Line 52  if (@ARGV) {
     $noprint=1;      $noprint=1;
 }  }
   
   # Read in /etc/passwd, and make sure this process is running from user=www
 open (IN, "</etc/passwd");  open (IN, "</etc/passwd");
 my @lines=<IN>;  my @lines=<IN>;
 close IN;  close IN;
Line 59  for my $l (@lines) { Line 64  for my $l (@lines) {
 }  }
 if ($wwwid!=$<) {  if ($wwwid!=$<) {
     print("User ID mismatch.  This program must be run as user 'www'\n") unless $noprint;      print("User ID mismatch.  This program must be run as user 'www'\n") unless $noprint;
       unlink("/tmp/lock_lcpasswd");
     exit 1;      exit 1;
 }  }
 &disable_root_capability;  &disable_root_capability;
   
   # Handle case of another lcpasswd process
   unless (&try_to_lock("/tmp/lock_lcpasswd")) {
       print "Error. Too many other simultaneous password change requests being made.\n" unless $noprint;
       exit 4;
   }
   
 # Gather input.  Should only be 3 values.  # Gather input.  Should only be 3 values.
 my @input;  my @input;
 if (@ARGV==3) {  if (@ARGV==3) {
Line 70  if (@ARGV==3) { Line 82  if (@ARGV==3) {
 }  }
 elsif (@ARGV) {  elsif (@ARGV) {
     print("Error. This program needs 3 command-line arguments (username, old password, new password).\n") unless $noprint;      print("Error. This program needs 3 command-line arguments (username, old password, new password).\n") unless $noprint;
       unlink("/tmp/lock_lcpasswd");
     exit 2;      exit 2;
 }  }
 else {  else {
     @input=<>;      @input=<>;
     if (@input!=3) {      if (@input!=3) {
  print("Error. Three lines need to be entered into standard input.\n") unless $noprint;   print("Error. Three lines need to be entered into standard input.\n") unless $noprint;
    unlink("/tmp/lock_lcpasswd");
  exit 3;   exit 3;
     }      }
     map {chop} @input;      map {chop} @input;
 }  }
 # Handle case of another lcpasswd process  
 unless (&try_to_lock("/tmp/lock_lcpasswd")) {  
     print "Error. Too many other simultaneous password change requests being made.\n" unless $noprint;  
     exit 4;  
 }  
   
 my ($username,$oldpwd,$newpwd)=@input;  my ($username,$oldpwd,$newpwd)=@input;
   
Line 184  sub try_to_lock { Line 193  sub try_to_lock {
     my ($lockfile)=@_;      my ($lockfile)=@_;
     my $currentpid;      my $currentpid;
     my $lastpid;      my $lastpid;
       # Do not manipulate lock file as root
       if ($>==0) {
    return 0;
       }
       # Try to generate lock file.
       # Wait 3 seconds.  If same process id is in
       # lock file, then assume lock file is stale, and
       # go ahead.  If process id's fluctuate, try
       # for a maximum of 10 times.
     for (0..10) {      for (0..10) {
  if (-e $lockfile) {   if (-e $lockfile) {
     open(LOCK,"<$lockfile");      open(LOCK,"<$lockfile");

Removed from v.1.4  
changed lines
  Added in v.1.5


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