[SCM] Samba Shared Repository - branch master updated
Michael Adam
obnox at samba.org
Tue Oct 18 14:33:02 MDT 2011
The branch, master has been updated
via 47aa9ed lib/util: skip single hex digit at the end of the input sting - fix potential segfault
via cb47890 lib/util: fix function header comment to strhex_to_str()
via 5d91a26 lib/util: untangle assignent from check in strhex_to_str()
via 196fd14 s3-util: dbwrap_tool: add fetch fuctions for hex and string
via 140b5d7 s3-util: dbwrap_tool: add store hex function
via 4874e1f selftest:Samba3: fix signature for check_or_start()
via dd6b413 selftest:Samba3: fix a message printed when starting winbindd
from 605d7d9 pdb-interface: Do not use unid_t here
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 47aa9ed82f67758c3b4d9ab46dd8dd65508a10eb
Author: Michael Adam <obnox at samba.org>
Date: Tue Oct 18 18:10:00 2011 +0200
lib/util: skip single hex digit at the end of the input sting - fix potential segfault
The second of two digits was read without checking for the length of the input
string. For a non-zero-terminated input string, this might have caused a
segfault.
Autobuild-User: Michael Adam <obnox at samba.org>
Autobuild-Date: Tue Oct 18 22:32:59 CEST 2011 on sn-devel-104
commit cb47890cf2734afff502cf8b95635ebc75bc5974
Author: Michael Adam <obnox at samba.org>
Date: Tue Oct 18 18:07:54 2011 +0200
lib/util: fix function header comment to strhex_to_str()
The description did not match the function's behaviour.
commit 5d91a2680e594d47ed137b45f79738bddb641cea
Author: Michael Adam <obnox at samba.org>
Date: Tue Oct 18 18:03:10 2011 +0200
lib/util: untangle assignent from check in strhex_to_str()
commit 196fd147888efec3e1f79efd1e54f5a99e3dd544
Author: Björn Baumbach <bb at sernet.de>
Date: Mon Oct 17 16:08:38 2011 +0200
s3-util: dbwrap_tool: add fetch fuctions for hex and string
Signed-off-by: Michael Adam <obnox at samba.org>
commit 140b5d790a8d87eb59e117ad25c7c441f887d6fc
Author: Björn Baumbach <bb at sernet.de>
Date: Mon Oct 17 16:05:52 2011 +0200
s3-util: dbwrap_tool: add store hex function
Allows the user to store hex blobs in a tdb.
Signed-off-by: Michael Adam <obnox at samba.org>
commit 4874e1f5b3a4b959050012d5135be7c1df38552b
Author: Michael Adam <obnox at samba.org>
Date: Tue Oct 18 11:37:25 2011 +0200
selftest:Samba3: fix signature for check_or_start()
commit dd6b413a57f76abb92110fcce67c957084db80b3
Author: Michael Adam <obnox at samba.org>
Date: Tue Oct 18 11:34:22 2011 +0200
selftest:Samba3: fix a message printed when starting winbindd
-----------------------------------------------------------------------
Summary of changes:
lib/util/util.c | 28 ++++++-----
selftest/target/Samba3.pm | 4 +-
source3/utils/dbwrap_tool.c | 107 +++++++++++++++++++++++++++++++++++++++++-
3 files changed, 122 insertions(+), 17 deletions(-)
Changeset truncated at 500 lines:
diff --git a/lib/util/util.c b/lib/util/util.c
index b700f37..133bd0d 100644
--- a/lib/util/util.c
+++ b/lib/util/util.c
@@ -689,15 +689,15 @@ _PUBLIC_ _PURE_ size_t count_chars(const char *s, char c)
}
/**
- Routine to get hex characters and turn them into a 16 byte array.
- the array can be variable length, and any non-hex-numeric
- characters are skipped. "0xnn" or "0Xnn" is specially catered
- for.
-
- valid examples: "0A5D15"; "0x15, 0x49, 0xa2"; "59\ta9\te3\n"
-
-
-**/
+ * Routine to get hex characters and turn them into a byte array.
+ * the array can be variable length.
+ * - "0xnn" or "0Xnn" is specially catered for.
+ * - The first non-hex-digit character (apart from possibly leading "0x"
+ * finishes the conversion and skips the rest of the input.
+ * - A single hex-digit character at the end of the string is skipped.
+ *
+ * valid examples: "0A5D15"; "0x123456"
+ */
_PUBLIC_ size_t strhex_to_str(char *p, size_t p_len, const char *strhex, size_t strhex_len)
{
size_t i = 0;
@@ -711,14 +711,18 @@ _PUBLIC_ size_t strhex_to_str(char *p, size_t p_len, const char *strhex, size_t
i += 2; /* skip two chars */
}
- for (; i < strhex_len && strhex[i] != 0; i++) {
- if (!(p1 = strchr(hexchars, toupper((unsigned char)strhex[i]))))
+ for (; i+1 < strhex_len && strhex[i] != 0 && strhex[i+1] != 0; i++) {
+ p1 = strchr(hexchars, toupper((unsigned char)strhex[i]));
+ if (p1 == NULL) {
break;
+ }
i++; /* next hex digit */
- if (!(p2 = strchr(hexchars, toupper((unsigned char)strhex[i]))))
+ p2 = strchr(hexchars, toupper((unsigned char)strhex[i]));
+ if (p2 == NULL) {
break;
+ }
/* get the two nybbles */
hinybble = PTR_DIFF(p1, hexchars);
diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
index c17455d..2f23ae3 100755
--- a/selftest/target/Samba3.pm
+++ b/selftest/target/Samba3.pm
@@ -556,7 +556,7 @@ sub read_pid($$)
return $pid;
}
-sub check_or_start($$$$) {
+sub check_or_start($$$$$) {
my ($self, $env_vars, $nmbd, $winbindd, $smbd) = @_;
unlink($env_vars->{NMBD_TEST_LOG});
@@ -646,7 +646,7 @@ sub check_or_start($$$$) {
@preargs = split(/ /, $ENV{WINBINDD_VALGRIND});
}
- print "Starting winbindd with config $env_vars->{SERVERCONFFILE})\n";
+ print "Starting winbindd with config $env_vars->{SERVERCONFFILE}\n";
exec(@preargs, Samba::bindir_path($self, "winbindd"), "-F", "--no-process-group", "--stdout", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start winbindd: $!");
}
diff --git a/source3/utils/dbwrap_tool.c b/source3/utils/dbwrap_tool.c
index 5d30c93..84ff3a1 100644
--- a/source3/utils/dbwrap_tool.c
+++ b/source3/utils/dbwrap_tool.c
@@ -30,7 +30,7 @@
typedef enum { OP_FETCH, OP_STORE, OP_DELETE, OP_ERASE, OP_LISTKEYS } dbwrap_op;
-typedef enum { TYPE_INT32, TYPE_UINT32, TYPE_STRING } dbwrap_type;
+typedef enum { TYPE_INT32, TYPE_UINT32, TYPE_STRING, TYPE_HEX } dbwrap_type;
static int dbwrap_tool_fetch_int32(struct db_context *db,
const char *keyname,
@@ -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)
@@ -124,6 +183,42 @@ static int dbwrap_tool_store_string(struct db_context *db,
return 0;
}
+static int dbwrap_tool_store_hex(struct db_context *db,
+ const char *keyname,
+ const char *data)
+{
+ NTSTATUS status;
+ DATA_BLOB datablob;
+ TDB_DATA tdbdata;
+ TALLOC_CTX *tmp_ctx = talloc_stackframe();
+
+ datablob = strhex_to_data_blob(tmp_ctx, data);
+ if(strlen(data) > 0 && datablob.length == 0) {
+ d_fprintf(stderr,
+ "ERROR: could not convert hex string to data blob\n"
+ " Not a valid hex string?\n");
+ talloc_free(tmp_ctx);
+ return -1;
+ }
+
+ tdbdata.dptr = (unsigned char *)datablob.data;
+ tdbdata.dsize = datablob.length;
+
+ status = dbwrap_trans_store_bystring(db, keyname,
+ tdbdata,
+ TDB_REPLACE);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_fprintf(stderr,
+ "ERROR: could not store string key '%s': %s\n",
+ keyname, nt_errstr(status));
+ talloc_free(tmp_ctx);
+ return -1;
+ }
+
+ talloc_free(tmp_ctx);
+ return 0;
+}
+
static int dbwrap_tool_delete(struct db_context *db,
const char *keyname,
const char *data)
@@ -213,9 +308,12 @@ 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 },
+ { OP_STORE, TYPE_HEX, dbwrap_tool_store_hex },
{ OP_DELETE, TYPE_INT32, dbwrap_tool_delete },
{ OP_ERASE, TYPE_INT32, dbwrap_tool_erase },
{ OP_LISTKEYS, TYPE_INT32, dbwrap_tool_listkeys },
@@ -280,7 +378,7 @@ int main(int argc, const char **argv)
d_fprintf(stderr,
"USAGE: %s <database> <op> [<key> [<type> [<value>]]]\n"
" ops: fetch, store, delete, erase, listkeys\n"
- " types: int32, uint32, string\n",
+ " types: int32, uint32, string, hex\n",
argv[0]);
goto done;
}
@@ -343,9 +441,12 @@ int main(int argc, const char **argv)
type = TYPE_UINT32;
} else if (strcmp(keytype, "string") == 0) {
type = TYPE_STRING;
+ } else if (strcmp(keytype, "hex") == 0) {
+ type = TYPE_HEX;
} else {
d_fprintf(stderr, "ERROR: invalid type '%s' specified.\n"
- " supported types: int32, uint32, string\n",
+ " supported types: int32, uint32, "
+ "string, hex\n",
keytype);
goto done;
}
--
Samba Shared Repository
More information about the samba-cvs
mailing list