Annotation of loncom/lcuserdel, revision 1.2
1.1 harris41 1: #!/usr/bin/perl
2: #
3: # lcuserdel
4: #
5: # Scott Harrison
6: # October 27, 2000
7:
8: use strict;
9:
1.2 ! harris41 10: # This script is a setuid script (chmod 6755) that should
1.1 harris41 11: # be run by user 'www'. It DOES NOT delete directories.
12: # All it does is remove a user's entries from
13: # /etc/passwd, /etc/groups, and /etc/smbpasswd.
14:
15:
16:
17: # Standard input usage
18: # First line is USERNAME
19:
20: # Command-line arguments [USERNAME]
21: # Yes, but be very careful here (don't pass shell commands)
22: # and this is only supported to allow perl-system calls.
23:
1.2 ! harris41 24: # Usage within code
! 25: #
! 26: # $exitcode=system("NAME")/256;
! 27: # print "uh-oh" if $exitcode;
! 28:
! 29: # These are the exit codes.
! 30:
1.1 harris41 31: # Security
32: $ENV{'PATH'}=""; # Nullify path information.
33: $ENV{'BASH_ENV'}=""; # Nullify shell environment information.
1.2 ! harris41 34:
! 35: # Do not print error messages if there are command-line arguments
! 36: my $noprint=0;
! 37: if (@ARGV) {
! 38: $noprint=1;
! 39: }
! 40:
! 41: open (IN, "</etc/passwd");
! 42: my @lines=<IN>;
! 43: close IN;
! 44: my $wwwid;
! 45: for my $l (@lines) {
! 46: chop $l;
! 47: my @F=split(/\:/,$l);
! 48: if ($F[0] eq 'www') {$wwwid=$F[2];}
! 49: }
! 50: if ($wwwid!=$<) {
! 51: print("User ID mismatch. This program must be run as user 'www'\n") unless $noprint;
! 52: exit 1;
! 53: }
! 54: &disable_root_capability;
! 55:
! 56: # Gather input. Should only be 3 values.
! 57: my @input;
! 58: if (@ARGV==3) {
! 59: @input=@ARGV;
! 60: }
! 61: elsif (@ARGV) {
! 62: print("Error. This program needs 3 command-line arguments (username, old password, new password).\n") unless $noprint;
! 63: exit 2;
! 64: }
! 65: else {
! 66: @input=<>;
! 67: if (@input!=3) {
! 68: print("Error. Three lines need to be entered into standard input.\n") unless $noprint;
! 69: exit 3;
! 70: }
! 71: map {chop} @input;
! 72: }
! 73: # Handle case of another lcpasswd process
! 74: unless (&try_to_lock("/tmp/lock_lcpasswd")) {
! 75: print "Error. Too many other simultaneous password change requests being made.\n" unless $noprint;
! 76: exit 4;
! 77: }
! 78:
! 79:
1.1 harris41 80:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>