[Samba] smbclient mask command seems not to work the same way with recurse ON for mget and mput

Jeremy Allison jra at samba.org
Mon Aug 24 20:33:52 UTC 2020


On Mon, Aug 24, 2020 at 09:15:48PM +0200, LPC DPG via samba wrote:
> Dear fellows.
> 
> Another piece of information. The issue reprduces on RHEL 7.7, Samba 4.9.1
> 
> [root at vnhprerhds01 ~]# cat /etc/redhat-release
> Red Hat Enterprise Linux Server release 7.7 (Maipo)
> [root at vnhprerhds01 ~]# smbclient -V
> Version 4.9.1
> 
> [root at vnhprerhds01 ~]# smbclient -W "${d}" -U "${u}" "${s}" "${p}"
> Try "help" to get a list of possible commands.
> smb: \> !mkdir -p /tmp/borrame/a
> smb: \> !mkdir -p /tmp/borrame/b
> smb: \> !touch /tmp/borrame/a/AM.xls
> smb: \> !touch /tmp/borrame/a/AT.xls
> smb: \> !touch /tmp/borrame/b/BT.xls
> smb: \> lcd /tmp/borrame
> smb: \> cd borrar
> smb: \borrar\> recurse
> smb: \borrar\> prompt
> smb: \borrar\> mask *M.xls
> smb: \borrar\> mput *
> putting file a/AT.xls as \borrar\a\AT.xls (0,0 kb/s) (average 0,0 kb/s)
> putting file a/AM.xls as \borrar\a\AM.xls (0,0 kb/s) (average 0,0 kb/s)
> putting file b/BT.xls as \borrar\b\BT.xls (0,0 kb/s) (average 0,0 kb/s)

All the 'mask' command does is set a global string that
is returned by the smbclient internal function: client_get_fileselection().

Here is the code that decides if smbclient should do anything
with a given filename:

/*******************************************************************
 Decide if a file should be operated on.
********************************************************************/

static bool do_this_one(struct file_info *finfo)
{
        if (!finfo->name) {
                return false;
        }

        if (finfo->attr & FILE_ATTRIBUTE_DIRECTORY) {
                return true;
        }

        if (*client_get_fileselection() &&
            !mask_match(finfo->name,client_get_fileselection(),false)) {
                DEBUG(3,("mask_match %s failed\n", finfo->name));
                return false;
        }
.....

Note, all it's doing is a mask_match() call against the
returned name and the string set via the 'mask' parameter.

Note that when you're doing 'recurse' and the operation
you set you're providing a second mask parameter '*'
in this case.

Looks like the function do_list_helper() only looks
at the mask set via the 'mask' command if it's not
recursing.

Looks like this might be a bug that no one ever ran
into before. Normally, people expect the mask given
to the mXXXX functions to take priority. I'm guessing
almost no one uses the 'mask' command.



More information about the samba mailing list