From 3df1e64b3959f4ae9759f27a9e9f1fd0dd6d3ed5 Mon Sep 17 00:00:00 2001 From: HD Moore Date: Mon, 31 Dec 2007 09:18:41 +0000 Subject: [PATCH] connect to an existing database with db_create git-svn-id: file:///home/svn/framework3/trunk@5253 4d416f70-5f16-0410-b530-b9f4589650da --- plugins/db_sqlite2.rb | 28 ++++++++++++++-------------- plugins/db_sqlite3.rb | 24 ++++++++++++------------ 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/plugins/db_sqlite2.rb b/plugins/db_sqlite2.rb index c1f4abb856..d7176c4f6e 100644 --- a/plugins/db_sqlite2.rb +++ b/plugins/db_sqlite2.rb @@ -83,31 +83,31 @@ class Plugin::DBSQLite2 < Msf::Plugin opts['dbfile'] = info[:path] sql = File.join(Msf::Config.install_root, "data", "sql", "sqlite.sql") - if (File.exists?(opts['dbfile'])) - print_status("The specified database already exists, use db_connect or delete this file") - print_status("File: #{opts['dbfile']}") - return - end + print_status("The specified database already exists, connecting") + else - print_status("Creating a new database instance...") + print_status("Creating a new database instance...") - db = SQLite::Database.new(opts['dbfile']) - File.read(sql).split(";").each do |line| - begin - db.execute(line.strip) - rescue ::SQLite::Exceptions::SQLException, ::NoMethodError + db = SQLite::Database.new(opts['dbfile']) + File.read(sql).split(";").each do |line| + begin + db.execute(line.strip) + rescue ::SQLite::Exceptions::SQLException, ::NoMethodError + end end + db.close end - db.close - if (not framework.db.connect(opts)) raise PluginLoadError.new("Failed to connect to the database") end + driver.append_dispatcher(DatabaseCommandDispatcher) - + + print_status("Successfully connected to the database") + print_status("File: #{opts['dbfile']}") end # diff --git a/plugins/db_sqlite3.rb b/plugins/db_sqlite3.rb index 70e4a9683b..a227f1c8b4 100644 --- a/plugins/db_sqlite3.rb +++ b/plugins/db_sqlite3.rb @@ -90,29 +90,29 @@ class Plugin::DBSQLite3 < Msf::Plugin sql = File.join(Msf::Config.install_root, "data", "sql", "sqlite.sql") if (File.exists?(opts['dbfile'])) - print_status("The specified database already exists, use db_connect or delete this file") - print_status("File: #{opts['dbfile']}") - return - end + print_status("The specified database already exists, connecting") + else - print_status("Creating a new database instance...") + print_status("Creating a new database instance...") - db = SQLite3::Database.new(opts['dbfile']) - File.read(sql).split(";").each do |line| - begin - db.execute(line.strip) - rescue ::SQLite3::SQLException, ::SQLite3::MisuseException + db = SQLite3::Database.new(opts['dbfile']) + File.read(sql).split(";").each do |line| + begin + db.execute(line.strip) + rescue ::SQLite3::SQLException, ::SQLite3::MisuseException + end end + db.close end - db.close if (not framework.db.connect(opts)) raise PluginLoadError.new("Failed to connect to the database") end + driver.append_dispatcher(DatabaseCommandDispatcher) - print_status("Successfully created the database") + print_status("Successfully connected to the database") print_status("File: #{opts['dbfile']}") end