1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-02 09:47:23 +03:00

s3: Properly print binary values "net cache"

Autobuild-User: Volker Lendecke <vlendec@samba.org>
Autobuild-Date: Sun Nov 28 15:03:26 CET 2010 on sn-devel-104
This commit is contained in:
Volker Lendecke 2010-11-28 13:14:38 +01:00 committed by Volker Lendecke
parent 1a91fe90b6
commit c69b1edcb9

View File

@ -33,11 +33,13 @@
* (print_cache_entry) and to flush it (delete_cache_entry).
* Both of them are defined by first arg of gencache_iterate() routine.
*/
static void print_cache_entry(const char* keystr, const char* datastr,
static void print_cache_entry(const char* keystr, DATA_BLOB value,
const time_t timeout, void* dptr)
{
char *timeout_str;
char *alloc_str = NULL;
const char *datastr;
char *datastr_free = NULL;
time_t now_t = time(NULL);
struct tm timeout_tm, now_tm;
struct tm *ptimeout_tm, *pnow_tm;
@ -69,6 +71,18 @@ static void print_cache_entry(const char* keystr, const char* datastr,
timeout_str = alloc_str;
}
datastr = (char *)value.data;
if ((value.length > 0) && (value.data[value.length-1] != '\0')) {
datastr_free = talloc_asprintf(
talloc_tos(), "<binary length %d>",
(int)value.length);
datastr = datastr_free;
if (datastr == NULL) {
datastr = "<binary>";
}
}
d_printf(_("Key: %s\t Timeout: %s\t Value: %s %s\n"), keystr,
timeout_str, datastr, timeout > now_t ? "": _("(expired)"));
@ -218,7 +232,7 @@ static int net_cache_del(struct net_context *c, int argc, const char **argv)
static int net_cache_get(struct net_context *c, int argc, const char **argv)
{
const char* keystr = argv[0];
char* valuestr = NULL;
DATA_BLOB value;
time_t timeout;
if (argc < 1 || c->display_usage) {
@ -228,9 +242,9 @@ static int net_cache_get(struct net_context *c, int argc, const char **argv)
return -1;
}
if (gencache_get(keystr, &valuestr, &timeout)) {
print_cache_entry(keystr, valuestr, timeout, NULL);
SAFE_FREE(valuestr);
if (gencache_get_data_blob(keystr, &value, &timeout, NULL)) {
print_cache_entry(keystr, value, timeout, NULL);
SAFE_FREE(value.data);
return 0;
}
@ -258,7 +272,7 @@ static int net_cache_search(struct net_context *c, int argc, const char **argv)
}
pattern = argv[0];
gencache_iterate(print_cache_entry, NULL, pattern);
gencache_iterate_blobs(print_cache_entry, NULL, pattern);
return 0;
}
@ -282,7 +296,7 @@ static int net_cache_list(struct net_context *c, int argc, const char **argv)
_("List all cache entries."));
return 0;
}
gencache_iterate(print_cache_entry, NULL, pattern);
gencache_iterate_blobs(print_cache_entry, NULL, pattern);
return 0;
}