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): dos2unix-7.3.4-2.fc26.x86_64 How reproducible: always Steps to Reproduce: 1. # mkdir /tmp/tmp # chmod 777 /tmp/tmp # touch /tmp/tmp/file # chmod 777 /tmp/tmp/file 2. # su - test 3. $ cd /tmp/tmp/ $ dos2unix file Actual results: 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 Expected results: (with with "force/unsafe" option or env variable) dos2unix: converting file file to UNIX format ... file is converted Additional info: upstream already considered this https://sourceforge.net/p/dos2unix/bugs/8/#3b63 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
The explanation is in the manual. See option -o, --oldfile https://waterlan.home.xs4all.nl/dos2unix/dos2unix.htm#OPTIONS In an industry environment users can be member of many unix groups. It could happen that a user who is member of many groups changes unintended the group permission, and make the file unreadable for people with less group permissions. Also the file could be made readable for people who should not be able to read it. The original group permission must (or could) have been there for a reason. If you intentionally want to create a new file with your own user/group permission, use the -n (new file) option: dos2unix -n file file Is this sufficient for you? regards, Erwin
The feature keep the original permissions was introduced in version 5.3.1 (2011-08-09), based on a bug report by Christopher Williams, McAfee, Inc. See https://sourceforge.net/p/dos2unix/bugs/7/
Dear Filip, These broken scripts, are these RedHat's own scripts, or did you get problem reports from RHEL customers? Is 'dos2unix -n file file' an acceptable solution, or do you really need a new option to change oldfile (in-place) mode behaviour? In both cases, using option -n or a new option, scripts need to be adapted. If you want exactly the old pre-5.3.1 behaviour you can add CFLAGS_USER=-DNO_CHOWN to the build make command line. Then there will be no script changes needed. The manual will not be in line with the behaviour then. The behaviour changed in 2011. Other people see the old behaviour as a bug. Going back to the old behaviour is not an option, but I will consider a new option as requested if it is really needed. best regards, Erwin Waterlander
If it is hard to explain show them that running these commands: chown $(whoami) /tmp/tmp/file chgrp $(id -gn) /tmp/tmp/file also fail. $ chown $(whoami) /tmp/tmp/file chown: changing ownership of '/tmp/tmp/file': Operation not permitted $ chgrp $(id -gn) /tmp/tmp/file chgrp: changing group of '/tmp/tmp/file': Operation not permitted And when you change the file with an editor the owner and group permissions do not change. Only when you delete the original file and create a new file you can change ownership and group.
The downside of the -n option is that you can't use wild cards. Converting multiple files in-place with -n requires extra scripting. In the next dos2unix version I will add an option which makes dos2unix continue if the original owner/group properties can't be restored. A message will be printed to notify the user. Option -V will show if dos2unix was compiled with -DNO_CHOWN or not.
A beta version of dos2unix is available which has a new option --allow-chown. https://waterlan.home.xs4all.nl/dos2unix/dos2unix-7.3.6-beta2.tar.gz
Today I released dos2unix 7.4.0 which has a new option --allow-chown.