Change in osmocom-bb[master]: lua: Add API to enable passing credentials

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Holger Freyther gerrit-no-reply at lists.osmocom.org
Mon Jun 25 20:26:17 UTC 2018


Holger Freyther has submitted this change and it was merged. ( https://gerrit.osmocom.org/9662 )

Change subject: lua: Add API to enable passing credentials
......................................................................

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
---
M src/host/layer23/src/mobile/script_lua.c
1 file changed, 22 insertions(+), 1 deletion(-)

Approvals:
  Jenkins Builder: Verified
  Harald Welte: Looks good to me, approved
  Pau Espin Pedrol: Looks good to me, but someone else must approve



diff --git a/src/host/layer23/src/mobile/script_lua.c b/src/host/layer23/src/mobile/script_lua.c
index 8d3064d..4cfe55a 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 @@
 	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 osmo_funcs[] = {
 	{ "timeout",	lua_osmo_timeout },
+	{ "unix_passcred", lua_unix_passcred },
 	{ "ms",	lua_osmo_ms },
 	{ NULL, NULL },
 };

-- 
To view, visit https://gerrit.osmocom.org/9662
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib4a5eef611f524f5d21cb6a7f4eace22b8ba60d0
Gerrit-Change-Number: 9662
Gerrit-PatchSet: 1
Gerrit-Owner: Holger Freyther <holger at freyther.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Holger Freyther <holger at freyther.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180625/c0a49d03/attachment.htm>


More information about the gerrit-log mailing list