From 5d288a9b1705b75e7e8dcf93a93b7fd6715ad5ef Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 21 Apr 2017 14:10:33 +0200 Subject: [PATCH] tdbtool: Add "storehex" command MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Volker Lendecke Reviewed-by: Ralph Böhme Autobuild-User(master): Jeremy Allison Autobuild-Date(master): Sat Apr 22 09:16:16 CEST 2017 on sn-devel-144 --- lib/tdb/man/tdbtool.8.xml | 10 +++++ lib/tdb/tools/tdbtool.c | 87 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) diff --git a/lib/tdb/man/tdbtool.8.xml b/lib/tdb/man/tdbtool.8.xml index 9a9b95e6a06..045cbde73dd 100644 --- a/lib/tdb/man/tdbtool.8.xml +++ b/lib/tdb/man/tdbtool.8.xml @@ -159,6 +159,16 @@ + + + KEY + DATA + + Store (replace) a record in the + current database where key and data are in hex format. + + + KEY diff --git a/lib/tdb/tools/tdbtool.c b/lib/tdb/tools/tdbtool.c index beb3af18e23..e3535b93c7c 100644 --- a/lib/tdb/tools/tdbtool.c +++ b/lib/tdb/tools/tdbtool.c @@ -48,6 +48,7 @@ enum commands { CMD_DUMP, CMD_INSERT, CMD_MOVE, + CMD_STOREHEX, CMD_STORE, CMD_SHOW, CMD_KEYS, @@ -83,6 +84,7 @@ COMMAND_TABLE cmd_table[] = { {"dump", CMD_DUMP}, {"insert", CMD_INSERT}, {"move", CMD_MOVE}, + {"storehex", CMD_STOREHEX}, {"store", CMD_STORE}, {"show", CMD_SHOW}, {"keys", CMD_KEYS}, @@ -229,6 +231,7 @@ static void help(void) " info : print summary info about the database\n" " insert key data : insert a record\n" " move key file : move a record to a destination tdb\n" +" storehex key data : store a record (replace), key/value in hex format\n" " store key data : store a record (replace)\n" " show key : show a record by key\n" " delete key : delete a record by key\n" @@ -346,6 +349,86 @@ static void store_tdb(char *keyname, size_t keylen, char* data, size_t datalen) } } +static bool hexchar(char c, uint8_t *v) +{ + if ((c >= '0') && (c <= '9')) { + *v = (c - '0'); + return true; + } + if ((c >= 'A') && (c <= 'F')) { + *v = (c - 'A' + 10); + return true; + } + if ((c >= 'a') && (c <= 'f')) { + *v = (c - 'a' + 10); + return true; + } + return false; +} + +static bool parse_hex(const char *src, size_t srclen, uint8_t *dst) +{ + size_t i=0; + + if ((srclen % 2) != 0) { + return false; + } + + while (i