【问题标题】:Protecting /etc/passwd and /etc/shadow from concurrent access保护 /etc/passwd 和 /etc/shadow 免受并发访问
【发布时间】:2010-02-26 09:42:02
【问题描述】:

如何保护 /etc/passwd 和 /etc/shadow 免受并发访问?我在pwd.h 中看不到任何锁定机制。我看到pwd_mkdb 的手册提到获得锁,但它只是锁定文件以进行独占访问吗?

如果我要编写一个实用程序来直接修改它们,或者通过 get/set/endpwent 系列函数,是否有锁定这些文件的约定?

【问题讨论】:

    标签: c++ c linux passwd


    【解决方案1】:

    我认为现在大多数应用程序都使用 PAM,不是吗? http://www.kernel.org/pub/linux/libs/pam/Linux-PAM-html/Linux-PAM_ADG.html。也就是说,您可以查看 `pam_unix.so' 的源代码以了解他们是如何做到的。我查看了pam_unix_passwd.c 并遵循了这个:

    /* update the password database(s) -- race conditions..? */
    
    retval = unix_update_db(pamh, ctrl, user, pass_old, pass_new);
    

    here,它有很多以“pwdb”为前缀的函数。谷歌再次发现this,我认为这是passwd的来源。

    因此,我认为编辑这些文件由libpwdb 处理。当然,我看到包括:

    #include <pwdb/pwdb_public.h>
    #include <pwdb/pwdb_shadow.h>
    

    但是到目前为止,find . -name "*pwdb*" 2&gt;/dev/null 在我的系统上没有出现任何内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多