summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2015-09-17 15:54:40 -0700
committerKarolin Seeger <kseeger@samba.org>2015-10-05 09:41:29 +0200
commitd7682739ee82a5d5ce98d04e585ee9e8e9ff924b (patch)
treef3ba194776590a394185be908df08c2e99ee5f21
parente818bae92ce4f655ba4873383bfb4915efaa9213 (diff)
downloadsamba-d7682739ee82a5d5ce98d04e585ee9e8e9ff924b.tar.gz
s3: smbclient: Move cmd_setmode out of clitar.c and back into client.c
setmode <file> attribute is a valid smbclient command even if libarchive isn't on the system and tarmode isn't compiled in. Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org> (cherry picked from commit a47012d5429044c9a3616718bac21360f281aa81)
-rw-r--r--source3/client/client.c118
-rw-r--r--source3/client/client_proto.h6
-rw-r--r--source3/client/clitar.c129
3 files changed, 124 insertions, 129 deletions
diff --git a/source3/client/client.c b/source3/client/client.c
index f49f3ff1da0..034b48a2678 100644
--- a/source3/client/client.c
+++ b/source3/client/client.c
@@ -4656,6 +4656,124 @@ static int cmd_show_connect( void )
return 0;
}
+/**
+ * set_remote_attr - set DOS attributes of a remote file
+ * @filename: path to the file name
+ * @new_attr: attribute bit mask to use
+ * @mode: one of ATTR_SET or ATTR_UNSET
+ *
+ * Update the file attributes with the one provided.
+ */
+int set_remote_attr(const char *filename, uint16_t new_attr, int mode)
+{
+ extern struct cli_state *cli;
+ uint16_t old_attr;
+ NTSTATUS status;
+
+ status = cli_getatr(cli, filename, &old_attr, NULL, NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("cli_getatr failed: %s\n", nt_errstr(status));
+ return 1;
+ }
+
+ if (mode == ATTR_SET) {
+ new_attr |= old_attr;
+ } else {
+ new_attr = old_attr & ~new_attr;
+ }
+
+ status = cli_setatr(cli, filename, new_attr, 0);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("cli_setatr failed: %s\n", nt_errstr(status));
+ return 1;
+ }
+
+ return 0;
+}
+
+/**
+ * cmd_setmode - interactive command to set DOS attributes
+ *
+ * Read a filename and mode from the client command line and update
+ * the file DOS attributes.
+ */
+int cmd_setmode(void)
+{
+ const extern char *cmd_ptr;
+ char *buf;
+ char *fname = NULL;
+ uint16_t attr[2] = {0};
+ int mode = ATTR_SET;
+ int err = 0;
+ bool ok;
+ TALLOC_CTX *ctx = talloc_new(NULL);
+ if (ctx == NULL) {
+ return 1;
+ }
+
+ ok = next_token_talloc(ctx, &cmd_ptr, &buf, NULL);
+ if (!ok) {
+ d_printf("setmode <filename> <[+|-]rsha>\n");
+ err = 1;
+ goto out;
+ }
+
+ fname = talloc_asprintf(ctx,
+ "%s%s",
+ client_get_cur_dir(),
+ buf);
+ if (fname == NULL) {
+ err = 1;
+ goto out;
+ }
+
+ while (next_token_talloc(ctx, &cmd_ptr, &buf, NULL)) {
+ const char *s = buf;
+
+ while (*s) {
+ switch (*s++) {
+ case '+':
+ mode = ATTR_SET;
+ break;
+ case '-':
+ mode = ATTR_UNSET;
+ break;
+ case 'r':
+ attr[mode] |= FILE_ATTRIBUTE_READONLY;
+ break;
+ case 'h':
+ attr[mode] |= FILE_ATTRIBUTE_HIDDEN;
+ break;
+ case 's':
+ attr[mode] |= FILE_ATTRIBUTE_SYSTEM;
+ break;
+ case 'a':
+ attr[mode] |= FILE_ATTRIBUTE_ARCHIVE;
+ break;
+ default:
+ d_printf("setmode <filename> <perm=[+|-]rsha>\n");
+ err = 1;
+ goto out;
+ }
+ }
+ }
+
+ if (attr[ATTR_SET] == 0 && attr[ATTR_UNSET] == 0) {
+ d_printf("setmode <filename> <[+|-]rsha>\n");
+ err = 1;
+ goto out;
+ }
+
+ DEBUG(2, ("perm set %d %d\n", attr[ATTR_SET], attr[ATTR_UNSET]));
+
+ /* ignore return value: server might not store DOS attributes */
+ set_remote_attr(fname, attr[ATTR_SET], ATTR_SET);
+ set_remote_attr(fname, attr[ATTR_UNSET], ATTR_UNSET);
+out:
+ talloc_free(ctx);
+ return err;
+}
+
/****************************************************************************
iosize command
***************************************************************************/
diff --git a/source3/client/client_proto.h b/source3/client/client_proto.h
index 86f1d186492..d3d40363f20 100644
--- a/source3/client/client_proto.h
+++ b/source3/client/client_proto.h
@@ -26,6 +26,11 @@
struct cli_state;
struct file_info;
+enum {
+ ATTR_UNSET,
+ ATTR_SET,
+};
+
/* The following definitions come from client/client.c */
const char *client_get_cur_dir(void);
@@ -36,6 +41,7 @@ NTSTATUS do_list(const char *mask,
const char *dir),
bool rec,
bool dirs);
+int set_remote_attr(const char *filename, uint16_t new_attr, int mode);
int cmd_iosize(void);
/* The following definitions come from client/dnsbrowse.c */
diff --git a/source3/client/clitar.c b/source3/client/clitar.c
index 55618454142..7eb3fa087eb 100644
--- a/source3/client/clitar.c
+++ b/source3/client/clitar.c
@@ -121,11 +121,6 @@ enum tar_selection {
TAR_EXCLUDE, /* X flag */
};
-enum {
- ATTR_UNSET,
- ATTR_SET,
-};
-
struct tar {
TALLOC_CTX *talloc_ctx;
@@ -216,7 +211,6 @@ static int make_remote_path(const char *full_path);
static int max_token (const char *str);
static NTSTATUS is_subpath(const char *sub, const char *full,
bool *_subpath_match);
-static int set_remote_attr(const char *filename, uint16_t new_attr, int mode);
/**
* tar_get_ctx - retrieve global tar context handle
@@ -383,88 +377,6 @@ out:
return err;
}
-/**
- * cmd_setmode - interactive command to set DOS attributes
- *
- * Read a filename and mode from the client command line and update
- * the file DOS attributes.
- */
-int cmd_setmode(void)
-{
- const extern char *cmd_ptr;
- char *buf;
- char *fname = NULL;
- uint16_t attr[2] = {0};
- int mode = ATTR_SET;
- int err = 0;
- bool ok;
- TALLOC_CTX *ctx = talloc_new(NULL);
- if (ctx == NULL) {
- return 1;
- }
-
- ok = next_token_talloc(ctx, &cmd_ptr, &buf, NULL);
- if (!ok) {
- DBG(0, ("setmode <filename> <[+|-]rsha>\n"));
- err = 1;
- goto out;
- }
-
- fname = talloc_asprintf(ctx,
- "%s%s",
- client_get_cur_dir(),
- buf);
- if (fname == NULL) {
- err = 1;
- goto out;
- }
-
- while (next_token_talloc(ctx, &cmd_ptr, &buf, NULL)) {
- const char *s = buf;
-
- while (*s) {
- switch (*s++) {
- case '+':
- mode = ATTR_SET;
- break;
- case '-':
- mode = ATTR_UNSET;
- break;
- case 'r':
- attr[mode] |= FILE_ATTRIBUTE_READONLY;
- break;
- case 'h':
- attr[mode] |= FILE_ATTRIBUTE_HIDDEN;
- break;
- case 's':
- attr[mode] |= FILE_ATTRIBUTE_SYSTEM;
- break;
- case 'a':
- attr[mode] |= FILE_ATTRIBUTE_ARCHIVE;
- break;
- default:
- DBG(0, ("setmode <filename> <perm=[+|-]rsha>\n"));
- err = 1;
- goto out;
- }
- }
- }
-
- if (attr[ATTR_SET] == 0 && attr[ATTR_UNSET] == 0) {
- DBG(0, ("setmode <filename> <[+|-]rsha>\n"));
- err = 1;
- goto out;
- }
-
- DBG(2, ("perm set %d %d\n", attr[ATTR_SET], attr[ATTR_UNSET]));
-
- /* ignore return value: server might not store DOS attributes */
- set_remote_attr(fname, attr[ATTR_SET], ATTR_SET);
- set_remote_attr(fname, attr[ATTR_UNSET], ATTR_UNSET);
-out:
- talloc_free(ctx);
- return err;
-}
/**
* tar_parse_args - parse and set tar command line arguments
@@ -1631,41 +1543,6 @@ out:
return status;
}
-/**
- * set_remote_attr - set DOS attributes of a remote file
- * @filename: path to the file name
- * @new_attr: attribute bit mask to use
- * @mode: one of ATTR_SET or ATTR_UNSET
- *
- * Update the file attributes with the one provided.
- */
-static int set_remote_attr(const char *filename, uint16_t new_attr, int mode)
-{
- extern struct cli_state *cli;
- uint16_t old_attr;
- NTSTATUS status;
-
- status = cli_getatr(cli, filename, &old_attr, NULL, NULL);
- if (!NT_STATUS_IS_OK(status)) {
- DBG(0, ("cli_getatr failed: %s\n", nt_errstr(status)));
- return 1;
- }
-
- if (mode == ATTR_SET) {
- new_attr |= old_attr;
- } else {
- new_attr = old_attr & ~new_attr;
- }
-
- status = cli_setatr(cli, filename, new_attr, 0);
- if (!NT_STATUS_IS_OK(status)) {
- DBG(1, ("cli_setatr failed: %s\n", nt_errstr(status)));
- return 1;
- }
-
- return 0;
-}
-
/**
* make_remote_path - recursively make remote dirs
@@ -1932,12 +1809,6 @@ int cmd_tarmode(void)
return 1;
}
-int cmd_setmode(void)
-{
- NOT_IMPLEMENTED;
- return 1;
-}
-
int cmd_tar(void)
{
NOT_IMPLEMENTED;