s3-net: add command registry convert
authorGregor Beck <gbeck@sernet.de>
Wed, 29 Sep 2010 13:06:05 +0000 (15:06 +0200)
committerGregor Beck <gbeck@sernet.de>
Wed, 29 Sep 2010 13:18:28 +0000 (15:18 +0200)
source3/utils/net_registry.c

index 657a5617c42717c51913ceb34538f77086ae1d31..f0db17a8bcd9f805ef1e9afa3aed38923480dcac 100644 (file)
@@ -25,6 +25,7 @@
 #include "include/g_lock.h"
 #include "registry/reg_import.h"
 #include "registry/reg_format.h"
+#include <assert.h>
 
 /*
  *
@@ -1021,6 +1022,60 @@ done:
 /**@}*/
 
 /******************************************************************************/
+/**
+ * @defgroup net_registry_convert Convert
+ * @ingroup net_registry
+ * @{
+ */
+
+static int net_registry_convert(struct net_context *c, int argc,
+                              const char **argv)
+{
+       int ret;
+       void* mem_ctx;
+       const char* in_opt  = NULL;
+       const char* out_opt = NULL;
+
+       if (argc < 2 || argc > 4|| c->display_usage) {
+               d_printf("%s\n%s",
+                        "Usage:",
+                        "net registry convert <in> <out> [in_opt] [out_opt]\n"
+                          "net registry convert <in> <out> [out_opt]\n");
+               d_printf("%s\n%s",
+                        "Example:",
+                        "net registry convert in.reg out.reg regedit4,enc=CP1252\n");
+               return -1;
+       }
+
+       mem_ctx = talloc_stackframe();
+
+       switch (argc ) {
+       case 2:
+               break;
+       case 3:
+               out_opt = argv[2];
+               break;
+       case 4:
+               out_opt = argv[3];
+               in_opt  = argv[2];
+               break;
+       default:
+               assert(false);
+       }
+
+
+       ret = reg_parse_file(argv[0], (struct reg_parse_callback*)
+                            reg_format_file(mem_ctx, argv[1], out_opt),
+                            in_opt);
+
+       talloc_free(mem_ctx);
+
+       return ret;
+}
+/**@}*/
+
+/******************************************************************************/
+
 int net_registry(struct net_context *c, int argc, const char **argv)
 {
        int ret = -1;
@@ -1138,6 +1193,14 @@ int net_registry(struct net_context *c, int argc, const char **argv)
                        "net registry export\n"
                           "    Export .reg file"
                },
+               {
+                       "convert",
+                       net_registry_convert,
+                       NET_TRANSPORT_LOCAL,
+                       "Convert .reg file",
+                       "net registry convert\n"
+                          "    Convert .reg file"
+               },
        { NULL, NULL, 0, NULL, NULL }
        };