aboutsummaryrefslogtreecommitdiff
path: root/src/util/service.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/service.c')
-rw-r--r--src/util/service.c37
1 files changed, 28 insertions, 9 deletions
diff --git a/src/util/service.c b/src/util/service.c
index c03247a6d..deb0be46b 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -475,10 +475,13 @@ process_acl6 (struct GNUNET_STRINGS_IPv6NetworkPolicy **ret, struct GNUNET_SERVI
475 * @param saddrs array to update 475 * @param saddrs array to update
476 * @param saddrlens where to store the address length 476 * @param saddrlens where to store the address length
477 * @param unixpath path to add 477 * @param unixpath path to add
478 * @param abstract GNUNET_YES to add an abstract UNIX domain socket. This
479 * parameter is ignore on systems other than LINUX
478 */ 480 */
479static void 481static void
480add_unixpath (struct sockaddr **saddrs, socklen_t * saddrlens, 482add_unixpath (struct sockaddr **saddrs, socklen_t * saddrlens,
481 const char *unixpath) 483 const char *unixpath,
484 int abstract)
482{ 485{
483#ifdef AF_UNIX 486#ifdef AF_UNIX
484 struct sockaddr_un *un; 487 struct sockaddr_un *un;
@@ -486,6 +489,10 @@ add_unixpath (struct sockaddr **saddrs, socklen_t * saddrlens,
486 un = GNUNET_new (struct sockaddr_un); 489 un = GNUNET_new (struct sockaddr_un);
487 un->sun_family = AF_UNIX; 490 un->sun_family = AF_UNIX;
488 strncpy (un->sun_path, unixpath, sizeof (un->sun_path) - 1); 491 strncpy (un->sun_path, unixpath, sizeof (un->sun_path) - 1);
492#ifdef LINUX
493 if (GNUNET_YES == abstract)
494 un->sun_path[0] = '\0';
495#endif
489#if HAVE_SOCKADDR_IN_SIN_LEN 496#if HAVE_SOCKADDR_IN_SIN_LEN
490 un->sun_len = (u_char) sizeof (struct sockaddr_un); 497 un->sun_len = (u_char) sizeof (struct sockaddr_un);
491#endif 498#endif
@@ -536,6 +543,7 @@ GNUNET_SERVICE_get_server_addresses (const char *service_name,
536 unsigned int i; 543 unsigned int i;
537 int resi; 544 int resi;
538 int ret; 545 int ret;
546 int abstract;
539 struct sockaddr **saddrs; 547 struct sockaddr **saddrs;
540 socklen_t *saddrlens; 548 socklen_t *saddrlens;
541 char *hostname; 549 char *hostname;
@@ -608,6 +616,7 @@ GNUNET_SERVICE_get_server_addresses (const char *service_name,
608 hostname = NULL; 616 hostname = NULL;
609 617
610 unixpath = NULL; 618 unixpath = NULL;
619 abstract = GNUNET_NO;
611#ifdef AF_UNIX 620#ifdef AF_UNIX
612 if ((GNUNET_YES == 621 if ((GNUNET_YES ==
613 GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) && 622 GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) &&
@@ -628,8 +637,16 @@ GNUNET_SERVICE_get_server_addresses (const char *service_name,
628 LOG (GNUNET_ERROR_TYPE_INFO, 637 LOG (GNUNET_ERROR_TYPE_INFO,
629 _("Using `%s' instead\n"), unixpath); 638 _("Using `%s' instead\n"), unixpath);
630 } 639 }
631 if (GNUNET_OK != 640#ifdef LINUX
632 GNUNET_DISK_directory_create_for_file (unixpath)) 641 abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg,
642 "TESTING",
643 "USE_ABSTRACT_SOCKETS");
644 if (GNUNET_SYSERR == abstract)
645 abstract = GNUNET_NO;
646#endif
647 if ((GNUNET_YES != abstract)
648 && (GNUNET_OK !=
649 GNUNET_DISK_directory_create_for_file (unixpath)))
633 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 650 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
634 "mkdir", 651 "mkdir",
635 unixpath); 652 unixpath);
@@ -673,7 +690,7 @@ GNUNET_SERVICE_get_server_addresses (const char *service_name,
673 { 690 {
674 saddrs = GNUNET_malloc (2 * sizeof (struct sockaddr *)); 691 saddrs = GNUNET_malloc (2 * sizeof (struct sockaddr *));
675 saddrlens = GNUNET_malloc (2 * sizeof (socklen_t)); 692 saddrlens = GNUNET_malloc (2 * sizeof (socklen_t));
676 add_unixpath (saddrs, saddrlens, unixpath); 693 add_unixpath (saddrs, saddrlens, unixpath, abstract);
677 GNUNET_free_non_null (unixpath); 694 GNUNET_free_non_null (unixpath);
678 GNUNET_free_non_null (hostname); 695 GNUNET_free_non_null (hostname);
679 *addrs = saddrs; 696 *addrs = saddrs;
@@ -725,7 +742,7 @@ GNUNET_SERVICE_get_server_addresses (const char *service_name,
725 i = 0; 742 i = 0;
726 if (NULL != unixpath) 743 if (NULL != unixpath)
727 { 744 {
728 add_unixpath (saddrs, saddrlens, unixpath); 745 add_unixpath (saddrs, saddrlens, unixpath, abstract);
729 i++; 746 i++;
730 } 747 }
731 next = res; 748 next = res;
@@ -777,7 +794,7 @@ GNUNET_SERVICE_get_server_addresses (const char *service_name,
777 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t)); 794 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
778 if (NULL != unixpath) 795 if (NULL != unixpath)
779 { 796 {
780 add_unixpath (saddrs, saddrlens, unixpath); 797 add_unixpath (saddrs, saddrlens, unixpath, abstract);
781 i++; 798 i++;
782 } 799 }
783 saddrlens[i] = sizeof (struct sockaddr_in); 800 saddrlens[i] = sizeof (struct sockaddr_in);
@@ -799,7 +816,7 @@ GNUNET_SERVICE_get_server_addresses (const char *service_name,
799 i = 0; 816 i = 0;
800 if (NULL != unixpath) 817 if (NULL != unixpath)
801 { 818 {
802 add_unixpath (saddrs, saddrlens, unixpath); 819 add_unixpath (saddrs, saddrlens, unixpath, abstract);
803 i++; 820 i++;
804 } 821 }
805 saddrlens[i] = sizeof (struct sockaddr_in6); 822 saddrlens[i] = sizeof (struct sockaddr_in6);
@@ -1168,7 +1185,8 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1168#ifndef WINDOWS 1185#ifndef WINDOWS
1169 if (NULL != sctx->addrs) 1186 if (NULL != sctx->addrs)
1170 for (i = 0; NULL != sctx->addrs[i]; i++) 1187 for (i = 0; NULL != sctx->addrs[i]; i++)
1171 if (AF_UNIX == sctx->addrs[i]->sa_family) 1188 if ((AF_UNIX == sctx->addrs[i]->sa_family)
1189 && ('\0' != ((const struct sockaddr_un *)sctx->addrs[i])->sun_path[0]))
1172 GNUNET_DISK_fix_permissions (((const struct sockaddr_un *)sctx->addrs[i])->sun_path, 1190 GNUNET_DISK_fix_permissions (((const struct sockaddr_un *)sctx->addrs[i])->sun_path,
1173 sctx->match_uid, 1191 sctx->match_uid,
1174 sctx->match_gid); 1192 sctx->match_gid);
@@ -1589,7 +1607,8 @@ GNUNET_SERVICE_start (const char *service_name,
1589#ifndef WINDOWS 1607#ifndef WINDOWS
1590 if (NULL != sctx->addrs) 1608 if (NULL != sctx->addrs)
1591 for (i = 0; NULL != sctx->addrs[i]; i++) 1609 for (i = 0; NULL != sctx->addrs[i]; i++)
1592 if (AF_UNIX == sctx->addrs[i]->sa_family) 1610 if ((AF_UNIX == sctx->addrs[i]->sa_family)
1611 && ('\0' != ((const struct sockaddr_un *)sctx->addrs[i])->sun_path[0]))
1593 GNUNET_DISK_fix_permissions (((const struct sockaddr_un *)sctx->addrs[i])->sun_path, 1612 GNUNET_DISK_fix_permissions (((const struct sockaddr_un *)sctx->addrs[i])->sun_path,
1594 sctx->match_uid, 1613 sctx->match_uid,
1595 sctx->match_gid); 1614 sctx->match_gid);