The Official *nix Thread

Inane baanter or words of wisdom - you decide...
Post Reply
User avatar
defsdoor
Baaaaaa!
Baaaaaa!
Posts: 3909
Joined: Fri Jan 30, 2004 12:26 am 0
Location: Sunny Beduff

Re: The Official *nix Thread

Post by defsdoor »

Where mode & ~mask is mask inverted and AND'd with the file creation mode :)

Why it's that way I do not know.
mode specifies the permissions to use in case a new file is cre‐
ated. This argument must be supplied when O_CREAT is specified
in flags; if O_CREAT is not specified, then mode is ignored.
The effective permissions are modified by the process’s umask in
the usual way: The permissions of the created file are
(mode & ~umask). Note that this mode only applies to future
accesses of the newly created file; the open() call that creates
a read-only file may well return a read/write file descriptor.
User avatar
defsdoor
Baaaaaa!
Baaaaaa!
Posts: 3909
Joined: Fri Jan 30, 2004 12:26 am 0
Location: Sunny Beduff

Re: The Official *nix Thread

Post by defsdoor »

Ok - done some reading and it makes sense.

It's for future compatibility. When more mode bits are added (sticky bits, suid bits etc..) the mask is still valid - 007 still works - leaving the new bits as the creating process chooses.

Plain ANDing would mean that anything that set the umask would have to be updated to allow the new bits to be set. It excludes anything other than those bits specified.

Have to admire the forethought of our forefathers.
User avatar
Dungeon-Dave
Baaaaaa!
Baaaaaa!
Posts: 3925
Joined: Thu Aug 04, 2005 12:01 pm 0
Location: UK
Contact:

Re: The Official *nix Thread

Post by Dungeon-Dave »

Just to add some confusion here...

max dir permissions by default = 777, max file perms = 666.

Your umask is then subtracted[1] from that to determine default perms for dir/file.

If your umask = 002 then:
- "mkdir newdir" will create a directory with perms 775 (rwxrwr-x).
- "touch mywilly" will create a file of perms 664 (rw-rw-r--). And a sticky mess, possibly.

Coupla last points:
1. The umask acts as a "filter" - setting it high means objects get little default perms. Setting it low allows greater permissions, which you may need to tighten up later.
2. your umask is user-centric, so affects *you*, not files or dirs - you don't put a umask against a file and it affects users attempting to change permissions.
3. your umask determines new objects created, so setting it higher for tighter security doesn't magically run "chmod" against your existent files and dirs. Yes, that may sound obvious, but I've known people who believe it to be retrospective.
4. umasks are session-specific - setting it higher then logging out will make it revert to its original setting. Generally, people add their preferred umask to their profile (.bash_profile, etc).
5. An odd umask will always be "rounded down" to the nearest even number, so there is no way a newly-created file will gain execute permission by default. That's part of Unix security from the 70s, and it's still a valid idea. Annoys the fuck out of developers that moan they need to run "chmod u+x" on their scripts first. Annoys people even further when they try "chmod 777" on my server, too.

Hope that helps.

For further headaches, read up about ACLs (chacl) and immutable bits (chattr), also. Yah, they'll fry your noodle. Then read about PolicyKit. Oh, shitting christ on stilts.

[1] no, it's not - read defdoor's correction below!
Last edited by Dungeon-Dave on Tue Jun 16, 2009 11:05 pm 0, edited 2 times in total.
User avatar
Dungeon-Dave
Baaaaaa!
Baaaaaa!
Posts: 3925
Joined: Thu Aug 04, 2005 12:01 pm 0
Location: UK
Contact:

Re: The Official *nix Thread

Post by Dungeon-Dave »

defsdoor wrote:(sticky bits, suid bits etc..)
SUID, SGID and STVX = set user ID, set group ID and STVX = only the owner can delete (formerly known as the "sticky bit").
defsdoor wrote:Have to admire the forethought of our forefathers.
Oh, indeed. Hallowed be thy memes.
User avatar
Dungeon-Dave
Baaaaaa!
Baaaaaa!
Posts: 3925
Joined: Thu Aug 04, 2005 12:01 pm 0
Location: UK
Contact:

