in tacacs-F4.0.4.28/do_auth.py [0:0]
def get_attribute(config, the_section, the_option, log_file, filename):
if not config.has_section(the_section):
log_file.write(strftime("%Y-%m-%d %H:%M:%S: ")
+ "Error: Section '%s' does not exist in %s\n"
% (the_section, filename))
sys.exit(1)
if not config.has_option(the_section, the_option):
log_file.write(strftime("%Y-%m-%d %H:%M:%S: ")
+ "Error: Option '%s' does not exist in section %s in file %s\n"
% (the_option, the_section, filename))
sys.exit(1)
#Should not have any exceptions - BUT, just in case
try:
attributes = config.get(the_section, the_option)
except ConfigParser.NoSectionError:
log_file.write(strftime("%Y-%m-%d %H:%M:%S: ")
+ "Error: Section '%s' Doesn't Exist!\n"
% (the_section))
sys.exit(1)
except ConfigParser.DuplicateSectionError:
log_file.write(strftime("%Y-%m-%d %H:%M:%S: ")
+ "Error: Duplicate section '%s'\n"
% (the_section))
sys.exit(1)
except ConfigParser.NoOptionError:
log_file.write(strftime("%Y-%m-%d %H:%M:%S: ")
+ "Error: '%s' not found in section '%s\n'"
% (the_option, the_section))
sys.exit(1)
#To do: finish exceptions.
except ConfigParser.ParsingError:
log_file.write(strftime("%Y-%m-%d %H:%M:%S: ")
+ "Error: Can't parse file '%s'! (You got me)\n"
% (filename))
sys.exit(1)
attributes = attributes.split('\n')
#Strip empty lines
attributes2 = []
for line in attributes:
if line:
attributes2.append(line)
return attributes2