def login(self, user, passwd, authsrv): maxbuf, vers = self.rpc.version(16 * 1024, P9.version) if vers != P9.version: raise Error("version mismatch: %r" % vers) afid = self.AFID try: self.rpc.auth(afid, user, '') needauth = 1 except P9.RpcError as e: afid = P9.nofid if afid != P9.nofid: if passwd is None: raise Error("Password required") import P9sk1 try: P9sk1.clientAuth(self.rpc, afid, user, P9sk1.makeKey(passwd), authsrv, P9sk1.AUTHPORT) except socket.error as e: raise Error("%s: %s" % (authsrv, e.args[1])) self.rpc.attach(self.ROOT, afid, user, "") if afid != P9.nofid: self.rpc.clunk(afid) self.rpc.walk(self.ROOT, self.CWD, [])
class Client(object): """ A tiny 9p client. """ AFID = 10 ROOT = 11 CWD = 12 F = 13 def __init__(self, fd, user, passwd, authsrv): self.rpc = P9.RpcClient(fd) self.login(user, passwd, authsrv) def login(self, user, passwd, authsrv): maxbuf, vers = self.rpc.version(16 * 1024, P9.version) if vers != P9.version: raise Error("version mismatch: %r" % vers) afid = self.AFID try: self.rpc.auth(afid, user, '') needauth = 1 except P9.RpcError, e: afid = P9.nofid if afid != P9.nofid: if passwd is None: raise Error("Password required") import P9sk1 try: P9sk1.clientAuth(self.rpc, afid, user, P9sk1.makeKey(passwd), authsrv, P9sk1.AUTHPORT) except socket.error, e: raise Error("%s: %s" % (authsrv, e.args[1]))
def main(prog, *args): import getopt import getpass port = P9.PORT root = '/' mods = [] try: opt, args = getopt.getopt(args, "dm:p:r:") except: usage(prog) for opt, optarg in opt: if opt == "-d": global dbg import debug dbg = 1 if opt == '-m': mods.append(optarg) if opt == '-r': root = optarg if opt == "-p": port = int(optarg) if len(args) < 2: usage(prog) user = args[0] dom = args[1] passwd = getpass.getpass() key = P9sk1.makeKey(passwd) mount('/', LocalFs(root)) for m in mods: x = __import__(m) mount(x.mountpoint, x.root) print('%s loaded.' % m) sockserver(user, dom, key, port)