IPC::ShellCmd::Sudo - Chain sudo-ing to a different user before running the command


IPC-ShellCmd documentation Contained in the IPC-ShellCmd distribution.

Index


Code Index:

NAME

Top

  IPC::ShellCmd::Sudo - Chain sudo-ing to a different user before running the command

SYNOPSIS

Top

    $cmd_obj->chain_prog(
        IPC::ShellCmd::Sudo->new(
	        User => 'cpanbuild',
            SetHome => 1,
        )
    );




DESCRIPTION

Top

IPC::ShellCmd::Sudo->new([$opt => $val, ...])

The only external method for this is the constructor. This sets up the various arguments that are going to be used to generate the command-line.

Other methods on this are used by IPC::ShellCmd, but it should only ever be used inside of the chain_prog method on a IPC::ShellCmd object.

User

Specifies the username to sudo to

SetHome

If true, this will cause sudo to set up $ENV{HOME} for the new user, otherwise it will be that of the current user.

BUGS

Top

I don't know of any, but that doesn't mean they're not there.

AUTHORS

Top

See IPC::ShellCmd for authors.

LICENSE

Top

See IPC::ShellCmd for the license.


IPC-ShellCmd documentation Contained in the IPC-ShellCmd distribution.
package IPC::ShellCmd::Sudo;

use strict;
use Carp qw(croak);
use base qw(IPC::ShellCmd::ShBase);

sub chain {
    my $self = shift;
    my $cmd = shift;
    my $args = shift;

    my $cmd_string = $self->generate_sh_cmd($cmd, $args);

    my @sudo_args = ('sudo');

    push (@sudo_args, "-u", $self->{args}->{User})
	    if(defined $self->{args}->{User});

    push (@sudo_args, "-H")
	    if(defined $self->{args}->{SetHome} && $self->{args}->{SetHome});

    push (@sudo_args, "sh", "-c", $cmd_string);

    return @sudo_args;
}

1;