Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Unable to establish SMB2 connection using Filesys::SmbClient

by Netras (Initiate)
on Feb 09, 2016 at 13:05 UTC ( #1154727=perlquestion: print w/replies, xml ) Need Help??
Netras has asked for the wisdom of the Perl Monks concerning the following question:

Hello Perl Monks,

I need to access a SMB host which requires SMB version 2. Filesys::SmbClient (3.2) has served me well working with SMB1 but does not successfully create a SMB2 connection. This is the error I get:

samba_tevent: EPOLL_CTL_DEL EBADF for fde[0x27c9930] mpx_fde[(nil)] fd[8] - disabling

Directly using smbclient with SMB version 2 works fine:

smbclient -U domain\\user //HOSTNAME/ShareName -c "dir" -m SMB2

But when omitting the max-protocol tag (-m) while using smbclient, a very similar error appears:

smbclient -U domain\\user //HOSTNAME/ShareName -c "dir" samba_tevent: EPOLL_CTL_DEL EBADF for fde[0x7f454d1eff50] mpx_fde[(nil +)] fd[7] - disabling

I assume that Filesys::SmbClient is trying to use SMB version 1 to connect to the target host and I have no idea how I can change this behaviour. I have checked the official module documentation with no success and tried forcing the client protocol version in /etc/samba/smb.conf but this has no effect on Filesys::SmbClient as well.

Is there someone that has had this issue or has any ideas? I would appreciate any feedback and/or help in the matter.

Thank you!

Replies are listed 'Best First'.
Re: Unable to establish SMB2 connection using Filesys::SmbClient
by natxo (Scribe) on May 18, 2017 at 20:51 UTC
    A bit late to this post, but for future reference maybe worth it as smb 1 after the wannacry drama will probably be less and less common out there :-)

    I have just used Filesys::SmbClient with smb2 or 3. You just need to fill in the file ~/.smb/smb.conf that Filesys::Smbclient autocreates with something like this:

    [global] client max protocol = SMB3
    If the share only accepts smb2, it will downgrade to 2 or 2.1, otherwise it will use 3.

    I verified this using wireshark traces.

