From 75a3f9b2924abc76eaf09a5b34d03b65b1037df3 Mon Sep 17 00:00:00 2001 From: Joerg Steffens Date: Thu, 6 Jun 2019 15:03:49 +0200 Subject: [PATCH] Univention (UCS): change umask only temporary improvement Do a try/finally exception handling around modifying the umask. --- .../platforms/univention/univention-bareos.py | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/core/platforms/univention/univention-bareos.py b/core/platforms/univention/univention-bareos.py index e4de1102f73..6b5a64465a4 100644 --- a/core/platforms/univention/univention-bareos.py +++ b/core/platforms/univention/univention-bareos.py @@ -143,10 +143,12 @@ def createClientSecret(client_name): char_set = string.ascii_uppercase + string.digits + string.ascii_lowercase password=''.join(random.sample(char_set*40,40)) oldumask = os.umask(0o077) - with open(path,'w') as f: - f.write(password) - os.chown(path,-1,0) - os.umask(oldumask) + try: + with open(path,'w') as f: + f.write(password) + os.chown(path,-1,0) + finally: + os.umask(oldumask) return password @@ -165,11 +167,13 @@ def createClientJob(client_name,client_type,enable='Yes'): t=string.Template(content) oldumask = os.umask(0o077) - with open(path,"w") as f: - f.write(t.substitute(enable=enable, password=password, client_name=client_name)) - os.chown(path,-1,bareos_gid) - os.chmod(path,stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP) - os.umask(oldumask) + try: + with open(path,"w") as f: + f.write(t.substitute(enable=enable, password=password, client_name=client_name)) + os.chown(path,-1,bareos_gid) + os.chmod(path,stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP) + finally: + os.umask(oldumask) def disableClientJob(client_name,client_type): createClientJob(client_name,client_type,'No')