LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-08-2009, 11:42 AM   #1
dsirrine
LQ Newbie
 
Registered: Nov 2004
Posts: 2

Rep: Reputation: 0
Need solution to prevent deletion of files but allow editing and writing.


I am trying to figure out a solution to a problem I have been posed. I need to make it so that a file can be opened, edited, and saved, but not deleted. The chattr -u won't cut it because that still allows the delete. Also, chattr -i won't work either because that won't allow for opening, writing, and saving. Thank you in advance for your help.
 
Old 12-08-2009, 11:47 AM   #2
bret381
Member
 
Registered: Nov 2009
Location: Alabama
Distribution: Arch x86_64
Posts: 650

Rep: Reputation: 78
You can use the stickybit. chmod +t

I think it can only be used on directories..... someone correct me if I'm wrong

Last edited by bret381; 12-08-2009 at 11:48 AM.
 
Old 12-08-2009, 06:11 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
Yeah, -t is only for dirs and only stops non-owners from deleting. You can't stop the owner for obvious reasons.

Another way is this:

1. Create a new master user eg m1 and a grp grp1 (this will be m1's primary grp)
2. create a dir /home/gshare owned by m1:grp1
3. chgrp +s /home/gshare
4. add reqd users to grp grp1 as secondary group
5. have all files created by m1
6. set dir perms rwxr-x---
7. set file perms rwxrw----
 
Old 12-08-2009, 06:18 PM   #4
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,117
Blog Entries: 2

Rep: Reputation: 113Reputation: 113
You could always make a directory that shadows the original one and has a hard link to each of the files, so even if they get removed out of the original the file still exists
 
Old 12-09-2009, 03:50 PM   #5
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 675

Rep: Reputation: 136Reputation: 136
Quote:
Originally Posted by dsirrine View Post
I am trying to figure out a solution to a problem I have been posed. I need to make it so that a file can be opened, edited, and saved, but not deleted. The chattr -u won't cut it because that still allows the delete. Also, chattr -i won't work either because that won't allow for opening, writing, and saving. Thank you in advance for your help.
Just wondering - if one allowed to edit file (include remove all of it content) while one shouldn't be allowed to delete this file ?
 
Old 12-09-2009, 06:20 PM   #6
jefro
Moderator
 
Registered: Mar 2008
Posts: 15,409

Rep: Reputation: 2207Reputation: 2207Reputation: 2207Reputation: 2207Reputation: 2207Reputation: 2207Reputation: 2207Reputation: 2207Reputation: 2207Reputation: 2207Reputation: 2207
You'd have to copy the file to a directory that the user can read and write to. Then on exit of app the script would do some compare to decide to edit original or leave. The original would have to be done with masked credentials. Might end up being hackable.

Wonder if NTFS formated partition would work?
 
Old 12-10-2009, 02:38 AM   #7
lugoteehalt
Senior Member
 
Registered: Sep 2003
Location: UK
Distribution: Debian
Posts: 1,215
Blog Entries: 2

Rep: Reputation: 49
Possibly not quite what you're after but might be part of a solution: the semi-legendary noclobber option. E.g.

SHELLOPTS=braceexpand:emacs:hashall:histexpand:interactive-comments:monitor:noclobber
 
Old 12-10-2009, 03:02 AM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Remove write permission on the directory the files are in. The files' content can be deleted (that counts as editing, right?) but the files cannot be removed.
 
Old 12-10-2009, 03:46 AM   #9
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 675

Rep: Reputation: 136Reputation: 136
Quote:
Originally Posted by catkin View Post
Remove write permission on the directory the files are in. The files' content can be deleted (that counts as editing, right?) but the files cannot be removed.
Cool, I thought that removing write permission from directory will prevent file editing too, but I was wrong, it works.

Any idea WHY OP want such setup ?
 
Old 12-10-2009, 03:15 PM   #10
lugoteehalt
Senior Member
 
Registered: Sep 2003
Location: UK
Distribution: Debian
Posts: 1,215
Blog Entries: 2

Rep: Reputation: 49
Poisons rising from the gonads.
 
Old 12-10-2009, 03:46 PM   #11
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 675

Rep: Reputation: 136Reputation: 136
Quote:
Originally Posted by lugoteehalt View Post
Poisons rising from the gonads.
Can you explain - I didn't catch it
 
Old 12-10-2009, 03:55 PM   #12
lugoteehalt
Senior Member
 
Registered: Sep 2003
Location: UK
Distribution: Debian
Posts: 1,215
Blog Entries: 2

Rep: Reputation: 49
Quote:
Originally Posted by Valery Reznic View Post
Can you explain - I didn't catch it
I intended it as witty remark, calculated to spread happiness. Clearly I miscalculated.
 
Old 12-10-2009, 04:06 PM   #13
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 675

Rep: Reputation: 136Reputation: 136
Quote:
Originally Posted by lugoteehalt View Post
I intended it as witty remark, calculated to spread happiness. Clearly I miscalculated.
May by you not miscalculated - just English is not my native language.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Prevent editing/truncating file but not deletion (unlink) ruisselet Linux - Software 1 11-18-2009 11:40 AM
solution to prevent arp spoofing h725 Linux - Security 2 01-22-2009 05:20 PM
Prevent folder deletion, centos 5 danedmo Linux - Newbie 2 10-01-2008 11:40 PM
safe deletion of files entz Linux - Security 7 10-01-2007 09:46 PM
retrieve files for deletion props666999 Slackware 5 06-14-2006 11:03 PM


All times are GMT -5. The time now is 02:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration