From a9db2ca8a50f4bb4e95966e20cd0188b69f4ce59 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 16 Mar 2018 13:07:05 +0100 Subject: [PATCH] cifs: move plugin related code into plugin --- PVE/API2/Storage/Config.pm | 23 ++++------------------- PVE/Storage/CIFSPlugin.pm | 23 ++++++++++++++++++----- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/PVE/API2/Storage/Config.pm b/PVE/API2/Storage/Config.pm index a7d9bf6..53c2107 100755 --- a/PVE/API2/Storage/Config.pm +++ b/PVE/API2/Storage/Config.pm @@ -9,6 +9,7 @@ use PVE::Cluster qw(cfs_read_file cfs_write_file); use PVE::Storage; use PVE::Storage::Plugin; use PVE::Storage::LVMPlugin; +use PVE::Storage::CIFSPlugin; use HTTP::Status qw(:constants); use Storable qw(dclone); use PVE::JSONSchema qw(get_standard_option); @@ -37,22 +38,6 @@ my $api_storage_config = sub { return $scfg; }; -my $cifs_cred_file_name = sub { - my ($storeid) = @_; - - return "/etc/pve/priv/${storeid}.cred"; -}; - -my $set_cifs_credentials = sub { - my ($password, $storeid) = @_; - - my $cred_file = $cifs_cred_file_name->($storeid); - - PVE::Tools::file_set_contents($cred_file, "password=$password\n"); - - return $cred_file; -}; - __PACKAGE__->register_method ({ name => 'index', path => '', @@ -204,8 +189,8 @@ __PACKAGE__->register_method ({ } # create a password file in /etc/pve/priv, # this file is used as a cert_file at mount time. - my $cred_file = &$set_cifs_credentials($password, $storeid) - if defined($password); + my $cred_file = PVE::Storage::cifs_set_credentials($password, $storeid) + if $type eq 'cifs' && defined($password); eval { # try to activate if enabled on local node, @@ -300,7 +285,7 @@ __PACKAGE__->register_method ({ if PVE::Storage::storage_is_used($cfg, $storeid); if ($scfg->{type} eq 'cifs') { - my $cred_file = $cifs_cred_file_name->($storeid); + my $cred_file = PVE::Storage::cifs_cred_file_name($storeid); if (-f $cred_file) { unlink($cred_file) or warn "removing cifs credientials '$cred_file' failed: $!\n"; } diff --git a/PVE/Storage/CIFSPlugin.pm b/PVE/Storage/CIFSPlugin.pm index 5cf8509..1670a5c 100644 --- a/PVE/Storage/CIFSPlugin.pm +++ b/PVE/Storage/CIFSPlugin.pm @@ -28,15 +28,28 @@ sub cifs_is_mounted { return undef; } +sub cifs_cred_file_name { + my ($storeid) = @_; + + return "/etc/pve/priv/${storeid}.cred"; +} + +sub cifs_set_credentials { + my ($password, $storeid) = @_; + + my $cred_file = cifs_cred_file_name($storeid); + + PVE::Tools::file_set_contents($cred_file, "password=$password\n"); + + return $cred_file; +} + sub get_cred_file { my ($storeid) = @_; - my $cred_file = '/etc/pve/priv/'.$storeid.'.cred'; + my $cred_file = cifs_cred_file_name($storeid); - if (-e $cred_file) { - return $cred_file; - } - return undef; + return -e $cred_file ? $cred_file : undef; } sub cifs_mount { -- 2.39.2