CharmingYang0 / NfsClient

The python library to simulate NFS client, currently only support NFSv3
MIT License
26 stars 10 forks source link

Unpack the RPC response data error #10

Open aszx826477 opened 2 months ago

aszx826477 commented 2 months ago

Dear CharmingYang, I meet a problem while using your NfsClient library. Could you help me to see this problem. I use your sample code like this. When it getport from 10.232.94.126, it can get the correct port 635 from the NFS server (I print it)

mnt_port = portmap.getport(Mount.program, Mount.program_version)

However when running the mount

mnt_res = mount.mnt(mount_path, None) 

the RPC cannot unpack data correctly, it seems the data format is wrong but I don't know why.

Looking forward for your reply!

The Code written like this:

# variable preparation
host = "10.232.94.126"
mount_path = "/vol_log/VASC_SILA/VMS/VMSKPI"

auth = {
    "flavor": 1,
    "machine_name": "maccrt03",
    "uid": 0,
    "gid": 0,
    "aux_gid": list(),
}

# portmap initialization
portmap = Portmap(host, timeout=3600)
portmap.connect()

# mount initialization
mnt_port = portmap.getport(Mount.program, Mount.program_version)
print("mnt_port")
print(mnt_port)
mount = Mount(host=host, port=mnt_port, timeout=3600, auth=auth)
mount.connect()

# do mount
mnt_res = mount.mnt(mount_path, None) # Have problem
print(mnt_res)

[2024-09-05 04:43:42 mnt_port] [2024-09-05 04:43:42 635] [2024-09-05 04:43:42 rpc.request:125 - unpack requires a buffer of 24 bytesTraceback (most recent call last): File "pyNfsClient/rpc.py", line 117, in request ) = struct.unpack('!LLLLLL', rpc)struct.error: unpack requires a buffer of 24 bytes] [2024-09-05 04:43:42 'value=1725511422 not in enum mountstat3': Traceback (most recent call last):; File: "index.py", line 31, in handler; mnt_res = mount.mnt(mount_path, None); File: "pyNfsClient/mount.py", line 38, in mnt; res = unpacker.unpack_mountres3(); File: "pyNfsClient/pack.py", line 1728, in unpack_mountres3; data.status = self.unpack_mountstat3(); File: "pyNfsClient/pack.py", line 1717, in unpack_mountstat3; raise XDRError('value=%s not in enum mountstat3' % data); xdrlib.Error: value=1725511422 not in enum mountstat3;]

NeffIsBack commented 1 month ago

Hi, i had the same problem so i dove into the issue. The problem is an incomplete handling of the rpc answer. If the rpc request gets a MSG_DENIED error the reply is shorter than usual, so the unpacking fails. As i don't think this repo is maintained anymore (the last commit is over 5 years ago) i patched it myself: https://github.com/Pennyw0rth/NfsClient