r26644: Janitorial: Pass resolve_context explicitly to various SMB functions, should...
[jelmer/samba4-debian.git] / source / client / cifsdd.c
index cf3ab17308bb852c6f27bbdc511110b2618d3c47..8749a82573cf1161201eb5f3a2fe663621c04fc4 100644 (file)
@@ -6,7 +6,7 @@
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
 #include "system/filesys.h"
 #include "auth/gensec/gensec.h"
 #include "lib/cmdline/popt_common.h"
+#include "libcli/resolve/resolve.h"
 
 #include "cifsdd.h"
+#include "param/param.h"
 
 const char * const PROGNAME = "cifsdd";
 
@@ -103,7 +104,7 @@ static struct argdef args[] =
  */
 };
 
-struct argdef * find_named_arg(const char * arg)
+static struct argdef * find_named_arg(const char * arg)
 {
        int i;
 
@@ -195,7 +196,7 @@ void set_arg_val(const char * name, ...)
                        arg->arg_val.nval = va_arg(ap, uint64_t);
                        break;
                case ARG_BOOL:
-                       arg->arg_val.bval = va_arg(ap, BOOL);
+                       arg->arg_val.bval = va_arg(ap, int);
                        break;
                case ARG_PATHNAME:
                        arg->arg_val.pval = va_arg(ap, char *);
@@ -219,7 +220,7 @@ fail:
        return;
 }
 
-BOOL check_arg_bool(const char * name)
+bool check_arg_bool(const char * name)
 {
        struct argdef * arg;
 
@@ -230,7 +231,7 @@ BOOL check_arg_bool(const char * name)
 
        DEBUG(0, ("invalid argument name: %s", name));
        SMB_ASSERT(0);
-       return(False);
+       return(false);
 }
 
 uint64_t check_arg_numeric(const char * name)
@@ -295,7 +296,7 @@ static void cifsdd_help_message(poptContext pctx,
                const char * parg,
                void * pdata)
 {
-       static const char const notes[] = 
+       static const char notes[] = 
 "FILE can be a local filename or a UNC path of the form //server/share/path.\n";
 
        char prefix[24];
@@ -351,7 +352,8 @@ static void print_transfer_stats(void)
        }
 }
 
