Fix prototype for attrib_string().
[ira/wip.git] / source4 / client / client.c
index 79cc1b53820a4512f37147a15de5fbd78f217d88..02f46852b1a2baae9a0ea11f759f3401cfe141b4 100644 (file)
@@ -41,7 +41,7 @@
 #include "libcli/util/clilsa.h"
 #include "system/dir.h"
 #include "system/filesys.h"
-#include "lib/util/dlinklist.h"
+#include "../lib/util/dlinklist.h"
 #include "system/readline.h"
 #include "auth/credentials/credentials.h"
 #include "auth/gensec/gensec.h"
 #include "librpc/gen_ndr/ndr_nbt.h"
 #include "param/param.h"
 #include "librpc/rpc/dcerpc.h"
+#include "libcli/raw/raw_proto.h"
+
+/* the default pager to use for the client "more" command. Users can
+ *    override this with the PAGER environment variable */
+#ifndef DEFAULT_PAGER
+#define DEFAULT_PAGER "more"
+#endif
 
 struct smbclient_context {
        char *remote_cur_dir;
@@ -214,15 +221,18 @@ check the space on a device
 ****************************************************************************/
 static int do_dskattr(struct smbclient_context *ctx)
 {
-       int total, bsize, avail;
+       uint32_t bsize;
+       uint64_t total, avail;
 
        if (NT_STATUS_IS_ERR(smbcli_dskattr(ctx->cli->tree, &bsize, &total, &avail))) {
                d_printf("Error in dskattr: %s\n",smbcli_errstr(ctx->cli->tree)); 
                return 1;
        }
 
-       d_printf("\n\t\t%d blocks of size %d. %d blocks available\n",
-                total, bsize, avail);
+       d_printf("\n\t\t%llu blocks of size %u. %llu blocks available\n",
+                (unsigned long long)total, 
+                (unsigned)bsize, 
+                (unsigned long long)avail);
 
        return 0;
 }
@@ -931,7 +941,7 @@ static int cmd_more(struct smbclient_context *ctx, const char **args)
 
        pager=getenv("PAGER");
 
-       pager_cmd = talloc_asprintf(ctx, "%s %s",(pager? pager:PAGER), lname);
+       pager_cmd = talloc_asprintf(ctx, "%s %s",(pager? pager:DEFAULT_PAGER), lname);
        system(pager_cmd);
        unlink(lname);
        
@@ -2554,9 +2564,11 @@ static bool browse_host(struct loadparm_context *lp_ctx,
        char *binding;
        NTSTATUS status;
        struct srvsvc_NetShareEnumAll r;
+       struct srvsvc_NetShareInfoCtr info_ctr;
        uint32_t resume_handle = 0;
        TALLOC_CTX *mem_ctx = talloc_init("browse_host");
        struct srvsvc_NetShareCtr1 ctr1;
+       uint32_t totalentries = 0;
 
        binding = talloc_asprintf(mem_ctx, "ncacn_np:%s", query_host);
 
@@ -2571,11 +2583,16 @@ static bool browse_host(struct loadparm_context *lp_ctx,
                return false;
        }
 
+       info_ctr.level = 1;
+       info_ctr.ctr.ctr1 = &ctr1;
+
        r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
-       r.in.level = 1;
-       r.in.ctr.ctr1 = &ctr1;
+       r.in.info_ctr = &info_ctr;
        r.in.max_buffer = ~0;
        r.in.resume_handle = &resume_handle;
+       r.out.resume_handle = &resume_handle;
+       r.out.totalentries = &totalentries;
+       r.out.info_ctr = &info_ctr;
 
        d_printf("\n\tSharename       Type       Comment\n");
        d_printf("\t---------       ----       -------\n");
@@ -2587,9 +2604,9 @@ static bool browse_host(struct loadparm_context *lp_ctx,
                if (NT_STATUS_IS_OK(status) && 
                    (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA) ||
                     W_ERROR_IS_OK(r.out.result)) &&
-                   r.out.ctr.ctr1) {
-                       display_share_result(r.out.ctr.ctr1);
-                       resume_handle += r.out.ctr.ctr1->count;
+                   r.out.info_ctr->ctr.ctr1) {
+                       display_share_result(r.out.info_ctr->ctr.ctr1);
+                       resume_handle += r.out.info_ctr->ctr.ctr1->count;
                }
        } while (NT_STATUS_IS_OK(status) && W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA));
 
