[PATCH] Fix bug #9587 - archive flag is always set on directories.

Jeremy Allison jra at samba.org
Thu Jan 24 14:32:31 MST 2013


On Thu, Jan 24, 2013 at 04:23:49PM -0500, Scott Lovenberg wrote:
> On Thu, Jan 24, 2013 at 4:21 PM, Jeremy Allison <jra at samba.org> wrote:
> > Please review and push to master if you agree.
> >
> > Creating a directory to a Samba share sets the attributes to 'D' only
> > (correct) - only when creating a new file should the 'A' attribute
> > be set.
> >
> > However, doing a rename of that directory sets the 'A' attribute in error.
> >
> > Regression test is included to ensure we don't break in
> > future :-).
> >
> > Cheers,
> >
> >         Jeremy.
> 
> 
> Seems that you sent the patch twice instead of the regression test. :)

Actually I sent the patch+regression test, then the patch again
as another attachment. Doh !

Here's just the patch+regression test as one attachment.

Jeremy.
-------------- next part --------------
>From ce8eb8b155cc24772f4f68e2ec7c3e5f514920f2 Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Thu, 24 Jan 2013 11:02:30 -0800
Subject: [PATCH 1/2] Fix bug #9587 - archive flag is always set on
 directories.

Creating a directory to a Samba share sets the attributes to 'D' only
(correct) - only when creating a new file should the 'A' attribute
be set.

However, doing a rename of that directory sets the 'A' attribute in error.
This should only be done on a file rename. smbclient regression test to follow.

Signed-off-by: Jeremy Allison <jra at samba.org>
---
 source3/smbd/reply.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index 6e1cd27..64c4fdb 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -6416,7 +6416,8 @@ NTSTATUS rename_internals_fsp(connection_struct *conn,
 			  "%s -> %s\n", smb_fname_str_dbg(fsp->fsp_name),
 			  smb_fname_str_dbg(smb_fname_dst)));
 
