So just to make sure I was clear, "fixing" the client to send cleaner messages does avoid the problem. But (imho) the real issue is on the server, since other servers can deal with the less clean messages just fine, and there's nothing wrong (again, imho) with the less clean messages.
Is that uname -r, etc, on your client machine?
A script to test all of this is a good idea. I started with what you put and tried to simplify it a bit. This is where I ended up:
#Set date to January 1 2020 at 12:34.56 PM
touch -t "202001011234.56" "$source_path"
cp -p "$source_path" "$target_path"
echo "Copy complete; sleeping 10 seconds before stat"
#We sleep, as smbd actually does work after the cp -p returns.
#An immediate stat may return the current time for the modified timestamp
#even though it will be corrected shortly
sleep 10
So just to make sure I was clear, "fixing" the client to send cleaner messages does avoid the problem. But (imho) the real issue is on the server, since other servers can deal with the less clean messages just fine, and there's nothing wrong (again, imho) with the less clean messages.
Is that uname -r, etc, on your client machine?
A script to test all of this is a good idea. I started with what you put and tried to simplify it a bit. This is where I ended up:
#!/bin/bash
source_ path=/tmp/ mod_time_ test_file path=/media/ rn214/user/ Temp/mod_ time_test_ file
target_
rm "$source_path"
rm "$target_path"
echo abcd > "$source_path"
#Set date to January 1 2020 at 12:34.56 PM
touch -t "202001011234.56" "$source_path"
cp -p "$source_path" "$target_path"
echo "Copy complete; sleeping 10 seconds before stat"
#We sleep, as smbd actually does work after the cp -p returns.
#An immediate stat may return the current time for the modified timestamp
#even though it will be corrected shortly
sleep 10
source_time=$(stat -c "%y" "$source_path")
target_time=$(stat -c "%y" "$target_path")
echo "Source modtime: $source_time"
echo "Target modtime: $target_time"
if [ "$source_time" = "$target_time" ]; then echo "PASS: Modtime preserved"; else echo "FAIL: Modtime not preserved"; fi