diff options
author | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2018-06-04 16:42:55 +0200 |
---|---|---|
committer | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2018-06-17 19:22:57 +0100 |
commit | ce772ce3380ea97d615aebcec1b44d066b37c4e2 (patch) | |
tree | 38a5e2c6099b538684acd7a60782ee372a729cf5 /src/host/layer23 | |
parent | ac37f55b1ce213d1a829c85b3739fe9c61104f2e (diff) |
lua: Add API to enable passing credentials
This can be useful to have bidirectional communication between the
mobile lua script an external control script.
Change-Id: Ib4a5eef611f524f5d21cb6a7f4eace22b8ba60d0
Diffstat (limited to 'src/host/layer23')
-rw-r--r-- | src/host/layer23/src/mobile/script_lua.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/host/layer23/src/mobile/script_lua.c b/src/host/layer23/src/mobile/script_lua.c index 8d3064d0..4cfe55a9 100644 --- a/src/host/layer23/src/mobile/script_lua.c +++ b/src/host/layer23/src/mobile/script_lua.c @@ -1,4 +1,4 @@ -/* (C) 2017 by Holger Hans Peter Freyther +/* (C) 2017-2018 by Holger Hans Peter Freyther * * All Rights Reserved * @@ -30,6 +30,9 @@ #include <osmocom/vty/misc.h> +#include <sys/types.h> +#include <sys/socket.h> + struct timer_userdata { int cb_ref; }; @@ -410,6 +413,23 @@ static int lua_ms_name(lua_State *L) return 1; } +/* Expect a fd on the stack and enable SO_PASSCRED */ +static int lua_unix_passcred(lua_State *L) +{ + int one = 1; + int fd, rc; + + luaL_argcheck(L, lua_isnumber(L, -1), 1, "needs to be a filedescriptor"); + fd = (int) lua_tonumber(L, -1); + + rc = setsockopt(fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one)); + if (rc != 0) + LOGP(DLUA, LOGL_ERROR, "Failed to set SO_PASSCRED: %s\n", + strerror(errno)); + lua_pushinteger(L, rc); + return 1; +} + static const struct luaL_Reg ms_funcs[] = { { "imsi", lua_ms_imsi }, { "imei", lua_ms_imei }, @@ -426,6 +446,7 @@ static const struct luaL_Reg ms_funcs[] = { static const struct luaL_Reg osmo_funcs[] = { { "timeout", lua_osmo_timeout }, + { "unix_passcred", lua_unix_passcred }, { "ms", lua_osmo_ms }, { NULL, NULL }, }; |