Skip to content

Commit 674fe5e

Browse files
authored
Merge pull request Pennyw0rth#584 from Pennyw0rth/neff-nfs-escape-to-rootfs
Small bug fixes for NFS
2 parents 9768568 + 4a696df commit 674fe5e

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

nxc/protocols/nfs.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,8 @@ def put_file(self):
445445

446446
# Iterate over the path
447447
curr_fh = mount_fh
448-
for sub_path in remote_dir_path.lstrip("/").split("/"):
448+
# If target dir is "" or "/" without filter we would get one item with [""]
449+
for sub_path in list(filter(None, remote_dir_path.lstrip("/").split("/"))):
449450
self.update_auth(mount_fh)
450451
res = self.nfs3.lookup(curr_fh, sub_path, auth=self.auth)
451452

@@ -494,7 +495,7 @@ def put_file(self):
494495
file_data = file.read().decode()
495496

496497
# Write the data to the remote file
497-
self.logger.display(f"Trying to write data from {local_file_path} to {remote_file_path}")
498+
self.logger.info(f"Trying to write data from {local_file_path} to {remote_file_path}")
498499
res = self.nfs3.write(file_handle, 0, len(file_data), file_data, 1, auth=self.auth)
499500
if res["status"] != 0:
500501
self.logger.fail(f"Error writing to {remote_file_path}: {NFSSTAT3[res['status']]}")
@@ -645,7 +646,13 @@ def ls(self):
645646
break
646647
curr_fh = res["resok"]["object"]["data"]
647648

649+
# Update the UID and GID for the file/dir
650+
self.update_auth(curr_fh)
651+
648652
dir_listing = self.nfs3.readdirplus(curr_fh, auth=self.auth)
653+
if dir_listing["status"] != 0:
654+
self.logger.fail(f"Error on listing directory: {NFSSTAT3[dir_listing['status']]}")
655+
return
649656
content = self.format_directory(dir_listing)
650657

651658
# Sometimes the NFS Server does not return the attributes for the files
@@ -676,8 +683,6 @@ def print_directory(self, content, path):
676683
self.logger.highlight(f"{'UID':<11}{'Perms':<7}{'File Size':<14}{'File Path'}")
677684
self.logger.highlight(f"{'---':<11}{'-----':<7}{'---------':<14}{'---------'}")
678685
for item in content:
679-
if item["name"] in [b".", b".."]:
680-
continue
681686
if not item["name_attributes"]["present"] or not item["name_handle"]["present"]:
682687
uid = "-"
683688
perms = "----"

0 commit comments

Comments
 (0)