]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
libsmb: Convert cli_posix_stat_send/recv() to modern conventions
authorVolker Lendecke <vl@samba.org>
Thu, 16 Feb 2023 16:35:24 +0000 (17:35 +0100)
committerJeremy Allison <jra@samba.org>
Thu, 9 Mar 2023 18:10:33 +0000 (18:10 +0000)
It's unusual these days to pass output arguments in the _send
function, instead save the result in the _state struct

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

index 45c8c96a0364418e3f574b5f8ff9a9472c8135c4..5c2e8208d75d5fc704897e0a2b7cc91df6ed9c53 100644 (file)
@@ -785,8 +785,8 @@ NTSTATUS cli_posix_setacl(struct cli_state *cli,
  Stat a file (UNIX extensions).
 ****************************************************************************/
 
-struct stat_state {
-       SMB_STRUCT_STAT *sbuf;
+struct cli_posix_stat_state {
+       struct stat_ex sbuf;
 };
 
 static void cli_posix_stat_done(struct tevent_req *subreq);
@@ -794,17 +794,15 @@ static void cli_posix_stat_done(struct tevent_req *subreq);
 struct tevent_req *cli_posix_stat_send(TALLOC_CTX *mem_ctx,
                                       struct tevent_context *ev,
                                       struct cli_state *cli,
-                                      const char *fname,
-                                      SMB_STRUCT_STAT *sbuf)
+                                      const char *fname)
 {
        struct tevent_req *req = NULL, *subreq = NULL;
        struct stat_state *state = NULL;
 
-       req = tevent_req_create(mem_ctx, &state, struct stat_state);
+       req = tevent_req_create(mem_ctx, &state, struct cli_posix_stat_state);
        if (req == NULL) {
                return NULL;
        }
-       state->sbuf = sbuf;
 
        subreq = cli_qpathinfo_send(state, ev, cli, fname,
                                    SMB_QUERY_FILE_UNIX_BASIC, 100, 100);
@@ -819,8 +817,9 @@ static void cli_posix_stat_done(struct tevent_req *subreq)
 {
        struct tevent_req *req = tevent_req_callback_data(
                                subreq, struct tevent_req);
-       struct stat_state *state = tevent_req_data(req, struct stat_state);
-       SMB_STRUCT_STAT *sbuf = state->sbuf;
+       struct cli_posix_stat_state *state = tevent_req_data(
+               req, struct cli_posix_stat_state);
+       SMB_STRUCT_STAT *sbuf = &state->sbuf;
        uint8_t *data;
        uint32_t num_data = 0;
        NTSTATUS status;
@@ -840,8 +839,6 @@ static void cli_posix_stat_done(struct tevent_req *subreq)
                return;
        }
 
-       *sbuf = (SMB_STRUCT_STAT) { 0 };
-
        /* total size, in bytes */
        sbuf->st_ex_size = IVAL2_TO_SMB_BIG_UINT(data, 0);
 
@@ -885,14 +882,22 @@ static void cli_posix_stat_done(struct tevent_req *subreq)
        tevent_req_done(req);
 }
 
-NTSTATUS cli_posix_stat_recv(struct tevent_req *req)
+NTSTATUS cli_posix_stat_recv(struct tevent_req *req, struct stat_ex *sbuf)
 {
-       return tevent_req_simple_recv_ntstatus(req);
+       struct cli_posix_stat_state *state = tevent_req_data(
+               req, struct cli_posix_stat_state);
+       NTSTATUS status;
+
+       if (tevent_req_is_nterror(req, &status)) {
+               return status;
+       }
+       *sbuf = state->sbuf;
+       return NT_STATUS_OK;
 }
 
 NTSTATUS cli_posix_stat(struct cli_state *cli,
                        const char *fname,
-                       SMB_STRUCT_STAT *sbuf)
+                       struct stat_ex *sbuf)
 {
        TALLOC_CTX *frame = talloc_stackframe();
        struct tevent_context *ev = NULL;
@@ -913,7 +918,7 @@ NTSTATUS cli_posix_stat(struct cli_state *cli,
                goto fail;
        }
 
-       req = cli_posix_stat_send(frame, ev, cli, fname, sbuf);
+       req = cli_posix_stat_send(frame, ev, cli, fname);
        if (req == NULL) {
                status = NT_STATUS_NO_MEMORY;
                goto fail;
@@ -923,7 +928,7 @@ NTSTATUS cli_posix_stat(struct cli_state *cli,
                goto fail;
        }
 
-       status = cli_posix_stat_recv(req);
+       status = cli_posix_stat_recv(req, sbuf);
 
  fail:
        TALLOC_FREE(frame);
index 3d732fe852477393e79e602f10de2b203c47f33e..3bac88c2ee434281619f35d07f0f74411f3f526e 100644 (file)
@@ -304,12 +304,11 @@ NTSTATUS cli_posix_setacl(struct cli_state *cli,
 struct tevent_req *cli_posix_stat_send(TALLOC_CTX *mem_ctx,
                                       struct tevent_context *ev,
                                       struct cli_state *cli,
-                                      const char *fname,
-                                      SMB_STRUCT_STAT *sbuf);
-NTSTATUS cli_posix_stat_recv(struct tevent_req *req);
+                                      const char *fname);
+NTSTATUS cli_posix_stat_recv(struct tevent_req *req, struct stat_ex *sbuf);
 NTSTATUS cli_posix_stat(struct cli_state *cli,
                        const char *fname,
-                       SMB_STRUCT_STAT *sbuf);
+                       struct stat_ex *sbuf);
 struct tevent_req *cli_posix_chmod_send(TALLOC_CTX *mem_ctx,
                                        struct tevent_context *ev,
                                        struct cli_state *cli,