Bug 1483637

Summary: Add option to force in-place conversion even if ownership cannot be preserved
Product: Red Hat Enterprise Linux 7 Reporter: Filip Krska <fkrska>
Component: dos2unixAssignee: Than Ngo <than>
Status: CLOSED WONTFIX QA Contact: BaseOS QE - Apps <qe-baseos-apps>
Severity: high Docs Contact:
Priority: high    
Version: 7.5-AltCC: extras-qa, fkrska, supercyper1, twaugh, waterlan
Target Milestone: rcKeywords: FutureFeature
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of: 1483633 Environment:
Last Closed: 2017-09-11 07:53:54 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1483633    
Bug Blocks:    

Description Filip Krska 2017-08-21 14:18:18 UTC
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):

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