66
77from pathlib import Path
88from os import path
9- from datetime import datetime , timedelta
9+ from datetime import datetime , timedelta , timezone
1010from dns import resolver , rdatatype
1111from shutil import which
1212from pid import PidFile , PidFileAlreadyLockedError , PidFileAlreadyRunningError
@@ -161,7 +161,7 @@ def searchComputer(self):
161161 self .tmpExpiryDate = filetime_to_dt ( int (str (entry [self .cfgLdapAttributePasswordExpiry ])) )
162162 except Exception as e :
163163 print ('Unable to parse date ' + str (self .tmpExpiry )+ ' - assuming that no expiration date is set.' )
164- self .tmpExpiryDate = datetime .fromtimestamp (0 , datetime . timezone .utc )
164+ self .tmpExpiryDate = datetime .fromtimestamp (0 , timezone .utc )
165165 return True
166166
167167 # no result found
@@ -181,7 +181,7 @@ def updatePassword(self):
181181 # generate new values
182182 newPassword = self .generatePassword ()
183183 newPasswordHashed = CryptContext (schemes = ['sha512_crypt' ]).hash (newPassword )
184- newExpirationDate = datetime .now () + timedelta (days = self .cfgDaysValid )
184+ newExpirationDate = datetime .now (). astimezone ( timezone . utc ) + timedelta (days = self .cfgDaysValid )
185185
186186 # update password in local database
187187 self .updateLocalPassword (self .cfgUsername , newPasswordHashed )
@@ -232,7 +232,7 @@ def setPasswordAndExpiry(self, newPassword, newExpirationDate):
232232 newPassword = json .dumps ({
233233 'p' : newPassword ,
234234 'n' : self .cfgUsername ,
235- 't' : ('%0.2X' % dt_to_filetime (datetime .now ())).lower ()
235+ 't' : ('%0.2X' % dt_to_filetime (datetime .now (). astimezone ( timezone . utc ) )).lower ()
236236 })
237237
238238 # encrypt Native LAPS content
@@ -305,7 +305,7 @@ def encryptPassword(self, content):
305305 # 8-12 - blob size, uint32
306306 # 12-16 - flags, currently always 0
307307 preMagic = (
308- self .rotate_and_pack_msdatetime (dt_to_filetime (datetime .now ()))
308+ self .rotate_and_pack_msdatetime (dt_to_filetime (datetime .now (). astimezone ( timezone . utc ) ))
309309 + struct .pack ('<i' , len (encrypted ))
310310 + b'\x00 \x00 \x00 \x00 '
311311 )
@@ -416,7 +416,7 @@ def main():
416416 runner .connectToServer ()
417417 runner .searchComputer ()
418418
419- if runner .tmpExpiryDate < datetime .now ():
419+ if runner .tmpExpiryDate < datetime .now (). astimezone ( timezone . utc ) :
420420 print ('Updating password (expired ' + str (runner .tmpExpiryDate )+ ')' )
421421 runner .updatePassword ()
422422
@@ -436,7 +436,7 @@ def main():
436436 if runner .cfgPamGracePeriod :
437437 runner .logger .debug (__title__ + ': PAM grace period - waiting ' + str (runner .cfgPamGracePeriod )+ ' seconds...' )
438438 # set expiration in directory, e.g. to handle reboots
439- runner .setExpiry (datetime .now () + timedelta (seconds = runner .cfgPamGracePeriod ))
439+ runner .setExpiry (datetime .now (). astimezone ( timezone . utc ) + timedelta (seconds = runner .cfgPamGracePeriod ))
440440 # wait grace period
441441 time .sleep (runner .cfgPamGracePeriod )
442442 print ('Updating password (forced update by PAM)...' )
0 commit comments