s3: Convert cli_list() to return NTSTATUS
authorVolker Lendecke <vl@samba.org>
Mon, 2 Aug 2010 17:22:22 +0000 (19:22 +0200)
committerVolker Lendecke <vl@samba.org>
Wed, 4 Aug 2010 18:32:50 +0000 (20:32 +0200)
If needed, the callback functions can count themselves

source3/client/client.c
source3/include/proto.h
source3/libgpo/gpo_filesync.c
source3/libsmb/clilist.c
source3/libsmb/libsmb_dir.c
source3/torture/torture.c
source3/utils/net_rpc.c

index 7f804bf80931a14f102f8c47cd48ef8de953e1d7..d4395818a790a9b129ee210040ec2ae34ac38525 100644 (file)
@@ -865,10 +865,13 @@ void do_list(const char *mask,
        } else {
                /* check for dfs */
                if (cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetpath)) {
-                       if (cli_list(targetcli, targetpath, attribute,
-                                    do_list_helper, targetcli) == -1) {
+                       NTSTATUS status;
+
+                       status = cli_list(targetcli, targetpath, attribute,
+                                         do_list_helper, targetcli);
+                       if (!NT_STATUS_IS_OK(status)) {
                                d_printf("%s listing %s\n",
-                                       cli_errstr(targetcli), targetpath);
+                                        nt_errstr(status), targetpath);
                        }
                        TALLOC_FREE(targetpath);
                } else {
@@ -4281,6 +4284,7 @@ static char **remote_completion(const char *text, int len)
        struct cli_state *targetcli = NULL;
        int i;
        struct completion_remote info = { NULL, NULL, 1, 0, NULL, 0 };
+       NTSTATUS status;
 
        /* can't have non-static initialisation on Sun CC, so do it
           at run time here */
@@ -4339,8 +4343,9 @@ static char **remote_completion(const char *text, int len)
        if (!cli_resolve_path(ctx, "", auth_info, cli, dirmask, &targetcli, &targetpath)) {
                goto cleanup;
        }
-       if (cli_list(targetcli, targetpath, aDIR | aSYSTEM | aHIDDEN,
-                               completion_remote_filter, (void *)&info) < 0) {
+       status = cli_list(targetcli, targetpath, aDIR | aSYSTEM | aHIDDEN,
+                         completion_remote_filter, (void *)&info);
+       if (!NT_STATUS_IS_OK(status)) {
                goto cleanup;
        }
 
index 4e3ec7a24f34ad5666c8ca43cf4ed8f4333abdf8..f9684ad16ee2db25154d1201e90d5da894c38b04 100644 (file)
@@ -2580,9 +2580,9 @@ int cli_list_new(struct cli_state *cli,const char *Mask,uint16 attribute,
 int cli_list_old(struct cli_state *cli,const char *Mask,uint16 attribute,
                 void (*fn)(const char *, struct file_info *, const char *,
                            void *), void *state);
-int cli_list(struct cli_state *cli,const char *Mask,uint16 attribute,
-            void (*fn)(const char *, struct file_info *, const char *,
-                       void *), void *state);
+NTSTATUS cli_list(struct cli_state *cli,const char *Mask,uint16 attribute,
+                 void (*fn)(const char *, struct file_info *, const char *,
+                            void *), void *state);
 
 /* The following definitions come from libsmb/climessage.c  */
 
index 461ebb742feac25141893237f07f0be152d55a18..d85df1f7e15017209da6a4a86fd87107f99d3892 100644 (file)
@@ -110,15 +110,15 @@ static NTSTATUS gpo_copy_dir(const char *unix_path)
 
 static bool gpo_sync_files(struct sync_context *ctx)
 {
+       NTSTATUS status;
+
        DEBUG(3,("calling cli_list with mask: %s\n", ctx->mask));
 
-       if (cli_list(ctx->cli,
-                    ctx->mask,
-                    ctx->attribute,
-                    gpo_sync_func,
-                    ctx) == -1) {
-               DEBUG(1,("listing [%s] failed with error: %s\n",
-                       ctx->mask, cli_errstr(ctx->cli)));
+       status = cli_list(ctx->cli, ctx->mask, ctx->attribute, gpo_sync_func,
+                         ctx);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(1, ("listing [%s] failed with error: %s\n",
+                         ctx->mask, nt_errstr(status)));
                return false;
        }
 
index 99dcc3f9c6c421821df088b62326dd574190de22..a8e3bd50179539e598b56b24a4aa235097809c88 100644 (file)
@@ -677,11 +677,19 @@ int cli_list_old(struct cli_state *cli,const char *Mask,uint16 attribute,
  This auto-switches between old and new style.
 ****************************************************************************/
 
-int cli_list(struct cli_state *cli,const char *Mask,uint16 attribute,
-            void (*fn)(const char *, struct file_info *, const char *,
-                       void *), void *state)
+NTSTATUS cli_list(struct cli_state *cli,const char *Mask,uint16 attribute,
+                 void (*fn)(const char *, struct file_info *, const char *,
+                            void *), void *state)
 {
-       if (cli->protocol <= PROTOCOL_LANMAN1)
-               return cli_list_old(cli, Mask, attribute, fn, state);
-       return cli_list_new(cli, Mask, attribute, fn, state);
+       int rec;
+
+       if (cli->protocol <= PROTOCOL_LANMAN1) {
+               rec = cli_list_old(cli, Mask, attribute, fn, state);
+       } else {
+               rec = cli_list_new(cli, Mask, attribute, fn, state);
+       }
+       if (rec == -1) {
+               return cli_nt_error(cli);
+       }
+       return NT_STATUS_OK;
 }
index 1a1ca68a8a6734795660eda1381c771a9108794c..6d3da1cd7798f09222b3376150af9c017db470c7 100644 (file)
@@ -748,6 +748,7 @@ SMBC_opendir_ctx(SMBCCTX *context,
                          */
                        char *targetpath;
                        struct cli_state *targetcli;
+                       NTSTATUS status;
 
                        /* We connect to the server and list the directory */
                        dir->dir_type = SMBC_FILE_SHARE;
@@ -791,10 +792,10 @@ SMBC_opendir_ctx(SMBCCTX *context,
                                return NULL;
                        }
 
-                       if (cli_list(targetcli, targetpath,
-                                     aDIR | aSYSTEM | aHIDDEN,
-                                     dir_list_fn, (void *)dir) < 0) {
-
+                       status = cli_list(targetcli, targetpath,
+                                         aDIR | aSYSTEM | aHIDDEN,
+                                         dir_list_fn, (void *)dir);
+                       if (!NT_STATUS_IS_OK(status)) {
                                if (dir) {
                                        SAFE_FREE(dir->fname);
                                        SAFE_FREE(dir);
@@ -1302,6 +1303,7 @@ SMBC_rmdir_ctx(SMBCCTX *context,
                         /* Local storage to avoid buffer overflows */
                        char *lpath;
                        bool smbc_rmdir_dirempty = true;
+                       NTSTATUS status;
 
                        lpath = talloc_asprintf(frame, "%s\\*",
                                                targetpath);
@@ -1311,11 +1313,12 @@ SMBC_rmdir_ctx(SMBCCTX *context,
                                return -1;
                        }
 
-                       if (cli_list(targetcli, lpath,
-                                     aDIR | aSYSTEM | aHIDDEN,
-                                     rmdir_list_fn,
-                                    &smbc_rmdir_dirempty) < 0) {
+                       status = cli_list(targetcli, lpath,
+                                         aDIR | aSYSTEM | aHIDDEN,
+                                         rmdir_list_fn,
+                                         &smbc_rmdir_dirempty);
 
+                       if (!NT_STATUS_IS_OK(status)) {
                                /* Fix errno to ignore latest error ... */
                                DEBUG(5, ("smbc_rmdir: "
                                           "cli_list returned an error: %d\n",
index df8adbdfdf4f8277c6d3cbe7c4423128d6775dff..cea7b8a4bfa0cd7aff9ea127210d7ecb161dc0d8 100644 (file)
@@ -4794,7 +4794,10 @@ static bool run_openattrtest(int dummy)
 static void list_fn(const char *mnt, struct file_info *finfo,
                    const char *name, void *state)
 {
-
+       int *matched = (int *)state;
+       if (matched != NULL) {
+               *matched += 1;
+       }
 }
 
 /*
@@ -4807,6 +4810,7 @@ static bool run_dirtest(int dummy)
        uint16_t fnum;
        struct timeval core_start;
        bool correct = True;
+       int matched;
 
        printf("starting directory test\n");
 
@@ -4829,9 +4833,17 @@ static bool run_dirtest(int dummy)
 
        core_start = timeval_current();
 
-       printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
-       printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
-       printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
+       matched = 0;
+       cli_list(cli, "a*.*", 0, list_fn, &matched);
+       printf("Matched %d\n", matched);
+
+       matched = 0;
+       cli_list(cli, "b*.*", 0, list_fn, &matched);
+       printf("Matched %d\n", matched);
+
+       matched = 0;
+       cli_list(cli, "xyzabc", 0, list_fn, &matched);
+       printf("Matched %d\n", matched);
 
        printf("dirtest core %g seconds\n", timeval_elapsed(&core_start));
 
@@ -6173,6 +6185,7 @@ static void shortname_del_fn(const char *mnt, struct file_info *finfo,
 }
 
 struct sn_state {
+       int matched;
        int i;
        bool val;
 };
@@ -6201,6 +6214,7 @@ static void shortname_list_fn(const char *mnt, struct file_info *finfo,
                        __location__, finfo->short_name, finfo->name);
                s->val = true;
        }
+       s->matched += 1;
 }
 
 static bool run_shortname_test(int dummy)
@@ -6255,7 +6269,11 @@ static bool run_shortname_test(int dummy)
                        goto out;
                }
                cli_close(cli, fnum);
-               if (cli_list(cli, "\\shortname\\test*.*", 0, shortname_list_fn, &s) != 1) {
+
+               s.matched = 0;
+               cli_list(cli, "\\shortname\\test*.*", 0, shortname_list_fn,
+                        &s);
+               if (s.matched != 1) {
                        d_printf("(%s) failed to list %s: %s\n",
                                __location__, fname, cli_errstr(cli));
                        correct = false;
index cafab87a963dc7f92c87ddfed1747de16b49be32..d27545d1c630284a9e1510a96c8194facd227700 100644 (file)
@@ -3452,6 +3452,7 @@ static bool sync_files(struct copy_clistate *cp_clistate, const char *mask)
 {
        struct cli_state *targetcli;
        char *targetpath = NULL;
+       NTSTATUS status;
 
        DEBUG(3,("calling cli_list with mask: %s\n", mask));
 
@@ -3463,9 +3464,11 @@ static bool sync_files(struct copy_clistate *cp_clistate, const char *mask)
                return false;
        }
 
-       if (cli_list(targetcli, targetpath, cp_clistate->attribute, copy_fn, cp_clistate) == -1) {
+       status = cli_list(targetcli, targetpath, cp_clistate->attribute,
+                         copy_fn, cp_clistate);
+       if (!NT_STATUS_IS_OK(status)) {
                d_fprintf(stderr, _("listing %s failed with error: %s\n"),
-                       mask, cli_errstr(targetcli));
+                         mask, nt_errstr(status));
                return false;
        }