1111import rpc
1212from rpc import Packer , Unpacker , TCPClient , UDPClient
1313
14+
15+ # Program number and version for the mount protocol
1416MOUNTPROG = 100005
1517MOUNTVERS = 1
1618
19+ # Size of the 'fhandle' opaque structure
1720FHSIZE = 32
1821
1922
@@ -77,14 +80,21 @@ def addpackers(self):
7780 self .packer = MountPacker ().init ()
7881 self .unpacker = MountUnpacker ().init ('' )
7982
80- # This function is called to gobble up a suitable
83+ # This method is called by Client.init to bind the socket
84+ # to a particular network interface and port. We use the
85+ # default network interface, but if we're running as root,
86+ # we want to bind to a reserved port
87+ def bindsocket (self ):
88+ import os
89+ if os .getuid () == 0 :
90+ port = rpc .bindresvport (self .sock , '' )
91+ # 'port' is not used
92+ else :
93+ self .sock .bind (('' , 0 ))
94+
95+ # This function is called to cough up a suitable
8196 # authentication object for a call to procedure 'proc'.
82- # (Experiments suggest that for Mnt/Umnt, Unix authentication
83- # is necessary, while the other calls require no
84- # authentication.)
85- def mkcred (self , proc ):
86- if proc not in (1 , 3 , 4 ): # not Mnt/Umnt/Umntall
87- return rpc .AUTH_NULL , ''
97+ def mkcred (self ):
8898 if self .cred == None :
8999 self .cred = rpc .AUTH_UNIX , rpc .make_auth_unix_default ()
90100 return self .cred
@@ -158,13 +168,23 @@ def init(self, host):
158168
159169# A little test program for the Mount client. This takes a host as
160170# command line argument (default the local machine), prints its export
161- # list, and attempt to mount and unmount each exported files system.
171+ # list, and attempts to mount and unmount each exported files system.
172+ # An optional first argument of -t or -u specifies the protocol to use
173+ # (TCP or UDP), default is UDP.
162174
163175def test ():
164176 import sys
177+ if sys .argv [1 :] and sys .argv [1 ] == '-t' :
178+ C = TCPMountClient
179+ del sys .argv [1 ]
180+ elif sys .argv [1 :] and sys .argv [1 ] == '-u' :
181+ C = UDPMountClient
182+ del sys .argv [1 ]
183+ else :
184+ C = UDPMountClient
165185 if sys .argv [1 :]: host = sys .argv [1 ]
166186 else : host = ''
167- mcl = UDPMountClient ().init (host )
187+ mcl = C ().init (host )
168188 list = mcl .Export ()
169189 for item in list :
170190 print item
@@ -174,4 +194,3 @@ def test():
174194 print 'Sorry'
175195 continue
176196 mcl .Umnt (item [0 ])
177- return
0 commit comments