gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r32267 - in gnunet/src: testing transport util


From: gnunet
Subject: [GNUnet-SVN] r32267 - in gnunet/src: testing transport util
Date: Sun, 9 Feb 2014 22:54:56 +0100

Author: harsha
Date: 2014-02-09 22:54:56 +0100 (Sun, 09 Feb 2014)
New Revision: 32267

Modified:
   gnunet/src/testing/
   gnunet/src/transport/plugin_transport_unix.c
   gnunet/src/util/client.c
   gnunet/src/util/connection.c
   gnunet/src/util/network.c
   gnunet/src/util/service.c
   gnunet/src/util/util.conf
Log:
Create UNIX domain sockets as abstract sockets when running in LINUX and the
option USE_ABSTRACT_SOCKETS is present in configuration.


Index: gnunet/src/testing
===================================================================
--- gnunet/src/testing  2014-02-09 19:15:47 UTC (rev 32266)
+++ gnunet/src/testing  2014-02-09 21:54:56 UTC (rev 32267)

Property changes on: gnunet/src/testing
___________________________________________________________________
Modified: svn:ignore
## -1,3 +1,5 ##
+*.log
+*.trs
 topology_clique.dot
 testing_topo_initial
 final_topology.dot
Modified: gnunet/src/transport/plugin_transport_unix.c
===================================================================
--- gnunet/src/transport/plugin_transport_unix.c        2014-02-09 19:15:47 UTC 
(rev 32266)
+++ gnunet/src/transport/plugin_transport_unix.c        2014-02-09 21:54:56 UTC 
(rev 32267)
@@ -384,7 +384,8 @@
 
 
 static struct sockaddr_un *
-unix_address_to_sockaddr (const char *unixpath,
+unix_address_to_sockaddr (const struct GNUNET_CONFIGURATION_Handle *cfg,
+                          const char *unixpath,
                           socklen_t *sock_len)
 {
   struct sockaddr_un *un;
@@ -398,6 +399,17 @@
     slen = sizeof (un->sun_path) - 1;
   memcpy (un->sun_path, unixpath, slen);
   un->sun_path[slen] = '\0';
+#ifdef LINUX
+  {
+    int abstract;
+
+    abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg,
+                                                     "TESTING",
+                                                     "USE_ABSTRACT_SOCKETS");
+    if (GNUNET_YES == abstract)
+      un->sun_path[0] = '\0';
+  }
+#endif
   slen = sizeof (struct sockaddr_un);
 #if HAVE_SOCKADDR_IN_SIN_LEN
   un->sun_len = (u_char) slen;
@@ -633,7 +645,9 @@
 
   /* Prepare address */
   unixpath = (const char *)  &addr[1];
-  if (NULL == (un = unix_address_to_sockaddr (unixpath, &un_len)))
+  if (NULL == (un = unix_address_to_sockaddr (plugin->env->cfg,
+                                              unixpath,
+                                              &un_len)))
   {
     GNUNET_break (0);
     return -1;
@@ -1252,7 +1266,9 @@
   struct sockaddr_un *un;
   socklen_t un_len;
 
-  un = unix_address_to_sockaddr (plugin->unix_socket_path, &un_len);
+  un = unix_address_to_sockaddr (plugin->env->cfg,
+                                 plugin->unix_socket_path,
+                                 &un_len);
   plugin->ats_network = plugin->env->get_address_type (plugin->env->cls, 
(const struct sockaddr *) un, un_len);
   plugin->unix_sock.desc =
       GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0);

Modified: gnunet/src/util/client.c
===================================================================
--- gnunet/src/util/client.c    2014-02-09 19:15:47 UTC (rev 32266)
+++ gnunet/src/util/client.c    2014-02-09 21:54:56 UTC (rev 32267)
@@ -842,6 +842,7 @@
     /* probe UNIX support */
     struct sockaddr_un s_un;
     char *unixpath;
+    int abstract;
 
     unixpath = NULL;
     if ((GNUNET_OK ==
@@ -862,17 +863,29 @@
              _("Using `%s' instead\n"), unixpath);
       }
     }
-    if (NULL != unixpath)
+#ifdef LINUX
+    abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg,
+                                                     "TESTING",
+                                                     "USE_ABSTRACT_SOCKETS");
+#else
+    abstract = GNUNET_NO;
+#endif
+    if ((NULL != unixpath) && (GNUNET_YES != abstract))
     {
       if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (unixpath))
         GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
