X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=bin%2Fshadow.reimport;h=7957011eb7bda839e92074cd73645cce00fd1273;hp=2c0ad1fea0d01d699b26c1b7f8251c559b53c300;hb=2c112f32561f23f9c538ace00db46659ce16da32;hpb=eb9668a6f3181ee02cb335272c5ee4616e61fd09 diff --git a/bin/shadow.reimport b/bin/shadow.reimport index 2c0ad1fea..7957011eb 100755 --- a/bin/shadow.reimport +++ b/bin/shadow.reimport @@ -1,8 +1,14 @@ -#!/usr/bin/perl -Tw -# $Id: shadow.reimport,v 1.1 2004-02-03 00:19:45 ivan Exp $ +#!/usr/bin/perl -w +# +# -d: dry-run: make no changes +# -r: replace: overwrite existing passwords (otherwise only "*" passwords will +# be changed) +# -b: blowfish replace: overwrite existing passwords only if they are +# blowfish-encrypted use strict; use vars qw(%part_svc); +use Getopt::Std; use Term::Query qw(query); use Net::SCP qw(iscp); use FS::UID qw(adminsuidsetup datasrc); @@ -10,6 +16,9 @@ use FS::Record qw(qsearch qsearchs); use FS::svc_acct; use FS::part_svc; +use vars qw($opt_d $opt_r $opt_b); +getopts("drb"); + my $user = shift or die &usage; adminsuidsetup $user; @@ -27,9 +36,10 @@ $FS::svc_Common::noexport_hack = 1; die "No services with svcdb svc_acct!\n" unless %part_svc; print "\n\n", &menu_svc, "\n", <) { chop; my($username,$password)=split(/:/); - my @svc_acct = grep { $_->cust_svc->svcpart == $shell_svcpart } - qsearch('svc_acct', { 'username' => $username } ); +# my @svc_acct = grep { $_->cust_svc->svcpart == $shell_svcpart } +# qsearch('svc_acct', { 'username' => $username } ); + my @svc_acct = grep { + my $svcpart = $_->cust_svc->svcpart; + grep { $_ == $svcpart } @shell_svcpart; + } qsearch('svc_acct', { 'username' => $username } ); next unless @svc_acct; if ( scalar(@svc_acct) > 1 ) { - warn "more than one $username found!\n"; + die "more than one $username found!\n"; next; } my $svc_acct = shift @svc_acct; + next unless $svc_acct->_password eq '*' + || $opt_r + || ( $opt_b && $svc_acct->_password =~ /^\$2a?\$/ ); + + next if $svc_acct->username eq 'root'; + + next if $password eq 'NP' || $password eq '*LK*'; + next if $svc_acct->_password eq $password; + next if $svc_acct->_password =~ /^\*SUSPENDED\*/; my $new_svc_acct = new FS::svc_acct( { $svc_acct->hash } ); $new_svc_acct->_password($password); - #my $error = $new_svc_acct->replace($svc_acct); - #die "$username: $error" if $error; + #warn "$username: ". $svc_acct->_password. " -> $password\n"; + warn "changing password for $username\n"; + unless ( $opt_d ) { + my $error = $new_svc_acct->replace($svc_acct); + die "$username: $error" if $error; + } $updated++; @@ -93,6 +120,6 @@ while () { warn "$updated of $line passwords changed\n"; sub usage { - die "Usage:\n\n shadow.reimport user\n"; + die "Usage:\n\n shadow.reimport [ -d ] [ -r ] user\n"; }