30 lines
686 B
Python
Executable file
30 lines
686 B
Python
Executable file
#!/usr/bin/env python3
|
|
import subprocess
|
|
import hashlib
|
|
import sys
|
|
|
|
destfile = "authkeyfile/authorized_keys"
|
|
|
|
p = subprocess.Popen(["./ldap_query.py"], stdout=subprocess.PIPE, stdin=subprocess.PIPE)
|
|
(po, pr) = p.communicate()
|
|
if(p.returncode != 0):
|
|
print("Data from ldap_query.py seems to be invalid. QUIT")
|
|
sys.exit(1)
|
|
|
|
newhash = hashlib.md5(po).hexdigest()
|
|
#print(newhash)
|
|
|
|
try:
|
|
f = open(destfile, "rb")
|
|
oldhash = hashlib.md5(f.read()).hexdigest()
|
|
f.close()
|
|
# print(oldhash)
|
|
except:
|
|
oldhash = None
|
|
print("cannot open auth key file for read")
|
|
|
|
if newhash != oldhash:
|
|
# print("Updating file")
|
|
f = open(destfile, "wb")
|
|
f.write(po)
|
|
f.close()
|