[sf-lug] favorite interview questions (chmod, perms, etc.)

Michael Paoli Michael.Paoli at cal.berkeley.edu
Mon Apr 26 21:13:02 PDT 2010


And another "bonus" question (and a minor correction):

Another bonus question:
chmod(1) indicates (***** emphasis added):
"
SETUID AND SETGID BITS
        chmod clears the set-group-ID bit of a regular file if the file's group
        ID  does  not  match the user's effective group ID or one of the user's
        supplementary group IDs, unless the user  has  appropriate  privileges.
        Additional restrictions may cause the set-user-ID and set-group-ID bits
        of MODE or RFILE to be ignored.  This behavior depends  on  the  policy
        and  functionality of the underlying chmod system call.  When in doubt,
        check the underlying system behavior.
        chmod preserves a directory's set-user-ID and set-group-ID bits  unless
        you  explicitly  specify otherwise.  You can set or clear the bits with
*****  symbolic modes like u+s and g-s, and you can set (but  not  clear)  the
*****  bits with a numeric mode.
"
Is that correct, or not, or "it depends"?  Explain.

Hints:
$ mkdir d && chmod 7777 d && ls -ld d
drwsrwsrwt 2 mpaoli mpaoli 48 Apr 26 21:03 d
$ chmod 0 d && ls -ld d
d--S--S--- 2 mpaoli mpaoli 48 Apr 26 21:03 d
$

$ mkdir d && chmod 7777 d && ls -ld d
drwsrwsrwt  2 michael users 48 Apr 26 21:04 d
$ chmod 0 d && ls -ld d
d---------  2 michael users 48 Apr 26 21:04 d
$

And on that earlier posting (below), there should be a line containing:

right after the line ending with echo $?
(somehow it got swallowed up on it's way to my posting it).

references/excerpts:
http://linuxmafia.com/pipermail/sf-lug/2010q2/007721.html

Quoting "Michael Paoli" <Michael.Paoli at cal.berkeley.edu>:

> $ mkdir d && >>f && chmod 01777 f d && echo $?
>
> $ ls -ld f d





More information about the sf-lug mailing list