From aa1656803c5742ed54ce983bdf656045e9c49b87 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 3 Feb 2004 00:19:45 +0000 Subject: adding shadow.reimport --- bin/shadow.reimport | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100755 bin/shadow.reimport (limited to 'bin/shadow.reimport') diff --git a/bin/shadow.reimport b/bin/shadow.reimport new file mode 100755 index 000000000..2c0ad1fea --- /dev/null +++ b/bin/shadow.reimport @@ -0,0 +1,98 @@ +#!/usr/bin/perl -Tw +# $Id: shadow.reimport,v 1.1 2004-02-03 00:19:45 ivan Exp $ + +use strict; +use vars qw(%part_svc); +use Term::Query qw(query); +use Net::SCP qw(iscp); +use FS::UID qw(adminsuidsetup datasrc); +use FS::Record qw(qsearch qsearchs); +use FS::svc_acct; +use FS::part_svc; + +my $user = shift or die &usage; +adminsuidsetup $user; + +push @FS::svc_acct::shells, qw(/bin/sync /sbin/shutdown /bin/halt /sbin/halt); #others? + +my($spooldir)="/usr/local/etc/freeside/export.". datasrc; + +#$FS::svc_acct::nossh_hack = 1; +$FS::svc_Common::noexport_hack = 1; + +### + +%part_svc=map { $_->svcpart, $_ } qsearch('part_svc',{'svcdb'=>'svc_acct'}); + +die "No services with svcdb svc_acct!\n" unless %part_svc; + +print "\n\n", &menu_svc, "\n", <svc, sort keys %part_svc ). "\n"; +} +sub getpart { + $^W=0; # Term::Query isn't -w-safe + my $return = query "Enter part number:", 'irk', [ keys %part_svc ]; + $^W=1; + $return; +} +sub getvalue { + my $prompt = shift; + $^W=0; # Term::Query isn't -w-safe + my $return = query $prompt, ''; + $^W=1; + $return; +} + +print "\n\n"; + +### + +open(SHADOW,"<$spooldir/shadow.import"); + +my($line, $updated); +while () { + $line++; + chop; + my($username,$password)=split(/:/); + + my @svc_acct = grep { $_->cust_svc->svcpart == $shell_svcpart } + qsearch('svc_acct', { 'username' => $username } ); + + next unless @svc_acct; + + if ( scalar(@svc_acct) > 1 ) { + warn "more than one $username found!\n"; + next; + } + + my $svc_acct = shift @svc_acct; + + next if $svc_acct->_password eq $password; + + 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; + + $updated++; + +} + +warn "$updated of $line passwords changed\n"; + +sub usage { + die "Usage:\n\n shadow.reimport user\n"; +} + -- cgit v1.2.1 From 44a98d88974faf787ba4f4264ee9532c86e19f1f Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 17 Mar 2004 22:45:15 +0000 Subject: add -d and -r options --- bin/shadow.reimport | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'bin/shadow.reimport') diff --git a/bin/shadow.reimport b/bin/shadow.reimport index 2c0ad1fea..4cb68a583 100755 --- a/bin/shadow.reimport +++ b/bin/shadow.reimport @@ -1,8 +1,12 @@ -#!/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) 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 +14,9 @@ use FS::Record qw(qsearch qsearchs); use FS::svc_acct; use FS::part_svc; +use vars qw($opt_d $opt_r); +getopts("dr"); + my $user = shift or die &usage; adminsuidsetup $user; @@ -29,14 +36,15 @@ die "No services with svcdb svc_acct!\n" unless %part_svc; print "\n\n", &menu_svc, "\n", <svc, sort keys %part_svc ). "\n"; @@ -73,18 +81,25 @@ while () { 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; + 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 +108,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"; } -- cgit v1.2.1 From 389dad7142dd7bf9c4b12d42958ebec50e4ae400 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 17 Mar 2004 22:49:26 +0000 Subject: re-enable prompting --- bin/shadow.reimport | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'bin/shadow.reimport') diff --git a/bin/shadow.reimport b/bin/shadow.reimport index 4cb68a583..846cb89c5 100755 --- a/bin/shadow.reimport +++ b/bin/shadow.reimport @@ -36,15 +36,14 @@ die "No services with svcdb svc_acct!\n" unless %part_svc; print "\n\n", &menu_svc, "\n", <svc, sort keys %part_svc ). "\n"; -- cgit v1.2.1 From c2962f704aa7711489f2dd2fc8be3396095aa166 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 17 Mar 2004 22:53:07 +0000 Subject: allow multiple svcparts --- bin/shadow.reimport | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'bin/shadow.reimport') diff --git a/bin/shadow.reimport b/bin/shadow.reimport index 846cb89c5..4d112d753 100755 --- a/bin/shadow.reimport +++ b/bin/shadow.reimport @@ -34,9 +34,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; -- cgit v1.2.1 From 9ceb48a8f852ba25cc569d2da87c092cf33b3a28 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 17 Mar 2004 22:55:51 +0000 Subject: fix multiple svcparts --- bin/shadow.reimport | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bin/shadow.reimport') diff --git a/bin/shadow.reimport b/bin/shadow.reimport index 4d112d753..a02582d96 100755 --- a/bin/shadow.reimport +++ b/bin/shadow.reimport @@ -36,7 +36,7 @@ die "No services with svcdb svc_acct!\n" unless %part_svc; print "\n\n", &menu_svc, "\n", < Date: Wed, 17 Mar 2004 23:08:48 +0000 Subject: skip root user and anyone with *LK* or NP accounts --- bin/shadow.reimport | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'bin/shadow.reimport') diff --git a/bin/shadow.reimport b/bin/shadow.reimport index a02582d96..2fc90d7f2 100755 --- a/bin/shadow.reimport +++ b/bin/shadow.reimport @@ -93,6 +93,10 @@ while () { next unless $svc_acct->_password eq '*' || $opt_r; + 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\*/; -- cgit v1.2.1 From 3b7030c2c7464c2a1b409cdc22fad4a593d4f231 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 18 Mar 2004 22:00:25 +0000 Subject: add -b option --- bin/shadow.reimport | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'bin/shadow.reimport') diff --git a/bin/shadow.reimport b/bin/shadow.reimport index 2fc90d7f2..7957011eb 100755 --- a/bin/shadow.reimport +++ b/bin/shadow.reimport @@ -3,6 +3,8 @@ # -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); @@ -14,8 +16,8 @@ use FS::Record qw(qsearch qsearchs); use FS::svc_acct; use FS::part_svc; -use vars qw($opt_d $opt_r); -getopts("dr"); +use vars qw($opt_d $opt_r $opt_b); +getopts("drb"); my $user = shift or die &usage; adminsuidsetup $user; @@ -91,7 +93,9 @@ while () { my $svc_acct = shift @svc_acct; - next unless $svc_acct->_password eq '*' || $opt_r; + next unless $svc_acct->_password eq '*' + || $opt_r + || ( $opt_b && $svc_acct->_password =~ /^\$2a?\$/ ); next if $svc_acct->username eq 'root'; -- cgit v1.2.1