From 27b3e7e84d1a77d854acaf93d3c99fb7040a1d2a Mon Sep 17 00:00:00 2001 From: Kevin Guerineau Date: Tue, 7 May 2024 16:15:14 +0200 Subject: [PATCH] [IMP] Check directory before create root ca --- common.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/common.py b/common.py index 176f74c..e3207c1 100644 --- a/common.py +++ b/common.py @@ -75,31 +75,36 @@ class TisPKI: -def check_directories(root_path): +def check_directories(path): print('Check directories') directories_list = ['certs','config','crl','newcerts','private','csr','crl','p12'] - if not os.path.isdir(root_path): + if not os.path.isdir(path): print(f'Create { root_path } directory') - os.makedirs(root_path) + os.makedirs(path) for directory in directories_list: - directory_path = os.path.join(root_path,directory) + directory_path = os.path.join(path,directory) if not os.path.isdir(directory_path): print(f'Create { directory_path } directory') os.makedirs(directory_path) - if not os.path.isfile(os.path.join(root_path,'index.txt')): - with open(os.path.join(root_path,'index.txt'),'w') as file: + if not os.path.isfile(os.path.join(path,'index.txt')): + with open(os.path.join(path,'index.txt'),'w') as file: pass def create_openssl_config(): print('Check Root CA OpenSSL Config') - root_ca_config = os.path.join(TisPKI.pki_dir(),'config','openssl_root_ca.ini') + if config.get('general','pki_dir'): + check_directories(path=config.get('general','pki_dir')) + else: + print('No pki_dir set in samba-pki-tools.ini') + sys.exit(1) + root_ca_config = os.path.join(TisPKI.pki_dir(),'config','openssl_root_ca.ini') if not os.path.isfile(root_ca_config): print('Root CA OpenSSL configfile not exist. Creating...')