3 # -d: dry-run: make no changes
4 # -r: replace: overwrite existing passwords (otherwise only "*" passwords will
6 # -b: blowfish replace: overwrite existing passwords only if they are
10 use vars qw(%part_svc);
12 use Term::Query qw(query);
13 use Net::SCP qw(iscp);
14 use FS::UID qw(adminsuidsetup datasrc);
15 use FS::Record qw(qsearch qsearchs);
19 use vars qw($opt_d $opt_r $opt_b);
22 my $user = shift or die &usage;
25 push @FS::svc_acct::shells, qw(/bin/sync /sbin/shutdown /bin/halt /sbin/halt); #others?
27 my($spooldir)="/usr/local/etc/freeside/export.". datasrc;
29 #$FS::svc_acct::nossh_hack = 1;
30 $FS::svc_Common::noexport_hack = 1;
34 %part_svc=map { $_->svcpart, $_ } qsearch('part_svc',{'svcdb'=>'svc_acct'});
36 die "No services with svcdb svc_acct!\n" unless %part_svc;
38 print "\n\n", &menu_svc, "\n", <<END;
39 Enter part number or part numbers to import.
41 my($shell_svcpart)=&getvalue;
42 my @shell_svcpart = split(/[,\s]+/, $shell_svcpart);
45 Enter the location and name of your _user_ shadow file, for example
46 "mail.isp.com:/etc/shadow" or "bsd.isp.com:/etc/master.passwd"
48 my($loc_shadow)=&getvalue(":");
49 iscp("root\@$loc_shadow", "$spooldir/shadow.import");
52 ( join "\n", map "$_: ".$part_svc{$_}->svc, sort keys %part_svc ). "\n";
55 $^W=0; # Term::Query isn't -w-safe
56 my $return = query "Enter part number:", 'irk', [ keys %part_svc ];
62 $^W=0; # Term::Query isn't -w-safe
63 my $return = query $prompt, '';
72 open(SHADOW,"<$spooldir/shadow.import");
78 my($username,$password)=split(/:/);
80 # my @svc_acct = grep { $_->cust_svc->svcpart == $shell_svcpart }
81 # qsearch('svc_acct', { 'username' => $username } );
83 my $svcpart = $_->cust_svc->svcpart;
84 grep { $_ == $svcpart } @shell_svcpart;
85 } qsearch('svc_acct', { 'username' => $username } );
87 next unless @svc_acct;
89 if ( scalar(@svc_acct) > 1 ) {
90 die "more than one $username found!\n";
94 my $svc_acct = shift @svc_acct;
96 next unless $svc_acct->_password eq '*'
98 || ( $opt_b && $svc_acct->_password =~ /^\$2a?\$/ );
100 next if $svc_acct->username eq 'root';
102 next if $password eq 'NP' || $password eq '*LK*';
104 next if $svc_acct->_password eq $password;
105 next if $svc_acct->_password =~ /^\*SUSPENDED\*/;
107 my $new_svc_acct = new FS::svc_acct( { $svc_acct->hash } );
108 $new_svc_acct->_password($password);
109 #warn "$username: ". $svc_acct->_password. " -> $password\n";
110 warn "changing password for $username\n";
112 my $error = $new_svc_acct->replace($svc_acct);
113 die "$username: $error" if $error;
120 warn "$updated of $line passwords changed\n";
123 die "Usage:\n\n shadow.reimport [ -d ] [ -r ] user\n";