Beispiel #1
0
 def checkLoc(self):
     """ Check for new, uncached safes in the loc """
     log.debug("Going to check for new safes to cache in %r" % self.loc)
     assert os.access(self.loc, os.R_OK)
     
     for (dirpath, dirnames, filenames) in os.walk(self.loc):
         log.debug("Checking %r" % dirpath)
         for filename in filenames:
             fil = os.path.join(self.loc, dirpath, filename)
             log.debug("Check file %r" % fil)
             if self.safes.has_key(fil):
                 log.debug("Safe exists. Updating")
                 self.safes[fil].checkUpdate()
             else:
                 log.debug("Don't have in cache...adding")
                 if ispsafe3(fil):
                     if self.passwordLookup:
                         try:
                             pw = self.passwordLookup(fil)
                             if not pw in self.safePasswords:
                                 self.safePasswords.append(pw)
                                 log.debug("Added %r to safe pw list" % (pw))
                         except Exception, e:
                             log.warn("Tried doing a pw lookup for %r. Error: %r" % (fil, e))
                     for passwd in self.safePasswords:
                         log.debug("Trying to open safe %r with %r" % (fil, passwd))
                         try:
                             self.safes[fil] = CachedPWS(fil, passwd)
                             log.debug("Cached %r" % self.safes[fil])
                         except:
                             log.debug("Failed to open safe %r with %r" % (fil, passwd))
                 else:
                     log.debug("Not a psafe v3")
Beispiel #2
0
def findSafesInRepo(repoPK):
    """ Find all safes in the given repo and make sure there is a PasswordSafe object for it
    @param repoPK: The PK of the repo to check
    @type repoPK: int  
    @return: int, the number of safes located
    @note: Set to ignore result by default. Make sure to override this if you want a value or plan to .wait().
    """
    repo = PasswordSafeRepo.objects.get(pk=repoPK)
    cnt = 0
    for (dirpath, dirnames, filenames) in os.walk(repo.path):
        for filename in filenames:
            ext = filename.split('.')[-1].lower()
            if ext == "psafe3":
                # Dont' just assume - validate!
                if ispsafe3(os.path.join(repo.path, dirpath, filename)):
                    fullFilePath = os.path.join(dirpath, filename)
                    filePath = fullFilePath.lstrip(repo.path)
                    # Make sure it doesn't already exists in the DB
                    if PasswordSafe.objects.filter(
                                                   filename=filePath,
                                                   repo=repo,
                                                   ).count() == 0:
                        try:
                            pws = PasswordSafe(
                                             filename=filePath,
                                             repo=repo,
                                             )
                            pws.save()
                            cnt += 1
                        except:
                            pass

    return cnt