s3/utils: restore client share connection after call to sec_desc_parse
authorNoel Power <noel.power@suse.com>
Fri, 24 Jul 2020 14:32:11 +0000 (15:32 +0100)
committerJeremy Allison <jra@samba.org>
Mon, 31 Aug 2020 17:44:38 +0000 (17:44 +0000)
This normally isn't a problem *except* for when the share is a dfs root
(which results in cli_resolve_patch creating an incorrect path)

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/utils/smbcacls.c

index d2becb3294841fc4a181f588260a1ac004a9cb8a..34c552b449070c7ab3e3d5c12cff764964e770f4 100644 (file)
@@ -1417,6 +1417,7 @@ static int inheritance_cacl_set(char *filename,
        bool isdirectory = false;
        uint16_t attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM
                                | FILE_ATTRIBUTE_HIDDEN;
+       char *save_share = NULL;
        ctx = talloc_init("inherit_set");
        if (ctx == NULL) {
                d_printf("out of memory\n");
@@ -1475,6 +1476,12 @@ static int inheritance_cacl_set(char *filename,
         * prepare for automatic propagation of the acl passed on the
         * cmdline.
         */
+       save_share = talloc_strdup(ctx, cli->share);
+       if (save_share == NULL) {
+               result = EXIT_FAILED;
+               goto out;
+       }
+
        ntstatus = prepare_inheritance_propagation(ctx, filename,
                                                           cbstate);
        if (!NT_STATUS_IS_OK(ntstatus)) {
@@ -1483,6 +1490,26 @@ static int inheritance_cacl_set(char *filename,
                result = EXIT_FAILED;
                goto out;
        }
+
+       /*
+        * sec_desc_parse ends up calling a bunch of functions one of which
+        * connects to IPC$ (which overwrites cli->share)
+        * we need a new connection to the share here.
+        * Note: This only is an issue when the share is a msdfs root
+        *       because the presence of cli->share gets expanded out
+        *       later on by cli_resolve_path (when it is constructing a path)
+        */
+       ntstatus = cli_tree_connect_creds(cli,
+                         save_share,
+                         "?????",
+                         get_cmdline_auth_info_creds(cbstate->auth_info));
+
+       if (!NT_STATUS_IS_OK(ntstatus)) {
+               d_printf("error: %s processing %s\n",
+                        nt_errstr(ntstatus), filename);
+               result = EXIT_FAILED;
+               goto out;
+       }
        result = cacl_set_from_sd(cli, filename, cbstate->aclsd,
                                cbstate->mode, cbstate->numeric);