Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > setting uid gid after fork

Reply
Thread Tools

setting uid gid after fork

 
 
hakim
Guest
Posts: n/a
 
      08-28-2007
Hi list,

I have the following script, and it gets started as root:

#!/usr/bin/perl -w

use strict;
use POSIX;

my $uid;
my $gid;

if(($uid = getpwnam("iday")) && ($gid = getgrnam("iday"))) {
print "iday:\n";
print "UID = $uid\n";
print "GID = $gid\n";
$< = $> = $uid;
$( = $) = $gid;
} elsif(($uid = getpwnam("idayserv")) && ($gid =
getgrnam("idayserv"))) {
print "idayserv:\n";
print "UID = $uid\n";
print "GID = $gid\n";
} else {
print "Sorry\n";
}


while(1) {
sleep 10;
}


With "ps -ax -o euid,egid,user,group,command":
EUID EGID USER GROUP COMMAND
1001 0 iday root /usr/bin/perl -w ./test

The user iday has uid 1001 and gid 1001 (groupname iday), but that
does not show up.

How can I change the process uid and gid for example like an apache
server does?

Thanks...

 
Reply With Quote
 
 
 
 
John W. Krahn
Guest
Posts: n/a
 
      08-28-2007
hakim wrote:
>
> I have the following script, and it gets started as root:
>
> #!/usr/bin/perl -w
>
> use strict;
> use POSIX;
>
> my $uid;
> my $gid;
>
> if(($uid = getpwnam("iday")) && ($gid = getgrnam("iday"))) {
> print "iday:\n";
> print "UID = $uid\n";
> print "GID = $gid\n";
> $< = $> = $uid;
> $( = $) = $gid;
> } elsif(($uid = getpwnam("idayserv")) && ($gid =
> getgrnam("idayserv"))) {
> print "idayserv:\n";
> print "UID = $uid\n";
> print "GID = $gid\n";
> } else {
> print "Sorry\n";
> }
>
>
> while(1) {
> sleep 10;
> }
>
>
> With "ps -ax -o euid,egid,user,group,command":
> EUID EGID USER GROUP COMMAND
> 1001 0 iday root /usr/bin/perl -w ./test
>
> The user iday has uid 1001 and gid 1001 (groupname iday), but that
> does not show up.
>
> How can I change the process uid and gid for example like an apache
> server does?


Once you change the UID you don't have permission to then change the GID so
change:

$< = $> = $uid;
$( = $) = $gid;

To:

$( = $) = $gid;
$< = $> = $uid;

And change the GID first.



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
os.fork and pty.fork Eric Snow Python 0 01-08-2009 06:32 AM
How to get the user/group name from uid/gid in python ? raocheng Python 0 01-20-2008 01:43 AM
Process::GID.change_privilege not changing groups properly? Scott McNab Ruby 2 06-05-2007 12:30 PM
Find out username and UID/GID Florian Lindner Python 2 01-04-2004 03:10 PM
Messing with UID's and GID's Dave Ardrey Perl Misc 1 06-30-2003 02:52 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57