Make cli_setatr async.
authorJeremy Allison <jra@samba.org>
Wed, 6 May 2009 23:13:42 +0000 (16:13 -0700)
committerJeremy Allison <jra@samba.org>
Wed, 6 May 2009 23:13:42 +0000 (16:13 -0700)
Jeremy.

source3/client/clitar.c
source3/include/proto.h
source3/libsmb/clifile.c
source3/libsmb/libsmb_dir.c
source3/libsmb/libsmb_file.c
source3/torture/torture.c
source3/utils/net_rpc_printer.c

index 80f6c81880a18c5c5caad4334698ef5f3c40bbf8..ff719245551119fb246319eb089d70236ec14d10 100644 (file)
@@ -604,7 +604,7 @@ static void do_setrattr(char *name, uint16 attr, int set)
                attr = oldattr & ~attr;
        }
 
-       if (!cli_setatr(cli, name, attr, 0)) {
+       if (!NT_STATUS_IS_OK(cli_setatr(cli, name, attr, 0))) {
                DEBUG(1,("setatr failed: %s\n", cli_errstr(cli)));
        }
 }
@@ -1078,7 +1078,7 @@ static int get_file(file_info2 finfo)
        /* Now we update the creation date ... */
        DEBUG(5, ("Updating creation date on %s\n", finfo.name));
 
