The branch, master has been updated
       via  7caf2cbdf11 libsmb: Use tevent_req_simple_finish_ntstatus
       via  9a38dc0c1f7 libsmb: Add "in_cblobs" to cli_smb2_unlink
       via  7fc3b2b2642 libsmb: Add "in_cblobs" to cli_smb2_rmdir
       via  20ebd176859 libsmb: Make cli_smb2_unlink async
       via  3873437ee06 libsmb: Simplify cli_smb2_mxac
      from  c71334ec0c9 lib:util: Move debug message for mkdir failing to log 
level 1

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 7caf2cbdf11029c7ed9d78338c797fb8c4fa46b3
Author: Volker Lendecke <[email protected]>
Date:   Sat Mar 2 20:01:10 2019 +0100

    libsmb: Use tevent_req_simple_finish_ntstatus
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Jeremy Allison <[email protected]>
    
    Autobuild-User(master): Jeremy Allison <[email protected]>
    Autobuild-Date(master): Fri Mar  8 19:16:18 UTC 2019 on sn-devel-144

commit 9a38dc0c1f776ef21599f212dd5659676bf9c9fc
Author: Volker Lendecke <[email protected]>
Date:   Mon Mar 4 20:40:14 2019 +0100

    libsmb: Add "in_cblobs" to cli_smb2_unlink
    
    This reveals the fact that unlink is an open/close in smb2 through the
    API. This is not nice, but it's an internal API with currently only
    one user. And it enables posix semantics for the open easily.
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Jeremy Allison <[email protected]>

commit 7fc3b2b2642425cf9f55b4409cfb108a5a87e69e
Author: Volker Lendecke <[email protected]>
Date:   Mon Mar 4 20:40:14 2019 +0100

    libsmb: Add "in_cblobs" to cli_smb2_rmdir
    
    This reveals the fact that rmdir is an open/close in smb2 through the
    API. This is not nice, but it's an internal API with currently only
    one user. And it enables posix semantics for the open easily.
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Jeremy Allison <[email protected]>

commit 20ebd1768594fec757f4b0a5b56730c3f00226c0
Author: Volker Lendecke <[email protected]>
Date:   Mon Mar 4 20:38:24 2019 +0100

    libsmb: Make cli_smb2_unlink async
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Jeremy Allison <[email protected]>

commit 3873437ee0648e140cb0122c3122dc3839986105
Author: Volker Lendecke <[email protected]>
Date:   Mon Mar 4 21:21:57 2019 +0100

    libsmb: Simplify cli_smb2_mxac
    
    smb2_create_blob_find() can search for a create blob for us
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Jeremy Allison <[email protected]>

-----------------------------------------------------------------------

Summary of changes:
 source3/libsmb/cli_smb2_fnum.c | 229 +++++++++++++++++++++++++++++++----------
 source3/libsmb/cli_smb2_fnum.h |  27 +++--
 source3/libsmb/clifile.c       |  10 +-
 3 files changed, 198 insertions(+), 68 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/libsmb/cli_smb2_fnum.c b/source3/libsmb/cli_smb2_fnum.c
index 349d99b8eee..76eec6b3a0b 100644
--- a/source3/libsmb/cli_smb2_fnum.c
+++ b/source3/libsmb/cli_smb2_fnum.c
@@ -707,6 +707,7 @@ struct cli_smb2_rmdir_state {
        struct tevent_context *ev;
        struct cli_state *cli;
        const char *dname;
+       const struct smb2_create_blobs *in_cblobs;
        uint16_t fnum;
        NTSTATUS status;
 };
@@ -716,10 +717,12 @@ static void cli_smb2_rmdir_opened2(struct tevent_req 
*subreq);
 static void cli_smb2_rmdir_disp_set(struct tevent_req *subreq);
 static void cli_smb2_rmdir_closed(struct tevent_req *subreq);
 
