Example #1
0
  def getAclDef(self, aclName, allRights='ZZ'):
    acls=[]
    for acl in shlexSplit(self.info[aclName][1:-1], ','):
      if acl.startswith('='):
        user='******'
        b=shlexSplit(acl[1:], '/')
      else:
        a=shlexSplit(acl, '=')
        user=quoteIdent(a[0])
        b=shlexSplit(a[1], '/')
      # grantor=b[1]

      privileges=""
      grants=""
      lastP=""
      for p in b[0]:
        if p == '*':
          grants += lastP
        else:
          lastP=p
          privileges += p

      def mkGrant(lst, withGrant=""):
        if lst == allRights:
          pl=['ALL']
        else:
          pl=[]
          for p in b[0]:
            pl.append(rightString[p])
        return "GRANT " + ",".join(pl) + " ON " + self.ObjectSql() +" TO " + user + withGrant +";"
      if privileges:
        acls.append(mkGrant(privileges))
      if grants:
        acls.append(mkGrant(grants, " WITH GRANT OPTION"))
    return acls  
Example #2
0
 def GrantCommentSql(self):
   str=""
   acl=self.info.get('acl')
   if acl:
     for grant in shlexSplit(acl[1:-1], ','):
       if grant.startswith('='):
         user="******"
         rest=grant[1:]
       else:
         user, rest=shlexSplit(grant, '=')
         user=quoteIdent(user)
       rights=shlexSplit(rest, '/')[0]
       if rights == self.allGrants:
         rights="ALL"
       else:
         rightlist=[]
         for right in rights:
           rightlist.append(rightString[right])
         rights=",".join(rightlist)
       str += "GRANT %s ON %s TO %s\n" % (rights, self.ObjectSql(), user)
     
   des=self.info.get('description')
   if des:
     str += "\nCOMMENT ON %s IS %s\n" % (self.ObjectSql(), quoteValue(des)) 
   return str
Example #3
0
    def GrantCommentSql(self):
        str = ""
        acl = self.info.get('acl')
        if acl:
            for grant in shlexSplit(acl[1:-1], ','):
                if grant.startswith('='):
                    user = "******"
                    rest = grant[1:]
                else:
                    user, rest = shlexSplit(grant, '=')
                    user = quoteIdent(user)
                rights = shlexSplit(rest, '/')[0]
                if rights == self.allGrants:
                    rights = "ALL"
                else:
                    rightlist = []
                    for right in rights:
                        rightlist.append(rightString[right])
                    rights = ",".join(rightlist)
                str += "GRANT %s ON %s TO %s\n" % (rights, self.ObjectSql(),
                                                   user)

        des = self.info.get('description')
        if des:
            str += "\nCOMMENT ON %s IS %s\n" % (self.ObjectSql(),
                                                quoteValue(des))
        return str
Example #4
0
 def splitMbInfo(self, line):
   parts=shlexSplit(line, ' ')
   separator=parts[-2]
   mailbox=parts[-1]
   flags=parts[:-2]
   flags[0] = flags[0][1:]
   flags[-1] = flags[-1][:-1]
   return (mailbox, separator, flags)
Example #5
0
 def splitMbInfo(self, line):
     parts = shlexSplit(line, ' ')
     separator = parts[-2]
     mailbox = parts[-1]
     flags = parts[:-2]
     flags[0] = flags[0][1:]
     flags[-1] = flags[-1][:-1]
     return (mailbox, separator, flags)
Example #6
0
 def __init__(self, parentNode, line):
   name, self.separator, self.flags = self.splitMbInfo(line)
   self.mailboxPath=name
   parts=shlexSplit(self.mailboxPath, self.separator)
   if len(parts) > 1:
     name=parts[-1]
   name=decodeUtf7(name)
   super(Mailbox, self).__init__(parentNode, name)
   if len(parts) == 2 and parts[0] == "user":
     self.GetServer().userList.append(name)
Example #7
0
 def __init__(self, parentNode, line):
     name, self.separator, self.flags = self.splitMbInfo(line)
     self.mailboxPath = name
     parts = shlexSplit(self.mailboxPath, self.separator)
     if len(parts) > 1:
         name = parts[-1]
     name = decodeUtf7(name)
     super(Mailbox, self).__init__(parentNode, name)
     if len(parts) == 2 and parts[0] == "user":
         self.GetServer().userList.append(name)
