On 2/20/20 12:33 PM, Dietmar Maurer wrote:
> We need this to correctly update the password file.
> ---
>  PVE/API2/Storage/Config.pm | 25 +++++++++++++++++++++++--
>  PVE/Storage/Plugin.pm      |  9 +++++++++
>  2 files changed, 32 insertions(+), 2 deletions(-)
> 
> diff --git a/PVE/API2/Storage/Config.pm b/PVE/API2/Storage/Config.pm
> index d202784..09724f4 100755
> --- a/PVE/API2/Storage/Config.pm
> +++ b/PVE/API2/Storage/Config.pm
> @@ -204,12 +204,25 @@ __PACKAGE__->register_method ({
>           PVE::SectionConfig::assert_if_modified($cfg, $digest);
>  
>           my $scfg = PVE::Storage::storage_config($cfg, $storeid);
> +         my $type = $scfg->{type};
> +
> +         my $password;
> +         # always extract pw, else it gets written to the www-data readable 
> scfg
> +         if (my $tmp_pw = extract_param($param, 'password')) {
> +             if (($type eq 'pbs') || ($type eq 'cifs' && 
> $param->{username})) {
> +                 $password = $tmp_pw;
> +             } else {
> +                 warn "ignore password parameter\n";
> +             }
> +         }
>  
> -         my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
> +         my $plugin = PVE::Storage::Plugin->lookup($type);
>           my $opts = $plugin->check_config($storeid, $param, 0, 1);
>  
> +         my $delete_password = 0;
> +
>           if ($delete) {
> -             my $options = $plugin->private()->{options}->{$scfg->{type}};
> +             my $options = $plugin->private()->{options}->{$type};
>               foreach my $k (PVE::Tools::split_list($delete)) {
>                   my $d = $options->{$k} || die "no such option '$k'\n";
>                   die "unable to delete required option '$k'\n" if 
> !$d->{optional};
> @@ -218,9 +231,17 @@ __PACKAGE__->register_method ({
>                       if defined($opts->{$k});
>  
>                   delete $scfg->{$k};
> +
> +                 $delete_password = 1 if $k eq 'password';
>               }
>           }
>  
> +         if ($delete_password || defined($password)) {
> +             $plugin->on_update_hook($storeid, $opts, password => $password);
> +         } else {
> +             $plugin->on_update_hook($storeid, $opts);
> +         }
> +
>           for my $k (keys %$opts) {
>               $scfg->{$k} = $opts->{$k};
>           }
> diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm
> index 0c39cbd..fb06c38 100644
> --- a/PVE/Storage/Plugin.pm
> +++ b/PVE/Storage/Plugin.pm
> @@ -366,6 +366,15 @@ sub on_add_hook {
>      # do nothing by default
>  }
>  
> +# called during storage configuration update (before the updated storage 
> config got written)
> +# die to abort the update if there are (grave) problems
> +# NOTE: runs in a storage config *locked* context
> +sub on_update_hook {
> +    my ($class, $storeid, $scfg, %param) = @_;
> +
> +    # do nothing by default
> +}
> +
>  # called during deletion of storage (before the new storage config got 
> written)
>  # and if the activate check on addition fails, to cleanup all storage traces
>  # which on_add_hook may have created.
> 

applied all three patches, thanks for adding this missing piece!

_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to