lua: Enable Lua
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Mon, 16 Sep 2013 11:33:16 +0000 (14:33 +0300)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Wed, 11 Jun 2014 14:48:03 +0000 (17:48 +0300)
However, disable the "io" and "os" standard libraries and only enable
the access() function from the "posix" extension library.

Change-Id: If3b5f0776f6684af4ebaeb7bff742ab9a2123221
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
luaext/lposix.c
rpmio/rpmlua.c

index f3c787eab2889ec6f5c7b0e03b2aa6581f826e8a..4d5269a4f3dcf3643745e99a93bec2ec1eca75dc 100644 (file)
@@ -813,7 +813,7 @@ static int Pmkstemp(lua_State *L)
 static const luaL_Reg R[] =
 {
        {"access",              Paccess},
-       {"chdir",               Pchdir},
+/*     {"chdir",               Pchdir},
        {"chmod",               Pchmod},
        {"chown",               Pchown},
        {"ctermid",             Pctermid},
@@ -851,7 +851,7 @@ static const luaL_Reg R[] =
        {"utime",               Putime},
        {"wait",                Pwait},
        {"setenv",              Psetenv},
-       {"unsetenv",            Punsetenv},
+       {"unsetenv",            Punsetenv},*/
        {NULL,                  NULL}
 };
 
index 49ae7a0aa3e6548943e75fe8460ea7d498e69363..8e6841d4eab7e3dd93d349f266d514742bc97436 100644 (file)
@@ -72,7 +72,7 @@ rpmlua rpmluaNew()
        {"posix", luaopen_posix},
        {"rex", luaopen_rex},
        {"rpm", luaopen_rpm},
-       {"os",  luaopen_rpm_os},
+       /*{"os",        luaopen_rpm_os},*/
        {NULL, NULL},
     };
     
@@ -86,6 +86,12 @@ rpmlua rpmluaNew()
        lua_call(L, 1, 0);
        lua_settop(L, 0);
     }
+    /* Disable os and io standard libraries */
+    lua_pushnil (L);
+    lua_setglobal(L, "os");
+    lua_pushnil (L);
+    lua_setglobal(L, "io");
+
 #ifndef LUA_GLOBALSINDEX
     lua_pushglobaltable(L);
 #endif
@@ -516,11 +522,6 @@ int rpmluaRunScript(rpmlua _lua, const char *script, const char *name)
     INITSTATE(_lua, lua);
     lua_State *L = lua->L;
     int ret = 0;
-#define LUA_OUTPUT "UNEXPANDEDLUASCRIPT"
-    rpmlog(RPMLOG_WARNING, _("Refusing to run lua code: %s\n"), script);
-    lua->printbuf->buf = xcalloc(1, sizeof(LUA_OUTPUT));
-    strcpy(lua->printbuf->buf, LUA_OUTPUT);
-#if 0
     if (name == NULL)
        name = "<lua>";
     if (luaL_loadbuffer(L, script, strlen(script), name) != 0) {
@@ -534,7 +535,6 @@ int rpmluaRunScript(rpmlua _lua, const char *script, const char *name)
        lua_pop(L, 1);
        ret = -1;
     }
-#endif
     return ret;
 }