3 # -d: dry-run: make no changes
4 # -r: replace: overwrite existing passwords (otherwise only "*" passwords will
8 use vars qw(%part_svc);
9 use Term::Query qw(query);
10 use Net::SCP qw(iscp);
11 use FS::UID qw(adminsuidsetup datasrc);
12 use FS::Record qw(qsearch qsearchs);
16 use vars qw($opt_d $opt_r);
19 my $user = shift or die &usage;
22 push @FS::svc_acct::shells, qw(/bin/sync /sbin/shutdown /bin/halt /sbin/halt); #others?
24 my($spooldir)="/usr/local/etc/freeside/export.". datasrc;
26 #$FS::svc_acct::nossh_hack = 1;
27 $FS::svc_Common::noexport_hack = 1;
31 %part_svc=map { $_->svcpart, $_ } qsearch('part_svc',{'svcdb'=>'svc_acct'});
33 die "No services with svcdb svc_acct!\n" unless %part_svc;
35 print "\n\n", &menu_svc, "\n", <<END;
36 Enter part number to import.
38 my($shell_svcpart)=&getpart;
41 Enter the location and name of your _user_ shadow file, for example
42 "mail.isp.com:/etc/shadow" or "bsd.isp.com:/etc/master.passwd"
44 my($loc_shadow)=&getvalue(":");
45 iscp("root\@$loc_shadow", "$spooldir/shadow.import");
48 ( join "\n", map "$_: ".$part_svc{$_}->svc, sort keys %part_svc ). "\n";
51 $^W=0; # Term::Query isn't -w-safe
52 my $return = query "Enter part number:", 'irk', [ keys %part_svc ];
58 $^W=0; # Term::Query isn't -w-safe
59 my $return = query $prompt, '';
68 open(SHADOW,"<$spooldir/shadow.import");
74 my($username,$password)=split(/:/);
76 my @svc_acct = grep { $_->cust_svc->svcpart == $shell_svcpart }
77 qsearch('svc_acct', { 'username' => $username } );
79 next unless @svc_acct;
81 if ( scalar(@svc_acct) > 1 ) {
82 die "more than one $username found!\n";
86 my $svc_acct = shift @svc_acct;
88 next unless $svc_acct->_password eq '*' || $opt_r;
90 next if $svc_acct->_password eq $password;
91 next if $svc_acct->_password =~ /^\*SUSPENDED\*/;
93 my $new_svc_acct = new FS::svc_acct( { $svc_acct->hash } );
94 $new_svc_acct->_password($password);
95 #warn "$username: ". $svc_acct->_password. " -> $password\n";
96 warn "changing password for $username\n";
98 my $error = $new_svc_acct->replace($svc_acct);
99 die "$username: $error" if $error;
106 warn "$updated of $line passwords changed\n";
109 die "Usage:\n\n shadow.reimport [ -d ] [ -r ] user\n";