Make cli_nt_delete_on_close() async.
authorJeremy Allison <jra@samba.org>
Fri, 29 May 2009 21:58:34 +0000 (14:58 -0700)
committerJeremy Allison <jra@samba.org>
Fri, 29 May 2009 21:58:34 +0000 (14:58 -0700)
Jeremy.

source3/include/proto.h
source3/libsmb/clifile.c
source3/torture/torture.c

index a0ff361411a033d3010721f07aa44cfc0a1cec8a..81d254f1ffb1d32cb2f1f888295ecf8475893736 100644 (file)
@@ -2442,7 +2442,13 @@ struct tevent_req *cli_rmdir_send(TALLOC_CTX *mem_ctx,
                                  const char *dname);
 NTSTATUS cli_rmdir_recv(struct tevent_req *req);
 NTSTATUS cli_rmdir(struct cli_state *cli, const char *dname);
                                  const char *dname);
 NTSTATUS cli_rmdir_recv(struct tevent_req *req);
 NTSTATUS cli_rmdir(struct cli_state *cli, const char *dname);
-int cli_nt_delete_on_close(struct cli_state *cli, uint16_t fnum, bool flag);
+struct tevent_req *cli_nt_delete_on_close_send(TALLOC_CTX *mem_ctx,
+                                       struct event_context *ev,
+                                       struct cli_state *cli,
+                                       uint16_t fnum,
+                                       bool flag);
+NTSTATUS cli_nt_delete_on_close_recv(struct tevent_req *req);
+NTSTATUS cli_nt_delete_on_close(struct cli_state *cli, uint16_t fnum, bool flag);
 struct tevent_req *cli_ntcreate_send(TALLOC_CTX *mem_ctx,
                                     struct event_context *ev,
                                     struct cli_state *cli,
 struct tevent_req *cli_ntcreate_send(TALLOC_CTX *mem_ctx,
                                     struct event_context *ev,
                                     struct cli_state *cli,
index f73428ee214105bade7f0c6e880323bec0e70c7f..693d97626faff67546a0e91bb76085133717ab71 100644 (file)
@@ -1853,6 +1853,135 @@ NTSTATUS cli_rmdir(struct cli_state *cli, const char *dname)
  Set or clear the delete on close flag.
 ****************************************************************************/
 
  Set or clear the delete on close flag.
 ****************************************************************************/
 
+struct doc_state {
+       uint16_t setup;
+       uint8_t param[6];
+       uint8_t data[1];
+};
+
+static void cli_nt_delete_on_close_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+                               subreq, struct tevent_req);
+       struct doc_state *state = tevent_req_data(req, struct doc_state);
+       NTSTATUS status;
+
+       status = cli_trans_recv(subreq, state, NULL, NULL, NULL, NULL, NULL, NULL);
+       TALLOC_FREE(subreq);
+       if (!NT_STATUS_IS_OK(status)) {
+               tevent_req_nterror(req, status);
+               return;
+       }
+       tevent_req_done(req);
+}
+
+struct tevent_req *cli_nt_delete_on_close_send(TALLOC_CTX *mem_ctx,
+                                       struct event_context *ev,
+                                       struct cli_state *cli,
+                                       uint16_t fnum,
+                                       bool flag)
+{
+       struct tevent_req *req = NULL, *subreq = NULL;
+       struct doc_state *state = NULL;
+
+       req = tevent_req_create(mem_ctx, &state, struct doc_state);
+       if (req == NULL) {
+               return NULL;
+       }
+
+       /* Setup setup word. */
+       SSVAL(&state->setup, 0, TRANSACT2_SETFILEINFO);
+
+       /* Setup param array. */
+       memset(state->param, '\0', 6);
+       SSVAL(state->param,0,fnum);
+       SSVAL(state->param,2,SMB_SET_FILE_DISPOSITION_INFO);
+
+       /* Setup data array. */
+       SCVAL(&state->data[0], 0, flag ? 1 : 0);
+
+       subreq = cli_trans_send(state,                  /* mem ctx. */
+                               ev,                     /* event ctx. */
+                               cli,                    /* cli_state. */
+                               SMBtrans2,              /* cmd. */
+                               NULL,                   /* pipe name. */
+                               -1,                     /* fid. */
+                               0,                      /* function. */
+                               0,                      /* flags. */
+                               &state->setup,          /* setup. */
+                               1,                      /* num setup uint16_t words. */
+                               0,                      /* max returned setup. */
+                               state->param,           /* param. */
+                               6,                      /* num param. */
+                               2,                      /* max returned param. */
+                               state->data,            /* data. */
+                               1,                      /* num data. */
+                               0);                     /* max returned data. */
+
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, cli_nt_delete_on_close_done, req);
+       return req;
+}
+
+NTSTATUS cli_nt_delete_on_close_recv(struct tevent_req *req)
+{
+       NTSTATUS status;
+
+       if (tevent_req_is_nterror(req, &status)) {
+               return status;
+       }
+       return NT_STATUS_OK;
+}
+
+NTSTATUS cli_nt_delete_on_close(struct cli_state *cli, uint16_t fnum, bool flag)
+{
+       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_nt_delete_on_close_send(frame,
+                               ev,
+                               cli,
+                               fnum,
+                               flag);
+       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_nt_delete_on_close_recv(req);
+
+ fail:
+       TALLOC_FREE(frame);
+       if (!NT_STATUS_IS_OK(status)) {
+               cli_set_error(cli, status);
+       }
+       return status;
+}
+
+#if 0
 int cli_nt_delete_on_close(struct cli_state *cli, uint16_t fnum, bool flag)
 {
        unsigned int data_len = 1;
 int cli_nt_delete_on_close(struct cli_state *cli, uint16_t fnum, bool flag)
 {
        unsigned int data_len = 1;
@@ -1889,6 +2018,7 @@ int cli_nt_delete_on_close(struct cli_state *cli, uint16_t fnum, bool flag)
 
        return true;
 }
 
        return true;
 }
