s3: smbd: Simplify logic inside rename_internals_fsp() part 2
authorJeremy Allison <jra@samba.org>
Thu, 10 Mar 2016 00:12:00 +0000 (16:12 -0800)
committerJeremy Allison <jra@samba.org>
Thu, 10 Mar 2016 19:55:09 +0000 (20:55 +0100)
Removes the use of an extraneous 'struct smb_filename *'
which wasn't being created correctly, only as a place
holder for two char * pointers.

Use split_stream_filename() to create the char * pointers
directly and make it clearer what we're up to here.

The logic here is still complex, but I'm satified
it does the correct thing.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Uri Simchoni <uri@samba.org>
source3/smbd/reply.c

index 81750fab720aef3b64f38a1550520a831c479158..b88c2cfa2a2efece559e9506c7ced76760f0a7a2 100644 (file)
@@ -6624,7 +6624,9 @@ NTSTATUS rename_internals_fsp(connection_struct *conn,
            strequal(fsp->fsp_name->stream_name, smb_fname_dst->stream_name)) {
                char *fname_dst_parent = NULL;
                const char *fname_dst_lcomp = NULL;
-               struct smb_filename *smb_fname_orig_lcomp = NULL;
+               char *orig_lcomp_path = NULL;
+               char *orig_lcomp_stream = NULL;
+               bool ok = true;
 
                /*
                 * Split off the last component of the processed
@@ -6640,22 +6642,36 @@ NTSTATUS rename_internals_fsp(connection_struct *conn,
                }
 
                /*
-                * Create an smb_filename struct using the original last
-                * component of the destination.
+                * The original_lcomp component contains
+                * the last_component of the path + stream
+                * name (if a stream exists).
+                *
+                * Split off the stream name so we
+                * can check them separately.
                 */
-               smb_fname_orig_lcomp = synthetic_smb_fname_split(
-                       ctx,
-                       smb_fname_dst->original_lcomp,
-                       lp_posix_pathnames());
-               if (smb_fname_orig_lcomp == NULL) {
-                       status = NT_STATUS_NO_MEMORY;
+
+               if (fsp->posix_flags & FSP_POSIX_FLAGS_PATHNAMES) {
+                       /* POSIX - no stream component. */
+                       orig_lcomp_path = talloc_strdup(ctx,
+                                               smb_fname_dst->original_lcomp);
+                       if (orig_lcomp_path == NULL) {
+                               ok = false;
+                       }
+               } else {
+                       ok = split_stream_filename(ctx,
+                                       smb_fname_dst->original_lcomp,
+                                       &orig_lcomp_path,
+                                       &orig_lcomp_stream);
+               }
+
+               if (!ok) {
                        TALLOC_FREE(fname_dst_parent);
+                       status = NT_STATUS_NO_MEMORY;
                        goto out;
                }
 
                /* If the base names only differ by case, use original. */
-               if(!strcsequal(fname_dst_lcomp,
-                              smb_fname_orig_lcomp->base_name)) {
+               if(!strcsequal(fname_dst_lcomp, orig_lcomp_path)) {
                        char *tmp;
                        /*
                         * Replace the modified last component with the
@@ -6665,15 +6681,16 @@ NTSTATUS rename_internals_fsp(connection_struct *conn,
                                tmp = talloc_asprintf(smb_fname_dst,
                                        "%s/%s",
                                        fname_dst_parent,
-                                       smb_fname_orig_lcomp->base_name);
+                                       orig_lcomp_path);
                        } else {
                                tmp = talloc_strdup(smb_fname_dst,
-                                       smb_fname_orig_lcomp->base_name);
+                                       orig_lcomp_path);
                        }
                        if (tmp == NULL) {
                                status = NT_STATUS_NO_MEMORY;
                                TALLOC_FREE(fname_dst_parent);
-                               TALLOC_FREE(smb_fname_orig_lcomp);
+                               TALLOC_FREE(orig_lcomp_path);
+                               TALLOC_FREE(orig_lcomp_stream);
                                goto out;
                        }
                        TALLOC_FREE(smb_fname_dst->base_name);
@@ -6682,22 +6699,23 @@ NTSTATUS rename_internals_fsp(connection_struct *conn,
 
                /* If the stream_names only differ by case, use original. */
                if(!strcsequal(smb_fname_dst->stream_name,
-                              smb_fname_orig_lcomp->stream_name)) {
-                       char *tmp = NULL;
+                              orig_lcomp_stream)) {
                        /* Use the original stream. */
-                       tmp = talloc_strdup(smb_fname_dst,
-                                           smb_fname_orig_lcomp->stream_name);
+                       char *tmp = talloc_strdup(smb_fname_dst,
+                                           orig_lcomp_stream);
                        if (tmp == NULL) {
                                status = NT_STATUS_NO_MEMORY;
                                TALLOC_FREE(fname_dst_parent);
-                               TALLOC_FREE(smb_fname_orig_lcomp);
+                               TALLOC_FREE(orig_lcomp_path);
+                               TALLOC_FREE(orig_lcomp_stream);
                                goto out;
                        }
                        TALLOC_FREE(smb_fname_dst->stream_name);
                        smb_fname_dst->stream_name = tmp;
                }
                TALLOC_FREE(fname_dst_parent);
-               TALLOC_FREE(smb_fname_orig_lcomp);
+               TALLOC_FREE(orig_lcomp_path);
+               TALLOC_FREE(orig_lcomp_stream);
        }
 
        /*