At http://samba.sernet.de/ma/bzr/SAMBA_3_0-registry.bzr/

------------------------------------------------------------
revno: 5318
revision-id: [EMAIL PROTECTED]
parent: [EMAIL PROTECTED]
committer: Michael Adam <[EMAIL PROTECTED]>
branch nick: SAMBA_3_0-registry.bzr
timestamp: Mon 2007-04-02 12:48:21 +0200
message:
  add real writing to registry to import function.
  output is preserved and made available though
  new "--test|-T" switch to the net command.
modified:
  source/utils/net.c             net.c-20060530022628-046c7d5fbf0eceac
  source/utils/net.h             net.h-20060530022628-645259ee28ff73bf
  source/utils/net_conf.c        net_conf.c-20070228210606-uywdn1acd043wgvt-1
=== modified file 'source/utils/net.c'
--- a/source/utils/net.c        2007-03-14 23:18:34 +0000
+++ b/source/utils/net.c        2007-04-02 10:48:21 +0000
@@ -85,6 +85,7 @@
 int opt_timestamps = 0;
 const char *opt_exclude = NULL;
 const char *opt_destination = NULL;
+BOOL opt_testmode = False;
 
 BOOL opt_have_ip = False;
 struct in_addr opt_dest_ip;
@@ -913,6 +914,7 @@
                {"machine-pass",'P', POPT_ARG_NONE,   &opt_machine_pass},
                {"myworkgroup", 'W', POPT_ARG_STRING, &opt_workgroup},
                {"verbose",     'v', POPT_ARG_NONE,   &opt_verbose},
+               {"test",        'T', POPT_ARG_NONE,   &opt_testmode},
                /* Options for 'net groupmap set' */
                {"local",       'L', POPT_ARG_NONE,   &opt_localgroup},
                {"domain",      'D', POPT_ARG_NONE,   &opt_domaingroup},

=== modified file 'source/utils/net.h'
--- a/source/utils/net.h        2006-09-28 21:20:31 +0000
+++ b/source/utils/net.h        2007-04-02 10:48:21 +0000
@@ -114,6 +114,7 @@
 extern int opt_timestamps;
 extern const char *opt_exclude;
 extern const char *opt_destination;
+extern BOOL opt_testmode;
 
 extern BOOL opt_have_ip;
 extern struct in_addr opt_dest_ip;

