diff options
author | Jeremy Allison <jra@samba.org> | 2009-05-06 15:07:05 -0700 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2009-05-06 15:07:05 -0700 |
commit | 512879a69b6e94c323c37a6c0e56824c097b7f70 (patch) | |
tree | 4673c7f00ae7cb4675f4355b4ed3fbe11145b977 /source3 | |
parent | 78754ab2c9b28ea8ab09d3fd1f5450abe721a2c1 (diff) | |
download | samba-512879a69b6e94c323c37a6c0e56824c097b7f70.tar.gz samba-512879a69b6e94c323c37a6c0e56824c097b7f70.tar.bz2 samba-512879a69b6e94c323c37a6c0e56824c097b7f70.zip |
Make cli_setattrE async.
Jeremy.
Diffstat (limited to 'source3')
-rw-r--r-- | source3/include/proto.h | 17 | ||||
-rw-r--r-- | source3/libsmb/clifile.c | 120 | ||||
-rw-r--r-- | source3/libsmb/libsmb_file.c | 4 | ||||
-rw-r--r-- | source3/utils/net_rpc_printer.c | 2 |
4 files changed, 112 insertions, 31 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h index 6b1febb160..9a8b6a8fc9 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -2460,10 +2460,19 @@ NTSTATUS cli_getattrE(struct cli_state *cli, time_t *change_time, time_t *access_time, time_t *write_time); -bool cli_setattrE(struct cli_state *cli, int fd, - time_t change_time, - time_t access_time, - time_t write_time); +struct tevent_req *cli_setattrE_send(TALLOC_CTX *mem_ctx, + struct event_context *ev, + struct cli_state *cli, + uint16_t fnum, + time_t change_time, + time_t access_time, + time_t write_time); +NTSTATUS cli_setattrE_recv(struct tevent_req *req); +NTSTATUS cli_setattrE(struct cli_state *cli, + uint16_t fnum, + time_t change_time, + time_t access_time, + time_t write_time); struct tevent_req *cli_getatr_send(TALLOC_CTX *mem_ctx, struct event_context *ev, struct cli_state *cli, diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c index 357923abcb..7983516f87 100644 --- a/source3/libsmb/clifile.c +++ b/source3/libsmb/clifile.c @@ -2391,43 +2391,115 @@ NTSTATUS cli_getatr(struct cli_state *cli, Do a SMBsetattrE call. ****************************************************************************/ -bool cli_setattrE(struct cli_state *cli, int fd, - time_t change_time, - time_t access_time, - time_t write_time) +static void cli_setattrE_done(struct tevent_req *subreq); +struct cli_setattrE_state { + int dummy; +}; + +struct tevent_req *cli_setattrE_send(TALLOC_CTX *mem_ctx, + struct event_context *ev, + struct cli_state *cli, + uint16_t fnum, + time_t change_time, + time_t access_time, + time_t write_time) { - char *p; + struct tevent_req *req = NULL, *subreq = NULL; + struct cli_setattrE_state *state = NULL; + uint8_t additional_flags = 0; + uint16_t vwv[7]; - memset(cli->outbuf,'\0',smb_size); - memset(cli->inbuf,'\0',smb_size); + req = tevent_req_create(mem_ctx, &state, struct cli_setattrE_state); + if (req == NULL) { + return NULL; + } - cli_set_message(cli->outbuf,7,0,True); + memset(vwv, '\0', sizeof(vwv)); + SSVAL(vwv+0, 0, fnum); + cli_put_dos_date2(cli, (char *)&vwv[1], 0, change_time); + cli_put_dos_date2(cli, (char *)&vwv[3], 0, access_time); + cli_put_dos_date2(cli, (char *)&vwv[5], 0, write_time); - SCVAL(cli->outbuf,smb_com,SMBsetattrE); - SSVAL(cli->outbuf,smb_tid,cli->cnum); - cli_setup_packet(cli); + subreq = cli_smb_send(state, ev, cli, SMBsetattrE, additional_flags, + 7, vwv, 0, NULL); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); + } + tevent_req_set_callback(subreq, cli_setattrE_done, req); + return req; +} - SSVAL(cli->outbuf,smb_vwv0, fd); - cli_put_dos_date2(cli, cli->outbuf,smb_vwv1, change_time); - cli_put_dos_date2(cli, cli->outbuf,smb_vwv3, access_time); - cli_put_dos_date2(cli, cli->outbuf,smb_vwv5, write_time); +static void cli_setattrE_done(struct tevent_req *subreq) +{ + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + NTSTATUS status; - p = smb_buf(cli->outbuf); - *p++ = 4; + status = cli_smb_recv(subreq, 0, NULL, NULL, NULL, NULL); + TALLOC_FREE(subreq); + if (!NT_STATUS_IS_OK(status)) { + tevent_req_nterror(req, status); + return; + } + tevent_req_done(req); +} - cli_setup_bcc(cli, p); +NTSTATUS cli_setattrE_recv(struct tevent_req *req) +{ + return tevent_req_simple_recv_ntstatus(req); +} - cli_send_smb(cli); - if (!cli_receive_smb(cli)) { - return False; +NTSTATUS cli_setattrE(struct cli_state *cli, + uint16_t fnum, + time_t change_time, + time_t access_time, + time_t write_time) +{ + TALLOC_CTX *frame = talloc_stackframe(); + struct event_context *ev = NULL; + struct tevent_req *req = NULL; + NTSTATUS status = NT_STATUS_OK; + + if (cli_has_async_calls(cli)) { + /* + * Can't use sync call while an async call is in flight + */ + status = NT_STATUS_INVALID_PARAMETER; + goto fail; } - if (cli_is_error(cli)) { - return False; + ev = event_context_init(frame); + if (ev == NULL) { + status = NT_STATUS_NO_MEMORY; + goto fail; } - return True; + req = cli_setattrE_send(frame, ev, + cli, + fnum, + change_time, + access_time, + write_time); + + if (req == NULL) { + status = NT_STATUS_NO_MEMORY; + goto fail; + } + + if (!tevent_req_poll(req, ev)) { + status = map_nt_error_from_unix(errno); + goto fail; + } + + status = cli_setattrE_recv(req); + + fail: + TALLOC_FREE(frame); + if (!NT_STATUS_IS_OK(status)) { + cli_set_error(cli, status); + } + return status; } /**************************************************************************** diff --git a/source3/libsmb/libsmb_file.c b/source3/libsmb/libsmb_file.c index 63590d2fdf..1bb12123a5 100644 --- a/source3/libsmb/libsmb_file.c +++ b/source3/libsmb/libsmb_file.c @@ -669,10 +669,10 @@ SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path, } /* Set the new attributes */ - ret = cli_setattrE(srv->cli, fd, + ret = NT_STATUS_IS_OK(cli_setattrE(srv->cli, fd, change_time, access_time, - write_time); + write_time)); /* Close the file */ cli_close(srv->cli, fd); diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 10fd4157b7..b01c5af1dd 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -221,7 +221,7 @@ NTSTATUS net_copy_fileattr(struct net_context *c, if (copy_timestamps) { /* set timestamps */ - if (!cli_setattrE(cli_share_dst, fnum_dst, f_ctime, f_atime, f_mtime)) { + if (!NT_STATUS_IS_OK(cli_setattrE(cli_share_dst, fnum_dst, f_ctime, f_atime, f_mtime))) { DEBUG(0,("failed to set file-attrs (timestamps): %s\n", cli_errstr(cli_share_dst))); nt_status = cli_nt_error(cli_share_dst); |