db-dict.c revision b5052fbfdbc2678cc8f12899afe55c998f43b740
/* Copyright (c) 2013-2016 Dovecot authors, see the included COPYING file */
#include "auth-common.h"
#include "array.h"
#include "istream.h"
#include "str.h"
#include "json-parser.h"
#include "settings.h"
#include "dict.h"
#include "auth-request.h"
#include "auth-worker-client.h"
#include "db-dict.h"
#include <stddef.h>
enum dict_settings_section {
};
struct dict_settings_parser_ctx {
struct dict_connection *conn;
enum dict_settings_section section;
struct db_dict_key *cur_key;
};
struct db_dict_iter_key {
const struct db_dict_key *key;
bool used;
const char *value;
};
struct db_dict_value_iter {
struct auth_request *auth_request;
struct dict_connection *conn;
const struct var_expand_table *var_expand_table;
unsigned int field_idx;
unsigned int object_idx;
struct json_parser *json_parser;
const char *error;
};
static struct setting_def setting_defs[] = {
{ 0, NULL, 0 }
};
static struct db_dict_settings default_dict_settings = {
.default_pass_scheme = "MD5",
.iterate_prefix = "",
.iterate_disable = FALSE,
.passdb_objects = "",
.userdb_objects = ""
};
static struct setting_def key_setting_defs[] = {
{ 0, NULL, 0 }
};
static struct db_dict_key default_key_settings = {
.key = "",
.format = "value",
};
{
struct dict_connection *conn;
return conn;
}
return NULL;
}
static bool
struct dict_settings_parser_ctx *ctx,
const char **error_r)
{
const struct db_dict_key *dbkey;
/* key passdb { key=<value> format=json }
passdb_objects = passdb */
return TRUE;
}
/* key userdb { key=<value> format=json }
userdb_objects = userdb */
return TRUE;
}
return TRUE;
*error_r = "Deprecated value_format must be 'json'";
return FALSE;
}
return FALSE;
}
struct dict_settings_parser_ctx *ctx)
{
struct db_dict_field *field;
return NULL;
return error;
return NULL;
return NULL;
}
}
struct dict_settings_parser_ctx *ctx,
const char **errormsg)
{
} else {
return t_strconcat("Unknown key format: ",
}
}
return TRUE;
}
*errormsg = "Nested sections not supported";
return FALSE;
}
*errormsg = "Key section is missing name";
return FALSE;
}
*errormsg = "Key section names must not contain '.'";
return FALSE;
}
return TRUE;
}
return TRUE;
}
return TRUE;
}
*errormsg = "Unknown section";
return FALSE;
}
static void
{
const struct db_dict_key *key;
const char *const *tmp;
i_fatal("dict: passdb_objects refers to key %s, "
"which doesn't exist", *tmp);
}
i_fatal("dict: passdb_objects refers to key %s, "
"but it's in value-only format", *tmp);
}
}
i_fatal("dict: userdb_objects refers to key %s, "
"which doesn't exist", *tmp);
}
i_fatal("dict: userdb_objects refers to key %s, "
"but it's in value-only format", *tmp);
}
}
}
{
struct dict_settings dict_set;
struct dict_settings_parser_ctx ctx;
struct dict_connection *conn;
const char *error;
return conn;
}
if (*config_path == '\0')
i_fatal("dict: Configuration file path not given");
connections = conn;
return conn;
}
{
return;
}
static struct db_dict_iter_key *
{
struct db_dict_iter_key *key;
return key;
}
return NULL;
}
{
const struct db_dict_field *field;
struct db_dict_iter_key *key;
const char *p, *name;
if (*p != '%') {
p++;
continue;
}
if (size == 0) {
/* broken %variable ending too early */
break;
}
p += idx;
}
p += size;
}
}
}
{
const struct db_dict_key *const *keyp;
struct db_dict_iter_key *key;
}
}
static int
const struct db_dict_iter_key *k2)
{
}
{
struct db_dict_iter_key *key;
const char *error;
int ret;
/* sort the keys so that we'll first lookup the keys without
default value. if their lookup fails, the user doesn't exist. */
continue;
if (ret > 0) {
} else if (ret < 0) {
return -1;
"Lookup: %s not found, using default value %s",
} else {
return 0;
}
}
return 1;
}
struct auth_request *auth_request,
struct db_dict_value_iter **iter_r)
{
struct db_dict_value_iter *iter;
struct db_dict_iter_key *iterkey;
const struct db_dict_key *key;
int ret;
/* figure out what keys we need to lookup, and lookup them */
}
T_BEGIN {
} T_END;
if (ret <= 0) {
pool_unref(&pool);
return ret;
}
return 1;
}
static bool
{
const char *value;
return FALSE;
if (type != JSON_TYPE_OBJECT_KEY) {
return FALSE;
}
if (*value == '\0') {
return FALSE;
}
str_truncate(tmpstr, 0);
return FALSE;
}
if (type == JSON_TYPE_OBJECT) {
return FALSE;
}
return TRUE;
}
static void
{
}
static bool
{
const struct db_dict_key *const *keyp;
struct db_dict_iter_key *key;
return FALSE;
i_unreached();
}
i_unreached();
}
static const char *
{
struct db_dict_iter_key *key;
return NULL;
return NULL;
ret = "";
break;
}
}
return ret;
}
i_unreached();
}
{
static struct var_expand_func_table var_funcs_table[] = {
{ "dict", db_dict_field_find },
};
const struct db_dict_field *field;
return TRUE;
}
const char **error_r)
{
}
}