Example #1
0
 def DeleteSignedBinaryReferences(
     self,
     binary_id: rdf_objects.SignedBinaryID,
     cursor: MySQLdb.cursors.Cursor,
 ) -> None:
     """Deletes blob references for the given signed binary from the DB."""
     cursor.execute(
         """
   DELETE FROM signed_binary_references
   WHERE binary_type = %s AND binary_path_hash = %s
 """, [
             binary_id.binary_type.SerializeToWireFormat(),
             mysql_utils.Hash(binary_id.path)
         ])
Example #2
0
    def VerifyYaraSignatureReference(
        self,
        blob_id: rdf_objects.BlobID,
        cursor: MySQLdb.cursors.Cursor,
    ) -> bool:
        """Verifies whether specified blob is a YARA signature."""
        query = """
    SELECT 1
      FROM yara_signature_references
     WHERE blob_id = %(blob_id)s
    """
        cursor.execute(query, {"blob_id": blob_id.AsBytes()})

        return len(cursor.fetchall()) == 1
def update_diseases(all_diseases: Dict[StateYearPair, StrItemSet],
                    cursor: MySQLdb.cursors.Cursor):
    """
    Fetches rows from cursor and updates all_diseases with the rows
    Doesn't return anything, but updates all_diseases directly
    :param all_diseases: dict from place and time to set of diseases at that time and place
    :param cursor: a database cursor with rows containing Admin1Name, Year, and ConditionName
    """
    current_row = cursor.fetchone()
    while current_row is not None:
        place_time = tuple(current_row[:2])
        disease = current_row[2]
        all_diseases[place_time] = all_diseases[place_time].union({disease})
        current_row = cursor.fetchone()
Example #4
0
    def WriteYaraSignatureReference(
        self,
        blob_id: rdf_objects.BlobID,
        username: Text,
        cursor: MySQLdb.cursors.Cursor,
    ) -> None:
        """Marks specified blob id as a YARA signature."""
        query = """
    INSERT IGNORE INTO yara_signature_references
    VALUES (%(blob_id)s, %(username_hash)s, NOW(6))
    """
        args = {
            "blob_id": blob_id.AsBytes(),
            "username_hash": mysql_utils.Hash(username),
        }

        try:
            cursor.execute(query, args)
        except MySQLdb.IntegrityError:
            raise db.UnknownGRRUserError(username=username)
Example #5
0
  def Now(self, cursor: MySQLdb.cursors.Cursor) -> rdfvalue.RDFDatetime:
    cursor.execute("SELECT UNIX_TIMESTAMP(NOW(6))")
    [(timestamp,)] = cursor.fetchall()

    return mysql_utils.TimestampToRDFDatetime(timestamp)