-		if (!lp_posix_pathnames() &&
+		if (!fsp->is_directory &&
+		    !lp_posix_pathnames() &&
 		    (lp_map_archive(SNUM(conn)) ||
 		    lp_store_dos_attributes(SNUM(conn)))) {
 			/* We must set the archive bit on the newly
-- 
1.8.1


>From db9c43849130699684f3364b60c0674a2b24d6ca Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Thu, 24 Jan 2013 12:33:53 -0800
Subject: [PATCH 2/2] Regression test for bug #9587 - archive flag is always
 set on directories.

Ensure we get the correct attributes on files
and directories after a rename.

Signed-off-by: Jeremy Allison <jra at samba.org>
---
 source3/script/tests/test_smbclient_s3.sh | 186 ++++++++++++++++++++++++++++++
 1 file changed, 186 insertions(+)

diff --git a/source3/script/tests/test_smbclient_s3.sh b/source3/script/tests/test_smbclient_s3.sh
index b240da0..596cd42 100755
--- a/source3/script/tests/test_smbclient_s3.sh
+++ b/source3/script/tests/test_smbclient_s3.sh
@@ -409,6 +409,187 @@ EOF
     fi
 }
 
+# Archive bits are correctly set on file/dir creation and rename.
+test_rename_archive_bit()
+{
+    prompt_file="attributes: A (20)"
+    prompt_dir="attributes: D (10)"
+    tmpfile="$PREFIX/smbclient.in.$$"
+    filename="foo.$$"
+    filename_ren="bar.$$"
+    dirname="foodir.$$"
+    dirname_ren="bardir.$$"
+    filename_path="$PREFIX/$filename"
+    local_name1="$LOCAL_PATH/$filename"
+    local_name2="$LOCAL_PATH/$filename_ren"
+    local_dir_name1="$LOCAL_PATH/$dirname"
+    local_dir_name2="$LOCAL_PATH/$dirname_ren"
+
+    rm -f $filename_path
+    rm -f $local_name1
+    rm -f $local_name2
+
+# Create a new file, ensure it has 'A' attributes.
+    touch $filename_path
+
+    cat > $tmpfile <<EOF
+lcd $PREFIX
+put $filename
+allinfo $filename
+quit
+EOF
+
+    cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
+    eval echo "$cmd"
+    out=`eval $cmd`
+    ret=$?
+    rm -f $tmpfile
+
+    if [ $ret != 0 ] ; then
+	echo "$out"
+	echo "failed creating file $filename with error $ret"
+	false
+	return
+    fi
+
+    echo "$out" | grep "$prompt_file" >/dev/null 2>&1
+
+    ret=$?
+
+    rm -f $filename_path
+    rm -f $local_name1
+    rm -f $local_name2
+
+    if [ $ret = 0 ] ; then
+	# got the correct prompt .. succeed
+	true
+    else
+	echo "$out"
+	echo "Attributes incorrect on new file $ret"
+	false
+    fi
+
+# Now check if we remove 'A' and rename, the A comes back.
+    touch $filename_path
+
+    cat > $tmpfile <<EOF
+lcd $PREFIX
+put $filename
+setmode $filename -a
+ren $filename $filename_ren
+allinfo $filename_ren
+quit
+EOF
+
+    cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
+    eval echo "$cmd"
+    out=`eval $cmd`
+    ret=$?
+    rm -f $tmpfile
+
+    if [ $ret != 0 ] ; then
+	echo "$out"
+	echo "failed creating file and renaming $filename with error $ret"
+	false
+	return
+    fi
+
+    echo "$out" | grep "$prompt_file" >/dev/null 2>&1
+
+    ret=$?
+
+    rm -f $filename_path
+    rm -f $local_name1
+    rm -f $local_name2
+
+    if [ $ret = 0 ] ; then
+	# got the correct prompt .. succeed
+	true
+    else
+	echo "$out"
+	echo "Attributes incorrect on renamed file $ret"
+	false
+    fi
+
+    rm -rf $local_dir_name1
+    rm -rf $local_dir_name2
+
+# Create a new directory, ensure it has 'D' but not 'A' attributes.
+
+    cat > $tmpfile <<EOF
+mkdir $dirname
+allinfo $dirname
+quit
+EOF
+
+    cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
+    eval echo "$cmd"
+    out=`eval $cmd`
+    ret=$?
+    rm -f $tmpfile
+
+    if [ $ret != 0 ] ; then
+	echo "$out"
+	echo "failed creating directory $dirname with error $ret"
+	false
+	return
+    fi
+
+    echo "$out" | grep "$prompt_dir" >/dev/null 2>&1
+
+    ret=$?
+
+    rm -rf $local_dir_name1
+    rm -rf $local_dir_name2
+
+    if [ $ret = 0 ] ; then
+	# got the correct prompt .. succeed
+	true
+    else
+	echo "$out"
+	echo "Attributes incorrect on new directory $ret"
+	false
+    fi
+
+# Now check if we rename, we still only have 'D' attributes
+
+    cat > $tmpfile <<EOF
+mkdir $dirname
+ren $dirname $dirname_ren
+allinfo $dirname_ren
+quit
+EOF
+
+    cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
+    eval echo "$cmd"
+    out=`eval $cmd`
+    ret=$?
+    rm -f $tmpfile
+
+    if [ $ret != 0 ] ; then
+	echo "$out"
+	echo "failed creating directory $dirname and renaming with error $ret"
+	false
+	return
+    fi
+
+    echo "$out" | grep "$prompt_dir" >/dev/null 2>&1
+
+    ret=$?
+
+    rm -f $local_name1
+    rm -f $local_name2
+
+    if [ $ret = 0 ] ; then
+	# got the correct prompt .. succeed
+	true
+    else
+	echo "$out"
+	echo "Attributes incorrect on renamed directory $ret"
+	false
+    fi
+}
+
 # Test authenticating using the winbind ccache
 test_ccache_access()
 {
@@ -541,6 +722,7 @@ EOF
     fi
 }
 
+
 LOGDIR_PREFIX=test_smbclient_s3
 
 # possibly remove old logdirs:
@@ -596,6 +778,10 @@ testit "Accessing an MS-DFS link" \
    test_msdfs_link || \
    failed=`expr $failed + 1`
 
+testit "Ensure archive bit is set correctly on file/dir rename" \
+    test_rename_archive_bit || \
+    failed=`expr $failed + 1`
+
 testit "ccache access works for smbclient" \
     test_ccache_access || \
     failed=`expr $failed + 1`
-- 
1.8.1



More information about the samba-technical mailing list