mirror of
https://github.com/troglobit/finit.git
synced 2026-11-21 19:51:46 +00:00
Protect API socket from unauthorized access
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
c3b7530b98
commit
1b6931eaea
1 file changed
+4
@@ -344,6 +344,7 @@ leave:
|
|||||||
int api_init(uev_ctx_t *ctx)
|
int api_init(uev_ctx_t *ctx)
|
||||||
{
|
{
|
||||||
int sd;
|
int sd;
|
||||||
|
mode_t oldmask;
|
||||||
struct sockaddr_un sun = {
|
struct sockaddr_un sun = {
|
||||||
.sun_family = AF_UNIX,
|
.sun_family = AF_UNIX,
|
||||||
.sun_path = INIT_SOCKET,
|
.sun_path = INIT_SOCKET,
|
||||||
@@ -356,17 +357,20 @@ int api_init(uev_ctx_t *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
erase(INIT_SOCKET);
|
erase(INIT_SOCKET);
|
||||||
|
oldmask = umask(0077);
|
||||||
if (-1 == bind(sd, (struct sockaddr*)&sun, sizeof(sun)))
|
if (-1 == bind(sd, (struct sockaddr*)&sun, sizeof(sun)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (-1 == listen(sd, 10))
|
if (-1 == listen(sd, 10))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
umask(oldmask);
|
||||||
if (!uev_io_init(ctx, &api_watcher, cb, NULL, sd, UEV_READ))
|
if (!uev_io_init(ctx, &api_watcher, cb, NULL, sd, UEV_READ))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
_pe("Failed intializing API socket");
|
_pe("Failed intializing API socket");
|
||||||
|
umask(oldmask);
|
||||||
close(sd);
|
close(sd);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user