• Bob (unregistered)

    $ chmod article 666

    FIRST!

  • Bob (unregistered)

    Too simple. My method of checking file permissions would have many more steps, and involve a wooden table.

  • jamface (unregistered) in reply to Bob
    Bob:
    $ chmod article 666

    FIRST!

    No... chmod article 777

    I want to be able to execute the code in it too!

  • The Complicator (unregistered)

    Gloves!

  • changa dullwit (unregistered)

    regex rulez not

  • (cs)
    For example, if you wanted to check read permissions, you'd check bits 4 (owner read), 32 (group read), and 256 (other read).

    Pretty sure those are backwards - the 256 is owner read and the 4 is other read (since mode 0600 is read/write only for the owner, not other users).

  • Barack Obama (unregistered)

    This reminds me of the following xkcd comic:

    http://xkcd.com/208/

    Stand Back! I know regular expressions!

  • (cs)

    Heh...heh...it says "$perms".

  • 73313 permissions (unregistered)

    OK, this has to be approaching the record for number of WTFs per byte of code!

    We'll just start here:

    $perms->mode & 0777

    Whoever wrote this had some clue about masking bits in/out of the permissions result. So close, yet so far...

  • Christian Vogel (unregistered)

    http://de2.php.net/manual/en/function.posix-access.php

  • Nathan (unregistered)

    Stupid question, what's a clean way to do it?

  • umm (unregistered)

    if(-r $path){

    file is readable

    }

  • Boobies (unregistered) in reply to DoctorFriday
    DoctorFriday:
    Heh...heh...it says "$perms".

    You missed the (.).(.) part

  • Josh (unregistered)

    Pretty clever though.

  • fred (unregistered)

    What exactly is a $permsbin? This code kinda makes me wanna go home to my wife and $earch for one...

  • (cs) in reply to Boobies
    Boobies:
    DoctorFriday:
    Heh...heh...it says "$perms".

    You missed the (.).(.) part

    Actually, it contained (.)..(.)..(.) Clearly a reference to Eccentrica Gallumbits, the triple-breasted whore of Eroticon Six

  • Greg (unregistered) in reply to umm

    LOL

  • MacFrog (unregistered)

    The RWTF is the

    $perms->mode & 0777
    .

  • mauhiz (unregistered)

    If you think you are going to need PERL, then it's probably too late to save you. You shall die a painful regexp death.

  • · (unregistered)

    As someone mentioned, perl has inherited test(1)'s -r test for checking if a file is readable, and that aside stat(2) is only a partial check - it'll tell you the unix permissions, but not quite which apply to you, nor if there are ACLs involved. Most of the time you don't need to check, and if you do, chances are you want access(2). Perl's equivalent difference is in -r versus -R.

  • mauhiz (unregistered) in reply to DoctorFriday

    Who's buying my $permsbin?

  • alan (unregistered) in reply to DoctorFriday

    Hah! lol!

  • AdT (unregistered) in reply to DoctorFriday
    DoctorFriday:
    Heh...heh...it says "$perms".

    ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o O ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o

  • Arture Le Coiffeur (unregistered)

    stat($path) should be (stat($path))[2]

    Even Rube Goldberg machines should work.

  • fanguad (unregistered)
    Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. — Jamie Zawinski
    The rebuttal to which is:
    If regular expressions are never the answer to your problems, you must not have very interesting problems.
    (if someone knows who actually said that, that would be fantastic)
  • NiceWTF (unregistered) in reply to jamface
    jamface:
    Bob:
    $ chmod article 666

    FIRST!

    No... chmod article 777

    I want to be able to execute the code in it too!

    Failure for forgetting to include "-R" somewhere, and preferably a "/", too.

  • memals (unregistered) in reply to fanguad
    fanguad:
    Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. — Jamie Zawinski
    The rebuttal to which is:
    If regular expressions are never the answer to your problems, you must not have very interesting problems.
    (if someone knows who actually said that, that would be fantastic)
    I believe that would be "fanguad" on the 2008-11-10 at 10:10
  • Dlareg (unregistered)

    chmod 666 /bin/chmod :)

  • bord4kop (unregistered) in reply to DoctorFriday
    DoctorFriday:
    Heh...heh...it says "$perms".

    And all go into the $permsbin

  • (cs) in reply to NiceWTF
    NiceWTF:
    jamface:
    Bob:
    $ chmod article 666

    FIRST!

    No... chmod article 777

    I want to be able to execute the code in it too!

    Failure for forgetting to include "-R" somewhere, and preferably a "/", too.

    Failure for not nitpicking that the arguments are reversed.

    chmod 777 article

  • Lustig (unregistered) in reply to Dlareg
    Dlareg:
    chmod 666 /bin/chmod :)

    Is that a problem? If you are a superuser, Instead of running dubious built-in shell command search for the source code of 'chmod'. When all else fails backup your files, format the disk, and write a program in assembly language to change the permissions of a file. If you cannot trust your assembler write the generated machine code, and write it to the computer's memory.

  • Edward Royce (unregistered) in reply to AdT
    AdT:
    DoctorFriday:
    Heh...heh...it says "$perms".

    ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o O ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o ~~o

    The new Ovula Invaders!

  • (cs)

    Could someone tell me why you want to know if a file is universally readable? I mean I could see wanting to know if some user X can read a file (if he is user/group/other to the file), but I have never written something to ensure that ugo+r was set.

  • mauve (unregistered)

    EAFP anyway.

  • SayWhat? (unregistered) in reply to Adriano

    Ah, I fondly remember Eroticon Six. But, Comic-con XII was much better. There was this woman in a Xena costume...

  • Me (unregistered) in reply to Quietust
    Quietust:
    For example, if you wanted to check read permissions, you'd check bits 4 (owner read), 32 (group read), and 256 (other read).

    Pretty sure those are backwards - the 256 is owner read and the 4 is other read (since mode 0600 is read/write only for the owner, not other users).

    Which is why you use

    S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU S_ISGID S_ISUID S_IWGRP S_IWOTH S_IWUSR S_IXGRP S_IXOTH S_IXUSR

    if you are even going to go the route of doing this yourself and not letting perl shortcut it for you. C provides these in stat.h, and perl provides them as part of the POSIX module.

  • Me (unregistered) in reply to Mhendren
    Mhendren:
    Could someone tell me why you want to know if a file is universally readable? I mean I could see wanting to know if some user X can read a file (if he is user/group/other to the file), but I have never written something to ensure that ugo+r was set.

    plz, send teh codes.

  • Django (unregistered)

    You have nothing to teach to Bill Gates about UNIX. You were either still a naughty project from your parent or at most very young when Microsoft worked on XENIX.

    A lot of things happened in the past. I guess you should learn about people before you bash them.

  • (cs)

    ..and of course there's...

    $permsbin =~ s/.*(.)..(.)..(.)../$1$2$3/;

    I won't go into the mechanics of backtracking etc., but that expression could conceivably take many many millions of years to run...

  • hapbt (unregistered)

    got 200 problems but a b1tch ain't one

  • Bob (unregistered) in reply to dpm
    dpm:
    Failure for not nitpicking that the arguments are reversed.

    chmod 777 article

    That's because it's actually not UNIX.

  • Barack Obama (unregistered)

    This is a UNIX system. I know this!

  • mauhiz (unregistered) in reply to Django

    Yeah, he was still a $perm at that time.

  • (cs)

    Here's the correct way to do it.

    1. Using a third party program that can emulate keyboard and mouse controls bring up a terminal screen. You'll need the mouse control because you have to click on the terminal shortcut.
    2. In the terminal screen have it type in the file you are getting the permissions from.
    3. Take a screenshot, save it to the desktop, and have the user open it in a program with OCR and have them run it and save the resulting file to the desktop as SAVEDPERMISSIONSxxxxxxxx.txt where the x's are a unique number given to the user through a message box.
    4. Open the text file and use a regular expression to find the permissions.
    5. Done!
  • Glow-in-the-dark (unregistered) in reply to DoctorFriday
    DoctorFriday:
    Heh...heh...it says "$perms".

    And? Never heard of self-propagating code?

    :-)

  • James O'Boston (unregistered) in reply to DoctorFriday

    so that's more like two-hundred-million little problems

  • (cs)

    So much for my mode-700 files.

    rwx------

  • Steve (unregistered)

    Ah, Perl. The Swiss Army Chainsaw.

  • (cs) in reply to Yaos
    Yaos:
    Here's the correct way to do it. 1. Using a third party program that can emulate keyboard and mouse controls bring up a terminal screen. You'll need the mouse control because you have to click on the terminal shortcut. 2. In the terminal screen have it type in the file you are getting the permissions from. 3. Take a screenshot, save it to the desktop, and have the user open it in a program with OCR and have them run it and save the resulting file to the desktop as SAVEDPERMISSIONSxxxxxxxx.txt where the x's are a unique number given to the user through a message box. 4. Open the text file and use a regular expression to find the permissions. 5. Profit!
    FIFY
  • Tilman Baumann (unregistered)
    Every $perm is sacred,
    Every $perm is great.
    If a $perm is wasted,
    God gets quite irate. 
    

Leave a comment on “Now I Have Two Hundred Problems”

Log In or post as a guest

Replying to comment #:

« Return to Article