c++ - 使用 setuid 运行 git 'post-receive' hook 失败

标签 c++ git ubuntu permissions setuid

我有一个 git 存储库,需要以 sudo 运行一个接收后 Hook 。我为测试这个而编译的二进制文件如下所示:

#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>

int main() {
   int ret;
   ret = setuid(geteuid());
   if(!ret) {
      fprintf(stderr, "error setting uid %d \n", ret);
   }       
   system("[...command only sudo can access...]");

   return 0;
}

geteuid() 检索post-receive 的所有者id,然后尝试setuid。当与任何用户(包括 super 用户)一起运行时,它会以 root 身份正确运行脚本。但是,当由 git hook 触发时,系统无法设置 uid。我试过运行 chmod u+s post-receive 我还尝试了一些其他配置,但我的想法已经用完了。除了 git 触发它之外,它在所有情况下都有效的任何原因?

顺便说一句,平台 Ubuntu Server 9.04(2.6.28-15),git1.6.0.4,gcc 版本 4.3.3 (Ubuntu 4.3.3-5ubuntu4)

最佳答案

  1. 存储 git repo 的文件系统可以使用 nosuid 选项挂载
  2. 如果您通过 ssh 推送,则可能会为使用 ssh 调用的命令禁用 suid 功能(无 CAP_SETUID)

无论如何,您尝试做的事情是非常不可取的。

关于c++ - 使用 setuid 运行 git 'post-receive' hook 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1366090/

相关文章:

c++ - 如何使用 uint8_t 而不是 char?

c++ - 如何比较两个同名的预处理器宏?

typescript - 如何组织一个项目来共享代码?

linux - virtualbox 上的 Ubuntu 服务器 TFTP

ruby-on-rails - Bundler 不会安装 libxml-ruby (2.3.3) Ubuntu

c++ - 如何对 16 位数字执行按位运算 (Arduino)

c++ - boost::filesystem:path检测到两个路径共享同一物理驱动器

java - 如何使用github上的eclipse项目进行Android开发

git - Visual Studio 2013 和 Git 2.4

ubuntu - 我在 Vim 上编写 c++ 时得到 "Error detected while processing ~/vimrc"