Example #8
0
 def GetAcl(self, mailbox):
   result=self.getresult(self.getacl(mailbox))
   if result:
     acls={}
     for line in result:
       parts=shlexSplit(line, ' ')     
       for i in range(1, len(parts), 2): 
         who=parts[i]
         acl=parts[i+1]
         acls[who] = acl
     return acls
   return None
Example #9
0
 def GetAcl(self, mailbox):
     result = self.getresult(self.getacl(mailbox))
     if result:
         acls = {}
         for line in result:
             parts = shlexSplit(line, ' ')
             for i in range(1, len(parts), 2):
                 who = parts[i]
                 acl = parts[i + 1]
                 acls[who] = acl
         return acls
     return None
Example #10
0
 def Go(self):
     pl = self['PrivList']
     pl.ClearAll()
     pl.AddColumnInfo(xlt("Usr/Group"), 20)
     pl.AddColumnInfo(xlt("Privilege"), -1)
     acls = self.dialog.colDef['attacl']
     if acls:
         for acl in shlexSplit(acls[1:-1], ','):
             up = shlexSplit(acl, '=')
             if len(up) == 1:
                 priv = up[0]
                 usr = "******"
             else:
                 usr = up[0]
                 priv = up[1]
             up = shlexSplit(priv, '/')
             priv = up[0]
             if len(up) > 1: grantor = up[1]
             else: grantor = None
             print usr, priv, grantor
     pl.Show()
Example #11
0
 def Go(self):
   pl=self['PrivList']
   pl.ClearAll()
   pl.AddColumnInfo(xlt("Usr/Group"), 20)
   pl.AddColumnInfo(xlt("Privilege"), -1)
   acls=self.dialog.colDef['attacl']
   if acls:
     for acl in shlexSplit(acls[1:-1], ','):
       up = shlexSplit(acl, '=')
       if len(up) == 1:
         priv=up[0]
         usr="******"
       else:
         usr=up[0]
         priv=up[1]
       up=shlexSplit(priv, '/')
       priv=up[0]
       if len(up) > 1: grantor=up[1]
       else:           grantor=None
       print usr, priv, grantor
   pl.Show()       
Example #12
0
    def Login(self, user, password):
        if 'AUTH=CRAM-MD5' in self.capabilities:
            res = self.login_cram_md5(user, password)
        else:
            res = self.login(user, password)
        if self.getresult(res):
            self.id = {}
            typ, dat = self.xatomResult('ID', 'NIL')
            if typ == "OK":
                parts = shlexSplit(dat[0][1:-1], " ")
                for i in range(0, len(parts), 2):
                    self.id[parts[i]] = parts[i + 1]

        return self.ok()
Example #13
0
 def GetAnnotations(self, mailbox):
   dat=self.getresult(self.getannotation(mailbox, '"*"', '"value.shared"'))
   if not dat:
     return None
   annotations=Annotations()
   
   for ann in dat:
     # this tries to deal with some imaplib weirdness if non-ascii is returned.
     # usually, ann should be a string, but if the value.shared contains non-ascii
     # a tuple is returned, with the next ann being ")"
     # This is so for imaplib.__version__ == 2.58
     if not ann or ann == ")":
       continue
     if isinstance(ann, str):
       parts=shlexSplit(ann.decode('utf-8'), " ")
       annotations[parts[1]] = parts[-1][:-1]
     elif isinstance(ann, tuple):
       parts=shlexSplit(ann[0].decode('utf-8'), " ")
       annotations[parts[1]] = ann[1].decode('utf-8')
     else:
       # whats that?
       pass
   return annotations
Example #14
0
 def Login(self, user, password):
   if 'AUTH=CRAM-MD5' in self.capabilities:
     res=self.login_cram_md5(user, password)
   else:
     res=self.login(user, password)
   if self.getresult(res):
     self.id={}
     typ,dat=self.xatomResult('ID', 'NIL')
     if typ == "OK":
       parts=shlexSplit(dat[0][1:-1], " ")
       for i in range(0, len(parts), 2):
         self.id[parts[i]]= parts[i+1]
       
   return self.ok()
