summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/utils/net_cache.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/source3/utils/net_cache.c b/source3/utils/net_cache.c
index 4339094489..88aff4e16e 100644
--- a/source3/utils/net_cache.c
+++ b/source3/utils/net_cache.c
@@ -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;
}