diff options
Diffstat (limited to 'src')
49 files changed, 182 insertions, 117 deletions
diff --git a/src/arm/arm.conf.in b/src/arm/arm.conf.in index e9bf82e9f0..b9a33242f0 100644 --- a/src/arm/arm.conf.in +++ b/src/arm/arm.conf.in @@ -7,7 +7,7 @@ BINARY = gnunet-service-arm ACCEPT_FROM = 127.0.0.1; ACCEPT_FROM6 = ::1; DEFAULTSERVICES = topology hostlist dht nse mesh fs -UNIXPATH = $SERVICEHOME/gnunet-service-arm.sock +UNIXPATH = /tmp/gnunet-service-arm.sock UNIX_MATCH_UID = YES UNIX_MATCH_GID = YES diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c index ab1fe64818..906f0adde7 100644 --- a/src/arm/gnunet-service-arm.c +++ b/src/arm/gnunet-service-arm.c @@ -622,8 +622,8 @@ create_listen_socket (struct sockaddr *sa, socklen_t addr_len, "setsockopt"); #endif - if (GNUNET_OK != - GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) sa, addr_len)) + if (GNUNET_NETWORK_socket_bind + (sock, (const struct sockaddr *) sa, addr_len, 0) != GNUNET_OK) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ diff --git a/src/arm/test_exponential_backoff.c b/src/arm/test_exponential_backoff.c index 557e81ee54..08c4fd8ee8 100644 --- a/src/arm/test_exponential_backoff.c +++ b/src/arm/test_exponential_backoff.c @@ -42,7 +42,7 @@ #define BINARY "mockup-service" -#define CFGFILENAME "test_arm_api_data_copy.conf" +#define CFGFILENAME "test_arm_api_data2.conf" static const struct GNUNET_CONFIGURATION_Handle *cfg; diff --git a/src/ats/ats.conf.in b/src/ats/ats.conf.in index f911c0bcf8..457e86c656 100644 --- a/src/ats/ats.conf.in +++ b/src/ats/ats.conf.in @@ -6,7 +6,7 @@ HOME = $SERVICEHOME BINARY = gnunet-service-ats ACCEPT_FROM = 127.0.0.1; ACCEPT_FROM6 = ::1; -UNIXPATH = $SERVICEHOME/gnunet-service-ats.sock +UNIXPATH = /tmp/gnunet-service-ats.sock UNIX_MATCH_UID = YES UNIX_MATCH_GID = YES diff --git a/src/consensus/consensus.conf.in b/src/consensus/consensus.conf.in index c91a0be49d..18e976deb9 100644 --- a/src/consensus/consensus.conf.in +++ b/src/consensus/consensus.conf.in @@ -6,6 +6,6 @@ HOME = $SERVICEHOME BINARY = gnunet-service-consensus ACCEPT_FROM = 127.0.0.1; ACCEPT_FROM6 = ::1; -UNIXPATH = $SERVICEHOME/gnunet-service-consensus.sock +UNIXPATH = /tmp/gnunet-service-consensus.sock UNIX_MATCH_UID = YES UNIX_MATCH_GID = YES diff --git a/src/core/core.conf.in b/src/core/core.conf.in index e1e5f5b6f2..839c21eeb3 100644 --- a/src/core/core.conf.in +++ b/src/core/core.conf.in @@ -6,7 +6,7 @@ HOME = $SERVICEHOME BINARY = gnunet-service-core ACCEPT_FROM = 127.0.0.1; ACCEPT_FROM6 = ::1; -UNIXPATH = $SERVICEHOME/gnunet-service-core.sock +UNIXPATH = /tmp/gnunet-service-core.sock UNIX_MATCH_UID = YES UNIX_MATCH_GID = YES # DISABLE_SOCKET_FORWARDING = NO diff --git a/src/datastore/datastore.conf.in b/src/datastore/datastore.conf.in index f996ce5594..7a92070d7e 100644 --- a/src/datastore/datastore.conf.in +++ b/src/datastore/datastore.conf.in @@ -1,6 +1,6 @@ [datastore] AUTOSTART = YES -UNIXPATH = $SERVICEHOME/gnunet-service-datastore.sock +UNIXPATH = /tmp/gnunet-service-datastore.sock UNIX_MATCH_UID = NO UNIX_MATCH_GID = YES @UNIXONLY@ PORT = 2093 diff --git a/src/dht/dht.conf.in b/src/dht/dht.conf.in index 38c04a182a..59c5bc1b7c 100644 --- a/src/dht/dht.conf.in +++ b/src/dht/dht.conf.in @@ -7,7 +7,7 @@ BINARY = gnunet-service-dht ACCEPT_FROM = 127.0.0.1; ACCEPT_FROM6 = ::1; BUCKET_SIZE = 4 -UNIXPATH = $SERVICEHOME/gnunet-service-dht.sock +UNIXPATH = /tmp/gnunet-service-dht.sock # This could be relaxed... UNIX_MATCH_UID = YES UNIX_MATCH_GID = YES diff --git a/src/dns/dns.conf.in b/src/dns/dns.conf.in index a1282b3ed7..7944b410a3 100644 --- a/src/dns/dns.conf.in +++ b/src/dns/dns.conf.in @@ -3,7 +3,7 @@ AUTOSTART = YES HOSTNAME = localhost HOME = $SERVICEHOME BINARY = gnunet-service-dns -UNIXPATH = $SERVICEHOME/gnunet-service-dns.sock +UNIXPATH = /tmp/gnunet-service-dns.sock # Access to this service can compromise all DNS queries in this # system. Thus access should be restricted to the same UID. diff --git a/src/dns/dnsstub.c b/src/dns/dnsstub.c index caf90f3d29..0e130a77ff 100644 --- a/src/dns/dnsstub.c +++ b/src/dns/dnsstub.c @@ -167,11 +167,11 @@ open_socket (int af) return NULL; } sa->sa_family = af; - if (GNUNET_OK != - GNUNET_NETWORK_socket_bind (ret, - sa, - alen)) - { + if (GNUNET_OK != GNUNET_NETWORK_socket_bind (ret, + sa, + alen, + 0)) + { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not bind to any port: %s\n"), STRERROR (errno)); diff --git a/src/dv/dv.conf.in b/src/dv/dv.conf.in index 70b9cfd556..c0dc21bfd3 100644 --- a/src/dv/dv.conf.in +++ b/src/dv/dv.conf.in @@ -6,7 +6,7 @@ BINARY = gnunet-service-dv HOME = $SERVICEHOME HOSTNAME = localhost @UNIXONLY@ PORT = 2571 -UNIXPATH = $SERVICEHOME/gnunet-service-dv.sock +UNIXPATH = /tmp/gnunet-service-dv.sock UNIX_MATCH_UID = YES UNIX_MATCH_GID = YES # ACCEPT_FROM = diff --git a/src/experimentation/experimentation.conf.in b/src/experimentation/experimentation.conf.in index c06e54dd49..6597dd0c17 100644 --- a/src/experimentation/experimentation.conf.in +++ b/src/experimentation/experimentation.conf.in @@ -6,7 +6,7 @@ HOME = $SERVICEHOME BINARY = gnunet-daemon-experimentation ACCEPT_FROM = 127.0.0.1; ACCEPT_FROM6 = ::1; -UNIXPATH = $SERVICEHOME/gnunet-daemon-experimentation.sock +UNIXPATH = /tmp/gnunet-daemon-experimentation.sock UNIX_MATCH_UID = YES UNIX_MATCH_GID = YES ISSUERS = TFRM29O2RQNKLVBQIGODJ6GD58LSQ2NM9TNFBC6N48BRJHQO38Q73N2OM3V4CLKDM6CILQV4CU8PMJDRG0FNB0PDI057DBRANMLPLRG
\ No newline at end of file diff --git a/src/fs/fs.conf.in b/src/fs/fs.conf.in index ef98272f6c..2375dc7ec2 100644 --- a/src/fs/fs.conf.in +++ b/src/fs/fs.conf.in @@ -22,7 +22,7 @@ CONTENT_CACHING = YES # (may improve anonymity, probably not a good idea if content_caching is NO) CONTENT_PUSHING = YES -UNIXPATH = $SERVICEHOME/gnunet-service-fs.sock +UNIXPATH = /tmp/gnunet-service-fs.sock # Do we require users that want to access file-sharing to run this process # (usually not a good idea) diff --git a/src/gns/gns.conf.in b/src/gns/gns.conf.in index 53da718f56..91fd822f80 100644 --- a/src/gns/gns.conf.in +++ b/src/gns/gns.conf.in @@ -3,7 +3,7 @@ AUTOSTART = YES HOSTNAME = localhost HOME = $SERVICEHOME BINARY = gnunet-service-gns -UNIXPATH = $SERVICEHOME/gnunet-service-gns.sock +UNIXPATH = /tmp/gnunet-service-gns.sock @UNIXONLY@PORT = 2102 ZONE_DIR = $SERVICEHOME/gns/ @@ -32,7 +32,7 @@ AUTOSTART = NO # Where is the certificate for the GNS proxy stored? PROXY_CACERT = $SERVICEHOME/gns/gnsCAcert.pem -PROXY_UNIXPATH = $SERVICEHOME/gnunet-gns-proxy.sock +PROXY_UNIXPATH = /tmp/gnunet-gns-proxy.sock [fcfsd] diff --git a/src/gns/gnunet-dns2gns.c b/src/gns/gnunet-dns2gns.c index f22cba0d7e..8bbf22c46d 100644 --- a/src/gns/gnunet-dns2gns.c +++ b/src/gns/gnunet-dns2gns.c @@ -616,7 +616,8 @@ run_dnsd () if (GNUNET_OK != GNUNET_NETWORK_socket_bind (listen_socket4, (struct sockaddr *) &v4, - sizeof (v4))) + sizeof (v4), + 0)) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); GNUNET_NETWORK_socket_close (listen_socket4); @@ -639,7 +640,8 @@ run_dnsd () if (GNUNET_OK != GNUNET_NETWORK_socket_bind (listen_socket6, (struct sockaddr *) &v6, - sizeof (v6))) + sizeof (v6), + 0)) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); GNUNET_NETWORK_socket_close (listen_socket6); diff --git a/src/identity/identity.conf.in b/src/identity/identity.conf.in index d069126817..671e5f2f10 100644 --- a/src/identity/identity.conf.in +++ b/src/identity/identity.conf.in @@ -6,7 +6,7 @@ HOME = $SERVICEHOME BINARY = gnunet-service-identity ACCEPT_FROM = 127.0.0.1; ACCEPT_FROM6 = ::1; -UNIXPATH = $SERVICEHOME/gnunet-service-identity.unix +UNIXPATH = /tmp/gnunet-service-identity.unix UNIX_MATCH_UID = NO UNIX_MATCH_GID = YES diff --git a/src/include/gnunet_network_lib.h b/src/include/gnunet_network_lib.h index 55d0a3d7b0..e2ebd450ef 100644 --- a/src/include/gnunet_network_lib.h +++ b/src/include/gnunet_network_lib.h @@ -132,17 +132,25 @@ GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, /** + * Fail to bind if an address is already in use. + */ +#define GNUNET_BIND_EXCLUSIVE 0x01 + + +/** * Bind a socket to a particular address. * * @param desc socket to bind * @param address address to be bound * @param address_len length of address + * @param flags flags affecting bind behaviour * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise */ int GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, - socklen_t address_len); + socklen_t address_len, + int flags); /** * Close a socket. diff --git a/src/lockmanager/lockmanager.conf.in b/src/lockmanager/lockmanager.conf.in index 1fee355e2c..42d5743244 100644 --- a/src/lockmanager/lockmanager.conf.in +++ b/src/lockmanager/lockmanager.conf.in @@ -6,7 +6,7 @@ HOME = $SERVICEHOME BINARY = gnunet-service-lockmanager ACCEPT_FROM = 127.0.0.1; ACCEPT_FROM6 = ::1; -UNIXPATH = $SERVICEHOME/gnunet-service-lockmanager.sock +UNIXPATH = /tmp/gnunet-service-lockmanager.sock UNIX_MATCH_UID = YES UNIX_MATCH_GID = YES diff --git a/src/mesh/mesh.conf.in b/src/mesh/mesh.conf.in index aaa337a98f..504e2ecb15 100644 --- a/src/mesh/mesh.conf.in +++ b/src/mesh/mesh.conf.in @@ -6,7 +6,7 @@ HOME = $SERVICEHOME BINARY = gnunet-service-mesh ACCEPT_FROM = 127.0.0.1; ACCEPT_FROM6 = ::1; -UNIXPATH = $SERVICEHOME/gnunet-service-mesh.sock +UNIXPATH = /tmp/gnunet-service-mesh.sock UNIX_MATCH_UID = YES UNIX_MATCH_GID = YES REFRESH_CONNECTION_TIME = 5 min diff --git a/src/multicast/multicast.conf.in b/src/multicast/multicast.conf.in index 8a19450ab4..bd37cb4749 100644 --- a/src/multicast/multicast.conf.in +++ b/src/multicast/multicast.conf.in @@ -6,7 +6,7 @@ HOME = $SERVICEHOME BINARY = gnunet-service-multicast ACCEPT_FROM = 127.0.0.1; ACCEPT_FROM6 = ::1; -UNIXPATH = $SERVICEHOME/gnunet-service-multicast.sock +UNIXPATH = /tmp/gnunet-service-multicast.sock UNIX_MATCH_UID = YES UNIX_MATCH_GID = YES # DISABLE_SOCKET_FORWARDING = NO diff --git a/src/namestore/namestore.conf.in b/src/namestore/namestore.conf.in index 8c4b714143..18a37f0da1 100644 --- a/src/namestore/namestore.conf.in +++ b/src/namestore/namestore.conf.in @@ -1,6 +1,6 @@ [namestore] AUTOSTART = YES -UNIXPATH = $SERVICEHOME/gnunet-service-namestore.sock +UNIXPATH = /tmp/gnunet-service-namestore.sock UNIX_MATCH_UID = NO UNIX_MATCH_GID = YES @UNIXONLY@ PORT = 2099 diff --git a/src/nat/nat_test.c b/src/nat/nat_test.c index 387a68d8f7..0c1d59a87d 100644 --- a/src/nat/nat_test.c +++ b/src/nat/nat_test.c @@ -404,7 +404,7 @@ GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, if ((ret->lsock == NULL) || (GNUNET_OK != GNUNET_NETWORK_socket_bind (ret->lsock, (const struct sockaddr *) &sa, - sizeof (sa)))) + sizeof (sa), 0))) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ diff --git a/src/nse/nse.conf.in b/src/nse/nse.conf.in index f613b51d29..c96830c426 100644 --- a/src/nse/nse.conf.in +++ b/src/nse/nse.conf.in @@ -6,7 +6,7 @@ HOME = $SERVICEHOME BINARY = gnunet-service-nse ACCEPT_FROM = 127.0.0.1; ACCEPT_FROM6 = ::1; -UNIXPATH = $SERVICEHOME/gnunet-service-nse.unix +UNIXPATH = /tmp/gnunet-service-nse.unix UNIX_MATCH_UID = NO UNIX_MATCH_GID = YES PROOFFILE = $SERVICEHOME/.nse-proof diff --git a/src/peerinfo/peerinfo.conf.in b/src/peerinfo/peerinfo.conf.in index 0fba5cfde4..11302211de 100644 --- a/src/peerinfo/peerinfo.conf.in +++ b/src/peerinfo/peerinfo.conf.in @@ -6,7 +6,7 @@ HOME = $SERVICEHOME BINARY = gnunet-service-peerinfo ACCEPT_FROM = 127.0.0.1; ACCEPT_FROM6 = ::1; -UNIXPATH = $SERVICEHOME/gnunet-service-peerinfo.sock +UNIXPATH = /tmp/gnunet-service-peerinfo.sock UNIX_MATCH_UID = NO UNIX_MATCH_GID = YES # DISABLE_SOCKET_FORWARDING = NO diff --git a/src/psyc/psyc.conf.in b/src/psyc/psyc.conf.in index ad8403a95a..5a1eebf61f 100644 --- a/src/psyc/psyc.conf.in +++ b/src/psyc/psyc.conf.in @@ -2,6 +2,6 @@ AUTOSTART = YES HOME = $SERVICEHOME BINARY = gnunet-service-psyc -UNIXPATH = $SERVICEHOME/gnunet-service-psyc.sock +UNIXPATH = /tmp/gnunet-service-psyc.sock UNIX_MATCH_UID = NO UNIX_MATCH_GID = YES diff --git a/src/psycstore/psycstore.conf.in b/src/psycstore/psycstore.conf.in index 21bfef3284..c43c5158e8 100644 --- a/src/psycstore/psycstore.conf.in +++ b/src/psycstore/psycstore.conf.in @@ -2,7 +2,7 @@ AUTOSTART = YES HOME = $SERVICEHOME BINARY = gnunet-service-psycstore -UNIXPATH = $SERVICEHOME/gnunet-service-psycstore.sock +UNIXPATH = /tmp/gnunet-service-psycstore.sock @UNIXONLY@PORT = 2111 UNIX_MATCH_UID = NO UNIX_MATCH_GID = YES diff --git a/src/regex/regex.conf.in b/src/regex/regex.conf.in index ad4dbaf088..2ff48c5aef 100644 --- a/src/regex/regex.conf.in +++ b/src/regex/regex.conf.in @@ -1,7 +1,7 @@ [regex] AUTOSTART = YES @UNIXONLY@ PORT = 2107 -UNIXPATH = $SERVICEHOME/gnunet-service-regex.sock +UNIXPATH = /tmp/gnunet-service-regex.sock HOSTNAME = localhost HOME = $SERVICEHOME BINARY = gnunet-service-regex diff --git a/src/scalarproduct/scalarproduct.conf.in b/src/scalarproduct/scalarproduct.conf.in index 05f23aa957..e47af6f6a0 100644 --- a/src/scalarproduct/scalarproduct.conf.in +++ b/src/scalarproduct/scalarproduct.conf.in @@ -1,6 +1,6 @@ [vectorproduct] BINARY = gnunet-service-vectorproduct -UNIXPATH = $SERVICEHOME/gnunet-service-vectorproduct.sock +UNIXPATH = /tmp/gnunet-service-vectorproduct.sock HOME = $SERVICEHOME # PORT = 2106 @UNIXONLY@ PORT = 2087 diff --git a/src/set/set.conf.in b/src/set/set.conf.in index fda94a5350..2dc1c21d2f 100644 --- a/src/set/set.conf.in +++ b/src/set/set.conf.in @@ -6,6 +6,6 @@ HOME = $SERVICEHOME BINARY = gnunet-service-set ACCEPT_FROM = 127.0.0.1; ACCEPT_FROM6 = ::1; -UNIXPATH = $SERVICEHOME/gnunet-service-set.sock +UNIXPATH = /tmp/gnunet-service-set.sock UNIX_MATCH_UID = YES UNIX_MATCH_GID = YES diff --git a/src/statistics/statistics.conf.in b/src/statistics/statistics.conf.in index 3d2294d377..669e89bd76 100644 --- a/src/statistics/statistics.conf.in +++ b/src/statistics/statistics.conf.in @@ -6,7 +6,7 @@ HOME = $SERVICEHOME BINARY = gnunet-service-statistics ACCEPT_FROM = 127.0.0.1; ACCEPT_FROM6 = ::1; -UNIXPATH = $SERVICEHOME/gnunet-service-statistics.sock +UNIXPATH = /tmp/gnunet-service-statistics.sock UNIX_MATCH_UID = NO UNIX_MATCH_GID = YES # DISABLE_SOCKET_FORWARDING = NO diff --git a/src/testbed/testbed.conf.in b/src/testbed/testbed.conf.in index fba0a12286..40bdae16d0 100644 --- a/src/testbed/testbed.conf.in +++ b/src/testbed/testbed.conf.in @@ -19,7 +19,7 @@ OPERATION_TIMEOUT = 30 s ACCEPT_FROM = 127.0.0.1; ACCEPT_FROM6 = ::1; -UNIXPATH = $SERVICEHOME/gnunet-service-testbed.sock +UNIXPATH = /tmp/gnunet-service-testbed.sock UNIX_MATCH_UID = YES UNIX_MATCH_GID = YES @@ -88,7 +88,7 @@ AUTOSTART = NO @UNIXONLY@ PORT = 2102 HOSTNAME = localhost BINARY = gnunet-service-testbed-logger -UNIXPATH = $SERVICEHOME/gnunet-gnunet-testbed-logger.sock +UNIXPATH = /tmp/gnunet-gnunet-testbed-logger.sock DIR = /tmp UNIX_MATCH_UID = YES UNIX_MATCH_GID = YES @@ -98,6 +98,6 @@ UNIX_MATCH_GID = YES AUTOSTART = NO @UNIXONLY@ PORT = 2103 HOSTNAME = localhost -UNIXPATH = $SERVICEHOME/gnunet-service-testbed-barrier.sock +UNIXPATH = /tmp/gnunet-service-testbed-barrier.sock UNIX_MATCH_UID = YES UNIX_MATCH_GID = YES diff --git a/src/testing/testing.c b/src/testing/testing.c index 7f5154a4c5..8502809f3a 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c @@ -619,7 +619,8 @@ GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system) continue; bind_status = GNUNET_NETWORK_socket_bind (socket, ai->ai_addr, - ai->ai_addrlen); + ai->ai_addrlen, + 0); GNUNET_NETWORK_socket_close (socket); if (GNUNET_OK != bind_status) break; @@ -628,7 +629,8 @@ GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system) continue; bind_status = GNUNET_NETWORK_socket_bind (socket, ai->ai_addr, - ai->ai_addrlen); + ai->ai_addrlen, + 0); GNUNET_NETWORK_socket_close (socket); if (GNUNET_OK != bind_status) break; diff --git a/src/transport/gnunet-helper-transport-bluetooth.c b/src/transport/gnunet-helper-transport-bluetooth.c index f123039825..43eccf0aa8 100644 --- a/src/transport/gnunet-helper-transport-bluetooth.c +++ b/src/transport/gnunet-helper-transport-bluetooth.c @@ -1070,7 +1070,6 @@ read_from_the_socket (void *sock, return count; } - /** * Open the bluetooth interface for reading/writing * @@ -1088,8 +1087,7 @@ open_device (struct HardwareInfos *dev) addr.btAddr = 0; addr.port = BT_PORT_ANY; - if (GNUNET_OK != - GNUNET_NETWORK_socket_bind (dev->handle, (const SOCKADDR*)&addr, sizeof (SOCKADDR_BTH))) + if (GNUNET_NETWORK_socket_bind (dev->handle, (const SOCKADDR*)&addr, sizeof (SOCKADDR_BTH), 0) != GNUNET_OK) { fprintf (stderr, "Failed to bind the socket: "); if (GetLastError() == WSAENETDOWN) diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index eb3d92163d..bc64fd5d25 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c @@ -2808,7 +2808,7 @@ setup_sockets (struct Plugin *plugin, GNUNET_a2s (serverAddr, addrlen)); /* binding */ if (GNUNET_OK == GNUNET_NETWORK_socket_bind (plugin->sockv6, - serverAddr, addrlen)) + serverAddr, addrlen, 0)) break; eno = errno; if (0 != plugin->port) @@ -2885,7 +2885,7 @@ setup_sockets (struct Plugin *plugin, /* binding */ if (GNUNET_OK == GNUNET_NETWORK_socket_bind (plugin->sockv4, - serverAddr, addrlen)) + serverAddr, addrlen, 0)) break; eno = errno; if (0 != plugin->port) diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c index 4e30387871..2087d30e5a 100644 --- a/src/transport/plugin_transport_unix.c +++ b/src/transport/plugin_transport_unix.c @@ -572,6 +572,7 @@ unix_real_send (void *cls, const void *sb; size_t sbs; struct sockaddr_un un; + size_t slen; const char *unix_path; @@ -591,12 +592,21 @@ unix_real_send (void *cls, unix_path = (const char *) &addr[1]; memset (&un, 0, sizeof (un)); un.sun_family = AF_UNIX; - strncpy (un.sun_path, unix_path, sizeof (un.sun_path) - 1); + slen = strlen (unix_path); + if (slen >= sizeof (un.sun_path)) + slen = sizeof (un.sun_path) - 1; + GNUNET_assert (slen < sizeof (un.sun_path)); + memcpy (un.sun_path, unix_path, slen); + un.sun_path[slen] = '\0'; + slen = sizeof (struct sockaddr_un); +#if LINUX + un.sun_path[0] = '\0'; +#endif #if HAVE_SOCKADDR_IN_SIN_LEN - un.sun_len = (u_char) sizeof (struct sockaddr_un); + un.sun_len = (u_char) slen; #endif sb = (struct sockaddr *) &un; - sbs = sizeof (struct sockaddr_un); + sbs = slen; resend: /* Send the data */ @@ -1013,18 +1023,19 @@ unix_plugin_select_read (struct Plugin *plugin) } else { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Read %d bytes from socket %s\n", - (int) ret, - un.sun_path); +#if LINUX + un.sun_path[0] = '/'; +#endif + LOG (GNUNET_ERROR_TYPE_DEBUG, "Read %d bytes from socket %s\n", ret, + &un.sun_path[0]); } GNUNET_assert (AF_UNIX == (un.sun_family)); - ua_len = sizeof (struct UnixAddress) + strlen (un.sun_path) + 1; + ua_len = sizeof (struct UnixAddress) + strlen (&un.sun_path[0]) +1; ua = GNUNET_malloc (ua_len); ua->addrlen = htonl (strlen (&un.sun_path[0]) +1); ua->options = htonl (0); - memcpy (&ua[1], &un.sun_path[0], strlen (un.sun_path) + 1); + memcpy (&ua[1], &un.sun_path[0], strlen (&un.sun_path[0]) +1); msg = (struct UNIXMessage *) buf; csize = ntohs (msg->header.size); @@ -1203,7 +1214,7 @@ unix_plugin_select (void *cls, * Create a slew of UNIX sockets. If possible, use IPv6 and IPv4. * * @param cls closure for server start, should be a struct Plugin * - * @return number of sockets created or #GNUNET_SYSERR on error + * @return number of sockets created or GNUNET_SYSERR on error */ static int unix_transport_server_start (void *cls) @@ -1212,16 +1223,26 @@ unix_transport_server_start (void *cls) struct sockaddr *serverAddr; socklen_t addrlen; struct sockaddr_un un; + size_t slen; memset (&un, 0, sizeof (un)); un.sun_family = AF_UNIX; - strncpy (un.sun_path, plugin->unix_socket_path, sizeof (un.sun_path) - 1); + slen = strlen (plugin->unix_socket_path) + 1; + if (slen >= sizeof (un.sun_path)) + slen = sizeof (un.sun_path) - 1; + + memcpy (un.sun_path, plugin->unix_socket_path, slen); + un.sun_path[slen] = '\0'; + slen = sizeof (struct sockaddr_un); #if HAVE_SOCKADDR_IN_SIN_LEN - un.sun_len = (u_char) sizeof (struct sockaddr_un); + un.sun_len = (u_char) slen; #endif serverAddr = (struct sockaddr *) &un; - addrlen = sizeof (struct sockaddr_un); + addrlen = slen; +#if LINUX + un.sun_path[0] = '\0'; +#endif plugin->ats_network = plugin->env->get_address_type (plugin->env->cls, serverAddr, addrlen); plugin->unix_sock.desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0); @@ -1230,8 +1251,8 @@ unix_transport_server_start (void *cls) GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); return GNUNET_SYSERR; } - if (GNUNET_OK != - GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc, serverAddr, addrlen)) + if (GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc, serverAddr, addrlen, 0) + != GNUNET_OK) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); GNUNET_NETWORK_socket_close (plugin->unix_sock.desc); diff --git a/src/transport/transport.conf.in b/src/transport/transport.conf.in index d33fa99fe4..fd8b5dbbbe 100644 --- a/src/transport/transport.conf.in +++ b/src/transport/transport.conf.in @@ -9,7 +9,7 @@ NEIGHBOUR_LIMIT = 50 ACCEPT_FROM = 127.0.0.1; ACCEPT_FROM6 = ::1; PLUGINS = tcp udp -UNIXPATH = $SERVICEHOME/gnunet-service-transport.sock +UNIXPATH = /tmp/gnunet-service-transport.sock BLACKLIST_FILE = $SERVICEHOME/blacklist UNIX_MATCH_UID = NO UNIX_MATCH_GID = YES diff --git a/src/util/client.c b/src/util/client.c index 64960f232f..30c80bf032 100644 --- a/src/util/client.c +++ b/src/util/client.c @@ -251,9 +251,7 @@ try_unixpath (const char *service_name, struct sockaddr_un s_un; unixpath = NULL; - if ((GNUNET_OK == - GNUNET_CONFIGURATION_get_value_filename (cfg, service_name, - "UNIXPATH", &unixpath)) && + if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "UNIXPATH", &unixpath)) && (0 < strlen (unixpath))) { /* We have a non-NULL unixpath, need to validate it */ @@ -301,8 +299,7 @@ test_service_configuration (const char *service_name, #if AF_UNIX char *unixpath = NULL; - if ((GNUNET_OK == - GNUNET_CONFIGURATION_get_value_filename (cfg, service_name, "UNIXPATH", &unixpath)) && + if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "UNIXPATH", &unixpath)) && (0 < strlen (unixpath))) ret = GNUNET_OK; GNUNET_free_non_null (unixpath); @@ -832,12 +829,11 @@ GNUNET_CLIENT_service_test (const char *service, { /* probe UNIX support */ struct sockaddr_un s_un; + size_t slen; char *unixpath; unixpath = NULL; - if ((GNUNET_OK == - GNUNET_CONFIGURATION_get_value_filename (cfg, service, "UNIXPATH", &unixpath)) && - (0 < strlen (unixpath))) /* We have a non-NULL unixpath, does that mean it's valid? */ + if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, service, "UNIXPATH", &unixpath)) && (0 < strlen (unixpath))) /* We have a non-NULL unixpath, does that mean it's valid? */ { if (strlen (unixpath) >= sizeof (s_un.sun_path)) { @@ -856,13 +852,21 @@ GNUNET_CLIENT_service_test (const char *service, { 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); + slen = strlen (unixpath) + 1; + if (slen >= sizeof (s_un.sun_path)) + slen = sizeof (s_un.sun_path) - 1; + memcpy (s_un.sun_path, unixpath, slen); + s_un.sun_path[slen] = '\0'; + slen = sizeof (struct sockaddr_un); +#if LINUX + s_un.sun_path[0] = '\0'; +#endif #if HAVE_SOCKADDR_IN_SIN_LEN - s_un.sun_len = (u_char) sizeof (struct sockaddr_un); + s_un.sun_len = (u_char) slen; #endif if (GNUNET_OK != GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_un, - sizeof (struct sockaddr_un))) + slen, GNUNET_BIND_EXCLUSIVE)) { /* failed to bind => service must be running */ GNUNET_free (unixpath); @@ -912,7 +916,7 @@ GNUNET_CLIENT_service_test (const char *service, { if (GNUNET_OK != GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_in, - sizeof (s_in))) + sizeof (s_in), GNUNET_BIND_EXCLUSIVE)) { /* failed to bind => service must be running */ GNUNET_free (hostname); @@ -945,7 +949,7 @@ GNUNET_CLIENT_service_test (const char *service, { if (GNUNET_OK != GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_in6, - sizeof (s_in6))) + sizeof (s_in6), GNUNET_BIND_EXCLUSIVE)) { /* failed to bind => service must be running */ GNUNET_free (hostname); diff --git a/src/util/connection.c b/src/util/connection.c index c8d9919ea4..3290abcfc3 100644 --- a/src/util/connection.c +++ b/src/util/connection.c @@ -828,13 +828,22 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct #ifdef AF_UNIX struct GNUNET_CONNECTION_Handle *connection; struct sockaddr_un *un; + size_t slen; GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ un = GNUNET_new (struct sockaddr_un); un->sun_family = AF_UNIX; - strncpy(un->sun_path, unixpath, sizeof(un->sun_path) - 1); + slen = strlen (unixpath); + if (slen >= sizeof (un->sun_path)) + slen = sizeof (un->sun_path) - 1; + memcpy (un->sun_path, unixpath, slen); + un->sun_path[slen] = '\0'; + slen = sizeof (struct sockaddr_un); #if HAVE_SOCKADDR_IN_SIN_LEN - un->sun_len = (u_char) sizeof (struct sockaddr_un); + un->sun_len = (u_char) slen; +#endif +#if LINUX + un->sun_path[0] = '\0'; #endif connection = GNUNET_new (struct GNUNET_CONNECTION_Handle); connection->cfg = cfg; @@ -843,7 +852,7 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct connection->port = 0; connection->hostname = NULL; connection->addr = (struct sockaddr *) un; - connection->addrlen = sizeof (struct sockaddr_un); + connection->addrlen = slen; connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); if (NULL == connection->sock) { diff --git a/src/util/disk.c b/src/util/disk.c index 34480e36ae..066b0b99b6 100644 --- a/src/util/disk.c +++ b/src/util/disk.c @@ -759,12 +759,13 @@ GNUNET_DISK_directory_create (const char *dir) /** - * Create the directory structure for storing a file. + * Create the directory structure for storing + * a file. * * @param filename name of a file in the directory - * @returns #GNUNET_OK on success, - * #GNUNET_SYSERR on failure, - * #GNUNET_NO if the directory + * @returns GNUNET_OK on success, + * GNUNET_SYSERR on failure, + * GNUNET_NO if the directory * exists but is not writeable for us */ int @@ -791,11 +792,10 @@ GNUNET_DISK_directory_create_for_file (const char *filename) /** * Read the contents of a binary file into a buffer. - * * @param h handle to an open file * @param result the buffer to write the result to * @param len the maximum number of bytes to read - * @return the number of bytes read on success, #GNUNET_SYSERR on failure + * @return the number of bytes read on success, GNUNET_SYSERR on failure */ ssize_t GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle * h, void *result, diff --git a/src/util/network.c b/src/util/network.c index 793290b451..c0b9773680 100644 --- a/src/util/network.c +++ b/src/util/network.c @@ -87,9 +87,7 @@ GNUNET_NETWORK_test_pf (int pf) { if (EAFNOSUPPORT == errno) return GNUNET_NO; - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Failed to create test socket: %s\n", - STRERROR (errno)); + fprintf (stderr, "Failed to create test socket: %s\n", STRERROR (errno)); return GNUNET_SYSERR; } #if WINDOWS @@ -385,18 +383,20 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, * @param desc socket to bind * @param address address to be bound * @param address_len length of @a address + * @param flags flags affecting bind behaviour * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise */ int GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, - socklen_t address_len) + socklen_t address_len, + int flags) { int ret; socklen_t bind_address_len = address_len; #ifdef LINUX - if (AF_UNIX == address->sa_family) + if (address->sa_family == AF_UNIX) { const struct sockaddr_un *address_un = (const struct sockaddr_un *)address; if (address_un->sun_path[0] == '\0') @@ -431,6 +431,16 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, "setsockopt"); } #endif +#ifndef LINUX +#ifndef MINGW + if (address->sa_family == AF_UNIX && (flags & GNUNET_BIND_EXCLUSIVE) == 0) + { + const struct sockaddr_un *un = (const struct sockaddr_un *) address; + + (void) unlink (un->sun_path); + } +#endif +#endif ret = bind (desc->fd, address, bind_address_len); #ifdef MINGW if (SOCKET_ERROR == ret) @@ -439,10 +449,12 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, if (ret != 0) return GNUNET_SYSERR; #ifndef MINGW +#ifndef LINUX desc->addr = GNUNET_malloc (address_len); memcpy (desc->addr, address, address_len); desc->addrlen = address_len; #endif +#endif return GNUNET_OK; } @@ -471,17 +483,17 @@ GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc) #else ret = close (desc->fd); #endif +#ifndef LINUX #ifndef MINGW if ((desc->af == AF_UNIX) && (NULL != desc->addr)) { const struct sockaddr_un *un = (const struct sockaddr_un *) desc->addr; if (0 != unlink (un->sun_path)) - LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, - "unlink", - un->sun_path); + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", un->sun_path); } #endif +#endif GNUNET_NETWORK_socket_free_memory_only_ (desc); return (ret == 0) ? GNUNET_OK : GNUNET_SYSERR; } diff --git a/src/util/resolver.conf.in b/src/util/resolver.conf.in index 005082ea56..cccb60c2f3 100644 --- a/src/util/resolver.conf.in +++ b/src/util/resolver.conf.in @@ -6,7 +6,7 @@ HOME = $SERVICEHOME BINARY = gnunet-service-resolver ACCEPT_FROM = 127.0.0.1; ACCEPT_FROM6 = ::1; -UNIXPATH = $SERVICEHOME/gnunet-service-resolver.sock +UNIXPATH = /tmp/gnunet-service-resolver.sock UNIX_MATCH_UID = NO UNIX_MATCH_GID = NO # DISABLE_SOCKET_FORWARDING = NO diff --git a/src/util/server.c b/src/util/server.c index 4df8fd83d9..9e88992ca8 100644 --- a/src/util/server.c +++ b/src/util/server.c @@ -469,7 +469,7 @@ open_listen_socket (const struct sockaddr *serverAddr, socklen_t socklen) return NULL; } /* bind the socket */ - if (GNUNET_OK != GNUNET_NETWORK_socket_bind (sock, serverAddr, socklen)) + if (GNUNET_OK != GNUNET_NETWORK_socket_bind (sock, serverAddr, socklen, 0)) { eno = errno; if (EADDRINUSE != errno) diff --git a/src/util/service.c b/src/util/service.c index 489dd2e550..b91be96645 100644 --- a/src/util/service.c +++ b/src/util/service.c @@ -841,15 +841,24 @@ add_unixpath (struct sockaddr **saddrs, socklen_t * saddrlens, { #ifdef AF_UNIX struct sockaddr_un *un; + size_t slen; un = GNUNET_malloc (sizeof (struct sockaddr_un)); un->sun_family = AF_UNIX; - strncpy (un->sun_path, unixpath, sizeof (un->sun_path) - 1); + slen = strlen (unixpath) + 1; + if (slen >= sizeof (un->sun_path)) + slen = sizeof (un->sun_path) - 1; + memcpy (un->sun_path, unixpath, slen); + un->sun_path[slen] = '\0'; + slen = sizeof (struct sockaddr_un); +#if LINUX + un->sun_path[0] = '\0'; +#endif #if HAVE_SOCKADDR_IN_SIN_LEN - un->sun_len = (u_char) sizeof (struct sockaddr_un); + un->sun_len = (u_char) slen; #endif *saddrs = (struct sockaddr *) un; - *saddrlens = sizeof (struct sockaddr_un); + *saddrlens = slen; #else /* this function should never be called * unless AF_UNIX is defined! */ @@ -971,8 +980,8 @@ GNUNET_SERVICE_get_server_addresses (const char *service_name, if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) && (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_filename (cfg, service_name, "UNIXPATH", - &unixpath)) && + GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "UNIXPATH", + &unixpath)) && (0 < strlen (unixpath))) { /* probe UNIX support */ @@ -987,11 +996,6 @@ GNUNET_SERVICE_get_server_addresses (const char *service_name, LOG (GNUNET_ERROR_TYPE_INFO, _("Using `%s' instead\n"), unixpath); } - if (GNUNET_OK != - GNUNET_DISK_directory_create_for_file (unixpath)) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, - "mkdir", - unixpath); } if (NULL != unixpath) { diff --git a/src/util/test_connection.c b/src/util/test_connection.c index 6644623d4a..1ba20498fd 100644 --- a/src/util/test_connection.c +++ b/src/util/test_connection.c @@ -65,9 +65,9 @@ open_listen_socket () if (GNUNET_NETWORK_socket_setsockopt (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); - GNUNET_assert (GNUNET_OK == - GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr *) &sa, - sizeof (sa))); + GNUNET_assert (GNUNET_NETWORK_socket_bind + (desc, (const struct sockaddr *) &sa, + sizeof (sa), 0) == GNUNET_OK); GNUNET_NETWORK_socket_listen (desc, 5); return desc; } diff --git a/src/util/test_connection_addressing.c b/src/util/test_connection_addressing.c index e5c8edeeb7..eeb610dd11 100644 --- a/src/util/test_connection_addressing.c +++ b/src/util/test_connection_addressing.c @@ -68,7 +68,7 @@ open_listen_socket () GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); if (GNUNET_OK != GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr *) &sa, - sizeof (sa))) + sizeof (sa), 0)) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "bind"); diff --git a/src/util/test_connection_receive_cancel.c b/src/util/test_connection_receive_cancel.c index c61272a57a..99905e232d 100644 --- a/src/util/test_connection_receive_cancel.c +++ b/src/util/test_connection_receive_cancel.c @@ -64,9 +64,9 @@ open_listen_socket () if (GNUNET_NETWORK_socket_setsockopt (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); - GNUNET_assert (GNUNET_OK == - GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr *) &sa, - sizeof (sa))); + GNUNET_assert (GNUNET_NETWORK_socket_bind + (desc, (const struct sockaddr *) &sa, + sizeof (sa), 0) == GNUNET_OK); GNUNET_NETWORK_socket_listen (desc, 5); return desc; } diff --git a/src/util/test_connection_timeout.c b/src/util/test_connection_timeout.c index 7241bbfaed..6608e18dbb 100644 --- a/src/util/test_connection_timeout.c +++ b/src/util/test_connection_timeout.c @@ -61,9 +61,9 @@ open_listen_socket () if (GNUNET_NETWORK_socket_setsockopt (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); - GNUNET_assert (GNUNET_OK == - GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr *) &sa, - sizeof (sa))); + GNUNET_assert (GNUNET_NETWORK_socket_bind + (desc, (const struct sockaddr *) &sa, + sizeof (sa), 0) == GNUNET_OK); GNUNET_NETWORK_socket_listen (desc, 5); return desc; } diff --git a/src/util/test_server_with_client_unix.c b/src/util/test_server_with_client_unix.c index a4e0ffe5d0..57a67d3f45 100644 --- a/src/util/test_server_with_client_unix.c +++ b/src/util/test_server_with_client_unix.c @@ -134,15 +134,20 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct sockaddr_un un; const char *unixpath = "/tmp/testsock"; + size_t slen = strlen (unixpath); struct sockaddr *sap[2]; socklen_t slens[2]; memset (&un, 0, sizeof (un)); un.sun_family = AF_UNIX; - strncpy(un.sun_path, unixpath, sizeof (un.sun_path) - 1); + memcpy (un.sun_path, unixpath, slen); + un.sun_path[slen] = '\0'; #if HAVE_SOCKADDR_IN_SIN_LEN un.sun_len = (u_char) sizeof (un); #endif +#if LINUX + un.sun_path[0] = '\0'; +#endif sap[0] = (struct sockaddr *) &un; slens[0] = sizeof (un); diff --git a/src/vpn/vpn.conf.in b/src/vpn/vpn.conf.in index 55c86dc030..57657b94f6 100644 --- a/src/vpn/vpn.conf.in +++ b/src/vpn/vpn.conf.in @@ -6,7 +6,7 @@ HOME = $SERVICEHOME BINARY = gnunet-service-vpn ACCEPT_FROM = 127.0.0.1; ACCEPT_FROM6 = ::1; -UNIXPATH = $SERVICEHOME/gnunet-service-vpn.sock +UNIXPATH = /tmp/gnunet-service-vpn.sock UNIX_MATCH_UID = YES UNIX_MATCH_GID = YES |