-            "mkdir", unixpath);
+                                  "mkdir", unixpath);
+    }
+    if (NULL != unixpath)
+    {
       sock = GNUNET_NETWORK_socket_create (PF_UNIX, SOCK_STREAM, 0);
       if (NULL != sock)
       {
        memset (&s_un, 0, sizeof (s_un));
        s_un.sun_family = AF_UNIX;
         strncpy (s_un.sun_path, unixpath, sizeof (s_un.sun_path) - 1);
+        if (GNUNET_YES == abstract)
+          s_un.sun_path[0] = '\0';
 #if HAVE_SOCKADDR_IN_SIN_LEN
         s_un.sun_len = (u_char) sizeof (struct sockaddr_un);
 #endif

Modified: gnunet/src/util/connection.c
===================================================================
--- gnunet/src/util/connection.c        2014-02-09 19:15:47 UTC (rev 32266)
+++ gnunet/src/util/connection.c        2014-02-09 21:54:56 UTC (rev 32267)
@@ -832,6 +832,16 @@
   un = GNUNET_new (struct sockaddr_un);
   un->sun_family = AF_UNIX;
   strncpy (un->sun_path, unixpath, sizeof (un->sun_path) - 1);
+#ifdef LINUX
+  {
+    int abstract;
+
+    abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, "TESTING",
+                                                     "USE_ABSTRACT_SOCKETS");
+    if (GNUNET_YES == abstract)
+      un->sun_path[0] = '\0';
+  }
+#endif
 #if HAVE_SOCKADDR_IN_SIN_LEN
   un->sun_len = (u_char) sizeof (struct sockaddr_un);
 #endif

Modified: gnunet/src/util/network.c
===================================================================
--- gnunet/src/util/network.c   2014-02-09 19:15:47 UTC (rev 32266)
+++ gnunet/src/util/network.c   2014-02-09 21:54:56 UTC (rev 32267)
@@ -420,17 +420,23 @@
 #endif
 #ifndef WINDOWS
   {
-    /* set permissions of newly created UNIX domain socket to "user-only"; 
applications
-       can choose to relax this later */
+    /* set permissions of newly created non-abstract UNIX domain socket to
+       "user-only"; applications can choose to relax this later */
     mode_t old_mask = 0; /* assigned to make compiler happy */
+    const struct sockaddr_un *un;
+    int not_abstract = 0;
 
-    if (AF_UNIX == address->sa_family)
+    if ((AF_UNIX == address->sa_family)
+        && (NULL != (un = (const struct sockaddr_un *) address)->sun_path)
+        && ('\0' != un->sun_path[0]) ) /* Not an abstract socket */
+      not_abstract = 1;
+    if (not_abstract)
       old_mask = umask (S_IWGRP | S_IRGRP | S_IXGRP | S_IWOTH | S_IROTH | 
S_IXOTH);
 #endif
 
     ret = bind (desc->fd, address, address_len);
 #ifndef WINDOWS
-    if (AF_UNIX == address->sa_family)
+    if (not_abstract)
       (void) umask (old_mask);
   }
 #endif
@@ -460,7 +466,7 @@
 {
   int ret;
 
-#ifdef MINGW
+#ifdef WINDOWS
   DWORD error = 0;
 
   SetLastError (0);
@@ -473,10 +479,15 @@
 #else
   ret = close (desc->fd);
 #endif
-#ifndef MINGW
-  if ((desc->af == AF_UNIX) && (NULL != desc->addr))
+#ifndef WINDOWS
+  const struct sockaddr_un *un;
+
+  /* Cleanup the UNIX domain socket and its parent directories in case of non
+     abstract sockets */
+  if ((AF_UNIX == desc->af) && (NULL != desc->addr)
+      && (NULL != (un = (const struct sockaddr_un *) desc->addr)->sun_path)
+      && ('\0' != un->sun_path[0]))
   {
-    const struct sockaddr_un *un = (const struct sockaddr_un *) desc->addr;
     char *dirname = GNUNET_strndup (un->sun_path,
                                     sizeof (un->sun_path));
 

Modified: gnunet/src/util/service.c
===================================================================
--- gnunet/src/util/service.c   2014-02-09 19:15:47 UTC (rev 32266)
+++ gnunet/src/util/service.c   2014-02-09 21:54:56 UTC (rev 32267)
@@ -475,10 +475,13 @@
  * @param saddrs array to update
  * @param saddrlens where to store the address length
  * @param unixpath path to add
+ * @param abstract GNUNET_YES to add an abstract UNIX domain socket.  This
+ *          parameter is ignore on systems other than LINUX
  */
 static void
 add_unixpath (struct sockaddr **saddrs, socklen_t * saddrlens,
-              const char *unixpath)
+              const char *unixpath,
+              int abstract)
 {
 #ifdef AF_UNIX
   struct sockaddr_un *un;
@@ -486,6 +489,10 @@
   un = GNUNET_new (struct sockaddr_un);
   un->sun_family = AF_UNIX;
   strncpy (un->sun_path, unixpath, sizeof (un->sun_path) - 1);
+#ifdef LINUX
+  if (GNUNET_YES == abstract)
+    un->sun_path[0] = '\0';
+#endif
 #if HAVE_SOCKADDR_IN_SIN_LEN
   un->sun_len = (u_char) sizeof (struct sockaddr_un);
 #endif
@@ -536,6 +543,7 @@
   unsigned int i;
   int resi;
   int ret;
+  int abstract;
   struct sockaddr **saddrs;
   socklen_t *saddrlens;
   char *hostname;
@@ -608,6 +616,7 @@
     hostname = NULL;
 
   unixpath = NULL;
+  abstract = GNUNET_NO;
 #ifdef AF_UNIX
   if ((GNUNET_YES ==
        GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) &&
@@ -628,8 +637,16 @@
       LOG (GNUNET_ERROR_TYPE_INFO,
           _("Using `%s' instead\n"), unixpath);
     }
-    if (GNUNET_OK !=
-       GNUNET_DISK_directory_create_for_file (unixpath))
+#ifdef LINUX
+    abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg,
+                                                     "TESTING",
+                                                     "USE_ABSTRACT_SOCKETS");
+    if (GNUNET_SYSERR == abstract)
+      abstract = GNUNET_NO;
+#endif
+    if ((GNUNET_YES != abstract)
+        && (GNUNET_OK !=
+            GNUNET_DISK_directory_create_for_file (unixpath)))
       GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
                                "mkdir",
                                unixpath);
@@ -673,7 +690,7 @@
   {
     saddrs = GNUNET_malloc (2 * sizeof (struct sockaddr *));
     saddrlens = GNUNET_malloc (2 * sizeof (socklen_t));
-    add_unixpath (saddrs, saddrlens, unixpath);
+    add_unixpath (saddrs, saddrlens, unixpath, abstract);
     GNUNET_free_non_null (unixpath);
     GNUNET_free_non_null (hostname);
     *addrs = saddrs;
@@ -725,7 +742,7 @@
     i = 0;
     if (NULL != unixpath)
     {
-      add_unixpath (saddrs, saddrlens, unixpath);
+      add_unixpath (saddrs, saddrlens, unixpath, abstract);
       i++;
     }
     next = res;
@@ -777,7 +794,7 @@
       saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
       if (NULL != unixpath)
       {
-        add_unixpath (saddrs, saddrlens, unixpath);
+        add_unixpath (saddrs, saddrlens, unixpath, abstract);
         i++;
       }
       saddrlens[i] = sizeof (struct sockaddr_in);
@@ -799,7 +816,7 @@
       i = 0;
       if (NULL != unixpath)
       {
-        add_unixpath (saddrs, saddrlens, unixpath);
+        add_unixpath (saddrs, saddrlens, unixpath, abstract);
         i++;
       }
       saddrlens[i] = sizeof (struct sockaddr_in6);
@@ -1168,7 +1185,8 @@
 #ifndef WINDOWS
   if (NULL != sctx->addrs)
     for (i = 0; NULL != sctx->addrs[i]; i++)
-      if (AF_UNIX == sctx->addrs[i]->sa_family)
+      if ((AF_UNIX == sctx->addrs[i]->sa_family)
+          && ('\0' != ((const struct sockaddr_un 
*)sctx->addrs[i])->sun_path[0]))
         GNUNET_DISK_fix_permissions (((const struct sockaddr_un 
*)sctx->addrs[i])->sun_path,
                                      sctx->match_uid,
                                      sctx->match_gid);
@@ -1589,7 +1607,8 @@
 #ifndef WINDOWS
   if (NULL != sctx->addrs)
     for (i = 0; NULL != sctx->addrs[i]; i++)
-      if (AF_UNIX == sctx->addrs[i]->sa_family)
+      if ((AF_UNIX == sctx->addrs[i]->sa_family)
+          && ('\0' != ((const struct sockaddr_un 
*)sctx->addrs[i])->sun_path[0]))
         GNUNET_DISK_fix_permissions (((const struct sockaddr_un 
*)sctx->addrs[i])->sun_path,
                                      sctx->match_uid,
                                      sctx->match_gid);

Modified: gnunet/src/util/util.conf
===================================================================
--- gnunet/src/util/util.conf   2014-02-09 19:15:47 UTC (rev 32266)
+++ gnunet/src/util/util.conf   2014-02-09 21:54:56 UTC (rev 32267)
@@ -49,3 +49,8 @@
 [TESTING]
 SPEEDUP_INTERVAL = 0 ms
 SPEEDUP_DELTA = 0 ms
+# This following option is applicable to LINUX.  Enabling this option causes 
all
+# UNIX domain sockets to be opened as abstract sockets.  Note that the
+# filesystem level restrictions no longer apply for abstract sockets.  An
+# end-user should not modify this option.
+USE_ABSTRACT_SOCKETS = NO




reply via email to

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