パスワードソースコード

パスワードソースコード

見ようpasswdおよびgpasswdプログラムのソースコード。これらのツールは、実行を正常に完了するためにゼロに設定された有効なUIDを確認します。しかし、私はC愚かなノルムで、プロセスがUID == 0で実行されていることを確認するコード行を見つけることができません。どんなアドバイスや解決策にも感謝します。

ベストアンサー1

「shadow-utils」の実装に言及している場合は、passwdテストを見つけることができます。ここ:

    /*
     * The program behaves differently when executed by root than when
     * executed by a normal user.
     */
    amroot = (getuid () == 0);

では、gpasswdテストは次の2つのステップで定義されます。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)

おすすめ記事