diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/client.c | 57 | ||||
-rw-r--r-- | src/util/network.c | 48 | ||||
-rw-r--r-- | src/util/service.c | 10 |
3 files changed, 79 insertions, 36 deletions
diff --git a/src/util/client.c b/src/util/client.c index c29b48e6b..d9be7f46e 100644 --- a/src/util/client.c +++ b/src/util/client.c | |||
@@ -738,40 +738,41 @@ GNUNET_CLIENT_service_test (const char *service, | |||
738 | { | 738 | { |
739 | LOG (GNUNET_ERROR_TYPE_WARNING, | 739 | LOG (GNUNET_ERROR_TYPE_WARNING, |
740 | _("UNIXPATH `%s' too long, maximum length is %llu\n"), unixpath, | 740 | _("UNIXPATH `%s' too long, maximum length is %llu\n"), unixpath, |
741 | sizeof (s_un.sun_path)); | 741 | (unsigned long long) sizeof (s_un.sun_path)); |
742 | unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath); | ||
742 | } | 743 | } |
743 | else | 744 | } |
745 | if (NULL != unixpath) | ||
746 | { | ||
747 | sock = GNUNET_NETWORK_socket_create (PF_UNIX, SOCK_STREAM, 0); | ||
748 | if (NULL != sock) | ||
744 | { | 749 | { |
745 | sock = GNUNET_NETWORK_socket_create (PF_UNIX, SOCK_STREAM, 0); | 750 | memset (&s_un, 0, sizeof (s_un)); |
746 | if (NULL != sock) | 751 | s_un.sun_family = AF_UNIX; |
747 | { | 752 | slen = strlen (unixpath) + 1; |
748 | memset (&s_un, 0, sizeof (s_un)); | 753 | if (slen >= sizeof (s_un.sun_path)) |
749 | s_un.sun_family = AF_UNIX; | 754 | slen = sizeof (s_un.sun_path) - 1; |
750 | slen = strlen (unixpath) + 1; | 755 | memcpy (s_un.sun_path, unixpath, slen); |
751 | if (slen >= sizeof (s_un.sun_path)) | 756 | s_un.sun_path[slen] = '\0'; |
752 | slen = sizeof (s_un.sun_path) - 1; | 757 | slen = sizeof (struct sockaddr_un); |
753 | memcpy (s_un.sun_path, unixpath, slen); | ||
754 | s_un.sun_path[slen] = '\0'; | ||
755 | slen = sizeof (struct sockaddr_un); | ||
756 | #if LINUX | 758 | #if LINUX |
757 | s_un.sun_path[0] = '\0'; | 759 | s_un.sun_path[0] = '\0'; |
758 | #endif | 760 | #endif |
759 | #if HAVE_SOCKADDR_IN_SIN_LEN | 761 | #if HAVE_SOCKADDR_IN_SIN_LEN |
760 | s_un.sun_len = (u_char) slen; | 762 | s_un.sun_len = (u_char) slen; |
761 | #endif | 763 | #endif |
762 | if (GNUNET_OK != | 764 | if (GNUNET_OK != |
763 | GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_un, | 765 | GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_un, |
764 | slen)) | 766 | slen)) |
765 | { | 767 | { |
766 | /* failed to bind => service must be running */ | 768 | /* failed to bind => service must be running */ |
767 | GNUNET_free (unixpath); | 769 | GNUNET_free (unixpath); |
768 | (void) GNUNET_NETWORK_socket_close (sock); | 770 | (void) GNUNET_NETWORK_socket_close (sock); |
769 | GNUNET_SCHEDULER_add_continuation (task, task_cls, | 771 | GNUNET_SCHEDULER_add_continuation (task, task_cls, |
770 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 772 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
771 | return; | 773 | return; |
772 | } | 774 | } |
773 | (void) GNUNET_NETWORK_socket_close (sock); | 775 | (void) GNUNET_NETWORK_socket_close (sock); |
774 | } | ||
775 | /* let's try IP */ | 776 | /* let's try IP */ |
776 | } | 777 | } |
777 | } | 778 | } |
diff --git a/src/util/network.c b/src/util/network.c index ed7e8be30..ca8105fc7 100644 --- a/src/util/network.c +++ b/src/util/network.c | |||
@@ -22,12 +22,11 @@ | |||
22 | * @file util/network.c | 22 | * @file util/network.c |
23 | * @brief basic, low-level networking interface | 23 | * @brief basic, low-level networking interface |
24 | * @author Nils Durner | 24 | * @author Nils Durner |
25 | * @author Christian Grothoff | ||
25 | */ | 26 | */ |
26 | |||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_disk_lib.h" | ||
29 | #include "disk.h" | 28 | #include "disk.h" |
30 | #include "gnunet_container_lib.h" | 29 | #include "gnunet_util_lib.h" |
31 | 30 | ||
32 | #define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__) | 31 | #define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__) |
33 | #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename) | 32 | #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename) |
@@ -67,6 +66,49 @@ struct GNUNET_NETWORK_Handle | |||
67 | }; | 66 | }; |
68 | 67 | ||
69 | 68 | ||
69 | /** | ||
70 | * Given a unixpath that is too long (larger than UNIX_PATH_MAX), | ||
71 | * shorten it to an acceptable length while keeping it unique | ||
72 | * and making sure it remains a valid filename (if possible). | ||
73 | * | ||
74 | * @param unixpath long path, will be freed (or same pointer returned | ||
75 | * with moved 0-termination). | ||
76 | * @return shortened unixpath, NULL on error | ||
77 | */ | ||
78 | char * | ||
79 | GNUNET_NETWORK_shorten_unixpath (char *unixpath) | ||
80 | { | ||
81 | struct sockaddr_un dummy; | ||
82 | size_t slen; | ||
83 | char *end; | ||
84 | struct GNUNET_CRYPTO_ShortHashCode sh; | ||
85 | struct GNUNET_CRYPTO_ShortHashAsciiEncoded ae; | ||
86 | size_t upm; | ||
87 | |||
88 | upm = sizeof (dummy.sun_path); | ||
89 | slen = strlen (unixpath); | ||
90 | if (slen < upm) | ||
91 | return unixpath; /* no shortening required */ | ||
92 | GNUNET_CRYPTO_short_hash (unixpath, slen, &sh); | ||
93 | while (sizeof (struct GNUNET_CRYPTO_ShortHashAsciiEncoded) + | ||
94 | strlen (unixpath) >= upm) | ||
95 | { | ||
96 | if (NULL == (end = strrchr (unixpath, '/'))) | ||
97 | { | ||
98 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
99 | _("Unable to shorten unix path `%s' while keeping name unique\n"), | ||
100 | unixpath); | ||
101 | GNUNET_free (unixpath); | ||
102 | return NULL; | ||
103 | } | ||
104 | *end = '\0'; | ||
105 | } | ||
106 | GNUNET_CRYPTO_short_hash_to_enc (&sh, &ae); | ||
107 | strcat (unixpath, (char*) ae.short_encoding); | ||
108 | return unixpath; | ||
109 | } | ||
110 | |||
111 | |||
70 | #ifndef FD_COPY | 112 | #ifndef FD_COPY |
71 | #define FD_COPY(s, d) (memcpy ((d), (s), sizeof (fd_set))) | 113 | #define FD_COPY(s, d) (memcpy ((d), (s), sizeof (fd_set))) |
72 | #endif | 114 | #endif |
diff --git a/src/util/service.c b/src/util/service.c index 2e75125ce..c9bbee3c8 100644 --- a/src/util/service.c +++ b/src/util/service.c | |||
@@ -973,12 +973,12 @@ GNUNET_SERVICE_get_server_addresses (const char *service_name, | |||
973 | { | 973 | { |
974 | LOG (GNUNET_ERROR_TYPE_WARNING, | 974 | LOG (GNUNET_ERROR_TYPE_WARNING, |
975 | _("UNIXPATH `%s' too long, maximum length is %llu\n"), unixpath, | 975 | _("UNIXPATH `%s' too long, maximum length is %llu\n"), unixpath, |
976 | sizeof (s_un.sun_path)); | 976 | (unsigned long long) sizeof (s_un.sun_path)); |
977 | GNUNET_free_non_null (hostname); | 977 | unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath); |
978 | GNUNET_free (unixpath); | ||
979 | return GNUNET_SYSERR; | ||
980 | } | 978 | } |
981 | 979 | } | |
980 | if (NULL != unixpath) | ||
981 | { | ||
982 | desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); | 982 | desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); |
983 | if (NULL == desc) | 983 | if (NULL == desc) |
984 | { | 984 | { |