s4:client
[ira/wip.git] / source4 / client / client.c
index 1865d8db132b311fa045459a09ec982e565c77a8..3fa819c8e7f1f17669bad6969dac1bc350a0649a 100644 (file)
 #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;
@@ -1214,10 +1221,14 @@ static int cmd_put(struct smbclient_context *ctx, const char **args)
 
        lname = talloc_strdup(ctx, args[1]);
   
-       if (args[2])
-               rname = talloc_strdup(ctx, args[2]);
-       else
+       if (args[2]) {
+               if (args[2][0]=='\\')
+                       rname = talloc_strdup(ctx, args[2]);
+               else
+                       rname = talloc_asprintf(ctx, "%s\\%s", ctx->remote_cur_dir, args[2]);
+       } else {
                rname = talloc_asprintf(ctx, "%s\\%s", ctx->remote_cur_dir, lname);
+       }
        
        dos_clean_name(rname);
 
@@ -2550,16 +2561,18 @@ static void display_share_result(struct srvsvc_NetShareCtr1 *ctr1)
 try and browse available shares on a host
 ****************************************************************************/
 static bool browse_host(struct loadparm_context *lp_ctx,
-                       struct event_context *ev_ctx,
+                       struct tevent_context *ev_ctx,
                        const char *query_host)
 {
        struct dcerpc_pipe *p;
        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);
 
@@ -2574,11 +2587,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");
@@ -2590,9 +2608,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));
 
@@ -3027,13 +3045,16 @@ static int process_stdin(struct smbclient_context *ctx)
 return a connection to a server
 *******************************************************/
 static bool do_connect(struct smbclient_context *ctx, 
-                      struct event_context *ev_ctx,
+                      struct tevent_context *ev_ctx,
                       struct resolve_context *resolve_ctx,
                       const char *specified_server, const char **ports, 
                       const char *specified_share, 
+                          const char *socket_options,
                       struct cli_credentials *cred, 
                       struct smbcli_options *options,
-                      struct smbcli_session_options *session_options)
+                      struct smbcli_session_options *session_options,
+                          struct smb_iconv_convenience *iconv_convenience,
+                          struct gensec_settings *gensec_settings)
 {
        NTSTATUS status;
        char *server, *share;
@@ -3051,8 +3072,12 @@ static bool do_connect(struct smbclient_context *ctx,
        ctx->remote_cur_dir = talloc_strdup(ctx, "\\");
        
        status = smbcli_full_connection(ctx, &ctx->cli, server, ports,
-                                       share, NULL, cred, resolve_ctx, 
-                                       ev_ctx, options, session_options);
+                                       share, NULL, 
+                                       socket_options,
+                                       cred, resolve_ctx, 
+                                       ev_ctx, options, session_options,
+                                       iconv_convenience,
+                                       gensec_settings);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("Connection to \\\\%s\\%s failed - %s\n", 
                         server, share, nt_errstr(status));
@@ -3067,7 +3092,7 @@ static bool do_connect(struct smbclient_context *ctx,
 handle a -L query
 ****************************************************************************/
 static int do_host_query(struct loadparm_context *lp_ctx,
-                        struct event_context *ev_ctx,
+                        struct tevent_context *ev_ctx,
                         const char *query_host,
                         const char *workgroup)
 {
@@ -3083,9 +3108,11 @@ handle a message operation
 static int do_message_op(const char *netbios_name, const char *desthost,
                         const char **destports, const char *destip,
                         int name_type,
-                        struct event_context *ev_ctx,
+                        struct tevent_context *ev_ctx,
                         struct resolve_context *resolve_ctx,
-                        struct smbcli_options *options)
+                        struct smbcli_options *options,
+                        struct smb_iconv_convenience *iconv_convenience,
+             const char *socket_options)
 {
        struct nbt_name called, calling;
        const char *server_name;
@@ -3099,7 +3126,9 @@ 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,
+                   socket_options)) {
                d_printf("Connection to %s failed\n", server_name);
                return 1;
        }
@@ -3135,7 +3164,7 @@ static int do_message_op(const char *netbios_name, const char *desthost,
        int rc = 0;
        int name_type = 0x20;
        TALLOC_CTX *mem_ctx;
-       struct event_context *ev_ctx;
+       struct tevent_context *ev_ctx;
        struct smbclient_context *ctx;
        const char *cmdstr = NULL;
        struct smbcli_options smb_options;
@@ -3165,7 +3194,7 @@ static int do_message_op(const char *netbios_name, const char *desthost,
                exit(1);
        }
 
-       ctx = talloc(mem_ctx, struct smbclient_context);
+       ctx = talloc_zero(mem_ctx, struct smbclient_context);
        ctx->io_bufsize = 64512;
 
        pc = poptGetContext("smbclient", argc, (const char **) argv, long_options, 0);
@@ -3252,24 +3281,31 @@ 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),
+                   lp_socket_options(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, &smb_session_options))
+                       lp_socket_options(cmdline_lp_ctx),
+                       cmdline_credentials, &smb_options, &smb_session_options,
+                       lp_iconv_convenience(cmdline_lp_ctx),
+                       lp_gensec_settings(ctx, cmdline_lp_ctx)))
                return 1;
 
-       if (base_directory) 
+       if (base_directory) {
                do_cd(ctx, base_directory);
+               free(base_directory);
+       }
        
        if (cmdstr) {
                rc = process_command_string(ctx, cmdstr);
        } else {
                rc = process_stdin(ctx);
        }
-  
+
+       free(desthost);
        talloc_free(mem_ctx);
 
        return rc;