这完全在RHEL6上
我试图通过将其包装在C二进制文件中然后设置二进制文件的setgid位来作为特定用户(perl脚本的所有者)运行perl脚本(参考:https://superuser.com/questions/440363/ can-i-make-a-script-always-execute-as-root).perl脚本使用各种perl模块.如果perl模块在试图运行C二进制文件的帐户的PERL5LIB中,并且未在C二进制文件上设置setgid-bit,则它运行正常.如果设置了setgid-bit,那么它会失败,因为使用的perl模块不在@INC中.
一些代码用于演示@INC如何随粘性位改变...
the.pl
#!/usr/bin/env perl
print "Size of INC: ".scalar(@INC)."\n";
exit;
Run Code Online (Sandbox Code Playgroud)
wrapper.c
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
exit(execvp("/home/me/the.pl",(char **)argv));
}
Run Code Online (Sandbox Code Playgroud)
perl脚本权限是-rwxrwxr-x
当我将包装器的权限设置为-rwxr-xr-x时(注意未设置setgid位),然后从其他帐户运行二进制文件,我得到...
Size of INC = 87
Run Code Online (Sandbox Code Playgroud)
...这是我所期望的(PERL5LIB中有87个元素).
但是当我将包装器的权限设置为-rwxr-sr-x时(注意setgid位已设置),然后从其他帐户运行二进制文件,我得到...
Size of INC = 4
Run Code Online (Sandbox Code Playgroud)
即使我在perl脚本的所有者和运行包装器的帐户的.cshrc中加载了所有87个元素的PERL5LIB,我也会得到相同的结果.
我需要将二进制文件作为perl脚本的所有者运行,因为该帐户具有用户帐户所没有的priv.root用户不是任何一个玩家.
为什么我会丢失这些PERL5LIB元素?有没有办法解决这个问题?
提前致谢!
RHEL6
在C中,一个传递如何包含execvp,而execvp又运行perl可执行文件?(这是在打开污点模式时将PERL5LIB的缺失翻译替换为@INC的方法)
这个问题正在寻找一个由mob提供的答案的工作实现... 为什么@INC在perl脚本改变的C包装器的setgid-bit时会改变?.
我在一个使用execvp调用perl的C程序中包装perl脚本执行.由于启用了污点模式,因此@INC将不会加载$ PERL5LIB的内容,因此我已使用"-I"将路径传递给perl可执行文件.perlsec说这是可能的(参考上面注释中的暴徒提供的答案).
我尝试这样做的尝试失败了.我的C程序试图将perl可执行文件作为execvp的第一个arg运行,然后将perl脚本作为参数列表的一部分运行.包含是perl脚本可执行语句的一部分.这是一个例子......
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
char **args; /*args will be passed to execvp. prepend perl executable*/
args=malloc(3*sizeof(char*));
args[0]=malloc(sizeof("/tools/bin/perl -I/proj/perlmods")+1);
strcpy(args[0],"/tools/bin/perl -I/proj/perlmods");
args[1]=malloc(sizeof("/home/me/the.pl")+1);
strcpy(args[1],"/home/me/the.pl");
args[2]=NULL;
execvp("/tools/bin/perl",args);
}
Run Code Online (Sandbox Code Playgroud)
perl脚本很简单......
use html_mail;
print "In my.pl\n";
exit;
Run Code Online (Sandbox Code Playgroud)
/ proj/perlmods有html_mail.pm
使用-I在linux提示符下直接执行perl执行...
% /tools/bin/perl -I /proj/perlmods /home/me/my.pl
In my.pl
Run Code Online (Sandbox Code Playgroud)
但是运行C二进制文件却没有.它抱怨无法找到perl模块.但是,如果将/ proj/perlmods放入PERL5LIB中,那么它确实有效.所以我认为args是好的,因为perl脚本在args [1]中.
我相信我投入args的include语句被忽略了.如果我把它作为后缀添加到execvp中的perl可执行调用中...
execvp("/tools/bin/perl -I /proj/perlmods",args);
Run Code Online (Sandbox Code Playgroud)
... C程序失败了,所以我不认为它属于那里.如果我把include作为perl脚本调用的一部分....
strcpy(args[1],"/home/me/the.pl -I /proj/perlmods");
Run Code Online (Sandbox Code Playgroud)
... 它失败.如果我将它添加为args的新元素(args [3]),它只是作为arg传递给perl脚本并且没有任何影响.
我看了execvpe,但这看起来像是设置env vars的一种方法.
问题是,如何将包含信息实际传递给execvp?
Linux 上的 perl 5.24.0
Perl 模块“嵌套”(某种)问题......我似乎无法让它工作,想知道是否有人能告诉我出了什么问题。下面的简单示例将比我的口头表达更好地阐明我的问题......
首先,ping.pl...
#!/usr/bin/env perl
# This is ping.pl
use ping_mod;
ping_dbh();
exit;
Run Code Online (Sandbox Code Playgroud)
接下来是 perl 模块,ping_mod.pm...
#!/usr/bin/env perl
use Exporter;
use ping_common;
package ping_mod;
@ISA = qw(Exporter);
@EXPORT = qw(ping_dbh);
sub ping_dbh {
set_dbh();
print "dbh = $dbh\n";
}
1;
Run Code Online (Sandbox Code Playgroud)
最后是 ping_common.pm ping_mod 使用...
#!/usr/bin/env perl
use Exporter;
our $dbh;
package ping_common;
@ISA = qw(Exporter);
@EXPORT = qw($dbh set_dbh);
sub set_dbh {
$dbh = 99;
}
1;
Run Code Online (Sandbox Code Playgroud)
当我运行 ping.pl 时,我得到...
Undefined subroutine &ping_mod::set_dbh called at ping_mod.pm …Run Code Online (Sandbox Code Playgroud) 我必须调试其他人的代码并遇到看起来像这样的子声明...
sub mysub($$$$) {
<code here>
}
Run Code Online (Sandbox Code Playgroud)
...也...
sub mysub($$$;$) {
<code here>
}
Run Code Online (Sandbox Code Playgroud)
带括号的“ $”(带有可选的“;”)列表是什么意思?我进行了一个实验,似乎不关心是否我向以这种方式声明的子项传递的参数比在列表中的“ $”少得多。我当时在想,它可能会被用来消除两个具有相同名称的不同子对象的歧义,只是区别在于所加参数的数量(由($$$$)vs($$$)vs($$)定义)等...)。但这似乎并非如此。
我必须调试一个旧的 perl 脚本,它显然是以一种我不理解的方式设置 perl 的版本......
: # use perl
eval 'exec perl -S $0 ${1+"$@"}'
if 0;
Run Code Online (Sandbox Code Playgroud)
perl -h说这-S意味着“使用 PATH 环境变量查找程序文件”。 $0是当前程序。我读过这$@意味着“来自最后一个eval命令的 Perl 语法错误消息”。但是他们为什么要加 1 呢?这一切是如何结合在一起的?它在做什么?
我必须调试的部分内容与它选择了我不想要的旧版本 perl 的事实有关。对于其他一切,我们使用#!/usr/bin/env perl它,我怀疑,可能会做同样的事情。我还怀疑我的解决方案可能在于修复$PATH(或防止弄乱它的代码弄乱它)。但我想通过更好地了解它现在如何选择版本来解决这个问题。
谢谢你的帮助 !
我希望能够在 Perl 中对由字符串标识的列表进行操作。代码可以更好地描述这一点......
my @colors = ("red", "white", "blue");
my @flavors = ("vanilla", "mint", "chocolate");
print "What favorites do you want to see ?";
my $fav_list = <>; chomp($fav_list);
foreach my $favorite (???) {
print "$favorite\n";
}
Run Code Online (Sandbox Code Playgroud)
鉴于这$fav_list是“颜色”或“口味”,应该/可以“???” 在上面的代码中是为了打印出正确的列表?
我在下面的代码中为sub2获取了一个"未定义的子例程",但是没有为sub1.
这是perl脚本(try.pl)......
#!/usr/bin/env perl
use strict;
use IO::CaptureOutput qw(capture_exec_combined);
use FindBin qw($Bin);
use lib "$Bin";
use try_common;
print "Running try.pl\n";
sub1("echo \"in sub1\"");
sub2("echo \"in sub2\"");
exit;
sub sub1 {
(my $cmd) = @_;
print "Executing... \"${cmd}\"\n";
my ($stdouterr, $success, $exit_code) = capture_exec_combined($cmd);
print "${stdouterr}\n";
return;
}
Run Code Online (Sandbox Code Playgroud)
这是try_common.pm ......
#! /usr/bin/env perl
use strict;
use IO::CaptureOutput qw(capture_exec_combined);
package try_common;
use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(
sub2
);
sub sub2 {
(my $cmd) = @_;
print "Executing... …Run Code Online (Sandbox Code Playgroud) RHEL6
我有一个运行perl脚本的c-shell脚本。在将大量的东西转储到stdout之后,它确定perl脚本完成时父shell应当安装到的目录(目录)。但这是一个字符串,而不是一个整数,这就是我可以通过“ exit()”返回的全部。
现在,将dir的名称存储在c-shell脚本可以读取的文件中。它有效,但不优雅。有一个更好的方法吗 ?也许我可以与perl脚本共享一些内存?
linux 上的 emacs 版本“emacs-24.3”
如果我在这条线的开头...
a b
Run Code Online (Sandbox Code Playgroud)
(where single spaces are the spaces between the letters) When I use ctrl-s and then hit the space bar to get the next space, it jumps to the space just before the 'b' instead of the space right after the a. It doesn't behave like this for other characters. It looks like someone went to great lengths to enable this behavior as some sort of feature. But I find it very annoying. How …
试图弄清楚如何用双引号内的单引号单引号.这就是我想要做的......
从perl开始,我想运行一个系统命令...... - 将ssh写入远程机器 - 执行'uptime'然后从中取出最后一个字段(平均负载持续15分钟).
\#\!/usr/bin/env perl
my $cmd = "ssh othermachine 'uptime | awk '{print $NF}'' > local_file.dat";
system($cmd);
Run Code Online (Sandbox Code Playgroud)
当然这不会运行......
% ./try.pl
Missing }.
%
Run Code Online (Sandbox Code Playgroud)
失踪 "}" ???看起来它将$ NF}解释为var?我试图逃避{}字符而没有运气.我试图逃避$,没有运气.我在}之前尝试了一个空格,没有运气但是不同的msg(未定义的变量).
c-shell BTW并提前感谢!