db-sql.c revision 3c9783956dea385b322cd7fa6bf8c98c17a907a0
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen/* Copyright (C) 2003-2004 Timo Sirainen */
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen#define DEF(type, name) { type, #name, offsetof(struct sql_settings, name) }
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen MEMBER(password_query) "SELECT password FROM users WHERE userid = '%u'",
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen MEMBER(user_query) "SELECT home, uid, gid FROM users WHERE userid = '%u'",
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenstatic struct sql_connection *connections = NULL;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenstatic struct sql_connection *sql_conn_find(const char *config_path)
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen for (conn = connections; conn != NULL; conn = conn->next) {
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen if (strcmp(conn->config_path, config_path) == 0)
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenstatic const char *parse_setting(const char *key, const char *value,
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen return parse_setting_from_defs(conn->pool, setting_defs,
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenstruct sql_connection *db_sql_init(const char *config_path)
2e1e493b248dec0127b1eabeea5a8bc330378fcdTimo Sirainen i_fatal("LDAP: Configuration file path not given");
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen pool = pool_alloconly_create("sql_connection", 1024);
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen conn->config_path = p_strdup(pool, config_path);
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen if (!settings_read(config_path, NULL, parse_setting, NULL, conn))
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen i_fatal("sql: driver not set in configuration file %s",
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen i_fatal("sql: connect string not set in configuration file %s",
f8a86fdfb0048f9c87bf223373b35416ceb5856bTimo Sirainen conn->db = sql_init(conn->set.driver, conn->set.connect);