Author Topic: TIP: Immutable files  (Read 2460 times)

0 Members and 1 Guest are viewing this topic.

Offline mynameistmp

  • Moderator
  • Full Member
  • *****
  • Posts: 111
  • Hi! I'm new here!
    • View Profile
TIP: Immutable files
« on: September 19, 2005, 03:20:55 am »
In the ext2 and ext3 filesystems there are a number of additional file attributes available that are beyond the standard bits accessible by chmod. Here is an example of a neat one:

Quote
sh-3.00$ cat test.txt; ls -l test.txt; id
x86
-rw-r--r--  1 tmp users 4 2005-09-19 00:33 test.txt
uid=1000(tmp) gid=100(users) groups=100(users),11(floppy),17(audio),18(video),19(cdrom)
sh-3.00$ rm -f test.txt
rm: cannot remove `test.txt': Operation not permitted

Seems strange. It's a typical text file. My UID is the owner of this file, but I can't delete it. Alright, let's try with root:

Quote
root@tmp:/home/tmp# id ; rm -f test.txt
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy)
rm: cannot remove `test.txt': Operation not permitted

The problem is that this file is 'immutable'. For those of you who aren't familiar with this you should check out the man page on lsattr and chattr. All we need to do is get rid of the immutable attribute and we're off to the races:

Quote
root@tmp:/home/tmp# lsattr test.txt
----i-------- test.txt
root@tmp:/home/tmp# chattr -i test.txt
root@tmp:/home/tmp# rm test.txt

While this flag is set any attempts to unlink, overwrite, rename, or append to the file will fail.

Offline Newby

  • Moderator
  • Hero Member
  • *****
  • Posts: 10877
  • Thrash!
    • View Profile
Re: TIP: Immutable files
« Reply #1 on: September 19, 2005, 09:26:26 pm »
That's awesome. Thanks for the tip. :)
- Newby
http://www.x86labs.org

Quote
[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

I'd bet that you're currently bloated like a water ballon on a hot summer's day.

That analogy doesn't even make sense.  Why would a water balloon be especially bloated on a hot summer's day? For your sake, I hope there wasn't too much logic testing on your LSAT. 

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: TIP: Immutable files
« Reply #2 on: September 19, 2005, 10:37:51 pm »
Indeed!  Thanks, tmp.  :)

Offline Quik

  • Webmaster Guy
  • x86
  • Hero Member
  • *****
  • Posts: 3262
  • \x51 \x75 \x69 \x6B \x5B \x78 \x38 \x36 \x5D
    • View Profile
Re: TIP: Immutable files
« Reply #3 on: September 20, 2005, 10:30:39 pm »
Hrm, was curious how you did this. Might be helpful.
Quote
[20:21:13] xar: i was just thinking about the time iago came over here and we made this huge bomb and light up the sky for 6 min
[20:21:15] xar: that was funny

Offline mfqr

  • Newbie
  • *
  • Posts: 25
  • I'm new here!
    • View Profile
Re: TIP: Immutable files
« Reply #4 on: September 21, 2005, 10:15:22 pm »
cool tip :). thanks.