Re: The Official *nix Thread

Post by Dungeon-Dave »

RageMatrix wrote: O G P
...Owner and Group and read for Public.
Better to think of them as "UGO" = user, group, other.

That way the symbolic permissions make more sense:

chmod u+x file1
chmod ug-w file2
chmod u+rw,go-x file3
chmod ugo=rx file4 (same as "chmod a=rx")
User avatar
defsdoor
Baaaaaa!
Baaaaaa!
Posts: 3909
Joined: Fri Jan 30, 2004 12:26 am 0
Location: Sunny Beduff

Re: The Official *nix Thread

Post by defsdoor »

Dungeon-Dave wrote: Your umask is then subtracted from that to determine default perms for dir/file.
The umask is not subtracted from anything - if a file was being created with a perms of 0444 and my umask was 666 just what would the outcome be ?. Your umask is inverted - i.e. 007 becomes 0777777770 if we are on a system with that wide a permission mode, and then ANDed with the creation mode requested by the call to fopen or creat etc..

Likewise it isn't "rounded down". For file creation it is ANDed with 0666 to prevent files from being executable by default.

Sorry to be pedantic but users have to understand that permissions are bitwise flags - not integers - so likewise the operations upon them are bitwise operations.
User avatar
RageMatrix
Baaaaaaa!
Baaaaaaa!
Posts: 5515
Joined: Fri May 10, 2002 12:52 pm 0
XBL Gamertag: Jon256
Location: East Sussex

Re: The Official *nix Thread

Post by RageMatrix »

8O
XBox Gamertag: Jon256
Wii Code: 4849 1090 9042 6725
"Wrapped in metal, wrapped in ivy"
The Official UNIX/Linux Thread
User avatar
Dungeon-Dave
Baaaaaa!
Baaaaaa!
Posts: 3925
Joined: Thu Aug 04, 2005 12:01 pm 0
Location: UK
Contact:

Re: The Official *nix Thread

Post by Dungeon-Dave »

defsdoor wrote:
Dungeon-Dave wrote: Your umask is then subtracted from that to determine default perms for dir/file.
The umask is not subtracted from anything....

Sorry to be pedantic but users have to understand that permissions are bitwise flags - not integers - so likewise the operations upon them are bitwise operations.
Sorry, you're right on that front - it's not a true "subtraction" since there isn't "carrying". Bitwise AND is correct; I tend to explain it as a subtraction to classes since many of them aren't familiar with the concept of binary (these are the ones that ask "is the internet down?" and "I've crashed the system again").

I guess I got into the wrong mode before reading properly!
User avatar
RageMatrix
Baaaaaaa!
Baaaaaaa!
Posts: 5515
Joined: Fri May 10, 2002 12:52 pm 0
XBL Gamertag: Jon256
Location: East Sussex

Re: The Official *nix Thread

Post by RageMatrix »

Dungeon-Dave wrote:
defsdoor wrote:
Dungeon-Dave wrote: Your umask is then subtracted from that to determine default perms for dir/file.
The umask is not subtracted from anything....

Sorry to be pedantic but users have to understand that permissions are bitwise flags - not integers - so likewise the operations upon them are bitwise operations.
Sorry, you're right on that front - it's not a true "subtraction" since there isn't "carrying". Bitwise AND is correct; I tend to explain it as a subtraction to classes since many of them aren't familiar with the concept of binary (these are the ones that ask "is the internet down?" and "I've crashed the system again").

