[pve-devel] [PATCH storage] fix #5181: pbs: store and read passwords as unicode
Maximiliano Sandoval
m.sandoval at proxmox.com
Wed Apr 9 10:30:19 CEST 2025
Previously a password "bär12345" would be stored as "b�r12345".
Signed-off-by: Maximiliano Sandoval <m.sandoval at proxmox.com>
---
This has the potential for breaking existing setups. However, given that it is
not possible to create such a storage in the first place (without performing a
rare encoding dance and/or editing the config files manually), I suspect the
fallback should be minimial.
This was tested via creating a user test at pbs with password 'bär12345' and then running:
```
pvesm add pbs test --server .. --datastore .. --username test at pbs --password 'bär12345' --fingerprint ..
cat /etc/pve/priv/storage/test.pw
```
src/PVE/Storage/PBSPlugin.pm | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/PVE/Storage/PBSPlugin.pm b/src/PVE/Storage/PBSPlugin.pm
index 9f75794e..7ecddd32 100644
--- a/src/PVE/Storage/PBSPlugin.pm
+++ b/src/PVE/Storage/PBSPlugin.pm
@@ -5,6 +5,7 @@ package PVE::Storage::PBSPlugin;
use strict;
use warnings;
+use Encode qw(decode);
use Fcntl qw(F_GETFD F_SETFD FD_CLOEXEC);
use IO::File;
use JSON;
@@ -91,7 +92,7 @@ sub pbs_set_password {
my $pwfile = pbs_password_file_name($scfg, $storeid);
mkdir "/etc/pve/priv/storage";
- PVE::Tools::file_set_contents($pwfile, "$password\n");
+ PVE::Tools::file_set_contents($pwfile, "$password\n", undef, 1);
}
sub pbs_delete_password {
@@ -107,7 +108,9 @@ sub pbs_get_password {
my $pwfile = pbs_password_file_name($scfg, $storeid);
- return PVE::Tools::file_read_firstline($pwfile);
+ my $contents = PVE::Tools::file_read_firstline($pwfile);
+
+ return eval { decode('UTF-8', $contents, 1) } // $contents;
}
sub pbs_encryption_key_file_name {
--
2.39.5
More information about the pve-devel
mailing list