Bug 1483637 - Add option to force in-place conversion even if ownership cannot be preserved
Summary: Add option to force in-place conversion even if ownership cannot be preserved
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: dos2unix
Version: 7.5-Alt
Hardware: Unspecified
OS: Unspecified
high
high
Target Milestone: rc
: ---
Assignee: Than Ngo
QA Contact: BaseOS QE - Apps
URL:
Whiteboard:
Depends On: 1483633
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-08-21 14:18 UTC by Filip Krska
Modified: 2021-03-11 15:37 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: Enhancement
Doc Text:
Clone Of: 1483633
Environment:
Last Closed: 2017-09-11 07:53:54 UTC
Target Upstream Version:


Attachments (Terms of Use)

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


Note You need to log in before you can comment on or make changes to this bug.