diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:54:06 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:54:06 +0000 |
commit | 5746309cb4be2073d550ad7a6885e918631dbc38 (patch) | |
tree | 89455bc4aadf977816b38df13f990372cd81d71a /src/util/service.c | |
parent | 6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff) | |
download | gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip |
indentation
Diffstat (limited to 'src/util/service.c')
-rw-r--r-- | src/util/service.c | 257 |
1 files changed, 112 insertions, 145 deletions
diff --git a/src/util/service.c b/src/util/service.c index 308267bd6..9b60dc56b 100644 --- a/src/util/service.c +++ b/src/util/service.c | |||
@@ -99,12 +99,10 @@ parse_ipv4_specification (const char *routeList) | |||
99 | pos = 0; | 99 | pos = 0; |
100 | while (i < count) | 100 | while (i < count) |
101 | { | 101 | { |
102 | cnt = sscanf (&routeList[pos], | 102 | cnt = |
103 | "%u.%u.%u.%u/%u.%u.%u.%u;", | 103 | sscanf (&routeList[pos], "%u.%u.%u.%u/%u.%u.%u.%u;", &temps[0], |
104 | &temps[0], | 104 | &temps[1], &temps[2], &temps[3], &temps[4], &temps[5], |
105 | &temps[1], | 105 | &temps[6], &temps[7]); |
106 | &temps[2], | ||
107 | &temps[3], &temps[4], &temps[5], &temps[6], &temps[7]); | ||
108 | if (cnt == 8) | 106 | if (cnt == 8) |
109 | { | 107 | { |
110 | for (j = 0; j < 8; j++) | 108 | for (j = 0; j < 8; j++) |
@@ -115,8 +113,7 @@ parse_ipv4_specification (const char *routeList) | |||
115 | GNUNET_free (result); | 113 | GNUNET_free (result); |
116 | return NULL; | 114 | return NULL; |
117 | } | 115 | } |
118 | result[i].network.s_addr | 116 | result[i].network.s_addr = |
119 | = | ||
120 | htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) + | 117 | htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) + |
121 | temps[3]); | 118 | temps[3]); |
122 | result[i].netmask.s_addr = | 119 | result[i].netmask.s_addr = |
@@ -129,9 +126,9 @@ parse_ipv4_specification (const char *routeList) | |||
129 | continue; | 126 | continue; |
130 | } | 127 | } |
131 | /* try second notation */ | 128 | /* try second notation */ |
132 | cnt = sscanf (&routeList[pos], | 129 | cnt = |
133 | "%u.%u.%u.%u/%u;", | 130 | sscanf (&routeList[pos], "%u.%u.%u.%u/%u;", &temps[0], &temps[1], |
134 | &temps[0], &temps[1], &temps[2], &temps[3], &slash); | 131 | &temps[2], &temps[3], &slash); |
135 | if (cnt == 5) | 132 | if (cnt == 5) |
136 | { | 133 | { |
137 | for (j = 0; j < 4; j++) | 134 | for (j = 0; j < 4; j++) |
@@ -142,8 +139,7 @@ parse_ipv4_specification (const char *routeList) | |||
142 | GNUNET_free (result); | 139 | GNUNET_free (result); |
143 | return NULL; | 140 | return NULL; |
144 | } | 141 | } |
145 | result[i].network.s_addr | 142 | result[i].network.s_addr = |
146 | = | ||
147 | htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) + | 143 | htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) + |
148 | temps[3]); | 144 | temps[3]); |
149 | if ((slash <= 32) && (slash >= 0)) | 145 | if ((slash <= 32) && (slash >= 0)) |
@@ -151,8 +147,8 @@ parse_ipv4_specification (const char *routeList) | |||
151 | result[i].netmask.s_addr = 0; | 147 | result[i].netmask.s_addr = 0; |
152 | while (slash > 0) | 148 | while (slash > 0) |
153 | { | 149 | { |
154 | result[i].netmask.s_addr | 150 | result[i].netmask.s_addr = |
155 | = (result[i].netmask.s_addr >> 1) + 0x80000000; | 151 | (result[i].netmask.s_addr >> 1) + 0x80000000; |
156 | slash--; | 152 | slash--; |
157 | } | 153 | } |
158 | result[i].netmask.s_addr = htonl (result[i].netmask.s_addr); | 154 | result[i].netmask.s_addr = htonl (result[i].netmask.s_addr); |
@@ -174,8 +170,9 @@ parse_ipv4_specification (const char *routeList) | |||
174 | } | 170 | } |
175 | /* try third notation */ | 171 | /* try third notation */ |
176 | slash = 32; | 172 | slash = 32; |
177 | cnt = sscanf (&routeList[pos], | 173 | cnt = |
178 | "%u.%u.%u.%u;", &temps[0], &temps[1], &temps[2], &temps[3]); | 174 | sscanf (&routeList[pos], "%u.%u.%u.%u;", &temps[0], &temps[1], |
175 | &temps[2], &temps[3]); | ||
179 | if (cnt == 4) | 176 | if (cnt == 4) |
180 | { | 177 | { |
181 | for (j = 0; j < 4; j++) | 178 | for (j = 0; j < 4; j++) |
@@ -186,8 +183,7 @@ parse_ipv4_specification (const char *routeList) | |||
186 | GNUNET_free (result); | 183 | GNUNET_free (result); |
187 | return NULL; | 184 | return NULL; |
188 | } | 185 | } |
189 | result[i].network.s_addr | 186 | result[i].network.s_addr = |
190 | = | ||
191 | htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) + | 187 | htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) + |
192 | temps[3]); | 188 | temps[3]); |
193 | result[i].netmask.s_addr = 0; | 189 | result[i].netmask.s_addr = 0; |
@@ -203,15 +199,15 @@ parse_ipv4_specification (const char *routeList) | |||
203 | i++; | 199 | i++; |
204 | continue; | 200 | continue; |
205 | } | 201 | } |
206 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 202 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Invalid format for IP: `%s'\n"), |
207 | _("Invalid format for IP: `%s'\n"), &routeList[pos]); | 203 | &routeList[pos]); |
208 | GNUNET_free (result); | 204 | GNUNET_free (result); |
209 | return NULL; /* error */ | 205 | return NULL; /* error */ |
210 | } | 206 | } |
211 | if (pos < strlen (routeList)) | 207 | if (pos < strlen (routeList)) |
212 | { | 208 | { |
213 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 209 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Invalid format for IP: `%s'\n"), |
214 | _("Invalid format for IP: `%s'\n"), &routeList[pos]); | 210 | &routeList[pos]); |
215 | GNUNET_free (result); | 211 | GNUNET_free (result); |
216 | return NULL; /* oops */ | 212 | return NULL; /* oops */ |
217 | } | 213 | } |
@@ -259,8 +255,7 @@ parse_ipv6_specification (const char *routeListX) | |||
259 | if (routeList[len - 1] != ';') | 255 | if (routeList[len - 1] != ';') |
260 | { | 256 | { |
261 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 257 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
262 | _ | 258 | _("Invalid network notation (does not end with ';': `%s')\n"), |
263 | ("Invalid network notation (does not end with ';': `%s')\n"), | ||
264 | routeList); | 259 | routeList); |
265 | GNUNET_free (routeList); | 260 | GNUNET_free (routeList); |
266 | return NULL; | 261 | return NULL; |
@@ -313,8 +308,8 @@ parse_ipv6_specification (const char *routeListX) | |||
313 | } | 308 | } |
314 | while (bits > 0) | 309 | while (bits > 0) |
315 | { | 310 | { |
316 | result[i].netmask.s6_addr[off] | 311 | result[i].netmask.s6_addr[off] = |
317 | = (result[i].netmask.s6_addr[off] >> 1) + 0x80; | 312 | (result[i].netmask.s6_addr[off] >> 1) + 0x80; |
318 | bits--; | 313 | bits--; |
319 | } | 314 | } |
320 | } | 315 | } |
@@ -550,16 +545,15 @@ write_test (void *cls, size_t size, void *buf) | |||
550 | * @param message the actual message | 545 | * @param message the actual message |
551 | */ | 546 | */ |
552 | static void | 547 | static void |
553 | handle_test (void *cls, | 548 | handle_test (void *cls, struct GNUNET_SERVER_Client *client, |
554 | struct GNUNET_SERVER_Client *client, | ||
555 | const struct GNUNET_MessageHeader *message) | 549 | const struct GNUNET_MessageHeader *message) |
556 | { | 550 | { |
557 | /* simply bounce message back to acknowledge */ | 551 | /* simply bounce message back to acknowledge */ |
558 | if (NULL == GNUNET_SERVER_notify_transmit_ready (client, | 552 | if (NULL == |
559 | sizeof (struct | 553 | GNUNET_SERVER_notify_transmit_ready (client, |
560 | GNUNET_MessageHeader), | 554 | sizeof (struct GNUNET_MessageHeader), |
561 | GNUNET_TIME_UNIT_FOREVER_REL, | 555 | GNUNET_TIME_UNIT_FOREVER_REL, |
562 | &write_test, client)) | 556 | &write_test, client)) |
563 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 557 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
564 | } | 558 | } |
565 | 559 | ||
@@ -591,8 +585,7 @@ static const struct GNUNET_SERVER_MessageHandler defhandlers[] = { | |||
591 | * for unknown address family (will be denied). | 585 | * for unknown address family (will be denied). |
592 | */ | 586 | */ |
593 | static int | 587 | static int |
594 | check_access (void *cls, | 588 | check_access (void *cls, const struct GNUNET_CONNECTION_Credentials *uc, |
595 | const struct GNUNET_CONNECTION_Credentials *uc, | ||
596 | const struct sockaddr *addr, socklen_t addrlen) | 589 | const struct sockaddr *addr, socklen_t addrlen) |
597 | { | 590 | { |
598 | struct GNUNET_SERVICE_Context *sctx = cls; | 591 | struct GNUNET_SERVICE_Context *sctx = cls; |
@@ -606,19 +599,17 @@ check_access (void *cls, | |||
606 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in)); | 599 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in)); |
607 | i4 = (const struct sockaddr_in *) addr; | 600 | i4 = (const struct sockaddr_in *) addr; |
608 | ret = ((sctx->v4_allowed == NULL) || | 601 | ret = ((sctx->v4_allowed == NULL) || |
609 | (check_ipv4_listed (sctx->v4_allowed, | 602 | (check_ipv4_listed (sctx->v4_allowed, &i4->sin_addr))) && |
610 | &i4->sin_addr))) | 603 | ((sctx->v4_denied == NULL) || |
611 | && ((sctx->v4_denied == NULL) || | 604 | (!check_ipv4_listed (sctx->v4_denied, &i4->sin_addr))); |
612 | (!check_ipv4_listed (sctx->v4_denied, &i4->sin_addr))); | ||
613 | break; | 605 | break; |
614 | case AF_INET6: | 606 | case AF_INET6: |
615 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); | 607 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); |
616 | i6 = (const struct sockaddr_in6 *) addr; | 608 | i6 = (const struct sockaddr_in6 *) addr; |
617 | ret = ((sctx->v6_allowed == NULL) || | 609 | ret = ((sctx->v6_allowed == NULL) || |
618 | (check_ipv6_listed (sctx->v6_allowed, | 610 | (check_ipv6_listed (sctx->v6_allowed, &i6->sin6_addr))) && |
619 | &i6->sin6_addr))) | 611 | ((sctx->v6_denied == NULL) || |
620 | && ((sctx->v6_denied == NULL) || | 612 | (!check_ipv6_listed (sctx->v6_denied, &i6->sin6_addr))); |
621 | (!check_ipv6_listed (sctx->v6_denied, &i6->sin6_addr))); | ||
622 | break; | 613 | break; |
623 | #ifndef WINDOWS | 614 | #ifndef WINDOWS |
624 | case AF_UNIX: | 615 | case AF_UNIX: |
@@ -626,11 +617,10 @@ check_access (void *cls, | |||
626 | if ((sctx->match_uid == GNUNET_YES) || (sctx->match_gid == GNUNET_YES)) | 617 | if ((sctx->match_uid == GNUNET_YES) || (sctx->match_gid == GNUNET_YES)) |
627 | ret = GNUNET_NO; | 618 | ret = GNUNET_NO; |
628 | if ((uc != NULL) && | 619 | if ((uc != NULL) && |
629 | ((sctx->match_uid != GNUNET_YES) || | 620 | ((sctx->match_uid != GNUNET_YES) || (uc->uid == geteuid ()) || |
630 | (uc->uid == geteuid ()) || | 621 | (uc->uid == getuid ())) && ((sctx->match_gid != GNUNET_YES) || |
631 | (uc->uid == getuid ())) && | 622 | (uc->gid == getegid ()) || |
632 | ((sctx->match_gid != GNUNET_YES) || | 623 | (uc->gid == getgid ()))) |
633 | (uc->gid == getegid ()) || (uc->gid == getgid ()))) | ||
634 | ret = GNUNET_YES; | 624 | ret = GNUNET_YES; |
635 | else | 625 | else |
636 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 626 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -639,8 +629,8 @@ check_access (void *cls, | |||
639 | break; | 629 | break; |
640 | #endif | 630 | #endif |
641 | default: | 631 | default: |
642 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 632 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Unknown address family %d\n"), |
643 | _("Unknown address family %d\n"), addr->sa_family); | 633 | addr->sa_family); |
644 | return GNUNET_SYSERR; | 634 | return GNUNET_SYSERR; |
645 | } | 635 | } |
646 | if (ret != GNUNET_OK) | 636 | if (ret != GNUNET_OK) |
@@ -664,8 +654,7 @@ get_pid_file_name (struct GNUNET_SERVICE_Context *sctx) | |||
664 | char *pif; | 654 | char *pif; |
665 | 655 | ||
666 | if (GNUNET_OK != | 656 | if (GNUNET_OK != |
667 | GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, | 657 | GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, sctx->serviceName, |
668 | sctx->serviceName, | ||
669 | "PIDFILE", &pif)) | 658 | "PIDFILE", &pif)) |
670 | return NULL; | 659 | return NULL; |
671 | return pif; | 660 | return pif; |
@@ -676,8 +665,8 @@ get_pid_file_name (struct GNUNET_SERVICE_Context *sctx) | |||
676 | * Parse an IPv4 access control list. | 665 | * Parse an IPv4 access control list. |
677 | */ | 666 | */ |
678 | static int | 667 | static int |
679 | process_acl4 (struct IPv4NetworkSet **ret, | 668 | process_acl4 (struct IPv4NetworkSet **ret, struct GNUNET_SERVICE_Context *sctx, |
680 | struct GNUNET_SERVICE_Context *sctx, const char *option) | 669 | const char *option) |
681 | { | 670 | { |
682 | char *opt; | 671 | char *opt; |
683 | 672 | ||
@@ -705,8 +694,8 @@ process_acl4 (struct IPv4NetworkSet **ret, | |||
705 | * Parse an IPv4 access control list. | 694 | * Parse an IPv4 access control list. |
706 | */ | 695 | */ |
707 | static int | 696 | static int |
708 | process_acl6 (struct IPv6NetworkSet **ret, | 697 | process_acl6 (struct IPv6NetworkSet **ret, struct GNUNET_SERVICE_Context *sctx, |
709 | struct GNUNET_SERVICE_Context *sctx, const char *option) | 698 | const char *option) |
710 | { | 699 | { |
711 | char *opt; | 700 | char *opt; |
712 | 701 | ||
@@ -738,8 +727,8 @@ process_acl6 (struct IPv6NetworkSet **ret, | |||
738 | * @param unixpath path to add | 727 | * @param unixpath path to add |
739 | */ | 728 | */ |
740 | static void | 729 | static void |
741 | add_unixpath (struct sockaddr **saddrs, | 730 | add_unixpath (struct sockaddr **saddrs, socklen_t * saddrlens, |
742 | socklen_t * saddrlens, const char *unixpath) | 731 | const char *unixpath) |
743 | { | 732 | { |
744 | #ifdef AF_UNIX | 733 | #ifdef AF_UNIX |
745 | struct sockaddr_un *un; | 734 | struct sockaddr_un *un; |
@@ -816,9 +805,8 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName, | |||
816 | if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "DISABLEV6")) | 805 | if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "DISABLEV6")) |
817 | { | 806 | { |
818 | if (GNUNET_SYSERR == | 807 | if (GNUNET_SYSERR == |
819 | (disablev6 = GNUNET_CONFIGURATION_get_value_yesno (cfg, | 808 | (disablev6 = |
820 | serviceName, | 809 | GNUNET_CONFIGURATION_get_value_yesno (cfg, serviceName, "DISABLEV6"))) |
821 | "DISABLEV6"))) | ||
822 | return GNUNET_SYSERR; | 810 | return GNUNET_SYSERR; |
823 | } | 811 | } |
824 | else | 812 | else |
@@ -830,8 +818,8 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName, | |||
830 | desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0); | 818 | desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0); |
831 | if (NULL == desc) | 819 | if (NULL == desc) |
832 | { | 820 | { |
833 | if ((errno == ENOBUFS) || | 821 | if ((errno == ENOBUFS) || (errno == ENOMEM) || (errno == ENFILE) || |
834 | (errno == ENOMEM) || (errno == ENFILE) || (errno == EACCES)) | 822 | (errno == EACCES)) |
835 | { | 823 | { |
836 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); | 824 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); |
837 | return GNUNET_SYSERR; | 825 | return GNUNET_SYSERR; |
@@ -853,8 +841,7 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName, | |||
853 | if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "PORT")) | 841 | if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "PORT")) |
854 | { | 842 | { |
855 | GNUNET_break (GNUNET_OK == | 843 | GNUNET_break (GNUNET_OK == |
856 | GNUNET_CONFIGURATION_get_value_number (cfg, | 844 | GNUNET_CONFIGURATION_get_value_number (cfg, serviceName, |
857 | serviceName, | ||
858 | "PORT", &port)); | 845 | "PORT", &port)); |
859 | if (port > 65535) | 846 | if (port > 65535) |
860 | { | 847 | { |
@@ -869,8 +856,7 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName, | |||
869 | if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "BINDTO")) | 856 | if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "BINDTO")) |
870 | { | 857 | { |
871 | GNUNET_break (GNUNET_OK == | 858 | GNUNET_break (GNUNET_OK == |
872 | GNUNET_CONFIGURATION_get_value_string (cfg, | 859 | GNUNET_CONFIGURATION_get_value_string (cfg, serviceName, |
873 | serviceName, | ||
874 | "BINDTO", &hostname)); | 860 | "BINDTO", &hostname)); |
875 | } | 861 | } |
876 | else | 862 | else |
@@ -878,11 +864,11 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName, | |||
878 | 864 | ||
879 | unixpath = NULL; | 865 | unixpath = NULL; |
880 | #ifdef AF_UNIX | 866 | #ifdef AF_UNIX |
881 | if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (cfg, | 867 | if ((GNUNET_YES == |
882 | serviceName, "UNIXPATH")) | 868 | GNUNET_CONFIGURATION_have_value (cfg, serviceName, "UNIXPATH")) && |
883 | && (GNUNET_OK == | 869 | (GNUNET_OK == |
884 | GNUNET_CONFIGURATION_get_value_string (cfg, serviceName, "UNIXPATH", | 870 | GNUNET_CONFIGURATION_get_value_string (cfg, serviceName, "UNIXPATH", |
885 | &unixpath)) && | 871 | &unixpath)) && |
886 | (0 < strlen (unixpath))) | 872 | (0 < strlen (unixpath))) |
887 | { | 873 | { |
888 | /* probe UNIX support */ | 874 | /* probe UNIX support */ |
@@ -901,8 +887,8 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName, | |||
901 | desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); | 887 | desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); |
902 | if (NULL == desc) | 888 | if (NULL == desc) |
903 | { | 889 | { |
904 | if ((errno == ENOBUFS) || | 890 | if ((errno == ENOBUFS) || (errno == ENOMEM) || (errno == ENFILE) || |
905 | (errno == ENOMEM) || (errno == ENFILE) || (errno == EACCES)) | 891 | (errno == EACCES)) |
906 | { | 892 | { |
907 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); | 893 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); |
908 | GNUNET_free_non_null (hostname); | 894 | GNUNET_free_non_null (hostname); |
@@ -955,11 +941,10 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName, | |||
955 | memset (&hints, 0, sizeof (struct addrinfo)); | 941 | memset (&hints, 0, sizeof (struct addrinfo)); |
956 | if (disablev6) | 942 | if (disablev6) |
957 | hints.ai_family = AF_INET; | 943 | hints.ai_family = AF_INET; |
958 | if ((0 != (ret = getaddrinfo (hostname, | 944 | if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) || |
959 | NULL, &hints, &res))) || (res == NULL)) | 945 | (res == NULL)) |
960 | { | 946 | { |
961 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 947 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to resolve `%s': %s\n"), |
962 | _("Failed to resolve `%s': %s\n"), | ||
963 | hostname, gai_strerror (ret)); | 948 | hostname, gai_strerror (ret)); |
964 | GNUNET_free (hostname); | 949 | GNUNET_free (hostname); |
965 | GNUNET_free_non_null (unixpath); | 950 | GNUNET_free_non_null (unixpath); |
@@ -1006,8 +991,7 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName, | |||
1006 | if ((pos->ai_socktype != SOCK_STREAM) && (pos->ai_socktype != 0)) | 991 | if ((pos->ai_socktype != SOCK_STREAM) && (pos->ai_socktype != 0)) |
1007 | continue; /* huh? */ | 992 | continue; /* huh? */ |
1008 | #if DEBUG_SERVICE | 993 | #if DEBUG_SERVICE |
1009 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 994 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service `%s' will bind to `%s'\n", |
1010 | "Service `%s' will bind to `%s'\n", | ||
1011 | serviceName, GNUNET_a2s (pos->ai_addr, pos->ai_addrlen)); | 995 | serviceName, GNUNET_a2s (pos->ai_addr, pos->ai_addrlen)); |
1012 | #endif | 996 | #endif |
1013 | if (pos->ai_family == AF_INET) | 997 | if (pos->ai_family == AF_INET) |
@@ -1130,8 +1114,7 @@ setup_service (struct GNUNET_SERVICE_Context *sctx) | |||
1130 | if (GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->serviceName, "TIMEOUT")) | 1114 | if (GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->serviceName, "TIMEOUT")) |
1131 | { | 1115 | { |
1132 | if (GNUNET_OK != | 1116 | if (GNUNET_OK != |
1133 | GNUNET_CONFIGURATION_get_value_time (sctx->cfg, | 1117 | GNUNET_CONFIGURATION_get_value_time (sctx->cfg, sctx->serviceName, |
1134 | sctx->serviceName, | ||
1135 | "TIMEOUT", &idleout)) | 1118 | "TIMEOUT", &idleout)) |
1136 | { | 1119 | { |
1137 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1120 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -1144,13 +1127,13 @@ setup_service (struct GNUNET_SERVICE_Context *sctx) | |||
1144 | else | 1127 | else |
1145 | sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL; | 1128 | sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL; |
1146 | 1129 | ||
1147 | if (GNUNET_CONFIGURATION_have_value (sctx->cfg, | 1130 | if (GNUNET_CONFIGURATION_have_value |
1148 | sctx->serviceName, "TOLERANT")) | 1131 | (sctx->cfg, sctx->serviceName, "TOLERANT")) |
1149 | { | 1132 | { |
1150 | if (GNUNET_SYSERR == | 1133 | if (GNUNET_SYSERR == |
1151 | (tolerant = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, | 1134 | (tolerant = |
1152 | sctx->serviceName, | 1135 | GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->serviceName, |
1153 | "TOLERANT"))) | 1136 | "TOLERANT"))) |
1154 | { | 1137 | { |
1155 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1138 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1156 | _("Specified value for `%s' of service `%s' is invalid\n"), | 1139 | _("Specified value for `%s' of service `%s' is invalid\n"), |
@@ -1164,19 +1147,17 @@ setup_service (struct GNUNET_SERVICE_Context *sctx) | |||
1164 | #ifndef MINGW | 1147 | #ifndef MINGW |
1165 | errno = 0; | 1148 | errno = 0; |
1166 | if ((NULL != (lpid = getenv ("LISTEN_PID"))) && | 1149 | if ((NULL != (lpid = getenv ("LISTEN_PID"))) && |
1167 | (1 == sscanf (lpid, "%u", &pid)) && | 1150 | (1 == sscanf (lpid, "%u", &pid)) && (getpid () == (pid_t) pid) && |
1168 | (getpid () == (pid_t) pid) && | ||
1169 | (NULL != (nfds = getenv ("LISTEN_FDS"))) && | 1151 | (NULL != (nfds = getenv ("LISTEN_FDS"))) && |
1170 | (1 == sscanf (nfds, "%u", &cnt)) && | 1152 | (1 == sscanf (nfds, "%u", &cnt)) && (cnt > 0) && (cnt < FD_SETSIZE) && |
1171 | (cnt > 0) && (cnt < FD_SETSIZE) && (cnt + 4 < FD_SETSIZE)) | 1153 | (cnt + 4 < FD_SETSIZE)) |
1172 | { | 1154 | { |
1173 | sctx->lsocks = | 1155 | sctx->lsocks = |
1174 | GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (cnt + 1)); | 1156 | GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (cnt + 1)); |
1175 | while (0 < cnt--) | 1157 | while (0 < cnt--) |
1176 | { | 1158 | { |
1177 | flags = fcntl (3 + cnt, F_GETFD); | 1159 | flags = fcntl (3 + cnt, F_GETFD); |
1178 | if ((flags < 0) || | 1160 | if ((flags < 0) || (0 != (flags & FD_CLOEXEC)) || |
1179 | (0 != (flags & FD_CLOEXEC)) || | ||
1180 | (NULL == | 1161 | (NULL == |
1181 | (sctx->lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt)))) | 1162 | (sctx->lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt)))) |
1182 | { | 1163 | { |
@@ -1199,17 +1180,16 @@ setup_service (struct GNUNET_SERVICE_Context *sctx) | |||
1199 | 1180 | ||
1200 | if ((sctx->lsocks == NULL) && | 1181 | if ((sctx->lsocks == NULL) && |
1201 | (GNUNET_SYSERR == | 1182 | (GNUNET_SYSERR == |
1202 | GNUNET_SERVICE_get_server_addresses (sctx->serviceName, | 1183 | GNUNET_SERVICE_get_server_addresses (sctx->serviceName, sctx->cfg, |
1203 | sctx->cfg, | ||
1204 | &sctx->addrs, &sctx->addrlens))) | 1184 | &sctx->addrs, &sctx->addrlens))) |
1205 | return GNUNET_SYSERR; | 1185 | return GNUNET_SYSERR; |
1206 | sctx->require_found = tolerant ? GNUNET_NO : GNUNET_YES; | 1186 | sctx->require_found = tolerant ? GNUNET_NO : GNUNET_YES; |
1207 | sctx->match_uid = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, | 1187 | sctx->match_uid = |
1208 | sctx->serviceName, | 1188 | GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->serviceName, |
1209 | "UNIX_MATCH_UID"); | 1189 | "UNIX_MATCH_UID"); |
1210 | sctx->match_gid = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, | 1190 | sctx->match_gid = |
1211 | sctx->serviceName, | 1191 | GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->serviceName, |
1212 | "UNIX_MATCH_GID"); | 1192 | "UNIX_MATCH_GID"); |
1213 | process_acl4 (&sctx->v4_denied, sctx, "REJECT_FROM"); | 1193 | process_acl4 (&sctx->v4_denied, sctx, "REJECT_FROM"); |
1214 | process_acl4 (&sctx->v4_allowed, sctx, "ACCEPT_FROM"); | 1194 | process_acl4 (&sctx->v4_allowed, sctx, "ACCEPT_FROM"); |
1215 | process_acl6 (&sctx->v6_denied, sctx, "REJECT_FROM6"); | 1195 | process_acl6 (&sctx->v6_denied, sctx, "REJECT_FROM6"); |
@@ -1230,8 +1210,7 @@ get_user_name (struct GNUNET_SERVICE_Context *sctx) | |||
1230 | char *un; | 1210 | char *un; |
1231 | 1211 | ||
1232 | if (GNUNET_OK != | 1212 | if (GNUNET_OK != |
1233 | GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, | 1213 | GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, sctx->serviceName, |
1234 | sctx->serviceName, | ||
1235 | "USERNAME", &un)) | 1214 | "USERNAME", &un)) |
1236 | return NULL; | 1215 | return NULL; |
1237 | return un; | 1216 | return un; |
@@ -1319,17 +1298,13 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1319 | 1298 | ||
1320 | GNUNET_RESOLVER_connect (sctx->cfg); | 1299 | GNUNET_RESOLVER_connect (sctx->cfg); |
1321 | if (sctx->lsocks != NULL) | 1300 | if (sctx->lsocks != NULL) |
1322 | sctx->server = GNUNET_SERVER_create_with_sockets (&check_access, | 1301 | sctx->server = |
1323 | sctx, | 1302 | GNUNET_SERVER_create_with_sockets (&check_access, sctx, sctx->lsocks, |
1324 | sctx->lsocks, | 1303 | sctx->timeout, sctx->require_found); |
1325 | sctx->timeout, | ||
1326 | sctx->require_found); | ||
1327 | else | 1304 | else |
1328 | sctx->server = GNUNET_SERVER_create (&check_access, | 1305 | sctx->server = |
1329 | sctx, | 1306 | GNUNET_SERVER_create (&check_access, sctx, sctx->addrs, sctx->addrlens, |
1330 | sctx->addrs, | 1307 | sctx->timeout, sctx->require_found); |
1331 | sctx->addrlens, | ||
1332 | sctx->timeout, sctx->require_found); | ||
1333 | if (sctx->server == NULL) | 1308 | if (sctx->server == NULL) |
1334 | { | 1309 | { |
1335 | if (sctx->addrs != NULL) | 1310 | if (sctx->addrs != NULL) |
@@ -1337,10 +1312,9 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1337 | i = 0; | 1312 | i = 0; |
1338 | while (sctx->addrs[i] != NULL) | 1313 | while (sctx->addrs[i] != NULL) |
1339 | { | 1314 | { |
1340 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1315 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Failed to start `%s' at `%s'\n"), |
1341 | _("Failed to start `%s' at `%s'\n"), | 1316 | sctx->serviceName, GNUNET_a2s (sctx->addrs[i], |
1342 | sctx->serviceName, | 1317 | sctx->addrlens[i])); |
1343 | GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i])); | ||
1344 | i++; | 1318 | i++; |
1345 | } | 1319 | } |
1346 | } | 1320 | } |
@@ -1351,8 +1325,8 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1351 | { | 1325 | { |
1352 | /* install a task that will kill the server | 1326 | /* install a task that will kill the server |
1353 | * process if the scheduler ever gets a shutdown signal */ | 1327 | * process if the scheduler ever gets a shutdown signal */ |
1354 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 1328 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, |
1355 | &shutdown_task, sctx->server); | 1329 | sctx->server); |
1356 | } | 1330 | } |
1357 | sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers)); | 1331 | sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers)); |
1358 | memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers)); | 1332 | memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers)); |
@@ -1372,10 +1346,9 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1372 | i = 0; | 1346 | i = 0; |
1373 | while (sctx->addrs[i] != NULL) | 1347 | while (sctx->addrs[i] != NULL) |
1374 | { | 1348 | { |
1375 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1349 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Service `%s' runs at %s\n"), |
1376 | _("Service `%s' runs at %s\n"), | 1350 | sctx->serviceName, GNUNET_a2s (sctx->addrs[i], |
1377 | sctx->serviceName, | 1351 | sctx->addrlens[i])); |
1378 | GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i])); | ||
1379 | i++; | 1352 | i++; |
1380 | } | 1353 | } |
1381 | } | 1354 | } |
@@ -1480,8 +1453,8 @@ set_user_id (struct GNUNET_SERVICE_Context *sctx) | |||
1480 | if (pws == NULL) | 1453 | if (pws == NULL) |
1481 | { | 1454 | { |
1482 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1455 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1483 | _("Cannot obtain information about user `%s': %s\n"), | 1456 | _("Cannot obtain information about user `%s': %s\n"), user, |
1484 | user, errno == 0 ? _("No such user") : STRERROR (errno)); | 1457 | errno == 0 ? _("No such user") : STRERROR (errno)); |
1485 | GNUNET_free (user); | 1458 | GNUNET_free (user); |
1486 | return GNUNET_SYSERR; | 1459 | return GNUNET_SYSERR; |
1487 | } | 1460 | } |
@@ -1537,11 +1510,9 @@ pid_file_delete (struct GNUNET_SERVICE_Context *sctx) | |||
1537 | * if we shutdown nicely | 1510 | * if we shutdown nicely |
1538 | */ | 1511 | */ |
1539 | int | 1512 | int |
1540 | GNUNET_SERVICE_run (int argc, | 1513 | GNUNET_SERVICE_run (int argc, char *const *argv, const char *serviceName, |
1541 | char *const *argv, | 1514 | enum GNUNET_SERVICE_Options opt, GNUNET_SERVICE_Main task, |
1542 | const char *serviceName, | 1515 | void *task_cls) |
1543 | enum GNUNET_SERVICE_Options opt, | ||
1544 | GNUNET_SERVICE_Main task, void *task_cls) | ||
1545 | { | 1516 | { |
1546 | #define HANDLE_ERROR do { err = 1; GNUNET_break (0); goto shutdown; } while (0) | 1517 | #define HANDLE_ERROR do { err = 1; GNUNET_break (0); goto shutdown; } while (0) |
1547 | 1518 | ||
@@ -1583,8 +1554,8 @@ GNUNET_SERVICE_run (int argc, | |||
1583 | sctx.serviceName = serviceName; | 1554 | sctx.serviceName = serviceName; |
1584 | sctx.cfg = cfg = GNUNET_CONFIGURATION_create (); | 1555 | sctx.cfg = cfg = GNUNET_CONFIGURATION_create (); |
1585 | /* setup subsystems */ | 1556 | /* setup subsystems */ |
1586 | if (GNUNET_SYSERR == GNUNET_GETOPT_run (serviceName, service_options, argc, | 1557 | if (GNUNET_SYSERR == |
1587 | argv)) | 1558 | GNUNET_GETOPT_run (serviceName, service_options, argc, argv)) |
1588 | goto shutdown; | 1559 | goto shutdown; |
1589 | if (GNUNET_OK != GNUNET_log_setup (serviceName, loglev, logfile)) | 1560 | if (GNUNET_OK != GNUNET_log_setup (serviceName, loglev, logfile)) |
1590 | HANDLE_ERROR; | 1561 | HANDLE_ERROR; |
@@ -1598,8 +1569,8 @@ GNUNET_SERVICE_run (int argc, | |||
1598 | goto shutdown; | 1569 | goto shutdown; |
1599 | #if DEBUG_SERVICE | 1570 | #if DEBUG_SERVICE |
1600 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1571 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1601 | "Service `%s' runs with configuration from `%s'\n", | 1572 | "Service `%s' runs with configuration from `%s'\n", serviceName, |
1602 | serviceName, cfg_fn); | 1573 | cfg_fn); |
1603 | #endif | 1574 | #endif |
1604 | if (GNUNET_OK == | 1575 | if (GNUNET_OK == |
1605 | GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "testing", "skew_offset", | 1576 | GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "testing", "skew_offset", |
@@ -1679,17 +1650,13 @@ GNUNET_SERVICE_start (const char *serviceName, | |||
1679 | return NULL; | 1650 | return NULL; |
1680 | } | 1651 | } |
1681 | if (sctx->lsocks != NULL) | 1652 | if (sctx->lsocks != NULL) |
1682 | sctx->server = GNUNET_SERVER_create_with_sockets (&check_access, | 1653 | sctx->server = |
1683 | sctx, | 1654 | GNUNET_SERVER_create_with_sockets (&check_access, sctx, sctx->lsocks, |
1684 | sctx->lsocks, | 1655 | sctx->timeout, sctx->require_found); |
1685 | sctx->timeout, | ||
1686 | sctx->require_found); | ||
1687 | else | 1656 | else |
1688 | sctx->server = GNUNET_SERVER_create (&check_access, | 1657 | sctx->server = |
1689 | sctx, | 1658 | GNUNET_SERVER_create (&check_access, sctx, sctx->addrs, sctx->addrlens, |
1690 | sctx->addrs, | 1659 | sctx->timeout, sctx->require_found); |
1691 | sctx->addrlens, | ||
1692 | sctx->timeout, sctx->require_found); | ||
1693 | 1660 | ||
1694 | if (NULL == sctx->server) | 1661 | if (NULL == sctx->server) |
1695 | { | 1662 | { |