]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Bind to reserved port if root; changed mkcred interface; added -t/-u option
authorGuido van Rossum <guido@python.org>
Sun, 20 Dec 1992 14:57:17 +0000 (14:57 +0000)
committerGuido van Rossum <guido@python.org>
Sun, 20 Dec 1992 14:57:17 +0000 (14:57 +0000)
Demo/rpc/mountclient.py

index b284b7fa2c44544834de039f7ae9f31ed02a6d2e..269dfbc98c0500825705062c4d2a9c0ca6ac8509 100644 (file)
 import rpc
 from rpc import Packer, Unpacker, TCPClient, UDPClient
 
+
+# Program number and version for the mount protocol
 MOUNTPROG = 100005
 MOUNTVERS = 1
 
+# Size of the 'fhandle' opaque structure
 FHSIZE = 32
 
 
@@ -77,14 +80,21 @@ class PartialMountClient:
                self.packer = MountPacker().init()
                self.unpacker = MountUnpacker().init('')
 
-       # This function is called to gobble up a suitable
+       # This method is called by Client.init to bind the socket
+       # to a particular network interface and port.  We use the
+       # default network interface, but if we're running as root,
+       # we want to bind to a reserved port
+       def bindsocket(self):
+               import os
+               if os.getuid() == 0:
+                       port = rpc.bindresvport(self.sock, '')
+                       # 'port' is not used
+               else:
+                       self.sock.bind(('', 0))
+
+       # This function is called to cough up a suitable
        # authentication object for a call to procedure 'proc'.
-       # (Experiments suggest that for Mnt/Umnt, Unix authentication
-       # is necessary, while the other calls require no
-       # authentication.)
-       def mkcred(self, proc):
-               if proc not in (1, 3, 4): # not Mnt/Umnt/Umntall
-                       return rpc.AUTH_NULL, ''
+       def mkcred(self):
                if self.cred == None:
                        self.cred = rpc.AUTH_UNIX, rpc.make_auth_unix_default()
                return self.cred
@@ -158,13 +168,23 @@ class UDPMountClient(PartialMountClient, UDPClient):
 
 # A little test program for the Mount client.  This takes a host as
 # command line argument (default the local machine), prints its export
-# list, and attempt to mount and unmount each exported files system.
+# list, and attempts to mount and unmount each exported files system.
+# An optional first argument of -t or -u specifies the protocol to use
+# (TCP or UDP), default is UDP.
 
 def test():
        import sys
+       if sys.argv[1:] and sys.argv[1] == '-t':
+               C = TCPMountClient
+               del sys.argv[1]
+       elif sys.argv[1:] and sys.argv[1] == '-u':
+               C = UDPMountClient
+               del sys.argv[1]
+       else:
+               C = UDPMountClient
        if sys.argv[1:]: host = sys.argv[1]
        else: host = ''
-       mcl = UDPMountClient().init(host)
+       mcl = C().init(host)
        list = mcl.Export()
        for item in list:
                print item
@@ -174,4 +194,3 @@ def test():
                        print 'Sorry'
                        continue
                mcl.Umnt(item[0])
-       return