+#endif
 
 struct cli_ntcreate_state {
        uint16_t vwv[24];
 
 struct cli_ntcreate_state {
        uint16_t vwv[24];
index b05ca44f0e5292c6ecb2f6632c335cc29efbe2e4..cfd3d640f9f15a4d86ac79ef4d56a6c4699f4718 100644 (file)
@@ -3092,7 +3092,7 @@ static bool run_deletetest(int dummy)
                goto fail;
        }
 
                goto fail;
        }
 
-       if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
+       if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
                printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
                correct = False;
                goto fail;
                printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
                correct = False;
                goto fail;
@@ -3145,7 +3145,7 @@ static bool run_deletetest(int dummy)
                goto fail;
        }
 
                goto fail;
        }
 
-       if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
+       if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
                printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
                correct = False;
                goto fail;
                printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
                correct = False;
                goto fail;
@@ -3201,7 +3201,7 @@ static bool run_deletetest(int dummy)
                goto fail;
        }
 
                goto fail;
        }
 
-       if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
+       if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
                printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
                correct = False;
                goto fail;
                printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
                correct = False;
                goto fail;
@@ -3235,7 +3235,7 @@ static bool run_deletetest(int dummy)
 
        /* This should fail - only allowed on NT opens with DELETE access. */
 
 
        /* This should fail - only allowed on NT opens with DELETE access. */
 
-       if (cli_nt_delete_on_close(cli1, fnum1, True)) {
+       if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
                printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
                correct = False;
                goto fail;
                printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
                correct = False;
                goto fail;
@@ -3263,7 +3263,7 @@ static bool run_deletetest(int dummy)
 
        /* This should fail - only allowed on NT opens with DELETE access. */
 
 
        /* This should fail - only allowed on NT opens with DELETE access. */
 
-       if (cli_nt_delete_on_close(cli1, fnum1, True)) {
+       if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
                printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
                correct = False;
                goto fail;
                printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
                correct = False;
                goto fail;
@@ -3288,13 +3288,13 @@ static bool run_deletetest(int dummy)
                goto fail;
        }
 
                goto fail;
        }
 
-       if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
+       if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
                printf("[7] setting delete_on_close on file failed !\n");
                correct = False;
                goto fail;
        }
 
                printf("[7] setting delete_on_close on file failed !\n");
                correct = False;
                goto fail;
        }
 
-       if (!cli_nt_delete_on_close(cli1, fnum1, False)) {
+       if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, false))) {
                printf("[7] unsetting delete_on_close on file failed !\n");
                correct = False;
                goto fail;
                printf("[7] unsetting delete_on_close on file failed !\n");
                correct = False;
                goto fail;
@@ -3350,7 +3350,7 @@ static bool run_deletetest(int dummy)
                goto fail;
        }
 
                goto fail;
        }
 
-       if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
+       if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
                printf("[8] setting delete_on_close on file failed !\n");
                correct = False;
                goto fail;
                printf("[8] setting delete_on_close on file failed !\n");
                correct = False;
                goto fail;
@@ -3639,7 +3639,7 @@ static bool run_rename(int dummy)
                printf("Fourth open failed - %s\n", cli_errstr(cli1));
                return False;
        }
                printf("Fourth open failed - %s\n", cli_errstr(cli1));
                return False;
        }
-       if (!cli_nt_delete_on_close(cli1, fnum2, True)) {
+       if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum2, true))) {
                printf("[8] setting delete_on_close on file failed !\n");
                return False;
        }
                printf("[8] setting delete_on_close on file failed !\n");
                return False;
        }