PHP/PAM更改用户密码?
有没有可以使用 PHP 更改 linux 用户密码的工作包?
我尝试过使用 PECL:PAM,但在尝试更改密码时出现错误。
编辑:
PHP 代码:
echo pam_chpass($username, $password, $new_pass, &$error) ? 'good' : $error;
PHP (echo) 输出:
Permission denied (in pam_authenticate)
来自 /var/log/auth (这些实际上是之前的,日志似乎无法在 ATM 上工作,由于某种原因尚未确定):
Jun 11 15:30:20 veda php: pam_unix(php:chauthtok): conversation failed
Jun 11 15:30:20 veda php: pam_unix(php:chauthtok): password - (old) token not obtained
Jun 11 15:30:20 veda php: pam_winbind(php:chauthtok): valid_user: wbcGetpwnam gave WBC_ERR_DOMAIN_NOT_FOUND
其他:
抱歉缺少之前的细节,当我发布问题时我真的很累,但这仍然是一个蹩脚的借口。
Are there any working packages to change a linux user passwords using PHP?
I've tried using PECL:PAM but theres an error when it tries to change the password.
Edit:
PHP code:
echo pam_chpass($username, $password, $new_pass, &$error) ? 'good' : $error;
PHP (echo) output:
Permission denied (in pam_authenticate)
From /var/log/auth (these are actually from before, the log doesn't seem to be working ATM for some reason yet to be determined):
Jun 11 15:30:20 veda php: pam_unix(php:chauthtok): conversation failed
Jun 11 15:30:20 veda php: pam_unix(php:chauthtok): password - (old) token not obtained
Jun 11 15:30:20 veda php: pam_winbind(php:chauthtok): valid_user: wbcGetpwnam gave WBC_ERR_DOMAIN_NOT_FOUND
Other:
Sorry for the lack of details before, I was really tired when I posted the question but thats still a crappy excuse.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这真的非常非常危险。假设您了解风险,那么您会意识到在应用更改之前需要构建许多约束,这些约束必须在允许更改密码的权限级别中实现 - 即运行此代码的代码必须是独立的可执行文件setuid executoin 或通过 sudo 从您的 php 代码调用。
当然,没有理由不能用 PHP 编写独立代码,除了 PHP 中的 PAM 绑定(至少是我上次看到这个)相当不成熟这一事实之外,
您可能想要一个 可用)或使用 proc_open('/usr/bin/passwd'... 并正确阅读并响应提示。HTH
查看 chpasswd 程序(在 Redhat 和其他一些发行版上
C.
This is really, really dangerous. Assuming you understand the risks then you'll realise that you need to build a number of constraints before applying the change which must be implemented in the privilege level which allows passwords to be changed - i.e. the code to run this must be a standalone executable with either setuid executoin or called via sudo from your php code.
Of course there's no reason that the standalone code couldn't be written in PHP, other than the fact that the (at least, the last time I looked at this) the PAM bindings in PHP were rather immature,
You might want to have a look at the chpasswd program (available on Redhat and some others distros) or use proc_open('/usr/bin/passwd'... and read and respond to the prompts correctly.
HTH
C.
您可以使用 RSBAC 密码。
容易多了。
You could use RSBAC passwords.
So much easier.
经过几个小时的在线研究,我无法找到一个超级好的选择,所以我实现了这个技巧。它使用这篇文章 用于使用 PHP 更改密码。
我还使用 PECL:PAM 包 添加一些验证。
此页面位于安全的 HTTPS 文件夹上(通过 .htaccess 自动重定向)
我还在 https://serverfault.com/questions/150306/how-to-let-users-change-linux-password-from-web-browser/152409# 152409
After hours of research online, I wasn't able to find a super good option so I'm implemented this hack. It uses this article for changing passwords using PHP.
I'm also using the PECL:PAM package to add a little verification.
This page is on a secure HTTPS folder (automatic redirect via .htaccess)
I also have this question/answer posted in https://serverfault.com/questions/150306/how-to-let-users-change-linux-password-from-web-browser/152409#152409
除了 wag2369 发布的答案之外,请确保执行以下操作:
安装 pear,它是 PHP 的扩展管理器:
从 yum 安装 pam-devel
安装 PHP PAM 扩展
--alldeps:意味着自动安装所有依赖项
修改文件 < code>/etc/php.ini 并输入以下内容:
执行以下操作以允许 PAM php 服务:
重新启动 apache:
/etc/shadow 应该可读(这是一个安全漏洞,请重新考虑)
如果没有,请安装 Expect已安装
修复 wag2369 发布的代码中的错误或仅复制以下修改后的代码:
使用 array_push($error,..) 而不是 array_push(&$error, ...)
不应使用“passwd:密码已成功更新”,请使用
“passwd:所有身份验证令牌均已成功更新。”来检查。
In addition to the answer posted by wag2369, make sure to perform the following:
Install pear which is the extension manager for PHP:
Install pam-devel from yum
Install the PHP PAM extension
--alldeps: Means automatically install all dependencies
Modify the file
/etc/php.ini
and enter the following:Do the following to allow PAM php service:
Restart apache:
/etc/shadow should be readable (this is a security hole, rethink please)
Install expect if not already installed
Fix the bugs in the code posted by wag2369 or just copy the modified code below:
Use array_push($error,..) instead of array_push(&$error, ...)
'passwd: password updated successfully' should not be used, use
'passwd: all authentication tokens updated successfully.' to check instead.
直接从 PHP 更改 PAM 密码需要对系统文件和服务进行大量访问。这是因为 PAM 默认情况下使用 pam_unix 模块,该模块将用户凭据存储在 root 拥有的系统文件中。解决此问题的一个好方法是设置 PAM 以使用 pam_ldap 模块。这样,PAM 就可以使用 LDAP 服务器对用户进行身份验证。然后,您可以使用用户凭据从 PHP 绑定到 LDAP 服务器并更改其密码。此类修改的授权可以由 LDAP 授权机制负责。 (您的应用程序还应该强制执行授权规则,以提供分层安全性)
上述配置并不简单。您必须首先设置 LDAP 服务器,然后将所有用户数据从系统文件(passwd、shadow)迁移到 LDAP 目录。 (有自动化工具)。最后,您必须安装并设置 pam_ldap 模块。上述过程中的任何错误配置都可能导致严重的安全问题。
另请注意,这样您将通过应用程序将 LDAP 服务器公开到网络。任何可能影响 LDAP 身份验证或授权机制的安全问题也会影响您的系统安全。
资源:
使用 LDAP 存储 POSIX 帐户:
http://www.ibm.com /developerworks/linux/library/l-openldap/
设置 PAM 以使用 LDAP 进行身份验证:
http: //wiki.debian.org/LDAP/PAM
Changing PAM passwords from PHP directly, requires to much access to your system files and services. This is because PAM by default uses the pam_unix module, that stores user credentials in system files owned by root. A good way to overcome this problem, is to setup PAM to use the pam_ldap module. This way PAM with authenticate users using an LDAP server. Then from PHP you can bind to the LDAP server using the user credentials and change his password. Authorization for such a modification will can be taken care of by the LDAP authorization mechanism. (Your application should also enforce authorization rules, in order to provide layered security)
The above configuration is not trivial. You must first setup an LDAP server, then migrate all your user data from system files (passwd, shadow) to the LDAP directory. (there are automated tools for that). And finally you must install and setup the pam_ldap module. Any misconfigurations in the above process can lead to serious security issues.
Please, also note that this way you will be exposing the LDAP server to the web through your application. Any security issues that may affect LDAP authentication or authorization mechanisms will also affect your system security.
Resources:
Using LDAP to store POSIX accounts:
http://www.ibm.com/developerworks/linux/library/l-openldap/
Setup PAM to use LDAP for authentication:
http://wiki.debian.org/LDAP/PAM