我想看看passwd和gpasswd程序的源代码。这些工具检查有效的UID设置为零,以成功地完成执行。但我是C的新手,无法找到检查进程是否由UID == 0运行的代码行。如有任何提示或解决办法,我将不胜感激。
发布于 2022-06-21 09:40:07
如果您指的是passwd的“影子-实用程序”实现,您将找到测试这里:
/*
* The program behaves differently when executed by root than when
* executed by a normal user.
*/
amroot = (getuid () == 0);在gpasswd中,测试分为两个阶段:第一个阶段是UID存储在:
/*
* 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宏中使用:
/* Indicate if gpasswd was called by root */
#define amroot (0 == bywho)https://unix.stackexchange.com/questions/706940
复制相似问题