s3: Remove a "typedef struct"
[sfrench/samba-autobuild/.git] / source3 / client / client.c
index 08526527257221cf9d84f7a37cf25063edaa3bc6..9245428c5e2684b74dc386c25543921f14cad044 100644 (file)
@@ -23,7 +23,8 @@
 
 #include "includes.h"
 #include "client/client_proto.h"
-#include "include/rpc_client.h"
+#include "../librpc/gen_ndr/cli_srvsvc.h"
+
 #ifndef REGISTER
 #define REGISTER 0
 #endif
@@ -161,6 +162,24 @@ const char *client_set_cur_dir(const char *newdir)
        return client_get_cur_dir();
 }
 
+/****************************************************************************
+ Put up a yes/no prompt.
+****************************************************************************/
+
+static bool yesno(const char *p)
+{
+       char ans[20];
+       printf("%s",p);
+
+       if (!fgets(ans,sizeof(ans)-1,stdin))
+               return(False);
+
+       if (*ans == 'y' || *ans == 'Y')
+               return(True);
+
+       return(False);
+}
+
 /****************************************************************************
  Write to a local file with CR/LF->LF translation if appropriate. Return the
  number taken from the buffer. This may not equal the number written.
@@ -243,51 +262,29 @@ static size_t push_source(uint8_t *buf, size_t n, void *priv)
 
 static void send_message(const char *username)
 {
-       int total_len = 0;
-       int grp_id;
-
-       if (!cli_message_start(cli, desthost, username, &grp_id)) {
-               d_printf("message start: %s\n", cli_errstr(cli));
-               return;
-       }
-
-
-       d_printf("Connected. Type your message, ending it with a Control-D\n");
-
-       while (!feof(stdin) && total_len < 1600) {
-               int maxlen = MIN(1600 - total_len,127);
-               char msg[1024];
-               int l=0;
-               int c;
-
-               ZERO_ARRAY(msg);
+       char buf[1600];
+       NTSTATUS status;
+       int i;
 
-               for (l=0;l<maxlen && (c=fgetc(stdin))!=EOF;l++) {
-                       if (c == '\n')
-                               msg[l++] = '\r';
-                       msg[l] = c;
-               }
+       d_printf("Type your message, ending it with a Control-D\n");
 
-               if ((total_len > 0) && (strlen(msg) == 0)) {
+       i = 0;
+       while (i<sizeof(buf)-2) {
+               int c = fgetc(stdin);
+               if (c == EOF) {
                        break;
                }
-
-               if (!cli_message_text(cli, msg, l, grp_id)) {
-                       d_printf("SMBsendtxt failed (%s)\n",cli_errstr(cli));
-                       return;
+               if (c == '\n') {
+                       buf[i++] = '\r';
                }
-
-               total_len += l;
+               buf[i++] = c;
        }
+       buf[i] = '\0';
 
-       if (total_len >= 1600)
-               d_printf("the message was truncated to 1600 bytes\n");
-       else
-               d_printf("sent %d bytes\n",total_len);
-
-       if (!cli_message_end(cli, grp_id)) {
-               d_printf("SMBsendend failed (%s)\n",cli_errstr(cli));
-               return;
+       status = cli_message(cli, desthost, username, buf);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_fprintf(stderr, "cli_message returned %s\n",
+                         nt_errstr(status));
        }
 }
 
@@ -411,8 +408,12 @@ static int do_cd(const char *new_dir)
           Except Win9x doesn't support the qpathinfo_basic() call..... */
 
        if (targetcli->protocol > PROTOCOL_LANMAN2 && !targetcli->win95) {
-               if (!cli_qpathinfo_basic( targetcli, targetpath, &sbuf, &attributes ) ) {
-                       d_printf("cd %s: %s\n", new_cd, cli_errstr(targetcli));
+               NTSTATUS status;
+
+               status = cli_qpathinfo_basic(targetcli, targetpath, &sbuf,
+                                            &attributes);
+               if (!NT_STATUS_IS_OK(status)) {
+                       d_printf("cd %s: %s\n", new_cd, nt_errstr(status));
                        client_set_cur_dir(saved_dir);
                        goto out;
                }
@@ -1666,6 +1667,7 @@ static int do_put(const char *rname, const char *lname, bool reput)
                if (f && reput) {
                        if (x_tseek(f, start, SEEK_SET) == -1) {
                                d_printf("Error seeking local file\n");
+                               x_fclose(f);
                                return 1;
                        }
                }
@@ -1692,7 +1694,9 @@ static int do_put(const char *rname, const char *lname, bool reput)
 
        if (!NT_STATUS_IS_OK(cli_close(targetcli, fnum))) {
                d_printf("%s closing remote file %s\n",cli_errstr(cli),rname);
-               x_fclose(f);
+               if (f != x_stdin) {
+                       x_fclose(f);
+               }
                return 1;
        }
 
@@ -1763,7 +1767,7 @@ static int cmd_put(void)
                SMB_STRUCT_STAT st;
                /* allow '-' to represent stdin
                   jdblair, 24.jun.98 */
-               if (!file_exist_stat(lname,&st) &&
+               if (!file_exist_stat(lname, &st, false) &&
                    (strcmp(lname,"-"))) {
                        d_printf("%s does not exist\n",lname);
                        return 1;
@@ -2468,14 +2472,18 @@ static int cmd_posix(void)
        uint16 major, minor;
        uint32 caplow, caphigh;
        char *caps;
+       NTSTATUS status;
 
        if (!SERVER_HAS_UNIX_CIFS(cli)) {
                d_printf("Server doesn't support UNIX CIFS extensions.\n");
                return 1;
        }
 
-       if (!cli_unix_extensions_version(cli, &major, &minor, &caplow, &caphigh)) {
-               d_printf("Can't get UNIX CIFS extensions version from server.\n");
+       status = cli_unix_extensions_version(cli, &major, &minor, &caplow,
+                                            &caphigh);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("Can't get UNIX CIFS extensions version from "
+                        "server: %s\n", nt_errstr(status));
                return 1;
        }
 
@@ -2546,8 +2554,11 @@ static int cmd_posix(void)
 
        d_printf("Server supports CIFS capabilities %s\n", caps);
 
-       if (!cli_set_unix_extensions_capabilities(cli, major, minor, caplow, caphigh)) {
-               d_printf("Can't set UNIX CIFS extensions capabilities. %s.\n", cli_errstr(cli));
+       status = cli_set_unix_extensions_capabilities(cli, major, minor,
+                                                     caplow, caphigh);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("Can't set UNIX CIFS extensions capabilities. %s.\n",
+                        nt_errstr(status));
                return 1;
        }
 
@@ -2602,7 +2613,7 @@ static int cmd_lock(void)
 
        len = (uint64_t)strtol(buf, (char **)NULL, 16);
 
-       if (!cli_posix_lock(cli, fnum, start, len, true, lock_type)) {
+       if (!NT_STATUS_IS_OK(cli_posix_lock(cli, fnum, start, len, true, lock_type))) {
                d_printf("lock failed %d: %s\n", fnum, cli_errstr(cli));
        }
 
@@ -2636,7 +2647,7 @@ static int cmd_unlock(void)
 
        len = (uint64_t)strtol(buf, (char **)NULL, 16);
 
-       if (!cli_posix_unlock(cli, fnum, start, len)) {
+       if (!NT_STATUS_IS_OK(cli_posix_unlock(cli, fnum, start, len))) {
                d_printf("unlock failed %d: %s\n", fnum, cli_errstr(cli));
        }
 
@@ -3002,6 +3013,7 @@ static int cmd_getfacl(void)
        uint16 num_file_acls = 0;
        uint16 num_dir_acls = 0;
        uint16 i;
+       NTSTATUS status;
 
        if (!next_token_talloc(ctx, &cmd_ptr,&name,NULL)) {
                d_printf("getfacl filename\n");
@@ -3025,9 +3037,11 @@ static int cmd_getfacl(void)
                return 1;
        }
 
-       if (!cli_unix_extensions_version(targetcli, &major, &minor,
-                               &caplow, &caphigh)) {
-               d_printf("Can't get UNIX CIFS version from server.\n");
+       status = cli_unix_extensions_version(targetcli, &major, &minor,
+                                            &caplow, &caphigh);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("Can't get UNIX CIFS version from server: %s.\n",
+                        nt_errstr(status));
                return 1;
        }
 
@@ -3366,9 +3380,12 @@ static int cmd_volume(void)
        fstring volname;
        uint32 serial_num;
        time_t create_date;
+       NTSTATUS status;
 
-       if (!cli_get_fs_volume_info(cli, volname, &serial_num, &create_date)) {
-               d_printf("Errr %s getting volume info\n",cli_errstr(cli));
+       status = cli_get_fs_volume_info(cli, volname, &serial_num,
+                                       &create_date);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("Error %s getting volume info\n", nt_errstr(status));
                return 1;
        }
 
@@ -3447,7 +3464,7 @@ static int cmd_newer(void)
        SMB_STRUCT_STAT sbuf;
 
        ok = next_token_talloc(ctx, &cmd_ptr,&buf,NULL);
-       if (ok && (sys_stat(buf,&sbuf) == 0)) {
+       if (ok && (sys_stat(buf, &sbuf, false) == 0)) {
                newer_than = convert_timespec_to_time_t(sbuf.st_ex_mtime);
                DEBUG(1,("Getting files newer than %s",
                         time_to_asc(newer_than)));
@@ -3626,7 +3643,7 @@ static int cmd_reput(void)
                return 1;
        }
 
-       if (!file_exist_stat(local_name, &st)) {
+       if (!file_exist_stat(local_name, &st, false)) {
                d_printf("%s does not exist\n", local_name);
                return 1;
        }
@@ -3687,7 +3704,7 @@ static void browse_fn(const char *name, uint32 m,
 static bool browse_host_rpc(bool sort)
 {
        NTSTATUS status;
-       struct rpc_pipe_client *pipe_hnd;
+       struct rpc_pipe_client *pipe_hnd = NULL;
        TALLOC_CTX *frame = talloc_stackframe();
        WERROR werr;
        struct srvsvc_NetShareInfoCtr info_ctr;
@@ -4144,20 +4161,20 @@ static int process_command_string(const char *cmd_in)
 
 #define MAX_COMPLETIONS 100
 
-typedef struct {
+struct completion_remote {
        char *dirmask;
        char **matches;
        int count, samelen;
        const char *text;
        int len;
-} completion_remote_t;
+};
 
 static void completion_remote_filter(const char *mnt,
                                file_info *f,
                                const char *mask,
                                void *state)
 {
-       completion_remote_t *info = (completion_remote_t *)state;
+       struct completion_remote *info = (struct completion_remote *)state;
 
        if ((info->count < MAX_COMPLETIONS - 1) &&
                        (strncmp(info->text, f->name, info->len) == 0) &&
@@ -4215,9 +4232,9 @@ static char **remote_completion(const char *text, int len)
        char *targetpath = NULL;
        struct cli_state *targetcli = NULL;
        int i;
-       completion_remote_t info = { NULL, NULL, 1, 0, NULL, 0 };
+       struct completion_remote info = { NULL, NULL, 1, 0, NULL, 0 };
 
-       /* can't have non-static intialisation on Sun CC, so do it
+       /* can't have non-static initialisation on Sun CC, so do it
           at run time here */
        info.samelen = len;
        info.text = text;
@@ -4738,7 +4755,6 @@ static int do_message_op(struct user_auth_info *a_info)
        int opt;
        char *query_host = NULL;
        bool message = false;
-       char *term_code = NULL;
        static const char *new_name_resolve_order = NULL;
        poptContext pc;
        char *p;
@@ -4754,7 +4770,6 @@ static int do_message_op(struct user_auth_info *a_info)
                { "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" },
                { "max-protocol", 'm', POPT_ARG_STRING, NULL, 'm', "Set the max protocol level", "LEVEL" },
                { "tar", 'T', POPT_ARG_STRING, NULL, 'T', "Command line tar", "<c|x>IXFqgbNan" },
                { "directory", 'D', POPT_ARG_STRING, NULL, 'D', "Start from directory", "DIR" },
@@ -4774,15 +4789,6 @@ static int do_message_op(struct user_auth_info *a_info)
                exit(ENOMEM);
        }
 
-#ifdef KANJI
-       term_code = talloc_strdup(frame,KANJI);
-#else /* KANJI */
-       term_code = talloc_strdup(frame,"");
-#endif /* KANJI */
-       if (!term_code) {
-               exit(ENOMEM);
-       }
-
        /* initialize the workgroup name so we can determine whether or
           not it was set by a command line option */
 
@@ -4876,12 +4882,6 @@ static int do_message_op(struct user_auth_info *a_info)
                                exit(ENOMEM);
                        }
                        break;
-               case 't':
-                       term_code = talloc_strdup(frame,poptGetOptArg(pc));
-                       if (!term_code) {
-                               exit(ENOMEM);
-                       }
-                       break;
                case 'm':
                        max_protocol = interpret_protocol(poptGetOptArg(pc), max_protocol);
                        break;