Greetings, Monks.

As I start typing this, I realize I may be asking more of a UNIX question than a Perl question, but Perl is my tool of choice... so please bear with me.

I am experimenting with creating a setuid script. I've done this once successfully in the past. But if I create the script, set the appropriate permissions, then run it as a different user, my effective user id does not change.

The little test script looks like this:

owner> cat setuid_program #!/usr/bin/perl -wT use POSIX; my $uid = getuid() or die "Failed to determine user id."; my $euid = geteuid() or die "Failed to determine effective user id."; print "UID = $uid, EUID = $euid.\n";
I set permissions as follows:
owner> chmod 04755 setuid_program owner> ls -l setuid_program -rwsr-xr-x 1 owner owner 202 2007-07-25 18:40 setuid_program owner> id -u 20375
If I then log in as another user (call him guest) I do the following:
guest> id -u 20244 guest> ./setuid_program UID = 20244, EUID = 20244.

What I expected was UID = 20244, EUID = 20375. That is, I expected my effective user id to be the script's owner, not the user running the script.

At this point, I wonder if I am misinterpreting the results of geteuid, or if I am missing something fundamental with respect to how setuid scripts work. Is there a better way to do this test? Or is the test showing me the correct result, and the script is not in fact running setuid for some reason?

I'll admit that my knowledge has been passed down from google, which doesn't always guarantee comprehensive coverage of a topic, nor accuracy.

I am running this on a Solaris 8 machine.

Thanks in advance for any pointers or hints.

UPDATE: mr_mischief was right. The filesystem is mounted to specifically not allow setuid:

owner> mount -p ... /the/device/ - /my/mountpoint nfs - no rw,soft,intr,nosuid,xattr
I had not known you could do that.

Thanks also to kyle; nice catch on my or die ... code there. I guess it's moot now, but I wouldn't have ever run as root anyway.


In reply to Determining if a script is running setuid by crashtest

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.