-struct tevent_req *cli_smb2_rmdir_send(TALLOC_CTX *mem_ctx,
-                                      struct tevent_context *ev,
-                                      struct cli_state *cli,
-                                      const char *dname)
+struct tevent_req *cli_smb2_rmdir_send(
+       TALLOC_CTX *mem_ctx,
+       struct tevent_context *ev,
+       struct cli_state *cli,
+       const char *dname,
+       const struct smb2_create_blobs *in_cblobs)
 {
        struct tevent_req *req = NULL, *subreq = NULL;
        struct cli_smb2_rmdir_state *state = NULL;
@@ -731,6 +734,7 @@ struct tevent_req *cli_smb2_rmdir_send(TALLOC_CTX *mem_ctx,
        state->ev = ev;
        state->cli = cli;
        state->dname = dname;
+       state->in_cblobs = in_cblobs;
 
        if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
                tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
@@ -749,7 +753,7 @@ struct tevent_req *cli_smb2_rmdir_send(TALLOC_CTX *mem_ctx,
                FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* 
share_access */
                FILE_OPEN,              /* create_disposition */
                FILE_DIRECTORY_FILE,    /* create_options */
-               NULL);                  /* in_cblobs */
+               state->in_cblobs);      /* in_cblobs */
        if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
@@ -790,7 +794,7 @@ static void cli_smb2_rmdir_opened1(struct tevent_req 
*subreq)
                        FILE_DIRECTORY_FILE|
                        FILE_DELETE_ON_CLOSE|
                        FILE_OPEN_REPARSE_POINT, /* create_options */
-                       NULL);                           /* in_cblobs */
+                       state->in_cblobs);       /* in_cblobs */
                if (tevent_req_nomem(subreq, req)) {
                        return;
                }
@@ -873,7 +877,10 @@ NTSTATUS cli_smb2_rmdir_recv(struct tevent_req *req)
        return state->status;
 }
 
