SQ fss: clean up _AddToShadowCopySet error paths
authorDavid Disseldorp <ddiss@samba.org>
Mon, 28 Jan 2013 16:48:01 +0000 (17:48 +0100)
committerDavid Disseldorp <ddiss@samba.org>
Tue, 14 May 2013 07:02:50 +0000 (09:02 +0200)
source3/rpc_server/fss/srv_fss_agent.c

index d3a133dceb89900efa45d2dc0f411bddcdc0e2e0..b546d649c3894c71985204f34d2bfa5dea50df05 100644 (file)
@@ -470,64 +470,66 @@ uint32_t _fss_AddToShadowCopySet(struct pipes_struct *p,
        NTSTATUS status;
        TALLOC_CTX *tmp_ctx = talloc_new(p->mem_ctx);
        if (tmp_ctx == NULL) {
-               return E_OUTOFMEMORY;
+               ret = E_OUTOFMEMORY;
+               goto err_out;
        }
 
        if (!fss_permitted(p)) {
-               talloc_free(tmp_ctx);
-               return E_ACCESSDENIED;
+               ret = E_ACCESSDENIED;
+               goto err_tmp_free;
        }
 
        sc_set = sc_set_lookup(fss_global.sc_sets, &r->in.ShadowCopySetId);
        if (sc_set == NULL) {
-               talloc_free(tmp_ctx);
-               return E_INVALIDARG;
+               ret = E_INVALIDARG;
+               goto err_tmp_free;
        }
 
        status = fss_unc_parse(tmp_ctx, r->in.ShareName, NULL, &share);
        if (!NT_STATUS_IS_OK(status)) {
-               talloc_free(tmp_ctx);
-               return fss_ntstatus_map(status);
+               ret = fss_ntstatus_map(status);
+               goto err_tmp_free;
        }
 
        snum = find_service(tmp_ctx, share, &service);
        if ((snum == -1) || (service == NULL)) {
                DEBUG(0, ("share at %s not found\n", r->in.ShareName));
-               talloc_free(tmp_ctx);
-               return E_INVALIDARG;
+               ret = E_INVALIDARG;
+               goto err_tmp_free;
        }
 
        path_name = lp_pathname(tmp_ctx, snum);
        if (path_name == NULL) {
-               talloc_free(tmp_ctx);
-               return E_OUTOFMEMORY;
+               ret = E_OUTOFMEMORY;
+               goto err_tmp_free;
        }
 
        status = fss_vfs_conn_create(tmp_ctx, server_event_context(),
                                     p->msg_ctx, p->session_info, snum, &conn);
        if (!NT_STATUS_IS_OK(status)) {
-               talloc_free(tmp_ctx);
-               return E_ACCESSDENIED;
+               ret = E_ACCESSDENIED;
+               goto err_tmp_free;
        }
        if (!become_user_by_session(conn, p->session_info)) {
                DEBUG(0, ("failed to become user\n"));
                fss_vfs_conn_destroy(conn);
-               talloc_free(tmp_ctx);
-               return E_ACCESSDENIED;
+               ret = E_ACCESSDENIED;
+               goto err_tmp_free;
        }
 
        status = SMB_VFS_SNAP_CHECK_PATH(conn, tmp_ctx, path_name, &base_vol);
        unbecome_user();
        fss_vfs_conn_destroy(conn);
        if (!NT_STATUS_IS_OK(status)) {
-               talloc_free(tmp_ctx);
-               return FSRVP_E_NOT_SUPPORTED;
+               /* FIXME ret = fss_ntstatus_map(status); */
+               ret = FSRVP_E_NOT_SUPPORTED;
+               goto err_tmp_free;
        }
 
        if ((sc_set->state != FSS_SC_STARTED)
         && (sc_set->state != FSS_SC_ADDED)) {
-               talloc_free(tmp_ctx);
-               return FSRVP_E_BAD_STATE;
+               ret = FSRVP_E_BAD_STATE;
+               goto err_tmp_free;
        }
 
        /* TODO stop msg seq timer */
@@ -543,14 +545,14 @@ uint32_t _fss_AddToShadowCopySet(struct pipes_struct *p,
         */
        sc = sc_lookup_volname(sc_set->scs, base_vol);
        if (sc != NULL) {
-               talloc_free(tmp_ctx);
-               return FSRVP_E_OBJECT_ALREADY_EXISTS;
+               ret = FSRVP_E_OBJECT_ALREADY_EXISTS;
+               goto err_tmp_free;
        }
 
        sc = talloc_zero(sc_set, struct fss_sc);
        if (sc == NULL) {
-               talloc_free(tmp_ctx);
-               return E_OUTOFMEMORY;
+               ret = E_OUTOFMEMORY;
+               goto err_tmp_free;
        }
        talloc_steal(sc, base_vol);
        sc->volume_name = base_vol;
@@ -560,16 +562,14 @@ uint32_t _fss_AddToShadowCopySet(struct pipes_struct *p,
        sc->id = GUID_random(); /* Windows servers ignore client ids */
        sc->id_str = GUID_string(sc, &sc->id);
        if (sc->id_str == NULL) {
-               talloc_free(sc);
-               talloc_free(tmp_ctx);
-               return E_OUTOFMEMORY;
+               ret = E_OUTOFMEMORY;
+               goto err_sc_free;
        }
 
        sc_smap = talloc_zero(sc, struct fss_sc_smap);
        if (sc_smap == NULL) {
-               talloc_free(sc);
-               talloc_free(tmp_ctx);
-               return E_OUTOFMEMORY;
+               ret = E_OUTOFMEMORY;
+               goto err_sc_free;
        }
 
        sc_smap->snum = snum;
@@ -582,9 +582,7 @@ uint32_t _fss_AddToShadowCopySet(struct pipes_struct *p,
         */
        ret = map_share_name(sc_smap, sc);
        if (ret) {
-               talloc_free(sc);
-               talloc_free(tmp_ctx);
-               return ret;
+               goto err_sc_free;
        }
 
        /* add share map to shadow-copy */
@@ -602,6 +600,13 @@ uint32_t _fss_AddToShadowCopySet(struct pipes_struct *p,
        /* TODO start the Message Sequence Timer with timeout of 180 seconds */
        talloc_free(tmp_ctx);
        return 0;
+
+err_sc_free:
+       talloc_free(sc);
+err_tmp_free:
+       talloc_free(tmp_ctx);
+err_out:
+       return ret;
 }
 
 struct fss_sc_commit_state {