s3-libsmb: move protos to libsmb/proto.h
[sfrench/samba-autobuild/.git] / source3 / client / client.c
index bc4816be8c3bb5b0a627c5b3f495e96be5a0d3a5..45494efe62db9e891b80ae26df9401c48f0a1f9e 100644 (file)
@@ -22,6 +22,7 @@
 */
 
 #include "includes.h"
+#include "system/filesys.h"
 #include "popt_common.h"
 #include "rpc_client/cli_pipe.h"
 #include "client/client_proto.h"
 #include "../libcli/smbreadline/smbreadline.h"
 #include "../libcli/security/security.h"
 #include "system/select.h"
+#include "libsmb/libsmb.h"
 #include "libsmb/clirap.h"
 #include "trans2.h"
+#include "libsmb/nmblib.h"
 
 #ifndef REGISTER
 #define REGISTER 0
@@ -503,7 +506,7 @@ static bool do_this_one(struct file_info *finfo)
                return false;
        }
 
-       if (finfo->mode & aDIR) {
+       if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
                return true;
        }
 
@@ -518,7 +521,7 @@ static bool do_this_one(struct file_info *finfo)
                return false;
        }
 
-       if ((archive_level==1 || archive_level==2) && !(finfo->mode & aARCH)) {
+       if ((archive_level==1 || archive_level==2) && !(finfo->mode & FILE_ATTRIBUTE_ARCHIVE)) {
                DEBUG(3,("archive %s failed\n", finfo->name));
                return false;
        }
@@ -545,7 +548,7 @@ static NTSTATUS display_finfo(struct cli_state *cli_state, struct file_info *fin
        if (!showacls) {
                d_printf("  %-30s%7.7s %8.0f  %s",
                         finfo->name,
-                        attrib_string(finfo->mode),
+                        attrib_string(talloc_tos(), finfo->mode),
                        (double)finfo->size,
                        time_to_asc(t));
                dir_total += finfo->size;
@@ -567,7 +570,7 @@ static NTSTATUS display_finfo(struct cli_state *cli_state, struct file_info *fin
                }
                /* print file meta date header */
                d_printf( "FILENAME:%s\n", finfo->name);
-               d_printf( "MODE:%s\n", attrib_string(finfo->mode));
+               d_printf( "MODE:%s\n", attrib_string(talloc_tos(), finfo->mode));
                d_printf( "SIZE:%.0f\n", (double)finfo->size);
                d_printf( "MTIME:%s", time_to_asc(t));
                status = cli_ntcreate(cli_state, afname, 0,
@@ -700,7 +703,7 @@ static void add_to_do_list_queue(const char *entry)
                }
        }
        if (do_list_queue) {
-               safe_strcpy_base(do_list_queue + do_list_queue_end,
+               strlcpy_base(do_list_queue + do_list_queue_end,
                                 entry, do_list_queue, do_list_queue_size);
                do_list_queue_end = new_end;
                DEBUG(4,("added %s to do_list_queue (start=%d, end=%d)\n",
@@ -750,7 +753,7 @@ static NTSTATUS do_list_helper(const char *mntpoint, struct file_info *f,
                *dir_end = '\0';
        }
 
-       if (f->mode & aDIR) {
+       if (f->mode & FILE_ATTRIBUTE_DIRECTORY) {
                if (do_list_dirs && do_this_one(f)) {
                        status = do_list_fn(cli_state, f, dir);
                        if (!NT_STATUS_IS_OK(status)) {
@@ -922,7 +925,7 @@ NTSTATUS do_list(const char *mask,
 static int cmd_dir(void)
 {
        TALLOC_CTX *ctx = talloc_tos();
-       uint16 attribute = aDIR | aSYSTEM | aHIDDEN;
+       uint16 attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
        char *mask = NULL;
        char *buf = NULL;
        int rc = 1;
@@ -972,7 +975,7 @@ static int cmd_dir(void)
 static int cmd_du(void)
 {
        TALLOC_CTX *ctx = talloc_tos();
-       uint16 attribute = aDIR | aSYSTEM | aHIDDEN;
+       uint16 attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
        char *mask = NULL;
        char *buf = NULL;
        NTSTATUS status;
@@ -1145,8 +1148,8 @@ static int do_get(const char *rname, const char *lname_in, bool reget)
                close(handle);
        }
 
-       if (archive_level >= 2 && (attr & aARCH)) {
-               cli_setatr(cli, rname, attr & ~(uint16)aARCH, 0);
+       if (archive_level >= 2 && (attr & FILE_ATTRIBUTE_ARCHIVE)) {
+               cli_setatr(cli, rname, attr & ~(uint16)FILE_ATTRIBUTE_ARCHIVE, 0);
        }
 
        {
@@ -1231,7 +1234,7 @@ static NTSTATUS do_mget(struct cli_state *cli_state, struct file_info *finfo,
                return NT_STATUS_UNSUCCESSFUL;
        }
 
-       if (finfo->mode & aDIR) {
+       if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
                if (asprintf(&quest,
                         "Get directory %s? ",finfo->name) < 0) {
                        return NT_STATUS_NO_MEMORY;
@@ -1249,7 +1252,7 @@ static NTSTATUS do_mget(struct cli_state *cli_state, struct file_info *finfo,
        }
        SAFE_FREE(quest);
 
-       if (!(finfo->mode & aDIR)) {
+       if (!(finfo->mode & FILE_ATTRIBUTE_DIRECTORY)) {
                rname = talloc_asprintf(ctx,
                                "%s%s",
                                client_get_cur_dir(),
@@ -1304,7 +1307,7 @@ static NTSTATUS do_mget(struct cli_state *cli_state, struct file_info *finfo,
                return NT_STATUS_NO_MEMORY;
        }
 
-       status = do_list(mget_mask, aSYSTEM | aHIDDEN | aDIR,do_mget,false, true);
+       status = do_list(mget_mask, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_DIRECTORY,do_mget,false, true);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
@@ -1393,13 +1396,13 @@ static int cmd_more(void)
 static int cmd_mget(void)
 {
        TALLOC_CTX *ctx = talloc_tos();
-       uint16 attribute = aSYSTEM | aHIDDEN;
+       uint16 attribute = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
        char *mget_mask = NULL;
        char *buf = NULL;
        NTSTATUS status = NT_STATUS_OK;
 
        if (recurse) {
-               attribute |= aDIR;
+               attribute |= FILE_ATTRIBUTE_DIRECTORY;
        }
 
        abort_mget = false;
@@ -1713,7 +1716,11 @@ static int do_allinfo(const char *name)
                         (unsigned long long)streams[i].size);
        }
 
-       status = cli_open(cli, name, O_RDONLY, DENY_NONE, &fnum);
+       status = cli_ntcreate(cli, name, 0,
+                             CREATE_ACCESS_READ, 0,
+                             FILE_SHARE_READ|FILE_SHARE_WRITE
+                             |FILE_SHARE_DELETE,
+                             FILE_OPEN, 0x0, 0x0, &fnum);
        if (!NT_STATUS_IS_OK(status)) {
                /*
                 * Ignore failure, it does not hurt if we can't list
@@ -2300,12 +2307,12 @@ static NTSTATUS do_del(struct cli_state *cli_state, struct file_info *finfo,
                return NT_STATUS_NO_MEMORY;
        }
 
-       if (finfo->mode & aDIR) {
+       if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
                TALLOC_FREE(mask);
                return NT_STATUS_OK;
        }
 
-       status = cli_unlink(cli_state, mask, aSYSTEM | aHIDDEN);
+       status = cli_unlink(cli_state, mask, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("%s deleting remote file %s\n",
                         nt_errstr(status), mask);
@@ -2324,10 +2331,10 @@ static int cmd_del(void)
        char *mask = NULL;
        char *buf = NULL;
        NTSTATUS status = NT_STATUS_OK;
-       uint16 attribute = aSYSTEM | aHIDDEN;
+       uint16 attribute = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
 
        if (recurse) {
-               attribute |= aDIR;
+               attribute |= FILE_ATTRIBUTE_DIRECTORY;
        }
 
        mask = talloc_strdup(ctx, client_get_cur_dir());
@@ -4510,7 +4517,7 @@ static NTSTATUS completion_remote_filter(const char *mnt,
                return NT_STATUS_OK;
        }
 
-       if ((info->dirmask[0] == 0) && !(f->mode & aDIR))
+       if ((info->dirmask[0] == 0) && !(f->mode & FILE_ATTRIBUTE_DIRECTORY))
                info->matches[info->count] = SMB_STRDUP(f->name);
        else {
                TALLOC_CTX *ctx = talloc_stackframe();
@@ -4526,7 +4533,7 @@ static NTSTATUS completion_remote_filter(const char *mnt,
                        TALLOC_FREE(ctx);
                        return NT_STATUS_NO_MEMORY;
                }
-               if (f->mode & aDIR) {
+               if (f->mode & FILE_ATTRIBUTE_DIRECTORY) {
                        tmp = talloc_asprintf_append(tmp, "%s",
                                                     CLI_DIRSEP_STR);
                }
@@ -4540,7 +4547,7 @@ static NTSTATUS completion_remote_filter(const char *mnt,
        if (info->matches[info->count] == NULL) {
                return NT_STATUS_OK;
        }
-       if (f->mode & aDIR) {
+       if (f->mode & FILE_ATTRIBUTE_DIRECTORY) {
                smb_readline_ca_char(0);
        }
        if (info->count == 1) {
@@ -4623,7 +4630,7 @@ static char **remote_completion(const char *text, int len)
        if (!cli_resolve_path(ctx, "", auth_info, cli, dirmask, &targetcli, &targetpath)) {
                goto cleanup;
        }
-       status = cli_list(targetcli, targetpath, aDIR | aSYSTEM | aHIDDEN,
+       status = cli_list(targetcli, targetpath, FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN,
                          completion_remote_filter, (void *)&info);
        if (!NT_STATUS_IS_OK(status)) {
                goto cleanup;
@@ -5040,9 +5047,9 @@ static int do_message_op(struct user_auth_info *a_info)
        make_nmb_name(&calling, calling_name, 0x0);
        make_nmb_name(&called , desthost, name_type);
 
-       fstrcpy(server_name, desthost);
+       strlcpy(server_name, desthost,sizeof(server_name));
        snprintf(name_type_hex, sizeof(name_type_hex), "#%X", name_type);
-       fstrcat(server_name, name_type_hex);
+       strlcat(server_name, name_type_hex,sizeof(server_name));
 
         zero_sockaddr(&ss);
        if (have_ip)