Skip to content

Commit

Permalink
Ensure NFSv4 data is parsed correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Leseratte10 committed Aug 1, 2024
1 parent 6eea579 commit eae6a83
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/middlewared/middlewared/plugins/nfs_/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,25 @@ def get_nfs4_client_info(self, id_):
"""
info = {}
with suppress(FileNotFoundError):
# The data sent by the kernel isn't always 100% valid YAML
# The "callback address" field is missing quotation marks.
# So, read the whole file in Python, then if we encounter that line,
# add quotation marks before parsing as YAML.

with open(f"/proc/fs/nfsd/clients/{id_}/info", "r") as f:
info = yaml.safe_load(f.read())
yaml_data = f.readlines()

safe_content = ""

for line in yaml_data:
if line.startswith("callback address") and not '"' in line:
payload = line.split(':', 1)[1].strip()
safe_content += f'callback address: "{payload}"\n'
pass
else:
safe_content += line

info = yaml.safe_load(safe_content)

return info

Expand Down

0 comments on commit eae6a83

Please sign in to comment.