From 14ff2e8de9bd8d0064762234555260f5eea643fe Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 29 Oct 2010 11:56:51 -0700 Subject: Fix bug #7700 - Improvement of return code of smbclient Based on an initial patch from H Hasegawa . Convert cli_list and associated functions to take calls that return NTSTATUS. Jeremy. Autobuild-User: Jeremy Allison Autobuild-Date: Fri Oct 29 19:40:16 UTC 2010 on sn-devel-104 --- source3/torture/masktest.c | 13 +++++++++---- source3/torture/nbio.c | 18 +++++++++++++----- source3/torture/torture.c | 26 ++++++++++++++++++-------- 3 files changed, 40 insertions(+), 17 deletions(-) (limited to 'source3/torture') diff --git a/source3/torture/masktest.c b/source3/torture/masktest.c index 51de6d9505..82aa6bff36 100644 --- a/source3/torture/masktest.c +++ b/source3/torture/masktest.c @@ -269,7 +269,7 @@ struct rn_state { char *short_name; }; -static void listfn(const char *mnt, struct file_info *f, const char *s, +static NTSTATUS listfn(const char *mnt, struct file_info *f, const char *s, void *private_data) { struct rn_state *state = (struct rn_state *)private_data; @@ -281,17 +281,22 @@ static void listfn(const char *mnt, struct file_info *f, const char *s, resultp[2] = '+'; } - if ((state == NULL) || ISDOT(f->name) || ISDOTDOT(f->name)) { - return; + if (state == NULL) { + return NT_STATUS_INTERNAL_ERROR; + } + + if (ISDOT(f->name) || ISDOTDOT(f->name)) { + return NT_STATUS_OK; } fstrcpy(state->short_name, f->short_name); strlower_m(state->short_name); *state->pp_long_name = SMB_STRDUP(f->name); if (!*state->pp_long_name) { - return; + return NT_STATUS_NO_MEMORY; } strlower_m(*state->pp_long_name); + return NT_STATUS_OK; } static void get_real_name(struct cli_state *cli, diff --git a/source3/torture/nbio.c b/source3/torture/nbio.c index 1e72a6f7e4..f4625ab632 100644 --- a/source3/torture/nbio.c +++ b/source3/torture/nbio.c @@ -264,10 +264,11 @@ void nb_qfsinfo(int level) cli_dskattr(c, &bsize, &total, &avail); } -static void find_fn(const char *mnt, struct file_info *finfo, const char *name, +static NTSTATUS find_fn(const char *mnt, struct file_info *finfo, const char *name, void *state) { /* noop */ + return NT_STATUS_OK; } void nb_findfirst(const char *mask) @@ -284,9 +285,10 @@ void nb_flush(int fnum) static int total_deleted; -static void delete_fn(const char *mnt, struct file_info *finfo, +static NTSTATUS delete_fn(const char *mnt, struct file_info *finfo, const char *name, void *state) { + NTSTATUS status; char *s, *n; if (finfo->name[0] == '.') return; @@ -294,15 +296,20 @@ static void delete_fn(const char *mnt, struct file_info *finfo, n[strlen(n)-1] = 0; if (asprintf(&s, "%s%s", n, finfo->name) == -1) { printf("asprintf failed\n"); - return; + return NT_STATUS_NO_MEMORY; } if (finfo->mode & aDIR) { char *s2; if (asprintf(&s2, "%s\\*", s) == -1) { printf("asprintf failed\n"); - return; + return NT_STATUS_NO_MEMORY; + } + status = cli_list(c, s2, aDIR, delete_fn, NULL); + if (!NT_STATUS_IS_OK(status)) { + free(n); + free(s2); + return status; } - cli_list(c, s2, aDIR, delete_fn, NULL); nb_rmdir(s); } else { total_deleted++; @@ -310,6 +317,7 @@ static void delete_fn(const char *mnt, struct file_info *finfo, } free(s); free(n); + return NT_STATUS_OK; } void nb_deltree(const char *dname) diff --git a/source3/torture/torture.c b/source3/torture/torture.c index c416a161e0..57db3d47b7 100644 --- a/source3/torture/torture.c +++ b/source3/torture/torture.c @@ -4923,13 +4923,14 @@ static bool run_openattrtest(int dummy) return correct; } -static void list_fn(const char *mnt, struct file_info *finfo, +static NTSTATUS list_fn(const char *mnt, struct file_info *finfo, const char *name, void *state) { int *matched = (int *)state; if (matched != NULL) { *matched += 1; } + return NT_STATUS_OK; } /* @@ -4995,7 +4996,7 @@ static bool run_dirtest(int dummy) return correct; } -static void del_fn(const char *mnt, struct file_info *finfo, const char *mask, +static NTSTATUS del_fn(const char *mnt, struct file_info *finfo, const char *mask, void *state) { struct cli_state *pcli = (struct cli_state *)state; @@ -5003,7 +5004,7 @@ static void del_fn(const char *mnt, struct file_info *finfo, const char *mask, slprintf(fname, sizeof(fname), "\\LISTDIR\\%s", finfo->name); if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0) - return; + return NT_STATUS_OK; if (finfo->mode & aDIR) { if (!NT_STATUS_IS_OK(cli_rmdir(pcli, fname))) @@ -5012,6 +5013,7 @@ static void del_fn(const char *mnt, struct file_info *finfo, const char *mask, if (!NT_STATUS_IS_OK(cli_unlink(pcli, fname, aSYSTEM | aHIDDEN))) printf("del_fn: failed to unlink %s\n,", fname ); } + return NT_STATUS_OK; } @@ -6312,23 +6314,30 @@ static bool run_uid_regression_test(int dummy) static const char *illegal_chars = "*\\/?<>|\":"; static char force_shortname_chars[] = " +,.[];=\177"; -static void shortname_del_fn(const char *mnt, struct file_info *finfo, +static NTSTATUS shortname_del_fn(const char *mnt, struct file_info *finfo, const char *mask, void *state) { struct cli_state *pcli = (struct cli_state *)state; fstring fname; + NTSTATUS status = NT_STATUS_OK; + slprintf(fname, sizeof(fname), "\\shortname\\%s", finfo->name); if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0) - return; + return NT_STATUS_OK; if (finfo->mode & aDIR) { - if (!NT_STATUS_IS_OK(cli_rmdir(pcli, fname))) + status = cli_rmdir(pcli, fname); + if (!NT_STATUS_IS_OK(status)) { printf("del_fn: failed to rmdir %s\n,", fname ); + } } else { - if (!NT_STATUS_IS_OK(cli_unlink(pcli, fname, aSYSTEM | aHIDDEN))) + status = cli_unlink(pcli, fname, aSYSTEM | aHIDDEN); + if (!NT_STATUS_IS_OK(status)) { printf("del_fn: failed to unlink %s\n,", fname ); + } } + return status; } struct sn_state { @@ -6337,7 +6346,7 @@ struct sn_state { bool val; }; -static void shortname_list_fn(const char *mnt, struct file_info *finfo, +static NTSTATUS shortname_list_fn(const char *mnt, struct file_info *finfo, const char *name, void *state) { struct sn_state *s = (struct sn_state *)state; @@ -6362,6 +6371,7 @@ static void shortname_list_fn(const char *mnt, struct file_info *finfo, s->val = true; } s->matched += 1; + return NT_STATUS_OK; } static bool run_shortname_test(int dummy) -- cgit