Make cli_mkdir async. Change it to return NTSTATUS.
authorJeremy Allison <jra@samba.org>
Tue, 21 Apr 2009 12:52:34 +0000 (05:52 -0700)
committerJeremy Allison <jra@samba.org>
Tue, 21 Apr 2009 12:52:34 +0000 (05:52 -0700)
Jeremy.

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

index fcb9b27f1fa571e590514fad543cb8029bd45bf5..d74de35bc5ad80315a33e7b8034e2ca3971288dd 100644 (file)
@@ -1389,7 +1389,7 @@ static bool do_mkdir(const char *name)
                return false;
        }
 
-       if (!cli_mkdir(targetcli, targetname)) {
+       if (!NT_STATUS_IS_OK(cli_mkdir(targetcli, targetname))) {
                d_printf("%s making remote directory %s\n",
                         cli_errstr(targetcli),name);
                return false;
index c9f3e87c4df2bd120f27afc878e0b9e7f2e5d66b..7512583e1938ce75d5d839f3836727f9b168ffc5 100644 (file)
@@ -555,7 +555,7 @@ static bool ensurepath(const char *fname)
                safe_strcat(partpath, p, strlen(fname) + 1);
 
                if (!cli_chkpath(cli, partpath)) {
-                       if (!cli_mkdir(cli, partpath)) {
+                       if (!NT_STATUS_IS_OK(cli_mkdir(cli, partpath))) {
                                SAFE_FREE(partpath);
                                SAFE_FREE(ffname);
                                DEBUG(0, ("Error mkdir %s\n", cli_errstr(cli)));
index fa6dafa1b0a690fc2cca2e97d12bb2efff867454..3ddbf6f3b9d2722cb758e09b869f2fe2ca9590fc 100644 (file)
@@ -2338,7 +2338,7 @@ bool cli_ntrename(struct cli_state *cli, const char *fname_src, const char *fnam
 bool cli_nt_hardlink(struct cli_state *cli, const char *fname_src, const char *fname_dst);
 bool cli_unlink_full(struct cli_state *cli, const char *fname, uint16 attrs);
 bool cli_unlink(struct cli_state *cli, const char *fname);
-bool cli_mkdir(struct cli_state *cli, const char *dname);
+NTSTATUS cli_mkdir(struct cli_state *cli, const char *dname);
 bool cli_rmdir(struct cli_state *cli, const char *dname);
 int cli_nt_delete_on_close(struct cli_state *cli, int fnum, bool flag);
 int cli_nt_create_full(struct cli_state *cli, const char *fname,
index 0a1168fd0fe3566d7e335a23d0e870016d52d905..5be18366b9d5464921ed207d64ef2740f3211cd4 100644 (file)
@@ -596,6 +596,7 @@ bool cli_unlink(struct cli_state *cli, const char *fname)
        return cli_unlink_full(cli, fname, aSYSTEM | aHIDDEN);
 }
 
+#if 0
 /****************************************************************************
  Create a directory.
 ****************************************************************************/
@@ -631,6 +632,115 @@ bool cli_mkdir(struct cli_state *cli, const char *dname)
 
        return True;
 }
+#endif
+
+/****************************************************************************
+ Create a directory.
+****************************************************************************/
+
+static void cli_mkdir_done(struct tevent_req *subreq);
+
+struct cli_mkdir_state {
+       int dummy;
+};
+
+struct tevent_req *cli_mkdir_send(TALLOC_CTX *mem_ctx,
+                                 struct event_context *ev,
+                                 struct cli_state *cli,
+                                 const char *dname)
+{
+       struct tevent_req *req = NULL, *subreq = NULL;
+       struct cli_mkdir_state *state = NULL;
+       uint8_t additional_flags = 0;
+       uint8_t *bytes = NULL;
+
+       req = tevent_req_create(mem_ctx, &state, struct cli_mkdir_state);
+       if (req == NULL) {
+               return NULL;
+       }
+
+       bytes = talloc_array(state, uint8_t, 1);
+       if (!bytes) {
+               return NULL;
+       }
+       bytes[0] = 4;
+       bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), dname,
+                                  strlen(dname)+1, NULL);
+
+       if (tevent_req_nomem(bytes, req)) {
+               return tevent_req_post(req, ev);
+       }
+
+       subreq = cli_smb_send(state, ev, cli, SMBmkdir, additional_flags,
+                                   0, NULL, talloc_get_size(bytes), bytes);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, cli_mkdir_done, req);
+       return req;
+}
+
+static void cli_mkdir_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_mkdir_recv(struct tevent_req *req)
+{
+       return tevent_req_simple_recv_ntstatus(req);
+}
+
+NTSTATUS cli_mkdir(struct cli_state *cli, const char *dname)
+{
+       TALLOC_CTX *frame = talloc_stackframe();
+       struct event_context *ev;
+       struct tevent_req *req;
+       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_mkdir_send(frame, ev, cli, dname);
+       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_mkdir_recv(req);
+
+ fail:
+       TALLOC_FREE(frame);
+       if (!NT_STATUS_IS_OK(status)) {
+               cli_set_error(cli, status);
+       }
+       return status;
+}
 
 /****************************************************************************
  Remove a directory.
index 219bbe64e120bf369174fcfe75ef6e170157de7f..5afc8e48b6249703496b84a53bea4b3c58bcab19 100644 (file)
@@ -1177,8 +1177,7 @@ SMBC_mkdir_ctx(SMBCCTX *context,
        }
        /*d_printf(">>>mkdir: resolved path as %s\n", targetpath);*/
 
-       if (!cli_mkdir(targetcli, targetpath)) {
-
+       if (!NT_STATUS_IS_OK(cli_mkdir(targetcli, targetpath))) {
                errno = SMBC_errno(context, targetcli);
                TALLOC_FREE(frame);
                return -1;
index 00457719a89113a57796ffcfff2ebb7ff724f3ca..525a1eb3c379074e108b8c8fb786a73df2a3ce40 100644 (file)
@@ -180,7 +180,7 @@ bool torture_mangle(int dummy)
        cli_unlink(cli, "\\mangle_test\\*");
        cli_rmdir(cli, "\\mangle_test");
 
-       if (!cli_mkdir(cli, "\\mangle_test")) {
+       if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\mangle_test"))) {
                printf("ERROR: Failed to make directory\n");
                return False;
        }
index 07945fccf1f9b5301c2bfaa588a8cafe150f2da4..0328cfe545ac90d8d3901fda540b5bf7ea868ead 100644 (file)
@@ -2625,7 +2625,7 @@ static bool run_trans2test(int dummy)
 
        /* check if the server updates the directory modification time
            when creating a new file */
-       if (!cli_mkdir(cli, dname)) {
+       if (!NT_STATUS_IS_OK(cli_mkdir(cli, dname))) {
                printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli));
                correct = False;
        }
@@ -4584,12 +4584,12 @@ bool torture_chkpath_test(int dummy)
        cli_unlink(cli, "\\chkpath.dir\\*");
        cli_rmdir(cli, "\\chkpath.dir");
 
-       if (!cli_mkdir(cli, "\\chkpath.dir")) {
+       if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\chkpath.dir"))) {
                printf("mkdir1 failed : %s\n", cli_errstr(cli));
                return False;
        }
 
-       if (!cli_mkdir(cli, "\\chkpath.dir\\dir2")) {
+       if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\chkpath.dir\\dir2"))) {
                printf("mkdir2 failed : %s\n", cli_errstr(cli));
                return False;
        }
@@ -4801,7 +4801,7 @@ static bool run_dirtest1(int dummy)
        for (i=0;i<1000;i++) {
                fstring fname;
                slprintf(fname, sizeof(fname), "\\LISTDIR\\d%d", i);
-               if (!cli_mkdir(cli, fname)) {
+               if (!NT_STATUS_IS_OK(cli_mkdir(cli, fname))) {
                        fprintf(stderr,"Failed to open %s\n", fname);
                        return False;
                }
@@ -5279,7 +5279,7 @@ static bool run_uid_regression_test(int dummy)
        cli->vuid = old_vuid;
 
        /* Try an operation. */
-       if (!cli_mkdir(cli, "\\uid_reg_test")) {
+       if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\uid_reg_test"))) {
                /* We expect bad uid. */
                if (!check_error(__LINE__, cli, ERRSRV, ERRbaduid,
                                NT_STATUS_NO_SUCH_USER)) {
index e36b0388c4ed42a1c1b80ff30a5d6ed13006ea9a..aaa763a2a3cb5bd9916decbe017be1aefb805bf6 100644 (file)
@@ -132,7 +132,7 @@ bool torture_casetable(int dummy)
 
        cli_unlink(cli, "\\utable\\*");
        cli_rmdir(cli, "\\utable");
-       if (!cli_mkdir(cli, "\\utable")) {
+       if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\utable"))) {
                printf("Failed to create utable directory!\n");
                return False;
        }
index 9721628f022b53dde3cd2d1a256a5bbb7d81dad0..477ddf7f26aca028b2293cb5728201c56a2aef1e 100644 (file)
@@ -406,7 +406,7 @@ NTSTATUS net_copy_file(struct net_context *c,
                DEBUGADD(3,("creating dir %s on the destination server\n",
                        dst_name));
 
-               if (!cli_mkdir(cli_share_dst, dst_name)) {
+               if (!NT_STATUS_IS_OK(cli_mkdir(cli_share_dst, dst_name))) {
                        DEBUG(0,("cannot create directory %s: %s\n",
                                dst_name, cli_errstr(cli_share_dst)));
                        nt_status = NT_STATUS_NO_SUCH_FILE;
@@ -555,7 +555,7 @@ static NTSTATUS check_arch_dir(struct cli_state *cli_share, const char *short_ar
        DEBUG(10,("creating print-driver dir for architecture: %s\n",
                short_archi));
 
-       if (!cli_mkdir(cli_share, dir)) {
+       if (!NT_STATUS_IS_OK(cli_mkdir(cli_share, dir))) {
                 DEBUG(1,("cannot create directory %s: %s\n",
                          dir, cli_errstr(cli_share)));
                 nt_status = NT_STATUS_NO_SUCH_FILE;