【问题标题】:Not able to set password in PAM module using pam_set_item()无法使用 pam_set_item() 在 PAM 模块中设置密码
【发布时间】:2018-01-30 08:52:35
【问题描述】:

我创建了一个自定义 PAM 模块,以使用我的自定义身份验证方法登录 Linux。 在我的模块完成身份验证后,它会从数据库接收 Linux 用户帐户的实际用户名和密码(明文)。

现在我正在尝试使用以下方式设置用户名和密码:

pam_set_item(pamh, PAM_USER, user)pam_set_item(pamh, PAM_AUTHTOK, passwd),在做pam_start("m_pamconf", user, &conv, &pamh) 之后。

“m_pamconf”是我的 pam 配置文件,其中包含:

auth    pam_unix.so nullok_secure  use_first_pass

使用此方法成功设置了用户名,但密码似乎不起作用,因为我收到密码提示(如果使用我提供的密码,这当然不会发生)。

感谢任何帮助。谢谢。

我在使用 try_first_pass 标志时收到密码提示, 如果我改用use_first_pass,模块就会失败并在调试日志中给出以下错误:

auth could not identify password for [username]

这是我的 /etc/pam.d/sudo :

#%PAM-1.0

# my pam test
auth    requisite       pam_test.so

session    required   pam_env.so readenv=1 user_readenv=0
session    required   pam_env.so readenv=1 envfile=/etc/default/locale user_readenv=0
@include common-auth
@include common-account
@include common-session-noninteractive

第一行使用我创建的模块,我尝试通过执行pam_start("mypamd", user, &conv, &pamh) 然后pam_authenticate(pamh, 0) 使用上面“m_pamconf”中指定的pam_unix.so 的auth 方法对用户进行身份验证。

【问题讨论】:

  • 密码应该永远以纯文本形式保存在任何地方。
  • 如果您收到密码提示,那么我怀疑您的自定义 PAM 模块要么被完全忽略(设置错误?)要么失败,然后是另一个身份验证策略。
  • @arkascha 密码不以明文形式存储。我的意思是我以明文设置密码。而且我已将我的 pam 配置设置为“必需”,因此,我很确定它没有使用另一个模块进行身份验证。
  • 此外,该模块不会被忽略,因为我正在从中获取调试控制台。
  • 好吧,在您的问题中,您写道:“它从数据库接收 Linux 用户帐户的实际用户名和密码(明文)”。如果不这样存储怎么办?

标签: c linux pam


【解决方案1】:

您可能需要将模块设置为足够。将其设置为 requisite 意味着它需要执行,并且如果它返回 false 将立即使堆栈失败。这并不意味着它会使堆栈成功。根据码头(http://www.linux-pam.org/Linux-PAM-html/sag-configuration-file.html

对于简单(历史)语法,有效的控制值是:

必填

failure of such a PAM will ultimately lead to the PAM-API returning failure but only after the remaining stacked modules (for

此服务和类型)已被调用。

必备

like required, however, in the case that such a module returns a failure, control is directly returned to the application or to the

优越的 PAM 堆栈。返回值是与第一个关联的 必需或必需的模块失败。请注意,此标志可用于 防止用户有机会 通过不安全的介质输入密码。可以想象,这样的 行为可能会通知攻击者系统上的有效帐户。这 应权衡可能性与并非无关紧要的问题 在敌对环境中暴露敏感密码。

足够了

if such a module succeeds and no prior required module has failed the PAM framework returns success to the application or to the

立即上级 PAM 堆栈,而无需在其中调用任何其他模块 堆栈。足够模块的故障被忽略并处理 的 PAM 模块堆栈继续不受影响。

可选

the success or failure of this module is only important if it is the only module in the stack associated with this service+type. 

包括

include all lines of given type from the configuration file specified as an argument to this control.  substack

include all lines of given type from the configuration file specified as an argument to this control. This differs from include in

对子堆栈中的 done 和 die 动作的评估不会 导致跳过完整模块堆栈的其余部分,但仅 子栈。在子栈中跳转也不能使求值跳出 它,并且在跳转时将整个子堆栈计为一个模块 在父堆栈中完成。重置动作将重置一个状态 模块堆栈到子堆栈开始时的状态 评估。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-27
    • 2012-09-15
    • 2018-11-08
    • 2019-03-06
    • 1970-01-01
    相关资源
    最近更新 更多