免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2661 | 回复: 6

[C] 有效用户ID问题 [复制链接]

论坛徽章:
0
发表于 2008-11-26 10:44 |显示全部楼层
想用普通用户启动一个需要root权限的程序,
发现system启动的程序没有继承有效用户ID,该怎么办呢?
a.c
#include <stdlib.h>
int main()
{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("real uid:%d, effective uid=%d\n", getuid(), geteuid());
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;system("./uid");
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//system("/etc/init.d/mysqld restart");

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 0;
}


uid.c
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>

int main()
{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("system:real uid:%d, effective uid=%d\n", getuid(), geteuid());
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 0;
}


[tian@localhost test]$ ./a.out
real uid:501, effective uid=0
system:real uid:501, effective uid=501

论坛徽章:
0
发表于 2008-11-26 13:16 |显示全部楼层
su -c xxxx

论坛徽章:
0
发表于 2008-11-26 13:47 |显示全部楼层
chmod +s ./uid

论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
发表于 2008-11-26 14:16 |显示全部楼层
了解一下system执行的时候是以什么身份

论坛徽章:
0
发表于 2008-11-27 14:28 |显示全部楼层
原帖由 emacsnw 于 2008-11-26 13:47 发表
chmod +s ./uid


./a.out 设过了...
./uid 还要设??

[ 本帖最后由 204tian 于 2008-11-27 14:30 编辑 ]

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
发表于 2008-11-27 16:00 |显示全部楼层
首先一点,没看到你调用 setuid。

其次,和 shell 有关。
而且,几乎可以肯定,是和 bash 有关。
怀疑楼主是 debian 用户。

[ 本帖最后由 flw 于 2008-11-27 16:02 编辑 ]

论坛徽章:
0
发表于 2008-11-27 21:26 |显示全部楼层
The system() function hands the argument string to the command inter- preter sh(1). The calling process waits for the shell to finish execut- ing the command, ignoring SIGINT and SIGQUIT, and blocking SIGCHLD.

而很多linux上的sh其实是到bash的一个链接,而bash:

    If the shell is started with the effective user (group) id not equal to the real user (group) id, and the -p option is not supplied, no startup files are read, shell functions are not inherited from the environment, the SHELLOPTS variable, if it appears in the environment, is ignored, and the effective user id is set to the real user id. If the -p option is supplied at invocation, the startup behavior is the same, but the effective user id is not reset.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP