]> git.proxmox.com Git - pve-storage.git/commitdiff
cifs: negotiates the highest SMB2+ version supported by default
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 14 Sep 2021 14:23:23 +0000 (16:23 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 15 Sep 2021 08:59:00 +0000 (10:59 +0200)
instead of hardcoding it to a potential outdated value.

For `smbclient` we only set max-protocol version and that could only
be smb2 or smb3 (no finer granularity) any how, so this was not
really correct.

Nowadays the kernel dropped SMB1 and tries to go for SMB2.1 or higher
by default, depending on what client and server supports. SMB2.1 is
Windows 7/2008R2 - both EOL since quite a bit, so ok as default lower
boundary.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/Storage/CIFSPlugin.pm

index 565fb78ce4fbe2f0a46cb8ec9eae7adad84bbe88..c5f38942979aafeb4dcfb28bbd892c83910e6c20 100644 (file)
@@ -78,7 +78,7 @@ sub cifs_mount {
        push @$cmd, 'guest,username=guest';
     }
 
-    push @$cmd, '-o', defined($smbver) ? "vers=$smbver" : "vers=3.0";
+    push @$cmd, '-o', defined($smbver) ? "vers=$smbver" : "vers=default";
 
     run_command($cmd, errmsg => "mount error");
 }
@@ -115,8 +115,10 @@ sub properties {
            maxLength => 256,
        },
        smbversion => {
-           description => "SMB protocol version",
+           description => "SMB protocol version. 'default' if not set, negotiates the highest SMB2+"
+               ." version supported by both the client and server.",
            type => 'string',
+           default => 'default',
            enum => ['default', '2.0', '2.1', '3', '3.0', '3.11'],
            optional => 1,
        },
@@ -255,9 +257,12 @@ sub check_connection {
 
     my $servicename = '//'.$scfg->{server}.'/'.$scfg->{share};
 
-    my $cmd = ['/usr/bin/smbclient', $servicename, '-d', '0', '-m'];
+    my $cmd = ['/usr/bin/smbclient', $servicename, '-d', '0'];
 
-    push @$cmd, $scfg->{smbversion} ? "smb".int($scfg->{smbversion}) : 'smb3';
+    if (defined($scfg->{smbversion}) && $scfg->{smbversion} ne 'default') {
+       # max-protocol version, so basically only relevant for smb2 vs smb3
+       push @$cmd, '-m', "smb" . int($scfg->{smbversion});
+    }
 
     if (my $cred_file = get_cred_file($storeid)) {
        push @$cmd, '-U', $scfg->{username}, '-A', $cred_file;