net_registry: split utility function of common interest out into util module.
authorMichael Adam <obnox@samba.org>
Fri, 4 Apr 2008 11:21:03 +0000 (13:21 +0200)
committerMichael Adam <obnox@samba.org>
Fri, 4 Apr 2008 15:05:00 +0000 (17:05 +0200)
Michael
(This used to be commit 3bf890783fadd245c59280173627a6caca2dbefe)

source3/Makefile.in
source3/utils/net_registry.c
source3/utils/net_registry_util.c [new file with mode: 0644]
source3/utils/net_registry_util.h [new file with mode: 0644]

index 60f03e4363f5228fdd21c5c41c676a0b13fe4f10..6846d80c0b81899781fd1632b61a6b2dcb5b7d76 100644 (file)
@@ -844,6 +844,7 @@ NET_OBJ1 = utils/net.o utils/net_ads.o utils/net_help.o \
           $(PASSWD_UTIL_OBJ) utils/net_dns.o utils/net_ads_gpo.o \
           utils/net_conf.o \
           utils/net_registry.o \
+          utils/net_registry_util.o \
           auth/token_util.o utils/net_dom.o nsswitch/wb_client.o
 
 NET_OBJ = $(NET_OBJ1) $(PARAM_WITHOUT_REG_OBJ) $(SECRETS_OBJ) $(LIBSMB_OBJ) \
index 3d245007749f8292463917d368b482e476be552d..f21a1603cf3ee55ab975c0f53c04a654e618859d 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "includes.h"
 #include "utils/net.h"
+#include "utils/net_registry_util.h"
 
 
 /*
  *
  */
 
-static 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");
-       d_printf("\n");
-}
-
-static void print_registry_value(const char *valname,
-                                const struct registry_value *valvalue)
-{
-       d_printf("Valuename  = %s\n", valname);
-       d_printf("Type       = %s\n",
-                reg_type_lookup(valvalue->type));
-       switch(valvalue->type) {
-       case REG_DWORD:
-               d_printf("Value      = %d\n", valvalue->v.dword);
-               break;
-       case REG_SZ:
-       case REG_EXPAND_SZ:
-               d_printf("Value      = \"%s\"\n", valvalue->v.sz.str);
-               break;
-       case REG_MULTI_SZ: {
-               uint32 j;
-               for (j = 0; j < valvalue->v.multi_sz.num_strings; j++) {
-                       d_printf("Value[%3.3d] = \"%s\"\n", j,
-                                valvalue->v.multi_sz.strings[j]);
-               }
-               break;
-       }
-       case REG_BINARY:
-               d_printf("Value      = %d bytes\n",
-                        (int)valvalue->v.binary.length);
-               break;
-       default:
-               d_printf("Value      = <unprintable>\n");
-               break;
-       }
-       d_printf("\n");
-}
-
-/**
- * Split path into hive name and subkeyname
- * normalizations performed:
- *  - convert '/' to '\\'
- *  - strip trailing '\\' chars
- */
-static WERROR split_hive_key(TALLOC_CTX *ctx, const char *path,
-                            char **hivename, const char **subkeyname)
-{
-       char *p;
-
-       if ((path == NULL) || (hivename == NULL) || (subkeyname == NULL)) {
-               return WERR_INVALID_PARAM;
-       }
-
-       if (strlen(path) == 0) {
-               return WERR_INVALID_PARAM;
-       }
-
-       *hivename = talloc_string_sub(ctx, path, "/", "\\");
-       if (*hivename == NULL) {
-               return WERR_NOMEM;
-       }
-
-       /* strip trailing '\\' chars */
-       p = strrchr(*hivename, '\\');
-       while ((p != NULL) && (p[1] == '\0')) {
-               *p = '\0';
-               p = strrchr(*hivename, '\\');
-       }
-
-       p = strchr(*hivename, '\\');
-
-       if ((p == NULL) || (*p == '\0')) {
-               /* just the hive - no subkey given */
-               *subkeyname = "";
-       } else {
-               *p = '\0';
-               *subkeyname = p+1;
-       }
-
-       return WERR_OK;
-}
-
 /**
  * split given path into hive and remaining path and open the hive key
  */
