Make cli_setattrE async.
authorJeremy Allison <jra@samba.org>
Wed, 6 May 2009 22:07:05 +0000 (15:07 -0700)
committerJeremy Allison <jra@samba.org>
Wed, 6 May 2009 22:07:05 +0000 (15:07 -0700)
Jeremy.

source3/include/proto.h
source3/libsmb/clifile.c
source3/libsmb/libsmb_file.c
source3/utils/net_rpc_printer.c

index 6b1febb16089f2624126d4b147642d168d0b34b1..9a8b6a8fc9b3ba00e33f070a00ddb590668d50e3 100644 (file)
@@ -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,
index 357923abcbc3a5c5733e88143dc4901a15138a66..7983516f87e44d360ca3349c525d7bd7e94a254b 100644 (file)
@@ -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;
 }
 
 /****************************************************************************
index 63590d2fdf1688ab66d8ad0523f6b68611ec439d..1bb12123a59b936756b9a4c64f3595d78329c568 100644 (file)
@@ -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);
index 10fd4157b7a885bbe09c38e145c306005735f56e..b01c5af1dd74859f42bd20d127793ebd7e216749 100644 (file)
@@ -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);