diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2014-02-09 21:54:56 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2014-02-09 21:54:56 +0000 |
commit | 8a6d5d56ba09ddd8a8848bae490b84ef3ea2923d (patch) | |
tree | bf6550e218666d2df51dd02bf185298b2ab4cf03 /src/util/network.c | |
parent | 09104d9e153cfce464ef38cda9ccbba4b029ae11 (diff) | |
download | gnunet-8a6d5d56ba09ddd8a8848bae490b84ef3ea2923d.tar.gz gnunet-8a6d5d56ba09ddd8a8848bae490b84ef3ea2923d.zip |
Create UNIX domain sockets as abstract sockets when running in LINUX and the
option USE_ABSTRACT_SOCKETS is present in configuration.
Diffstat (limited to 'src/util/network.c')
-rw-r--r-- | src/util/network.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/util/network.c b/src/util/network.c index 2ee1a73a0..d321a7009 100644 --- a/src/util/network.c +++ b/src/util/network.c | |||
@@ -420,17 +420,23 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, | |||
420 | #endif | 420 | #endif |
421 | #ifndef WINDOWS | 421 | #ifndef WINDOWS |
422 | { | 422 | { |
423 | /* set permissions of newly created UNIX domain socket to "user-only"; applications | 423 | /* set permissions of newly created non-abstract UNIX domain socket to |
424 | can choose to relax this later */ | 424 | "user-only"; applications can choose to relax this later */ |
425 | mode_t old_mask = 0; /* assigned to make compiler happy */ | 425 | mode_t old_mask = 0; /* assigned to make compiler happy */ |
426 | 426 | const struct sockaddr_un *un; | |
427 | if (AF_UNIX == address->sa_family) | 427 | int not_abstract = 0; |
428 | |||
429 | if ((AF_UNIX == address->sa_family) | ||
430 | && (NULL != (un = (const struct sockaddr_un *) address)->sun_path) | ||
431 | && ('\0' != un->sun_path[0]) ) /* Not an abstract socket */ | ||
432 | not_abstract = 1; | ||
433 | if (not_abstract) | ||
428 | old_mask = umask (S_IWGRP | S_IRGRP | S_IXGRP | S_IWOTH | S_IROTH | S_IXOTH); | 434 | old_mask = umask (S_IWGRP | S_IRGRP | S_IXGRP | S_IWOTH | S_IROTH | S_IXOTH); |
429 | #endif | 435 | #endif |
430 | 436 | ||
431 | ret = bind (desc->fd, address, address_len); | 437 | ret = bind (desc->fd, address, address_len); |
432 | #ifndef WINDOWS | 438 | #ifndef WINDOWS |
433 | if (AF_UNIX == address->sa_family) | 439 | if (not_abstract) |
434 | (void) umask (old_mask); | 440 | (void) umask (old_mask); |
435 | } | 441 | } |
436 | #endif | 442 | #endif |
@@ -460,7 +466,7 @@ GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc) | |||
460 | { | 466 | { |
461 | int ret; | 467 | int ret; |
462 | 468 | ||
463 | #ifdef MINGW | 469 | #ifdef WINDOWS |
464 | DWORD error = 0; | 470 | DWORD error = 0; |
465 | 471 | ||
466 | SetLastError (0); | 472 | SetLastError (0); |
@@ -473,10 +479,15 @@ GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc) | |||
473 | #else | 479 | #else |
474 | ret = close (desc->fd); | 480 | ret = close (desc->fd); |
475 | #endif | 481 | #endif |
476 | #ifndef MINGW | 482 | #ifndef WINDOWS |
477 | if ((desc->af == AF_UNIX) && (NULL != desc->addr)) | 483 | const struct sockaddr_un *un; |
484 | |||
485 | /* Cleanup the UNIX domain socket and its parent directories in case of non | ||
486 | abstract sockets */ | ||
487 | if ((AF_UNIX == desc->af) && (NULL != desc->addr) | ||
488 | && (NULL != (un = (const struct sockaddr_un *) desc->addr)->sun_path) | ||
489 | && ('\0' != un->sun_path[0])) | ||
478 | { | 490 | { |
479 | const struct sockaddr_un *un = (const struct sockaddr_un *) desc->addr; | ||
480 | char *dirname = GNUNET_strndup (un->sun_path, | 491 | char *dirname = GNUNET_strndup (un->sun_path, |
481 | sizeof (un->sun_path)); | 492 | sizeof (un->sun_path)); |
482 | 493 | ||