Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Setuid script not working

by druidmatrix (Acolyte)
on Apr 30, 2010 at 06:06 UTC ( [id://837698]=note: print w/replies, xml ) Need Help??


in reply to Re: Setuid script not working
in thread Setuid script not working

Thank you for your response. I looked for $! and sure enough it is populated, but does not explain why it failed.

$< = $> = 0; print "Could not setuid ".$<." error: $! \n" if ($<); POSIX::setuid(0) if ($<); print "Posix could not setuid either ".$<." error: $! \n" if ( +$<);
It now produces:
Could not setuid 500 error: Operation not permitted Posix could not setuid either 500 error: Operation not permitted

Replies are listed 'Best First'.
Re^3: Setuid script not working
by Anonymous Monk on Apr 30, 2010 at 07:03 UTC
    but does not explain why it failed.

    Yes it does, Operation not permitted. Oh you want to know why it isn't permitted? You'll have to rule out each possibility (or use strace, OS usually doesn't provide backtrace)

      Linux, like many other Unix variants, ignores the setuid-bit on scripts. So your script runs as unprivileged user. Unprivileged users aren't allowed to change the UID or GID, hence the "Operation not permitted" error.

      Perl once had a separate interpreter, suidperl, that was installed setuid root, and that should respect the setuid-bit on scripts. It never worked as secure as it should, so it was deprecated and finally removed.

      Consider using sudo, as recommended in perl587delta. Read perlsec for a different approach. A third approach may be splitting the job into a privileged daemon and an unprivileged front-end, communicating over unix domain sockets or named pipes.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

      strace will give you the same message

      setuid32(0) = -1 EPERM (Operation not permitted)

      Not that helpful, except it tells you which system call's man page you should be reading.

      $ man setuid32 ... EPERM The user is not privileged (Linux: does not have the CAP_SETUID capability) and uid does not match the real UID or saved set-user-ID of the calling process. ...
      Thank you for the suggestions. I believe the root cause has been exposed in the thread above; however, if it is not too much, I would be interested in a simple example of using backtrace/strace to investigate an issue like this.
        I would be interested in a simple example of using backtrace/strace to investigate an issue like this.

        Instead of some command as in foo.pl or perl foo.pl you prefix with strace, as in strace perl foo.pl ... and then you watch

      Once again, thank you for your response regarding the setuid module/part that is required to run setuid programs. I believe it is still possible to configure this with the current installer, however, I am having some issues with doing so silently (please see my response in the thread above).

      Also, very grateful for the lil' strace tutorial above! :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-04-23 10:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found