Beispiel #1
0
    def getDocuments(cls, database, buddy=None, *path):
        helper = DocumentHelper(cls, database)

        if len(path) > 0:
            login = get_user_infos(uid=int(buddy))["login"]
            for doc in helper.by_dir(key="/" + "/".join([login] + list(path))):
                yield doc

        elif buddy:
            uid = int(buddy)
            shared_dirs = {}
            provider_id = get_user_infos(login=database.name)["uid"]
            startkey = [provider_id, uid]
            endkey = [provider_id, uid + 1]
            for key, doc in helper.by_provider_and_participant(startkey=startkey, endkey=endkey):
                if doc.type == "application/x-directory":
                    shared_dirs[doc.path] = doc
                else:
                    if doc.dirpath in shared_dirs:
                        continue
                yield doc

        else:
            uid = utils.get_user_infos(login=database.name)["uid"]
            for key, doc in helper.by_provider_and_participant(startkey=[uid], group_level=2, reduce=True):
                if key != uid:
                    # Retrieve participant infos from gss api
                    infos = utils.get_user_infos(uid=key[1])
                    yield cls(
                        filename=infos["login"],
                        dirpath=os.sep,
                        mode=0555 | stat.S_IFDIR,
                        uid=infos["uid"],
                        gid=infos["gid"],
                        type="application/x-directory",
                    )
Beispiel #2
0
 def from_string(s):
     kind, qualifier, perms = s.split(':')
     for key, value in acl_types.items():
         if value == kind or value[0] == kind:
             if key == ACL_USER_OBJ and qualifier:
                 key = ACL_USER
                 _qualifier = get_user_infos(login=qualifier)['uid']
             elif key == ACL_GROUP_OBJ and qualifier:
                  key = ACL_GROUP
                  _qualifier = 0
             else:
                  _qualifier = ACL_UNQUALIFIED
             _kind = key
             break
     _perms = ACE.perms_from_string(perms)
     return ACE(_kind, _perms, _qualifier)
Beispiel #3
0
  def rename(self, old, new):
    try:
      # Replace the full name of the friend by its uid within the path
      new = self.hackedPath(new)

      remote = rpc.Server(config.sync_host, KerbTransport())
      owner  = os.environ['USER'].encode('utf8')

      friend_uid = os.path.basename(os.path.dirname(new))
      friend = utils.get_user_infos(uid=int(friend_uid))['login']

      document = self._syncDocs.by_path(key=self.overlayPath(old), pk=True)

      self.debug("Sharing file %s from '%s' to '%s'" % (document.id, owner, friend))

      try:
        remote.sync.add_new_share(friend, document.id, "R")
      except rpc.Fault, f:
        raise utils.fault_to_exception(f)

    except AlreadySharedDocError, e:
      raise OSError(errno.EEXIST, str(e))
Beispiel #4
0
  def removeCachedFile(self, path, removeperm=False):
    try:
      # Replace the full name of the friend by its uid within the path.
      uidpath = self.hackedPath(path)

      # Here we want to remove a file that correspond to an active
      # share with a friend.
      if self.isFileLevel(path):
        remote = rpc.Server(config.sync_host, KerbTransport())
        owner  = unicode(os.environ['USER'], "utf8")

        friend_uid = uidpath.split(os.sep)[1]
        friend = utils.get_user_infos(uid=int(friend_uid))['login']

        document = self._syncDocs.by_path(key=self.realFilePath(path), pk=True)

        self.debug("%s remove %s from the share of '%s'" % (owner, friend, document.id))

        try:
          remote.sync.remove_participant_from_share(friend, document.id)
        except rpc.Fault, f:
          raise utils.fault_to_exception(f)

      else:
Beispiel #5
0
 def gecos(self):
     if self.type == "application/x-directory":
         return get_user_infos(uid=self.uid)['fullname']
     else:
         return ""
Beispiel #6
0
 def fullname(self):
     return get_user_infos(login=self.initiator)['fullname']
Beispiel #7
0
@extendedattribute('file', 'tsumufs.myshares.share')
def xattr_share(type_, path, friend=None):
   if tsumufs.viewsManager.isAnyViewPath(path):
     path = tsumufs.viewsManager.realFilePath(path)

   try:
     posix_acl = tsumufs.cacheManager.getxattr(path, acl.ACL_XATTR)
   except KeyError, e:
     current_acl = acl.ACL.from_mode(tsumufs.cacheManager.statFile(path).st_mode)
   else:
     current_acl = acl.ACL.from_xattr(posix_acl)

   current_acl.append(acl.ACE(acl.ACL_USER,
                              acl.ACL_READ,
                              utils.get_user_infos(login=friend)['uid']))

   tsumufs.cacheManager.setxattr(path, acl.ACL_XATTR, current_acl.to_xattr())

   return 0

@extendedattribute('file', 'tsumufs.myshares.unshare')
def xattr_unshare(type_, path, value=None):
   if tsumufs.viewsManager.isAnyViewPath(path):
     path = tsumufs.viewsManager.realFilePath(path)

   try:
     posix_acl = tsumufs.cacheManager.getxattr(path, acl.ACL_XATTR)
   except KeyError, e:
     return errno.ENODATA
Beispiel #8
0
 def qualifier(self):
     if self.kind & ACL_USER:
         return get_user_infos(uid=self._qualifier)['login']
     return ""
Beispiel #9
0
 def to_nfs4(self):
     if self._qualifier != (1 << 32) - 1:
         qualifier = get_user_infos(uid=self._qualifier)['login'] + '@' + ACL.default_domain
     else:
         qualifier = nfs4_acl_types[self.kind]
     return "A::%s:%s" % (qualifier, self.nfs4_perms)
Beispiel #10
0
    def __repr__(self):
        qualifier = ""
        if self._qualifier != (1 << 32) - 1:
            qualifier = get_user_infos(uid=self._qualifier)['login']

        return "%s:%s:%s" % (acl_types[self.kind], qualifier, self.perms)