Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: root-owned script needs to "shell out" to bash as a non-privileged user. How?

by aitap (Deacon)
on Jan 16, 2013 at 19:05 UTC ( #1013638=note: print w/ replies, xml ) Need Help??


in reply to root-owned script needs to "shell out" to bash as a non-privileged user. How?

Where do you run your script on, so it doesn't have a tty, but can be run interactively?

A pure-perl approach to this problem looks like this:

if ((my $pid = fork) == 0) { $< = getpwnam "dbuser" || die "getpwnam: $!"; $( = getgrnam "dbuser" || die "getgrnam: $!"; exec "/bin/bash", "-i" or die "exec: $!"; } elsif ($pid > 0) { waitpid $pid, 0; } else { die "fork: $!"; }
Sorry if my advice was wrong.


Comment on Re: root-owned script needs to "shell out" to bash as a non-privileged user. How?
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1013638]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (16)
As of 2015-07-06 20:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (83 votes), past polls