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-9
11 # crypt-aware, s/password/_password/; ivan@sisd.com 98-aug-23
15 use Net::SSH qw(sshopen2);
16 use FS::UID qw(adminsuidsetup);
17 use FS::Record qw(qsearchs);
20 my $user = shift or die &usage;
23 my($shellmachine)=shift or die &usage;
25 #causing trouble for some folks
26 #$SIG{CHLD} = sub { wait() };
28 my($fs_passwdd)="/usr/local/sbin/fs_passwdd";
31 my($reader,$writer)=(new IO::Handle, new IO::Handle);
32 $writer->autoflush(1);
33 sshopen2($shellmachine,$reader,$writer,$fs_passwdd);
35 my($username,$old_password,$new_password,$new_gecos,$new_shell);
36 defined($username=<$reader>) or last;
37 defined($old_password=<$reader>) or last;
38 defined($new_password=<$reader>) or last;
39 defined($new_gecos=<$reader>) or last;
40 defined($new_shell=<$reader>) or last;
48 #need to try both $old_password and encrypted $old_password
49 #maybe the crypt function in svc_acct.export needs to be a library?
50 my $salt = substr($old_password,0,2);
51 my $cold_password = crypt($old_password,$salt);
52 $svc_acct=qsearchs('svc_acct',{'username'=>$username,
53 '_password'=>$old_password,
55 || qsearchs('svc_acct',{'username'=>$username,
56 '_password'=>$cold_password,
58 unless ( $svc_acct ) { print $writer "Incorrect password.\n"; next; }
60 my(%hash)=$svc_acct->hash;
61 my($new_svc_acct) = new FS::svc_acct ( \%hash );
62 $new_svc_acct->setfield('_password',$new_password)
63 if $new_password && $new_password ne $old_password;
64 $new_svc_acct->setfield('finger',$new_gecos) if $new_gecos;
65 $new_svc_acct->setfield('shell',$new_shell) if $new_shell;
66 my($error)=$new_svc_acct->replace($svc_acct);
67 print $writer $error,"\n";
72 warn "Connection to $shellmachine lost! Reconnecting...\n";
76 die "Usage:\n\n fs_passwd_server user shellmachine\n";