问题描述
我当前正在尝试为Web服务器创建作为root脚本的登录名,我有一个小问题,php正在执行(使用exec())/usr/bin/python /var/www/html/QWP/public_html/scripts/checkadminpass.py root rootpassword
,以检查输入的密码是否为root密码,当我以root用户身份在终端中写入此命令时,它正在工作,但是当我在apache php中运行该命令时,我得到了python异常getspnam(): name not found
。
Python脚本:
import crypt # Interface to crypt(3),to encrypt passwords.
import spwd # Shadow password database (to read /etc/shadow).
import sys # get parameters
def login(user,password):
"""Tries to authenticate a user.
Returns True if the authentication succeeds,else the reason
(string) is returned."""
try:
enc_pwd = spwd.getspnam(user)[1]
if enc_pwd in ["LK","*"]:
return "false"
if enc_pwd == "!!":
return "false"
# Encryption happens here,the hash is stripped from the
# enc_pwd and the algorithm id and salt are used to encrypt
# the password.
if crypt.crypt(password,enc_pwd) == enc_pwd:
return True
else:
return "false"
except KeyError as errn:
return "false" # i tested and i GET THIS FALSE (getspnam(): name not found),when i run it terminal i get the correct response
return "false"
if __name__ == "__main__":
username = sys.argv[1]
password = sys.argv[2]
status = login(username,password)
if status == True:
print("true")
else:
print(status)
此exec()php函数由apache
用户运行。
有人可以帮助我吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)