Skip to content

Commit

Permalink
Try to handle bad config file password
Browse files Browse the repository at this point in the history
If a user doesn't place a space between the ':' and the
password we simply get a string returned back from the yaml parse.

In this case we will ensure that the returned value is not none and
not simply a string.  Perhaps there is a better way to handle this?

Ref. open-iscsi#35

Signed-off-by: Tony Asleson <tasleson@redhat.com>
  • Loading branch information
tasleson committed Feb 25, 2020
1 parent 5279dee commit 0f339ad
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions targetd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,11 @@ def load_config(config_path):

if os.path.isfile(config_path):
config = yaml.safe_load(open(config_path).read())
if config is None:
# If a user supplies a password as "password:whatever" we don't get
# a parse failure, we simply get a string with the contents.
# Maybe there is a better way to handle this issue where we don't
# have a space between key and value?
if config is None or type(config) is str:
config = {}

for key, value in iter(default_config.items()):
Expand All @@ -221,8 +225,10 @@ def load_config(config_path):
config['block_pools'] = set(config['block_pools'])
config['fs_pools'] = set(config['fs_pools'])

if not config.get('password', None):
log.critical("password not set in %s" % config_path)
passwd = config.get('password', None)
if not passwd or type(passwd) is not str:
log.critical("password not set in %s in the form 'password: string_pw'"
% config_path)
raise AttributeError

# convert log level to int
Expand Down

0 comments on commit 0f339ad

Please sign in to comment.