Cleanup logic and be more paranoid about passwords with spaces
This commit is contained in:
parent
5c5806d669
commit
b58d7470d4
1 changed files with 21 additions and 14 deletions
|
@ -134,17 +134,24 @@ class LookupModule(LookupBase):
|
|||
f.write(content + '\n')
|
||||
else:
|
||||
content = open(path).read().rstrip()
|
||||
sep = content.find(' ')
|
||||
|
||||
if sep >= 0:
|
||||
if params['encrypt'] is not None:
|
||||
try:
|
||||
sep = content.rindex(' ')
|
||||
except ValueError:
|
||||
password = content
|
||||
salt = None
|
||||
else:
|
||||
salt_field = content[sep + 1:]
|
||||
if salt_field.startswith('salt='):
|
||||
password = content[:sep]
|
||||
salt = content[sep + 1:].split('=')[1]
|
||||
salt = salt_field[len('salt=':]
|
||||
else:
|
||||
password = content
|
||||
salt = None
|
||||
|
||||
# crypt requested, add salt if missing
|
||||
if (params['encrypt'] is not None and not salt):
|
||||
if not salt:
|
||||
salt = self.random_salt()
|
||||
content = '%s salt=%s' % (password, salt)
|
||||
with open(path, 'w') as f:
|
||||
|
|
Loading…
Reference in a new issue