From a19cb2c13a8dc1a7326884912bde02f64cf36dc2 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Fri, 17 Dec 2010 21:29:09 +0000 Subject: [PATCH] code refactoring (added UNKNOWN_DBMS_VERSION instead of "Unknown") --- lib/core/common.py | 5 +++-- lib/core/option.py | 3 ++- lib/core/session.py | 3 ++- lib/core/settings.py | 2 ++ plugins/dbms/mssqlserver/fingerprint.py | 3 ++- plugins/dbms/mysql/fingerprint.py | 3 ++- 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 20958e540..dc59a642c 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -60,6 +60,7 @@ from lib.core.settings import PLATFORM from lib.core.settings import SITE from lib.core.settings import SQL_STATEMENTS from lib.core.settings import SUPPORTED_DBMS +from lib.core.settings import UNKNOWN_DBMS_VERSION from lib.core.settings import VERSION_STRING from lib.core.settings import DUMP_NEWLINE_MARKER from lib.core.settings import DUMP_CR_MARKER @@ -203,7 +204,7 @@ def formatDBMSfp(versions=None): while versions and None in versions: versions.remove(None) - if not versions and kb.dbmsVersion and kb.dbmsVersion[0] != "Unknown" and kb.dbmsVersion[0] != None: + if not versions and kb.dbmsVersion and kb.dbmsVersion[0] != UNKNOWN_DBMS_VERSION and kb.dbmsVersion[0] != None: versions = kb.dbmsVersion if isinstance(versions, basestring): @@ -1719,7 +1720,7 @@ def removeDynamicContent(page): def isDBMSVersionAtLeast(version): retVal = None - if kb.dbmsVersion and kb.dbmsVersion[0] != "Unknown" and kb.dbmsVersion[0] != None: + if kb.dbmsVersion and kb.dbmsVersion[0] != UNKNOWN_DBMS_VERSION and kb.dbmsVersion[0] != None: value = kb.dbmsVersion[0].replace(" ", "") if isinstance(value, basestring): diff --git a/lib/core/option.py b/lib/core/option.py index abd799ab2..81f2340f5 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -73,6 +73,7 @@ from lib.core.settings import ACCESS_ALIASES from lib.core.settings import FIREBIRD_ALIASES from lib.core.settings import MAXDB_ALIASES from lib.core.settings import SYBASE_ALIASES +from lib.core.settings import UNKNOWN_DBMS_VERSION from lib.core.update import update from lib.parse.configfile import configFileParser from lib.parse.payloads import loadPayloads @@ -1144,7 +1145,7 @@ def __setKnowledgeBaseAttributes(): kb.dbmsDetected = False # Active (extensive) back-end DBMS fingerprint - kb.dbmsVersion = [ "Unknown" ] + kb.dbmsVersion = [ UNKNOWN_DBMS_VERSION ] kb.dep = None kb.docRoot = None diff --git a/lib/core/session.py b/lib/core/session.py index 1feaadc97..5f0136333 100644 --- a/lib/core/session.py +++ b/lib/core/session.py @@ -25,6 +25,7 @@ from lib.core.settings import MSSQL_ALIASES from lib.core.settings import MYSQL_ALIASES from lib.core.settings import PGSQL_ALIASES from lib.core.settings import ORACLE_ALIASES +from lib.core.settings import UNKNOWN_DBMS_VERSION def safeFormatString(value): retVal = value @@ -361,7 +362,7 @@ def resumeConfKb(expression, url, value): elif expression == "DBMS" and url == conf.url: dbms = unSafeFormatString(value[:-1]) dbms = dbms.lower() - dbmsVersion = ["Unknown"] + dbmsVersion = [UNKNOWN_DBMS_VERSION] logMsg = "resuming back-end DBMS '%s' " % dbms logMsg += "from session file" diff --git a/lib/core/settings.py b/lib/core/settings.py index 8515baa7a..52354d941 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -49,6 +49,8 @@ DUMP_STOP_MARKER = "__STOP__" PAYLOAD_DELIMITER = "\x00" CHAR_INFERENCE_MARK = "%c" +UNKNOWN_DBMS_VERSION = "Unknown" + # suffix used for naming meta databases in DBMS(es) without explicit database name METADB_SUFFIX = "_masterdb" diff --git a/plugins/dbms/mssqlserver/fingerprint.py b/plugins/dbms/mssqlserver/fingerprint.py index 19635a3e4..0eb7b98c1 100644 --- a/plugins/dbms/mssqlserver/fingerprint.py +++ b/plugins/dbms/mssqlserver/fingerprint.py @@ -19,6 +19,7 @@ from lib.core.data import logger from lib.core.enums import DBMS from lib.core.session import setDbms from lib.core.settings import MSSQL_ALIASES +from lib.core.settings import UNKNOWN_DBMS_VERSION from lib.request import inject from lib.request.connect import Connect as Request @@ -132,7 +133,7 @@ class Fingerprint(GenericFingerprint): break - if not kb.dbmsVersion or kb.dbmsVersion == ["Unknown"]: + if not kb.dbmsVersion or kb.dbmsVersion == [UNKNOWN_DBMS_VERSION]: for version, check in [\ ("2000", "HOST_NAME()=HOST_NAME()"),\ ("2005", "XACT_STATE()=XACT_STATE()"),\ diff --git a/plugins/dbms/mysql/fingerprint.py b/plugins/dbms/mysql/fingerprint.py index 092efd4c7..fbd1d789b 100644 --- a/plugins/dbms/mysql/fingerprint.py +++ b/plugins/dbms/mysql/fingerprint.py @@ -22,6 +22,7 @@ from lib.core.enums import DBMS from lib.core.enums import PLACE from lib.core.session import setDbms from lib.core.settings import MYSQL_ALIASES +from lib.core.settings import UNKNOWN_DBMS_VERSION from lib.request import inject from lib.request.connect import Connect as Request @@ -144,7 +145,7 @@ class Fingerprint(GenericFingerprint): if ((kb.dbms is not None and kb.dbms.lower() in MYSQL_ALIASES) \ or conf.dbms in MYSQL_ALIASES) and kb.dbmsVersion and \ - kb.dbmsVersion[0] != "Unknown": + kb.dbmsVersion[0] != UNKNOWN_DBMS_VERSION: kb.dbmsVersion[0] = kb.dbmsVersion[0].replace(">", "") kb.dbmsVersion[0] = kb.dbmsVersion[0].replace("=", "") kb.dbmsVersion[0] = kb.dbmsVersion[0].replace(" ", "")