-       if (!cli_setatr(cli, finfo.name, finfo.mode, finfo.mtime_ts.tv_sec)) {
+       if (!NT_STATUS_IS_OK(cli_setatr(cli, finfo.name, finfo.mode, finfo.mtime_ts.tv_sec))) {
                if (tar_real_noisy) {
                        DEBUG(0, ("Could not set time on file: %s\n", finfo.name));
                        /*return(False); */ /* Ignore, as Win95 does not allow changes */
index 9a8b6a8fc9b3ba00e33f070a00ddb590668d50e3..c8b79278ea62959f6ce4c50393c123d5e4988d8e 100644 (file)
@@ -2486,7 +2486,17 @@ NTSTATUS cli_getatr(struct cli_state *cli,
                        uint16_t *attr,
                        SMB_OFF_T *size,
                        time_t *write_time);
-bool cli_setatr(struct cli_state *cli, const char *fname, uint16_t attr, time_t t);
+struct tevent_req *cli_setatr_send(TALLOC_CTX *mem_ctx,
+                               struct event_context *ev,
+                               struct cli_state *cli,
+                               const char *fname,
+                               uint16_t attr,
+                               time_t mtime);
+NTSTATUS cli_setatr_recv(struct tevent_req *req);
+NTSTATUS cli_setatr(struct cli_state *cli,
+                const char *fname,
+                uint16_t attr,
+                time_t mtime);
 struct tevent_req *cli_chkpath_send(TALLOC_CTX *mem_ctx,
                                  struct event_context *ev,
                                  struct cli_state *cli,
index 7983516f87e44d360ca3349c525d7bd7e94a254b..e210d76b28a5665091980e6854b56a7f527fbd40 100644 (file)
@@ -2506,6 +2506,132 @@ NTSTATUS cli_setattrE(struct cli_state *cli,
  Do a SMBsetatr call.
 ****************************************************************************/
 
+static void cli_setatr_done(struct tevent_req *subreq);
+
+struct cli_setatr_state {
+       int dummy;
+};
+
+struct tevent_req *cli_setatr_send(TALLOC_CTX *mem_ctx,
+                               struct event_context *ev,
+                               struct cli_state *cli,
+                               const char *fname,
+                               uint16_t attr,
+                               time_t mtime)
+{
+       struct tevent_req *req = NULL, *subreq = NULL;
+       struct cli_setatr_state *state = NULL;
+       uint8_t additional_flags = 0;
+       uint16_t vwv[8];
+       uint8_t *bytes = NULL;
+
+       req = tevent_req_create(mem_ctx, &state, struct cli_setatr_state);
+       if (req == NULL) {
+               return NULL;
+       }
+
+       memset(vwv, '\0', sizeof(vwv));
+       SSVAL(vwv+0, 0, attr);
+       cli_put_dos_date3(cli, (char *)&vwv[1], 0, mtime);
+
+       bytes = talloc_array(state, uint8_t, 1);
+       if (tevent_req_nomem(bytes, req)) {
+               return tevent_req_post(req, ev);
+       }
+       bytes[0] = 4;
+       bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), fname,
+                                  strlen(fname)+1, NULL);
+       if (tevent_req_nomem(bytes, req)) {
+               return tevent_req_post(req, ev);
+       }
+       bytes = TALLOC_REALLOC_ARRAY(state, bytes, uint8_t,
+                       talloc_get_size(bytes)+1);
+       if (tevent_req_nomem(bytes, req)) {
+               return tevent_req_post(req, ev);
+       }
+
+       bytes[talloc_get_size(bytes)-1] = 4;
+       bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), "",
+                                  1, NULL);
+       if (tevent_req_nomem(bytes, req)) {
+               return tevent_req_post(req, ev);
+       }
+
+       subreq = cli_smb_send(state, ev, cli, SMBsetatr, additional_flags,
+                             8, vwv, talloc_get_size(bytes), bytes);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, cli_setatr_done, req);
+       return req;
+}
+
+static void cli_setatr_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       NTSTATUS status;
+
+       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);
+}
+
+NTSTATUS cli_setatr_recv(struct tevent_req *req)
+{
+       return tevent_req_simple_recv_ntstatus(req);
+}
+
+NTSTATUS cli_setatr(struct cli_state *cli,
+               const char *fname,
+               uint16_t attr,
+               time_t mtime)
+{
+       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;
+       }
+
+       ev = event_context_init(frame);
+       if (ev == NULL) {
+               status = NT_STATUS_NO_MEMORY;
+               goto fail;
+       }
+
+       req = cli_setatr_send(frame, ev, cli, fname, attr, mtime);
+       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_setatr_recv(req);
+
+ fail:
+       TALLOC_FREE(frame);
+       if (!NT_STATUS_IS_OK(status)) {
+               cli_set_error(cli, status);
+       }
+       return status;
+}
+
+#if 0
 bool cli_setatr(struct cli_state *cli, const char *fname, uint16_t attr, time_t t)
 {
        char *p;
@@ -2541,6 +2667,7 @@ bool cli_setatr(struct cli_state *cli, const char *fname, uint16_t attr, time_t
 
        return True;
 }
+#endif
 
 /****************************************************************************
  Check for existance of a dir.
index d230275685df12f9742d73e0ddfa8d8e5109c998..a3f63f204d2fa652df80080351079d365a49aefc 100644 (file)
@@ -1573,7 +1573,7 @@ SMBC_chmod_ctx(SMBCCTX *context,
        if ((newmode & S_IXGRP) && lp_map_system(-1)) mode |= aSYSTEM;
        if ((newmode & S_IXOTH) && lp_map_hidden(-1)) mode |= aHIDDEN;
 
-       if (!cli_setatr(targetcli, targetpath, mode, 0)) {
+       if (!NT_STATUS_IS_OK(cli_setatr(targetcli, targetpath, mode, 0))) {
                errno = SMBC_errno(context, targetcli);
                TALLOC_FREE(frame);
                return -1;
index 1bb12123a59b936756b9a4c64f3595d78329c568..abfec172e4f11643f41859cedd93e96201435f94 100644 (file)
@@ -684,7 +684,7 @@ SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
                  * seems to work on win98.
                  */
                 if (ret && mode != (uint16) -1) {
-                        ret = cli_setatr(srv->cli, path, mode, 0);
+                        ret = NT_STATUS_IS_OK(cli_setatr(srv->cli, path, mode, 0));
                 }
                 
                 if (! ret) {
index bc7ac12a76f98ff9f3deaaf50953ad30553e015c..9c0449a16ed2c3f584801f702ebf4556282b09a4 100644 (file)
@@ -2485,7 +2485,7 @@ static bool run_attrtest(int dummy)
 
        t2 = t-60*60*24; /* 1 day ago */
 
-       if (!cli_setatr(cli, fname, 0, t2)) {
+       if (!NT_STATUS_IS_OK(cli_setatr(cli, fname, 0, t2))) {
                printf("setatr failed (%s)\n", cli_errstr(cli));
                correct = True;
        }
@@ -3726,7 +3726,7 @@ static bool run_opentest(int dummy)
                return False;
        }
 
-       if (!cli_setatr(cli1, fname, aRONLY, 0)) {
+       if (!NT_STATUS_IS_OK(cli_setatr(cli1, fname, aRONLY, 0))) {
                printf("cli_setatr failed (%s)\n", cli_errstr(cli1));
                return False;
        }
index b01c5af1dd74859f42bd20d127793ebd7e216749..3914a42aded14dc06b9c25cd846f788f21119ccb 100644 (file)
@@ -243,7 +243,7 @@ NTSTATUS net_copy_fileattr(struct net_context *c,
        if (copy_attrs) {
 
                /* set attrs */
-               if (!cli_setatr(cli_share_dst, dst_name, attr, 0)) {
+               if (!NT_STATUS_IS_OK(cli_setatr(cli_share_dst, dst_name, attr, 0))) {
                        DEBUG(0,("failed to set file-attrs: %s\n",
                                cli_errstr(cli_share_dst)));
                        nt_status = cli_nt_error(cli_share_dst);