s4-dns: dlz_bind9: Fix ipv6 updates
[samba.git] / source3 / utils / net_registry_util.c
index 278377867aa8bd58df48ed0beeb0812ba325429f..2020a0a47372c120fe4f15f5fe027748b58d00db 100644 (file)
  */
 
 #include "includes.h"
+#include "registry.h"
 #include "utils/net_registry_util.h"
+#include "utils/net.h"
+#include "../libcli/registry/util_reg.h"
 
 void print_registry_key(const char *keyname, NTTIME *modtime)
 {
-       d_printf("Keyname   = %s\n", keyname);
-       d_printf("Modtime   = %s\n",
-                modtime
-                ? http_timestring(nt_time_to_unix(*modtime))
-                : "None");
+       const char *ts = _("None");
+       char *freeme = NULL;
+
+       if (modtime != 0) {
+               freeme = http_timestring(talloc_tos(),
+                                        nt_time_to_unix(*modtime));
+               ts = freeme;
+       }
+
+       d_printf(_("Keyname   = %s\n"), keyname);
+       d_printf(_("Modtime   = %s\n"), ts);
        d_printf("\n");
+
+       TALLOC_FREE(freeme);
 }
 
 void print_registry_value(const struct registry_value *valvalue, bool raw)
 {
        if (!raw) {
-               d_printf("Type       = %s\n",
-                        reg_type_lookup(valvalue->type));
+               d_printf(_("Type       = %s\n"),
+                        str_regtype(valvalue->type));
        }
        switch(valvalue->type) {
-       case REG_DWORD:
+       case REG_DWORD: {
+               uint32_t v = 0;
+               if (valvalue->data.length >= 4) {
+                       v = IVAL(valvalue->data.data, 0);
+               }
                if (!raw) {
-                       d_printf("Value      = ");
+                       d_printf(_("Value      = "));
                }
-               d_printf("%d\n", valvalue->v.dword);
+               d_printf("%u\n", v);
                break;
+       }
        case REG_SZ:
-       case REG_EXPAND_SZ:
+       case REG_EXPAND_SZ: {
+               const char *s;
+
+               if (!pull_reg_sz(talloc_tos(), &valvalue->data, &s)) {
+                       break;
+               }
                if (!raw) {
-                       d_printf("Value      = \"");
+                       d_printf(_("Value      = \""));
                }
-               d_printf("%s", valvalue->v.sz.str);
+               d_printf("%s", s);
                if (!raw) {
                        d_printf("\"");
                }
                d_printf("\n");
                break;
+       }
        case REG_MULTI_SZ: {
                uint32 j;
-               for (j = 0; j < valvalue->v.multi_sz.num_strings; j++) {
+               const char **a;
+
+               if (!pull_reg_multi_sz(talloc_tos(), &valvalue->data, &a)) {
+                       break;
+               }
+               for (j = 0; a[j] != NULL; j++) {
                        if (!raw) {
-                               d_printf("Value[%3.3d] = \"", j);
+                               d_printf(_("Value[%3.3d] = \""), j);
                        }
-                       d_printf("%s", valvalue->v.multi_sz.strings[j]);
+                       d_printf("%s", a[j]);
                        if (!raw) {
                                d_printf("\"");
                        }
@@ -72,15 +99,15 @@ void print_registry_value(const struct registry_value *valvalue, bool raw)
        }
        case REG_BINARY:
                if (!raw) {
-                       d_printf("Value      = ");
+                       d_printf(_("Value      = "));
                }
-               d_printf("%d bytes\n", (int)valvalue->v.binary.length);
+               d_printf(_("%d bytes\n"), (int)valvalue->data.length);
                break;
        default:
                if (!raw) {
-                       d_printf("Value      = ");
+                       d_printf(_("Value      = "));
                }
-               d_printf("<unprintable>\n");
+               d_printf(_("<unprintable>\n"));
                break;
        }
 }
@@ -88,7 +115,7 @@ void print_registry_value(const struct registry_value *valvalue, bool raw)
 void print_registry_value_with_name(const char *valname,
                                    const struct registry_value *valvalue)
 {
-       d_printf("Valuename  = %s\n", valname);
+       d_printf(_("Valuename  = %s\n"), valname);
        print_registry_value(valvalue, false);
        d_printf("\n");
 }
@@ -96,7 +123,9 @@ void print_registry_value_with_name(const char *valname,
 /**
  * Split path into hive name and subkeyname
  * normalizations performed:
- *  - convert '/' to '\\'
+ *  - if the path contains no '\\' characters,
+ *    assume that the legacy format of using '/'
+ *    as a separator is used and  convert '/' to '\\'
  *  - strip trailing '\\' chars
  */
 WERROR split_hive_key(TALLOC_CTX *ctx, const char *path, char **hivename,
@@ -113,7 +142,12 @@ WERROR split_hive_key(TALLOC_CTX *ctx, const char *path, char **hivename,
                return WERR_INVALID_PARAM;
        }
 
-       *hivename = talloc_string_sub(ctx, path, "/", "\\");
+       if (strchr(path, '\\') == NULL) {
+               *hivename = talloc_string_sub(ctx, path, "/", "\\");
+       } else {
+               *hivename = talloc_strdup(ctx, path);
+       }
+
        if (*hivename == NULL) {
                return WERR_NOMEM;
        }