s3:make "net conf addshare" atomic by wrapping all writes in one transaction
authorMichael Adam <obnox@samba.org>
Fri, 29 Jan 2010 14:04:25 +0000 (15:04 +0100)
committerMichael Adam <obnox@samba.org>
Thu, 4 Feb 2010 09:08:04 +0000 (10:08 +0100)
Michael

source3/utils/net_conf.c

index ca3cb0bfda1fb9a98b18e3098e86035f0b6c5aa6..11fedc0a404ace118d5e6832d34a1d3e99112b4d 100644 (file)
@@ -669,6 +669,17 @@ static int net_conf_addshare(struct net_context *c,
                goto done;
        }
 
+       /*
+        * start a transaction
+        */
+
+       werr = smbconf_transaction_start(conf_ctx);
+       if (!W_ERROR_IS_OK(werr)) {
+               d_printf("error starting transaction: %s\n",
+                        win_errstr(werr));
+               goto done;
+       }
+
        /*
         * create the share
         */
@@ -677,7 +688,7 @@ static int net_conf_addshare(struct net_context *c,
        if (!W_ERROR_IS_OK(werr)) {
                d_fprintf(stderr, "Error creating share %s: %s\n",
                          sharename, win_errstr(werr));
-               goto done;
+               goto cancel;
        }
 
        /*
@@ -688,7 +699,7 @@ static int net_conf_addshare(struct net_context *c,
        if (!W_ERROR_IS_OK(werr)) {
                d_fprintf(stderr, "Error setting parameter %s: %s\n",
                          "path", win_errstr(werr));
-               goto done;
+               goto cancel;
        }
 
        if (comment != NULL) {
@@ -697,7 +708,7 @@ static int net_conf_addshare(struct net_context *c,
                if (!W_ERROR_IS_OK(werr)) {
                        d_fprintf(stderr, "Error setting parameter %s: %s\n",
                                  "comment", win_errstr(werr));
-                       goto done;
+                       goto cancel;
                }
        }
 
@@ -705,7 +716,7 @@ static int net_conf_addshare(struct net_context *c,
        if (!W_ERROR_IS_OK(werr)) {
                d_fprintf(stderr, "Error setting parameter %s: %s\n",
                          "'guest ok'", win_errstr(werr));
-               goto done;
+               goto cancel;
        }
 
        werr = smbconf_set_parameter(conf_ctx, sharename, "writeable",
@@ -713,10 +724,29 @@ static int net_conf_addshare(struct net_context *c,
        if (!W_ERROR_IS_OK(werr)) {
                d_fprintf(stderr, "Error setting parameter %s: %s\n",
                          "writeable", win_errstr(werr));
-               goto done;
+               goto cancel;
        }
 
-       ret = 0;
+       /*
+        * commit the whole thing
+        */
+
+       werr = smbconf_transaction_commit(conf_ctx);
+       if (!W_ERROR_IS_OK(werr)) {
+               d_printf("error committing transaction: %s\n",
+                        win_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",
+                        win_errstr(werr));
+       }
 
 done:
        TALLOC_FREE(mem_ctx);