Exemplo n.º 1
0
def parse_one(grph, database_dicts, database):
    # Get the database name and a set of (name, value) pairs.
    try:
        name = re.match(r'(\w+)', database).group(1)
    except AttributeError:
        # AttributeError: 'NoneType' object has no attribute 'group'
        # print("Cannot parse:"+database)
        return

    names_and_values = re.findall(r'(?i)([a-z]+)\s*=\s*([a-z0-9-\.]+)',
                                  database)

    # Build a dictionary from them, and if it has a HOST, add the IP.
    #'veyx': {'HOST': 'nykcmss3059.us.net.intra',
    #         'NAME': 'U016US',
    #         'PORT': '1521',
    #         'PROTOCOL': 'TCP',
    #         'SID': 'abcd',
    #         'SERVER': 'DEDICATED'},
    # The same pair host+socket can host several databases.
    database_dict = dict(names_and_values)

    try:
        node_addr = lib_common.gUriGen.AddrUri(database_dict['HOST'],
                                               database_dict['PORT'])
    except KeyError:
        # pprint.pprint(database_dict)
        return

    # Here we should do something better, for example getting more information about this database.
    node_oradb = oracle_db.MakeUri(name)

    grph.add((node_addr, pc.property_oracle_db, node_oradb))
Exemplo n.º 2
0
def AddInfo(grph,node,entity_ids_arr):
	dsnNam = entity_ids_arr[0]

	ODBC_ConnectString = MakeOdbcConnectionString(dsnNam)

	try:
		cnxn = pyodbc.connect(ODBC_ConnectString)
	except:
		exc = sys.exc_info()[1]
		grph.add( ( node, pc.property_information, lib_common.NodeLiteral(str(exc)) ) )
		return

	dbEntityType = GetDatabaseEntityTypeFromConnection(cnxn)

	DEBUG("AddInfo dbEntityType=%s", dbEntityType )
	if dbEntityType == "oracle":
		# For example "XE".
		server_name = cnxn.getinfo(pyodbc.SQL_SERVER_NAME)
		node_oradb = oracle_db.MakeUri( server_name )

		grph.add( ( node, pc.property_oracle_db, node_oradb ) )

	elif dbEntityType == "sqlserver":
		# We stick to the DSN because it encloses all the needed information.
		node_sqlserverdb = survol_sqlserver_dsn.MakeUri( dsnNam )

		grph.add( ( node, pc.property_sqlserver_db, node_sqlserverdb ) )
		DEBUG("AddInfo dbEntityType=%s ADDING NODE", dbEntityType )
Exemplo n.º 3
0
def AddInfo(grph, node, entity_ids_arr):
    """"
    This displays links to the Oracle database, not seen from ODBC,
    so we can have more specific queries.
    """ ""
    dsn_nam = entity_ids_arr[0]

    odbc_connect_string = MakeOdbcConnectionString(dsn_nam)

    try:
        cnxn = pyodbc.connect(odbc_connect_string)
    except Exception as exc:
        grph.add(
            (node, pc.property_information, lib_util.NodeLiteral(str(exc))))
        return

    db_entity_type = GetDatabaseEntityTypeFromConnection(cnxn)

    logging.debug("AddInfo db_entity_type=%s", db_entity_type)
    if db_entity_type == "oracle":
        # For example "XE".
        server_name = cnxn.getinfo(pyodbc.SQL_SERVER_NAME)
        node_oradb = oracle_db.MakeUri(server_name)

        grph.add((node, pc.property_oracle_db, node_oradb))

    elif db_entity_type == "sqlserver":
        # We stick to the DSN because it encloses all the needed information.
        node_sqlserverdb = survol_sqlserver_dsn.MakeUri(dsn_nam)

        grph.add((node, pc.property_sqlserver_db, node_sqlserverdb))
        logging.debug("AddInfo db_entity_type=%s ADDING NODE", db_entity_type)
Exemplo n.º 4
0
def Main():
    cgiEnv = lib_oracle.OracleEnv()

    grph = cgiEnv.GetGraph()
    node_oradb = oracle_db.MakeUri(cgiEnv.m_oraDatabase)

    try:
        _list_dba_users(cgiEnv, node_oradb, grph)
    except:
        try:
            _list_all_users(cgiEnv, node_oradb, grph)
        except Exception as exc:
            lib_common.ErrorMessageHtml("ExecuteQuery exception:%s" %
                                        (str(exc)))

    cgiEnv.OutCgiRdf("LAYOUT_RECT")
Exemplo n.º 5
0
def Main():
    cgiEnv = lib_oracle.OracleEnv()

    grph = cgiEnv.GetGraph()
    node_oradb = oracle_db.MakeUri(cgiEnv.m_oraDatabase)

    try:
        ListDbaUsers(cgiEnv, node_oradb, grph)
    except:
        try:
            ListAllUsers(cgiEnv, node_oradb, grph)
        except:
            exc = sys.exc_info()[1]
            lib_common.ErrorMessageHtml("ExecuteQuery exception:%s" %
                                        (str(exc)))

    cgiEnv.OutCgiRdf("LAYOUT_RECT")
Exemplo n.º 6
0
def AddInfo(grph, node, entity_ids_arr):
    theDb = entity_ids_arr[1]
    nodeDb = oracle_db.MakeUri(theDb)
    grph.add((node, lib_common.MakeProp("Db"), nodeDb))
