2019-04-08 23:22:26 +08:00

1 line
6.9 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<div class="body" role="main"><div class="section" id="module-pwd"><h1><span class="yiyi-st" id="yiyi-10">35.2. <a class="reference internal" href="#module-pwd" title="pwd: The password database (getpwnam() and friends). (Unix)"><code class="xref py py-mod docutils literal"><span class="pre">pwd</span></code></a> - 密码数据库</span></h1><p><span class="yiyi-st" id="yiyi-11">此模块提供对Unix用户帐户和密码数据库的访问。</span><span class="yiyi-st" id="yiyi-12">它在所有Unix版本上可用。</span></p><p><span class="yiyi-st" id="yiyi-13">密码数据库条目被报告为类元组对象,其属性对应于<code class="docutils literal"><span class="pre">passwd</span></code>结构(下面的属性字段,参见<code class="docutils literal"><span class="pre">&lt;pwd.h&gt;</span></code>)的成员:</span></p><table border="1" class="docutils"><thead valign="bottom"><tr class="row-odd"><th class="head"><span class="yiyi-st" id="yiyi-14">指数</span></th><th class="head"><span class="yiyi-st" id="yiyi-15">属性</span></th><th class="head"><span class="yiyi-st" id="yiyi-16">含义</span></th></tr></thead><tbody valign="top"><tr class="row-even"><td><span class="yiyi-st" id="yiyi-17">0</span></td><td><span class="yiyi-st" id="yiyi-18"><code class="docutils literal"><span class="pre">pw_name</span></code></span></td><td><span class="yiyi-st" id="yiyi-19">登录名</span></td></tr><tr class="row-odd"><td><span class="yiyi-st" id="yiyi-20">1</span></td><td><span class="yiyi-st" id="yiyi-21"><code class="docutils literal"><span class="pre">pw_passwd</span></code></span></td><td><span class="yiyi-st" id="yiyi-22">可选加密密码</span></td></tr><tr class="row-even"><td><span class="yiyi-st" id="yiyi-23">2</span></td><td><span class="yiyi-st" id="yiyi-24"><code class="docutils literal"><span class="pre">pw_uid</span></code></span></td><td><span class="yiyi-st" id="yiyi-25">数字用户ID</span></td></tr><tr class="row-odd"><td><span class="yiyi-st" id="yiyi-26">3</span></td><td><span class="yiyi-st" id="yiyi-27"><code class="docutils literal"><span class="pre">pw_gid</span></code></span></td><td><span class="yiyi-st" id="yiyi-28">数字组ID</span></td></tr><tr class="row-even"><td><span class="yiyi-st" id="yiyi-29">4</span></td><td><span class="yiyi-st" id="yiyi-30"><code class="docutils literal"><span class="pre">pw_gecos</span></code></span></td><td><span class="yiyi-st" id="yiyi-31">用户名或注释字段</span></td></tr><tr class="row-odd"><td><span class="yiyi-st" id="yiyi-32">5</span></td><td><span class="yiyi-st" id="yiyi-33"><code class="docutils literal"><span class="pre">pw_dir</span></code></span></td><td><span class="yiyi-st" id="yiyi-34">用户主目录</span></td></tr><tr class="row-even"><td><span class="yiyi-st" id="yiyi-35">6</span></td><td><span class="yiyi-st" id="yiyi-36"><code class="docutils literal"><span class="pre">pw_shell</span></code></span></td><td><span class="yiyi-st" id="yiyi-37">用户命令解释器</span></td></tr></tbody></table><p><span class="yiyi-st" id="yiyi-38">uid和gid项是整数所有其他都是字符串。</span><span class="yiyi-st" id="yiyi-39">如果无法找到要求的条目,则会引发<a class="reference internal" href="exceptions.html#KeyError" title="KeyError"><code class="xref py py-exc docutils literal"><span class="pre">KeyError</span></code></a></span></p><div class="admonition note"><p class="first admonition-title"><span class="yiyi-st" id="yiyi-40">注意</span></p><p class="last" id="index-0"><span class="yiyi-st" id="yiyi-41">在传统的Unix中字段<code class="docutils literal"><span class="pre">pw_passwd</span></code>通常包含用DES导出的算法加密的密码参见模块<a class="reference internal" href="crypt.html#module-crypt" title="crypt: The crypt() function used to check Unix passwords. (Unix)"><code class="xref py py-mod docutils literal"><span class="pre">crypt</span></code></a>)。</span><span class="yiyi-st" id="yiyi-42">然而大多数现代unices使用所谓的<em>shadow密码</em>系统。</span><span class="yiyi-st" id="yiyi-43">On those unices the <em>pw_passwd</em> field only contains an asterisk (<code class="docutils literal"><span class="pre">'*'</span></code>) or the letter <code class="docutils literal"><span class="pre">'x'</span></code> where the encrypted password is stored in a file <code class="file docutils literal"><span class="pre">/etc/shadow</span></code> which is not world readable. </span><span class="yiyi-st" id="yiyi-44"><em>pw_passwd</em>字段是否包含任何有用的是系统相关的。</span><span class="yiyi-st" id="yiyi-45">如果可用,应在需要访问加密密码的地方使用<a class="reference internal" href="spwd.html#module-spwd" title="spwd: The shadow password database (getspnam() and friends). (Unix)"><code class="xref py py-mod docutils literal"><span class="pre">spwd</span></code></a>模块。</span></p></div><p><span class="yiyi-st" id="yiyi-46">它定义以下项目:</span></p><dl class="function"><dt id="pwd.getpwuid"><span class="yiyi-st" id="yiyi-47"> <code class="descclassname">pwd.</code><code class="descname">getpwuid</code><span class="sig-paren">(</span><em>uid</em><span class="sig-paren">)</span></span></dt><dd><p><span class="yiyi-st" id="yiyi-48">返回给定数字用户ID的密码数据库条目。</span></p></dd></dl><dl class="function"><dt id="pwd.getpwnam"><span class="yiyi-st" id="yiyi-49"> <code class="descclassname">pwd.</code><code class="descname">getpwnam</code><span class="sig-paren">(</span><em>name</em><span class="sig-paren">)</span></span></dt><dd><p><span class="yiyi-st" id="yiyi-50">返回给定用户名的密码数据库条目。</span></p></dd></dl><dl class="function"><dt id="pwd.getpwall"><span class="yiyi-st" id="yiyi-51"> <code class="descclassname">pwd.</code><code class="descname">getpwall</code><span class="sig-paren">(</span><span class="sig-paren">)</span></span></dt><dd><p><span class="yiyi-st" id="yiyi-52">以任意顺序返回所有可用密码数据库条目的列表。</span></p></dd></dl><div class="admonition seealso"><p class="first admonition-title"><span class="yiyi-st" id="yiyi-53">也可以看看</span></p><dl class="last docutils"><dt><span class="yiyi-st" id="yiyi-54">模块<a class="reference internal" href="grp.html#module-grp" title="grp: The group database (getgrnam() and friends). (Unix)"><code class="xref py py-mod docutils literal"><span class="pre">grp</span></code></a></span></dt><dd><span class="yiyi-st" id="yiyi-55">一个到组数据库的接口,类似于此。</span></dd><dt><span class="yiyi-st" id="yiyi-56">模块<a class="reference internal" href="spwd.html#module-spwd" title="spwd: The shadow password database (getspnam() and friends). (Unix)"><code class="xref py py-mod docutils literal"><span class="pre">spwd</span></code></a></span></dt><dd><span class="yiyi-st" id="yiyi-57">一个到shadow密码数据库的接口类似这样。</span></dd></dl></div></div></div>