I guess I got into the wrong mode before reading properly!
Okay, bitwise then - but I'll probably just use subtraction if it comes up as the RHCE book that I'm using (the Michael Jang one) says it's subtraction. I'd love to get hold of the RHCT book instead, as this is the certification I'm going for, but I'll be damned if I can find it anywhere....Amazon only have it second-hand for £100 :(
XBox Gamertag: Jon256
Wii Code: 4849 1090 9042 6725
"Wrapped in metal, wrapped in ivy"
The Official UNIX/Linux Thread
User avatar
defsdoor
Baaaaaa!
Baaaaaa!
Posts: 3909
Joined: Fri Jan 30, 2004 12:26 am 0
Location: Sunny Beduff

Re: The Official *nix Thread

Post by defsdoor »

RageMatrix wrote: Okay, bitwise then - but I'll probably just use subtraction if it comes up as the RHCE book that I'm using (the Michael Jang one) says it's subtraction
I'd throw that away then.
User avatar
RageMatrix
Baaaaaaa!
Baaaaaaa!
Posts: 5515
Joined: Fri May 10, 2002 12:52 pm 0
XBL Gamertag: Jon256
Location: East Sussex

Re: The Official *nix Thread

Post by RageMatrix »

defsdoor wrote:
RageMatrix wrote: Okay, bitwise then - but I'll probably just use subtraction if it comes up as the RHCE book that I'm using (the Michael Jang one) says it's subtraction
I'd throw that away then.
<shrug> it's Certification Press...but I'll keep the bitwise thing in mind and mention it if it comes up.

It's this one...

http://www.amazon.co.uk/Certified-Engin ... 737&sr=8-1

I'll be taking the course before the exam anyway, this is just me "boning up" before I take the course.
XBox Gamertag: Jon256
Wii Code: 4849 1090 9042 6725
"Wrapped in metal, wrapped in ivy"
The Official UNIX/Linux Thread
User avatar
Dungeon-Dave
Baaaaaa!
Baaaaaa!
Posts: 3925
Joined: Thu Aug 04, 2005 12:01 pm 0
Location: UK
Contact:

Re: The Official *nix Thread

Post by Dungeon-Dave »

Just to highlight: I use "subtraction" to explain how it works to a mostly non-technical audience.

I say "subtraction" since - as defsdoor mentioned above - it's not a true subtraction: I have to explain that there's no concept of "borrowing", and when it comes to file perms there will never be an odd result (meaning executable perms by default). I have seen it mentioned in some other books, but it's not strictly correct, just easier to understand provided you observe the exceptions.
User avatar
RageMatrix
Baaaaaaa!
Baaaaaaa!
Posts: 5515
Joined: Fri May 10, 2002 12:52 pm 0
XBL Gamertag: Jon256
Location: East Sussex

Re: The Official *nix Thread

Post by RageMatrix »

Backups.

I've got our shiny new Samba server (well, not really shiny or new - I built it out of bits from our storeroom and threw in a 500GB drive). Anyway....I need to backup the Samba share to an external drive once a month. This bit is easy. The hard bit is that the boss wants incremental daily backups of files that have changed in this directory tree to be copied to a daily sub-directory named with todays date on the external drive.

Can I use rdiff-backup for this? Or something else? Or some sort of scripting? The directory struture is rather complex.
XBox Gamertag: Jon256
Wii Code: 4849 1090 9042 6725
"Wrapped in metal, wrapped in ivy"
The Official UNIX/Linux Thread
User avatar
wanye
Baaaaaa!
Baaaaaa!
Posts: 3047
Joined: Tue Sep 07, 2004 12:46 pm 0
PSN: wanye_m
Location: nottingham
Contact:

Re: The Official *nix Thread

Post by wanye »

if anyone is looking for a cheap media server/NAS, then ebuyer are doing 320gb buffalo linkstations for £50

http://www.ebuyer.com/product/139061

you can drop in a larger sata drive (or plug in a usb external drive) and flash it with linux, so you can run twonky/slimserver/mediatomb/torrent client/etc and free up your pc for more fun things :)
---
psn: spazhammer75
http://nottsdj.co.uk - Nottinghamshire Weddings and Events DJ
User avatar
WiteWulf
Sheepie Whore
Sheepie Whore
Posts: 10125
Joined: Mon Aug 23, 2004 11:20 am 0
PSN: WiteWulf
Location: Loughborough(ish)

Re: The Official *nix Thread

Post by WiteWulf »

Nice looking piece of kit, quite tempting if I didn't already have the Mac Mini.
:::G:::

PSN: WiteWulf
Switch: SW-3941-2878-7584
Steam: WITEWULF66
Post Reply