- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在研究 exec
系列函数,我看到了一个非常奇怪的行为:它们似乎在 chroot()
系统调用后不起作用。
这是来自联机帮助页的相关引述:
Special semantics for execlp() and execvp()
The execlp(), execvp(), and execvpe() functions duplicate the actions of the shell in searching for an executable file if the specified filename does not contain a slash (/) character. The file is sought in the colon-separated list of directory pathnames specified in the PATH envi‐ ronment variable. If this variable isn't defined, the path list defaults to the current directory followed by the list of directories returned by confstr(_CS_PATH). (This confstr(3) call typically returns the value "/bin:/usr/bin".)
If the specified filename includes a slash character, then PATH is ignored, and the file at the specified pathname is executed.
这是理论,现在让我们看看它是如何表现的:
我有 prog.c
文件,它将由 execlp
执行:
#include <stdio.h>
int main()
{
puts("works!");
return 0;
}
我有 exec.c
文件,它将尝试执行 prog
:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <dirent.h>
int main(int argc, char* const argv[])
{
const char path[] = "/home/zaffy/cool";
if (argc < 2)
return 1;
if (argc > 2 && (chdir(path) || chroot(path)))
{
printf("Cannot chroot(%s): %s\n", path, strerror(errno));
return 1;
}
/* Clear our environment, including PATH */
clearenv();
if (execlp(argv[1], argv[1], NULL))
{
printf("Cannot execlp(%s): %s\n", argv[1], strerror(errno));
/* Well, we failed... let's see
contents of the current root */
struct dirent* entry;
DIR* dir = opendir("/");
while ( (entry = readdir(dir)) )
printf("%s\n", entry->d_name);
closedir(dir);
}
return 0;
}
所有测试都在 /home/zaffy/cool
中完成:
/home/zaffy/cool
├── exec
├── exec.c
├── prog
└── prog.c
# /home/zaffy/cool/exec /home/zaffy/cool/prog
works!
# /home/zaffy/cool/exec /prog 1
Cannot execlp(/prog): No such file or directory
.
..
prog.c
prog
exec.c
exec
我很困惑!根据手册页,如果我已将绝对路径传递给 execlp
,则不应在 PATH
中搜索,或者如果未设置 PATH
,它也应该设置为当前目录,所以我看不到这里的问题。
该文件确实存在并且可用!即使我在 execlp
之前使用 fopen
,fopen
会找到并打开文件,但 execlp
仍然发出错误没有这样的文件或目录。
你知道为什么会这样吗?为什么 exec() 在 chroot() 之后不起作用?
最佳答案
您的问题很可能是您尝试执行的程序是动态链接的,并且动态链接器不存在于 chroot 环境的 /lib
中。这将导致 ENOENT
(没有这样的文件或目录
)错误。但是,仅仅单独添加它是无济于事的。您需要动态链接程序所依赖的所有其他文件,包括共享库和任何必要的配置/表/等。这些库需要的文件。
关于c++ - 为什么 exec() 在 chroot() 之后不工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24342758/
关闭。这个问题需要details or clarity .它目前不接受答案。 想改善这个问题吗?通过 editing this post 添加详细信息并澄清问题. 7年前关闭。 Improve thi
我尝试让我的代码在 chroot('/root/test1') 下工作,但它不能正常工作。 但是当我删除chroot('/root/test1'),修改execl("/test2", "test2",
如果我在 shell 脚本中写 chroot /home/mayank/chroot/codebase cd SBC 当我运行这个 shell 脚本时,它确实进入了 chroot 但没有执行命令 cd
Using chroot: Why do I get error from running sudo chroot /bin /bash ? 我从文档中了解到 chroot 应该执行 /bin/bas
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 7年前关闭。 Imp
我正在使用 C 语言在 UNIX 环境中开发网络服务器。目前,我已经完成了对进程的限制,但现在我无法使用系统日志和记录到文件选项,这主要是由于更改了根路径。 程序的新根路径是它的目录。我无法从它逃脱到
这是我遇到的情况: 我已经创建了一个 debootstrap ubuntu maverick(64 位)环境。我把它放在我的 ubuntu(64 位)清醒系统上的 /env/mav/ 中。我可以 ch
我可以使用 Dir.chroot chroot Dir.chroot("/var/chroot/mychroot") 但是我怎样才能从 chroot 返回呢? 最佳答案 chroot 的意义在于您无法
我正在开发一个 web 应用程序(在 Ubuntu 服务器上运行),它将允许用户运行 Octave 代码(基本上是 Matlab)。但是,我只希望他们能够读取或修改他们指定的主文件夹中的文件夹。 我知
我有一个 chroot 环境的小问题,我希望你能帮助我 :) 这是我的故事: 1 - 我创建了一个用户演示(有一个像/home/demo这样的家)并且我通过脚本/bin/chrootshell chr
为了避免将所有共享库和配置文件复制到 chroot 文件夹中,我计划在所有共享库和配置之后立即调用 chroot("path/to/folder");文件已加载。 先前加载的库中的缓冲区溢出漏洞是否会
虽然有another question与类似的主题,它不包括共享库在 chroot jail 中使用的内存。 假设我们有几个类似的 chroot。更具体地说,完全相同的二进制文件和共享库集,它们实际上
有 ubuntu img 是由砧木制作的 在 ARM 架构中运行 但我无法对 img 进行 chroot 很多人说这是依赖问题 如果我没有可用的加载器和/或共享库, 我应该做些什么? 我有 ubunt
我需要一些帮助,以了解为什么在PHP-FPM服务启动后的几分钟内,PHP-FPM chroot的PHP脚本无法解析FQDN。 当我(重新)启动PHP-FPM服务时,它会工作(解析成功)几秒钟,然后解析
我想知道 kazoo 库中是否有一种方法可以让 Zookeeper 在连接字符串中创建 chroot 路径(如果该路径尚不存在)?有人对此有经验吗?我已阅读文档,但我还没有真正找到任何可以处理此问题的
我尝试在 chroot 中运行一些 Python 程序,但出现以下错误 Could not find platform independent libraries Could not find pl
名为 =program.c 的程序的一部分 int memoryPercent() { int memoryPercent=0; FILE *pipe1 = NULL; pip
更新 知道了!看我的解决方案(第五条评论) 这是我的问题: 我创建了一个名为“jail”的小型二进制文件,并在/etc/password 中将其设为测试用户的默认 shell。 这是经过简化的源代码:
我正在尝试将数据写入 chroot 环境中的文件。由于我是非 root 用户,他们与 chroot 通信的唯一方法是使用 schroot 命令。 目前我正在使用以下技巧来写入数据。 $ schroot
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 9 年前。 Improve this
我是一名优秀的程序员,十分优秀!