Re: Unable to establish SMB2 connection using Filesys::SmbClient
by Anonymous Monk on Feb 10, 2016 at 13:05 UTC

    Did you try to configure that option in your ~/.smb/smb.conf?

    [global]
    client max protocol = SMB2
    

      That is a bit embarrassing: I changed the general smb.conf in /etc/samba, the user didnīt have one. But then I created it and added the global parameter (client max protocol) and something changed! Now the connection is actually established, as far as I can see though I still get an error:

      map_errno_from_nt_status: 32 bit codes: code=c0000059 smbc errno NT_STATUS_REVISION_MISMATCH -> 22

      Google has failed me on my first try but I now have something I can work on. Maybe you also know about the new error but in any case - thank you a lot Anonymous Monk!

        It may or may not be related, but libsmbclient seems to have (had) some peculiarities regarding the smb.conf file, as commented on in the module:

        # Actually libsmbclient will segfault if it can't find file # $ENV{HOME}/.smb/smb.conf so I will test if it exist, # and create it if no file is found. A empty file is enough ... ... creation of an empty $ENV{HOME}/.smb/smb.conf

        So maybe libsmbclient does not crash nowadays but doesn't necessarily respect /etc/smb.conf if it doesn't find a local file.

      Yes, I have set the global parameter in smb.conf. And it did cause the smbclient call to work without adding the max-protocol tag (-m), so this was successful:

      smbclient -U domain\\user //HOSTNAME/ShareName -c "dir"

      But unfortunately it has no effect on Filesys::SmbClient and my Perl-script. It appears that it still uses SMB1 (same error message as before). I am very puzzled over this behaviour.

        Filesys::SmbClient doesn't have any knowledge of the protocol flag. I've gone ahead and fixed this in my environment (since I just had scheduled transfers fail because of it). I've supplied the patch here. I make no guarantees, I've done minimal testing, and I'm not responsible for anything that this patch may break in your environment. -- Jeremy Baumgartner
        --- SmbClientParser.pm.orig 2018-05-11 10:55:54.033252684 -0500 +++ SmbClientParser.pm 2018-05-11 11:07:15.612066151 -0500 @@ -5,6 +5,9 @@ # Copyright 2000-2002 A.Barbet alian@alianwebserver.com. All rights +reserved. # $Log: SmbClientParser.pm,v $ +# Revision 2.7.1 2018-05-11 11:06:00 jjb0528 +# - Added protocol selection to the options for smbclient +# # Revision 2.7 2004/04/14 21:53:18 alian # - fix rt#5896: Will Not work on shares that contain spaces in names # @@ -83,6 +86,7 @@ $self->Password($ref{password}) if ($ref{password}); $self->Workgroup($ref{workgroup}) if ($ref{workgroup}); $self->IpAdress($ref{ipadress}) if ($ref{ipadress}); + $self->Protocol($ref{protocol}) if ($ref{protocol}); $self->{DIR}='/'; $self->{"DEBUG"} = 0; return $self; @@ -99,6 +103,7 @@ sub Password {if ($_[1]) {$_[0]->{PASSWORD}=$_[1];} return $_[0]->{PA +SSWORD};} sub Workgroup {if ($_[1]) {$_[0]->{WG}=$_[1];} return $_[0]->{WG};} sub IpAdress {if ($_[1]) {$_[0]->{IP}=$_[1];} return $_[0]->{IP};} +sub Protocol {if ($_[1]) {$_[0]->{PROTO}=$_[1];} return $_[0]->{PROTO +};} sub LastResponse { if ($_[1]) {$_[0]->{LAST_REP}=$_[1];} return $_[0]->{LAST_REP};} sub err { @@ -498,17 +503,19 @@ # rearrange_param #-------------------------------------------------------------------- +---------- sub rearrange_param { - my ($self,$command,$dir, $host, $share, $user, $pass, $wg, $ip) = @ +_; + my ($self,$command,$dir, $host, $share, $user, $pass, $wg, $ip, $pr +oto) = @_; if (!$user) {$user=$self->User;} if (!$host) {$host=$self->Host;} if (!$share){$share=$self->Share;} if (!$pass) {$pass=$self->Password;} if (!$wg) {$wg=$self->Workgroup; } if (!$ip) {$ip =$self->IpAdress; } + if (!$proto) {$proto =$self->Protocol; } if (!$dir) {$dir=$self->{DIR}; } my $debug = ($self->{DEBUG} ? " -d".$self->{DEBUG} : ' -d0 '); $wg = ($wg ? ("-W ".$wg." ") : ' '); # Workgroup $ip = ($ip ? ("-I ".$ip." ") : ' '); # Ip adress of server + $proto = ($proto ? ("-m ".$proto." ") : ' '); # Protocol $dir = ($dir ? (' -D "'.$dir.'"') : ' '); # Path # User / Password if (($user)&&($pass)) { $user = '-U "'.$user.'%'.$pass.'" '; } @@ -519,7 +526,7 @@ if ($host) {$host='//'.$host; $path.=$host; } if ($share) {$share='/'.$share;$path.=$share; } $path.='" '; - my $prefix = $self->{SMBLIENT}.$path.$user.$wg.$ip.$debug; + my $prefix = $self->{SMBLIENT}.$path.$user.$wg.$ip.$debug.$proto; return ($self, $command, $prefix, $dir); }
Re: Unable to establish SMB2 connection using Filesys::SmbClient
by u65 (Chaplain) on Feb 10, 2016 at 12:23 UTC

    Welcome to the monastery, Netras! Have patience, some knowledgeable monk will help you eventually.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1154727]
Front-paged by GotToBTru
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2018-05-21 00:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?