user: fix removing the expiry time when it's 0 (#47115)

user: fix removing the expiry time when it's 0 (#47115)

* user: fix removing the expiry time when it's 0

* Improve tests and add changelog

Co-authored-by: Martin Krizek <martin.krizek@gmail.com>
(cherry picked from commit 41dfc5162f)
pull/49215/head
Sam Doran 6 years ago committed by Matt Clay
parent 4d748d34f9
commit f936309d93

@ -0,0 +1,2 @@
bugfixes:
- user - properly remove expiration when set to a negative value (https://github.com/ansible/ansible/issues/47114)

@ -662,7 +662,7 @@ class User(object):
current_expires = int(self.user_password()[1])
if self.expires < time.gmtime(0):
if current_expires > 0:
if current_expires >= 0:
cmd.append('-e')
cmd.append('')
else:
@ -670,7 +670,7 @@ class User(object):
current_expire_date = time.gmtime(current_expires * 86400)
# Current expires is negative or we compare year, month, and day only
if current_expires <= 0 or current_expire_date[:3] != self.expires[:3]:
if current_expires < 0 or current_expire_date[:3] != self.expires[:3]:
cmd.append('-e')
cmd.append(time.strftime(self.DATE_FORMAT, self.expires))
@ -1136,7 +1136,9 @@ class FreeBsdUser(User):
current_expires = int(self.user_password()[1])
if self.expires < time.gmtime(0):
# If expiration is negative or zero and the current expiration is greater than zero, disable expiration.
# In OpenBSD, setting expiration to zero disables expiration. It does not expire the account.
if self.expires <= time.gmtime(0):
if current_expires > 0:
cmd.append('-e')
cmd.append('0')

Loading…
Cancel
Save