我有一个 git 存储库,需要将接收后挂钩作为 sudo 运行。我为测试它而编译的二进制文件如下所示:
#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()
所有者 id post-receive
,然后尝试 setuid。使用任何用户(包括超级用户)运行此脚本时,它会以 root 身份正确运行脚本。但是,当被 git 钩子触发时,系统无法设置 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)