diff -urN e-smith-backup-2.6.0.old/root/etc/e-smith/events/actions/workstation-backup-dar e-smith-backup-2.6.0/root/etc/e-smith/events/actions/workstation-backup-dar --- e-smith-backup-2.6.0.old/root/etc/e-smith/events/actions/workstation-backup-dar 2021-01-30 20:13:44.698955067 +0000 +++ e-smith-backup-2.6.0/root/etc/e-smith/events/actions/workstation-backup-dar 2021-01-30 20:18:00.982571819 +0000 @@ -31,6 +31,7 @@ use File::Glob qw(bsd_glob); use esmith::ConfigDB; use esmith::Backup; +use esmith::BlockDevices; sub ldie; sub start_dar_killer; @@ -312,77 +313,61 @@ return $code; } - +# Copied from /etc/e-smith/web/functions/backup +# TODO: Move to a shared module sub checkMount { # check if $mountdir is mounted my $mountdir = shift; $|=1; # Auto-flush - - # copy STDOUT to another filehandle - open (my $STDOLD, '>&', STDOUT); - - open(STDOUT, ">/dev/null"); - if ( open(MOUNTDIR, "|-", "/bin/findmnt", $mountdir)){;} - # restore STDOUT - open (STDOUT, '>&', $STDOLD); - - return (!close(MOUNTDIR)); + my @res = qx( findmnt $mountdir ); + return ( !@res ); } -# dmount is copied from /etc/e-smith/web/functions/backup -# it could become a common function later +# Copied from /etc/e-smith/web/functions/backup +# TODO: Move to a shared module sub dmount { # mount dar unit according to dar-workstation configuration # return nothing if mount successfull my ($host,$share,$mountdir,$login,$password,$VFSType) = @_; - + if ($VFSType eq 'cifs') { - return ( qx(/bin/mount -t cifs "//$host/$share" $mountdir -o credentials=/etc/dar/CIFScredentials,nounix 2>&1) ); + return ( qx(/bin/mount -t cifs "//$host/$share" $mountdir -o credentials=/etc/dar/CIFScredentials,nounix 2>&1) ); } elsif ($VFSType eq 'nfs') { - return ( qx(/bin/mount -t nfs -o nolock "$host:/$share" $mountdir 2>&1) ); + return ( qx(/bin/mount -t nfs -o nolock "$host:/$share" $mountdir 2>&1) ); } elsif ($VFSType eq 'usb') { my $device = ""; - my $blkdev = ""; my $vollbl = ""; - foreach my $udi (qx(hal-find-by-property --key volume.fsusage --string filesystem)) - { - $udi =~ m/^(\S+)/; - my $is_mounted = qx(hal-get-property --udi $1 --key volume.is_mounted); - if ($is_mounted eq "false\n") - { - $blkdev = qx(hal-get-property --udi $1 --key block.device); - if ($blkdev =~ m/^(\S+)/) {$blkdev = $1;} - } - if ($is_mounted eq "false\n") - { - $vollbl = qx(hal-get-property --udi $1 --key volume.label); - $vollbl =~ m/^(\S+)/; - if ($vollbl =~ /^\s/) {$vollbl = 'nolabel';} - } + my $devices = esmith::BlockDevices->new ('allowmount' => 'disabled'); + my ($valid, $invalid) = $devices->checkBackupDrives(0, 1); - chomp $vollbl; - chomp $blkdev; - $vollbl = "media/$vollbl"; - if ($vollbl eq $share) {$device = $blkdev;} + if ( ${$valid}[0] ) { + foreach ( @{$valid} ) { + warn $_; + $vollbl = $devices->label($_); + if ( $share eq "media/$vollbl" ) { + $device = "/dev/$_"; + } + } } - return ( qx(/bin/mount $device "/$share" 2>&1) ); + $devices->destroy; + return ( qx (mount $device /$share 2>&1) ); } else { - return ("Mount of type $VFSType not supported.\n"); + return ("Error while mounting $host/$share : $VFSType not supported.\n"); } -} +} sub removeTree diff -urN e-smith-backup-2.6.0.old/root/etc/e-smith/web/functions/backup e-smith-backup-2.6.0/root/etc/e-smith/web/functions/backup --- e-smith-backup-2.6.0.old/root/etc/e-smith/web/functions/backup 2021-01-30 20:13:44.674956230 +0000 +++ e-smith-backup-2.6.0/root/etc/e-smith/web/functions/backup 2021-01-30 20:17:32.531942610 +0000 @@ -27,6 +27,7 @@ use esmith::ConfigDB; use esmith::Backup; use esmith::BackupHistoryDB; +use esmith::BlockDevices; use esmith::AccountsDB; use esmith::cgi; use esmith::util; @@ -697,9 +698,9 @@ if (defined $status && $status eq "on") { - #-------------------------------------------------- - # Untaint parameters and check for validity - #-------------------------------------------------- + #-------------------------------------------------- + # Untaint parameters and check for validity + #-------------------------------------------------- my $backupHour = $q->param ('backupHour'); if ($backupHour =~ /^(.*)$/) { @@ -1237,23 +1238,20 @@ $q, undef, $fm->localise('CONFIGURE_WORKSTN_BACKUP')); if ( $VFSType eq 'usb' ) { - foreach my $udi (qx(hal-find-by-property --key volume.fsusage --string filesystem)) { - $udi =~ m/^(\S+)/; + my $devices = esmith::BlockDevices->new ('allowmount' => 'disabled'); + my ($valid, $invalid) = $devices->checkBackupDrives(0, 1); - my $is_mounted = qx(hal-get-property --udi $1 --key volume.is_mounted); - - if ($is_mounted eq "false\n") { - my $vollbl = qx(hal-get-property --udi $1 --key volume.label); - $vollbl =~ m/^(\S+)/; - if ($vollbl =~ /^\s/) {$vollbl = 'nolabel';} - chomp $vollbl; - push @usbdisks, $vollbl; + if ( ${$valid}[0] ) { + foreach ( @{$valid} ) { + push @usbdisks, $devices->label($_); } } - unless ($usbdisks[0]){ + else + { push @usbdisks, $fm->localise('ERR_NO_USB_DISK'); $error='nousb'; } + $devices->destroy; } if ( $VFSType eq 'mnt' ) { @@ -1509,9 +1507,9 @@ return; } - #-------------------------------------------------- - # Untaint parameters and check for validity - #-------------------------------------------------- + #-------------------------------------------------- + # Untaint parameters and check for validity + #-------------------------------------------------- my $VFSType = $q->param ('VFSType'); if ( $VFSType eq 'nousb') @@ -3007,7 +3005,7 @@ my $dumpsize = 0; open(DF, "-|") - or exec '/bin/df', '-P', '-t', 'ext3', '-t', 'ext4'; + or exec '/bin/df', '-P', '-t', 'ext3', '-t', 'ext4', '-t', 'xfs'; while () { @@ -3034,7 +3032,7 @@ my $halffree = 0; open(DF, "-|") - or exec '/bin/df', '-P', '-t', 'ext3', '-t', 'ext4', '/tmp'; + or exec '/bin/df', '-P', '-t', 'ext3', '-t', 'ext4', '-t', 'xfs', '/tmp'; while () { @@ -3106,30 +3104,21 @@ elsif ($VFSType eq 'usb') { my $device = ""; - my $blkdev = ""; my $vollbl = ""; - foreach my $udi (qx(hal-find-by-property --key volume.fsusage --string filesystem)) { - $udi =~ m/^(\S+)/; - my $is_mounted = qx(hal-get-property --udi $1 --key volume.is_mounted); - - if ($is_mounted eq "false\n") { - $blkdev = qx(hal-get-property --udi $1 --key block.device); - if ($blkdev =~ m/^(\S+)/) {$blkdev = $1;} - } - if ($is_mounted eq "false\n") { - $vollbl = qx(hal-get-property --udi $1 --key volume.label); - $vollbl =~ m/^(\S+)/; - if ($vollbl =~ /^\s/) {$vollbl = 'nolabel';} - } - - chomp $vollbl; - chomp $blkdev; - $vollbl = "media/$vollbl"; - if ($vollbl eq $share) { - $device = $blkdev; - } + + my $devices = esmith::BlockDevices->new ('allowmount' => 'disabled'); + my ($valid, $invalid) = $devices->checkBackupDrives(0, 1); + + if ( ${$valid}[0] ) { + foreach ( @{$valid} ) { + $vollbl = $devices->label($_); + if ( $share eq "media/$vollbl" ) { + $device = "/dev/$_"; + } + } } - return ( qx(/bin/mount $device "/$share" 2>&1) ); + $devices->destroy; + return ( qx (mount $device /$share 2>&1) ); } else { @@ -3142,17 +3131,9 @@ # check if $mountdir is mounted my $mountdir = shift; $|=1; # Auto-flush - - # copy STDOUT to another filehandle - open (my $STDOLD, '>&', STDOUT); - - open(STDOUT, ">/dev/null"); - if ( open(MOUNTDIR, "|-", "/bin/findmnt", $mountdir)){;} - - # restore STDOUT - open (STDOUT, '>&', $STDOLD); - - return (!close(MOUNTDIR)); + + my @res = qx( findmnt $mountdir ); + return ( !@res ); } sub bmount diff -urN e-smith-backup-2.6.0.old/root/usr/share/perl5/vendor_perl/esmith/BlockDevices.pm e-smith-backup-2.6.0/root/usr/share/perl5/vendor_perl/esmith/BlockDevices.pm --- e-smith-backup-2.6.0.old/root/usr/share/perl5/vendor_perl/esmith/BlockDevices.pm 2021-01-30 20:13:44.702954873 +0000 +++ e-smith-backup-2.6.0/root/usr/share/perl5/vendor_perl/esmith/BlockDevices.pm 2021-01-30 20:16:39.613490616 +0000 @@ -200,7 +200,7 @@ # Return two arrays, valid drives, invalid drives sub checkBackupDrives { - my ($self,$bsize) = @_; + my ($self,$bsize,$removable) = @_; my @valid = (); my @invalid = (); $self->scanBlocks; # scan all block devices @@ -209,6 +209,7 @@ my $checks = 'UU RO FS'; # These checks are always valid $checks .= ' MO' if ($allowmount eq 'enabled'); $checks .= ' SZ' if ($bsize); # Only run the size check when a valid size is given + $checks .= ' RM' if ($removable); # Only run the removable check if asked foreach my $drive (keys %{$hashref}) { @@ -239,6 +240,10 @@ { $hashref->{$drive}{REASON} .='MO ' if $self->mountpoint ($drive); last; } + if (/^RM/si) # Non-removable + { + $hashref->{$drive}{REASON} .='RM ' unless $self->removable ($drive); last; + } if (/^SZ/si) # filesystem size, this includes mounting to check free space { $hashref->{$drive}{REASON} .='SZ ' if $self->checkBackupDriveSize ($drive, $bsize); @@ -360,13 +365,20 @@ return ($hashref->{$kname}{MODEL}); } +sub removable +{ + my ($self,$kname) = @_; + my $hashref = $self->{_blox}; + return ($hashref->{$kname}{RM}) ? 1 : $EMPTY; +} + # Given the KNAME return the label # returns 'no label' if none found sub label { my ($self,$kname) = @_; my $hashref = $self->{_blox}; - return ($hashref->{$kname}{LABEL}) || gettext('no label'); + return ($hashref->{$kname}{LABEL}) || gettext('nolabel'); } sub size