s3:fix bug #6371, unsuccessful net conf setparm leaves empty share
authorMichael Adam <obnox@samba.org>
Sun, 17 May 2009 20:15:02 +0000 (22:15 +0200)
committerMichael Adam <obnox@samba.org>
Mon, 18 May 2009 08:58:19 +0000 (10:58 +0200)
Wrap creation of share and setting of parameter into a transaction.

Michael

source/utils/net_conf.c

index 57b9d512028f9ea0d91eaff5649ba2dfc637cd76..2962af990ccdbc88cfa5111def78f39c9d9c95b1 100644 (file)
@@ -753,12 +753,19 @@ static int net_conf_setparm(struct smbconf_ctx *conf_ctx,
        }
        value_str = argv[2];
 
+       werr = smbconf_transaction_start(conf_ctx);
+       if (!W_ERROR_IS_OK(werr)) {
+               d_printf("error starting transaction: %s\n",
+                        dos_errstr(werr));
+               goto done;
+       }
+
        if (!smbconf_share_exists(conf_ctx, service)) {
                werr = smbconf_create_share(conf_ctx, service);
                if (!W_ERROR_IS_OK(werr)) {
                        d_fprintf(stderr, "Error creating share '%s': %s\n",
                                  service, dos_errstr(werr));
-                       goto done;
+                       goto cancel;
                }
        }
 
@@ -767,10 +774,25 @@ static int net_conf_setparm(struct smbconf_ctx *conf_ctx,
        if (!W_ERROR_IS_OK(werr)) {
                d_fprintf(stderr, "Error setting value '%s': %s\n",
                          param, dos_errstr(werr));
-               goto done;
+               goto cancel;
        }
 
-       ret = 0;
+       werr = smbconf_transaction_commit(conf_ctx);
+       if (!W_ERROR_IS_OK(werr)) {
+               d_printf("error committing transaction: %s\n",
+                        dos_errstr(werr));
+       } else {
+               ret = 0;
+       }
+
+       goto done;
+
+cancel:
+       werr = smbconf_transaction_cancel(conf_ctx);
+       if (!W_ERROR_IS_OK(werr)) {
+               d_printf("error cancelling transaction: %s\n",
+                        dos_errstr(werr));
+       }
 
 done:
        TALLOC_FREE(mem_ctx);