aboutsummaryrefslogtreecommitdiffstats
path: root/iurt_root_command
diff options
context:
space:
mode:
authorClaudio Matsuoka <claudio@mandriva.com>2006-11-12 11:11:52 +0000
committerClaudio Matsuoka <claudio@mandriva.com>2006-11-12 11:11:52 +0000
commit16aad85bd47515a91ff462efd25121848370bf78 (patch)
treeae178ba0c52c702730af7c4864a52910bbd1e946 /iurt_root_command
parente00ac60cf3191d0b351a3b09003dedcd0e5dd7dc (diff)
downloadiurt-16aad85bd47515a91ff462efd25121848370bf78.tar
iurt-16aad85bd47515a91ff462efd25121848370bf78.tar.gz
iurt-16aad85bd47515a91ff462efd25121848370bf78.tar.bz2
iurt-16aad85bd47515a91ff462efd25121848370bf78.tar.xz
iurt-16aad85bd47515a91ff462efd25121848370bf78.zip
Using plot() functions.
Diffstat (limited to 'iurt_root_command')
-rw-r--r--iurt_root_command56
1 files changed, 28 insertions, 28 deletions
diff --git a/iurt_root_command b/iurt_root_command
index 0effdef..cfc763e 100644
--- a/iurt_root_command
+++ b/iurt_root_command
@@ -1,7 +1,5 @@
#!/usr/bin/perl
#
-#!/usr/bin/perl
-#
# Copyright (C) 2006 Mandriva
#
# Author: Florent Villard <warly@mandriva.com>
@@ -28,6 +26,7 @@ my $program_name = 'iurt_root_command';
use Mkcd::Commandline qw(parseCommandLine usage);
use MDK::Common;
use File::NCopy qw(copy);
+use Iurt::Util qw(plog_init plog);
my $arg = @ARGV;
my (@params, %run);
@@ -117,12 +116,13 @@ $run{todo} = [ ];
open(my $LOG, ">&STDERR");
$run{LOG} = $LOG;
-#print {$run{LOG}} "$program_name: @ARGV\n";
+plog_init($program_name, $LOG, $run{verbose});
+
my $todo = parseCommandLine($program_name, \@ARGV, \@params);
@ARGV and usage($program_name, \@params, "@ARGV, too many arguments");
my $ok = 1;
foreach my $t (@$todo) {
- print {$run{LOG}} "$program_name: $t->[2]\n" if $run{verbose} > 5;
+ plog(6, $t->[2]\n" if $run{verbose});
my $ok2 = &{$t->[0]}(\%run, @{$t->[1]});
$ok2 or print {$run{LOG}} "ERROR: $t->[2]\n";
$ok &&= $ok2;
@@ -133,7 +133,7 @@ exit !$ok;
sub modprobe {
my ($run, $module) = @_;
if (!$authorized_modules{$module}) {
- print {$run->{LOG}} "ERROR $program_name: unauthorized module $module\n";
+ plog("ERROR: unauthorized module $module");
return 0
}
open my $modules, '/proc/modules';
@@ -152,7 +152,7 @@ sub mkdir {
foreach my $path (@dir) {
-d $path and next;
if ($path =~ m,/dev|/proc|/root|/var, && $path !~ /chroot|unionfs/) {
- print {$run->{LOG}} "ERROR $program_name: $path creation forbidden\n";
+ plog("ERROR: $path creation forbidden");
}
if ($opt->{parents}) {
mkdir_p $path
@@ -166,7 +166,7 @@ sub mkdir {
sub initdb {
my ($run, $chroot) = @_;
if (-d $chroot && $chroot !~ /chroot|unionfs/) {
- print {$run{LOG}} "ERROR $program_name: rpm --initdb not authorized in $chroot\n";
+ plog($program_name: rpm --initdb not authorized in $chroot");
return 0
}
!system("rpm", "--initdb", "--root", "$chroot")
@@ -180,47 +180,47 @@ sub rm {
foreach my $f (@files) {
if (-d $f) {
if (!$opt->{recursive}) {
- print {$run->{LOG}} "$program_name: could not remove directories without the -r option\n";
+ plog("can't remove directories without the -r option");
$ok = 0
} else {
if ($f =~ m,$unauthorized,) {
- print {$run->{LOG}} "$program_name: removal of $f forbidden\n";
+ plog("removal of $f forbidden");
$ok = 0
} else {
system($sudo, 'rm', '-rf', $f);
- print {$run->{LOG}} "$program_name: removing $f\n" if $run->{verbose};
+ plog(1, "removing $f");
$done = 1
}
}
} else {
if ($f =~ m,/$unauthorized,) {
- print {$run->{LOG}} "$program_name: removal of $f forbidden\n";
+ plog("removal of $f forbidden");
$ok = 0
} else {
- # The original regexp was /\*?/, which doesn't seem to be
- # what we want. Check if we can always glob instead of
- # testing, or if glob expansion is needed at all --claudio
+ # CM: The original regexp was /\*?/, which doesn't seem to be
+ # what we want. Check if we can always glob instead of
+ # testing, or if glob expansion is needed at all
if ($f =~ /[*?]/) {
foreach my $file (glob $f) {
if ($f =~ m,$unauthorized,) {
- print {$run->{LOG}} "$program_name: removal of $f forbidden\n";
+ plog("removal of $f forbidden");
$ok = 0
} else {
unlink $file;
$done = 1;
- print {$run->{LOG}} "$program_name: removing $file\n" if $run->{verbose}
+ plog(1, "removing $file");
}
}
} else {
unlink $f;
$done = 1;
- print {$run->{LOG}} "$program_name: removing $f\n" if $run->{verbose}
+ plog(1, "removing $f");
}
}
}
}
- if (!$done) { print {$run->{LOG}} "$program_name: nothing deleted\n" }
+ if (!$done) { plog("nothing deleted"); }
$ok
}
@@ -231,17 +231,17 @@ sub cp {
my $dest = pop @files;
my $unauthorized = "^(/etc|/root|/dev|/var|/lib|/usr)";
if ($dest =~ /$unauthorized/ || $dest eq '/') {
- print {$run->{LOG}} "$program_name: copying to $dest forbidden\n";
+ plog("copying to $dest forbidden");
return
}
foreach my $f (@files) {
if (-d $f) {
if (!$opt->{recursive}) {
- print {$run->{LOG}} "$program_name: could not copy directories without the -r option\n";
+ plog("can't copy directories without the -r option");
$ok = 0
} else {
system($sudo, 'cp', '-raf', $f);
- print {$run->{LOG}} "$program_name: copying $f -> $dest\n" if $run->{verbose};
+ plog(1, "copying $f -> $dest");
$done = 1
}
} else {
@@ -249,24 +249,24 @@ sub cp {
foreach my $file (glob $f) {
if (copy $file, $dest) {
$done = 1;
- print {$run->{LOG}} "$program_name: copying $file -> $dest\n" if $run->{verbose}
+ plog(1, "copying $file -> $dest");
} else {
$ok = 0;
- print {$run->{LOG}} "$program_name: copying $file to $dest failed ($!)\n" if $run->{verbose}
+ plog(1, "copying $file to $dest failed ($!)");
}
}
} else {
if (copy $f, $dest) {
$done = 1;
- print {$run->{LOG}} "$program_name: copying $f -> $dest\n" if $run->{verbose}
+ plog(1, "copying $f -> $dest");
} else {
$ok = 0;
- print {$run->{LOG}} "$program_name: copying $f to $dest failed ($!)\n" if $run->{verbose}
+ plog(1, "copying $f to $dest failed ($!)");
}
}
}
}
- if (!$done) { print {$run->{LOG}} "$program_name: nothing copied\n" }
+ if (!$done) { plog("nothing copied"); }
$ok
}
@@ -274,8 +274,8 @@ sub ln {
my ($run, $opt, $file1, $file2) = @_;
my $unauthorized = "^(/etc|/root|/dev|/var|/lib|/usr)";
if ($file2 =~ /$unauthorized/ || $file2 eq '/') {
- print {$run->{LOG}} "$program_name: linking to $file2 forbidden\n";
- return
+ plog("linking to $file2 forbidden");
+ return;
}
link $file1, $file2;
}