in reply to Changing user and GROUP id for security?
sub switchUsers { my ($uname,$gname)=@_; $>=0; if($> != 0) { mlog('',"requested to switch to user/group '$uname/$gname' but canno +t set effective uid to 0 -- quitting; uid is $>"); die "requested to switch to user/group '$uname/$gname' but cannot se +t effective uid to 0 -- quitting; uid is $>\n"; } $<=0; if($gname) { my $gid = getgrnam($gname); if(defined $gid) { if($switchRealUID) { $(=$gid; if($(+0==$gid) { mlog('',"Switched real gid to $gid ($gname)"); } else { mlog('',"Failed to switch real gid to $gid ($gname) -- real uid=$ +("); } } $)=$gid; if($)+0==$gid) { mlog('',"Switched effective gid to $gid ($gname)"); } else { mlog('',"Failed to switch effective gid to $gid ($gname) -- effect +ive gid=$) -- quitting"); die "Failed to switch effective gid to $gid ($gname) -- effective +gid=$) -- quitting"; } } else { mlog('',"Could not find gid for group '$gname' -- not switching eff +ective gid -- quitting"); die "Could not find gid for group '$gname' -- not switching effecti +ve gid -- quitting"; } } if($uname) { my $uid = getpwnam($uname); if(defined $uid) { if($switchRealUID) { $<=$uid; if($<==$uid) { mlog('',"Switched real uid to $uid ($uname)"); } else { mlog('',"Failed to switch real uid to $uid ($uname) -- real uid=$ +<"); } } $>=$uid; if($>==$uid) { mlog('',"Switched effective uid to $uid ($uname)"); } else { mlog('',"Failed to switch effective uid to $uid ($uname) -- real u +id=$< -- quitting"); die "Failed to switch effective uid to $uid ($uname) -- real uid=$ +< -- quitting"; } } else { mlog('',"Could not find uid for user '$uname' -- not switching effe +ctive uid -- quitting"); die "Could not find uid for user '$uname' -- not switching effectiv +e uid -- quitting"; } } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Changing user and GROUP id for security?
by jhanna (Scribe) on Jan 29, 2003 at 17:29 UTC | |
Re: Re: Changing user and GROUP id for security?
by jhanna (Scribe) on Jan 29, 2003 at 20:43 UTC |