]> git.proxmox.com Git - pve-storage.git/commitdiff
CIFSPlugin.pm: fix crediential handling using new on_update_hook
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 20 Feb 2020 11:33:59 +0000 (12:33 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 20 Feb 2020 11:39:50 +0000 (12:39 +0100)
PVE/Storage/CIFSPlugin.pm

index 6115a967c069ce2de734c99f3c3817db9bad8571..6c8cd720b87f3dd3fb8122616cb27588834ebdfc 100644 (file)
@@ -34,6 +34,15 @@ sub cifs_cred_file_name {
     return "/etc/pve/priv/${storeid}.cred";
 }
 
+sub cifs_delete_credentials {
+    my ($storeid) = @_;
+
+    my $cred_file = cifs_cred_file_name($storeid);
+    if (-f $cred_file) {
+       unlink($cred_file) or warn "removing cifs credientials '$cred_file' failed: $!\n";
+    }
+}
+
 sub cifs_set_credentials {
     my ($password, $storeid) = @_;
 
@@ -145,18 +154,29 @@ sub check_config {
 sub on_add_hook {
     my ($class, $storeid, $scfg, %param) = @_;
 
-    if (my $password = $param{password}) {
-       cifs_set_credentials($password, $storeid);
+    if (defined($param{password})) {
+       cifs_set_credentials($param{password}, $storeid);
+    } else {
+       cifs_delete_credentials($storeid);
+    }
+}
+
+sub on_update_hook {
+    my ($class, $storeid, $scfg, %param) = @_;
+
+    return if !exists($param{password});
+
+    if (defined($param{password})) {
+       cifs_set_credentials($param{password}, $storeid);
+    } else {
+       cifs_delete_credentials($storeid);
     }
 }
 
 sub on_delete_hook {
     my ($class, $storeid, $scfg) = @_;
 
-    my $cred_file = cifs_cred_file_name($storeid);
-    if (-f $cred_file) {
-       unlink($cred_file) or warn "removing cifs credientials '$cred_file' failed: $!\n";
-    }
+    cifs_delete_credentials($storeid);
 }
 
 sub status {