• (cs) in reply to DoctorFriday
    DoctorFriday:
    Heh...heh...it says "$perms".
    He was trying to create a genetic algorithm.
  • Soviut (unregistered)

    I like this format for the CodeSOD column. A few paragraphs to describe what's actually wrong with the code shown really helps those who aren't familiar with every language on earth.

  • Worf (unregistered) in reply to Barack Obama
    Barack Obama:
    This is a UNIX system. I know this!

    That file browser was done on an IRIX machine, for it was available for SGI IRIX (MIPS) machines as a freeware app, so you could browse your IRIX machine exactly like the movie.

    Anyhow, I suspect permissions is probably the only time people use octal because it's simpler...

    And if I could only figure out what "x" means on a directory or the sticky bit... those are the annoying complex and system-dependent ones.

  • (cs) in reply to Django
    Django:
    You have nothing to teach to Bill Gates about UNIX.
    There's a statement I never thought I'd see.
    You were either still a naughty project from your parent or at most very young when Microsoft worked on XENIX.
    Right, the operating system that they licensed from AT&T. What on earth makes you think Bill personally had anything to do with it? He probably cared about the business aspect of the deal, but system calls? I think not.
  • Jamie (unregistered) in reply to Soviut
    Soviut:
    I like this format for the CodeSOD column. A few paragraphs to describe what's actually wrong with the code shown really helps those who aren't familiar with every language on earth.

    From now on, all CodeSODs must be submitted using pseudo code.

    • admin
  • TZ (unregistered) in reply to DoctorFriday

    $permsbin is better.

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

    Having done similar stupid things, the easy fix for this is to copy some executable to be named, say, foo, then cat chmod into foo, then now rename foo to chmod and copy it back over the original chmod.

  • Steevie (unregistered) in reply to DoctorFriday
    DoctorFriday:
    Heh...heh...it says "$perms".
    ...which are correctly put in a $permbin
  • (cs)

    Personally I find attacks on regular expressions offensive. Like every other tool/technique, they can be abused. (Don't try to parse HTML with them. Please.) They were developed as a Domain Specific Language for handling certain types of parsing problems, and they handle those quite well.

    This is not meant to be a slam on Perl (which, like other tools, has its uses), but I don't find stat($path)->mode & 0444 particularly readable either. Other Perl built-in features should be used instead (as others have mentioned) or this logic should be encapsulated.

  • FragFrog (unregistered) in reply to DoctorFriday
    DoctorFriday:
    Heh...heh...it says "$perms".
    Clbuttic!
  • (cs) in reply to Benn
    Benn:
    ..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...

    Nonsense. It will succeed very quickly or fail in a small handful of iterations.

  • Mike M. (unregistered)

    I'm sure everyone's heard the old joke about how there are 10 kinds of people -- those who understand binary and those who don't. It's true, though -- and this is exactly the sort of mistake commonly (and frequently) made by people who don't understand binary arithmetic and the application of boolean logic operators to bitwise representations.

  • (cs) in reply to Mike M.
    Mike M.:
    I'm sure everyone's heard the old joke about how there are 10 kinds of people -- those who understand binary and those who don't. It's true, though -- and this is exactly the sort of mistake commonly (and frequently) made by people who don't understand binary arithmetic and the application of boolean logic operators to bitwise representations.
    You forgot to list the complete failure to use the operator designed for the task that's been there for at least 15 years. That's the part that makes a small part of me want to curl up in the corner and cry.
  • (cs)

    I've been programming in perl since 1993. I don't know I've seen something quite that bad (aside from code entered into a contest). Like others have said, what's his beef with using normal file tests?

    Now that I think about it, I'm wondering why he bothered with recasting and string comparisons at all when he simply could have shelled out to ls with backticks and then parsed the output of that line by line, looking for his file...

  • NaN (unregistered) in reply to DoctorFriday

    And the solution, after all the effort, is wrong: a 0400 (*) file may be perfectly readable, if it has the right owner. Actually it is quite complex to see if somebody can read (or write) a file. So that's why you can do

    -r filename

    to see if the current effective user can read the file.

    *) leading zero indicates this is an octal value.

  • Elija (unregistered) in reply to DoctorFriday

    Even better - it says my $perms :eek:

  • Benny (unregistered) in reply to DoctorFriday

    HAHA, I didn't catch that.

  • Bfair123 (unregistered)

    Am I the only one who noticed that "bit 256" would imply you are using at least a 256-bit value... Unix must have a lot of permissions to keep track of...

  • coreystup (unregistered)

    Isn't it easier to use the file test operators?

    if -r $filename then...

  • A Wizard a True Star (unregistered)

    Ed's coworker may have two hundred problems, but a bitch ain't one.

  • Dan (unregistered) in reply to Maurits
    Maurits:
    Benn:
    ..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...

    Nonsense. It will succeed very quickly or fail in a small handful of iterations.

    Actually this Regexp depends on the compiler to do what the programmer wanted. If it is set to take the first possible solution, then it will fail on a string less than 9 characters long, or assign the first, 4th, and 7th characters to $1, $2, and $3. If it is set to do greedy matching, it will assign from the end of the string, the 9th, 6th, and 3rd characters to $1, $2, and $3. But technically, any 3 characters spaced 3 apart, starting anywhere in a string >=9 characters, would be a legal result. So this regexp is pretty unreliable. If (as the expression implies) the programmer wanted matching from the end, the expression should be:

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

    But really, '-r' should be used in place of the whole mess.

  • A Wizard a True Star (unregistered) in reply to A Wizard a True Star
    A Wizard a True Star:
    Ed's coworker may have two hundred problems, but a bitch ain't one.

    Damn, someone beat me to it. I did a find on "bitch" and found nothing, didn't see the other guy use "b1tch". I guess regular expressions would have solved this problem.

  • (cs) in reply to mauhiz
    mauhiz:
    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.

    What is PERL? "Protecting Escarpment Rural Lands"? (perlofburlington.org)

    If you are talking about the computer language, it's Perl, not PERL, unless you are missing a clue.

  • Django (unregistered) in reply to dpm
    dpm:
    Django:
    You have nothing to teach to Bill Gates about UNIX.
    There's a statement I never thought I'd see.
    You were either still a naughty project from your parent or at most very young when Microsoft worked on XENIX.
    Right, the operating system that they licensed from AT&T. What on earth makes you think Bill personally had anything to do with it? He probably cared about the business aspect of the deal, but system calls? I think not.

    Bill Gates personnally did software development on many, many operating systems, including Xenix. He was the chief architect for the BASIC and Fortran on all OS where they were ported by Microsoft (including on the Altair, Mac OS and god knows what).

    Contrary to common beliefs, MS-Dos is a product that came quite late in Microsoft history, before that the company pushed hard on Xenix and on cross-platforms languages, in which Bill Gates played a central role. Same with OS2, which was a IBM product largely developed by Microsoft.

    Bill Gates was always involved in business, but he kept a deep technical role until 2-3 years ago when Ray Ozzie came onboard at Microsoft. (Ozzie is the Lotus Notes guy).

    A few years back there was a contest during a convention, a competition between Bill Gates and many famous technical journalists (all experienced IT guys), to see who would come up with some specific feature in a software in the shortest time possible. Bill Gates won.

    The guy is unplesant but he knows his stuff.

  • Someone is WRONG on the Internet! (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).

    Yup. Also, you wouldn't check "bits 4, 32 and 256".. You'd check bits 2, 5 and 8 (starting at bit 0). The values used for ANDing would be 4, 32 and 256, though.

  • (cs) 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)
    Well, that's my pet project to solve Fermat's Last Theorem using regular expressions put to an elegant oratorical sword, then. I should have noticed, some time in the last three months, that the problem is simply "uninteresting."

    "Interesting" does not mean "fiendishly difficult to solve with the tool at hand," contrary to what many Perl dimwits might suggest.

    Back to the illogic of the OP: I presume that, if "1" is TRUE, and "0" is FALSE, then "111" is FILE_PERMISSION_NOT_FOUND?

  • Wesha (unregistered) in reply to jamface

    The Ed's colleague's solution is ugly indeed... but so is "perms & 0444 == true" -- because... it answers the wrong question!

    The proper answer to "whether you can read the file" question would be

    (myeffuser == file.owner && (file.perms & 0400)) || (myeffgroup == file.group && (file.perms & 0040)) || (file.perms & 0004))

    But, putting my "write what you MEAN, dammit!" ideology to use, if you want to know whether you can read the file, all you need to do is...

    ---------------- begin Ruby code --------------- begin File.open(target_file_name) { |f| /* do nothing */ } puts ":)" # File.open with a block opens the file, runs the block, closes the file rescue Errno::EACCES # or throws exception if it can't. puts ":(" # We particularily capture the "Access denied" error end ---------------- end Ruby code ---------------

    Don't fool around showing off how cool you are knowing UNIX perm flags, binary arithmetics, etc etc! The filesystem knows its own guts better, no need to fsck around emulating it. Besides, this code is obviously future proof and can be used on ANY filesystem, be it NTFS or whatever.

  • Mr.'; Drop Database -- (unregistered) in reply to DoctorFriday
    DoctorFriday:
    Heh...heh...it says "$perms".
    Reminds me of variables called "$lang" that hold localized strings, or "$ex" when catching exceptions.
  • Dan (unregistered) in reply to DoctorFriday
    DoctorFriday:
    Heh...heh...it says "$perms".
    lol
  • Chris (unregistered) in reply to Benn
    Benn:
    ..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...

    implemented idiotically, just about anything could take millions of years to run ... are you new to this site and code in general?

  • no one (unregistered)

    In code, stat($path)->mode & 0444. Easy peasy!

    ...or not... That'll be true even if you don't have read permission but everyone else does. i.e. ---r--r-- & 0444 == 044 == true

    Sorry about that chief. We now return you to your regularly scheduled comments.

  • Jon (unregistered) in reply to jamface
    jamface:
    No... chmod article 777

    If the "mark of the beast" is 666, then I, personally, feel good that the beast only has read/write permissions on me and not "execute."

    </revelation>
  • (cs) in reply to DoctorFriday
    DoctorFriday:
    Heh...heh...it says "$perms".

    That made my day...

    because that's the first thing I thought of. Does that make me immature?

  • anonymous (unregistered)

    WTF aside...

    Ahh sure, *nix kicks ass.

    And sure, *nix is stuck forever in the land of hopeless geek weenies like most of the posters here who either (a) can't figure out why it's never taken off or (b) are petulant, clannish children wanting to feel cooler because they know the secret. Long, long-standing condensed retardedness like bitflags to change file system modes is one reason. I did something similar twenty years ago in an app and I still feel bad about it.

    The fact that more than one challenged geek can't remember the order and/or is too lazy to use man suggests that it's a stupid idea.

  • Quick Joe Smith (unregistered) in reply to 73313 permissions
    73313 permissions:
    $perms->mode & 0777

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

    Not necessarily, it's a pretty standard example he probably ninja'd from perldoc.perl.org.

    http://perldoc.perl.org/functions/stat.html

  • Christopher (unregistered) in reply to realmerlyn
    realmerlyn:
    mauhiz:
    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.

    What is PERL? "Protecting Escarpment Rural Lands"? (perlofburlington.org)

    If you are talking about the computer language, it's Perl, not PERL, unless you are missing a clue.

    Well, PERL is an acronym for "Practical Extraction and Report Language", so it's not incorrect to write it out in all caps.

    Captcha: similis. Is that similar to syphilis?

  • Quick Joe Smith (unregistered) in reply to Christopher
    Christopher:
    Well, PERL is an acronym for "Practical Extraction and Report Language", so it's not incorrect to write it out in all caps.
    Not quite true, PERL is actually a backronym.

    http://en.wikipedia.org/wiki/Perl#Name

    Larry Wall originally derived the name (and the bless() function) from his religious beliefs.

    http://en.wikipedia.org/wiki/Larry_Wall

  • Isamu (unregistered) in reply to jamface

    Is it just me or is that code... really naughty looking?

  • danodemano (unregistered) in reply to hapbt
    hapbt:
    got 200 problems but a b1tch ain't one
    LOL, nice
  • Cheong (unregistered) in reply to 73313 permissions
    73313 permissions:
    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...

    I'm also annoyed by this line. It seems that some management effort that use LOC as reference is involved.

    This one is not very noticable unless you got someone check the code manaually.

  • Christopher (unregistered) in reply to Quick Joe Smith
    Quick Joe Smith:
    Christopher:
    Well, PERL is an acronym for "Practical Extraction and Report Language", so it's not incorrect to write it out in all caps.
    Not quite true, PERL is actually a backronym.

    http://en.wikipedia.org/wiki/Perl#Name

    Larry Wall originally derived the name (and the bless() function) from his religious beliefs.

    http://en.wikipedia.org/wiki/Larry_Wall

    So I stand (or sit) corrected. That doesn't happen very often! (My wife would tell you otherwise.)

  • Quick Joe Smith (unregistered) in reply to Christopher

    So would mine. :-)

  • flaggy (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)
    and the answer for that rebuttal is, of course, "what?"
  • flaggy (unregistered) in reply to anonymous
    anonymous:
    WTF aside...

    Ahh sure, *nix kicks ass.

    And sure, *nix is stuck forever in the land of hopeless geek weenies like most of the posters here who either (a) can't figure out why it's never taken off or (b) are petulant, clannish children wanting to feel cooler because they know the secret. Long, long-standing condensed retardedness like bitflags to change file system modes is one reason. I did something similar twenty years ago in an app and I still feel bad about it.

    The fact that more than one challenged geek can't remember the order and/or is too lazy to use man suggests that it's a stupid idea.

    What would you suggest instead? I really can't see a better way to represent permissions from a file. If you don't want to remember the order you can set constants like USER_READ=0400, then use & to find out if it's a hit or not (if (perm & USER_READ)).

    If you're the user actually setting the permissions you can use u+r to set read permission to the user, or you can use one of the many GUIs available for just that.

    You seem to have some resentment towards unix for some reason...

  • J (unregistered) in reply to DoctorFriday

    This is seriously the first thing online to make me literally laugh out loud in weeks.

    I'm not sure what that says about me.

  • Phil (unregistered) in reply to anonymous
    anonymous:
    The fact that more than one challenged geek can't remember the order and/or is too lazy to use man suggests that it's a stupid idea.

    What? Lazy people who can't be bothered to look up how to use something will always find ways to misuse things. What wouldn't be considered a stupid idea under your criteria?

  • Franz Kafka (unregistered) in reply to anonymous
    anonymous:
    WTF aside...

    Ahh sure, *nix kicks ass.

    And sure, *nix is stuck forever in the land of hopeless geek weenies like most of the posters here who either (a) can't figure out why it's never taken off or (b) are petulant, clannish children wanting to feel cooler because they know the secret. Long, long-standing condensed retardedness like bitflags to change file system modes is one reason. I did something similar twenty years ago in an app and I still feel bad about it.

    The fact that more than one challenged geek can't remember the order and/or is too lazy to use man suggests that it's a stupid idea.

    meanwhile, windows still uses file extensions to work out executable permission and can't mount a volume no execute, among other sins. At least unix also has ACLs, even though you enerally don't need them.

  • Even Easier (unregistered)

    '-r $path' ... wow

  • nightfly19 (unregistered) in reply to DoctorFriday

    I think you just ruined that variable name for me...

  • ölf (unregistered)

    Hey, it's Perl, of course there's more than one way to do it. (They never said anything about the number of non-stupid ways.)

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

Log In or post as a guest

Replying to comment #:

« Return to Article