Skip to content

Instantly share code, notes, and snippets.

@dndx
Created December 8, 2020 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dndx/b8b87f5abaac11ad89c89d8fd505a68f to your computer and use it in GitHub Desktop.
Save dndx/b8b87f5abaac11ad89c89d8fd505a68f to your computer and use it in GitHub Desktop.
LuaJIT checking user and group exists
local ffi = require("ffi")
local C = ffi.C
ffi.cdef([[
struct group *getgrnam(const char *name);
struct passwd *getpwnam(const char *name);
]])
if C.getpwnam("kong") == nil then
print("kong user does not exist")
else
print("kong user exists")
end
if C.getpwnam("root") == nil then
print("root user does not exist")
else
print("root user exists")
end
if C.getgrnam("kong") == nil then
print("kong group does not exist")
else
print("kong group exists")
end
if C.getgrnam("root") == nil then
print("root group does not exist")
else
print("root group exists")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment