我getpass
用来简单有效地编辑 LDAP 密码。例如,当我使用密码c;_pr8\\E0L)ec*\'E._rPBH?"4i9Tne
并尝试运行程序时,我收到以下错误:
Traceback (most recent call last):
File "/usr/local/bin/editpasswd", line 73, in <module>
main()
File "/usr/local/bin/editpasswd", line 66, in main
users_generated_password = generate_password()
File "/usr/local/bin/editpasswd", line 52, in generate_password
return send_command(PASSWORD_CREATION_COMMAND.format(users_password=password_to_generate))
File "/usr/local/bin/editpasswd", line 33, in send_command
command = shlex.split(command)
File "/usr/lib/python2.7/shlex.py", line 279, in split
return list(lex)
File "/usr/lib/python2.7/shlex.py", line 269, in next
token = self.get_token()
File "/usr/lib/python2.7/shlex.py", line 96, in get_token
raw = self.read_token()
File "/usr/lib/python2.7/shlex.py", line 172, in read_token
raise ValueError, "No closing quotation"
ValueError: No closing quotation
我如何调用密码:
PASSWORD_CREATION_COMMAND = "slappasswd -s {users_password}"
def send_command(command):
command = shlex.split(command)
sender = subprocess.Popen(
command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
res, err = sender.communicate()
if res:
return res.strip()
if err:
return err.strip()
def generate_password():
password_to_generate = getpass.getpass(
prompt="Enter the new password: "
)
confirm_password_to_generate = getpass.getpass(
prompt="Confirm the password you just entered: "
)
if password_to_generate == confirm_password_to_generate:
return send_command(PASSWORD_CREATION_COMMAND.format(users_password=password_to_generate))
else:
print("[!] password did not match")
exit(-1)
我认为造成这种情况的原因是,当命令运行时,密码既有密码又有密码"
,'
所以它失败了,因为它试图找到一个结束引号,我怎样才能创建这个命令来接受给它的任何密码,它是否有 1 个或 7 个引号?
IE 我可以用三引号括起来而不影响密码吗?