@@ -2751,7 +2768,7 @@ process a -c command string
 ****************************************************************************/
 static int process_command_string(struct smbclient_context *ctx, const char *cmd)
 {
-       const char **lines;
+       char **lines;
        int i, rc = 0;
 
        lines = str_list_make(NULL, cmd, ";");
@@ -3029,7 +3046,9 @@ static bool do_connect(struct smbclient_context *ctx,
                       const char *specified_server, const char **ports, 
                       const char *specified_share, 
                       struct cli_credentials *cred, 
-                      struct smbcli_options *options)
+                      struct smbcli_options *options,
+                      struct smbcli_session_options *session_options,
+                          struct smb_iconv_convenience *iconv_convenience)
 {
        NTSTATUS status;
        char *server, *share;
@@ -3048,7 +3067,8 @@ static bool do_connect(struct smbclient_context *ctx,
        
        status = smbcli_full_connection(ctx, &ctx->cli, server, ports,
                                        share, NULL, cred, resolve_ctx, 
-                                       ev_ctx, options);
+                                       ev_ctx, options, session_options,
+                                       iconv_convenience);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("Connection to \\\\%s\\%s failed - %s\n", 
                         server, share, nt_errstr(status));
@@ -3081,7 +3101,8 @@ static int do_message_op(const char *netbios_name, const char *desthost,
                         int name_type,
                         struct event_context *ev_ctx,
                         struct resolve_context *resolve_ctx,
-                        struct smbcli_options *options)
+                        struct smbcli_options *options,
+                        struct smb_iconv_convenience *iconv_convenience)
 {
        struct nbt_name called, calling;
        const char *server_name;
@@ -3095,7 +3116,8 @@ static int do_message_op(const char *netbios_name, const char *desthost,
 
        if (!(cli = smbcli_state_init(NULL)) ||
            !smbcli_socket_connect(cli, server_name, destports,
-                                  ev_ctx, resolve_ctx, options)) {
+                                  ev_ctx, resolve_ctx, options,
+                                  iconv_convenience)) {
                d_printf("Connection to %s failed\n", server_name);
                return 1;
        }
@@ -3124,11 +3146,6 @@ static int do_message_op(const char *netbios_name, const char *desthost,
        const char *query_host = NULL;
        bool message = false;
        const char *desthost = NULL;
-#ifdef KANJI
-       const char *term_code = KANJI;
-#else
-       const char *term_code = "";
-#endif /* KANJI */
        poptContext pc;
        const char *service = NULL;
        int port = 0;
@@ -3140,6 +3157,7 @@ static int do_message_op(const char *netbios_name, const char *desthost,
        struct smbclient_context *ctx;
        const char *cmdstr = NULL;
        struct smbcli_options smb_options;
+       struct smbcli_session_options smb_session_options;
 
        struct poptOption long_options[] = {
                POPT_AUTOHELP
@@ -3148,7 +3166,6 @@ static int do_message_op(const char *netbios_name, const char *desthost,
                { "ip-address", 'I', POPT_ARG_STRING, NULL, 'I', "Use this IP to connect to", "IP" },
                { "stderr", 'E', POPT_ARG_NONE, NULL, 'E', "Write messages to stderr instead of stdout" },
                { "list", 'L', POPT_ARG_STRING, NULL, 'L', "Get a list of shares available on a host", "HOST" },
-               { "terminal", 't', POPT_ARG_STRING, NULL, 't', "Terminal I/O code {sjis|euc|jis7|jis8|junet|hex}", "CODE" },
                { "directory", 'D', POPT_ARG_STRING, NULL, 'D', "Start from directory", "DIR" },
                { "command", 'c', POPT_ARG_STRING, &cmdstr, 'c', "Execute semicolon separated commands" }, 
                { "send-buffer", 'b', POPT_ARG_INT, NULL, 'b', "Changes the transmit/send buffer", "BYTES" },
@@ -3190,9 +3207,6 @@ static int do_message_op(const char *netbios_name, const char *desthost,
                case 'L':
                        query_host = strdup(poptGetOptArg(pc));
                        break;
-               case 't':
-                       term_code = strdup(poptGetOptArg(pc));
-                       break;
                case 'D':
                        base_directory = strdup(poptGetOptArg(pc));
                        break;
@@ -3233,8 +3247,9 @@ static int do_message_op(const char *netbios_name, const char *desthost,
        poptFreeContext(pc);
 
        lp_smbcli_options(cmdline_lp_ctx, &smb_options);
+       lp_smbcli_session_options(cmdline_lp_ctx, &smb_session_options);
 
-       ev_ctx = event_context_init(talloc_autofree_context());
+       ev_ctx = s4_event_context_init(talloc_autofree_context());
 
        DEBUG( 3, ( "Client started (version %s).\n", SAMBA_VERSION_STRING ) );
 
@@ -3255,13 +3270,14 @@ static int do_message_op(const char *netbios_name, const char *desthost,
                                   lp_smb_ports(cmdline_lp_ctx), dest_ip,
                                   name_type, ev_ctx,
                                   lp_resolve_context(cmdline_lp_ctx),
-                                  &smb_options);
+                                  &smb_options, lp_iconv_convenience(cmdline_lp_ctx));
                return rc;
        }
        
        if (!do_connect(ctx, ev_ctx, lp_resolve_context(cmdline_lp_ctx),
                        desthost, lp_smb_ports(cmdline_lp_ctx), service,
-                       cmdline_credentials, &smb_options))
+                       cmdline_credentials, &smb_options, &smb_session_options,
+                       lp_iconv_convenience(cmdline_lp_ctx)))
                return 1;
 
        if (base_directory)