SO_PASSCRED and SO_PEERCRED options
This commit is contained in:
parent
316a9455b9
commit
cc7cdf2d5b
3 changed files with 47 additions and 0 deletions
|
@ -251,6 +251,33 @@ int opt_set_ip6_v6only(lua_State *L, p_socket ps)
|
|||
return opt_setboolean(L, ps, IPPROTO_IPV6, IPV6_V6ONLY);
|
||||
}
|
||||
|
||||
int opt_set_passcred(lua_State *L, p_socket ps)
|
||||
{
|
||||
return opt_setboolean(L, ps, SOL_SOCKET, SO_PASSCRED);
|
||||
}
|
||||
|
||||
int opt_get_passcred(lua_State *L, p_socket ps)
|
||||
{
|
||||
return opt_getboolean(L, ps, SOL_SOCKET, SO_PASSCRED);
|
||||
}
|
||||
|
||||
int opt_get_peercred(lua_State *L, p_socket ps)
|
||||
{
|
||||
struct ucred cred;
|
||||
int len = sizeof(cred);
|
||||
int err = opt_get(L, ps, SOL_SOCKET, SO_PEERCRED, (char *) &cred, &len);
|
||||
if (err < 0)
|
||||
return err;
|
||||
lua_newtable(L);
|
||||
lua_pushinteger(L, (long) cred.pid);
|
||||
lua_setfield(L, -2, "pid");
|
||||
lua_pushinteger(L, (long) cred.uid);
|
||||
lua_setfield(L, -2, "uid");
|
||||
lua_pushinteger(L, (long) cred.gid);
|
||||
lua_setfield(L, -2, "gid");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*=========================================================================*\
|
||||
* Auxiliar functions
|
||||
\*=========================================================================*/
|
||||
|
|
|
@ -37,6 +37,7 @@ int opt_set_ip6_multicast_loop(lua_State *L, p_socket ps);
|
|||
int opt_set_ip6_add_membership(lua_State *L, p_socket ps);
|
||||
int opt_set_ip6_drop_membersip(lua_State *L, p_socket ps);
|
||||
int opt_set_ip6_v6only(lua_State *L, p_socket ps);
|
||||
int opt_set_passcred(lua_State *L, p_socket ps);
|
||||
|
||||
/* supported options for getoption */
|
||||
int opt_get_dontroute(lua_State *L, p_socket ps);
|
||||
|
@ -54,6 +55,8 @@ int opt_get_ip6_multicast_hops(lua_State *L, p_socket ps);
|
|||
int opt_get_ip6_unicast_hops(lua_State *L, p_socket ps);
|
||||
int opt_get_ip6_v6only(lua_State *L, p_socket ps);
|
||||
int opt_get_reuseport(lua_State *L, p_socket ps);
|
||||
int opt_get_passcred(lua_State *L, p_socket ps);
|
||||
int opt_get_peercred(lua_State *L, p_socket ps);
|
||||
|
||||
/* invokes the appropriate option handler */
|
||||
int opt_meth_setoption(lua_State *L, p_opt opt, p_socket ps);
|
||||
|
|
|
@ -27,6 +27,7 @@ static int meth_receive(lua_State *L);
|
|||
static int meth_accept(lua_State *L);
|
||||
static int meth_close(lua_State *L);
|
||||
static int meth_setoption(lua_State *L);
|
||||
static int meth_getoption(lua_State *L);
|
||||
static int meth_settimeout(lua_State *L);
|
||||
static int meth_getfd(lua_State *L);
|
||||
static int meth_setfd(lua_State *L);
|
||||
|
@ -55,6 +56,7 @@ static luaL_Reg unixtcp_methods[] = {
|
|||
{"send", meth_send},
|
||||
{"setfd", meth_setfd},
|
||||
{"setoption", meth_setoption},
|
||||
{"getoption", meth_getoption},
|
||||
{"setpeername", meth_connect},
|
||||
{"setsockname", meth_bind},
|
||||
{"getsockname", meth_getsockname},
|
||||
|
@ -68,6 +70,13 @@ static t_opt optset[] = {
|
|||
{"keepalive", opt_set_keepalive},
|
||||
{"reuseaddr", opt_set_reuseaddr},
|
||||
{"linger", opt_set_linger},
|
||||
{"passcred", opt_set_passcred},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
static t_opt optget[] = {
|
||||
{"passcred", opt_get_passcred},
|
||||
{"peercred", opt_get_peercred},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
|
@ -130,6 +139,14 @@ static int meth_setoption(lua_State *L) {
|
|||
return opt_meth_setoption(L, optset, &un->sock);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* Just call option handler
|
||||
\*-------------------------------------------------------------------------*/
|
||||
static int meth_getoption(lua_State *L) {
|
||||
p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1);
|
||||
return opt_meth_getoption(L, optget, &un->sock);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* Select support methods
|
||||
\*-------------------------------------------------------------------------*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue