コード例 #1
0
ファイル: liolib.c プロジェクト: Allowed/Protheus
static int io_popen(lua_State *L) {
	const char *filename = luaL_checkstring(L, 1);
	const char *mode = luaL_optstring(L, 2, "r");
	LStream *p = newprefile(L);
	p->f = lua_popen(L, filename, mode);
	p->closef = &io_pclose;
	return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;
}
コード例 #2
0
ファイル: liolib.c プロジェクト: RonDePrez/opentx
static LStream *newfile (lua_State *L) {
  LStream *p = newprefile(L);
#if !defined(USE_FATFS)
  p->f = NULL;
  p->closef = &io_fclose;
#endif
  return p;
}
コード例 #3
0
ファイル: liolib.c プロジェクト: Allowed/Protheus
static void createstdfile(lua_State *L, FILE *f, const char *k,
	const char *fname) {
	LStream *p = newprefile(L);
	p->f = f;
	p->closef = &io_noclose;
	if (k != NULL) {
		lua_pushvalue(L, -1);
		lua_setfield(L, LUA_REGISTRYINDEX, k);  /* add file to registry */
	}
	lua_setfield(L, -2, fname);  /* add file to module */
}
コード例 #4
0
ファイル: liolibext.c プロジェクト: zauguin/LuaTeX
static int io_popen(lua_State * L)
{
    int ret = 1;
    char *safecmd = NULL;
    char *cmdname = NULL;
    int allow = 0;
    const char *filename = luaL_checkstring(L, 1);
    const char *mode = luaL_optstring(L, 2, "r");
    LStream *p = newprefile(L);

    if (shellenabledp <= 0) {
        lua_pushnil(L);
        lua_pushliteral(L, "All command execution is disabled");
        return 2;
    }
    /* If restrictedshell == 0, any command is allowed. */
    if (restrictedshell == 0)
        allow = 1;
    else
        allow = shell_cmd_is_allowed(filename, &safecmd, &cmdname);

    if (allow == 1) {
        p->f = lua_popen(L, filename, mode);
	p->closef = &io_pclose;
        ret = (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;
    } else if (allow == 2) {
        p->f = lua_popen(L, safecmd, mode);
	p->closef = &io_pclose;
        ret = (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;
    } else if (allow == 0) {
        lua_pushnil(L);
        lua_pushliteral(L, "Command execution disabled via shell_escape='p'");
        ret = 2;
    } else {
        lua_pushnil(L);
        lua_pushliteral(L, "Bad command line quoting");
        ret = 2;
    }
    return ret;
}
コード例 #5
0
ファイル: liolib.c プロジェクト: Allowed/Protheus
static LStream *newfile(lua_State *L) {
	LStream *p = newprefile(L);
	p->f = NULL;
	p->closef = &io_fclose;
	return p;
}