Example #1
0
 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")
Example #2
0
    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)
Example #3
0
    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)
Example #4
0
 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")
Example #5
0
 def checkout(self, target):
     if not self.files.has_key(target):
         raise py9p.ServerError("file not found")
     return self.files[target]
Example #6
0
def _os(func, *args):
    try:
        return func(*args)
    except OSError, e:
        raise py9p.ServerError(e.args)
Example #7
0
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