1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Cleanup logic and be more paranoid about passwords with spaces

This commit is contained in:
Toshio Kuratomi 2015-10-12 12:55:33 -07:00
parent 5c5806d669
commit b58d7470d4

View file

@ -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: