Esempio n. 1
0
/*
** this function has a separated environment, which defines the
** correct __close for 'popen' files
*/
static int io_popen (lua_State *L) {
  const char *filename = luaL_checkstring(L, 1);
  const char *mode = luaL_optstring(L, 2, "r");
  FILE **pf = newfile(L);
  *pf = lua_popen(L, filename, mode);
  return (*pf == NULL) ? pushresult(L, 0, filename) : 1;
}
Esempio n. 2
0
static int io_popen (lua_State *L) {
  const char *filename = luaL_checkstring(L, 1);
  const char *mode = luaL_optstring(L, 2, "r");
  int *pf = newfile(L);
  *pf = lua_popen(L, filename, fs_mode2flag(mode));
  return (*pf == FS_OPEN_OK - 1) ? pushresult(L, 0, filename) : 1;
}
Esempio n. 3
0
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;
}
Esempio n. 4
0
/*
** this function has a separated environment, which defines the
** correct __close for 'popen' files
*/
static int io_popen(lua_State *L)
{
    const wchar_t *filename = check_utf8_string(L, 1, NULL);
    const wchar_t *mode = opt_utf8_string(L, 2, L"r");
    FILE **pf = newfile(L);
    *pf = lua_popen(L, filename, mode);
    return (*pf == NULL) ? pushresult(L, 0, filename) : 1;
}
Esempio n. 5
0
static int io_popen (lua_State *L) {
#if !USE_POPEN
  luaL_error(L, "`popen' not supported");
  return 0;
#else
  const char *filename = luaL_checkstring(L, 1);
  const char *mode = luaL_optstring(L, 2, "r");
  FILE **pf = newfile(L);
  *pf = lua_popen(L, filename, mode);
  return (*pf == NULL) ? pushresult(L, 0, filename) : 1;
#endif
}
Esempio n. 6
0
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;
}
Esempio n. 7
0
static int io_popen(lua_State * L)
{
    int ret = 1;
    char *safecmd = NULL;
    char *cmdname = NULL;
    int allow = 0;
    const char *cmd = luaL_checkstring(L, 1);
    const char *mode = luaL_optstring(L, 2, "rb");
    FILE **pf = newfile(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(cmd, &safecmd, &cmdname);

    if (allow == 1) {
        *pf = lua_popen(L, cmd, mode);
        ret = (*pf == NULL) ? pushresult(L, 0, cmd) : 1;
    } else if (allow == 2) {
        *pf = lua_popen(L, safecmd, mode);
        ret = (*pf == NULL) ? pushresult(L, 0, safecmd) : 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;
}
Esempio n. 8
0
static int io_popen (lua_State *L) {
  const char *filename = luaL_checkstring(L, 1);
  const char *mode = luaL_optstring(L, 2, "r");
  FILE **pf = newfile(L);
#ifdef WIN32
  wchar_t wfilename[MAX_PATH+1];
  wchar_t wmode[10];
  MultiByteToWideChar(CP_UTF8, 0, filename, -1, wfilename, MAX_PATH+1);
  MultiByteToWideChar(CP_UTF8, 0, mode, -1, wmode, 10);
  *pf = _wpopen(wfilename, wmode);
#else
  // FIXME: this should probably be patched to translate UTF-8 strings to the local filesystem encoding on other systems
  *pf = lua_popen(L, filename, mode);
#endif
  return (*pf == NULL) ? pushresult(L, 0, filename) : 1;
}