diff options
author | Björn Baumbach <bb@sernet.de> | 2011-10-17 16:08:38 +0200 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2011-10-18 20:58:26 +0200 |
commit | 196fd147888efec3e1f79efd1e54f5a99e3dd544 (patch) | |
tree | d9199fff0d31a88fae7c786d88a32f1fd1018cb1 /source3/utils/dbwrap_tool.c | |
parent | 140b5d790a8d87eb59e117ad25c7c441f887d6fc (diff) | |
download | samba-196fd147888efec3e1f79efd1e54f5a99e3dd544.tar.gz |
s3-util: dbwrap_tool: add fetch fuctions for hex and string
Signed-off-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'source3/utils/dbwrap_tool.c')
-rw-r--r-- | source3/utils/dbwrap_tool.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/source3/utils/dbwrap_tool.c b/source3/utils/dbwrap_tool.c index dd744d00886..84ff3a1fe23 100644 --- a/source3/utils/dbwrap_tool.c +++ b/source3/utils/dbwrap_tool.c @@ -68,6 +68,65 @@ static int dbwrap_tool_fetch_uint32(struct db_context *db, } } +static int dbwrap_tool_fetch_string(struct db_context *db, + const char *keyname, + const char *data) +{ + TDB_DATA tdbdata; + NTSTATUS status; + TALLOC_CTX *tmp_ctx = talloc_stackframe(); + int ret; + + status = dbwrap_fetch_bystring(db, tmp_ctx, keyname, &tdbdata); + if (NT_STATUS_IS_OK(status)) { + d_printf("%*.*s\n", (int)tdbdata.dsize-1, (int)tdbdata.dsize-1, + tdbdata.dptr); + ret = 0; + } else { + d_fprintf(stderr, "ERROR: could not fetch string key '%s': " + "%s\n", nt_errstr(status), keyname); + ret = -1; + } + + talloc_free(tmp_ctx); + return ret; +} + +static int dbwrap_tool_fetch_hex(struct db_context *db, + const char *keyname, + const char *data) +{ + TDB_DATA tdbdata; + DATA_BLOB datablob; + NTSTATUS status; + TALLOC_CTX *tmp_ctx = talloc_stackframe(); + char *hex_string; + int ret; + + status = dbwrap_fetch_bystring(db, tmp_ctx, keyname, &tdbdata); + if (NT_STATUS_IS_OK(status)) { + datablob.data = tdbdata.dptr; + datablob.length = tdbdata.dsize; + + hex_string = data_blob_hex_string_upper(tmp_ctx, &datablob); + if (hex_string == NULL) { + d_fprintf(stderr, "ERROR: could not get hex string " + "from data blob\n"); + ret = -1; + } else { + d_printf("%s\n", hex_string); + ret = 0; + } + } else { + d_fprintf(stderr, "ERROR: could not fetch hex key '%s': " + "%s\n", nt_errstr(status), keyname); + ret = -1; + } + + talloc_free(tmp_ctx); + return ret; +} + static int dbwrap_tool_store_int32(struct db_context *db, const char *keyname, const char *data) @@ -249,6 +308,8 @@ struct dbwrap_op_dispatch_table { struct dbwrap_op_dispatch_table dispatch_table[] = { { OP_FETCH, TYPE_INT32, dbwrap_tool_fetch_int32 }, { OP_FETCH, TYPE_UINT32, dbwrap_tool_fetch_uint32 }, + { OP_FETCH, TYPE_STRING, dbwrap_tool_fetch_string }, + { OP_FETCH, TYPE_HEX, dbwrap_tool_fetch_hex }, { OP_STORE, TYPE_INT32, dbwrap_tool_store_int32 }, { OP_STORE, TYPE_UINT32, dbwrap_tool_store_uint32 }, { OP_STORE, TYPE_STRING, dbwrap_tool_store_string }, |