=== modified file 'source/utils/net_conf.c'
--- a/source/utils/net_conf.c   2007-04-02 08:31:45 +0000
+++ b/source/utils/net_conf.c   2007-04-02 10:48:21 +0000
@@ -52,8 +52,8 @@
 
 static int net_conf_import_usage(int argc, const char**argv)
 {
-       d_printf("USAGE: net conf import [-t] <filename> [<servicename>]\n"
-                "\t-t             testmode - do not act, just print "
+       d_printf("USAGE: net conf import [--test|-T] <filename> 
[<servicename>]\n"
+                "\t[--test|-T]    testmode - do not act, just print "
                                   "what would be done\n"
                 "\t<servicename>  only import service <servicename>, "
                                   "ignore the rest\n");
@@ -285,16 +285,43 @@
 }
 
 static int import_process_service(TALLOC_CTX *ctx, 
-                                 struct share_params *share, 
-                                 BOOL testmode) 
+                                 struct share_params *share)
 {
        int ret = -1;
        struct parm_struct *parm;
        int pnum = 0;
-
-       d_printf("TEST: snum    %i : [%s]\n", share->service,
-                (share->service == GLOBAL_SECTION_SNUM)?
-                GLOBAL_NAME : lp_servicename(share->service));
+       const char *servicename;
+       struct registry_key *key;
+       WERROR werr;
+       const char *valtype = NULL;
+       char *valstr = NULL;
+
+       servicename = (share->service == GLOBAL_SECTION_SNUM)?
+               GLOBAL_NAME : lp_servicename(share->service);
+
+       if (opt_testmode) {
+               d_printf("TEST: snum    %i : [%s]\n", share->service, 
+                       servicename);
+       }
+       else {
+               if (share->service == GLOBAL_SECTION_SNUM) {
+                       werr = reg_open_path(ctx, KEY_SMBCONF, REG_KEY_WRITE,
+                                            get_root_nt_token(), &key);
+                       if (!W_ERROR_IS_OK(werr)) {
+                               d_fprintf(stderr, 
+                                       "Error opening registry path '%s': 
%s\n",
+                                       KEY_SMBCONF, dos_errstr(werr));
+                               goto done;
+                       }
+               }
+               else {
+                       werr = reg_createkey_internal(ctx, servicename, &key);
+                       if (!W_ERROR_IS_OK(werr)) {
+                               goto done;
+                       }
+               }
+       }
+
        while ((parm = lp_next_parameter(share->service, &pnum, 0)))
        {
                void *ptr = parm->ptr;
@@ -308,71 +335,96 @@
                        ptr = lp_local_ptr(share->service, ptr);
                }
 
-               if (parm->type != P_SEP) {
-                       d_printf("TEST: param %3d : %s = ", pnum, 
-                                parm->label);
-               }
+               valtype = "sz";
+
                switch (parm->type) {
                case P_CHAR:
-                       d_printf("%c\n", *(char *)ptr);
+                       valstr = talloc_asprintf(ctx, "%c", *(char *)ptr);
                        break;
                case P_STRING:
                case P_USTRING:
-                       d_printf("%s\n", *(char **)ptr);
+                       valstr = talloc_asprintf(ctx, "%s", *(char **)ptr);
                        break;
                case P_GSTRING:
                case P_UGSTRING:
-                       d_printf("%s\n", (char *)ptr);
+                       valstr = talloc_asprintf(ctx, "%s", (char *)ptr);
                        break;
                case P_BOOL:
-                       d_printf("%s\n", BOOLSTR(*(BOOL *)ptr));
+                       valstr = talloc_asprintf(ctx, "%s", 
+                                               BOOLSTR(*(BOOL *)ptr));
                        break;
                case P_BOOLREV:
-                       d_printf("%s\n", BOOLSTR(!*(BOOL *)ptr));
+                       valstr = talloc_asprintf(ctx, "%s", 
+                                               BOOLSTR(!*(BOOL *)ptr));
                        break;
                case P_ENUM:
                        for (i = 0; parm->enum_list[i].name; i++) {
                                if (*(int *)ptr == 
                                    parm->enum_list[i].value) 
                                {
-                                       d_printf("%s\n",
+                                       valstr = talloc_asprintf(ctx, "%s",
                                                 parm->enum_list[i].name);
                                        break;
                                }
                        }
                        break;
                case P_OCTAL:
-                       d_printf("%s\n", octal_string(*(int *)ptr));
+                       talloc_asprintf(ctx, "%s", octal_string(*(int *)ptr));
                        break;
                case P_LIST:
+                       valstr = talloc_asprintf(ctx, "");
                        if ((char ***)ptr && *(char ***)ptr) {
                                char **list = *(char ***)ptr;
                                for (; *list; list++) {
                                        /* surround strings with whitespace 
                                         * in double quotes */
-                                       if ( strchr_m( *list, ' ' ) )
-                                               d_printf("\"%s\"%s", *list, 
-                                                        ((*(list+1))?", ":""));
-                                       else
-                                               d_printf("%s%s", *list, 
-                                                        ((*(list+1))?", ":""));
+                                       if (strchr_m(*list, ' '))
+                                       {
+                                               valstr = talloc_asprintf_append(
+                                                       valstr, "\"%s\"%s", 
+                                                       *list, 
+                                                        ((*(list+1))?", ":""));
+                                       }
+                                       else {
+                                               valstr = talloc_asprintf_append(
+                                                       valstr, "%s%s", *list, 
+                                                        ((*(list+1))?", ":""));
+                                       }
                                }
                        }
-                       d_printf("\n");
                        break;
                case P_INTEGER:
-                       d_printf("%d\n", *(int *)ptr);
+                       valtype = "dword";
+                       talloc_asprintf(ctx, "%d", *(int *)ptr);
                        break;
                case P_SEP:
                        break;
                default:
-                       d_printf("<type unimplemented>\n");
+                       valstr = talloc_asprintf(ctx, "<type unimplemented>\n");
                        break;
                }
-       }
-       d_printf("TEST: -----------\n");
+
+               if (parm->type != P_SEP) {
+                       if (opt_testmode) {
+                               d_printf("TEST: param %3d : %s = %s\n", 
+                                       pnum, parm->label, valstr);
+                       }
+                       else {
+                               werr = reg_setvalue_internal(key, parm->label, 
+                                                            valtype, valstr);
+                               if (!W_ERROR_IS_OK(werr)) {
+                                       goto done;
+                               }
+                       }
+               }
+       }
+
+       if (opt_testmode) {
+               d_printf("TEST: -----------\n");
+       }
 
        ret = 0;
+done:
        return ret;
 }
 
@@ -456,7 +508,6 @@
        struct share_iterator *shares;
        struct share_params *share;
        struct share_params global_share = { GLOBAL_SECTION_SNUM };
-       BOOL testmode = False;
 
        ctx = talloc_init("net_conf_import");
 
@@ -465,31 +516,11 @@
                default:
                        net_conf_import_usage(argc, argv);
                        goto done;
+               case 2:
+                       servicename = argv[1];
                case 1:
                        filename = argv[0];
                        break;
-               case 2:
-                       if (strequal(argv[0], "-t")) {
-                               testmode = True;
-                               filename = argv[1];
-                       }
-                       else {
-                               filename = argv[0];
-                               servicename = argv[1];
-                       }
-                       break;
-               case 3:
-                       servicename = argv[2];
-                       filename = argv[1];
-                       if (strequal(argv[0], "-t")) {
-                               testmode = True;
-                               filename = argv[1];
-                       }
-                       else {
-                               net_conf_import_usage(argc, argv);
-                               goto done;
-                       }
-                       break;
        }
 
        DEBUG(3,("net_conf_import: reading configuration from file %s.\n",
@@ -509,7 +540,7 @@
 
        if ((servicename == NULL) || strequal(servicename, GLOBAL_NAME)) {
                service_found = True;
-               if (import_process_service(ctx, &global_share, testmode) != 0) {
+               if (import_process_service(ctx, &global_share) != 0) {
                        goto done;
                }
        }
@@ -528,7 +559,7 @@
                    || strequal(servicename, lp_servicename(share->service))) 
                {
                        service_found = True;
-                       if (import_process_service(ctx, share, testmode)!= 0) {
+                       if (import_process_service(ctx, share)!= 0) {
                                goto done;
                        }
                }

Reply via email to