Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

filehandles and setuid

by c (Hermit)
on Apr 10, 2002 at 04:40 UTC ( #157954=perlquestion: print w/replies, xml ) Need Help??

c has asked for the wisdom of the Perl Monks concerning the following question:

i am working on a script that will run setuid. i know the security lectures, but unfortunately, this one touches /etc/passwd so i am just trying to use taint checks as oft as possible and watch my back with any holes i can foresee.

in the process of the script however, i am writing the users being touched to a flat file. when running the script as setuid, i get an error complaining that opening a file via:

open(FH, "/etc/pop3/users.$domain") or die "Cant open file for reading : $!\n";

is not allowed or doesnt pass checks. sorry, but i cant at the moment recall the error and dont have the ability to duplicate it at the moment.

does this sound familiar? is there a way to safely perform such a task in a setuid file?

humbly -c

Replies are listed 'Best First'.
Re: filehandles and setuid
by Fletch (Bishop) on Apr 10, 2002 at 04:50 UTC

    You need to untaint $domain, presuming it's coming from user input and is what's causing the error. perldoc perlsec explains how to untaint expressions.

    And you'll get better answers by providing the real code and the exact error message.

Re: filehandles and setuid
by mce (Curate) on Apr 10, 2002 at 10:07 UTC
    Hi,

    use the Taint and the Apache::TaintRequest modules. They are genious in their simplicity.

    Yours,
    ---------------------------
    Dr. Mark Ceulemans
    Senior Consultant
    IT Masters, Belgium

Re: filehandles and setuid
by particle (Vicar) on Apr 10, 2002 at 11:07 UTC
    as an aside, in older versions of perl (as recent as 5.005_03,) using $! with \n causes different results than $! alone. perhaps you'll get a different (better) error if you strip off the newline. i don't know if this is still the case, but i never use newlines with $! anymore.

    ~Particle ;

      I think what you're alluding to is the fact that die, not $! (although die "... $!\n" is the common idiom), behaves differently if the message passed has a trailing newline or not. If it doesn't, the location the die occured at will be appended; if the message does end with a newline it's printed verbatim. I tend to use the with-a-newline for error messages that users may see, and without-newline in modules where the extra location information is of more use.

      See perldoc -f die and perldoc Carp for more information.

      Addendum: warn has similar behavior as well.

      Wow, particle, really??

      That is quite strange. Not that perl hasn't had other strange quirks, mind you... Do you have a pointer to more details?

      I'm curious about this one, it sounds like a problem that could be hard to diagnose if you don't know about it.

      Supersearch won't help, since $! and \n are both unfortunately shorter than 4 characters...
      --
      Mike

        lo, i have searched the deep recesses of my mind, and have found... nothing.

        neither Super Search nor Google have aided me. luckily, Fletch has come to my rescue! his response (below) is right-on. die behaves differently, not $!

        ~Particle ;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://157954]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2023-06-04 03:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you go to conferences?






    Results (17 votes). Check out past polls.

    Notices?