2 # -*-mode: python; coding: iso-8859-1 -*-
4 # Copyright (c) 2002-2005 Cendio AB. All rights reserved.
14 class PartialMOUNTClient:
19 self.packer = mountclient.mountpacker.MOUNTPacker(self)
20 self.unpacker = mountclient.mountpacker.MOUNTUnpacker(self, '')
22 def mnt(self, dirpath):
23 res = mountclient.mounttypes.mountres3(self)
24 self.make_call(mountclient.mountconstants.MOUNTPROC_MNT,
25 dirpath, self.packer.pack_string, res.unpack)
29 class TCPMOUNTClient(PartialMOUNTClient, rpc.RawTCPClient):
30 def __init__(self, host, port):
31 rpc.RawTCPClient.__init__(self, host,
32 mountclient.mountconstants.MOUNT_PROGRAM,
33 mountclient.mountconstants.MOUNT_V3,
35 PartialMOUNTClient.__init__(self)
39 def __init__(self, host, port):
40 self.mountcl = TCPMOUNTClient(host, port)
42 def getotp(self, password):
43 res = self.mountcl.mnt("@getnonce")
45 if res.fhs_status != mountclient.mountconstants.MNT3_OK:
46 print >>sys.stderr, "Failed to get nonce:", mountclient.mountconstants.mountstat3_id[res.fhs_status]
49 fhandle = res.mountinfo.fhandle
50 digest = md5.new(fhandle + password).hexdigest()
55 print >>sys.stderr, "Usage: nfsotpclient.py host[:port]"
59 if __name__ == "__main__":
60 if len(sys.argv) != 2:
63 fields = sys.argv[1].split(":")
69 # No port specified, fetch from portmapper
71 print >>sys.stderr, "Portmapper support not yet implemented"
74 cl = NFSOTPClient(host, port)
76 password = getpass.getpass()
78 print cl.getotp(password)