mirror of https://github.com/python/cpython.git
Bind to reserved port if root; changed mkcred interface; added -t/-u option
This commit is contained in:
parent
79f85eedfd
commit
fd92ac89cc
|
@ -11,9 +11,12 @@
|
||||||
import rpc
|
import rpc
|
||||||
from rpc import Packer, Unpacker, TCPClient, UDPClient
|
from rpc import Packer, Unpacker, TCPClient, UDPClient
|
||||||
|
|
||||||
|
|
||||||
|
# Program number and version for the mount protocol
|
||||||
MOUNTPROG = 100005
|
MOUNTPROG = 100005
|
||||||
MOUNTVERS = 1
|
MOUNTVERS = 1
|
||||||
|
|
||||||
|
# Size of the 'fhandle' opaque structure
|
||||||
FHSIZE = 32
|
FHSIZE = 32
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,14 +80,21 @@ def addpackers(self):
|
||||||
self.packer = MountPacker().init()
|
self.packer = MountPacker().init()
|
||||||
self.unpacker = MountUnpacker().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'.
|
# authentication object for a call to procedure 'proc'.
|
||||||
# (Experiments suggest that for Mnt/Umnt, Unix authentication
|
def mkcred(self):
|
||||||
# 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, ''
|
|
||||||
if self.cred == None:
|
if self.cred == None:
|
||||||
self.cred = rpc.AUTH_UNIX, rpc.make_auth_unix_default()
|
self.cred = rpc.AUTH_UNIX, rpc.make_auth_unix_default()
|
||||||
return self.cred
|
return self.cred
|
||||||
|
@ -158,13 +168,23 @@ def init(self, host):
|
||||||
|
|
||||||
# A little test program for the Mount client. This takes a host as
|
# A little test program for the Mount client. This takes a host as
|
||||||
# command line argument (default the local machine), prints its export
|
# 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():
|
def test():
|
||||||
import sys
|
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]
|
if sys.argv[1:]: host = sys.argv[1]
|
||||||
else: host = ''
|
else: host = ''
|
||||||
mcl = UDPMountClient().init(host)
|
mcl = C().init(host)
|
||||||
list = mcl.Export()
|
list = mcl.Export()
|
||||||
for item in list:
|
for item in list:
|
||||||
print item
|
print item
|
||||||
|
@ -174,4 +194,3 @@ def test():
|
||||||
print 'Sorry'
|
print 'Sorry'
|
||||||
continue
|
continue
|
||||||
mcl.Umnt(item[0])
|
mcl.Umnt(item[0])
|
||||||
return
|
|
||||||
|
|
Loading…
Reference in New Issue