-static struct dd_iohandle * open_file(const char * which)
+static struct dd_iohandle * open_file(struct resolve_context *resolve_ctx, 
+                                     const char * which, const char **ports)
 {
        int                     options = 0;
        const char *            path = NULL;
@@ -371,13 +373,13 @@ static struct dd_iohandle * open_file(const char * which)
 
        if (strcmp(which, "if") == 0) {
                path = check_arg_pathname("if");
-               handle = dd_open_path(path, check_arg_numeric("ibs"),
-                                       options);
+               handle = dd_open_path(resolve_ctx, path, ports, 
+                                     check_arg_numeric("ibs"), options);
        } else if (strcmp(which, "of") == 0) {
                options |= DD_WRITE;
                path = check_arg_pathname("of");
-               handle = dd_open_path(path, check_arg_numeric("obs"),
-                                       options);
+               handle = dd_open_path(resolve_ctx, path, ports, 
+                                     check_arg_numeric("obs"), options);
        } else {
                SMB_ASSERT(0);
                return(NULL);
@@ -390,19 +392,19 @@ static struct dd_iohandle * open_file(const char * which)
        return(handle);
 }
 
-static void set_max_xmit(uint64_t iomax)
+static void set_max_xmit(struct loadparm_context *lp_ctx, uint64_t iomax)
 {
        char buf[64];
 
        snprintf(buf, sizeof(buf), "%llu", (unsigned long long)iomax);
-       lp_set_cmdline("max xmit", buf);
+       lp_set_cmdline(lp_ctx, "max xmit", buf);
 }
 
-static int copy_files(void)
+static int copy_files(struct loadparm_context *lp_ctx)
 {
        uint8_t *       iobuf;  /* IO buffer. */
        uint64_t        iomax;  /* Size of the IO buffer. */
-       uint64_t        iosz;   /* Amount of data in the IO buffer. */
+       uint64_t        data_size; /* Amount of data in the IO buffer. */
 
        uint64_t        ibs;
        uint64_t        obs;
@@ -419,23 +421,25 @@ static int copy_files(void)
         * could accumulate a remainder if ibs and obs don't match.
         */
        iomax = 2 * MAX(ibs, obs);
-       if ((iobuf = malloc(iomax)) == NULL) {
+       if ((iobuf = malloc_array_p(uint8_t, iomax)) == NULL) {
                fprintf(stderr,
                        "%s: failed to allocate IO buffer of %llu bytes\n",
                        PROGNAME, (unsigned long long)iomax);
                return(EOM_EXIT_CODE);
        }
 
-       set_max_xmit(MAX(ibs, obs));
+       set_max_xmit(lp_ctx, MAX(ibs, obs));
 
        DEBUG(4, ("IO buffer size is %llu, max xmit is %d\n",
-                       (unsigned long long)iomax, lp_max_xmit()));
+                       (unsigned long long)iomax, lp_max_xmit(lp_ctx)));
 
-       if (!(ifile = open_file("if"))) {
+       if (!(ifile = open_file(lp_resolve_context(lp_ctx), "if", 
+                               lp_smb_ports(lp_ctx)))) {
                return(FILESYS_EXIT_CODE);
        }
 
-       if (!(ofile = open_file("of"))) {
+       if (!(ofile = open_file(lp_resolve_context(lp_ctx), "of", 
+                               lp_smb_ports(lp_ctx)))) {
                return(FILESYS_EXIT_CODE);
        }
 
@@ -443,9 +447,9 @@ static int copy_files(void)
        ifile->io_seek(ifile, check_arg_numeric("skip") * ibs);
        ofile->io_seek(ofile, check_arg_numeric("seek") * obs);
 
-       DEBUG(4, ("max xmit was negotiated to be %d\n", lp_max_xmit()));
+       DEBUG(4, ("max xmit was negotiated to be %d\n", lp_max_xmit(lp_ctx)));
 
-       for (iosz = 0;;) {
+       for (data_size = 0;;) {
 
                /* Handle signals. We are somewhat compatible with GNU dd.
                 * SIGINT makes us stop, but still print transfer statistics.
@@ -462,10 +466,11 @@ static int copy_files(void)
                }
 
                if (ifile->io_flags & DD_END_OF_FILE) {
-                       DEBUG(4, ("flushing %llu bytes at EOF\n", (unsigned long long)iosz));
-                       while (iosz > 0) {
+                       DEBUG(4, ("flushing %llu bytes at EOF\n",
+                                       (unsigned long long)data_size));
+                       while (data_size > 0) {
                                if (!dd_flush_block(ofile, iobuf,
-                                                       &iosz, obs)) {
+                                                       &data_size, obs)) {
                                        return(IOERROR_EXIT_CODE);
                                }
                        }
@@ -475,11 +480,11 @@ static int copy_files(void)
                /* Try and read enough blocks of ibs bytes to be able write
                 * out one of obs bytes.
                 */
-               if (!dd_fill_block(ifile, iobuf, &iosz, obs, ibs)) {
+               if (!dd_fill_block(ifile, iobuf, &data_size, obs, ibs)) {
                        return(IOERROR_EXIT_CODE);
                }
 
-               if (iosz == 0) {
+               if (data_size == 0) {
                        /* Done. */
                        SMB_ASSERT(ifile->io_flags & DD_END_OF_FILE);
                }
@@ -497,7 +502,8 @@ static int copy_files(void)
                 * at least obs bytes in the IO buffer but might not if the
                 * file is too small.
                 */
-               if (!dd_flush_block(ofile, iobuf, &iosz, obs)) {
+               if (data_size && 
+                   !dd_flush_block(ofile, iobuf, &data_size, obs)) {
                        return(IOERROR_EXIT_CODE);
                }
        }
@@ -515,7 +521,7 @@ struct poptOption cifsddHelpOptions[] = {
   { NULL, '\0', POPT_ARG_CALLBACK, (void *)&cifsdd_help_message, '\0', NULL, NULL },
   { "help", '?', 0, NULL, '?', "Show this help message", NULL },
   { "usage", '\0', 0, NULL, 'u', "Display brief usage message", NULL },
-    POPT_TABLEEND
+  { NULL }
 } ;
 
 int main(int argc, const char ** argv)
@@ -532,7 +538,7 @@ int main(int argc, const char ** argv)
                POPT_COMMON_CONNECTION
                POPT_COMMON_CREDENTIALS
                POPT_COMMON_VERSION
-               POPT_TABLEEND
+               { NULL }
        };
 
        /* Block sizes. */
@@ -547,9 +553,9 @@ int main(int argc, const char ** argv)
        set_arg_val("if", NULL);
        set_arg_val("of", NULL);
        /* Options. */
-       set_arg_val("direct", False);
-       set_arg_val("sync", False);
-       set_arg_val("oplock", False);
+       set_arg_val("direct", false);
+       set_arg_val("sync", false);
+       set_arg_val("oplock", false);
 
        pctx = poptGetContext(PROGNAME, argc, argv, poptions, 0);
        while ((i = poptGetNextOpt(pctx)) != -1) {
@@ -572,7 +578,7 @@ int main(int argc, const char ** argv)
                }
        }
 
-       gensec_init();
+       gensec_init(cmdline_lp_ctx);
        dump_args();
 
        if (check_arg_numeric("ibs") == 0 || check_arg_numeric("ibs") == 0) {
@@ -593,7 +599,7 @@ int main(int argc, const char ** argv)
 
        CatchSignal(SIGINT, dd_handle_signal);
        CatchSignal(SIGUSR1, dd_handle_signal);
-       return(copy_files());
+       return(copy_files(cmdline_lp_ctx));
 }
 
 /* vim: set sw=8 sts=8 ts=8 tw=79 : */