s3: libsmb: Add cli_smb2_chkpath() and use from cli_chkpath().
authorJeremy Allison <jra@samba.org>
Wed, 16 Aug 2017 22:48:01 +0000 (15:48 -0700)
committerJeremy Allison <jra@samba.org>
Thu, 17 Aug 2017 22:51:25 +0000 (00:51 +0200)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12968

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/libsmb/cli_smb2_fnum.c
source3/libsmb/cli_smb2_fnum.h
source3/libsmb/clifile.c

index 2d2667e4bb380c1b8088d1ad61f46bc63b42b2f0..b8179b0a48c8b241bfc7663b3cd5a992b81e6ddf 100644 (file)
@@ -1100,6 +1100,47 @@ NTSTATUS cli_smb2_qpathinfo_basic(struct cli_state *cli,
        return status;
 }
 
+/***************************************************************
+ Wrapper that allows SMB2 to check if a path is a directory.
+ Synchronous only.
+***************************************************************/
+
+NTSTATUS cli_smb2_chkpath(struct cli_state *cli,
+                               const char *name)
+{
+       NTSTATUS status;
+       uint16_t fnum = 0xffff;
+
+       if (smbXcli_conn_has_async_calls(cli->conn)) {
+               /*
+                * Can't use sync call while an async call is in flight
+                */
+               return NT_STATUS_INVALID_PARAMETER;
+       }
+
+       if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
+               return NT_STATUS_INVALID_PARAMETER;
+       }
+
+       /* Ensure this is a directory. */
+       status = cli_smb2_create_fnum(cli,
+                       name,
+                       0,                      /* create_flags */
+                       FILE_READ_ATTRIBUTES,   /* desired_access */
+                       FILE_ATTRIBUTE_DIRECTORY, /* file attributes */
+                       FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access */
+                       FILE_OPEN,              /* create_disposition */
+                       FILE_DIRECTORY_FILE,    /* create_options */
+                       &fnum,
+                       NULL);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       return cli_smb2_close_fnum(cli, fnum);
+}
+
 /***************************************************************
  Helper function for pathname operations.
 ***************************************************************/
index 402801bd18a33b77cf10baa1714c1aeb3fb4e51d..a6c36275eb8045e43dfb9dfd92f8de0c65303cbf 100644 (file)
@@ -79,6 +79,8 @@ NTSTATUS cli_smb2_qpathinfo_basic(struct cli_state *cli,
 NTSTATUS cli_smb2_qpathinfo_alt_name(struct cli_state *cli,
                        const char *name,
                        fstring alt_name);
+NTSTATUS cli_smb2_chkpath(struct cli_state *cli,
+                       const char *name);
 NTSTATUS cli_smb2_qfileinfo_basic(struct cli_state *cli,
                        uint16_t fnum,
                        uint16_t *mode,
index 828448f2d5a5efd3745e201390b7758a05141644..a6a0bafa2cd16e218729be783343ca71dc482123 100644 (file)
@@ -4233,12 +4233,18 @@ NTSTATUS cli_chkpath_recv(struct tevent_req *req)
 
 NTSTATUS cli_chkpath(struct cli_state *cli, const char *path)
 {
-       TALLOC_CTX *frame = talloc_stackframe();
+       TALLOC_CTX *frame = NULL;
        struct tevent_context *ev = NULL;
        struct tevent_req *req = NULL;
        char *path2 = NULL;
        NTSTATUS status = NT_STATUS_OK;
 
+       if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
+               return cli_smb2_chkpath(cli, path);
+       }
+
+       frame = talloc_stackframe();
+
        if (smbXcli_conn_has_async_calls(cli->conn)) {
                /*
                 * Can't use sync call while an async call is in flight