poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[COMMITTED 2/2] poked: create `poked.ipc' socket with `umask (0077)'


From: Mohammad-Reza Nabipoor
Subject: [COMMITTED 2/2] poked: create `poked.ipc' socket with `umask (0077)'
Date: Wed, 1 Feb 2023 00:25:06 +0100

2023-01-31  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>

        * poked/usock.c (usock_new): use `umask' to create the unix
        socket with the right permissions.
---
 ChangeLog     | 6 ++++++
 poked/usock.c | 4 ++++
 2 files changed, 10 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index ca4c9fe6..c16acc79 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2023-01-31  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
+
+       * poked/usock.c: Include `<sys/stat.h>' for `umask'.
+       (usock_new): use `umask' to create the unix
+       socket with the right permissions.
+
 2023-01-31  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
 
        * poked/usock.c (usock_new): use `pipe2' instead of `pipe'.
diff --git a/poked/usock.c b/poked/usock.c
index aa50a169..02c75c3f 100644
--- a/poked/usock.c
+++ b/poked/usock.c
@@ -33,6 +33,7 @@
 #include <poll.h>
 #include <pthread.h>
 #include <sys/socket.h>
+#include <sys/stat.h>
 #include <sys/un.h>
 #include <unistd.h>
 
@@ -622,6 +623,7 @@ usock_new (const char *path)
   struct usock *u;
   struct sockaddr_un adr;
   int flags;
+  mode_t mask;
 
   u = calloc (1, sizeof (*u));
   if (u == NULL)
@@ -654,8 +656,10 @@ usock_new (const char *path)
   adr.sun_family = AF_UNIX;
   strncpy (adr.sun_path, path, sizeof (adr.sun_path) - 1);
   unlink (adr.sun_path);
+  mask = umask (0077);
   if (bind (u->fd, (struct sockaddr *)&adr, sizeof (adr)) == -1)
     goto error;
+  umask (mask);
   if (listen (u->fd, 128) == -1)
     goto error;
 
-- 
2.39.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]