From: Volker Lendecke Date: Fri, 13 Nov 2020 15:23:48 +0000 (+0100) Subject: libsmb: Make cli_rename_send()/_recv() a proper tevent_req engine X-Git-Tag: samba-4.14.0rc1~602 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=db1fa2392d7be0ca433fcd65035985595bbf0c20;p=thirdparty%2Fsamba.git libsmb: Make cli_rename_send()/_recv() a proper tevent_req engine This will make it more obvious to add SMB2 soon Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c index 6f6ede24152..ee0b80ee378 100644 --- a/source3/libsmb/clifile.c +++ b/source3/libsmb/clifile.c @@ -1210,36 +1210,6 @@ NTSTATUS cli_posix_chown(struct cli_state *cli, Rename a file. ****************************************************************************/ -static struct tevent_req *cli_cifs_rename_send(TALLOC_CTX *mem_ctx, - struct tevent_context *ev, - struct cli_state *cli, - const char *fname_src, - const char *fname_dst, - bool replace); - -static struct tevent_req *cli_smb1_rename_send(TALLOC_CTX *mem_ctx, - struct tevent_context *ev, - struct cli_state *cli, - const char *fname_src, - const char *fname_dst, - bool replace); - -struct tevent_req *cli_rename_send(TALLOC_CTX *mem_ctx, - struct tevent_context *ev, - struct cli_state *cli, - const char *fname_src, - const char *fname_dst, - bool replace) -{ - if (replace && smbXcli_conn_support_passthrough(cli->conn)) { - return cli_smb1_rename_send(mem_ctx, ev, cli, fname_src, - fname_dst, replace); - } else { - return cli_cifs_rename_send(mem_ctx, ev, cli, fname_src, - fname_dst, replace); - } -} - struct cli_smb1_rename_state { uint8_t *data; }; @@ -1318,6 +1288,11 @@ static void cli_smb1_rename_done(struct tevent_req *subreq) tevent_req_simple_finish_ntstatus(subreq, status); } +static NTSTATUS cli_smb1_rename_recv(struct tevent_req *req) +{ + return tevent_req_simple_recv_ntstatus(req); +} + static void cli_cifs_rename_done(struct tevent_req *subreq); struct cli_cifs_rename_state { @@ -1392,16 +1367,67 @@ static struct tevent_req *cli_cifs_rename_send(TALLOC_CTX *mem_ctx, static void cli_cifs_rename_done(struct tevent_req *subreq) { - struct tevent_req *req = tevent_req_callback_data( - subreq, struct tevent_req); - NTSTATUS status; + NTSTATUS status = cli_smb_recv( + subreq, NULL, NULL, 0, NULL, NULL, NULL, NULL); + tevent_req_simple_finish_ntstatus(subreq, status); +} - status = cli_smb_recv(subreq, NULL, NULL, 0, NULL, NULL, NULL, NULL); - TALLOC_FREE(subreq); - if (tevent_req_nterror(req, status)) { - return; +static NTSTATUS cli_cifs_rename_recv(struct tevent_req *req) +{ + return tevent_req_simple_recv_ntstatus(req); +} + +struct cli_rename_state { + uint8_t dummy; +}; + +static void cli_rename_done1(struct tevent_req *subreq); +static void cli_rename_done_cifs(struct tevent_req *subreq); + +struct tevent_req *cli_rename_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct cli_state *cli, + const char *fname_src, + const char *fname_dst, + bool replace) +{ + struct tevent_req *req = NULL, *subreq = NULL; + struct cli_rename_state *state = NULL; + + req = tevent_req_create(mem_ctx, &state, struct cli_rename_state); + if (req == NULL) { + return NULL; } - tevent_req_done(req); + + if (replace && smbXcli_conn_support_passthrough(cli->conn)) { + subreq = cli_smb1_rename_send( + state, ev, cli, fname_src, fname_dst, replace); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); + } + tevent_req_set_callback(subreq, cli_rename_done1, req); + return req; + } + + subreq = cli_cifs_rename_send( + state, ev, cli, fname_src,fname_dst, replace); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); + } + tevent_req_set_callback(subreq, cli_rename_done_cifs, req); + return req; +} + +static void cli_rename_done1(struct tevent_req *subreq) +{ + NTSTATUS status = cli_smb1_rename_recv(subreq); + tevent_req_simple_finish_ntstatus(subreq, status); +} + +static void cli_rename_done_cifs(struct tevent_req *subreq) +{ + NTSTATUS status = cli_cifs_rename_recv(subreq); + tevent_req_simple_finish_ntstatus(subreq, status); } NTSTATUS cli_rename_recv(struct tevent_req *req)