diff options
author | Aurélien Aptel <aurelien.aptel@gmail.com> | 2013-07-05 09:51:43 +0200 |
---|---|---|
committer | Andreas Schneider <asn@samba.org> | 2014-02-19 18:22:26 +0100 |
commit | a896f046fecde4d6601d4789ad2a7057a1d0c8da (patch) | |
tree | 25071f61ae898b4359113b01519087f8afd92460 /source3/client | |
parent | 1d142c6237ded9994e4846fccb5c2ea085fb31ee (diff) | |
download | samba-a896f046fecde4d6601d4789ad2a7057a1d0c8da.tar.gz samba-a896f046fecde4d6601d4789ad2a7057a1d0c8da.tar.xz samba-a896f046fecde4d6601d4789ad2a7057a1d0c8da.zip |
clitar.c: add cmd_setmode(), remove typedef
Signed-off-by: Aurélien Aptel <aurelien.aptel@gmail.com>
Reviewed-by: David Disseldorp <ddiss@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Diffstat (limited to 'source3/client')
-rw-r--r-- | source3/client/clitar.c | 190 |
1 files changed, 162 insertions, 28 deletions
diff --git a/source3/client/clitar.c b/source3/client/clitar.c index ebf597033f3..04692c6bcb5 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -21,6 +21,9 @@ #include "system/filesys.h" #include "client/client_proto.h" #include "libsmb/libsmb.h" +#include <archive.h> + +#define LEN(x) (sizeof(x)/sizeof((x)[0])) /* XXX: used in client.c, we have to export it for now */ char tar_type = 0; @@ -31,7 +34,12 @@ enum tar_type_t { TAR_EXLUDE, /* X flag */ }; -typedef struct { +enum { + ATTR_UNSET, + ATTR_SET, +}; + +struct tar { /* include, include from file, exclude */ enum tar_type_t type; @@ -45,28 +53,27 @@ typedef struct { bool incremental; /* backup _only_ archived file? */ bool reset; /* unset archive bit? */ bool dry; /* don't write tar file? */ + bool verbose; } mode; /* path to tar archive name */ char *tar_path; /* path to file list (F flag) */ - char *list_path -} tar_ctx_t; + char *list_path; -static tar_ctx_t tar_ctx; + /* archive handle */ + struct archive *archive; +}; -static void tar_set_default (tar_ctx_t* t) -{ - memset(t, 0, sizeof(*t)); - - t->type = TAR_INCLUDE; - t->blocksize = 20; - t->mode.hidden = True; - t->mode.system = True; - t->mode.incremental = False; - t->mode.dry = False; -} +static struct tar tar_ctx = { + .type = TAR_INCLUDE, + .blocksize = 20, + .mode.hidden = True, + .mode.system = True, + .mode.incremental = False, + .mode.dry = False, +}; /**************************************************************************** @@ -79,23 +86,23 @@ int cmd_block(void) const extern char *cmd_ptr; char *buf; int size; - TALLOC_CTX *ctx = talloc_tos(); + TALLOC_CTX *ctx = talloc_tos(); - if (!next_token_talloc(ctx, &cmd_ptr, &buf, NULL)) { - DEBUG(0, ("blocksize <n>\n")); - return 1; - } + if (!next_token_talloc(ctx, &cmd_ptr, &buf, NULL)) { + DEBUG(0, ("blocksize <n>\n")); + return 1; + } - size = atoi(buf); - if (size < 0 || size > 65535) { - DEBUG(0, ("blocksize out of range")); - return 1; - } + size = atoi(buf); + if (size < 0 || size > 65535) { + DEBUG(0, ("blocksize out of range")); + return 1; + } - tar_ctx.blocksize = size; - DEBUG(2,("blocksize is now %d\n", size)); + tar_ctx.blocksize = size; + DEBUG(2,("blocksize is now %d\n", size)); - return 0; + return 0; } /**************************************************************************** @@ -104,15 +111,142 @@ command to set incremental / reset mode int cmd_tarmode(void) { + const extern char *cmd_ptr; + char *buf; + int i; + TALLOC_CTX *ctx = talloc_tos(); + + struct { + const char *cmd; + bool *p; + bool value; + } table[] = { + {"full", &tar_ctx.mode.incremental, False}, + {"inc", &tar_ctx.mode.incremental, True }, + {"reset", &tar_ctx.mode.reset, True }, + {"noreset", &tar_ctx.mode.reset, False}, + {"system", &tar_ctx.mode.system, True }, + {"nosystem", &tar_ctx.mode.system, False}, + {"hidden", &tar_ctx.mode.hidden, True }, + {"nohidden", &tar_ctx.mode.hidden, False}, + {"verbose", &tar_ctx.mode.verbose, True }, + {"noquiet", &tar_ctx.mode.verbose, True }, + {"quiet", &tar_ctx.mode.verbose, False}, + {"noverbose", &tar_ctx.mode.verbose, False}, + }; + + while (next_token_talloc(ctx, &cmd_ptr, &buf, NULL)) { + for (i = 0; i < LEN(table); i++) { + if (strequal(table[i].cmd, buf)) { + *table[i].p = table[i].value; + break; + } + } + + if (i == LEN(table)) + DEBUG(0, ("tarmode: unrecognised option %s\n", buf)); + + TALLOC_FREE(buf); + } + + DEBUG(0, ("tarmode is now %s, %s, %s, %s, %s\n", + tar_ctx.mode.incremental ? "incremental" : "full", + tar_ctx.mode.system ? "system" : "nosystem", + tar_ctx.mode.hidden ? "hidden" : "nohidden", + tar_ctx.mode.reset ? "reset" : "noreset", + tar_ctx.mode.verbose ? "verbose" : "quiet")); return 0; } +static void set_remote_attr(char *filename, uint16 new_attr, int mode) +{ + extern struct cli_state *cli; + uint16 old_attr; + NTSTATUS status; + + if (!NT_STATUS_IS_OK(cli_getatr(cli, filename, &old_attr, NULL, NULL))) { + /* XXX: debug message */ + return; + } + + 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)) { + DEBUG(1, ("setatr failed: %s\n", nt_errstr(status))); + } +} + + /**************************************************************************** Feeble attrib command ***************************************************************************/ int cmd_setmode(void) { + const extern char *cmd_ptr; + char *buf; + char *fname = NULL; + uint16 attr[2] = {0}; + int mode = ATTR_SET; + TALLOC_CTX *ctx = talloc_tos(); + + + if (!next_token_talloc(ctx, &cmd_ptr, &buf, NULL)) { + DEBUG(0, ("setmode <filename> <[+|-]rsha>\n")); + return 1; + } + + fname = talloc_asprintf(ctx, + "%s%s", + client_get_cur_dir(), + buf); + if (!fname) { + return 1; + } + + 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: + DEBUG(0, ("setmode <filename> <perm=[+|-]rsha>\n")); + return 1; + } + } + } + + if (attr[ATTR_SET] == 0 && attr[ATTR_UNSET] == 0) { + DEBUG(0, ("setmode <filename> <[+|-]rsha>\n")); + return 1; + } + + DEBUG(2, ("\nperm set %d %d\n", attr[ATTR_SET], attr[ATTR_UNSET])); + set_remote_attr(fname, attr[ATTR_SET], ATTR_SET); + set_remote_attr(fname, attr[ATTR_UNSET], ATTR_UNSET); return 0; } |