2017-05-24 11:57:15 +00:00
|
|
|
|
|
|
|
/*
|
2017-07-05 12:42:49 +00:00
|
|
|
* Odissey.
|
2017-05-24 11:57:15 +00:00
|
|
|
*
|
2017-07-05 12:42:49 +00:00
|
|
|
* Advanced PostgreSQL connection pooler.
|
2017-05-24 11:57:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2017-05-31 15:47:15 +00:00
|
|
|
#include <inttypes.h>
|
2017-05-24 11:57:15 +00:00
|
|
|
|
|
|
|
#include <machinarium.h>
|
|
|
|
|
2017-07-05 12:15:17 +00:00
|
|
|
#include "sources/macro.h"
|
|
|
|
#include "sources/list.h"
|
|
|
|
#include "sources/pid.h"
|
|
|
|
#include "sources/id.h"
|
|
|
|
#include "sources/syslog.h"
|
|
|
|
#include "sources/log.h"
|
|
|
|
#include "sources/scheme.h"
|
2017-07-14 13:40:31 +00:00
|
|
|
#include "sources/scheme_mgr.h"
|
2017-05-24 11:57:15 +00:00
|
|
|
|
2017-05-24 12:13:44 +00:00
|
|
|
void od_scheme_init(od_scheme_t *scheme)
|
2017-05-24 11:57:15 +00:00
|
|
|
{
|
|
|
|
scheme->daemonize = 0;
|
2017-06-01 09:38:46 +00:00
|
|
|
scheme->log_debug = 0;
|
2017-06-01 09:45:49 +00:00
|
|
|
scheme->log_config = 0;
|
2017-06-28 10:50:29 +00:00
|
|
|
scheme->log_session = 1;
|
2017-05-24 11:57:15 +00:00
|
|
|
scheme->log_file = NULL;
|
2017-06-23 10:34:51 +00:00
|
|
|
scheme->log_statistics = 0;
|
2017-05-24 11:57:15 +00:00
|
|
|
scheme->pid_file = NULL;
|
|
|
|
scheme->syslog = 0;
|
|
|
|
scheme->syslog_ident = NULL;
|
|
|
|
scheme->syslog_facility = NULL;
|
|
|
|
scheme->host = NULL;
|
|
|
|
scheme->port = 6432;
|
|
|
|
scheme->backlog = 128;
|
|
|
|
scheme->nodelay = 1;
|
|
|
|
scheme->keepalive = 7200;
|
2017-05-31 11:38:06 +00:00
|
|
|
scheme->readahead = 8192;
|
2017-06-07 12:40:08 +00:00
|
|
|
scheme->server_pipelining = 32768;
|
2017-05-24 11:57:15 +00:00
|
|
|
scheme->workers = 1;
|
2017-06-19 10:55:49 +00:00
|
|
|
scheme->client_max_set = 0;
|
|
|
|
scheme->client_max = 0;
|
2017-05-24 11:57:15 +00:00
|
|
|
scheme->tls_verify = OD_TDISABLE;
|
2017-06-24 13:04:20 +00:00
|
|
|
scheme->tls = NULL;
|
2017-05-24 11:57:15 +00:00
|
|
|
scheme->tls_ca_file = NULL;
|
|
|
|
scheme->tls_key_file = NULL;
|
|
|
|
scheme->tls_cert_file = NULL;
|
|
|
|
scheme->tls_protocols = NULL;
|
2017-07-03 14:32:48 +00:00
|
|
|
scheme->db_default = NULL;
|
|
|
|
od_list_init(&scheme->dbs);
|
2017-06-21 12:18:48 +00:00
|
|
|
od_list_init(&scheme->storages);
|
2017-05-24 11:57:15 +00:00
|
|
|
}
|
|
|
|
|
2017-05-24 12:13:44 +00:00
|
|
|
void od_scheme_free(od_scheme_t *scheme)
|
2017-05-24 11:57:15 +00:00
|
|
|
{
|
|
|
|
od_list_t *i, *n;
|
2017-07-03 14:32:48 +00:00
|
|
|
od_list_foreach_safe(&scheme->dbs, i, n) {
|
|
|
|
od_schemedb_t *db;
|
|
|
|
db = od_container_of(i, od_schemedb_t, link);
|
2017-07-13 12:58:32 +00:00
|
|
|
od_schemedb_unref(db);
|
2017-05-24 11:57:15 +00:00
|
|
|
}
|
2017-07-13 12:13:55 +00:00
|
|
|
od_list_foreach_safe(&scheme->storages, i, n) {
|
|
|
|
od_schemestorage_t *storage;
|
|
|
|
storage = od_container_of(i, od_schemestorage_t, link);
|
|
|
|
od_schemestorage_unref(storage);
|
|
|
|
}
|
2017-07-13 12:58:32 +00:00
|
|
|
if (scheme->log_file)
|
|
|
|
free(scheme->log_file);
|
|
|
|
if (scheme->pid_file)
|
|
|
|
free(scheme->pid_file);
|
|
|
|
if (scheme->syslog_ident)
|
|
|
|
free(scheme->syslog_ident);
|
|
|
|
if (scheme->syslog_facility)
|
|
|
|
free(scheme->syslog_facility);
|
|
|
|
if (scheme->host)
|
|
|
|
free(scheme->host);
|
|
|
|
if (scheme->tls)
|
|
|
|
free(scheme->tls);
|
|
|
|
if (scheme->tls_ca_file)
|
|
|
|
free(scheme->tls_ca_file);
|
|
|
|
if (scheme->tls_key_file)
|
|
|
|
free(scheme->tls_key_file);
|
|
|
|
if (scheme->tls_cert_file)
|
|
|
|
free(scheme->tls_cert_file);
|
|
|
|
if (scheme->tls_protocols)
|
|
|
|
free(scheme->tls_protocols);
|
2017-05-24 11:57:15 +00:00
|
|
|
}
|
|
|
|
|
2017-06-21 12:18:48 +00:00
|
|
|
od_schemestorage_t*
|
2017-07-14 13:40:31 +00:00
|
|
|
od_schemestorage_add(od_scheme_t *scheme, int version)
|
2017-05-24 11:57:15 +00:00
|
|
|
{
|
2017-06-21 12:18:48 +00:00
|
|
|
od_schemestorage_t *storage;
|
|
|
|
storage = (od_schemestorage_t*)malloc(sizeof(*storage));
|
|
|
|
if (storage == NULL)
|
2017-05-24 11:57:15 +00:00
|
|
|
return NULL;
|
2017-06-21 12:18:48 +00:00
|
|
|
memset(storage, 0, sizeof(*storage));
|
|
|
|
od_list_init(&storage->link);
|
|
|
|
od_list_append(&scheme->storages, &storage->link);
|
2017-07-14 13:40:31 +00:00
|
|
|
storage->version = version;
|
2017-06-21 12:18:48 +00:00
|
|
|
return storage;
|
2017-05-24 11:57:15 +00:00
|
|
|
}
|
|
|
|
|
2017-06-21 12:18:48 +00:00
|
|
|
od_schemestorage_t*
|
2017-07-14 13:55:01 +00:00
|
|
|
od_schemestorage_match(od_scheme_t *scheme, char *name, int version)
|
2017-05-24 11:57:15 +00:00
|
|
|
{
|
2017-07-14 13:55:01 +00:00
|
|
|
/* match maximum storage scheme version which is
|
|
|
|
* lower then 'version' */
|
|
|
|
od_schemestorage_t *match = NULL;
|
2017-05-24 11:57:15 +00:00
|
|
|
od_list_t *i;
|
2017-06-21 12:18:48 +00:00
|
|
|
od_list_foreach(&scheme->storages, i) {
|
|
|
|
od_schemestorage_t *storage;
|
|
|
|
storage = od_container_of(i, od_schemestorage_t, link);
|
2017-07-14 13:55:01 +00:00
|
|
|
if (strcmp(storage->name, name) != 0)
|
|
|
|
continue;
|
|
|
|
if (storage->version > version)
|
|
|
|
continue;
|
|
|
|
if (match) {
|
|
|
|
if (match->version < storage->version)
|
|
|
|
match = storage;
|
|
|
|
} else {
|
|
|
|
match = storage;
|
|
|
|
}
|
2017-05-24 11:57:15 +00:00
|
|
|
}
|
2017-07-14 13:55:01 +00:00
|
|
|
return match;
|
2017-05-24 11:57:15 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 12:13:55 +00:00
|
|
|
void od_schemestorage_ref(od_schemestorage_t *storage)
|
|
|
|
{
|
|
|
|
storage->refs++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void od_schemestorage_unref(od_schemestorage_t *storage)
|
|
|
|
{
|
2017-07-13 12:32:05 +00:00
|
|
|
if (storage->refs > 0)
|
|
|
|
--storage->refs;
|
|
|
|
if (storage->refs > 0)
|
2017-07-13 12:13:55 +00:00
|
|
|
return;
|
2017-07-13 12:32:05 +00:00
|
|
|
if (storage->name)
|
|
|
|
free(storage->name);
|
|
|
|
if (storage->type)
|
|
|
|
free(storage->type);
|
|
|
|
if (storage->host)
|
|
|
|
free(storage->host);
|
|
|
|
if (storage->tls)
|
|
|
|
free(storage->tls);
|
|
|
|
if (storage->tls_ca_file)
|
|
|
|
free(storage->tls_ca_file);
|
|
|
|
if (storage->tls_key_file)
|
|
|
|
free(storage->tls_key_file);
|
|
|
|
if (storage->tls_cert_file)
|
|
|
|
free(storage->tls_cert_file);
|
|
|
|
if (storage->tls_protocols)
|
|
|
|
free(storage->tls_protocols);
|
|
|
|
od_list_unlink(&storage->link);
|
|
|
|
free(storage);
|
2017-07-13 12:13:55 +00:00
|
|
|
}
|
|
|
|
|
2017-07-03 14:32:48 +00:00
|
|
|
od_schemedb_t*
|
2017-07-14 13:40:31 +00:00
|
|
|
od_schemedb_add(od_scheme_t *scheme, int version)
|
2017-05-24 11:57:15 +00:00
|
|
|
{
|
2017-07-03 14:32:48 +00:00
|
|
|
od_schemedb_t *db;
|
|
|
|
db = (od_schemedb_t*)malloc(sizeof(*db));
|
|
|
|
if (db == NULL)
|
|
|
|
return NULL;
|
|
|
|
memset(db, 0, sizeof(*db));
|
|
|
|
od_list_init(&db->users);
|
|
|
|
od_list_init(&db->link);
|
|
|
|
od_list_append(&scheme->dbs, &db->link);
|
2017-07-14 13:40:31 +00:00
|
|
|
db->version = version;
|
2017-07-03 14:32:48 +00:00
|
|
|
return db;
|
2017-05-24 11:57:15 +00:00
|
|
|
}
|
|
|
|
|
2017-07-03 14:32:48 +00:00
|
|
|
od_schemedb_t*
|
2017-07-14 13:55:01 +00:00
|
|
|
od_schemedb_match(od_scheme_t *scheme, char *name, int version)
|
2017-05-24 11:57:15 +00:00
|
|
|
{
|
2017-07-14 13:55:01 +00:00
|
|
|
/* match maximum db scheme version which is
|
|
|
|
* lower then 'version' */
|
|
|
|
od_schemedb_t *match = NULL;
|
2017-07-03 14:32:48 +00:00
|
|
|
od_list_t *i;
|
|
|
|
od_list_foreach(&scheme->dbs, i) {
|
|
|
|
od_schemedb_t *db;
|
|
|
|
db = od_container_of(i, od_schemedb_t, link);
|
|
|
|
if (db->is_default)
|
|
|
|
continue;
|
2017-07-14 13:55:01 +00:00
|
|
|
if (strcmp(db->name, name) != 0)
|
|
|
|
continue;
|
|
|
|
if (db->version > version)
|
|
|
|
continue;
|
|
|
|
if (match) {
|
|
|
|
if (match->version < db->version)
|
|
|
|
match = db;
|
|
|
|
} else {
|
|
|
|
match = db;
|
|
|
|
}
|
2017-07-03 14:32:48 +00:00
|
|
|
}
|
2017-07-14 13:55:01 +00:00
|
|
|
return match;
|
2017-05-24 11:57:15 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 12:58:32 +00:00
|
|
|
void od_schemedb_ref(od_schemedb_t *db)
|
|
|
|
{
|
|
|
|
db->refs++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
od_schemeuser_free(od_schemeuser_t*);
|
|
|
|
|
|
|
|
void od_schemedb_unref(od_schemedb_t *db)
|
|
|
|
{
|
|
|
|
if (db->refs > 0)
|
|
|
|
--db->refs;
|
|
|
|
if (db->refs > 0)
|
|
|
|
return;
|
|
|
|
od_list_t *i, *n;
|
|
|
|
od_list_foreach_safe(&db->users, i, n) {
|
|
|
|
od_schemeuser_t *user;
|
|
|
|
user = od_container_of(i, od_schemeuser_t, link);
|
|
|
|
od_schemeuser_free(user);
|
|
|
|
}
|
|
|
|
if (db->name)
|
|
|
|
free(db->name);
|
|
|
|
od_list_unlink(&db->link);
|
|
|
|
free(db);
|
|
|
|
}
|
|
|
|
|
2017-05-24 11:57:15 +00:00
|
|
|
od_schemeuser_t*
|
2017-07-03 14:32:48 +00:00
|
|
|
od_schemeuser_add(od_schemedb_t *db)
|
2017-05-24 11:57:15 +00:00
|
|
|
{
|
2017-07-03 14:32:48 +00:00
|
|
|
od_schemeuser_t *user;
|
|
|
|
user = (od_schemeuser_t*)malloc(sizeof(*user));
|
2017-05-24 11:57:15 +00:00
|
|
|
if (user == NULL)
|
|
|
|
return NULL;
|
|
|
|
memset(user, 0, sizeof(*user));
|
2017-07-03 14:32:48 +00:00
|
|
|
user->pool_size = 100;
|
|
|
|
user->pool_cancel = 1;
|
|
|
|
user->pool_discard = 1;
|
|
|
|
user->pool_rollback = 1;
|
2017-05-24 12:13:44 +00:00
|
|
|
od_list_init(&user->link);
|
2017-07-03 14:32:48 +00:00
|
|
|
od_list_append(&db->users, &user->link);
|
2017-05-24 11:57:15 +00:00
|
|
|
return user;
|
|
|
|
}
|
|
|
|
|
|
|
|
od_schemeuser_t*
|
2017-07-03 14:32:48 +00:00
|
|
|
od_schemeuser_match(od_schemedb_t *db, char *name)
|
2017-05-24 11:57:15 +00:00
|
|
|
{
|
|
|
|
od_list_t *i;
|
2017-07-03 14:32:48 +00:00
|
|
|
od_list_foreach(&db->users, i) {
|
2017-05-24 11:57:15 +00:00
|
|
|
od_schemeuser_t *user;
|
|
|
|
user = od_container_of(i, od_schemeuser_t, link);
|
2017-07-03 14:32:48 +00:00
|
|
|
if (user->is_default)
|
|
|
|
continue;
|
2017-05-24 11:57:15 +00:00
|
|
|
if (strcmp(user->user, name) == 0)
|
|
|
|
return user;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-07-13 12:58:32 +00:00
|
|
|
void od_schemeuser_ref(od_schemeuser_t *user)
|
|
|
|
{
|
|
|
|
od_schemedb_ref(user->db);
|
|
|
|
}
|
|
|
|
|
|
|
|
void od_schemeuser_unref(od_schemeuser_t *user)
|
|
|
|
{
|
|
|
|
od_schemedb_unref(user->db);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
od_schemeuser_free(od_schemeuser_t *user)
|
|
|
|
{
|
|
|
|
if (user->user)
|
|
|
|
free(user->user);
|
|
|
|
if (user->user_password)
|
|
|
|
free(user->user_password);
|
|
|
|
if (user->auth)
|
|
|
|
free(user->auth);
|
|
|
|
if (user->storage)
|
|
|
|
od_schemestorage_unref(user->storage);
|
|
|
|
if (user->storage_name)
|
|
|
|
free(user->storage_name);
|
|
|
|
if (user->storage_db)
|
|
|
|
free(user->storage_db);
|
|
|
|
if (user->storage_user)
|
|
|
|
free(user->storage_user);
|
|
|
|
if (user->storage_password)
|
|
|
|
free(user->storage_password);
|
|
|
|
if (user->pool_sz)
|
|
|
|
free(user->pool_sz);
|
|
|
|
free(user);
|
|
|
|
}
|
|
|
|
|
2017-05-24 12:13:44 +00:00
|
|
|
int od_scheme_validate(od_scheme_t *scheme, od_log_t *log)
|
2017-05-24 11:57:15 +00:00
|
|
|
{
|
2017-06-01 12:45:49 +00:00
|
|
|
/* workers */
|
|
|
|
if (scheme->workers == 0) {
|
2017-06-15 12:00:12 +00:00
|
|
|
od_error(log, "config", "bad workers number");
|
2017-06-01 12:45:49 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-05-24 11:57:15 +00:00
|
|
|
/* listen */
|
2017-07-13 12:18:46 +00:00
|
|
|
if (scheme->host == NULL) {
|
|
|
|
od_error(log, "config", "listen host is not defined");
|
|
|
|
return -1;
|
|
|
|
}
|
2017-05-24 11:57:15 +00:00
|
|
|
|
|
|
|
/* tls */
|
2017-06-24 13:04:20 +00:00
|
|
|
if (scheme->tls) {
|
|
|
|
if (strcmp(scheme->tls, "disable") == 0) {
|
2017-05-24 11:57:15 +00:00
|
|
|
scheme->tls_verify = OD_TDISABLE;
|
|
|
|
} else
|
2017-06-24 13:04:20 +00:00
|
|
|
if (strcmp(scheme->tls, "allow") == 0) {
|
2017-05-24 11:57:15 +00:00
|
|
|
scheme->tls_verify = OD_TALLOW;
|
|
|
|
} else
|
2017-06-24 13:04:20 +00:00
|
|
|
if (strcmp(scheme->tls, "require") == 0) {
|
2017-05-24 11:57:15 +00:00
|
|
|
scheme->tls_verify = OD_TREQUIRE;
|
|
|
|
} else
|
2017-06-24 13:04:20 +00:00
|
|
|
if (strcmp(scheme->tls, "verify_ca") == 0) {
|
2017-05-24 11:57:15 +00:00
|
|
|
scheme->tls_verify = OD_TVERIFY_CA;
|
|
|
|
} else
|
2017-06-24 13:04:20 +00:00
|
|
|
if (strcmp(scheme->tls, "verify_full") == 0) {
|
2017-05-24 11:57:15 +00:00
|
|
|
scheme->tls_verify = OD_TVERIFY_FULL;
|
|
|
|
} else {
|
2017-06-15 12:00:12 +00:00
|
|
|
od_error(log, "config", "unknown tls mode");
|
2017-05-24 11:57:15 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-21 12:18:48 +00:00
|
|
|
/* storages */
|
|
|
|
if (od_list_empty(&scheme->storages)) {
|
|
|
|
od_error(log, "config", "no storages defined");
|
2017-05-24 11:57:15 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
od_list_t *i;
|
2017-06-21 12:18:48 +00:00
|
|
|
od_list_foreach(&scheme->storages, i) {
|
|
|
|
od_schemestorage_t *storage;
|
|
|
|
storage = od_container_of(i, od_schemestorage_t, link);
|
2017-06-22 12:29:39 +00:00
|
|
|
if (storage->type == NULL) {
|
|
|
|
od_error(log, "config", "storage '%s': no type is specified",
|
|
|
|
storage->name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (strcmp(storage->type, "remote") == 0) {
|
|
|
|
storage->storage_type = OD_SREMOTE;
|
|
|
|
} else
|
|
|
|
if (strcmp(storage->type, "local") == 0) {
|
|
|
|
storage->storage_type = OD_SLOCAL;
|
|
|
|
} else {
|
|
|
|
od_error(log, "config", "unknown storage type");
|
|
|
|
return -1;
|
|
|
|
}
|
2017-06-24 14:58:38 +00:00
|
|
|
if (storage->storage_type == OD_SREMOTE &&
|
|
|
|
storage->host == NULL) {
|
|
|
|
od_error(log, "config", "storage '%s': no remote host is specified",
|
2017-06-21 12:18:48 +00:00
|
|
|
storage->name);
|
2017-05-24 11:57:15 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2017-06-24 13:04:20 +00:00
|
|
|
if (storage->tls) {
|
|
|
|
if (strcmp(storage->tls, "disable") == 0) {
|
2017-06-21 12:18:48 +00:00
|
|
|
storage->tls_verify = OD_TDISABLE;
|
2017-05-24 11:57:15 +00:00
|
|
|
} else
|
2017-06-24 13:04:20 +00:00
|
|
|
if (strcmp(storage->tls, "allow") == 0) {
|
2017-06-21 12:18:48 +00:00
|
|
|
storage->tls_verify = OD_TALLOW;
|
2017-05-24 11:57:15 +00:00
|
|
|
} else
|
2017-06-24 13:04:20 +00:00
|
|
|
if (strcmp(storage->tls, "require") == 0) {
|
2017-06-21 12:18:48 +00:00
|
|
|
storage->tls_verify = OD_TREQUIRE;
|
2017-05-24 11:57:15 +00:00
|
|
|
} else
|
2017-06-24 13:04:20 +00:00
|
|
|
if (strcmp(storage->tls, "verify_ca") == 0) {
|
2017-06-21 12:18:48 +00:00
|
|
|
storage->tls_verify = OD_TVERIFY_CA;
|
2017-05-24 11:57:15 +00:00
|
|
|
} else
|
2017-06-24 13:04:20 +00:00
|
|
|
if (strcmp(storage->tls, "verify_full") == 0) {
|
2017-06-21 12:18:48 +00:00
|
|
|
storage->tls_verify = OD_TVERIFY_FULL;
|
2017-05-24 11:57:15 +00:00
|
|
|
} else {
|
2017-06-21 12:18:48 +00:00
|
|
|
od_error(log, "config", "unknown storage tls mode");
|
2017-05-24 11:57:15 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-03 14:32:48 +00:00
|
|
|
/* databases */
|
|
|
|
od_list_foreach(&scheme->dbs, i) {
|
|
|
|
od_schemedb_t *db;
|
|
|
|
db = od_container_of(i, od_schemedb_t, link);
|
|
|
|
if (db->is_default) {
|
|
|
|
if (scheme->db_default) {
|
|
|
|
od_error(log, "config", "more than one default db");
|
2017-05-24 11:57:15 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2017-07-03 14:32:48 +00:00
|
|
|
scheme->db_default = db;
|
2017-05-24 11:57:15 +00:00
|
|
|
}
|
|
|
|
|
2017-07-03 14:32:48 +00:00
|
|
|
/* routing table (per db and user) */
|
|
|
|
if (od_list_empty(&scheme->dbs)) {
|
|
|
|
od_error(log, "config", "no databases defined");
|
2017-05-24 11:57:15 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2017-07-03 14:32:48 +00:00
|
|
|
od_list_t *j;
|
|
|
|
od_list_foreach(&db->users, j) {
|
|
|
|
od_schemeuser_t *user;
|
|
|
|
user = od_container_of(j, od_schemeuser_t, link);
|
|
|
|
if (user->is_default) {
|
|
|
|
if (db->user_default) {
|
|
|
|
od_error(log, "config", "more than one default user for db '%s'",
|
|
|
|
db->name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
db->user_default = user;
|
|
|
|
}
|
|
|
|
if (user->storage_name == NULL) {
|
|
|
|
od_error(log, "config", "db '%s' user '%s': no route storage is specified",
|
|
|
|
db->name, user->user);
|
2017-05-24 11:57:15 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2017-07-13 12:58:32 +00:00
|
|
|
/* match storage and make a reference */
|
2017-07-14 13:55:01 +00:00
|
|
|
user->storage = od_schemestorage_match(scheme, user->storage_name, db->version);
|
2017-07-03 14:32:48 +00:00
|
|
|
if (user->storage == NULL) {
|
|
|
|
od_error(log, "config", "db '%s' user '%s': no route storage '%s' found",
|
|
|
|
db->name, user->user);
|
2017-05-24 11:57:15 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2017-07-13 12:58:32 +00:00
|
|
|
od_schemestorage_ref(user->storage);
|
2017-07-13 12:32:05 +00:00
|
|
|
|
|
|
|
/* pooling mode */
|
|
|
|
if (! user->pool_sz) {
|
|
|
|
od_error(log, "config", "db '%s' user '%s': pooling mode is not set",
|
|
|
|
db->name, user->user);
|
|
|
|
return -1;
|
|
|
|
}
|
2017-07-03 14:32:48 +00:00
|
|
|
if (strcmp(user->pool_sz, "session") == 0) {
|
|
|
|
user->pool = OD_PSESSION;
|
|
|
|
} else
|
|
|
|
if (strcmp(user->pool_sz, "transaction") == 0) {
|
|
|
|
user->pool = OD_PTRANSACTION;
|
|
|
|
} else {
|
|
|
|
od_error(log, "config", "db '%s' user '%s': unknown pooling mode",
|
|
|
|
db->name, user->user);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! user->auth) {
|
|
|
|
od_error(log, "config", "db '%s' user '%s' authentication mode is not defined",
|
|
|
|
db->name, user->user);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* auth */
|
|
|
|
if (strcmp(user->auth, "none") == 0) {
|
|
|
|
user->auth_mode = OD_ANONE;
|
|
|
|
} else
|
2017-07-04 12:12:07 +00:00
|
|
|
if (strcmp(user->auth, "block") == 0) {
|
|
|
|
user->auth_mode = OD_ABLOCK;
|
|
|
|
} else
|
2017-07-03 14:32:48 +00:00
|
|
|
if (strcmp(user->auth, "clear_text") == 0) {
|
|
|
|
user->auth_mode = OD_ACLEAR_TEXT;
|
|
|
|
if (user->user_password == NULL) {
|
|
|
|
od_error(log, "config", "db '%s' user '%s' password is not set",
|
|
|
|
db->name, user->user);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
if (strcmp(user->auth, "md5") == 0) {
|
|
|
|
user->auth_mode = OD_AMD5;
|
|
|
|
if (user->user_password == NULL) {
|
|
|
|
od_error(log, "config", "db '%s' user '%s' password is not set",
|
|
|
|
db->name, user->user);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
od_error(log, "config", "db '%s' user '%s' has unknown authentication mode",
|
|
|
|
db->name, user->user);
|
2017-05-24 11:57:15 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2017-07-03 14:32:48 +00:00
|
|
|
}
|
|
|
|
if (od_list_empty(&db->users)) {
|
|
|
|
od_error(log, "config", "no users defined for db %s", db->name);
|
|
|
|
return -1;
|
2017-05-24 11:57:15 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-03 14:32:48 +00:00
|
|
|
|
2017-05-24 11:57:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-06-01 09:45:49 +00:00
|
|
|
static inline char*
|
|
|
|
od_scheme_yes_no(int value) {
|
|
|
|
return value ? "yes" : "no";
|
|
|
|
}
|
|
|
|
|
2017-05-24 12:13:44 +00:00
|
|
|
void od_scheme_print(od_scheme_t *scheme, od_log_t *log)
|
2017-05-24 11:57:15 +00:00
|
|
|
{
|
2017-06-01 09:38:46 +00:00
|
|
|
if (scheme->log_debug)
|
2017-06-01 09:45:49 +00:00
|
|
|
od_log(log, "log_debug %s",
|
|
|
|
od_scheme_yes_no(scheme->log_debug));
|
|
|
|
if (scheme->log_config)
|
|
|
|
od_log(log, "log_config %s",
|
|
|
|
od_scheme_yes_no(scheme->log_config));
|
2017-06-28 10:50:29 +00:00
|
|
|
if (scheme->log_session)
|
|
|
|
od_log(log, "log_session %s",
|
|
|
|
od_scheme_yes_no(scheme->log_session));
|
2017-06-23 10:34:51 +00:00
|
|
|
if (scheme->log_statistics)
|
|
|
|
od_log(log, "log_statistics %d", scheme->log_statistics);
|
2017-05-24 11:57:15 +00:00
|
|
|
if (scheme->log_file)
|
2017-06-01 09:45:49 +00:00
|
|
|
od_log(log, "log_file %s", scheme->log_file);
|
2017-05-24 11:57:15 +00:00
|
|
|
if (scheme->pid_file)
|
2017-06-01 09:45:49 +00:00
|
|
|
od_log(log, "pid_file %s", scheme->pid_file);
|
2017-05-24 11:57:15 +00:00
|
|
|
if (scheme->syslog)
|
2017-06-01 09:45:49 +00:00
|
|
|
od_log(log, "syslog %d", scheme->syslog);
|
2017-05-24 11:57:15 +00:00
|
|
|
if (scheme->syslog_ident)
|
2017-06-01 09:45:49 +00:00
|
|
|
od_log(log, "syslog_ident %s", scheme->syslog_ident);
|
2017-05-24 11:57:15 +00:00
|
|
|
if (scheme->syslog_facility)
|
2017-05-31 15:47:15 +00:00
|
|
|
od_log(log, "syslog_facility %s", scheme->syslog_facility);
|
2017-05-24 11:57:15 +00:00
|
|
|
if (scheme->daemonize)
|
2017-06-01 09:45:49 +00:00
|
|
|
od_log(log, "daemonize %s",
|
|
|
|
od_scheme_yes_no(scheme->daemonize));
|
2017-06-06 14:55:43 +00:00
|
|
|
od_log(log, "readahead %d", scheme->readahead);
|
2017-06-07 12:40:08 +00:00
|
|
|
od_log(log, "pipelining %d", scheme->server_pipelining);
|
2017-06-19 10:55:49 +00:00
|
|
|
if (scheme->client_max_set)
|
|
|
|
od_log(log, "client_max %d", scheme->client_max);
|
2017-06-05 15:12:10 +00:00
|
|
|
od_log(log, "workers %d", scheme->workers);
|
2017-05-31 15:47:15 +00:00
|
|
|
od_log(log, "");
|
|
|
|
od_log(log, "listen");
|
2017-06-28 11:47:42 +00:00
|
|
|
od_log(log, " host %s", scheme->host);
|
2017-06-21 12:58:59 +00:00
|
|
|
od_log(log, " port %d", scheme->port);
|
|
|
|
od_log(log, " backlog %d", scheme->backlog);
|
|
|
|
od_log(log, " nodelay %d", scheme->nodelay);
|
|
|
|
od_log(log, " keepalive %d", scheme->keepalive);
|
2017-06-24 13:04:20 +00:00
|
|
|
if (scheme->tls)
|
|
|
|
od_log(log, " tls %s", scheme->tls);
|
2017-05-24 11:57:15 +00:00
|
|
|
if (scheme->tls_ca_file)
|
2017-06-24 13:04:20 +00:00
|
|
|
od_log(log, " tls_ca_file %s", scheme->tls_ca_file);
|
2017-05-24 11:57:15 +00:00
|
|
|
if (scheme->tls_key_file)
|
2017-06-24 13:04:20 +00:00
|
|
|
od_log(log, " tls_key_file %s", scheme->tls_key_file);
|
2017-05-24 11:57:15 +00:00
|
|
|
if (scheme->tls_cert_file)
|
2017-06-24 13:04:20 +00:00
|
|
|
od_log(log, " tls_cert_file %s", scheme->tls_cert_file);
|
2017-05-24 11:57:15 +00:00
|
|
|
if (scheme->tls_protocols)
|
2017-06-24 13:04:20 +00:00
|
|
|
od_log(log, " tls_protocols %s", scheme->tls_protocols);
|
2017-05-31 15:47:15 +00:00
|
|
|
od_log(log, "");
|
2017-06-21 12:58:59 +00:00
|
|
|
|
2017-05-24 11:57:15 +00:00
|
|
|
od_list_t *i;
|
2017-06-21 12:18:48 +00:00
|
|
|
od_list_foreach(&scheme->storages, i) {
|
|
|
|
od_schemestorage_t *storage;
|
|
|
|
storage = od_container_of(i, od_schemestorage_t, link);
|
2017-07-03 14:32:48 +00:00
|
|
|
od_log(log, "storage %s", storage->name);
|
2017-06-22 12:29:39 +00:00
|
|
|
od_log(log, " type %s", storage->type);
|
2017-06-24 14:58:38 +00:00
|
|
|
if (storage->host)
|
|
|
|
od_log(log, " host %s", storage->host);
|
|
|
|
if (storage->port)
|
|
|
|
od_log(log, " port %d", storage->port);
|
2017-06-24 13:04:20 +00:00
|
|
|
if (storage->tls)
|
|
|
|
od_log(log, " tls %s", storage->tls);
|
2017-06-21 12:18:48 +00:00
|
|
|
if (storage->tls_ca_file)
|
2017-06-21 12:58:59 +00:00
|
|
|
od_log(log, " tls_ca_file %s", storage->tls_ca_file);
|
2017-06-21 12:18:48 +00:00
|
|
|
if (storage->tls_key_file)
|
2017-06-21 12:58:59 +00:00
|
|
|
od_log(log, " tls_key_file %s", storage->tls_key_file);
|
2017-06-21 12:18:48 +00:00
|
|
|
if (storage->tls_cert_file)
|
2017-06-21 12:58:59 +00:00
|
|
|
od_log(log, " tls_cert_file %s", storage->tls_cert_file);
|
2017-06-21 12:18:48 +00:00
|
|
|
if (storage->tls_protocols)
|
2017-06-21 12:58:59 +00:00
|
|
|
od_log(log, " tls_protocols %s", storage->tls_protocols);
|
|
|
|
od_log(log, "");
|
2017-05-24 11:57:15 +00:00
|
|
|
}
|
2017-06-21 12:58:59 +00:00
|
|
|
|
2017-07-03 14:32:48 +00:00
|
|
|
od_list_foreach(&scheme->dbs, i) {
|
|
|
|
od_schemedb_t *db;
|
|
|
|
db = od_container_of(i, od_schemedb_t, link);
|
|
|
|
od_log(log, "database %s", db->name);
|
|
|
|
od_list_t *j;
|
|
|
|
od_list_foreach(&db->users, j) {
|
|
|
|
od_schemeuser_t *user;
|
|
|
|
user = od_container_of(j, od_schemeuser_t, link);
|
|
|
|
od_log(log, " user %s", user->user);
|
|
|
|
od_log(log, " authentication %s", user->auth);
|
|
|
|
od_log(log, " storage %s", user->storage_name);
|
|
|
|
if (user->storage_db)
|
|
|
|
od_log(log, " storage_db %s", user->storage_db);
|
|
|
|
if (user->storage_user)
|
|
|
|
od_log(log, " storage_user %s", user->storage_user);
|
|
|
|
od_log(log, " pool %s", user->pool_sz);
|
|
|
|
od_log(log, " pool_size %d", user->pool_size);
|
|
|
|
od_log(log, " pool_timeout %d", user->pool_timeout);
|
|
|
|
od_log(log, " pool_ttl %d", user->pool_ttl);
|
|
|
|
od_log(log, " pool_cancel %s",
|
|
|
|
user->pool_cancel ? "yes" : "no");
|
|
|
|
od_log(log, " pool_rollback %s",
|
|
|
|
user->pool_rollback ? "yes" : "no");
|
|
|
|
od_log(log, " pool_discard %s",
|
|
|
|
user->pool_discard ? "yes" : "no");
|
|
|
|
if (user->client_max_set)
|
|
|
|
od_log(log, " client_max %d", user->client_max);
|
|
|
|
od_log(log, "");
|
|
|
|
}
|
2017-05-24 11:57:15 +00:00
|
|
|
}
|
|
|
|
}
|