-NTSTATUS cli_smb2_rmdir(struct cli_state *cli, const char *dname)
+NTSTATUS cli_smb2_rmdir(
+       struct cli_state *cli,
+       const char *dname,
+       const struct smb2_create_blobs *in_cblobs)
 {
        TALLOC_CTX *frame = talloc_stackframe();
        struct tevent_context *ev;
@@ -892,7 +899,7 @@ NTSTATUS cli_smb2_rmdir(struct cli_state *cli, const char 
*dname)
        if (ev == NULL) {
                goto fail;
        }
-       req = cli_smb2_rmdir_send(frame, ev, cli, dname);
+       req = cli_smb2_rmdir_send(frame, ev, cli, dname, in_cblobs);
        if (req == NULL) {
                goto fail;
        }
@@ -912,36 +919,74 @@ fail:
  Synchronous only.
 ***************************************************************/
 
-NTSTATUS cli_smb2_unlink(struct cli_state *cli, const char *fname)
+struct cli_smb2_unlink_state {
+       struct tevent_context *ev;
+       struct cli_state *cli;
+       const char *fname;
+       const struct smb2_create_blobs *in_cblobs;
+};
+
+static void cli_smb2_unlink_opened1(struct tevent_req *subreq);
+static void cli_smb2_unlink_opened2(struct tevent_req *subreq);
+static void cli_smb2_unlink_closed(struct tevent_req *subreq);
+
+struct tevent_req *cli_smb2_unlink_send(
+       TALLOC_CTX *mem_ctx,
+       struct tevent_context *ev,
+       struct cli_state *cli,
+       const char *fname,
+       const struct smb2_create_blobs *in_cblobs)
 {
-       NTSTATUS status;
-       uint16_t fnum;
+       struct tevent_req *req = NULL, *subreq = NULL;
+       struct cli_smb2_unlink_state *state = NULL;
 
-       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;
+       req = tevent_req_create(mem_ctx, &state, struct cli_smb2_unlink_state);
+       if (req == NULL) {
+               return NULL;
        }
+       state->ev = ev;
+       state->cli = cli;
+       state->fname = fname;
+       state->in_cblobs = in_cblobs;
 
        if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
-               return NT_STATUS_INVALID_PARAMETER;
+               tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
+               return tevent_req_post(req, ev);
        }
 
-       status = cli_smb2_create_fnum(cli,
-                       fname,
-                       0,                      /* create_flags */
-                       SMB2_IMPERSONATION_IMPERSONATION,
-                       DELETE_ACCESS,          /* desired_access */
-                       FILE_ATTRIBUTE_NORMAL, /* file attributes */
-                       FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* 
share_access */
-                       FILE_OPEN,              /* create_disposition */
-                       FILE_DELETE_ON_CLOSE,   /* create_options */
-                       NULL,
-                       &fnum,
-                       NULL,
-                       NULL,
-                       NULL);
+       subreq = cli_smb2_create_fnum_send(
+               state,          /* mem_ctx */
+               state->ev,      /* tevent_context */
+               state->cli,     /* cli_struct */
+               state->fname,   /* filename */
+               0,                      /* create_flags */
+               SMB2_IMPERSONATION_IMPERSONATION,
+               DELETE_ACCESS,          /* desired_access */
+               FILE_ATTRIBUTE_NORMAL, /* file attributes */
+               FILE_SHARE_READ|
+               FILE_SHARE_WRITE|
+               FILE_SHARE_DELETE, /* share_access */
+               FILE_OPEN,              /* create_disposition */
+               FILE_DELETE_ON_CLOSE,   /* create_options */
+               state->in_cblobs);      /* in_cblobs */
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, cli_smb2_unlink_opened1, req);
+       return req;
+}
+
+static void cli_smb2_unlink_opened1(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct cli_smb2_unlink_state *state = tevent_req_data(
+               req, struct cli_smb2_unlink_state);
+       uint16_t fnum;
+       NTSTATUS status;
+
+       status = cli_smb2_create_fnum_recv(subreq, &fnum, NULL, NULL, NULL);
+       TALLOC_FREE(subreq);
 
        if (NT_STATUS_EQUAL(status, NT_STATUS_STOPPED_ON_SYMLINK)) {
                /*
@@ -950,27 +995,108 @@ NTSTATUS cli_smb2_unlink(struct cli_state *cli, const 
char *fname)
                 * component and try again. Eventually we will have to
                 * deal with the returned path unprocessed component. JRA.
                 */
-               status = cli_smb2_create_fnum(cli,
-                       fname,
+               subreq = cli_smb2_create_fnum_send(
+                       state,          /* mem_ctx */
+                       state->ev,      /* tevent_context */
+                       state->cli,     /* cli_struct */
+                       state->fname,   /* filename */
                        0,                      /* create_flags */
                        SMB2_IMPERSONATION_IMPERSONATION,
                        DELETE_ACCESS,          /* desired_access */
                        FILE_ATTRIBUTE_NORMAL, /* file attributes */
-                       FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* 
share_access */
+                       FILE_SHARE_READ|
+                       FILE_SHARE_WRITE|
+                       FILE_SHARE_DELETE, /* share_access */
                        FILE_OPEN,              /* create_disposition */
                        FILE_DELETE_ON_CLOSE|
-                               FILE_OPEN_REPARSE_POINT, /* create_options */
-                       NULL,
-                       &fnum,
-                       NULL,
-                       NULL,
-                       NULL);
+                       FILE_OPEN_REPARSE_POINT, /* create_options */
+                       state->in_cblobs);       /* in_cblobs */
+               if (tevent_req_nomem(subreq, req)) {
+                       return;
+               }
+               tevent_req_set_callback(subreq, cli_smb2_unlink_opened2, req);
+               return;
        }
 
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
+       if (tevent_req_nterror(req, status)) {
+               return;
        }
-       return cli_smb2_close_fnum(cli, fnum);
+
+       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_unlink_closed, req);
+}
+
+static void cli_smb2_unlink_opened2(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct cli_smb2_unlink_state *state = tevent_req_data(
+               req, struct cli_smb2_unlink_state);
+       uint16_t fnum;
+       NTSTATUS status;
+
+       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_unlink_closed, req);
+}
+
+static void cli_smb2_unlink_closed(struct tevent_req *subreq)
+{
+       NTSTATUS status = cli_smb2_close_fnum_recv(subreq);
+       tevent_req_simple_finish_ntstatus(subreq, status);
+}
+
+NTSTATUS cli_smb2_unlink_recv(struct tevent_req *req)
+{
+       return tevent_req_simple_recv_ntstatus(req);
+}
+
+NTSTATUS cli_smb2_unlink(
+       struct cli_state *cli,
+       const char *fname,
+       const struct smb2_create_blobs *in_cblobs)
+{
+       TALLOC_CTX *frame = talloc_stackframe();
+       struct tevent_context *ev;
+       struct tevent_req *req;
+       NTSTATUS status = NT_STATUS_NO_MEMORY;
+       bool ok;
+
+       if (smbXcli_conn_has_async_calls(cli->conn)) {
+               /*
+                * Can't use sync call while an async call is in flight
+                */
+               status = NT_STATUS_INVALID_PARAMETER;
+               goto fail;
+       }
+       ev = samba_tevent_context_init(frame);
+       if (ev == NULL) {
+               goto fail;
+       }
+       req = cli_smb2_unlink_send(frame, ev, cli, fname, in_cblobs);
+       if (req == NULL) {
+               goto fail;
+       }
+       ok = tevent_req_poll_ntstatus(req, ev, &status);
+       if (!ok) {
+               goto fail;
+       }
+       status = cli_smb2_unlink_recv(req);
+fail:
+       cli->raw_status = status;
+       TALLOC_FREE(frame);
+       return status;
 }
 
 /***************************************************************
@@ -2852,9 +2978,8 @@ static void cli_smb2_mxac_opened(struct tevent_req 
*subreq)
        struct cli_smb2_mxac_state *state = tevent_req_data(
                req, struct cli_smb2_mxac_state);
        struct smb2_create_blobs out_cblobs = {0};
-       DATA_BLOB *mxac_blob = NULL;
+       struct smb2_create_blob *mxac_blob = NULL;
        NTSTATUS status;
-       int i;
 
        status = cli_smb2_create_fnum_recv(
                subreq, &state->fnum, NULL, state, &out_cblobs);
@@ -2864,24 +2989,18 @@ static void cli_smb2_mxac_opened(struct tevent_req 
*subreq)
                return;
        }
 
-       for (i = 0; i < out_cblobs.num_blobs; i++) {
-               if (strcmp(out_cblobs.blobs[i].tag, SMB2_CREATE_TAG_MXAC) != 0) 
{
-                       continue;
-               }
-               mxac_blob = &out_cblobs.blobs[i].data;
-               break;
-       }
+       mxac_blob = smb2_create_blob_find(&out_cblobs, SMB2_CREATE_TAG_MXAC);
        if (mxac_blob == NULL) {
                state->status = NT_STATUS_INVALID_NETWORK_RESPONSE;
                goto close;
        }
-       if (mxac_blob->length != 8) {
+       if (mxac_blob->data.length != 8) {
                state->status = NT_STATUS_INVALID_NETWORK_RESPONSE;
                goto close;
        }
 
-       state->status = NT_STATUS(IVAL(mxac_blob->data, 0));
-       state->mxac = IVAL(mxac_blob->data, 4);
+       state->status = NT_STATUS(IVAL(mxac_blob->data.data, 0));
+       state->mxac = IVAL(mxac_blob->data.data, 4);
 
 close:
        subreq = cli_smb2_close_fnum_send(
diff --git a/source3/libsmb/cli_smb2_fnum.h b/source3/libsmb/cli_smb2_fnum.h
index c4ca069ee96..c39c8e90983 100644
--- a/source3/libsmb/cli_smb2_fnum.h
+++ b/source3/libsmb/cli_smb2_fnum.h
@@ -74,13 +74,28 @@ struct tevent_req *cli_smb2_delete_on_close_send(TALLOC_CTX 
*mem_ctx,
 NTSTATUS cli_smb2_delete_on_close_recv(struct tevent_req *req);
 NTSTATUS cli_smb2_delete_on_close(struct cli_state *cli, uint16_t fnum, bool 
flag);
 NTSTATUS cli_smb2_mkdir(struct cli_state *cli, const char *dirname);
-struct tevent_req *cli_smb2_rmdir_send(TALLOC_CTX *mem_ctx,
-                                      struct tevent_context *ev,
-                                      struct cli_state *cli,
-                                      const char *dname);
+struct tevent_req *cli_smb2_rmdir_send(
+       TALLOC_CTX *mem_ctx,
+       struct tevent_context *ev,
+       struct cli_state *cli,
+       const char *dname,
+       const struct smb2_create_blobs *in_cblobs);
 NTSTATUS cli_smb2_rmdir_recv(struct tevent_req *req);
-NTSTATUS cli_smb2_rmdir(struct cli_state *cli, const char *dirname);
-NTSTATUS cli_smb2_unlink(struct cli_state *cli,const char *fname);
+NTSTATUS cli_smb2_rmdir(
+       struct cli_state *cli,
+       const char *dname,
+       const struct smb2_create_blobs *in_cblobs);
+struct tevent_req *cli_smb2_unlink_send(
+       TALLOC_CTX *mem_ctx,
+       struct tevent_context *ev,
+       struct cli_state *cli,
+       const char *fname,
+       const struct smb2_create_blobs *in_cblobs);
+NTSTATUS cli_smb2_unlink_recv(struct tevent_req *req);
+NTSTATUS cli_smb2_unlink(
+       struct cli_state *cli,
+       const char *fname,
+       const struct smb2_create_blobs *in_cblobs);
 NTSTATUS cli_smb2_list(struct cli_state *cli,
                        const char *pathname,
                        uint16_t attribute,
diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c
index 49e58c0d252..d648b495fc6 100644
--- a/source3/libsmb/clifile.c
+++ b/source3/libsmb/clifile.c
@@ -1528,7 +1528,7 @@ NTSTATUS cli_unlink(struct cli_state *cli, const char 
*fname, uint16_t mayhave_a
        NTSTATUS status = NT_STATUS_OK;
 
        if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
-               return cli_smb2_unlink(cli, fname);
+               return cli_smb2_unlink(cli, fname, NULL);
        }
 
        frame = talloc_stackframe();
@@ -1758,7 +1758,7 @@ NTSTATUS cli_rmdir(struct cli_state *cli, const char 
*dname)
        NTSTATUS status = NT_STATUS_OK;
 
        if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
-               return cli_smb2_rmdir(cli, dname);
+               return cli_smb2_rmdir(cli, dname, NULL);
        }
 
        frame = talloc_stackframe();
@@ -5294,11 +5294,7 @@ static void cli_posix_open_done(struct tevent_req 
*subreq)
        NTSTATUS status;
 
        status = cli_posix_open_internal_recv(subreq, &state->fnum);
-       TALLOC_FREE(subreq);
-       if (tevent_req_nterror(req, status)) {
-               return;
-       }
-       tevent_req_done(req);
+       tevent_req_simple_finish_ntstatus(subreq, status);
 }
 
 NTSTATUS cli_posix_open_recv(struct tevent_req *req, uint16_t *pfnum)


-- 
Samba Shared Repository

Reply via email to