s3:tests: add a blackbox test that confirms broken timestamp behaviour
authorRalph Boehme <slow@samba.org>
Thu, 21 Nov 2019 15:44:37 +0000 (16:44 +0100)
committerJeremy Allison <jra@samba.org>
Fri, 6 Dec 2019 00:17:35 +0000 (00:17 +0000)
This blackbox test confirms that Samba returns NTTIME=0 when a filesystem object
has a UNIX timestamp value of 0, ie UNIX epoch start 1.1.1970.

Here's an example output from running smbstatus allinfo on such a file:

  $ bin/smbclient -U slow%x //localhost/test -c "allinfo time_0_1970"
  altname: T11662~T
  create_time:    NTTIME(0)
  access_time:    NTTIME(0)
  write_time:     NTTIME(0)
  change_time:    NTTIME(0)
  attributes:  (80)
  stream: [::$DATA], 0 bytes

If you look at it with smbclient ls command, it munges the output to be 1970 so
you don't notice the problem:

  $ bin/smbclient -U slow%x //localhost/test -c "ls time_0_1970"
    time_0_1970                         N        0  Thu Jan  1 01:00:00 1970

The test also test other time_t values -1 and 4294967295 that are used as
sentinel values in Samba code and shows that handling these values is equally
broken.

Same for time_t values < -1.

Note that I'm adding a blackbox test *and* a torture test, as with this blackbox
test I can directly control the server side, but with smbtorture I have to go
through the SMB stack to create the files which doesn't work currently.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=7771

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
selftest/knownfail.d/samba3.blackbox [new file with mode: 0644]
source3/script/tests/test_timestamps.sh [new file with mode: 0755]
source3/selftest/tests.py

diff --git a/selftest/knownfail.d/samba3.blackbox b/selftest/knownfail.d/samba3.blackbox
new file mode 100644 (file)
index 0000000..81e8232
--- /dev/null
@@ -0,0 +1,4 @@
+^samba3.blackbox.timestamps.time=0\(fileserver\)
+^samba3.blackbox.timestamps.time=-1\(fileserver\)
+^samba3.blackbox.timestamps.time=-2\(fileserver\)
+^samba3.blackbox.timestamps.time=1968\(fileserver\)
diff --git a/source3/script/tests/test_timestamps.sh b/source3/script/tests/test_timestamps.sh
new file mode 100755 (executable)
index 0000000..be8410b
--- /dev/null
@@ -0,0 +1,69 @@
+#!/bin/sh
+#
+# This verifies getting and setting timestamps with non-trivial values like 0
+# and < 0 works.
+#
+
+if [ $# -lt 5 ]; then
+    echo "Usage: $0 SERVER_IP USERNAME PASSWORD PREFIX SMBCLIENT"
+    exit 1
+fi
+
+SERVER_IP="$1"
+USERNAME="$2"
+PASSWORD="$3"
+PREFIX="$4"
+SMBCLIENT="$5"
+
+SMBCLIENT="$VALGRIND ${SMBCLIENT}"
+failed=0
+
+incdir=`dirname $0`/../../../testprogs/blackbox
+. $incdir/subunit.sh
+
+export TZ=GMT
+
+setup_testfiles() {
+    touch -d "$(date --date=@0)" $PREFIX/time_0
+    touch -d "$(date --date=@-1)" $PREFIX/time_-1
+    touch -d "$(date --date=@-2)" $PREFIX/time_-2
+    touch -t 196801010000 $PREFIX/time_1968
+}
+
+remove_testfiles() {
+    rm $PREFIX/time_0
+    rm $PREFIX/time_-1
+    rm $PREFIX/time_-2
+    rm $PREFIX/time_1968
+}
+
+test_time() {
+    local file="$1"
+    local expected="$2"
+
+    $SMBCLIENT //$SERVER/tmp -U $USERNAME%$PASSWORD -c "allinfo $file"
+    out=$($SMBCLIENT //$SERVER/tmp -U $USERNAME%$PASSWORD -c "allinfo $file" 2>&1) || return 1
+    echo "smbclient allinfo on $fname returned: \"$out\""
+
+    # Ignore create_time as that is synthesized
+    for time in access_time write_time change_time ; do
+       echo "$out" | grep "$time" | grep "$expected" || {
+            echo "Expected \"$expected\", got: \"$(echo $out | grep $time)\""
+           return 1
+       }
+    done
+}
+
+#Setup
+testit "create testfiles" setup_testfiles || failed=`expr $failed + 1`
+
+# Tests
+testit "time=0" test_time time_0 "Thu Jan  1 12:00:00 AM 1970 GMT" || failed=`expr $failed + 1`
+testit "time=-1" test_time time_-1 "Wed Dec 31 11:59:59 PM 1969 GMT" || failed=`expr $failed + 1`
+testit "time=-2" test_time time_-2 "Wed Dec 31 11:59:58 PM 1969 GMT" || failed=`expr $failed + 1`
+testit "time=1968" test_time time_1968 "Mon Jan  1 12:00:00 AM 1968 GMT" || failed=`expr $failed + 1`
+
+# Cleanup
+testit "delete testfile" remove_testfiles || failed=`expr $failed + 1`
+
+exit $failed
index deadb960f3ec77ae8b69e5beb73bc406f70ae324..0e300f8914884560888d267a9359dce71b0058b3 100755 (executable)
@@ -364,6 +364,9 @@ for env in ["fileserver"]:
     plantestsuite("samba3.blackbox.zero-data", env,
                   [os.path.join(samba3srcdir, "script/tests/test_zero_data.sh"),
                    '$SERVER_IP', '$USERNAME', '$PASSWORD', '$LOCAL_PATH'])
+    plantestsuite("samba3.blackbox.timestamps", env,
+                  [os.path.join(samba3srcdir, "script/tests/test_timestamps.sh"),
+                   '$SERVER_IP', '$USERNAME', '$PASSWORD', '$LOCAL_PATH', smbclient3])
 
     #
     # tar command tests