equal
deleted
inserted
replaced
58 #include "lualib.h" |
58 #include "lualib.h" |
59 #include "lauxlib.h" |
59 #include "lauxlib.h" |
60 |
60 |
61 #if (LUA_VERSION_NUM == 501) |
61 #if (LUA_VERSION_NUM == 501) |
62 #define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R) |
62 #define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R) |
|
63 #endif |
|
64 #if (LUA_VERSION_NUM < 503) |
|
65 #define lua_isinteger(L, n) lua_isnumber(L, n) |
63 #endif |
66 #endif |
64 |
67 |
65 #include <fcntl.h> |
68 #include <fcntl.h> |
66 #if defined(__linux__) |
69 #if defined(__linux__) |
67 #include <linux/falloc.h> |
70 #include <linux/falloc.h> |
104 lua_pushstring(L, "fork-failed"); |
107 lua_pushstring(L, "fork-failed"); |
105 return 2; |
108 return 2; |
106 } else if(pid != 0) { |
109 } else if(pid != 0) { |
107 /* We are the parent process */ |
110 /* We are the parent process */ |
108 lua_pushboolean(L, 1); |
111 lua_pushboolean(L, 1); |
109 lua_pushnumber(L, pid); |
112 lua_pushinteger(L, pid); |
110 return 2; |
113 return 2; |
111 } |
114 } |
112 |
115 |
113 /* and we are the child process */ |
116 /* and we are the child process */ |
114 if(setsid() == -1) { |
117 if(setsid() == -1) { |
293 |
296 |
294 if(lua_gettop(L) < 1) { |
297 if(lua_gettop(L) < 1) { |
295 return 0; |
298 return 0; |
296 } |
299 } |
297 |
300 |
298 if(!lua_isnumber(L, 1) && lua_tostring(L, 1)) { |
301 if(!lua_isinteger(L, 1) && lua_tostring(L, 1)) { |
299 /* Passed UID is actually a string, so look up the UID */ |
302 /* Passed UID is actually a string, so look up the UID */ |
300 struct passwd *p; |
303 struct passwd *p; |
301 p = getpwnam(lua_tostring(L, 1)); |
304 p = getpwnam(lua_tostring(L, 1)); |
302 |
305 |
303 if(!p) { |
306 if(!p) { |
306 return 2; |
309 return 2; |
307 } |
310 } |
308 |
311 |
309 uid = p->pw_uid; |
312 uid = p->pw_uid; |
310 } else { |
313 } else { |
311 uid = lua_tonumber(L, 1); |
314 uid = lua_tointeger(L, 1); |
312 } |
315 } |
313 |
316 |
314 if(uid > -1) { |
317 if(uid > -1) { |
315 /* Ok, attempt setuid */ |
318 /* Ok, attempt setuid */ |
316 errno = 0; |
319 errno = 0; |
351 |
354 |
352 if(lua_gettop(L) < 1) { |
355 if(lua_gettop(L) < 1) { |
353 return 0; |
356 return 0; |
354 } |
357 } |
355 |
358 |
356 if(!lua_isnumber(L, 1) && lua_tostring(L, 1)) { |
359 if(!lua_isinteger(L, 1) && lua_tostring(L, 1)) { |
357 /* Passed GID is actually a string, so look up the GID */ |
360 /* Passed GID is actually a string, so look up the GID */ |
358 struct group *g; |
361 struct group *g; |
359 g = getgrnam(lua_tostring(L, 1)); |
362 g = getgrnam(lua_tostring(L, 1)); |
360 |
363 |
361 if(!g) { |
364 if(!g) { |
364 return 2; |
367 return 2; |
365 } |
368 } |
366 |
369 |
367 gid = g->gr_gid; |
370 gid = g->gr_gid; |
368 } else { |
371 } else { |
369 gid = lua_tonumber(L, 1); |
372 gid = lua_tointeger(L, 1); |
370 } |
373 } |
371 |
374 |
372 if(gid > -1) { |
375 if(gid > -1) { |
373 /* Ok, attempt setgid */ |
376 /* Ok, attempt setgid */ |
374 errno = 0; |
377 errno = 0; |
645 lua_pushboolean(L, 1); |
648 lua_pushboolean(L, 1); |
646 |
649 |
647 if(lim.rlim_cur == RLIM_INFINITY) { |
650 if(lim.rlim_cur == RLIM_INFINITY) { |
648 lua_pushstring(L, "unlimited"); |
651 lua_pushstring(L, "unlimited"); |
649 } else { |
652 } else { |
650 lua_pushnumber(L, lim.rlim_cur); |
653 lua_pushinteger(L, lim.rlim_cur); |
651 } |
654 } |
652 |
655 |
653 if(lim.rlim_max == RLIM_INFINITY) { |
656 if(lim.rlim_max == RLIM_INFINITY) { |
654 lua_pushstring(L, "unlimited"); |
657 lua_pushstring(L, "unlimited"); |
655 } else { |
658 } else { |
656 lua_pushnumber(L, lim.rlim_max); |
659 lua_pushinteger(L, lim.rlim_max); |
657 } |
660 } |
658 |
661 |
659 return 3; |
662 return 3; |
660 } |
663 } |
661 |
664 |