我有一个由 root 拥有并具有 setuid 的 Perl 脚本。
在此脚本中,我正在更改作为参数传递的文件的所有者。
但是在运行这个脚本时,我得到了
chown: changing ownership of `file': Operation not permitted
有人告诉我,如果启用,则默认情况下使用 suidperl 运行带有 setuid 的脚本。
但我不认为这发生在我的案例中。
任何人都可以在这件事上帮助我吗?我正在使用 Debian wheezy。我的 Perl 版本是 5.14.2。我试过了
apt-get install perl-suid
但它没有用。
apt-cache search perl
在 Perl 中没有给我与 suid 相关的候选人。
这是我的 Perl 程序
#! /usr/bin/perl -T
use Cwd 'abs_path';
sub check_path {
my $file = $_[0];
$file = abs_path($file);
if ($file =~ /^\/home\/abc\/dir1\//) {
return 1;
}
else {
return 0;
print("You can only update permissions for files inside /home/abc/dir1/ directory\n");
}
}
if (@ARGV == 1) {
if (&check_path($ARGV[0]) == 1) {
$ENV{PATH} = "/bin:/usr/bin";
my $command = "chown abc:abc " . $ARGV[0];
if ($command =~ /^(.*)$/) {
$command = $1;
}
$result = `$command`;
}
}
elsif ((@ARGV == 2) && ($ARGV[0] eq "-R")) {
if (&check_path($ARGV[1]) == 1) {
$ENV{PATH} = "/bin:/usr/bin";
my $command = "chown -R abc:abc " . $ARGV[1];
if ($command =~ /^(.*)$/) {
$command = $1;
}
$result = `$command`;
}
}
else {
print("Sorry wrong syntax. Syntax: perl /home/abc/sbin/update_permission.pl [-R] file_path");
}