diff --git a/source3/utils/net_registry_util.c b/source3/utils/net_registry_util.c
new file mode 100644 (file)
index 0000000..b1d0c77
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * Samba Unix/Linux SMB client library
+ * Distributed SMB/CIFS Server Management Utility
+ * registry utility functions
+ *
+ * Copyright (C) Michael Adam 2008
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "includes.h"
+#include "utils/net_registry_util.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");
+       d_printf("\n");
+}
+
+void print_registry_value(const char *valname,
+                         const struct registry_value *valvalue)
+{
+       d_printf("Valuename  = %s\n", valname);
+       d_printf("Type       = %s\n",
+                reg_type_lookup(valvalue->type));
+       switch(valvalue->type) {
+       case REG_DWORD:
+               d_printf("Value      = %d\n", valvalue->v.dword);
+               break;
+       case REG_SZ:
+       case REG_EXPAND_SZ:
+               d_printf("Value      = \"%s\"\n", valvalue->v.sz.str);
+               break;
+       case REG_MULTI_SZ: {
+               uint32 j;
+               for (j = 0; j < valvalue->v.multi_sz.num_strings; j++) {
+                       d_printf("Value[%3.3d] = \"%s\"\n", j,
+                                valvalue->v.multi_sz.strings[j]);
+               }
+               break;
+       }
+       case REG_BINARY:
+               d_printf("Value      = %d bytes\n",
+                        (int)valvalue->v.binary.length);
+               break;
+       default:
+               d_printf("Value      = <unprintable>\n");
+               break;
+       }
+       d_printf("\n");
+}
+
+/**
+ * Split path into hive name and subkeyname
+ * normalizations performed:
+ *  - convert '/' to '\\'
+ *  - strip trailing '\\' chars
+ */
+WERROR split_hive_key(TALLOC_CTX *ctx, const char *path, char **hivename,
+                     const char **subkeyname)
+{
+       char *p;
+
+       if ((path == NULL) || (hivename == NULL) || (subkeyname == NULL)) {
+               return WERR_INVALID_PARAM;
+       }
+
+       if (strlen(path) == 0) {
+               return WERR_INVALID_PARAM;
+       }
+
+       *hivename = talloc_string_sub(ctx, path, "/", "\\");
+       if (*hivename == NULL) {
+               return WERR_NOMEM;
+       }
+
+       /* strip trailing '\\' chars */
+       p = strrchr(*hivename, '\\');
+       while ((p != NULL) && (p[1] == '\0')) {
+               *p = '\0';
+               p = strrchr(*hivename, '\\');
+       }
+
+       p = strchr(*hivename, '\\');
+
+       if ((p == NULL) || (*p == '\0')) {
+               /* just the hive - no subkey given */
+               *subkeyname = "";
+       } else {
+               *p = '\0';
+               *subkeyname = p+1;
+       }
+
+       return WERR_OK;
+}
diff --git a/source3/utils/net_registry_util.h b/source3/utils/net_registry_util.h
new file mode 100644 (file)
index 0000000..5438f39
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Samba Unix/Linux SMB client library
+ * Distributed SMB/CIFS Server Management Utility
+ * registry utility functions
+ *
+ * Copyright (C) Michael Adam 2008
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __NET_REGISTRY_UTIL_H__
+#define __NET_REGISTRY_UTIL_H__
+
+void print_registry_key(const char *keyname, NTTIME *modtime);
+
+void print_registry_value(const char *valname,
+                         const struct registry_value *valvalue);
+
+/**
+ * Split path into hive name and subkeyname
+ * normalizations performed:
+ *  - convert '/' to '\\'
+ *  - strip trailing '\\' chars
+ */
+WERROR split_hive_key(TALLOC_CTX *ctx, const char *path, char **hivename,
+                     const char **subkeyname);
+
+#endif