Reproduces with dos2unix-6.0.3-7.el7.x86_64
+++ This bug was initially created as a clone of Bug #1483633 +++
Description of problem:
As of RHEL 6 dos2unix didn't care of ownership of oldfile.
Current dos2unix attempts to preserve ownership and when fails it refuses to convert the file from security reasons.
It breaks existing scripts which relied on old behaviour.
It's hard to explain to user why I cannot convert a file if I have RW permissions to it.
It's reasonable to keep current behaviour a default but user shall have option to willingly force old behaviour if ownership is not their concern.
Version-Release number of selected component (if applicable):
Steps to Reproduce:
# mkdir /tmp/tmp
# chmod 777 /tmp/tmp
# touch /tmp/tmp/file
# chmod 777 /tmp/tmp/file
# su - test
$ cd /tmp/tmp/
$ dos2unix file
dos2unix: Failed to change the owner and group of temporary output file ./d2utmpNBwoXm: Operation not permitted
dos2unix: dos2unix: problems converting file file
file is not converted
(with with "force/unsafe" option or env variable)
dos2unix: converting file file to UNIX format ...
file is converted
upstream already considered this
but the use case seemed to be rare back then.
Perhaps following approach can be considered as alternative:
1. copy oldfile to a tmpfile (we don't care about attributes, ownership of tmpfile)
2. if success perform st like dos2unix < tmpfile > oldfile (attributes of oldfile remain intact)
3. if not success (risk of oldfile corruption) exit with non-zero exitcode, warn. Then tmpfile can serve as backup of oldfile