RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
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:
Embargoed:


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.