s3: Properly print binary values "net cache"
authorVolker Lendecke <vl@samba.org>
Sun, 28 Nov 2010 12:14:38 +0000 (13:14 +0100)
committerVolker Lendecke <vlendec@samba.org>
Sun, 28 Nov 2010 14:03:26 +0000 (15:03 +0100)
Autobuild-User: Volker Lendecke <vlendec@samba.org>
Autobuild-Date: Sun Nov 28 15:03:26 CET 2010 on sn-devel-104

source3/utils/net_cache.c

index 4339094489b5891868fb8a9b1c2854093dc00977..88aff4e16ec73b0d9d641efb73304c4ac9b30d68 100644 (file)
  * (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;
 }