Skip to content

Commit

Permalink
Update sanitize_user_deployment_cfg()
Browse files Browse the repository at this point in the history
The sanitize_user_deployment_cfg() has been converted into
validate_user_deployment_cfg() which will validate user
deployment configuration instead of fixing it silently.
  • Loading branch information
edewata committed May 30, 2024
1 parent 43feca1 commit 3a68683
Showing 1 changed file with 10 additions and 28 deletions.
38 changes: 10 additions & 28 deletions base/server/python/pki/server/pkispawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def main(argv):
parser.indent = 0
print(log.PKISPAWN_INTERACTIVE_INSTALLATION)
else:
sanitize_user_deployment_cfg(config.user_deployment_cfg)
validate_user_deployment_cfg(config.user_deployment_cfg)

# Only run this program as "root".
if not os.geteuid() == 0:
Expand Down Expand Up @@ -676,35 +676,17 @@ def main(argv):
print_final_install_information(parser.mdict, deployer.instance)


def sanitize_user_deployment_cfg(cfg):
def validate_user_deployment_cfg(user_deployment_cfg):
'''
Validate section headings in user configuration file.
'''

# Correct any section headings in the user's configuration file
for line in fileinput.FileInput(cfg, inplace=1):
# Remove extraneous leading and trailing whitespace from all lines
for line in fileinput.FileInput(user_deployment_cfg):
line = line.strip()
# Normalize section headings to match '/usr/share/pki/server/etc/default.cfg'
if line.startswith("["):
if line.upper().startswith("[DEFAULT"):
line = "[DEFAULT]"
elif line.upper().startswith("[TOMCAT"):
line = "[Tomcat]"
elif line.upper().startswith("[CA"):
line = "[CA]"
elif line.upper().startswith("[KRA"):
line = "[KRA]"
elif line.upper().startswith("[OCSP"):
line = "[OCSP]"
elif line.upper().startswith("[RA"):
line = "[RA]"
elif line.upper().startswith("[TKS"):
line = "[TKS]"
elif line.upper().startswith("[TPS"):
line = "[TPS]"
else:
# Notify user of the existence of an invalid section heading
sys.stderr.write("'%s' contains an invalid section "
"heading called '%s'!\n" % (cfg, line))
print(line)
if not line.startswith('['):
continue
if line not in ['[DEFAULT]', '[Tomcat]', '[CA]', '[KRA]', '[OCSP]', '[TKS]', '[TPS]']:
raise Exception('Invalid deployment configuration section: %s' % line)


def create_master_dictionary(parser):
Expand Down

0 comments on commit 3a68683

Please sign in to comment.