Example #15
0
    def getAclDef(self, aclName, allRights='ZZ'):
        acls = []
        for acl in shlexSplit(self.info[aclName][1:-1], ','):
            if acl.startswith('='):
                user = '******'
                b = shlexSplit(acl[1:], '/')
            else:
                a = shlexSplit(acl, '=')
                user = quoteIdent(a[0])
                b = shlexSplit(a[1], '/')
            # grantor=b[1]

            privileges = ""
            grants = ""
            lastP = ""
            for p in b[0]:
                if p == '*':
                    grants += lastP
                else:
                    lastP = p
                    privileges += p

            def mkGrant(lst, withGrant=""):
                if lst == allRights:
                    pl = ['ALL']
                else:
                    pl = []
                    for p in b[0]:
                        pl.append(rightString[p])
                return "GRANT " + ",".join(pl) + " ON " + self.ObjectSql(
                ) + " TO " + user + withGrant + ";"

            if privileges:
                acls.append(mkGrant(privileges))
            if grants:
                acls.append(mkGrant(grants, " WITH GRANT OPTION"))
        return acls
Example #16
0
    def GetAnnotations(self, mailbox):
        dat = self.getresult(
            self.getannotation(mailbox, '"*"', '"value.shared"'))
        if not dat:
            return None
        annotations = Annotations()

        for ann in dat:
            # this tries to deal with some imaplib weirdness if non-ascii is returned.
            # usually, ann should be a string, but if the value.shared contains non-ascii
            # a tuple is returned, with the next ann being ")"
            # This is so for imaplib.__version__ == 2.58
            if not ann or ann == ")":
                continue
            if isinstance(ann, str):
                parts = shlexSplit(ann.decode('utf-8'), " ")
                annotations[parts[1]] = parts[-1][:-1]
            elif isinstance(ann, tuple):
                parts = shlexSplit(ann[0].decode('utf-8'), " ")
                annotations[parts[1]] = ann[1].decode('utf-8')
            else:
                # whats that?
                pass
        return annotations
Example #17
0
 def Save(self):
     ttl = int(timeToFloat(self.TTL))
     rds = None
     for value in self.Value.splitlines():
         value = value.strip()
         if not value:
             continue
         if self.dataclass == list:
             value = removeSmartQuote(value)
             data = shlexSplit(value, ' ')
         else:
             data = self.dataclass(value)
         if not rds:
             rds = Rdataset(ttl, rdataclass.IN, self.rdtype, data)
         else:
             rds.add(Rdata(rds, data), ttl)
     return self._save(rds)
Example #18
0
 def Save(self):
   ttl=int(timeToFloat(self.TTL))
   rds=None
   for value in self.Value.splitlines():
     value=value.strip()
     if not value:
       continue
     if self.dataclass == list:
       value=removeSmartQuote(value)
       data=shlexSplit(value, ' ')
     else:
       data=self.dataclass(value)
     if not rds:
       rds=Rdataset(ttl, rdataclass.IN, self.rdtype, data)
     else:
       rds.add(Rdata(rds, data), ttl)
   return self._save(rds)
Example #19
0
 def GetQuota(self, mailbox):
     quotas = {}
     res = self.getresult(self.getquotaroot(mailbox))
     if res and len(res) == 2:
         res = res[1]
     else:
         res = self.getresult(self.getquota(mailbox))
     if res:
         for quota in res:
             parts = shlexSplit(quota, ' ')
             if len(parts) > 3:
                 root = parts[0]
                 resource = parts[-3][1:]
                 filled = int(parts[-2])
                 total = int(parts[-1][:-1])
                 if resource == 'STORAGE':
                     filled *= 1024
                     total *= 1024
                 quotas[resource] = (root, filled, total)
             return quotas
     return None
Example #20
0
 def GetQuota(self, mailbox):
   quotas={}
   res=self.getresult(self.getquotaroot(mailbox))
   if res and len(res) == 2:
     res=res[1]
   else:
     res=self.getresult(self.getquota(mailbox))
   if res:
     for quota in res:
       parts=shlexSplit(quota, ' ')
       if len(parts) > 3:
         root=parts[0]
         resource=parts[-3][1:]
         filled=int(parts[-2])
         total=int(parts[-1][:-1])
         if resource == 'STORAGE':
           filled *= 1024
           total *= 1024
         quotas[resource] = (root, filled, total)
       return quotas
   return None