首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >passwd源代码

passwd源代码
EN

Unix & Linux用户
提问于 2022-06-21 09:28:30
回答 1查看 237关注 0票数 -1

我想看看passwd和gpasswd程序的源代码。这些工具检查有效的UID设置为零,以成功地完成执行。但我是C的新手,无法找到检查进程是否由UID == 0运行的代码行。如有任何提示或解决办法,我将不胜感激。

EN

回答 1

Unix & Linux用户

发布于 2022-06-21 09:40:07

如果您指的是passwd的“影子-实用程序”实现,您将找到测试这里

代码语言:javascript
复制
    /*
     * The program behaves differently when executed by root than when
     * executed by a normal user.
     */
    amroot = (getuid () == 0);

gpasswd中,测试分为两个阶段:第一个阶段是UID存储在

代码语言:javascript
复制
    /*
     * Make a note of whether or not this command was invoked by root.
     * This will be used to bypass certain checks later on. Also, set
     * the real user ID to match the effective user ID. This will
     * prevent the invoker from issuing signals which would interfere
     * with this command.
     */
    bywho = getuid ();

然后在这个amroot中使用:

代码语言:javascript
复制
/* Indicate if gpasswd was called by root */
#define amroot  (0 == bywho)
票数 5
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/706940

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档