From: Volker Lendecke Date: Thu, 16 Feb 2023 16:35:24 +0000 (+0100) Subject: libsmb: Convert cli_posix_stat_send/recv() to modern conventions X-Git-Tag: talloc-2.4.1~1429 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9bb8795aebdaad10713c791e45f11e3a4b94d5ff;p=thirdparty%2Fsamba.git libsmb: Convert cli_posix_stat_send/recv() to modern conventions 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 Reviewed-by: Jeremy Allison --- diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c index 45c8c96a036..5c2e8208d75 100644 --- a/source3/libsmb/clifile.c +++ b/source3/libsmb/clifile.c @@ -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); diff --git a/source3/libsmb/proto.h b/source3/libsmb/proto.h index 3d732fe8524..3bac88c2ee4 100644 --- a/source3/libsmb/proto.h +++ b/source3/libsmb/proto.h @@ -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,