setting uid gid after fork

H

hakim

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...
 
J

John W. Krahn

hakim said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top