From ce772ce3380ea97d615aebcec1b44d066b37c4e2 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Mon, 4 Jun 2018 16:42:55 +0200 Subject: 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 --- src/host/layer23/src/mobile/script_lua.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/host') 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 +#include +#include + 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 }, }; -- cgit v1.2.3