On Thu, Sep 21, 2006 at 11:30:08AM -0400, Alex Brelsfoard wrote:
> I know I've done this before, but I'm having a hard time finding my
> old code, and am not using the right search terms on google...  All I
> am looking for is the quickest method to find the user who is calling
> this script.
> This is a script that will only ever be run by shell command on a
> Linux system.

Well, perlvar points out $< and $>:

       $REAL_USER_ID
       $UID
       $<      The real uid of this process.  (Mnemonic: it’s the uid you came
               from, if you’re running setuid.)  You can change both the real
               uid and the effective uid at the same time by using
               POSIX::setuid().  Since changes to $< require a system call,
               check $! after a change attempt to detect any possible errors.

       $EFFECTIVE_USER_ID
       $EUID
       $>      The effective uid of this process.  Example:

                   $< = $>;            # set real to effective uid
                   ($<,$>) = ($>,$<);  # swap real and effective uid

               You can change both the effective uid and the real uid at the
               same time by using POSIX::setuid().  Changes to $> require a
               check to $!  to detect any possible errors after an attempted
               change.

               (Mnemonic: it’s the uid you went to, if you’re running setuid.)
               $< and $> can be swapped only on machines supporting
               setreuid().

Once you have the UID, you can use the getpwuid to get the username or
the whole passwd entry.

-- 
Dan Boger
[EMAIL PROTECTED]
 
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to