Exemplo n.º 7
0
def Main():
    cgiEnv = lib_oracle.OracleEnv()

    grph = cgiEnv.GetGraph()

    #v$process
    #PID	NUMBER	Oracle process identifier
    #SPID	VARCHAR2(12)	Operating system process identifier
    #USERNAME	VARCHAR2(15)	Operating system process username. Any two-task user coming across the network has "-T" appended to the username.
    #TERMINAL	VARCHAR2(30)	Operating system terminal identifier
    #PROGRAM	VARCHAR2(48)	Program in progress
    #
    #v$session
    #SID	NUMBER	Session identifier
    #USER#	NUMBER	Oracle user identifier
    #USERNAME	VARCHAR2(30)	Oracle username
    #COMMAND	NUMBER	Command in progress (last statement parsed); for a list of values, see Table 7-5. These values also appear in the AUDIT_ACTIONS table.
    #SCHEMA#	NUMBER	Schema user identifier
    #SCHEMANAME	VARCHAR2(30)	Schema user name
    #OSUSER	VARCHAR2(30)	Operating system client user name
    #PROCESS	VARCHAR2(12)	Operating system client process ID
    #MACHINE	VARCHAR2(64)	Operating system machine name
    #TERMINAL	VARCHAR2(30)	Operating system terminal name
    #PROGRAM	VARCHAR2(48)	Operating system program name

    sql_query = """
	SELECT distinct sess.sid, sess.username, sess.schemaname, proc.spid,pid,sess.osuser,sess.machine,sess.process,
	sess.port,proc.terminal,sess.program,proc.tracefile
	  FROM v$session sess,
		   v$process proc
	 WHERE sess.type     = 'USER'
	   and sess.paddr = proc.addr
	"""

    node_oradb = oracle_db.MakeUri(cgiEnv.m_oraDatabase)

    try:
        result = lib_oracle.ExecuteQueryThrow(cgiEnv.ConnectStr(), sql_query)
    except:
        exc = sys.exc_info()[1]
        lib_common.ErrorMessageHtml("ExecuteQuery exception:%s in %s" %
                                    (str(exc), sql_query))

    for row in result:
        if row[0] == None:
            continue
        # print("\nUser="******"WORKGROUP\RCHATEAU-HP"
        user_machine = lib_oracle.OraMachineToIp(row[6])
        theMachineBox = lib_common.MachineBox(user_machine)

        # Process and Thread id of the CLIENT program, executing sqlplus.exe for example.
        sessPidTid = row[7]  # 7120:4784
        sessPid = sessPidTid.split(":")[0]
        procTerminal = row[9]
        sessProgram = row[10]

        nodeSession = oracle_session.MakeUri(cgiEnv.m_oraDatabase, str(row[0]))
        grph.add((nodeSession, lib_common.MakeProp("Oracle user"),
                  lib_common.NodeLiteral(oraUsername)))
        grph.add((nodeSession, lib_common.MakeProp("Schema"),
                  lib_common.NodeLiteral(schemaName)))
        grph.add((nodeSession, lib_common.MakeProp("Program"),
                  lib_common.NodeLiteral(sessProgram)))

        if schemaName != None:
            nodeSchema = oracle_schema.MakeUri(cgiEnv.m_oraDatabase,
                                               str(schemaName))
            grph.add((nodeSession, pc.property_oracle_schema, nodeSchema))
            grph.add((node_oradb, pc.property_oracle_db, nodeSchema))

        sys.stderr.write("user_proc_id=%s user_machine=%s\n" %
                         (user_proc_id, user_machine))
        # node_process = lib_common.RemoteBox(user_machine).PidUri( sessPid )
        node_process = theMachineBox.PidUri(sessPid)
        grph.add((node_process, lib_common.MakeProp("SystemPid"),
                  lib_common.NodeLiteral(user_proc_id)))
        grph.add((node_process, lib_common.MakeProp("OraclePid"),
                  lib_common.NodeLiteral(process_pid)))
        grph.add((node_process, lib_common.MakeProp("Terminal"),
                  lib_common.NodeLiteral(procTerminal)))
        grph.add((nodeSession, pc.property_oracle_session, node_process))

        if sessOsuser != None:
            sys.stderr.write("user_machine=%s sessOsuser=%s\n" %
                             (user_machine, sessOsuser))
            nodeOsUser = theMachineBox.UserUri(sessOsuser)
            grph.add((nodeOsUser, lib_common.MakeProp("OsUser"),
                      lib_common.NodeLiteral(sessOsuser)))
            grph.add((node_process, pc.property_user, nodeOsUser))

    cgiEnv.OutCgiRdf()
Exemplo n.º 8
0
def AddInfo(grph, node, entity_ids_arr):
    # TODO: Ca serait quand meme mieux de passer au AddInfo un dict plutot qu un tableau.
    dbNam = entity_ids_arr[0]
    nodeDb = oracle_db.MakeUri(dbNam)

    grph.add((nodeDb, pc.property_oracle_schema, node))
Exemplo n.º 9
0
 def __init__(self, grph, database_name, propSqlQuery):
     self.m_grph = grph
     self.m_database_name = database_name
     self.m_node_oradb = oracle_db.MakeUri(database_name)
     self.m_propSqlQuery = propSqlQuery
Exemplo n.º 10
0
def AddInfo(grph, node, entity_ids_arr):
    db_nam = entity_ids_arr[0]
    node_db = oracle_db.MakeUri(db_nam)

    grph.add((node_db, pc.property_oracle_schema, node))
Exemplo n.º 11
0
 def CredUrlOracle(dbName):
     # Example: dbName = "XE", which must be defined in tnsnames-ora
     from sources_types.oracle import db as oracle_db
     node_oradb = oracle_db.MakeUri( dbName )
     return node_oradb