3604df
From f541f3d06ef279c37bacba0100ab6c068aad8e71 Mon Sep 17 00:00:00 2001
3604df
From: Aravinda VK <avishwan@redhat.com>
3604df
Date: Tue, 25 Oct 2016 12:56:05 +0530
3604df
Subject: [PATCH 167/206] geo-rep/cli: Validate Checkpoint label
3604df
3604df
Checkpoint command accepts "now" or any other Time
3604df
in "%Y-%m-%d %H:%M:%S" format as label.
3604df
3604df
Validation added with this patch for the input label. Checkpoint set
3604df
will fail for invalid label.
3604df
3604df
> Reviewed-on: http://review.gluster.org/15721
3604df
> Smoke: Gluster Build System <jenkins@build.gluster.org>
3604df
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
3604df
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
3604df
> Reviewed-by: Saravanakumar Arumugam <sarumuga@redhat.com>
3604df
> Reviewed-by: Kotresh HR <khiremat@redhat.com>
3604df
3604df
BUG: 1380122
3604df
Change-Id: I23518c151ab4b294f64cae3b78baaacb3d8f7b82
3604df
Signed-off-by: Aravinda VK <avishwan@redhat.com>
3604df
Reviewed-on: https://code.engineering.redhat.com/gerrit/90316
3604df
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
3604df
Tested-by: Atin Mukherjee <amukherj@redhat.com>
3604df
---
3604df
 cli/src/cli-cmd-parser.c | 25 +++++++++++++++++++++++++
3604df
 1 file changed, 25 insertions(+)
3604df
3604df
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
3604df
index 7eed1a4..b419915 100644
3604df
--- a/cli/src/cli-cmd-parser.c
3604df
+++ b/cli/src/cli-cmd-parser.c
3604df
@@ -13,6 +13,7 @@
3604df
 #include <stdint.h>
3604df
 #include <pthread.h>
3604df
 #include <fnmatch.h>
3604df
+#include <time.h>
3604df
 
3604df
 #include "cli.h"
3604df
 #include "cli-cmd.h"
3604df
@@ -2596,6 +2597,9 @@ config_parse (const char **words, int wordcount, dict_t *dict,
3604df
         char               *append_str = NULL;
3604df
         size_t             append_len = 0;
3604df
         char               *subop = NULL;
3604df
+        char               *ret_chkpt = NULL;
3604df
+        struct tm           checkpoint_time;
3604df
+        char                chkpt_buf[20] = "";
3604df
 
3604df
         switch ((wordcount - 1) - cmdi) {
3604df
         case 0:
3604df
@@ -2657,6 +2661,27 @@ config_parse (const char **words, int wordcount, dict_t *dict,
3604df
                         }
3604df
                         snprintf (append_str, 300, "%" GF_PRI_SECOND,
3604df
                                   tv.tv_sec);
3604df
+                } else if ((strcmp (words[cmdi + 1], "checkpoint") == 0) &&
3604df
+                           (strcmp (append_str, "now") != 0)) {
3604df
+                        memset(&checkpoint_time, 0, sizeof(struct tm));
3604df
+                        ret_chkpt = strptime(append_str, "%Y-%m-%d %H:%M:%S",
3604df
+                                             &checkpoint_time);
3604df
+
3604df
+                        if (ret_chkpt == NULL) {
3604df
+                                ret = -1;
3604df
+                                cli_err ("Invalid Checkpoint label. Use format "
3604df
+                                         "\"Y-m-d H:M:S\", Example: 2016-10-25 15:30:45");
3604df
+                                goto out;
3604df
+                        }
3604df
+                        GF_FREE (append_str);
3604df
+                        append_str = GF_CALLOC (1, 300, cli_mt_append_str);
3604df
+                        if (!append_str) {
3604df
+                                ret = -1;
3604df
+                                goto out;
3604df
+                        }
3604df
+                        strftime (chkpt_buf, sizeof(chkpt_buf), "%s",
3604df
+                                  &checkpoint_time);
3604df
+                        snprintf (append_str, 300, "%s", chkpt_buf);
3604df
                 }
3604df
 
3604df
                 ret = dict_set_dynstr (dict, "op_value", append_str);
3604df
-- 
3604df
2.9.3
3604df