]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
libsmb: Use cli_ntcreate in cli_chkpath
authorVolker Lendecke <vl@samba.org>
Tue, 26 Oct 2021 06:51:16 +0000 (08:51 +0200)
committerJeremy Allison <jra@samba.org>
Thu, 11 Nov 2021 19:08:37 +0000 (19:08 +0000)
cli_ntcreate handles smb2, thus remove cli_smb2_chkpath.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/libsmb/cli_smb2_fnum.c
source3/libsmb/cli_smb2_fnum.h
source3/libsmb/clifile.c

index f70639e41bd49294ec0bc804cb6de89387785468..87c56b5564dd852f82aa0725aba730261b46111c 100644 (file)
@@ -1627,87 +1627,6 @@ NTSTATUS cli_smb2_qpathinfo_basic(struct cli_state *cli,
        return status;
 }
 
-struct cli_smb2_chkpath_state {
-       struct tevent_context *ev;
-       struct cli_state *cli;
-};
-
-static void cli_smb2_chkpath_opened(struct tevent_req *subreq);
-static void cli_smb2_chkpath_closed(struct tevent_req *subreq);
-
-struct tevent_req *cli_smb2_chkpath_send(
-       TALLOC_CTX *mem_ctx,
-       struct tevent_context *ev,
-       struct cli_state *cli,
-       const char *name)
-{
-       struct tevent_req *req = NULL, *subreq = NULL;
-       struct cli_smb2_chkpath_state *state = NULL;
-
-       req = tevent_req_create(
-               mem_ctx, &state, struct cli_smb2_chkpath_state);
-       if (req == NULL) {
-               return NULL;
-       }
-       state->ev = ev;
-       state->cli = cli;
-
-       /* Ensure this is a directory. */
-       subreq = cli_smb2_create_fnum_send(
-               state,                             /* mem_ctx */
-               ev,                                /* ev */
-               cli,                               /* cli */
-               name,                              /* fname */
-               0,                                 /* create_flags */
-               SMB2_IMPERSONATION_IMPERSONATION,  /* impersonation_level */
-               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 */
-               NULL);                             /* in_cblobs */
-       if (tevent_req_nomem(subreq, req)) {
-               return tevent_req_post(req, ev);
-       }
-       tevent_req_set_callback(subreq, cli_smb2_chkpath_opened, req);
-       return req;
-}
-
-static void cli_smb2_chkpath_opened(struct tevent_req *subreq)
-{
-       struct tevent_req *req = tevent_req_callback_data(
-               subreq, struct tevent_req);
-       struct cli_smb2_chkpath_state *state = tevent_req_data(
-               req, struct cli_smb2_chkpath_state);
-       NTSTATUS status;
-       uint16_t fnum = 0xffff;
-
-       status = cli_smb2_create_fnum_recv(subreq, &fnum, NULL, NULL, NULL);
-       TALLOC_FREE(subreq);
-       if (tevent_req_nterror(req, status)) {
-               return;
-       }
-
-       subreq = cli_smb2_close_fnum_send(state, state->ev, state->cli, fnum);
-       if (tevent_req_nomem(subreq, req)) {
-               return;
-       }
-       tevent_req_set_callback(subreq, cli_smb2_chkpath_closed, req);
-}
-
-static void cli_smb2_chkpath_closed(struct tevent_req *subreq)
-{
-       NTSTATUS status = cli_smb2_close_fnum_recv(subreq);
-       tevent_req_simple_finish_ntstatus(subreq, status);
-}
-
-NTSTATUS cli_smb2_chkpath_recv(struct tevent_req *req)
-{
-       return tevent_req_simple_recv_ntstatus(req);
-}
-
 struct cli_smb2_query_info_fnum_state {
        DATA_BLOB outbuf;
 };
