diff options
Diffstat (limited to 'source3')
-rw-r--r-- | source3/client/client.c | 6 | ||||
-rw-r--r-- | source3/client/clitar.c | 2 | ||||
-rw-r--r-- | source3/include/proto.h | 2 | ||||
-rw-r--r-- | source3/libsmb/clifile.c | 121 | ||||
-rw-r--r-- | source3/torture/torture.c | 10 | ||||
-rw-r--r-- | source3/utils/net_rpc_printer.c | 6 |
6 files changed, 134 insertions, 13 deletions
diff --git a/source3/client/client.c b/source3/client/client.c index 54ff755ed3..151f7460fc 100644 --- a/source3/client/client.c +++ b/source3/client/client.c @@ -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 */ diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 7512583e19..fd375769e4 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -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); diff --git a/source3/include/proto.h b/source3/include/proto.h index 82a16598ec..1435f4f405 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -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); diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c index 1a1153d546..c98346e3b3 100644 --- a/source3/libsmb/clifile.c +++ b/source3/libsmb/clifile.c @@ -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. diff --git a/source3/torture/torture.c b/source3/torture/torture.c index b0cf33ecaf..c6efa803fa 100644 --- a/source3/torture/torture.c +++ b/source3/torture/torture.c @@ -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 { diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 477ddf7f26..ea613e7886 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -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; |