saving uncommitted changes in /etc prior to emerge run
This commit is contained in:
@@ -12,12 +12,48 @@
|
||||
-- This file is the Freeciv server`s interface to the database backend
|
||||
-- when authentication is enabled. See doc/README.fcdb.
|
||||
|
||||
-- **************************************************************************
|
||||
-- basic mysql functions
|
||||
-- **************************************************************************
|
||||
|
||||
local dbh = nil
|
||||
|
||||
-- Machinery for debug logging of options
|
||||
local seen_options
|
||||
local function options_init()
|
||||
seen_options = {}
|
||||
end
|
||||
local function option_log(name, val, is_sensitive, source)
|
||||
if not seen_options[name] then
|
||||
seen_options[name] = true
|
||||
if is_sensitive then
|
||||
log.debug('Database option \'%s\': %s', name, source)
|
||||
else
|
||||
log.debug('Database option \'%s\': %s: value \'%s\'', name, source, val)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Get an option from configuration file, falling back to sensible
|
||||
-- defaults where they exist
|
||||
local function get_option(name, is_sensitive)
|
||||
local defaults = {
|
||||
backend = "sqlite",
|
||||
table_user = "fcdb_auth",
|
||||
table_log = "fcdb_log"
|
||||
}
|
||||
local val = fcdb.option(name)
|
||||
if val then
|
||||
option_log(name, val, is_sensitive, 'read from file')
|
||||
else
|
||||
val = defaults[name]
|
||||
if val then
|
||||
option_log(name, val, is_sensitive, 'using default')
|
||||
end
|
||||
end
|
||||
if not val then
|
||||
log.error('Database option \'%s\' not specified in configuration file',
|
||||
name)
|
||||
end
|
||||
return val
|
||||
end
|
||||
|
||||
-- connect to a MySQL database (or stop with an error)
|
||||
local function mysql_connect()
|
||||
local err -- error message
|
||||
@@ -26,16 +62,16 @@ local function mysql_connect()
|
||||
dbh:close()
|
||||
end
|
||||
|
||||
local sql = luasql.mysql()
|
||||
local sql = ls_mysql.mysql()
|
||||
|
||||
log.verbose('MySQL database version is %s.', luasql._MYSQLVERSION)
|
||||
log.verbose('MySQL database version is %s.', ls_mysql._MYSQLVERSION)
|
||||
|
||||
-- Load the database parameters.
|
||||
local database = fcdb.option(fcdb.param.DATABASE)
|
||||
local user = fcdb.option(fcdb.param.USER)
|
||||
local password = fcdb.option(fcdb.param.PASSWORD)
|
||||
local host = fcdb.option(fcdb.param.HOST)
|
||||
local port = fcdb.option(fcdb.param.PORT)
|
||||
local database = get_option("database")
|
||||
local user = get_option("user")
|
||||
local password = get_option("password", true)
|
||||
local host = get_option("host")
|
||||
local port = get_option("port")
|
||||
|
||||
dbh, err = sql:connect(database, user, password, host, port)
|
||||
if not dbh then
|
||||
@@ -54,11 +90,10 @@ local function sqlite_connect()
|
||||
dbh:close()
|
||||
end
|
||||
|
||||
local sql = luasql.sqlite3()
|
||||
local sql = ls_sqlite3.sqlite3()
|
||||
|
||||
-- Load the database parameters.
|
||||
local database = fcdb.option(fcdb.param.DATABASE)
|
||||
-- USER/PASSWORD/HOST/PORT ignored for SQLite
|
||||
local database = get_option("database")
|
||||
|
||||
dbh, err = sql:connect(database)
|
||||
if not dbh then
|
||||
@@ -94,7 +129,7 @@ end
|
||||
-- (This should be replaced with Lua os.time() once the script has access
|
||||
-- to this, see <http://gna.org/bugs/?19729>.)
|
||||
function sql_time()
|
||||
local backend = fcdb.option(fcdb.param.BACKEND)
|
||||
local backend = get_option("backend")
|
||||
if backend == 'mysql' then
|
||||
return 'UNIX_TIMESTAMP()'
|
||||
elseif backend == 'sqlite' then
|
||||
@@ -113,13 +148,13 @@ function sqlite_createdb()
|
||||
local query
|
||||
local res
|
||||
|
||||
if fcdb.option(fcdb.param.BACKEND) ~= 'sqlite' then
|
||||
if get_option("backend") ~= 'sqlite' then
|
||||
log.error("'backend' in configuration file must be 'sqlite'")
|
||||
return fcdb.status.ERROR
|
||||
end
|
||||
|
||||
local table_user = fcdb.option(fcdb.param.TABLE_USER)
|
||||
local table_log = fcdb.option(fcdb.param.TABLE_LOG)
|
||||
local table_user = get_option("table_user")
|
||||
local table_log = get_option("table_log")
|
||||
|
||||
if not dbh then
|
||||
log.error("Missing database connection...")
|
||||
@@ -183,7 +218,7 @@ end
|
||||
-- logincount int(11) default '0',
|
||||
-- PRIMARY KEY (id),
|
||||
-- UNIQUE KEY name (name)
|
||||
-- ) TYPE=MyISAM;
|
||||
-- );
|
||||
--
|
||||
-- CREATE TABLE fcdb_log (
|
||||
-- id int(11) NOT NULL auto_increment,
|
||||
@@ -192,7 +227,7 @@ end
|
||||
-- address varchar(255) default NULL,
|
||||
-- succeed enum('S','F') default 'S',
|
||||
-- PRIMARY KEY (id)
|
||||
-- ) TYPE=MyISAM;
|
||||
-- );
|
||||
--
|
||||
-- N.B. if the tables are not of this format, then the select, insert,
|
||||
-- and update syntax in the following functions must be changed.
|
||||
@@ -211,8 +246,8 @@ function user_load(conn)
|
||||
|
||||
local fields = 'password'
|
||||
|
||||
local table_user = fcdb.option(fcdb.param.TABLE_USER)
|
||||
local table_log = fcdb.option(fcdb.param.TABLE_LOG)
|
||||
local table_user = get_option("table_user")
|
||||
local table_log = get_option("table_log")
|
||||
|
||||
if not dbh then
|
||||
log.error("Missing database connection...")
|
||||
@@ -258,7 +293,7 @@ function user_save(conn)
|
||||
local res -- result handle
|
||||
local query -- sql query
|
||||
|
||||
local table_user = fcdb.option(fcdb.param.TABLE_USER)
|
||||
local table_user = get_option("table_user")
|
||||
|
||||
if not dbh then
|
||||
log.error("Missing database connection...")
|
||||
@@ -296,8 +331,8 @@ function user_log(conn, success)
|
||||
return fcdb.status.ERROR
|
||||
end
|
||||
|
||||
local table_user = fcdb.option(fcdb.param.TABLE_USER)
|
||||
local table_log = fcdb.option(fcdb.param.TABLE_LOG)
|
||||
local table_user = get_option("table_user")
|
||||
local table_log = get_option("table_log")
|
||||
|
||||
local username = dbh:escape(auth.get_username(conn))
|
||||
local ipaddr = auth.get_ipaddr(conn)
|
||||
@@ -334,7 +369,9 @@ end
|
||||
function database_init()
|
||||
local status -- return value (status of the request)
|
||||
|
||||
local backend = fcdb.option(fcdb.param.BACKEND)
|
||||
options_init()
|
||||
|
||||
local backend = get_option("backend")
|
||||
if backend == 'mysql' then
|
||||
log.verbose('Opening MySQL database connection...')
|
||||
status = mysql_connect()
|
||||
|
||||
Reference in New Issue
Block a user