RFC: smbcacls fails with windows with SMB2 (succeeds with SMB1 only)

Jeremy Allison jra at samba.org
Thu Jul 20 16:28:03 UTC 2017


On Thu, Jul 20, 2017 at 02:30:14PM +0100, Noel Power via samba-technical wrote:
> 
> However since we only use this get_fileinfo function to return the file
> attributes (and actually only really to tell if the file is a directory)
> it seems the cli_qfileinfo_basic is unneccesary. Instead of changing the
> permissions I attach a patch to just remove the use of
> cli_qfileinfo_basic and get the file attributes instead from the
> cli_ntcreate call

Great analysis Noel and really nice simple fix.

Reviewed-by: Jeremy Allison <jra at samba.org>

Can I get a second Team reviewer ?

Jeremy.

> From f1648931a4fc45648f579742f62bd5140571ec5b Mon Sep 17 00:00:00 2001
> From: Noel Power <noel.power at suse.com>
> Date: Thu, 20 Jul 2017 13:01:50 +0100
> Subject: [PATCH] s3/utils: smbcacls failed to detect DIRECTORIES using SMB2
>  (windows only)
> 
> uint16_t get_fileinfo(...) returns file attributes, this function
> called
> 
>      cli_qfileinfo_basic(cli, fnum, &mode, NULL, NULL, NULL,
>                      NULL, NULL, NULL);
> 
> which was failing with NT_STATUS_ACCESS_DENIED errors when fnum above
> was obtained via (when using protocol > SMB). Note: This only seems to be
> an issue when run against a windows server, with smbd SMB1 & SMB2 work fine.
> 
>     status = cli_ntcreate(cli, filename, 0, CREATE_ACCESS_READ,
>                   0, FILE_SHARE_READ|FILE_SHARE_WRITE,
>                   FILE_OPEN, 0x0, 0x0, &fnum, NULL);
> 
> The failing cli_qfileinfo_basic call above is unnecessary as we can already
> obtain the required information from the cli_ntcreate call
> 
> Signed-off-by: Noel Power <noel.power at suse.com>
> ---
>  source3/utils/smbcacls.c | 14 +++-----------
>  1 file changed, 3 insertions(+), 11 deletions(-)
> 
> diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c
> index 36f8b3e3f8c..1f065e77af3 100644
> --- a/source3/utils/smbcacls.c
> +++ b/source3/utils/smbcacls.c
> @@ -253,30 +253,22 @@ get fileinfo for filename
>  static uint16_t get_fileinfo(struct cli_state *cli, const char *filename)
>  {
>  	uint16_t fnum = (uint16_t)-1;
> -	uint16_t mode = 0;
>  	NTSTATUS status;
> +	struct smb_create_returns cr = {0};
>  
>  	/* The desired access below is the only one I could find that works
>  	   with NT4, W2KP and Samba */
>  
>  	status = cli_ntcreate(cli, filename, 0, CREATE_ACCESS_READ,
>  			      0, FILE_SHARE_READ|FILE_SHARE_WRITE,
> -			      FILE_OPEN, 0x0, 0x0, &fnum, NULL);
> +			      FILE_OPEN, 0x0, 0x0, &fnum, &cr);
>  	if (!NT_STATUS_IS_OK(status)) {
>  		printf("Failed to open %s: %s\n", filename, nt_errstr(status));
>  		return 0;
>  	}
>  
> -	status = cli_qfileinfo_basic(cli, fnum, &mode, NULL, NULL, NULL,
> -				     NULL, NULL, NULL);
> -	if (!NT_STATUS_IS_OK(status)) {
> -		printf("Failed to file info %s: %s\n", filename,
> -		       nt_errstr(status));
> -        }
> -
>  	cli_close(cli, fnum);
> -
> -        return mode;
> +	return cr.file_attributes;
>  }
>  
>  /*****************************************************
> -- 
> 2.12.3
> 




More information about the samba-technical mailing list