mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-05 16:04:09 -07:00
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>
This commit is contained in:
parent
adce695aba
commit
41dfc5162f
3 changed files with 112 additions and 24 deletions
|
@ -706,7 +706,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:
|
||||
|
@ -714,7 +714,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))
|
||||
|
||||
|
@ -1180,7 +1180,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…
Add table
Add a link
Reference in a new issue