cramdorgi has asked for the wisdom of the Perl Monks concerning the following question:
Insecure dependency in system while running with -T switchon a line on which I use 'system' in list mode, with a full path on the first argument:
This is indeed the last line of a suid enabled script, in which I do on the previous line:system('/usr/bin/ssh', '-l', $owner, $host, $binct, @op, @lbtype);
How can I get what I intend, while obeying the injonction?$< = $>;
The code I am trying to write should allow local users to lock or unlock 'label types' (metadata objects) in ClearCase vobs (databases). This operation is usually restricted to the creator of these label types, or to priviledged users, which might be different per vob. Lacking 'sudo' (for "security reasons"), but having access to ssh, I wanted to allow one special user to act in place of the multiple 'vob owners'.
I join the whole code below.
Thanks,
Marc
#!/vobs/cello/cade_struct/bin/perl -w use strict; use Sys::Hostname; use File::Basename; use Getopt::Long; use ClearCase::Argv; use vars qw($help $unlock $vob @op @nusers @lbtype); my $me = basename($0); my $host = hostname; my $ssh = '/usr/bin/ssh'; my $binct = '/opt/rational/clearcase/bin/cleartool'; my $account = getlogin || getpwuid($<) or die "Couldn't get the uid: $ +!\n"; my $eaccount = getpwuid($>) or die "Couldn't get the euid: $!\n"; my $log = "/home/$eaccount/RANOS_autobuild/builds/logs/lbunlock.log"; $ENV{PATH} = ''; ClearCase::Argv->ipc(1); my $ct = ClearCase::Argv->new({autochomp=>1}); sub usage() { print "Usage: ${me} [[--unlock [| --nusers accounts]] --vob <vob>\n" . " --lbtype <lbtypes> | [--help]]\n" . " By default, lock; use --unlock explicitely.\n" . " Only one vob is accepted, and it is mandatory.\n" . " Multiple label types are possible, either with separate +options" . "\n or as one comma separated list.\n" . " All the types must exist in the vob.\n"; exit 1; } my $res = GetOptions("help" => \$help, "unlock" => \$unlock, "vob=s" = +> \$vob, "nusers=s" => \@nusers, "lbtype=s" => \@lbtype); usage if $help or !($res and $vob and @lbtype) or ($unlock and @nusers +); @lbtype = split(/,/, join(',', @lbtype)); my $vob = $ct->argv(qw(des -s), "vob:$vob")->qx; die "Couldn't find the vob $vob\n" unless $vob; my $pwnam = (getpwuid($<))[6]; $pwnam =~ s/^ *(.*[^ ]) *$/$1/; if ($unlock) { my @t = localtime; my $t = sprintf"%4d%02d%02d.%02d:%02d:%02d", (1900+$t[5]),1+$t[4],$t[3],$t[2],$t[1],$t[0]; open LOG, ">>", "$log" or die "Failed to open the $log log: $!\n"; print LOG "$t $account $vob @lbtype\n"; close LOG; @op = ('unlock'); } else { @op = ('lock', '-c', "'Actual lock author: $account \($pwnam\)'"); push(@op, '-nusers', join(',', @nusers)) if @nusers; } my ($owner) = grep s%^.*/(.*)$%$1%, $ct->argv(qw(des -fmt "%[owner]p"), "vob:$vob")->qx; map { $_ = "lbtype:$_\@$vob" } @lbtype; foreach my $t (@lbtype) { $ct->argv(qw(des -s), $t)->stdout(0)->system and die "Label type $t not found in $vob\n"; } $< = $>; system('/usr/bin/ssh', '-l', $owner, $host, $binct, @op, @lbtype);
|
|---|