def write(self, srv, req): f = req.fid buf = req.ifcall.data if f.phase == self.NeedSign: signature = pickle.loads(buf) if f.key.verify(f.chal, signature): f.phase = self.Success f.suid = f.uname req.ofcall.count = len(buf) srv.respond(req, None) return else: raise py9p.ServerError('signature not verified') raise py9p.ServerError("unexpected phase")
def open(self, srv, req): '''If we have a file tree then simply check whether the Qid matches anything inside. respond qid and iounit are set by protocol''' f = self.storage.checkout(req.fid.qid.path) if (req.ifcall.mode & f.mode) != py9p.OREAD: raise py9p.ServerError("permission denied") srv.respond(req, None)
def write(self, target, data, offset=0): f = self.checkout(target) f.writelock = True if f.qid.type & py9p.QTDIR: raise py9p.ServerError("Is a directory") f.data.seek(offset, os.SEEK_SET) f.data.write(data) return len(data)
def read(self, srv, req): f = req.fid if f.phase == self.HaveChal: f.phase = self.NeedSign req.ofcall.data = pickle.dumps(f.key.encrypt(f.chal, '')) srv.respond(req, None) return elif f.phase == self.Success: req.ofcall.data = 'success as ' + f.suid srv.respond(req, None) return raise py9p.ServerError("unexpected phase")
def checkout(self, target): if not self.files.has_key(target): raise py9p.ServerError("file not found") return self.files[target]
def _os(func, *args): try: return func(*args) except OSError, e: raise py9p.ServerError(e.args)
import os.path import copy import time import pwd import grp import py9p def _os(func, *args): try: return func(*args) except OSError, e: raise py9p.ServerError(e.args) except IOError, e: raise py9p.ServerError(e.args) def _nf(func, *args): try: return func(*args) except py9p.ServerError, e: return def uidname(u): try: return "%s" % pwd.getpwuid(u).pw_name except KeyError, e: return "%d" % u