Make cli_chkpath async.
authorJeremy Allison <jra@samba.org>
Wed, 22 Apr 2009 13:46:42 +0000 (06:46 -0700)
committerJeremy Allison <jra@samba.org>
Wed, 22 Apr 2009 13:46:42 +0000 (06:46 -0700)
Jeremy

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

index 54ff755ed32b5eb054c560a7e18f20db7a65ef2b..151f7460fcc50c0e74a487c4bd75dc7a37c7d9ee 100644 (file)
@@ -437,7 +437,7 @@ static int do_cd(const char *new_dir)
                        goto out;
                }
 
-               if (!cli_chkpath(targetcli, targetpath)) {
+               if (!NT_STATUS_IS_OK(cli_chkpath(targetcli, targetpath))) {
                        d_printf("cd %s: %s\n", new_cd, cli_errstr(targetcli));
                        client_set_cur_dir(saved_dir);
                        goto out;
@@ -1482,7 +1482,7 @@ static int cmd_mkdir(void)
                        if (!ddir2) {
                                return 1;
                        }
-                       if (!cli_chkpath(targetcli, ddir2)) {
+                       if (!NT_STATUS_IS_OK(cli_chkpath(targetcli, ddir2))) {
                                do_mkdir(ddir2);
                        }
                        ddir2 = talloc_asprintf_append(ddir2, "%s", CLI_DIRSEP_STR);
@@ -1956,7 +1956,7 @@ static int cmd_mput(void)
                                                break;
                                        }
                                        normalize_name(rname);
-                                       if (!cli_chkpath(cli, rname) &&
+                                       if (!NT_STATUS_IS_OK(cli_chkpath(cli, rname)) &&
                                            !do_mkdir(rname)) {
                                                DEBUG (0, ("Unable to make dir, skipping..."));
                                                /* Skip the directory */
index 7512583e1938ce75d5d839f3836727f9b168ffc5..fd375769e49dc1f6c60fb222538ecb7f60232cc0 100644 (file)
@@ -554,7 +554,7 @@ static bool ensurepath(const char *fname)
        while (p) {
                safe_strcat(partpath, p, strlen(fname) + 1);
 
-               if (!cli_chkpath(cli, partpath)) {
+               if (!NT_STATUS_IS_OK(cli_chkpath(cli, partpath))) {
                        if (!NT_STATUS_IS_OK(cli_mkdir(cli, partpath))) {
                                SAFE_FREE(partpath);
                                SAFE_FREE(ffname);
index 82a16598ecd2edfbad6a96dee54ab4f20174ef6f..1435f4f4051ee1223c08f92fff23834efdd40c1d 100644 (file)
@@ -2416,7 +2416,7 @@ bool cli_setattrE(struct cli_state *cli, int fd,
                   time_t access_time,
                   time_t write_time);
 bool cli_setatr(struct cli_state *cli, const char *fname, uint16 attr, time_t t);
-bool cli_chkpath(struct cli_state *cli, const char *path);
+NTSTATUS cli_chkpath(struct cli_state *cli, const char *path);
 bool cli_dskattr(struct cli_state *cli, int *bsize, int *total, int *avail);
 int cli_ctemp(struct cli_state *cli, const char *path, char **tmp_path);
 NTSTATUS cli_raw_ioctl(struct cli_state *cli, int fnum, uint32 code, DATA_BLOB *blob);
index 1a1153d5467556600bf94e49e22c7e5a888c54ce..c98346e3b30ea96675dbbb395d2cee2e3fbdf2cb 100644 (file)
@@ -2044,6 +2044,126 @@ bool cli_setatr(struct cli_state *cli, const char *fname, uint16 attr, time_t t)
  Check for existance of a dir.
 ****************************************************************************/
 
+static void cli_chkpath_done(struct tevent_req *subreq);
+
+struct cli_chkpath_state {
+       int dummy;
+};
+
+struct tevent_req *cli_chkpath_send(TALLOC_CTX *mem_ctx,
+                                 struct event_context *ev,
+                                 struct cli_state *cli,
+                                 const char *fname)
+{
+       struct tevent_req *req = NULL, *subreq = NULL;
+       struct cli_chkpath_state *state = NULL;
+       uint8_t additional_flags = 0;
+       uint8_t *bytes = NULL;
+
+       req = tevent_req_create(mem_ctx, &state, struct cli_chkpath_state);
+       if (req == NULL) {
+               return NULL;
+       }
+
+       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);
+       }
+
+       subreq = cli_smb_send(state, ev, cli, SMBcheckpath, 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_chkpath_done, req);
+       return req;
+}
+
+static void cli_chkpath_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_chkpath_recv(struct tevent_req *req)
+{
+       return tevent_req_simple_recv_ntstatus(req);
+}
+
+NTSTATUS cli_chkpath(struct cli_state *cli, const char *path)
+{
+       TALLOC_CTX *frame = talloc_stackframe();
+       struct event_context *ev = NULL;
+       struct tevent_req *req = NULL;
+       char *path2 = 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;
+       }
+
+       path2 = talloc_strdup(frame, path);
+       if (!path2) {
+               status = NT_STATUS_NO_MEMORY;
+               goto fail;
+       }
+       trim_char(path2,'\0','\\');
+       if (!*path2) {
+               path2 = talloc_strdup(frame, "\\");
+               if (!path2) {
+                       status = NT_STATUS_NO_MEMORY;
+                       goto fail;
+               }
+       }
+
+       ev = event_context_init(frame);
+       if (ev == NULL) {
+               status = NT_STATUS_NO_MEMORY;
+               goto fail;
+       }
+
+       req = cli_chkpath_send(frame, ev, cli, path2);
+       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_chkpath_recv(req);
+
+ fail:
+       TALLOC_FREE(frame);
+       if (!NT_STATUS_IS_OK(status)) {
+               cli_set_error(cli, status);
+       }
+       return status;
+}
+
+#if 0
 bool cli_chkpath(struct cli_state *cli, const char *path)
 {
        char *path2 = NULL;
@@ -2088,6 +2208,7 @@ bool cli_chkpath(struct cli_state *cli, const char *path)
 
        return True;
 }
+#endif
 
 /****************************************************************************
  Query disk space.
index b0cf33ecafe297151d6389a7f55d1cd0978fc416..c6efa803fa8d77d6606693c67dbc7f68992ac139 100644 (file)
@@ -4601,17 +4601,17 @@ bool torture_chkpath_test(int dummy)
        }
        cli_close(cli, fnum);
 
-       if (!cli_chkpath(cli, "\\chkpath.dir")) {
+       if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir"))) {
                printf("chkpath1 failed: %s\n", cli_errstr(cli));
                ret = False;
        }
 
-       if (!cli_chkpath(cli, "\\chkpath.dir\\dir2")) {
+       if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\dir2"))) {
                printf("chkpath2 failed: %s\n", cli_errstr(cli));
                ret = False;
        }
 
-       if (!cli_chkpath(cli, "\\chkpath.dir\\foo.txt")) {
+       if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\foo.txt"))) {
                ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath, 
                                  NT_STATUS_NOT_A_DIRECTORY);
        } else {
@@ -4619,7 +4619,7 @@ bool torture_chkpath_test(int dummy)
                ret = False;
        }
 
-       if (!cli_chkpath(cli, "\\chkpath.dir\\bar.txt")) {
+       if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\bar.txt"))) {
                ret = check_error(__LINE__, cli, ERRDOS, ERRbadfile, 
                                  NT_STATUS_OBJECT_NAME_NOT_FOUND);
        } else {
@@ -4627,7 +4627,7 @@ bool torture_chkpath_test(int dummy)
                ret = False;
        }
 
-       if (!cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt")) {
+       if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt"))) {
                ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath, 
                                  NT_STATUS_OBJECT_PATH_NOT_FOUND);
        } else {
index 477ddf7f26aca028b2293cb5728201c56a2aef1e..ea613e7886c146f875763d494074c898384f3476 100644 (file)
@@ -400,7 +400,7 @@ NTSTATUS net_copy_file(struct net_context *c,
        }
 
 
-       if (!is_file && !cli_chkpath(cli_share_dst, dst_name)) {
+       if (!is_file && !NT_STATUS_IS_OK(cli_chkpath(cli_share_dst, dst_name))) {
 
                /* creating dir */
                DEBUGADD(3,("creating dir %s on the destination server\n",
@@ -412,7 +412,7 @@ NTSTATUS net_copy_file(struct net_context *c,
                        nt_status = NT_STATUS_NO_SUCH_FILE;
                }
 
-               if (!cli_chkpath(cli_share_dst, dst_name)) {
+               if (!NT_STATUS_IS_OK(cli_chkpath(cli_share_dst, dst_name))) {
                        d_fprintf(stderr, "cannot check for directory %s: %s\n",
                                dst_name, cli_errstr(cli_share_dst));
                        goto out;
@@ -561,7 +561,7 @@ static NTSTATUS check_arch_dir(struct cli_state *cli_share, const char *short_ar
                 nt_status = NT_STATUS_NO_SUCH_FILE;
         }
 
-       if (!cli_chkpath(cli_share, dir)) {
+       if (!NT_STATUS_IS_OK(cli_chkpath(cli_share, dir))) {
                d_fprintf(stderr, "cannot check %s: %s\n",
                        dir, cli_errstr(cli_share));
                goto out;