/* Copyright (c) 2017-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#if defined(BUILTIN_LUA) || defined(PLUGIN_BUILD)
#include "llist.h"
#include "istream.h"
#include "array.h"
#include "sha1.h"
#include "hex-binary.h"
#include "auth.h"
#include "passdb.h"
#include "userdb.h"
#include "auth-request.h"
#include "userdb-template.h"
#include "passdb-template.h"
#include "password-scheme.h"
#include "auth-request-var-expand.h"
#include "db-lua.h"
#include "dlua-script-private.h"
struct auth_lua_userdb_iterate_context {
unsigned int idx;
};
static struct auth_request *
static int
{
const char *error;
return -1;
}
return 0;
}
{
return luaL_error(L, error);
} else {
lua_pushstring(L, value);
}
return 1;
}
static const char *const *
unsigned int *count_r)
{
if (req->userdb_lookup) {
if (userdb_template_is_empty(tpl))
return NULL;
} else {
if (passdb_template_is_empty(tpl))
return NULL;
}
}
{
unsigned int count,i;
/* push new table to stack */
lua_newtable(L);
return 1;
for(i = 0; i < count; i+=2) {
lua_pushnil(L);
return luaL_error(L, error);
} else {
lua_pushstring(L, expanded);
}
}
/* stack should be left with table */
return 1;
}
{
if (global_auth_settings->debug) {
}
return 0;
}
{
return 0;
}
{
return 0;
}
{
return 0;
}
{
lua_pop(L, 1);
lua_pushnil(L);
return 1;
}
lua_pushnil(L);
else
lua_pushstring(L, value);
return 1;
}
{
lua_pop(L, 1);
lua_pushnil(L);
return 1;
}
lua_pushnil(L);
else
lua_pushstring(L, value);
return 1;
}
/* put all methods here */
{ "var_expand", auth_request_lua_var_expand },
{ "response_from_template", auth_request_lua_response_from_template },
{ "log_debug", auth_request_lua_log_debug },
{ "log_info", auth_request_lua_log_info },
{ "log_warning", auth_request_lua_log_warning },
{" log_error", auth_request_lua_log_error },
};
{
lua_pop(L, 1);
/* check if it's variable */
for(unsigned int i = 0; i < AUTH_REQUEST_VAR_TAB_COUNT; i++) {
else
lua_pushnil(L);
return 1;
}
}
/* check if it's function, then */
return 1;
}
ptr++;
}
lua_pushstring(L, key);
lua_rawget(L, 1);
return 1;
}
{
/* create a table for holding few things */
lua_newtable(script->L);
lua_newtable(script->L);
}
static struct auth_request *
{
arg, "auth_request",
}
return (struct auth_request*)bp;
}
{
/* register passdb */
/* register userdb */
}
};
};
{
/* Create new table for holding values */
lua_newtable(script->L);
/* register constants */
/* push new metatable to stack */
/* this will register functions to the metatable itself */
/* point __index to self */
/* set table's metatable, pops stack */
/* put this as "dovecot.auth" */
}
{
}
{
int err = 0;
/* call lua function passdb_lookup, it is expected to return fields */
return -1;
}
/* call with auth request as parameter */
return -1;
"(expected number got %s)",
err = -1;
"(expected string or table, got %s)",
err = -1;
}
if (err != 0) {
return PASSDB_RESULT_INTERNAL_FAILURE;
}
return 0;
}
static void
const char *str,
const char **scheme_r, const char **password_r)
{
const char *key;
value = "";
} else {
}
*password_r = value;
} else if (req->userdb_lookup) {
} else {
}
fields++;
}
}
const char **scheme_r, const char **password_r)
{
lua_pushnil(script->L);
const char *value;
value = "";
} else {
"db-lua: '%s' has invalid value - ignoring",
key);
value = "";
}
*password_r = value;
} else if (req->userdb_lookup) {
} else {
}
}
}
static enum userdb_result
const char **error_r)
{
if (ret != USERDB_RESULT_OK) {
*error_r = "userdb failed";
return ret;
}
return USERDB_RESULT_OK;
}
static enum passdb_result
const char **scheme_r, const char **password_r,
const char **error_r)
{
if (ret != PASSDB_RESULT_OK) {
*error_r = "passb failed";
return ret;
}
return PASSDB_RESULT_OK;
}
static enum passdb_result
const char **scheme_r, const char **password_r,
const char **error_r)
{
}
} else {
}
*scheme_r = "PLAIN";
return ret;
}
enum passdb_result
{
int err = 0;
return PASSDB_RESULT_INTERNAL_FAILURE;
}
/* call with auth request, password as parameters */
return PASSDB_RESULT_INTERNAL_FAILURE;
"(expected number got %s)",
err = -1;
"(expected string or table, got %s)",
err = -1;
}
if (err != 0) {
return PASSDB_RESULT_INTERNAL_FAILURE;
}
}
enum passdb_result
const char **password_r, const char **error_r)
{
return PASSDB_RESULT_INTERNAL_FAILURE;
}
}
enum userdb_result
{
return USERDB_RESULT_INTERNAL_FAILURE;
}
}
if (ret != USERDB_RESULT_OK) {
return ret;
}
return USERDB_RESULT_OK;
}
struct userdb_iterate_context *
{
int ret;
}
}
}
lua_pushnil(script->L);
}
}
}
{
return;
}
}
{
return ret;
}
#ifndef BUILTIN_LUA
/* Building a plugin */
extern struct passdb_module_interface passdb_lua_plugin;
extern struct userdb_module_interface userdb_lua_plugin;
void authdb_lua_init(void);
void authdb_lua_deinit(void);
void authdb_lua_init(void)
{
}
void authdb_lua_deinit(void)
{
}
#endif
#endif