diff options
| author | TitanSnow <[email protected]> | 2017-05-23 07:45:22 +0800 |
|---|---|---|
| committer | TitanSnow <[email protected]> | 2017-05-23 07:45:22 +0800 |
| commit | ce5c4be20bb79418ec63b705952e3ef383b130eb (patch) | |
| tree | d1e4fb58d20bad8a8f00040da0304cc58e47d783 /core/src | |
| parent | 7b2bd5ca66ae8ed9f890d32f86fee9501d84968a (diff) | |
use setreuid
Diffstat (limited to 'core/src')
| -rw-r--r-- | core/src/xmake/os/gid.c | 39 | ||||
| -rw-r--r-- | core/src/xmake/os/uid.c | 39 |
2 files changed, 30 insertions, 48 deletions
diff --git a/core/src/xmake/os/gid.c b/core/src/xmake/os/gid.c index 03a8c0e13..e3506514d 100644 --- a/core/src/xmake/os/gid.c +++ b/core/src/xmake/os/gid.c @@ -41,13 +41,13 @@ * implementation */ -// get gid & egid +// get & set gid tb_int_t xm_os_gid(lua_State* lua) { // check tb_assert_and_check_return_val(lua, 0); - tb_int_t gidset = -1, egidset = -1; + tb_int_t rgidset = -1, egidset = -1; tb_int_t argc = lua_gettop(lua); @@ -55,8 +55,8 @@ tb_int_t xm_os_gid(lua_State* lua) { if (lua_istable(lua, 1)) { - // os.gid({["gid"] = gid, ["egid"] = egid}) - lua_getfield(lua, 1, "gid"); + // os.gid({["rgid"] = rgid, ["egid"] = egid}) + lua_getfield(lua, 1, "rgid"); lua_getfield(lua, 1, "egid"); if (!lua_isnil(lua, -1)) { @@ -73,17 +73,17 @@ tb_int_t xm_os_gid(lua_State* lua) { if (!lua_isnumber(lua, -1)) { - lua_pushfstring(lua, "invalid field type(%s) in `gid` for os.gid", luaL_typename(lua, -1)); + lua_pushfstring(lua, "invalid field type(%s) in `rgid` for os.gid", luaL_typename(lua, -1)); lua_error(lua); return 0; } - gidset = (tb_int_t)lua_tonumber(lua, -1); + rgidset = (tb_int_t)lua_tonumber(lua, -1); } lua_pop(lua, 1); } else if (lua_isnumber(lua, 1)) { - // os.gid(egid) - egidset = (tb_int_t)lua_tonumber(lua, 1); + // os.gid(gid) + rgidset = egidset = (tb_int_t)lua_tonumber(lua, 1); } else { lua_pushfstring(lua, "invalid argument type(%s) for os.gid", luaL_typename(lua, 1)); @@ -92,7 +92,7 @@ tb_int_t xm_os_gid(lua_State* lua) } } else if (argc == 2) { - // os.gid(gid, egid) + // os.gid(rgid, egid) if (!lua_isnil(lua, 1)) { if (!lua_isnumber(lua, 1)) @@ -101,7 +101,7 @@ tb_int_t xm_os_gid(lua_State* lua) lua_error(lua); return 0; } - gidset = (tb_int_t)lua_tonumber(lua, 1); + rgidset = (tb_int_t)lua_tonumber(lua, 1); } if (!lua_isnil(lua, 2)) { @@ -123,25 +123,16 @@ tb_int_t xm_os_gid(lua_State* lua) // store return value lua_newtable(lua); - // set gid & egid - if (gidset != -1) - { - lua_pushstring(lua, "setgid_errno"); - lua_pushinteger(lua, setgid(gidset) != 0 ? errno : 0); - lua_settable(lua, -3); - } - if (egidset != -1) - { - lua_pushstring(lua, "setegid_errno"); - lua_pushinteger(lua, setegid(egidset) != 0 ? errno : 0); - lua_settable(lua, -3); - } + // set rgid & egid + lua_pushstring(lua, "errno"); + lua_pushinteger(lua, setregid(rgidset, egidset) != 0 ? errno : 0); + lua_settable(lua, -3); // get gid & egid gid_t gid = getgid(), egid = getegid(); // push - lua_pushstring(lua, "gid"); + lua_pushstring(lua, "rgid"); lua_pushinteger(lua, gid); lua_settable(lua, -3); lua_pushstring(lua, "egid"); diff --git a/core/src/xmake/os/uid.c b/core/src/xmake/os/uid.c index 0c67a3edf..2c173b868 100644 --- a/core/src/xmake/os/uid.c +++ b/core/src/xmake/os/uid.c @@ -41,13 +41,13 @@ * implementation */ -// get uid & euid +// get & set uid tb_int_t xm_os_uid(lua_State* lua) { // check tb_assert_and_check_return_val(lua, 0); - tb_int_t uidset = -1, euidset = -1; + tb_int_t ruidset = -1, euidset = -1; tb_int_t argc = lua_gettop(lua); @@ -55,8 +55,8 @@ tb_int_t xm_os_uid(lua_State* lua) { if (lua_istable(lua, 1)) { - // os.uid({["uid"] = uid, ["euid"] = euid}) - lua_getfield(lua, 1, "uid"); + // os.uid({["ruid"] = ruid, ["euid"] = euid}) + lua_getfield(lua, 1, "ruid"); lua_getfield(lua, 1, "euid"); if (!lua_isnil(lua, -1)) { @@ -73,17 +73,17 @@ tb_int_t xm_os_uid(lua_State* lua) { if (!lua_isnumber(lua, -1)) { - lua_pushfstring(lua, "invalid field type(%s) in `uid` for os.uid", luaL_typename(lua, -1)); + lua_pushfstring(lua, "invalid field type(%s) in `ruid` for os.uid", luaL_typename(lua, -1)); lua_error(lua); return 0; } - uidset = (tb_int_t)lua_tonumber(lua, -1); + ruidset = (tb_int_t)lua_tonumber(lua, -1); } lua_pop(lua, 1); } else if (lua_isnumber(lua, 1)) { - // os.uid(euid) - euidset = (tb_int_t)lua_tonumber(lua, 1); + // os.uid(uid) + ruidset = euidset = (tb_int_t)lua_tonumber(lua, 1); } else { lua_pushfstring(lua, "invalid argument type(%s) for os.uid", luaL_typename(lua, 1)); @@ -92,7 +92,7 @@ tb_int_t xm_os_uid(lua_State* lua) } } else if (argc == 2) { - // os.uid(uid, euid) + // os.uid(ruid, euid) if (!lua_isnil(lua, 1)) { if (!lua_isnumber(lua, 1)) @@ -101,7 +101,7 @@ tb_int_t xm_os_uid(lua_State* lua) lua_error(lua); return 0; } - uidset = (tb_int_t)lua_tonumber(lua, 1); + ruidset = (tb_int_t)lua_tonumber(lua, 1); } if (!lua_isnil(lua, 2)) { @@ -123,25 +123,16 @@ tb_int_t xm_os_uid(lua_State* lua) // store return value lua_newtable(lua); - // set uid & euid - if (uidset != -1) - { - lua_pushstring(lua, "setuid_errno"); - lua_pushinteger(lua, setuid(uidset) != 0 ? errno : 0); - lua_settable(lua, -3); - } - if (euidset != -1) - { - lua_pushstring(lua, "seteuid_errno"); - lua_pushinteger(lua, seteuid(euidset) != 0 ? errno : 0); - lua_settable(lua, -3); - } + // set ruid & euid + lua_pushstring(lua, "errno"); + lua_pushinteger(lua, setreuid(ruidset, euidset) != 0 ? errno : 0); + lua_settable(lua, -3); // get uid & euid uid_t uid = getuid(), euid = geteuid(); // push - lua_pushstring(lua, "uid"); + lua_pushstring(lua, "ruid"); lua_pushinteger(lua, uid); lua_settable(lua, -3); lua_pushstring(lua, "euid"); |
