summaryrefslogtreecommitdiffstats
path: root/source3/client/clitar.c
diff options
context:
space:
mode:
authorAurélien Aptel <aurelien.aptel@gmail.com>2013-07-16 19:15:48 +0200
committerAndreas Schneider <asn@samba.org>2014-02-19 18:22:28 +0100
commit679cd1627021daf96ddc4c1dd8f71a2067dbaa99 (patch)
tree87b04f8e2574a08c5a863949ff151c07f255b89e /source3/client/clitar.c
parent3348b139d2a73c62181ad71be10973ec6e3a0366 (diff)
downloadsamba-679cd1627021daf96ddc4c1dd8f71a2067dbaa99.tar.gz
samba-679cd1627021daf96ddc4c1dd8f71a2067dbaa99.tar.xz
samba-679cd1627021daf96ddc4c1dd8f71a2067dbaa99.zip
clitar.c: implement interactive command + respective test
Signed-off-by: Aurélien Aptel <aurelien.aptel@gmail.com> [ddiss@samba.org: split from test changes already upstream] Reviewed-by: David Disseldorp <ddiss@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
Diffstat (limited to 'source3/client/clitar.c')
-rw-r--r--source3/client/clitar.c63
1 files changed, 62 insertions, 1 deletions
diff --git a/source3/client/clitar.c b/source3/client/clitar.c
index c27689429e8..b3cfc741eb6 100644
--- a/source3/client/clitar.c
+++ b/source3/client/clitar.c
@@ -910,13 +910,74 @@ static int tar_create(struct tar* t)
}
/**
+ * Return upper limit for the number of token in @str.
+ *
+ * The result is not exact, the actual number of token might be less
+ * than what is returned.
+ */
+static int max_token (const char *str)
+{
+ const char *s = str;
+ int nb = 0;
+
+ if (!str) {
+ return 0;
+ }
+
+ while (*s) {
+ if (isspace(*s)) {
+ nb++;
+ }
+ s++;
+ }
+
+ nb++;
+
+ return nb;
+}
+
+/**
* cmd_tar - interactive command to start a tar backup/restoration
*
* Check presence of argument, parse them and handle the request.
*/
int cmd_tar(void)
{
- return 0;
+ TALLOC_CTX *ctx = talloc_tos();
+ const extern char *cmd_ptr;
+ const char *flag;
+ const char **val;
+ char *buf;
+ int maxtok = max_token(cmd_ptr);
+ int i = 0;
+ int err = 0;
+
+ if (!next_token_talloc(ctx, &cmd_ptr, &buf, NULL)) {
+ DBG(0, ("tar <c|x>[IXFbganN] [options] <tar file> [path list]\n"));
+ return 1;
+ }
+
+ flag = buf;
+ val = talloc_array(ctx, const char*, maxtok);
+
+ while (next_token_talloc(ctx, &cmd_ptr, &buf, NULL)) {
+ val[i++] = buf;
+ }
+
+ if (!tar_parse_args(&tar_ctx, flag, val, i)) {
+ DBG(0, ("parse_args failed\n"));
+ err = 1;
+ goto out;
+ }
+
+ if (tar_process(&tar_ctx)) {
+ DBG(0, ("tar_process failed\n"));
+ err = 1;
+ goto out;
+ }
+
+ out:
+ return err;
}
static int tar_extract(struct tar *t)