5 # portions of this script are copied from the `passwd' script in the original
6 # (perl 4) camel book, now archived at
7 # http://www.perl.com/CPAN/scripts/nutshell/ch6/passwd
9 # ivan@sisd.com 98-mar-8
11 # password lengths 0,255 instead of 6,8 - we'll let the server process
12 # check the data ivan@sisd.com 98-jul-17
18 use vars qw($opt_f $opt_s);
20 my($fs_passwdd_socket)="/usr/local/freeside/fs_passwdd_socket";
21 my($freeside_uid)=scalar(getpwnam('freeside'));
23 $ENV{'PATH'} ='/usr/local/bin:/usr/bin:/usr/ucb:/bin';
24 $ENV{'SHELL'} = '/bin/sh';
25 $ENV{'IFS'} = " \t\n";
28 $ENV{'BASH_ENV'} = '';
30 $SIG{__DIE__}= sub { system '/bin/stty', 'echo'; };
32 die "passwd program isn't running setuid to freeside\n" if $> != $freeside_uid;
34 unshift @ARGV, "-f" if $0 =~ /chfn$/;
35 unshift @ARGV, "-s" if $0 =~ /chsh$/;
40 if ( $_ = shift(@ARGV) ) {
44 die "You can't change the password for $me." if $me && $<;
45 $me = (getpwuid($<))[0] unless $me;
47 my($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell)=
50 my($old_password,$new_password,$new_gecos,$new_shell);
52 if ( $opt_f || $opt_s ) {
53 system '/bin/stty', '-echo';
55 $old_password=<STDIN>;
56 system '/bin/stty', 'echo';
58 #$old_password =~ /^(.{6,8})$/ or die "\nIllegal password.\n";
59 $old_password =~ /^(.{0,255})$/ or die "\nIllegal password.\n";
65 print "\nChanging gecos for $me.\n";
66 print "Gecos [", $gcos, "]: ";
70 $new_gecos =~ /^(.{0,255})$/ or die "\nIllegal gecos.\n";
76 print "\nChanging shell for $me.\n";
77 print "Shell [", $shell, "]: ";
80 $new_shell ||= $shell;
81 $new_shell =~ /^(.{0,255})$/ or die "\nIllegal shell.\n";
88 print "Changing password for $me.\n";
89 print "Old password:";
90 system '/bin/stty', '-echo';
91 $old_password=<STDIN>;
93 #$old_password =~ /^(.{6,8})$/ or die "\nIllegal password.\n";
94 $old_password =~ /^(.{0,255})$/ or die "\nIllegal password.\n";
96 print "\nEnter the new password (minimum of 6, maximum of 8 characters)\n";
97 print "Please use a combination of upper and lowercase letters and numbers.\n";
98 print "New password:";
99 $new_password=<STDIN>;
101 #$new_password =~ /^(.{6,8})$/ or die "\nIllegal password.\n";
102 $new_password =~ /^(.{0,255})$/ or die "\nIllegal password.\n";
104 print "\nRe-enter new password:";
105 my($check_new_password);
106 $check_new_password=<STDIN>;
107 chop($check_new_password);
108 die "\nThey don't match; try again.\n" unless $check_new_password eq $new_password;
115 system '/bin/stty', 'echo';
117 socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!";
118 connect(SOCK, sockaddr_un($fs_passwdd_socket)) or die "connect: $!";
119 print SOCK join("\n",$me,$old_password,$new_password,$new_gecos,$new_shell),"\n";
126 print "\nUpdate error: $error\n";
128 print "\nUpdate sucessful.\n";