Accept the key in hex format for the pstore command
authorChristof Schmitt <cs@samba.org>
Thu, 2 Jul 2015 20:06:32 +0000 (13:06 -0700)
committerMartin Schwenke <martin@meltin.net>
Wed, 24 Feb 2016 10:44:27 +0000 (21:44 +1100)
This follows the same pattern as the tstore command, and it allows
specifying key strings with a trailing \0 character.

Signed-off-by: Christof Schmitt <cs@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Mon Jul  6 23:23:22 CEST 2015 on sn-devel-104

(Imported from commit cdbc6d92c6bf0645c5a23955e8ec5e253212e86d)

tools/ctdb.c

index 6eacd83349968a3d7eebdc2147796009029605e8..23765aec89ed0483d3772775f772ff6dae3468d0 100644 (file)
@@ -4281,8 +4281,17 @@ static int control_pstore(struct ctdb_context *ctdb, int argc, const char **argv
                return -1;
        }
 
-       key.dptr  = discard_const(argv[1]);
-       key.dsize = strlen(argv[1]);
+       if (!strncmp(argv[1], "0x", 2)) {
+               key = hextodata(tmp_ctx, argv[1] + 2);
+               if (key.dsize == 0) {
+                       printf("Failed to convert \"%s\" into a TDB_DATA\n", argv[1]);
+                       return -1;
+               }
+       } else {
+               key.dptr  = discard_const(argv[1]);
+               key.dsize = strlen(argv[1]);
+       }
+
        ret = ctdb_transaction_store(h, key, data);
        if (ret != 0) {
                DEBUG(DEBUG_ERR,("Failed to store record\n"));