dlua-dovecot.c (dovecot-2.3.16) | : | dlua-dovecot.c (dovecot-2.3.17) | ||
---|---|---|---|---|
skipping to change at line 573 | skipping to change at line 573 | |||
static int dlua_clear_flag(lua_State *L) | static int dlua_clear_flag(lua_State *L) | |||
{ | { | |||
DLUA_REQUIRE_ARGS(L, 2); | DLUA_REQUIRE_ARGS(L, 2); | |||
lua_Integer value = luaL_checkinteger(L, 1); | lua_Integer value = luaL_checkinteger(L, 1); | |||
lua_Integer flag = luaL_checkinteger(L, 2); | lua_Integer flag = luaL_checkinteger(L, 2); | |||
lua_pushinteger(L, value & (lua_Integer)~flag); | lua_pushinteger(L, value & (lua_Integer)~flag); | |||
return 1; | return 1; | |||
} | } | |||
static int dlua_script_strict_index(lua_State *L) | ||||
{ | ||||
DLUA_REQUIRE_ARGS(L, 2); | ||||
const char *name = luaL_checkstring(L, 2); | ||||
return luaL_error(L, "attempt to write to read undeclared global variable | ||||
%s", | ||||
name); | ||||
} | ||||
static int dlua_script_strict_newindex(lua_State *L) | ||||
{ | ||||
DLUA_REQUIRE_ARGS(L, 3); | ||||
if (lua_type(L, 3) == LUA_TFUNCTION) { | ||||
/* allow defining global functions */ | ||||
lua_rawset(L, 1); | ||||
} else { | ||||
const char *name = luaL_checkstring(L, 2); | ||||
return luaL_error(L, "attempt to write to undeclared global varia | ||||
ble %s", | ||||
name); | ||||
} | ||||
return 0; | ||||
} | ||||
static luaL_Reg env_strict_metamethods[] = { | ||||
{ "__index", dlua_script_strict_index }, | ||||
{ "__newindex", dlua_script_strict_newindex }, | ||||
{ NULL, NULL } | ||||
}; | ||||
static int dlua_restrict_global_variables(lua_State *L) | ||||
{ | ||||
DLUA_REQUIRE_ARGS(L, 1); | ||||
if (lua_toboolean(L, 1)) { | ||||
/* disable defining global variables */ | ||||
lua_getglobal(L, "_G"); | ||||
lua_newtable(L); | ||||
luaL_setfuncs(L, env_strict_metamethods, 0); | ||||
} else { | ||||
/* revert restrictions */ | ||||
lua_getglobal(L, "_G"); | ||||
lua_newtable(L); | ||||
} | ||||
lua_setmetatable(L, -2); | ||||
lua_pop(L, 1); | ||||
return 0; | ||||
} | ||||
static luaL_Reg lua_dovecot_methods[] = { | static luaL_Reg lua_dovecot_methods[] = { | |||
{ "i_debug", dlua_i_debug }, | { "i_debug", dlua_i_debug }, | |||
{ "i_info", dlua_i_info }, | { "i_info", dlua_i_info }, | |||
{ "i_warning", dlua_i_warning }, | { "i_warning", dlua_i_warning }, | |||
{ "i_error", dlua_i_error }, | { "i_error", dlua_i_error }, | |||
{ "event", dlua_event_new }, | { "event", dlua_event_new }, | |||
{ "has_flag", dlua_has_flag }, | { "has_flag", dlua_has_flag }, | |||
{ "set_flag", dlua_set_flag }, | { "set_flag", dlua_set_flag }, | |||
{ "clear_flag", dlua_clear_flag }, | { "clear_flag", dlua_clear_flag }, | |||
{ "restrict_global_variables", dlua_restrict_global_variables }, | ||||
{ NULL, NULL } | { NULL, NULL } | |||
}; | }; | |||
void dlua_getdovecot(lua_State *L) | void dlua_get_dovecot(lua_State *L) | |||
{ | { | |||
lua_getglobal(L, LUA_SCRIPT_DOVECOT); | lua_getglobal(L, LUA_SCRIPT_DOVECOT); | |||
} | } | |||
void dlua_dovecot_register(struct dlua_script *script) | void dlua_dovecot_register(struct dlua_script *script) | |||
{ | { | |||
i_assert(script != NULL); | i_assert(script != NULL); | |||
dlua_event_register(script); | dlua_event_register(script); | |||
End of changes. 3 change blocks. | ||||
1 lines changed or deleted | 51 lines changed or added |