index 91781b6a11b74c18a8e474972efa231e636e482e..f3355b33ca31355bbddbe410674859a35b6638e2 100644 (file)
@@ -109,12 +109,6 @@ 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);
-struct tevent_req *cli_smb2_chkpath_send(
-       TALLOC_CTX *mem_ctx,
-       struct tevent_context *ev,
-       struct cli_state *cli,
-       const char *name);
-NTSTATUS cli_smb2_chkpath_recv(struct tevent_req *req);
 struct tevent_req *cli_smb2_query_info_fnum_send(
        TALLOC_CTX *mem_ctx,
        struct tevent_context *ev,
index c619b009ec4732f41072fb5a35cc237f24002428..e300b6b96de9971fdccb97ec42b897ef23de5636 100644 (file)
@@ -4623,10 +4623,12 @@ NTSTATUS cli_setatr(struct cli_state *cli,
 ****************************************************************************/
 
 static void cli_chkpath_done(struct tevent_req *subreq);
-static void cli_chkpath_done2(struct tevent_req *subreq);
+static void cli_chkpath_opened(struct tevent_req *subreq);
+static void cli_chkpath_closed(struct tevent_req *subreq);
 
 struct cli_chkpath_state {
-       int dummy;
+       struct tevent_context *ev;
+       struct cli_state *cli;
 };
 
 struct tevent_req *cli_chkpath_send(TALLOC_CTX *mem_ctx,
@@ -4644,13 +4646,29 @@ struct tevent_req *cli_chkpath_send(TALLOC_CTX *mem_ctx,
        if (req == NULL) {
                return NULL;
        }
+       state->ev = ev;
+       state->cli = cli;
 
-       if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
-               subreq = cli_smb2_chkpath_send(state, ev, cli, fname);
+       if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_NT1) {
+               subreq = cli_ntcreate_send(
+                       state,                    /* mem_ctx */
+                       state->ev,                /* ev */
+                       state->cli,               /* cli */
+                       fname,                    /* fname */
+                       0,                        /* create_flags */
+                       FILE_READ_ATTRIBUTES,     /* desired_access */
+                       FILE_ATTRIBUTE_DIRECTORY, /* FileAttributes */
+                       FILE_SHARE_READ|
+                       FILE_SHARE_WRITE|
+                       FILE_SHARE_DELETE, /* share_access */
+                       FILE_OPEN,      /* CreateDisposition */
+                       FILE_DIRECTORY_FILE, /* CreateOptions */
+                       SMB2_IMPERSONATION_IMPERSONATION,
+                       0);             /* SecurityFlags */
                if (tevent_req_nomem(subreq, req)) {
                        return tevent_req_post(req, ev);
                }
-               tevent_req_set_callback(subreq, cli_chkpath_done2, req);
+               tevent_req_set_callback(subreq, cli_chkpath_opened, req);
                return req;
        }
 
@@ -4681,22 +4699,37 @@ struct tevent_req *cli_chkpath_send(TALLOC_CTX *mem_ctx,
 }
 
 static void cli_chkpath_done(struct tevent_req *subreq)
+{
+       NTSTATUS status = cli_smb_recv(
+               subreq, NULL, NULL, 0, NULL, NULL, NULL, NULL);
+       tevent_req_simple_finish_ntstatus(subreq, status);
+}
+
+static void cli_chkpath_opened(struct tevent_req *subreq)
 {
        struct tevent_req *req = tevent_req_callback_data(
                subreq, struct tevent_req);
+       struct cli_chkpath_state *state = tevent_req_data(
+               req, struct cli_chkpath_state);
        NTSTATUS status;
+       uint16_t fnum;
 
-       status = cli_smb_recv(subreq, NULL, NULL, 0, NULL, NULL, NULL, NULL);
+       status = cli_ntcreate_recv(subreq, &fnum, NULL);
        TALLOC_FREE(subreq);
        if (tevent_req_nterror(req, status)) {
                return;
        }
-       tevent_req_done(req);
+
+       subreq = cli_close_send(state, state->ev, state->cli, fnum);
+       if (tevent_req_nomem(subreq, req)) {
+               return;
+       }
+       tevent_req_set_callback(subreq, cli_chkpath_closed, req);
 }
 
-static void cli_chkpath_done2(struct tevent_req *subreq)
+static void cli_chkpath_closed(struct tevent_req *subreq)
 {
-       NTSTATUS status = cli_smb2_chkpath_recv(subreq);
+       NTSTATUS status = cli_close_recv(subreq);
        tevent_req_simple_finish_ntstatus(subreq, status);
 }