diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/transport/tcp_service_legacy.c | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/transport/tcp_service_legacy.c')
-rw-r--r-- | src/transport/tcp_service_legacy.c | 1761 |
1 files changed, 883 insertions, 878 deletions
diff --git a/src/transport/tcp_service_legacy.c b/src/transport/tcp_service_legacy.c index e59fa4a1c..3bb08c0e8 100644 --- a/src/transport/tcp_service_legacy.c +++ b/src/transport/tcp_service_legacy.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file util/service.c | 22 | * @file util/service.c |
@@ -45,8 +45,8 @@ | |||
45 | * @return #GNUNET_NO if the IP is not in the list, #GNUNET_YES if it it is | 45 | * @return #GNUNET_NO if the IP is not in the list, #GNUNET_YES if it it is |
46 | */ | 46 | */ |
47 | static int | 47 | static int |
48 | check_ipv4_listed (const struct GNUNET_STRINGS_IPv4NetworkPolicy *list, | 48 | check_ipv4_listed(const struct GNUNET_STRINGS_IPv4NetworkPolicy *list, |
49 | const struct in_addr *add) | 49 | const struct in_addr *add) |
50 | { | 50 | { |
51 | unsigned int i; | 51 | unsigned int i; |
52 | 52 | ||
@@ -54,12 +54,12 @@ check_ipv4_listed (const struct GNUNET_STRINGS_IPv4NetworkPolicy *list, | |||
54 | return GNUNET_NO; | 54 | return GNUNET_NO; |
55 | i = 0; | 55 | i = 0; |
56 | while ((list[i].network.s_addr != 0) || (list[i].netmask.s_addr != 0)) | 56 | while ((list[i].network.s_addr != 0) || (list[i].netmask.s_addr != 0)) |
57 | { | 57 | { |
58 | if ((add->s_addr & list[i].netmask.s_addr) == | 58 | if ((add->s_addr & list[i].netmask.s_addr) == |
59 | (list[i].network.s_addr & list[i].netmask.s_addr)) | 59 | (list[i].network.s_addr & list[i].netmask.s_addr)) |
60 | return GNUNET_YES; | 60 | return GNUNET_YES; |
61 | i++; | 61 | i++; |
62 | } | 62 | } |
63 | return GNUNET_NO; | 63 | return GNUNET_NO; |
64 | } | 64 | } |
65 | 65 | ||
@@ -72,8 +72,8 @@ check_ipv4_listed (const struct GNUNET_STRINGS_IPv4NetworkPolicy *list, | |||
72 | * @return #GNUNET_NO if the IP is not in the list, #GNUNET_YES if it it is | 72 | * @return #GNUNET_NO if the IP is not in the list, #GNUNET_YES if it it is |
73 | */ | 73 | */ |
74 | static int | 74 | static int |
75 | check_ipv6_listed (const struct GNUNET_STRINGS_IPv6NetworkPolicy *list, | 75 | check_ipv6_listed(const struct GNUNET_STRINGS_IPv6NetworkPolicy *list, |
76 | const struct in6_addr *ip) | 76 | const struct in6_addr *ip) |
77 | { | 77 | { |
78 | unsigned int i; | 78 | unsigned int i; |
79 | unsigned int j; | 79 | unsigned int j; |
@@ -81,20 +81,20 @@ check_ipv6_listed (const struct GNUNET_STRINGS_IPv6NetworkPolicy *list, | |||
81 | 81 | ||
82 | if (NULL == list) | 82 | if (NULL == list) |
83 | return GNUNET_NO; | 83 | return GNUNET_NO; |
84 | memset (&zero, 0, sizeof (struct in6_addr)); | 84 | memset(&zero, 0, sizeof(struct in6_addr)); |
85 | i = 0; | 85 | i = 0; |
86 | NEXT: | 86 | NEXT: |
87 | while (0 != memcmp (&zero, &list[i].network, sizeof (struct in6_addr))) | 87 | while (0 != memcmp(&zero, &list[i].network, sizeof(struct in6_addr))) |
88 | { | 88 | { |
89 | for (j = 0; j < sizeof (struct in6_addr) / sizeof (int); j++) | 89 | for (j = 0; j < sizeof(struct in6_addr) / sizeof(int); j++) |
90 | if (((((int *) ip)[j] & ((int *) &list[i].netmask)[j])) != | 90 | if (((((int *)ip)[j] & ((int *)&list[i].netmask)[j])) != |
91 | (((int *) &list[i].network)[j] & ((int *) &list[i].netmask)[j])) | 91 | (((int *)&list[i].network)[j] & ((int *)&list[i].netmask)[j])) |
92 | { | 92 | { |
93 | i++; | 93 | i++; |
94 | goto NEXT; | 94 | goto NEXT; |
95 | } | 95 | } |
96 | return GNUNET_YES; | 96 | return GNUNET_YES; |
97 | } | 97 | } |
98 | return GNUNET_NO; | 98 | return GNUNET_NO; |
99 | } | 99 | } |
100 | 100 | ||
@@ -105,8 +105,7 @@ NEXT: | |||
105 | /** | 105 | /** |
106 | * Context for "service_task". | 106 | * Context for "service_task". |
107 | */ | 107 | */ |
108 | struct LEGACY_SERVICE_Context | 108 | struct LEGACY_SERVICE_Context { |
109 | { | ||
110 | /** | 109 | /** |
111 | * Our configuration. | 110 | * Our configuration. |
112 | */ | 111 | */ |
@@ -238,21 +237,21 @@ struct LEGACY_SERVICE_Context | |||
238 | * @return number of bytes written to 'buf' | 237 | * @return number of bytes written to 'buf' |
239 | */ | 238 | */ |
240 | static size_t | 239 | static size_t |
241 | write_test (void *cls, size_t size, void *buf) | 240 | write_test(void *cls, size_t size, void *buf) |
242 | { | 241 | { |
243 | struct GNUNET_SERVER_Client *client = cls; | 242 | struct GNUNET_SERVER_Client *client = cls; |
244 | struct GNUNET_MessageHeader *msg; | 243 | struct GNUNET_MessageHeader *msg; |
245 | 244 | ||
246 | if (size < sizeof (struct GNUNET_MessageHeader)) | 245 | if (size < sizeof(struct GNUNET_MessageHeader)) |
247 | { | 246 | { |
248 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 247 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); |
249 | return 0; /* client disconnected */ | 248 | return 0; /* client disconnected */ |
250 | } | 249 | } |
251 | msg = (struct GNUNET_MessageHeader *) buf; | 250 | msg = (struct GNUNET_MessageHeader *)buf; |
252 | msg->type = htons (GNUNET_MESSAGE_TYPE_TEST); | 251 | msg->type = htons(GNUNET_MESSAGE_TYPE_TEST); |
253 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); | 252 | msg->size = htons(sizeof(struct GNUNET_MessageHeader)); |
254 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 253 | GNUNET_SERVER_receive_done(client, GNUNET_OK); |
255 | return sizeof (struct GNUNET_MessageHeader); | 254 | return sizeof(struct GNUNET_MessageHeader); |
256 | } | 255 | } |
257 | 256 | ||
258 | 257 | ||
@@ -264,18 +263,18 @@ write_test (void *cls, size_t size, void *buf) | |||
264 | * @param message the actual message | 263 | * @param message the actual message |
265 | */ | 264 | */ |
266 | static void | 265 | static void |
267 | handle_test (void *cls, | 266 | handle_test(void *cls, |
268 | struct GNUNET_SERVER_Client *client, | 267 | struct GNUNET_SERVER_Client *client, |
269 | const struct GNUNET_MessageHeader *message) | 268 | const struct GNUNET_MessageHeader *message) |
270 | { | 269 | { |
271 | /* simply bounce message back to acknowledge */ | 270 | /* simply bounce message back to acknowledge */ |
272 | if (NULL == | 271 | if (NULL == |
273 | GNUNET_SERVER_notify_transmit_ready (client, | 272 | GNUNET_SERVER_notify_transmit_ready(client, |
274 | sizeof (struct GNUNET_MessageHeader), | 273 | sizeof(struct GNUNET_MessageHeader), |
275 | GNUNET_TIME_UNIT_FOREVER_REL, | 274 | GNUNET_TIME_UNIT_FOREVER_REL, |
276 | &write_test, | 275 | &write_test, |
277 | client)) | 276 | client)) |
278 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 277 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); |
279 | } | 278 | } |
280 | 279 | ||
281 | 280 | ||
@@ -285,11 +284,11 @@ handle_test (void *cls, | |||
285 | * struct. | 284 | * struct. |
286 | */ | 285 | */ |
287 | static const struct GNUNET_SERVER_MessageHandler defhandlers[] = | 286 | static const struct GNUNET_SERVER_MessageHandler defhandlers[] = |
288 | {{&handle_test, | 287 | { { &handle_test, |
289 | NULL, | 288 | NULL, |
290 | GNUNET_MESSAGE_TYPE_TEST, | 289 | GNUNET_MESSAGE_TYPE_TEST, |
291 | sizeof (struct GNUNET_MessageHeader)}, | 290 | sizeof(struct GNUNET_MessageHeader) }, |
292 | {NULL, NULL, 0, 0}}; | 291 | { NULL, NULL, 0, 0 } }; |
293 | 292 | ||
294 | 293 | ||
295 | /* ****************** service core routines ************** */ | 294 | /* ****************** service core routines ************** */ |
@@ -306,10 +305,10 @@ static const struct GNUNET_SERVER_MessageHandler defhandlers[] = | |||
306 | * for unknown address family (will be denied). | 305 | * for unknown address family (will be denied). |
307 | */ | 306 | */ |
308 | static int | 307 | static int |
309 | check_access (void *cls, | 308 | check_access(void *cls, |
310 | const struct GNUNET_CONNECTION_Credentials *uc, | 309 | const struct GNUNET_CONNECTION_Credentials *uc, |
311 | const struct sockaddr *addr, | 310 | const struct sockaddr *addr, |
312 | socklen_t addrlen) | 311 | socklen_t addrlen) |
313 | { | 312 | { |
314 | struct LEGACY_SERVICE_Context *sctx = cls; | 313 | struct LEGACY_SERVICE_Context *sctx = cls; |
315 | const struct sockaddr_in *i4; | 314 | const struct sockaddr_in *i4; |
@@ -317,41 +316,43 @@ check_access (void *cls, | |||
317 | int ret; | 316 | int ret; |
318 | 317 | ||
319 | switch (addr->sa_family) | 318 | switch (addr->sa_family) |
320 | { | 319 | { |
321 | case AF_INET: | 320 | case AF_INET: |
322 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in)); | 321 | GNUNET_assert(addrlen == sizeof(struct sockaddr_in)); |
323 | i4 = (const struct sockaddr_in *) addr; | 322 | i4 = (const struct sockaddr_in *)addr; |
324 | ret = ((NULL == sctx->v4_allowed) || | 323 | ret = ((NULL == sctx->v4_allowed) || |
325 | (check_ipv4_listed (sctx->v4_allowed, &i4->sin_addr))) && | 324 | (check_ipv4_listed(sctx->v4_allowed, &i4->sin_addr))) && |
326 | ((NULL == sctx->v4_denied) || | 325 | ((NULL == sctx->v4_denied) || |
327 | (! check_ipv4_listed (sctx->v4_denied, &i4->sin_addr))); | 326 | (!check_ipv4_listed(sctx->v4_denied, &i4->sin_addr))); |
328 | break; | 327 | break; |
329 | case AF_INET6: | 328 | |
330 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); | 329 | case AF_INET6: |
331 | i6 = (const struct sockaddr_in6 *) addr; | 330 | GNUNET_assert(addrlen == sizeof(struct sockaddr_in6)); |
332 | ret = ((NULL == sctx->v6_allowed) || | 331 | i6 = (const struct sockaddr_in6 *)addr; |
333 | (check_ipv6_listed (sctx->v6_allowed, &i6->sin6_addr))) && | 332 | ret = ((NULL == sctx->v6_allowed) || |
334 | ((NULL == sctx->v6_denied) || | 333 | (check_ipv6_listed(sctx->v6_allowed, &i6->sin6_addr))) && |
335 | (! check_ipv6_listed (sctx->v6_denied, &i6->sin6_addr))); | 334 | ((NULL == sctx->v6_denied) || |
336 | break; | 335 | (!check_ipv6_listed(sctx->v6_denied, &i6->sin6_addr))); |
336 | break; | ||
337 | |||
337 | #ifndef WINDOWS | 338 | #ifndef WINDOWS |
338 | case AF_UNIX: | 339 | case AF_UNIX: |
339 | ret = GNUNET_OK; /* controlled using file-system ACL now */ | 340 | ret = GNUNET_OK; /* controlled using file-system ACL now */ |
340 | break; | 341 | break; |
341 | #endif | 342 | #endif |
342 | default: | 343 | default: |
343 | LOG (GNUNET_ERROR_TYPE_WARNING, | 344 | LOG(GNUNET_ERROR_TYPE_WARNING, |
344 | _ ("Unknown address family %d\n"), | 345 | _("Unknown address family %d\n"), |
345 | addr->sa_family); | 346 | addr->sa_family); |
346 | return GNUNET_SYSERR; | 347 | return GNUNET_SYSERR; |
347 | } | 348 | } |
348 | if (GNUNET_OK != ret) | 349 | if (GNUNET_OK != ret) |
349 | { | 350 | { |
350 | LOG (GNUNET_ERROR_TYPE_WARNING, | 351 | LOG(GNUNET_ERROR_TYPE_WARNING, |
351 | _ ("Access from `%s' denied to service `%s'\n"), | 352 | _("Access from `%s' denied to service `%s'\n"), |
352 | GNUNET_a2s (addr, addrlen), | 353 | GNUNET_a2s(addr, addrlen), |
353 | sctx->service_name); | 354 | sctx->service_name); |
354 | } | 355 | } |
355 | return ret; | 356 | return ret; |
356 | } | 357 | } |
357 | 358 | ||
@@ -364,14 +365,14 @@ check_access (void *cls, | |||
364 | * @return name of the file for the process ID | 365 | * @return name of the file for the process ID |
365 | */ | 366 | */ |
366 | static char * | 367 | static char * |
367 | get_pid_file_name (struct LEGACY_SERVICE_Context *sctx) | 368 | get_pid_file_name(struct LEGACY_SERVICE_Context *sctx) |
368 | { | 369 | { |
369 | char *pif; | 370 | char *pif; |
370 | 371 | ||
371 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, | 372 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(sctx->cfg, |
372 | sctx->service_name, | 373 | sctx->service_name, |
373 | "PIDFILE", | 374 | "PIDFILE", |
374 | &pif)) | 375 | &pif)) |
375 | return NULL; | 376 | return NULL; |
376 | return pif; | 377 | return pif; |
377 | } | 378 | } |
@@ -387,33 +388,33 @@ get_pid_file_name (struct LEGACY_SERVICE_Context *sctx) | |||
387 | * no ACL configured) | 388 | * no ACL configured) |
388 | */ | 389 | */ |
389 | static int | 390 | static int |
390 | process_acl4 (struct GNUNET_STRINGS_IPv4NetworkPolicy **ret, | 391 | process_acl4(struct GNUNET_STRINGS_IPv4NetworkPolicy **ret, |
391 | struct LEGACY_SERVICE_Context *sctx, | 392 | struct LEGACY_SERVICE_Context *sctx, |
392 | const char *option) | 393 | const char *option) |
393 | { | 394 | { |
394 | char *opt; | 395 | char *opt; |
395 | 396 | ||
396 | if (! GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, option)) | 397 | if (!GNUNET_CONFIGURATION_have_value(sctx->cfg, sctx->service_name, option)) |
397 | { | 398 | { |
398 | *ret = NULL; | 399 | *ret = NULL; |
399 | return GNUNET_OK; | 400 | return GNUNET_OK; |
400 | } | 401 | } |
401 | GNUNET_break (GNUNET_OK == | 402 | GNUNET_break(GNUNET_OK == |
402 | GNUNET_CONFIGURATION_get_value_string (sctx->cfg, | 403 | GNUNET_CONFIGURATION_get_value_string(sctx->cfg, |
403 | sctx->service_name, | 404 | sctx->service_name, |
404 | option, | 405 | option, |
405 | &opt)); | 406 | &opt)); |
406 | if (NULL == (*ret = GNUNET_STRINGS_parse_ipv4_policy (opt))) | 407 | if (NULL == (*ret = GNUNET_STRINGS_parse_ipv4_policy(opt))) |
407 | { | 408 | { |
408 | LOG (GNUNET_ERROR_TYPE_WARNING, | 409 | LOG(GNUNET_ERROR_TYPE_WARNING, |
409 | _ ("Could not parse IPv4 network specification `%s' for `%s:%s'\n"), | 410 | _("Could not parse IPv4 network specification `%s' for `%s:%s'\n"), |
410 | opt, | 411 | opt, |
411 | sctx->service_name, | 412 | sctx->service_name, |
412 | option); | 413 | option); |
413 | GNUNET_free (opt); | 414 | GNUNET_free(opt); |
414 | return GNUNET_SYSERR; | 415 | return GNUNET_SYSERR; |
415 | } | 416 | } |
416 | GNUNET_free (opt); | 417 | GNUNET_free(opt); |
417 | return GNUNET_OK; | 418 | return GNUNET_OK; |
418 | } | 419 | } |
419 | 420 | ||
@@ -428,33 +429,33 @@ process_acl4 (struct GNUNET_STRINGS_IPv4NetworkPolicy **ret, | |||
428 | * no ACL configured) | 429 | * no ACL configured) |
429 | */ | 430 | */ |
430 | static int | 431 | static int |
431 | process_acl6 (struct GNUNET_STRINGS_IPv6NetworkPolicy **ret, | 432 | process_acl6(struct GNUNET_STRINGS_IPv6NetworkPolicy **ret, |
432 | struct LEGACY_SERVICE_Context *sctx, | 433 | struct LEGACY_SERVICE_Context *sctx, |
433 | const char *option) | 434 | const char *option) |
434 | { | 435 | { |
435 | char *opt; | 436 | char *opt; |
436 | 437 | ||
437 | if (! GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, option)) | 438 | if (!GNUNET_CONFIGURATION_have_value(sctx->cfg, sctx->service_name, option)) |
438 | { | 439 | { |
439 | *ret = NULL; | 440 | *ret = NULL; |
440 | return GNUNET_OK; | 441 | return GNUNET_OK; |
441 | } | 442 | } |
442 | GNUNET_break (GNUNET_OK == | 443 | GNUNET_break(GNUNET_OK == |
443 | GNUNET_CONFIGURATION_get_value_string (sctx->cfg, | 444 | GNUNET_CONFIGURATION_get_value_string(sctx->cfg, |
444 | sctx->service_name, | 445 | sctx->service_name, |
445 | option, | 446 | option, |
446 | &opt)); | 447 | &opt)); |
447 | if (NULL == (*ret = GNUNET_STRINGS_parse_ipv6_policy (opt))) | 448 | if (NULL == (*ret = GNUNET_STRINGS_parse_ipv6_policy(opt))) |
448 | { | 449 | { |
449 | LOG (GNUNET_ERROR_TYPE_WARNING, | 450 | LOG(GNUNET_ERROR_TYPE_WARNING, |
450 | _ ("Could not parse IPv6 network specification `%s' for `%s:%s'\n"), | 451 | _("Could not parse IPv6 network specification `%s' for `%s:%s'\n"), |
451 | opt, | 452 | opt, |
452 | sctx->service_name, | 453 | sctx->service_name, |
453 | option); | 454 | option); |
454 | GNUNET_free (opt); | 455 | GNUNET_free(opt); |
455 | return GNUNET_SYSERR; | 456 | return GNUNET_SYSERR; |
456 | } | 457 | } |
457 | GNUNET_free (opt); | 458 | GNUNET_free(opt); |
458 | return GNUNET_OK; | 459 | return GNUNET_OK; |
459 | } | 460 | } |
460 | 461 | ||
@@ -470,30 +471,30 @@ process_acl6 (struct GNUNET_STRINGS_IPv6NetworkPolicy **ret, | |||
470 | * parameter is ignore on systems other than LINUX | 471 | * parameter is ignore on systems other than LINUX |
471 | */ | 472 | */ |
472 | static void | 473 | static void |
473 | add_unixpath (struct sockaddr **saddrs, | 474 | add_unixpath(struct sockaddr **saddrs, |
474 | socklen_t *saddrlens, | 475 | socklen_t *saddrlens, |
475 | const char *unixpath, | 476 | const char *unixpath, |
476 | int abstract) | 477 | int abstract) |
477 | { | 478 | { |
478 | #ifdef AF_UNIX | 479 | #ifdef AF_UNIX |
479 | struct sockaddr_un *un; | 480 | struct sockaddr_un *un; |
480 | 481 | ||
481 | un = GNUNET_new (struct sockaddr_un); | 482 | un = GNUNET_new(struct sockaddr_un); |
482 | un->sun_family = AF_UNIX; | 483 | un->sun_family = AF_UNIX; |
483 | GNUNET_strlcpy (un->sun_path, unixpath, sizeof (un->sun_path)); | 484 | GNUNET_strlcpy(un->sun_path, unixpath, sizeof(un->sun_path)); |
484 | #ifdef LINUX | 485 | #ifdef LINUX |
485 | if (GNUNET_YES == abstract) | 486 | if (GNUNET_YES == abstract) |
486 | un->sun_path[0] = '\0'; | 487 | un->sun_path[0] = '\0'; |
487 | #endif | 488 | #endif |
488 | #if HAVE_SOCKADDR_UN_SUN_LEN | 489 | #if HAVE_SOCKADDR_UN_SUN_LEN |
489 | un->sun_len = (u_char) sizeof (struct sockaddr_un); | 490 | un->sun_len = (u_char)sizeof(struct sockaddr_un); |
490 | #endif | 491 | #endif |
491 | *saddrs = (struct sockaddr *) un; | 492 | *saddrs = (struct sockaddr *)un; |
492 | *saddrlens = sizeof (struct sockaddr_un); | 493 | *saddrlens = sizeof(struct sockaddr_un); |
493 | #else | 494 | #else |
494 | /* this function should never be called | 495 | /* this function should never be called |
495 | * unless AF_UNIX is defined! */ | 496 | * unless AF_UNIX is defined! */ |
496 | GNUNET_assert (0); | 497 | GNUNET_assert(0); |
497 | #endif | 498 | #endif |
498 | } | 499 | } |
499 | 500 | ||
@@ -519,7 +520,7 @@ add_unixpath (struct sockaddr **saddrs, | |||
519 | * set to NULL). | 520 | * set to NULL). |
520 | */ | 521 | */ |
521 | int | 522 | int |
522 | LEGACY_SERVICE_get_server_addresses ( | 523 | LEGACY_SERVICE_get_server_addresses( |
523 | const char *service_name, | 524 | const char *service_name, |
524 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 525 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
525 | struct sockaddr ***addrs, | 526 | struct sockaddr ***addrs, |
@@ -544,72 +545,72 @@ LEGACY_SERVICE_get_server_addresses ( | |||
544 | *addrs = NULL; | 545 | *addrs = NULL; |
545 | *addr_lens = NULL; | 546 | *addr_lens = NULL; |
546 | desc = NULL; | 547 | desc = NULL; |
547 | if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "DISABLEV6")) | 548 | if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "DISABLEV6")) |
548 | { | ||
549 | if (GNUNET_SYSERR == | ||
550 | (disablev6 = GNUNET_CONFIGURATION_get_value_yesno (cfg, | ||
551 | service_name, | ||
552 | "DISABLEV6"))) | ||
553 | return GNUNET_SYSERR; | ||
554 | } | ||
555 | else | ||
556 | disablev6 = GNUNET_NO; | ||
557 | |||
558 | if (! disablev6) | ||
559 | { | ||
560 | /* probe IPv6 support */ | ||
561 | desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0); | ||
562 | if (NULL == desc) | ||
563 | { | 549 | { |
564 | if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) || | 550 | if (GNUNET_SYSERR == |
565 | (EACCES == errno)) | 551 | (disablev6 = GNUNET_CONFIGURATION_get_value_yesno(cfg, |
566 | { | 552 | service_name, |
567 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket"); | 553 | "DISABLEV6"))) |
568 | return GNUNET_SYSERR; | 554 | return GNUNET_SYSERR; |
569 | } | ||
570 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
571 | _ ( | ||
572 | "Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"), | ||
573 | service_name, | ||
574 | strerror (errno)); | ||
575 | disablev6 = GNUNET_YES; | ||
576 | } | 555 | } |
577 | else | 556 | else |
557 | disablev6 = GNUNET_NO; | ||
558 | |||
559 | if (!disablev6) | ||
578 | { | 560 | { |
579 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc)); | 561 | /* probe IPv6 support */ |
580 | desc = NULL; | 562 | desc = GNUNET_NETWORK_socket_create(PF_INET6, SOCK_STREAM, 0); |
563 | if (NULL == desc) | ||
564 | { | ||
565 | if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) || | ||
566 | (EACCES == errno)) | ||
567 | { | ||
568 | LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "socket"); | ||
569 | return GNUNET_SYSERR; | ||
570 | } | ||
571 | LOG(GNUNET_ERROR_TYPE_INFO, | ||
572 | _( | ||
573 | "Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"), | ||
574 | service_name, | ||
575 | strerror(errno)); | ||
576 | disablev6 = GNUNET_YES; | ||
577 | } | ||
578 | else | ||
579 | { | ||
580 | GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(desc)); | ||
581 | desc = NULL; | ||
582 | } | ||
581 | } | 583 | } |
582 | } | ||
583 | 584 | ||
584 | port = 0; | 585 | port = 0; |
585 | if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT")) | 586 | if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "PORT")) |
586 | { | ||
587 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, | ||
588 | service_name, | ||
589 | "PORT", | ||
590 | &port)) | ||
591 | { | ||
592 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
593 | _ ("Require valid port number for service `%s' in configuration!\n"), | ||
594 | service_name); | ||
595 | } | ||
596 | if (port > 65535) | ||
597 | { | 587 | { |
598 | LOG (GNUNET_ERROR_TYPE_ERROR, | 588 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg, |
599 | _ ("Require valid port number for service `%s' in configuration!\n"), | 589 | service_name, |
600 | service_name); | 590 | "PORT", |
601 | return GNUNET_SYSERR; | 591 | &port)) |
592 | { | ||
593 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
594 | _("Require valid port number for service `%s' in configuration!\n"), | ||
595 | service_name); | ||
596 | } | ||
597 | if (port > 65535) | ||
598 | { | ||
599 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
600 | _("Require valid port number for service `%s' in configuration!\n"), | ||
601 | service_name); | ||
602 | return GNUNET_SYSERR; | ||
603 | } | ||
602 | } | 604 | } |
603 | } | ||
604 | 605 | ||
605 | if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO")) | 606 | if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "BINDTO")) |
606 | { | 607 | { |
607 | GNUNET_break (GNUNET_OK == | 608 | GNUNET_break(GNUNET_OK == |
608 | GNUNET_CONFIGURATION_get_value_string (cfg, | 609 | GNUNET_CONFIGURATION_get_value_string(cfg, |
609 | service_name, | 610 | service_name, |
610 | "BINDTO", | 611 | "BINDTO", |
611 | &hostname)); | 612 | &hostname)); |
612 | } | 613 | } |
613 | else | 614 | else |
614 | hostname = NULL; | 615 | hostname = NULL; |
615 | 616 | ||
@@ -617,232 +618,232 @@ LEGACY_SERVICE_get_server_addresses ( | |||
617 | abstract = GNUNET_NO; | 618 | abstract = GNUNET_NO; |
618 | #ifdef AF_UNIX | 619 | #ifdef AF_UNIX |
619 | if ((GNUNET_YES == | 620 | if ((GNUNET_YES == |
620 | GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) && | 621 | GNUNET_CONFIGURATION_have_value(cfg, service_name, "UNIXPATH")) && |
621 | (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg, | 622 | (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename(cfg, |
622 | service_name, | 623 | service_name, |
623 | "UNIXPATH", | 624 | "UNIXPATH", |
624 | &unixpath)) && | 625 | &unixpath)) && |
625 | (0 < strlen (unixpath))) | 626 | (0 < strlen(unixpath))) |
626 | { | ||
627 | /* probe UNIX support */ | ||
628 | struct sockaddr_un s_un; | ||
629 | |||
630 | if (strlen (unixpath) >= sizeof (s_un.sun_path)) | ||
631 | { | 627 | { |
632 | LOG (GNUNET_ERROR_TYPE_WARNING, | 628 | /* probe UNIX support */ |
633 | _ ("UNIXPATH `%s' too long, maximum length is %llu\n"), | 629 | struct sockaddr_un s_un; |
634 | unixpath, | 630 | |
635 | (unsigned long long) sizeof (s_un.sun_path)); | 631 | if (strlen(unixpath) >= sizeof(s_un.sun_path)) |
636 | unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath); | 632 | { |
637 | LOG (GNUNET_ERROR_TYPE_INFO, _ ("Using `%s' instead\n"), unixpath); | 633 | LOG(GNUNET_ERROR_TYPE_WARNING, |
638 | } | 634 | _("UNIXPATH `%s' too long, maximum length is %llu\n"), |
635 | unixpath, | ||
636 | (unsigned long long)sizeof(s_un.sun_path)); | ||
637 | unixpath = GNUNET_NETWORK_shorten_unixpath(unixpath); | ||
638 | LOG(GNUNET_ERROR_TYPE_INFO, _("Using `%s' instead\n"), unixpath); | ||
639 | } | ||
639 | #ifdef LINUX | 640 | #ifdef LINUX |
640 | abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, | 641 | abstract = GNUNET_CONFIGURATION_get_value_yesno(cfg, |
641 | "TESTING", | 642 | "TESTING", |
642 | "USE_ABSTRACT_SOCKETS"); | 643 | "USE_ABSTRACT_SOCKETS"); |
643 | if (GNUNET_SYSERR == abstract) | 644 | if (GNUNET_SYSERR == abstract) |
644 | abstract = GNUNET_NO; | 645 | abstract = GNUNET_NO; |
645 | #endif | 646 | #endif |
646 | if ((GNUNET_YES != abstract) && | 647 | if ((GNUNET_YES != abstract) && |
647 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file (unixpath))) | 648 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file(unixpath))) |
648 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkdir", unixpath); | 649 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "mkdir", unixpath); |
649 | } | ||
650 | if (NULL != unixpath) | ||
651 | { | ||
652 | desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); | ||
653 | if (NULL == desc) | ||
654 | { | ||
655 | if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) || | ||
656 | (EACCES == errno)) | ||
657 | { | ||
658 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket"); | ||
659 | GNUNET_free_non_null (hostname); | ||
660 | GNUNET_free (unixpath); | ||
661 | return GNUNET_SYSERR; | ||
662 | } | ||
663 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
664 | _ ( | ||
665 | "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"), | ||
666 | service_name, | ||
667 | strerror (errno)); | ||
668 | GNUNET_free (unixpath); | ||
669 | unixpath = NULL; | ||
670 | } | 650 | } |
671 | else | 651 | if (NULL != unixpath) |
672 | { | 652 | { |
673 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc)); | 653 | desc = GNUNET_NETWORK_socket_create(AF_UNIX, SOCK_STREAM, 0); |
674 | desc = NULL; | 654 | if (NULL == desc) |
655 | { | ||
656 | if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) || | ||
657 | (EACCES == errno)) | ||
658 | { | ||
659 | LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "socket"); | ||
660 | GNUNET_free_non_null(hostname); | ||
661 | GNUNET_free(unixpath); | ||
662 | return GNUNET_SYSERR; | ||
663 | } | ||
664 | LOG(GNUNET_ERROR_TYPE_INFO, | ||
665 | _( | ||
666 | "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"), | ||
667 | service_name, | ||
668 | strerror(errno)); | ||
669 | GNUNET_free(unixpath); | ||
670 | unixpath = NULL; | ||
671 | } | ||
672 | else | ||
673 | { | ||
674 | GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(desc)); | ||
675 | desc = NULL; | ||
676 | } | ||
675 | } | 677 | } |
676 | } | ||
677 | #endif | 678 | #endif |
678 | 679 | ||
679 | if ((0 == port) && (NULL == unixpath)) | 680 | if ((0 == port) && (NULL == unixpath)) |
680 | { | ||
681 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
682 | _ ( | ||
683 | "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"), | ||
684 | service_name); | ||
685 | GNUNET_free_non_null (hostname); | ||
686 | return GNUNET_SYSERR; | ||
687 | } | ||
688 | if (0 == port) | ||
689 | { | ||
690 | saddrs = GNUNET_malloc (2 * sizeof (struct sockaddr *)); | ||
691 | saddrlens = GNUNET_malloc (2 * sizeof (socklen_t)); | ||
692 | add_unixpath (saddrs, saddrlens, unixpath, abstract); | ||
693 | GNUNET_free_non_null (unixpath); | ||
694 | GNUNET_free_non_null (hostname); | ||
695 | *addrs = saddrs; | ||
696 | *addr_lens = saddrlens; | ||
697 | return 1; | ||
698 | } | ||
699 | |||
700 | if (NULL != hostname) | ||
701 | { | ||
702 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
703 | "Resolving `%s' since that is where `%s' will bind to.\n", | ||
704 | hostname, | ||
705 | service_name); | ||
706 | memset (&hints, 0, sizeof (struct addrinfo)); | ||
707 | if (disablev6) | ||
708 | hints.ai_family = AF_INET; | ||
709 | hints.ai_protocol = IPPROTO_TCP; | ||
710 | if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) || | ||
711 | (NULL == res)) | ||
712 | { | 681 | { |
713 | LOG (GNUNET_ERROR_TYPE_ERROR, | 682 | LOG(GNUNET_ERROR_TYPE_ERROR, |
714 | _ ("Failed to resolve `%s': %s\n"), | 683 | _( |
715 | hostname, | 684 | "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"), |
716 | gai_strerror (ret)); | 685 | service_name); |
717 | GNUNET_free (hostname); | 686 | GNUNET_free_non_null(hostname); |
718 | GNUNET_free_non_null (unixpath); | ||
719 | return GNUNET_SYSERR; | 687 | return GNUNET_SYSERR; |
720 | } | 688 | } |
721 | next = res; | 689 | if (0 == port) |
722 | i = 0; | ||
723 | while (NULL != (pos = next)) | ||
724 | { | ||
725 | next = pos->ai_next; | ||
726 | if ((disablev6) && (pos->ai_family == AF_INET6)) | ||
727 | continue; | ||
728 | i++; | ||
729 | } | ||
730 | if (0 == i) | ||
731 | { | ||
732 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
733 | _ ("Failed to find %saddress for `%s'.\n"), | ||
734 | disablev6 ? "IPv4 " : "", | ||
735 | hostname); | ||
736 | freeaddrinfo (res); | ||
737 | GNUNET_free (hostname); | ||
738 | GNUNET_free_non_null (unixpath); | ||
739 | return GNUNET_SYSERR; | ||
740 | } | ||
741 | resi = i; | ||
742 | if (NULL != unixpath) | ||
743 | resi++; | ||
744 | saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *)); | ||
745 | saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t)); | ||
746 | i = 0; | ||
747 | if (NULL != unixpath) | ||
748 | { | ||
749 | add_unixpath (saddrs, saddrlens, unixpath, abstract); | ||
750 | i++; | ||
751 | } | ||
752 | next = res; | ||
753 | while (NULL != (pos = next)) | ||
754 | { | 690 | { |
755 | next = pos->ai_next; | 691 | saddrs = GNUNET_malloc(2 * sizeof(struct sockaddr *)); |
756 | if ((disablev6) && (AF_INET6 == pos->ai_family)) | 692 | saddrlens = GNUNET_malloc(2 * sizeof(socklen_t)); |
757 | continue; | 693 | add_unixpath(saddrs, saddrlens, unixpath, abstract); |
758 | if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol)) | 694 | GNUNET_free_non_null(unixpath); |
759 | continue; /* not TCP */ | 695 | GNUNET_free_non_null(hostname); |
760 | if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype)) | 696 | *addrs = saddrs; |
761 | continue; /* huh? */ | 697 | *addr_lens = saddrlens; |
762 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 698 | return 1; |
763 | "Service `%s' will bind to `%s'\n", | ||
764 | service_name, | ||
765 | GNUNET_a2s (pos->ai_addr, pos->ai_addrlen)); | ||
766 | if (AF_INET == pos->ai_family) | ||
767 | { | ||
768 | GNUNET_assert (sizeof (struct sockaddr_in) == pos->ai_addrlen); | ||
769 | saddrlens[i] = pos->ai_addrlen; | ||
770 | saddrs[i] = GNUNET_malloc (saddrlens[i]); | ||
771 | GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]); | ||
772 | ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); | ||
773 | } | ||
774 | else | ||
775 | { | ||
776 | GNUNET_assert (AF_INET6 == pos->ai_family); | ||
777 | GNUNET_assert (sizeof (struct sockaddr_in6) == pos->ai_addrlen); | ||
778 | saddrlens[i] = pos->ai_addrlen; | ||
779 | saddrs[i] = GNUNET_malloc (saddrlens[i]); | ||
780 | GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]); | ||
781 | ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port); | ||
782 | } | ||
783 | i++; | ||
784 | } | 699 | } |
785 | GNUNET_free (hostname); | 700 | |
786 | freeaddrinfo (res); | 701 | if (NULL != hostname) |
787 | resi = i; | ||
788 | } | ||
789 | else | ||
790 | { | ||
791 | /* will bind against everything, just set port */ | ||
792 | if (disablev6) | ||
793 | { | 702 | { |
794 | /* V4-only */ | 703 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
795 | resi = 1; | 704 | "Resolving `%s' since that is where `%s' will bind to.\n", |
705 | hostname, | ||
706 | service_name); | ||
707 | memset(&hints, 0, sizeof(struct addrinfo)); | ||
708 | if (disablev6) | ||
709 | hints.ai_family = AF_INET; | ||
710 | hints.ai_protocol = IPPROTO_TCP; | ||
711 | if ((0 != (ret = getaddrinfo(hostname, NULL, &hints, &res))) || | ||
712 | (NULL == res)) | ||
713 | { | ||
714 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
715 | _("Failed to resolve `%s': %s\n"), | ||
716 | hostname, | ||
717 | gai_strerror(ret)); | ||
718 | GNUNET_free(hostname); | ||
719 | GNUNET_free_non_null(unixpath); | ||
720 | return GNUNET_SYSERR; | ||
721 | } | ||
722 | next = res; | ||
723 | i = 0; | ||
724 | while (NULL != (pos = next)) | ||
725 | { | ||
726 | next = pos->ai_next; | ||
727 | if ((disablev6) && (pos->ai_family == AF_INET6)) | ||
728 | continue; | ||
729 | i++; | ||
730 | } | ||
731 | if (0 == i) | ||
732 | { | ||
733 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
734 | _("Failed to find %saddress for `%s'.\n"), | ||
735 | disablev6 ? "IPv4 " : "", | ||
736 | hostname); | ||
737 | freeaddrinfo(res); | ||
738 | GNUNET_free(hostname); | ||
739 | GNUNET_free_non_null(unixpath); | ||
740 | return GNUNET_SYSERR; | ||
741 | } | ||
742 | resi = i; | ||
796 | if (NULL != unixpath) | 743 | if (NULL != unixpath) |
797 | resi++; | 744 | resi++; |
745 | saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *)); | ||
746 | saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t)); | ||
798 | i = 0; | 747 | i = 0; |
799 | saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *)); | ||
800 | saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t)); | ||
801 | if (NULL != unixpath) | 748 | if (NULL != unixpath) |
802 | { | 749 | { |
803 | add_unixpath (saddrs, saddrlens, unixpath, abstract); | 750 | add_unixpath(saddrs, saddrlens, unixpath, abstract); |
804 | i++; | 751 | i++; |
805 | } | 752 | } |
806 | saddrlens[i] = sizeof (struct sockaddr_in); | 753 | next = res; |
807 | saddrs[i] = GNUNET_malloc (saddrlens[i]); | 754 | while (NULL != (pos = next)) |
808 | #if HAVE_SOCKADDR_IN_SIN_LEN | 755 | { |
809 | ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i]; | 756 | next = pos->ai_next; |
810 | #endif | 757 | if ((disablev6) && (AF_INET6 == pos->ai_family)) |
811 | ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET; | 758 | continue; |
812 | ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); | 759 | if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol)) |
760 | continue; /* not TCP */ | ||
761 | if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype)) | ||
762 | continue; /* huh? */ | ||
763 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
764 | "Service `%s' will bind to `%s'\n", | ||
765 | service_name, | ||
766 | GNUNET_a2s(pos->ai_addr, pos->ai_addrlen)); | ||
767 | if (AF_INET == pos->ai_family) | ||
768 | { | ||
769 | GNUNET_assert(sizeof(struct sockaddr_in) == pos->ai_addrlen); | ||
770 | saddrlens[i] = pos->ai_addrlen; | ||
771 | saddrs[i] = GNUNET_malloc(saddrlens[i]); | ||
772 | GNUNET_memcpy(saddrs[i], pos->ai_addr, saddrlens[i]); | ||
773 | ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port); | ||
774 | } | ||
775 | else | ||
776 | { | ||
777 | GNUNET_assert(AF_INET6 == pos->ai_family); | ||
778 | GNUNET_assert(sizeof(struct sockaddr_in6) == pos->ai_addrlen); | ||
779 | saddrlens[i] = pos->ai_addrlen; | ||
780 | saddrs[i] = GNUNET_malloc(saddrlens[i]); | ||
781 | GNUNET_memcpy(saddrs[i], pos->ai_addr, saddrlens[i]); | ||
782 | ((struct sockaddr_in6 *)saddrs[i])->sin6_port = htons(port); | ||
783 | } | ||
784 | i++; | ||
785 | } | ||
786 | GNUNET_free(hostname); | ||
787 | freeaddrinfo(res); | ||
788 | resi = i; | ||
813 | } | 789 | } |
814 | else | 790 | else |
815 | { | 791 | { |
816 | /* dual stack */ | 792 | /* will bind against everything, just set port */ |
817 | resi = 2; | 793 | if (disablev6) |
818 | if (NULL != unixpath) | 794 | { |
819 | resi++; | 795 | /* V4-only */ |
820 | saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *)); | 796 | resi = 1; |
821 | saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t)); | 797 | if (NULL != unixpath) |
822 | i = 0; | 798 | resi++; |
823 | if (NULL != unixpath) | 799 | i = 0; |
824 | { | 800 | saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *)); |
825 | add_unixpath (saddrs, saddrlens, unixpath, abstract); | 801 | saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t)); |
826 | i++; | 802 | if (NULL != unixpath) |
827 | } | 803 | { |
828 | saddrlens[i] = sizeof (struct sockaddr_in6); | 804 | add_unixpath(saddrs, saddrlens, unixpath, abstract); |
829 | saddrs[i] = GNUNET_malloc (saddrlens[i]); | 805 | i++; |
806 | } | ||
807 | saddrlens[i] = sizeof(struct sockaddr_in); | ||
808 | saddrs[i] = GNUNET_malloc(saddrlens[i]); | ||
830 | #if HAVE_SOCKADDR_IN_SIN_LEN | 809 | #if HAVE_SOCKADDR_IN_SIN_LEN |
831 | ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0]; | 810 | ((struct sockaddr_in *)saddrs[i])->sin_len = saddrlens[i]; |
832 | #endif | 811 | #endif |
833 | ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6; | 812 | ((struct sockaddr_in *)saddrs[i])->sin_family = AF_INET; |
834 | ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port); | 813 | ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port); |
835 | i++; | 814 | } |
836 | saddrlens[i] = sizeof (struct sockaddr_in); | 815 | else |
837 | saddrs[i] = GNUNET_malloc (saddrlens[i]); | 816 | { |
817 | /* dual stack */ | ||
818 | resi = 2; | ||
819 | if (NULL != unixpath) | ||
820 | resi++; | ||
821 | saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *)); | ||
822 | saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t)); | ||
823 | i = 0; | ||
824 | if (NULL != unixpath) | ||
825 | { | ||
826 | add_unixpath(saddrs, saddrlens, unixpath, abstract); | ||
827 | i++; | ||
828 | } | ||
829 | saddrlens[i] = sizeof(struct sockaddr_in6); | ||
830 | saddrs[i] = GNUNET_malloc(saddrlens[i]); | ||
831 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
832 | ((struct sockaddr_in6 *)saddrs[i])->sin6_len = saddrlens[0]; | ||
833 | #endif | ||
834 | ((struct sockaddr_in6 *)saddrs[i])->sin6_family = AF_INET6; | ||
835 | ((struct sockaddr_in6 *)saddrs[i])->sin6_port = htons(port); | ||
836 | i++; | ||
837 | saddrlens[i] = sizeof(struct sockaddr_in); | ||
838 | saddrs[i] = GNUNET_malloc(saddrlens[i]); | ||
838 | #if HAVE_SOCKADDR_IN_SIN_LEN | 839 | #if HAVE_SOCKADDR_IN_SIN_LEN |
839 | ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1]; | 840 | ((struct sockaddr_in *)saddrs[i])->sin_len = saddrlens[1]; |
840 | #endif | 841 | #endif |
841 | ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET; | 842 | ((struct sockaddr_in *)saddrs[i])->sin_family = AF_INET; |
842 | ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); | 843 | ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port); |
844 | } | ||
843 | } | 845 | } |
844 | } | 846 | GNUNET_free_non_null(unixpath); |
845 | GNUNET_free_non_null (unixpath); | ||
846 | *addrs = saddrs; | 847 | *addrs = saddrs; |
847 | *addr_lens = saddrlens; | 848 | *addr_lens = saddrlens; |
848 | return resi; | 849 | return resi; |
@@ -858,7 +859,7 @@ LEGACY_SERVICE_get_server_addresses ( | |||
858 | * and #GNUNET_SYSERR on error. | 859 | * and #GNUNET_SYSERR on error. |
859 | */ | 860 | */ |
860 | static int | 861 | static int |
861 | receive_sockets_from_parent (struct LEGACY_SERVICE_Context *sctx) | 862 | receive_sockets_from_parent(struct LEGACY_SERVICE_Context *sctx) |
862 | { | 863 | { |
863 | const char *env_buf; | 864 | const char *env_buf; |
864 | int fail; | 865 | int fail; |
@@ -866,72 +867,73 @@ receive_sockets_from_parent (struct LEGACY_SERVICE_Context *sctx) | |||
866 | uint64_t i; | 867 | uint64_t i; |
867 | HANDLE lsocks_pipe; | 868 | HANDLE lsocks_pipe; |
868 | 869 | ||
869 | env_buf = getenv ("GNUNET_OS_READ_LSOCKS"); | 870 | env_buf = getenv("GNUNET_OS_READ_LSOCKS"); |
870 | if ((NULL == env_buf) || (strlen (env_buf) <= 0)) | 871 | if ((NULL == env_buf) || (strlen(env_buf) <= 0)) |
871 | return GNUNET_NO; | 872 | return GNUNET_NO; |
872 | /* Using W32 API directly here, because this pipe will | 873 | /* Using W32 API directly here, because this pipe will |
873 | * never be used outside of this function, and it's just too much of a bother | 874 | * never be used outside of this function, and it's just too much of a bother |
874 | * to create a GNUnet API that boxes a HANDLE (the way it is done with socks) | 875 | * to create a GNUnet API that boxes a HANDLE (the way it is done with socks) |
875 | */ | 876 | */ |
876 | lsocks_pipe = (HANDLE) strtoul (env_buf, NULL, 10); | 877 | lsocks_pipe = (HANDLE)strtoul(env_buf, NULL, 10); |
877 | if ((0 == lsocks_pipe) || (INVALID_HANDLE_VALUE == lsocks_pipe)) | 878 | if ((0 == lsocks_pipe) || (INVALID_HANDLE_VALUE == lsocks_pipe)) |
878 | return GNUNET_NO; | 879 | return GNUNET_NO; |
879 | fail = 1; | 880 | fail = 1; |
880 | do | 881 | do |
881 | { | ||
882 | int ret; | ||
883 | int fail2; | ||
884 | DWORD rd; | ||
885 | |||
886 | ret = ReadFile (lsocks_pipe, &count, sizeof (count), &rd, NULL); | ||
887 | if ((0 == ret) || (sizeof (count) != rd) || (0 == count)) | ||
888 | break; | ||
889 | sctx->lsocks = | ||
890 | GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (count + 1)); | ||
891 | |||
892 | fail2 = 1; | ||
893 | for (i = 0; i < count; i++) | ||
894 | { | 882 | { |
895 | WSAPROTOCOL_INFOA pi; | 883 | int ret; |
896 | uint64_t size; | 884 | int fail2; |
897 | SOCKET s; | 885 | DWORD rd; |
898 | 886 | ||
899 | ret = ReadFile (lsocks_pipe, &size, sizeof (size), &rd, NULL); | 887 | ret = ReadFile(lsocks_pipe, &count, sizeof(count), &rd, NULL); |
900 | if ((0 == ret) || (sizeof (size) != rd) || (sizeof (pi) != size)) | 888 | if ((0 == ret) || (sizeof(count) != rd) || (0 == count)) |
901 | break; | ||
902 | ret = ReadFile (lsocks_pipe, &pi, sizeof (pi), &rd, NULL); | ||
903 | if ((0 == ret) || (sizeof (pi) != rd)) | ||
904 | break; | 889 | break; |
905 | s = WSASocketA (pi.iAddressFamily, | 890 | sctx->lsocks = |
906 | pi.iSocketType, | 891 | GNUNET_malloc(sizeof(struct GNUNET_NETWORK_Handle *) * (count + 1)); |
907 | pi.iProtocol, | 892 | |
908 | &pi, | 893 | fail2 = 1; |
909 | 0, | 894 | for (i = 0; i < count; i++) |
910 | WSA_FLAG_OVERLAPPED); | 895 | { |
911 | sctx->lsocks[i] = GNUNET_NETWORK_socket_box_native (s); | 896 | WSAPROTOCOL_INFOA pi; |
912 | if (NULL == sctx->lsocks[i]) | 897 | uint64_t size; |
898 | SOCKET s; | ||
899 | |||
900 | ret = ReadFile(lsocks_pipe, &size, sizeof(size), &rd, NULL); | ||
901 | if ((0 == ret) || (sizeof(size) != rd) || (sizeof(pi) != size)) | ||
902 | break; | ||
903 | ret = ReadFile(lsocks_pipe, &pi, sizeof(pi), &rd, NULL); | ||
904 | if ((0 == ret) || (sizeof(pi) != rd)) | ||
905 | break; | ||
906 | s = WSASocketA(pi.iAddressFamily, | ||
907 | pi.iSocketType, | ||
908 | pi.iProtocol, | ||
909 | &pi, | ||
910 | 0, | ||
911 | WSA_FLAG_OVERLAPPED); | ||
912 | sctx->lsocks[i] = GNUNET_NETWORK_socket_box_native(s); | ||
913 | if (NULL == sctx->lsocks[i]) | ||
914 | break; | ||
915 | else if (i == count - 1) | ||
916 | fail2 = 0; | ||
917 | } | ||
918 | if (fail2) | ||
913 | break; | 919 | break; |
914 | else if (i == count - 1) | 920 | sctx->lsocks[count] = NULL; |
915 | fail2 = 0; | 921 | fail = 0; |
916 | } | 922 | } |
917 | if (fail2) | 923 | while (fail); |
918 | break; | ||
919 | sctx->lsocks[count] = NULL; | ||
920 | fail = 0; | ||
921 | } while (fail); | ||
922 | 924 | ||
923 | CloseHandle (lsocks_pipe); | 925 | CloseHandle(lsocks_pipe); |
924 | 926 | ||
925 | if (fail) | 927 | if (fail) |
926 | { | 928 | { |
927 | LOG (GNUNET_ERROR_TYPE_ERROR, | 929 | LOG(GNUNET_ERROR_TYPE_ERROR, |
928 | _ ("Could not access a pre-bound socket, will try to bind myself\n")); | 930 | _("Could not access a pre-bound socket, will try to bind myself\n")); |
929 | for (i = 0; (i < count) && (NULL != sctx->lsocks[i]); i++) | 931 | for (i = 0; (i < count) && (NULL != sctx->lsocks[i]); i++) |
930 | GNUNET_break (0 == GNUNET_NETWORK_socket_close (sctx->lsocks[i])); | 932 | GNUNET_break(0 == GNUNET_NETWORK_socket_close(sctx->lsocks[i])); |
931 | GNUNET_free_non_null (sctx->lsocks); | 933 | GNUNET_free_non_null(sctx->lsocks); |
932 | sctx->lsocks = NULL; | 934 | sctx->lsocks = NULL; |
933 | return GNUNET_NO; | 935 | return GNUNET_NO; |
934 | } | 936 | } |
935 | return GNUNET_YES; | 937 | return GNUNET_YES; |
936 | } | 938 | } |
937 | #endif | 939 | #endif |
@@ -956,7 +958,7 @@ receive_sockets_from_parent (struct LEGACY_SERVICE_Context *sctx) | |||
956 | * @return #GNUNET_OK if configuration succeeded | 958 | * @return #GNUNET_OK if configuration succeeded |
957 | */ | 959 | */ |
958 | static int | 960 | static int |
959 | setup_service (struct LEGACY_SERVICE_Context *sctx) | 961 | setup_service(struct LEGACY_SERVICE_Context *sctx) |
960 | { | 962 | { |
961 | struct GNUNET_TIME_Relative idleout; | 963 | struct GNUNET_TIME_Relative idleout; |
962 | int tolerant; | 964 | int tolerant; |
@@ -967,99 +969,99 @@ setup_service (struct LEGACY_SERVICE_Context *sctx) | |||
967 | int flags; | 969 | int flags; |
968 | #endif | 970 | #endif |
969 | 971 | ||
970 | if (GNUNET_CONFIGURATION_have_value (sctx->cfg, | 972 | if (GNUNET_CONFIGURATION_have_value(sctx->cfg, |
971 | sctx->service_name, | 973 | sctx->service_name, |
972 | "TIMEOUT")) | 974 | "TIMEOUT")) |
973 | { | ||
974 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (sctx->cfg, | ||
975 | sctx->service_name, | ||
976 | "TIMEOUT", | ||
977 | &idleout)) | ||
978 | { | 975 | { |
979 | LOG (GNUNET_ERROR_TYPE_ERROR, | 976 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(sctx->cfg, |
980 | _ ("Specified value for `%s' of service `%s' is invalid\n"), | 977 | sctx->service_name, |
981 | "TIMEOUT", | 978 | "TIMEOUT", |
982 | sctx->service_name); | 979 | &idleout)) |
983 | return GNUNET_SYSERR; | 980 | { |
981 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
982 | _("Specified value for `%s' of service `%s' is invalid\n"), | ||
983 | "TIMEOUT", | ||
984 | sctx->service_name); | ||
985 | return GNUNET_SYSERR; | ||
986 | } | ||
987 | sctx->timeout = idleout; | ||
984 | } | 988 | } |
985 | sctx->timeout = idleout; | ||
986 | } | ||
987 | else | 989 | else |
988 | sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL; | 990 | sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL; |
989 | 991 | ||
990 | if (GNUNET_CONFIGURATION_have_value (sctx->cfg, | 992 | if (GNUNET_CONFIGURATION_have_value(sctx->cfg, |
991 | sctx->service_name, | 993 | sctx->service_name, |
992 | "TOLERANT")) | 994 | "TOLERANT")) |
993 | { | ||
994 | if (GNUNET_SYSERR == | ||
995 | (tolerant = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, | ||
996 | sctx->service_name, | ||
997 | "TOLERANT"))) | ||
998 | { | 995 | { |
999 | LOG (GNUNET_ERROR_TYPE_ERROR, | 996 | if (GNUNET_SYSERR == |
1000 | _ ("Specified value for `%s' of service `%s' is invalid\n"), | 997 | (tolerant = GNUNET_CONFIGURATION_get_value_yesno(sctx->cfg, |
1001 | "TOLERANT", | 998 | sctx->service_name, |
1002 | sctx->service_name); | 999 | "TOLERANT"))) |
1003 | return GNUNET_SYSERR; | 1000 | { |
1001 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
1002 | _("Specified value for `%s' of service `%s' is invalid\n"), | ||
1003 | "TOLERANT", | ||
1004 | sctx->service_name); | ||
1005 | return GNUNET_SYSERR; | ||
1006 | } | ||
1004 | } | 1007 | } |
1005 | } | ||
1006 | else | 1008 | else |
1007 | tolerant = GNUNET_NO; | 1009 | tolerant = GNUNET_NO; |
1008 | 1010 | ||
1009 | #ifndef MINGW | 1011 | #ifndef MINGW |
1010 | errno = 0; | 1012 | errno = 0; |
1011 | if ((NULL != (nfds = getenv ("LISTEN_FDS"))) && | 1013 | if ((NULL != (nfds = getenv("LISTEN_FDS"))) && |
1012 | (1 == sscanf (nfds, "%u", &cnt)) && (cnt > 0) && (cnt < FD_SETSIZE) && | 1014 | (1 == sscanf(nfds, "%u", &cnt)) && (cnt > 0) && (cnt < FD_SETSIZE) && |
1013 | (cnt + 4 < FD_SETSIZE)) | 1015 | (cnt + 4 < FD_SETSIZE)) |
1014 | { | ||
1015 | sctx->lsocks = | ||
1016 | GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (cnt + 1)); | ||
1017 | while (0 < cnt--) | ||
1018 | { | 1016 | { |
1019 | flags = fcntl (3 + cnt, F_GETFD); | 1017 | sctx->lsocks = |
1020 | if ((flags < 0) || (0 != (flags & FD_CLOEXEC)) || | 1018 | GNUNET_malloc(sizeof(struct GNUNET_NETWORK_Handle *) * (cnt + 1)); |
1021 | (NULL == | 1019 | while (0 < cnt--) |
1022 | (sctx->lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt)))) | 1020 | { |
1023 | { | 1021 | flags = fcntl(3 + cnt, F_GETFD); |
1024 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1022 | if ((flags < 0) || (0 != (flags & FD_CLOEXEC)) || |
1025 | _ ( | 1023 | (NULL == |
1026 | "Could not access pre-bound socket %u, will try to bind myself\n"), | 1024 | (sctx->lsocks[cnt] = GNUNET_NETWORK_socket_box_native(3 + cnt)))) |
1027 | (unsigned int) 3 + cnt); | 1025 | { |
1028 | cnt++; | 1026 | LOG(GNUNET_ERROR_TYPE_ERROR, |
1029 | while (sctx->lsocks[cnt] != NULL) | 1027 | _( |
1030 | GNUNET_break (0 == GNUNET_NETWORK_socket_close (sctx->lsocks[cnt++])); | 1028 | "Could not access pre-bound socket %u, will try to bind myself\n"), |
1031 | GNUNET_free (sctx->lsocks); | 1029 | (unsigned int)3 + cnt); |
1032 | sctx->lsocks = NULL; | 1030 | cnt++; |
1033 | break; | 1031 | while (sctx->lsocks[cnt] != NULL) |
1034 | } | 1032 | GNUNET_break(0 == GNUNET_NETWORK_socket_close(sctx->lsocks[cnt++])); |
1033 | GNUNET_free(sctx->lsocks); | ||
1034 | sctx->lsocks = NULL; | ||
1035 | break; | ||
1036 | } | ||
1037 | } | ||
1038 | unsetenv("LISTEN_FDS"); | ||
1035 | } | 1039 | } |
1036 | unsetenv ("LISTEN_FDS"); | ||
1037 | } | ||
1038 | #else | 1040 | #else |
1039 | if (getenv ("GNUNET_OS_READ_LSOCKS") != NULL) | 1041 | if (getenv("GNUNET_OS_READ_LSOCKS") != NULL) |
1040 | { | 1042 | { |
1041 | receive_sockets_from_parent (sctx); | 1043 | receive_sockets_from_parent(sctx); |
1042 | putenv ("GNUNET_OS_READ_LSOCKS="); | 1044 | putenv("GNUNET_OS_READ_LSOCKS="); |
1043 | } | 1045 | } |
1044 | #endif | 1046 | #endif |
1045 | 1047 | ||
1046 | if ((NULL == sctx->lsocks) && | 1048 | if ((NULL == sctx->lsocks) && |
1047 | (GNUNET_SYSERR == LEGACY_SERVICE_get_server_addresses (sctx->service_name, | 1049 | (GNUNET_SYSERR == LEGACY_SERVICE_get_server_addresses(sctx->service_name, |
1048 | sctx->cfg, | 1050 | sctx->cfg, |
1049 | &sctx->addrs, | 1051 | &sctx->addrs, |
1050 | &sctx->addrlens))) | 1052 | &sctx->addrlens))) |
1051 | return GNUNET_SYSERR; | 1053 | return GNUNET_SYSERR; |
1052 | sctx->require_found = tolerant ? GNUNET_NO : GNUNET_YES; | 1054 | sctx->require_found = tolerant ? GNUNET_NO : GNUNET_YES; |
1053 | sctx->match_uid = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, | 1055 | sctx->match_uid = GNUNET_CONFIGURATION_get_value_yesno(sctx->cfg, |
1054 | sctx->service_name, | 1056 | sctx->service_name, |
1055 | "UNIX_MATCH_UID"); | 1057 | "UNIX_MATCH_UID"); |
1056 | sctx->match_gid = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, | 1058 | sctx->match_gid = GNUNET_CONFIGURATION_get_value_yesno(sctx->cfg, |
1057 | sctx->service_name, | 1059 | sctx->service_name, |
1058 | "UNIX_MATCH_GID"); | 1060 | "UNIX_MATCH_GID"); |
1059 | process_acl4 (&sctx->v4_denied, sctx, "REJECT_FROM"); | 1061 | process_acl4(&sctx->v4_denied, sctx, "REJECT_FROM"); |
1060 | process_acl4 (&sctx->v4_allowed, sctx, "ACCEPT_FROM"); | 1062 | process_acl4(&sctx->v4_allowed, sctx, "ACCEPT_FROM"); |
1061 | process_acl6 (&sctx->v6_denied, sctx, "REJECT_FROM6"); | 1063 | process_acl6(&sctx->v6_denied, sctx, "REJECT_FROM6"); |
1062 | process_acl6 (&sctx->v6_allowed, sctx, "ACCEPT_FROM6"); | 1064 | process_acl6(&sctx->v6_allowed, sctx, "ACCEPT_FROM6"); |
1063 | 1065 | ||
1064 | return GNUNET_OK; | 1066 | return GNUNET_OK; |
1065 | } | 1067 | } |
@@ -1073,14 +1075,14 @@ setup_service (struct LEGACY_SERVICE_Context *sctx) | |||
1073 | * @return value of the 'USERNAME' option | 1075 | * @return value of the 'USERNAME' option |
1074 | */ | 1076 | */ |
1075 | static char * | 1077 | static char * |
1076 | get_user_name (struct LEGACY_SERVICE_Context *sctx) | 1078 | get_user_name(struct LEGACY_SERVICE_Context *sctx) |
1077 | { | 1079 | { |
1078 | char *un; | 1080 | char *un; |
1079 | 1081 | ||
1080 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, | 1082 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(sctx->cfg, |
1081 | sctx->service_name, | 1083 | sctx->service_name, |
1082 | "USERNAME", | 1084 | "USERNAME", |
1083 | &un)) | 1085 | &un)) |
1084 | return NULL; | 1086 | return NULL; |
1085 | return un; | 1087 | return un; |
1086 | } | 1088 | } |
@@ -1094,7 +1096,7 @@ get_user_name (struct LEGACY_SERVICE_Context *sctx) | |||
1094 | * @return #GNUNET_OK on success (including no work to be done) | 1096 | * @return #GNUNET_OK on success (including no work to be done) |
1095 | */ | 1097 | */ |
1096 | static int | 1098 | static int |
1097 | write_pid_file (struct LEGACY_SERVICE_Context *sctx, pid_t pid) | 1099 | write_pid_file(struct LEGACY_SERVICE_Context *sctx, pid_t pid) |
1098 | { | 1100 | { |
1099 | FILE *pidfd; | 1101 | FILE *pidfd; |
1100 | char *pif; | 1102 | char *pif; |
@@ -1102,46 +1104,46 @@ write_pid_file (struct LEGACY_SERVICE_Context *sctx, pid_t pid) | |||
1102 | char *rdir; | 1104 | char *rdir; |
1103 | int len; | 1105 | int len; |
1104 | 1106 | ||
1105 | if (NULL == (pif = get_pid_file_name (sctx))) | 1107 | if (NULL == (pif = get_pid_file_name(sctx))) |
1106 | return GNUNET_OK; /* no file desired */ | 1108 | return GNUNET_OK; /* no file desired */ |
1107 | user = get_user_name (sctx); | 1109 | user = get_user_name(sctx); |
1108 | rdir = GNUNET_strdup (pif); | 1110 | rdir = GNUNET_strdup(pif); |
1109 | len = strlen (rdir); | 1111 | len = strlen(rdir); |
1110 | while ((len > 0) && (rdir[len] != DIR_SEPARATOR)) | 1112 | while ((len > 0) && (rdir[len] != DIR_SEPARATOR)) |
1111 | len--; | 1113 | len--; |
1112 | rdir[len] = '\0'; | 1114 | rdir[len] = '\0'; |
1113 | if (0 != access (rdir, F_OK)) | 1115 | if (0 != access(rdir, F_OK)) |
1114 | { | 1116 | { |
1115 | /* we get to create a directory -- and claim it | 1117 | /* we get to create a directory -- and claim it |
1116 | * as ours! */ | 1118 | * as ours! */ |
1117 | (void) GNUNET_DISK_directory_create (rdir); | 1119 | (void)GNUNET_DISK_directory_create(rdir); |
1118 | if ((NULL != user) && (0 < strlen (user))) | 1120 | if ((NULL != user) && (0 < strlen(user))) |
1119 | GNUNET_DISK_file_change_owner (rdir, user); | 1121 | GNUNET_DISK_file_change_owner(rdir, user); |
1120 | } | 1122 | } |
1121 | if (0 != access (rdir, W_OK | X_OK)) | 1123 | if (0 != access(rdir, W_OK | X_OK)) |
1122 | { | 1124 | { |
1123 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", rdir); | 1125 | LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_ERROR, "access", rdir); |
1124 | GNUNET_free (rdir); | 1126 | GNUNET_free(rdir); |
1125 | GNUNET_free_non_null (user); | 1127 | GNUNET_free_non_null(user); |
1126 | GNUNET_free (pif); | 1128 | GNUNET_free(pif); |
1127 | return GNUNET_SYSERR; | 1129 | return GNUNET_SYSERR; |
1128 | } | 1130 | } |
1129 | GNUNET_free (rdir); | 1131 | GNUNET_free(rdir); |
1130 | pidfd = fopen (pif, "w"); | 1132 | pidfd = fopen(pif, "w"); |
1131 | if (NULL == pidfd) | 1133 | if (NULL == pidfd) |
1132 | { | 1134 | { |
1133 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "fopen", pif); | 1135 | LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_ERROR, "fopen", pif); |
1134 | GNUNET_free (pif); | 1136 | GNUNET_free(pif); |
1135 | GNUNET_free_non_null (user); | 1137 | GNUNET_free_non_null(user); |
1136 | return GNUNET_SYSERR; | 1138 | return GNUNET_SYSERR; |
1137 | } | 1139 | } |
1138 | if (0 > fprintf (pidfd, "%u", pid)) | 1140 | if (0 > fprintf(pidfd, "%u", pid)) |
1139 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fprintf", pif); | 1141 | LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_WARNING, "fprintf", pif); |
1140 | GNUNET_break (0 == fclose (pidfd)); | 1142 | GNUNET_break(0 == fclose(pidfd)); |
1141 | if ((NULL != user) && (0 < strlen (user))) | 1143 | if ((NULL != user) && (0 < strlen(user))) |
1142 | GNUNET_DISK_file_change_owner (pif, user); | 1144 | GNUNET_DISK_file_change_owner(pif, user); |
1143 | GNUNET_free_non_null (user); | 1145 | GNUNET_free_non_null(user); |
1144 | GNUNET_free (pif); | 1146 | GNUNET_free(pif); |
1145 | return GNUNET_OK; | 1147 | return GNUNET_OK; |
1146 | } | 1148 | } |
1147 | 1149 | ||
@@ -1152,16 +1154,16 @@ write_pid_file (struct LEGACY_SERVICE_Context *sctx, pid_t pid) | |||
1152 | * @param cls the `struct LEGACY_SERVICE_Context` | 1154 | * @param cls the `struct LEGACY_SERVICE_Context` |
1153 | */ | 1155 | */ |
1154 | static void | 1156 | static void |
1155 | shutdown_task (void *cls) | 1157 | shutdown_task(void *cls) |
1156 | { | 1158 | { |
1157 | struct LEGACY_SERVICE_Context *service = cls; | 1159 | struct LEGACY_SERVICE_Context *service = cls; |
1158 | struct GNUNET_SERVER_Handle *server = service->server; | 1160 | struct GNUNET_SERVER_Handle *server = service->server; |
1159 | 1161 | ||
1160 | service->shutdown_task = NULL; | 1162 | service->shutdown_task = NULL; |
1161 | if (0 != (service->options & LEGACY_SERVICE_OPTION_SOFT_SHUTDOWN)) | 1163 | if (0 != (service->options & LEGACY_SERVICE_OPTION_SOFT_SHUTDOWN)) |
1162 | GNUNET_SERVER_stop_listening (server); | 1164 | GNUNET_SERVER_stop_listening(server); |
1163 | else | 1165 | else |
1164 | GNUNET_SERVER_destroy (server); | 1166 | GNUNET_SERVER_destroy(server); |
1165 | } | 1167 | } |
1166 | 1168 | ||
1167 | 1169 | ||
@@ -1171,81 +1173,81 @@ shutdown_task (void *cls) | |||
1171 | * @param cls service context | 1173 | * @param cls service context |
1172 | */ | 1174 | */ |
1173 | static void | 1175 | static void |
1174 | service_task (void *cls) | 1176 | service_task(void *cls) |
1175 | { | 1177 | { |
1176 | struct LEGACY_SERVICE_Context *sctx = cls; | 1178 | struct LEGACY_SERVICE_Context *sctx = cls; |
1177 | unsigned int i; | 1179 | unsigned int i; |
1178 | 1180 | ||
1179 | GNUNET_RESOLVER_connect (sctx->cfg); | 1181 | GNUNET_RESOLVER_connect(sctx->cfg); |
1180 | if (NULL != sctx->lsocks) | 1182 | if (NULL != sctx->lsocks) |
1181 | sctx->server = GNUNET_SERVER_create_with_sockets (&check_access, | 1183 | sctx->server = GNUNET_SERVER_create_with_sockets(&check_access, |
1182 | sctx, | 1184 | sctx, |
1183 | sctx->lsocks, | 1185 | sctx->lsocks, |
1184 | sctx->timeout, | 1186 | sctx->timeout, |
1185 | sctx->require_found); | 1187 | sctx->require_found); |
1186 | else | 1188 | else |
1187 | sctx->server = GNUNET_SERVER_create (&check_access, | 1189 | sctx->server = GNUNET_SERVER_create(&check_access, |
1188 | sctx, | 1190 | sctx, |
1189 | sctx->addrs, | 1191 | sctx->addrs, |
1190 | sctx->addrlens, | 1192 | sctx->addrlens, |
1191 | sctx->timeout, | 1193 | sctx->timeout, |
1192 | sctx->require_found); | 1194 | sctx->require_found); |
1193 | if (NULL == sctx->server) | 1195 | if (NULL == sctx->server) |
1194 | { | 1196 | { |
1195 | if (NULL != sctx->addrs) | 1197 | if (NULL != sctx->addrs) |
1196 | for (i = 0; NULL != sctx->addrs[i]; i++) | 1198 | for (i = 0; NULL != sctx->addrs[i]; i++) |
1197 | LOG (GNUNET_ERROR_TYPE_INFO, | 1199 | LOG(GNUNET_ERROR_TYPE_INFO, |
1198 | _ ("Failed to start `%s' at `%s'\n"), | 1200 | _("Failed to start `%s' at `%s'\n"), |
1199 | sctx->service_name, | 1201 | sctx->service_name, |
1200 | GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i])); | 1202 | GNUNET_a2s(sctx->addrs[i], sctx->addrlens[i])); |
1201 | sctx->ret = GNUNET_SYSERR; | 1203 | sctx->ret = GNUNET_SYSERR; |
1202 | return; | 1204 | return; |
1203 | } | 1205 | } |
1204 | #ifndef WINDOWS | 1206 | #ifndef WINDOWS |
1205 | if (NULL != sctx->addrs) | 1207 | if (NULL != sctx->addrs) |
1206 | for (i = 0; NULL != sctx->addrs[i]; i++) | 1208 | for (i = 0; NULL != sctx->addrs[i]; i++) |
1207 | if ((AF_UNIX == sctx->addrs[i]->sa_family) && | 1209 | if ((AF_UNIX == sctx->addrs[i]->sa_family) && |
1208 | ('\0' != ((const struct sockaddr_un *) sctx->addrs[i])->sun_path[0])) | 1210 | ('\0' != ((const struct sockaddr_un *)sctx->addrs[i])->sun_path[0])) |
1209 | GNUNET_DISK_fix_permissions (((const struct sockaddr_un *) | 1211 | GNUNET_DISK_fix_permissions(((const struct sockaddr_un *) |
1210 | sctx->addrs[i]) | 1212 | sctx->addrs[i]) |
1211 | ->sun_path, | 1213 | ->sun_path, |
1212 | sctx->match_uid, | 1214 | sctx->match_uid, |
1213 | sctx->match_gid); | 1215 | sctx->match_gid); |
1214 | #endif | 1216 | #endif |
1215 | 1217 | ||
1216 | 1218 | ||
1217 | if (0 == (sctx->options & LEGACY_SERVICE_OPTION_MANUAL_SHUTDOWN)) | 1219 | if (0 == (sctx->options & LEGACY_SERVICE_OPTION_MANUAL_SHUTDOWN)) |
1218 | { | 1220 | { |
1219 | /* install a task that will kill the server | 1221 | /* install a task that will kill the server |
1220 | * process if the scheduler ever gets a shutdown signal */ | 1222 | * process if the scheduler ever gets a shutdown signal */ |
1221 | sctx->shutdown_task = GNUNET_SCHEDULER_add_shutdown (&shutdown_task, sctx); | 1223 | sctx->shutdown_task = GNUNET_SCHEDULER_add_shutdown(&shutdown_task, sctx); |
1222 | } | 1224 | } |
1223 | sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers)); | 1225 | sctx->my_handlers = GNUNET_malloc(sizeof(defhandlers)); |
1224 | GNUNET_memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers)); | 1226 | GNUNET_memcpy(sctx->my_handlers, defhandlers, sizeof(defhandlers)); |
1225 | i = 0; | 1227 | i = 0; |
1226 | while (NULL != sctx->my_handlers[i].callback) | 1228 | while (NULL != sctx->my_handlers[i].callback) |
1227 | sctx->my_handlers[i++].callback_cls = sctx; | 1229 | sctx->my_handlers[i++].callback_cls = sctx; |
1228 | GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers); | 1230 | GNUNET_SERVER_add_handlers(sctx->server, sctx->my_handlers); |
1229 | if (-1 != sctx->ready_confirm_fd) | 1231 | if (-1 != sctx->ready_confirm_fd) |
1230 | { | 1232 | { |
1231 | GNUNET_break (1 == write (sctx->ready_confirm_fd, ".", 1)); | 1233 | GNUNET_break(1 == write(sctx->ready_confirm_fd, ".", 1)); |
1232 | GNUNET_break (0 == close (sctx->ready_confirm_fd)); | 1234 | GNUNET_break(0 == close(sctx->ready_confirm_fd)); |
1233 | sctx->ready_confirm_fd = -1; | 1235 | sctx->ready_confirm_fd = -1; |
1234 | write_pid_file (sctx, getpid ()); | 1236 | write_pid_file(sctx, getpid()); |
1235 | } | 1237 | } |
1236 | if (NULL != sctx->addrs) | 1238 | if (NULL != sctx->addrs) |
1237 | { | ||
1238 | i = 0; | ||
1239 | while (NULL != sctx->addrs[i]) | ||
1240 | { | 1239 | { |
1241 | LOG (GNUNET_ERROR_TYPE_INFO, | 1240 | i = 0; |
1242 | _ ("Service `%s' runs at %s\n"), | 1241 | while (NULL != sctx->addrs[i]) |
1243 | sctx->service_name, | 1242 | { |
1244 | GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i])); | 1243 | LOG(GNUNET_ERROR_TYPE_INFO, |
1245 | i++; | 1244 | _("Service `%s' runs at %s\n"), |
1245 | sctx->service_name, | ||
1246 | GNUNET_a2s(sctx->addrs[i], sctx->addrlens[i])); | ||
1247 | i++; | ||
1248 | } | ||
1246 | } | 1249 | } |
1247 | } | 1250 | sctx->task(sctx->task_cls, sctx->server, sctx->cfg); |
1248 | sctx->task (sctx->task_cls, sctx->server, sctx->cfg); | ||
1249 | } | 1251 | } |
1250 | 1252 | ||
1251 | 1253 | ||
@@ -1256,76 +1258,79 @@ service_task (void *cls) | |||
1256 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 1258 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
1257 | */ | 1259 | */ |
1258 | static int | 1260 | static int |
1259 | detach_terminal (struct LEGACY_SERVICE_Context *sctx) | 1261 | detach_terminal(struct LEGACY_SERVICE_Context *sctx) |
1260 | { | 1262 | { |
1261 | #ifndef MINGW | 1263 | #ifndef MINGW |
1262 | pid_t pid; | 1264 | pid_t pid; |
1263 | int nullfd; | 1265 | int nullfd; |
1264 | int filedes[2]; | 1266 | int filedes[2]; |
1265 | 1267 | ||
1266 | if (0 != pipe (filedes)) | 1268 | if (0 != pipe(filedes)) |
1267 | { | 1269 | { |
1268 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe"); | 1270 | LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "pipe"); |
1269 | return GNUNET_SYSERR; | 1271 | return GNUNET_SYSERR; |
1270 | } | 1272 | } |
1271 | pid = fork (); | 1273 | pid = fork(); |
1272 | if (pid < 0) | 1274 | if (pid < 0) |
1273 | { | 1275 | { |
1274 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork"); | 1276 | LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "fork"); |
1275 | return GNUNET_SYSERR; | 1277 | return GNUNET_SYSERR; |
1276 | } | 1278 | } |
1277 | if (0 != pid) | 1279 | if (0 != pid) |
1278 | { | ||
1279 | /* Parent */ | ||
1280 | char c; | ||
1281 | |||
1282 | GNUNET_break (0 == close (filedes[1])); | ||
1283 | c = 'X'; | ||
1284 | if (1 != read (filedes[0], &c, sizeof (char))) | ||
1285 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "read"); | ||
1286 | fflush (stdout); | ||
1287 | switch (c) | ||
1288 | { | 1280 | { |
1289 | case '.': | 1281 | /* Parent */ |
1290 | exit (0); | 1282 | char c; |
1291 | case 'I': | 1283 | |
1292 | LOG (GNUNET_ERROR_TYPE_INFO, | 1284 | GNUNET_break(0 == close(filedes[1])); |
1293 | _ ("Service process failed to initialize\n")); | 1285 | c = 'X'; |
1294 | break; | 1286 | if (1 != read(filedes[0], &c, sizeof(char))) |
1295 | case 'S': | 1287 | LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, "read"); |
1296 | LOG (GNUNET_ERROR_TYPE_INFO, | 1288 | fflush(stdout); |
1297 | _ ("Service process could not initialize server function\n")); | 1289 | switch (c) |
1298 | break; | 1290 | { |
1299 | case 'X': | 1291 | case '.': |
1300 | LOG (GNUNET_ERROR_TYPE_INFO, | 1292 | exit(0); |
1301 | _ ("Service process failed to report status\n")); | 1293 | |
1302 | break; | 1294 | case 'I': |
1295 | LOG(GNUNET_ERROR_TYPE_INFO, | ||
1296 | _("Service process failed to initialize\n")); | ||
1297 | break; | ||
1298 | |||
1299 | case 'S': | ||
1300 | LOG(GNUNET_ERROR_TYPE_INFO, | ||
1301 | _("Service process could not initialize server function\n")); | ||
1302 | break; | ||
1303 | |||
1304 | case 'X': | ||
1305 | LOG(GNUNET_ERROR_TYPE_INFO, | ||
1306 | _("Service process failed to report status\n")); | ||
1307 | break; | ||
1308 | } | ||
1309 | exit(1); /* child reported error */ | ||
1303 | } | 1310 | } |
1304 | exit (1); /* child reported error */ | 1311 | GNUNET_break(0 == close(0)); |
1305 | } | 1312 | GNUNET_break(0 == close(1)); |
1306 | GNUNET_break (0 == close (0)); | 1313 | GNUNET_break(0 == close(filedes[0])); |
1307 | GNUNET_break (0 == close (1)); | 1314 | nullfd = open("/dev/null", O_RDWR | O_APPEND); |
1308 | GNUNET_break (0 == close (filedes[0])); | ||
1309 | nullfd = open ("/dev/null", O_RDWR | O_APPEND); | ||
1310 | if (nullfd < 0) | 1315 | if (nullfd < 0) |
1311 | return GNUNET_SYSERR; | 1316 | return GNUNET_SYSERR; |
1312 | /* set stdin/stdout to /dev/null */ | 1317 | /* set stdin/stdout to /dev/null */ |
1313 | if ((dup2 (nullfd, 0) < 0) || (dup2 (nullfd, 1) < 0)) | 1318 | if ((dup2(nullfd, 0) < 0) || (dup2(nullfd, 1) < 0)) |
1314 | { | 1319 | { |
1315 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2"); | 1320 | LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "dup2"); |
1316 | (void) close (nullfd); | 1321 | (void)close(nullfd); |
1317 | return GNUNET_SYSERR; | 1322 | return GNUNET_SYSERR; |
1318 | } | 1323 | } |
1319 | (void) close (nullfd); | 1324 | (void)close(nullfd); |
1320 | /* Detach from controlling terminal */ | 1325 | /* Detach from controlling terminal */ |
1321 | pid = setsid (); | 1326 | pid = setsid(); |
1322 | if (-1 == pid) | 1327 | if (-1 == pid) |
1323 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "setsid"); | 1328 | LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "setsid"); |
1324 | sctx->ready_confirm_fd = filedes[1]; | 1329 | sctx->ready_confirm_fd = filedes[1]; |
1325 | #else | 1330 | #else |
1326 | /* FIXME: we probably need to do something else | 1331 | /* FIXME: we probably need to do something else |
1327 | * elsewhere in order to fork the process itself... */ | 1332 | * elsewhere in order to fork the process itself... */ |
1328 | FreeConsole (); | 1333 | FreeConsole(); |
1329 | #endif | 1334 | #endif |
1330 | return GNUNET_OK; | 1335 | return GNUNET_OK; |
1331 | } | 1336 | } |
@@ -1338,45 +1343,45 @@ detach_terminal (struct LEGACY_SERVICE_Context *sctx) | |||
1338 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 1343 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
1339 | */ | 1344 | */ |
1340 | static int | 1345 | static int |
1341 | set_user_id (struct LEGACY_SERVICE_Context *sctx) | 1346 | set_user_id(struct LEGACY_SERVICE_Context *sctx) |
1342 | { | 1347 | { |
1343 | char *user; | 1348 | char *user; |
1344 | 1349 | ||
1345 | if (NULL == (user = get_user_name (sctx))) | 1350 | if (NULL == (user = get_user_name(sctx))) |
1346 | return GNUNET_OK; /* keep */ | 1351 | return GNUNET_OK; /* keep */ |
1347 | #ifndef MINGW | 1352 | #ifndef MINGW |
1348 | struct passwd *pws; | 1353 | struct passwd *pws; |
1349 | 1354 | ||
1350 | errno = 0; | 1355 | errno = 0; |
1351 | pws = getpwnam (user); | 1356 | pws = getpwnam(user); |
1352 | if (NULL == pws) | 1357 | if (NULL == pws) |
1353 | { | 1358 | { |
1354 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1359 | LOG(GNUNET_ERROR_TYPE_ERROR, |
1355 | _ ("Cannot obtain information about user `%s': %s\n"), | 1360 | _("Cannot obtain information about user `%s': %s\n"), |
1356 | user, | 1361 | user, |
1357 | errno == 0 ? _ ("No such user") : strerror (errno)); | 1362 | errno == 0 ? _("No such user") : strerror(errno)); |
1358 | GNUNET_free (user); | 1363 | GNUNET_free(user); |
1359 | return GNUNET_SYSERR; | 1364 | return GNUNET_SYSERR; |
1360 | } | 1365 | } |
1361 | if ((0 != setgid (pws->pw_gid)) || (0 != setegid (pws->pw_gid)) || | 1366 | if ((0 != setgid(pws->pw_gid)) || (0 != setegid(pws->pw_gid)) || |
1362 | #if HAVE_INITGROUPS | 1367 | #if HAVE_INITGROUPS |
1363 | (0 != initgroups (user, pws->pw_gid)) || | 1368 | (0 != initgroups(user, pws->pw_gid)) || |
1364 | #endif | 1369 | #endif |
1365 | (0 != setuid (pws->pw_uid)) || (0 != seteuid (pws->pw_uid))) | 1370 | (0 != setuid(pws->pw_uid)) || (0 != seteuid(pws->pw_uid))) |
1366 | { | ||
1367 | if ((0 != setregid (pws->pw_gid, pws->pw_gid)) || | ||
1368 | (0 != setreuid (pws->pw_uid, pws->pw_uid))) | ||
1369 | { | 1371 | { |
1370 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1372 | if ((0 != setregid(pws->pw_gid, pws->pw_gid)) || |
1371 | _ ("Cannot change user/group to `%s': %s\n"), | 1373 | (0 != setreuid(pws->pw_uid, pws->pw_uid))) |
1372 | user, | 1374 | { |
1373 | strerror (errno)); | 1375 | LOG(GNUNET_ERROR_TYPE_ERROR, |
1374 | GNUNET_free (user); | 1376 | _("Cannot change user/group to `%s': %s\n"), |
1375 | return GNUNET_SYSERR; | 1377 | user, |
1378 | strerror(errno)); | ||
1379 | GNUNET_free(user); | ||
1380 | return GNUNET_SYSERR; | ||
1381 | } | ||
1376 | } | 1382 | } |
1377 | } | ||
1378 | #endif | 1383 | #endif |
1379 | GNUNET_free (user); | 1384 | GNUNET_free(user); |
1380 | return GNUNET_OK; | 1385 | return GNUNET_OK; |
1381 | } | 1386 | } |
1382 | 1387 | ||
@@ -1387,15 +1392,15 @@ set_user_id (struct LEGACY_SERVICE_Context *sctx) | |||
1387 | * @param sctx service context | 1392 | * @param sctx service context |
1388 | */ | 1393 | */ |
1389 | static void | 1394 | static void |
1390 | pid_file_delete (struct LEGACY_SERVICE_Context *sctx) | 1395 | pid_file_delete(struct LEGACY_SERVICE_Context *sctx) |
1391 | { | 1396 | { |
1392 | char *pif = get_pid_file_name (sctx); | 1397 | char *pif = get_pid_file_name(sctx); |
1393 | 1398 | ||
1394 | if (NULL == pif) | 1399 | if (NULL == pif) |
1395 | return; /* no PID file */ | 1400 | return; /* no PID file */ |
1396 | if (0 != unlink (pif)) | 1401 | if (0 != unlink(pif)) |
1397 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", pif); | 1402 | LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_WARNING, "unlink", pif); |
1398 | GNUNET_free (pif); | 1403 | GNUNET_free(pif); |
1399 | } | 1404 | } |
1400 | 1405 | ||
1401 | 1406 | ||
@@ -1413,19 +1418,19 @@ pid_file_delete (struct LEGACY_SERVICE_Context *sctx) | |||
1413 | * if we shutdown nicely | 1418 | * if we shutdown nicely |
1414 | */ | 1419 | */ |
1415 | int | 1420 | int |
1416 | LEGACY_SERVICE_run (int argc, | 1421 | LEGACY_SERVICE_run(int argc, |
1417 | char *const *argv, | 1422 | char *const *argv, |
1418 | const char *service_name, | 1423 | const char *service_name, |
1419 | enum LEGACY_SERVICE_Options options, | 1424 | enum LEGACY_SERVICE_Options options, |
1420 | LEGACY_SERVICE_Main task, | 1425 | LEGACY_SERVICE_Main task, |
1421 | void *task_cls) | 1426 | void *task_cls) |
1422 | { | 1427 | { |
1423 | #define HANDLE_ERROR \ | 1428 | #define HANDLE_ERROR \ |
1424 | do \ | 1429 | do \ |
1425 | { \ | 1430 | { \ |
1426 | GNUNET_break (0); \ | 1431 | GNUNET_break(0); \ |
1427 | goto shutdown; \ | 1432 | goto shutdown; \ |
1428 | } while (0) | 1433 | } while (0) |
1429 | 1434 | ||
1430 | int err; | 1435 | int err; |
1431 | int ret; | 1436 | int ret; |
@@ -1443,32 +1448,32 @@ LEGACY_SERVICE_run (int argc, | |||
1443 | const char *xdg; | 1448 | const char *xdg; |
1444 | 1449 | ||
1445 | struct GNUNET_GETOPT_CommandLineOption service_options[] = | 1450 | struct GNUNET_GETOPT_CommandLineOption service_options[] = |
1446 | {GNUNET_GETOPT_option_cfgfile (&opt_cfg_fn), | 1451 | { GNUNET_GETOPT_option_cfgfile(&opt_cfg_fn), |
1447 | GNUNET_GETOPT_option_flag ('d', | 1452 | GNUNET_GETOPT_option_flag('d', |
1448 | "daemonize", | 1453 | "daemonize", |
1449 | gettext_noop ( | 1454 | gettext_noop( |
1450 | "do daemonize (detach from terminal)"), | 1455 | "do daemonize (detach from terminal)"), |
1451 | &do_daemonize), | 1456 | &do_daemonize), |
1452 | GNUNET_GETOPT_option_help (NULL), | 1457 | GNUNET_GETOPT_option_help(NULL), |
1453 | GNUNET_GETOPT_option_loglevel (&loglev), | 1458 | GNUNET_GETOPT_option_loglevel(&loglev), |
1454 | GNUNET_GETOPT_option_logfile (&logfile), | 1459 | GNUNET_GETOPT_option_logfile(&logfile), |
1455 | GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION), | 1460 | GNUNET_GETOPT_option_version(PACKAGE_VERSION " " VCS_VERSION), |
1456 | GNUNET_GETOPT_OPTION_END}; | 1461 | GNUNET_GETOPT_OPTION_END }; |
1457 | err = 1; | 1462 | err = 1; |
1458 | do_daemonize = 0; | 1463 | do_daemonize = 0; |
1459 | logfile = NULL; | 1464 | logfile = NULL; |
1460 | loglev = NULL; | 1465 | loglev = NULL; |
1461 | opt_cfg_fn = NULL; | 1466 | opt_cfg_fn = NULL; |
1462 | xdg = getenv ("XDG_CONFIG_HOME"); | 1467 | xdg = getenv("XDG_CONFIG_HOME"); |
1463 | if (NULL != xdg) | 1468 | if (NULL != xdg) |
1464 | GNUNET_asprintf (&cfg_fn, | 1469 | GNUNET_asprintf(&cfg_fn, |
1465 | "%s%s%s", | 1470 | "%s%s%s", |
1466 | xdg, | 1471 | xdg, |
1467 | DIR_SEPARATOR_STR, | 1472 | DIR_SEPARATOR_STR, |
1468 | GNUNET_OS_project_data_get ()->config_file); | 1473 | GNUNET_OS_project_data_get()->config_file); |
1469 | else | 1474 | else |
1470 | cfg_fn = GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file); | 1475 | cfg_fn = GNUNET_strdup(GNUNET_OS_project_data_get()->user_config_file); |
1471 | memset (&sctx, 0, sizeof (sctx)); | 1476 | memset(&sctx, 0, sizeof(sctx)); |
1472 | sctx.options = options; | 1477 | sctx.options = options; |
1473 | sctx.ready_confirm_fd = -1; | 1478 | sctx.ready_confirm_fd = -1; |
1474 | sctx.ret = GNUNET_OK; | 1479 | sctx.ret = GNUNET_OK; |
@@ -1476,117 +1481,117 @@ LEGACY_SERVICE_run (int argc, | |||
1476 | sctx.task = task; | 1481 | sctx.task = task; |
1477 | sctx.task_cls = task_cls; | 1482 | sctx.task_cls = task_cls; |
1478 | sctx.service_name = service_name; | 1483 | sctx.service_name = service_name; |
1479 | sctx.cfg = cfg = GNUNET_CONFIGURATION_create (); | 1484 | sctx.cfg = cfg = GNUNET_CONFIGURATION_create(); |
1480 | 1485 | ||
1481 | /* setup subsystems */ | 1486 | /* setup subsystems */ |
1482 | ret = GNUNET_GETOPT_run (service_name, service_options, argc, argv); | 1487 | ret = GNUNET_GETOPT_run(service_name, service_options, argc, argv); |
1483 | if (GNUNET_SYSERR == ret) | 1488 | if (GNUNET_SYSERR == ret) |
1484 | goto shutdown; | 1489 | goto shutdown; |
1485 | if (GNUNET_NO == ret) | 1490 | if (GNUNET_NO == ret) |
1486 | { | 1491 | { |
1487 | err = 0; | 1492 | err = 0; |
1488 | goto shutdown; | 1493 | goto shutdown; |
1489 | } | 1494 | } |
1490 | if (GNUNET_OK != GNUNET_log_setup (service_name, loglev, logfile)) | 1495 | if (GNUNET_OK != GNUNET_log_setup(service_name, loglev, logfile)) |
1491 | HANDLE_ERROR; | 1496 | HANDLE_ERROR; |
1492 | if (NULL == opt_cfg_fn) | 1497 | if (NULL == opt_cfg_fn) |
1493 | opt_cfg_fn = GNUNET_strdup (cfg_fn); | 1498 | opt_cfg_fn = GNUNET_strdup(cfg_fn); |
1494 | if (GNUNET_YES == GNUNET_DISK_file_test (opt_cfg_fn)) | 1499 | if (GNUNET_YES == GNUNET_DISK_file_test(opt_cfg_fn)) |
1495 | { | ||
1496 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, opt_cfg_fn)) | ||
1497 | { | 1500 | { |
1498 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1501 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load(cfg, opt_cfg_fn)) |
1499 | _ ("Malformed configuration file `%s', exit ...\n"), | 1502 | { |
1500 | opt_cfg_fn); | 1503 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1501 | goto shutdown; | 1504 | _("Malformed configuration file `%s', exit ...\n"), |
1505 | opt_cfg_fn); | ||
1506 | goto shutdown; | ||
1507 | } | ||
1502 | } | 1508 | } |
1503 | } | ||
1504 | else | 1509 | else |
1505 | { | ||
1506 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, NULL)) | ||
1507 | { | 1510 | { |
1508 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1511 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load(cfg, NULL)) |
1509 | _ ("Malformed configuration, exit ...\n")); | 1512 | { |
1510 | goto shutdown; | 1513 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1514 | _("Malformed configuration, exit ...\n")); | ||
1515 | goto shutdown; | ||
1516 | } | ||
1517 | if (0 != strcmp(opt_cfg_fn, cfg_fn)) | ||
1518 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
1519 | _("Could not access configuration file `%s'\n"), | ||
1520 | opt_cfg_fn); | ||
1511 | } | 1521 | } |
1512 | if (0 != strcmp (opt_cfg_fn, cfg_fn)) | 1522 | if (GNUNET_OK != setup_service(&sctx)) |
1513 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1514 | _ ("Could not access configuration file `%s'\n"), | ||
1515 | opt_cfg_fn); | ||
1516 | } | ||
1517 | if (GNUNET_OK != setup_service (&sctx)) | ||
1518 | goto shutdown; | 1523 | goto shutdown; |
1519 | if ((1 == do_daemonize) && (GNUNET_OK != detach_terminal (&sctx))) | 1524 | if ((1 == do_daemonize) && (GNUNET_OK != detach_terminal(&sctx))) |
1520 | HANDLE_ERROR; | 1525 | HANDLE_ERROR; |
1521 | if (GNUNET_OK != set_user_id (&sctx)) | 1526 | if (GNUNET_OK != set_user_id(&sctx)) |
1522 | goto shutdown; | 1527 | goto shutdown; |
1523 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1528 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1524 | "Service `%s' runs with configuration from `%s'\n", | 1529 | "Service `%s' runs with configuration from `%s'\n", |
1525 | service_name, | 1530 | service_name, |
1526 | opt_cfg_fn); | 1531 | opt_cfg_fn); |
1527 | if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sctx.cfg, | 1532 | if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(sctx.cfg, |
1528 | "TESTING", | 1533 | "TESTING", |
1529 | "SKEW_OFFSET", | 1534 | "SKEW_OFFSET", |
1530 | &skew_offset)) && | 1535 | &skew_offset)) && |
1531 | (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sctx.cfg, | 1536 | (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(sctx.cfg, |
1532 | "TESTING", | 1537 | "TESTING", |
1533 | "SKEW_VARIANCE", | 1538 | "SKEW_VARIANCE", |
1534 | &skew_variance))) | 1539 | &skew_variance))) |
1535 | { | 1540 | { |
1536 | clock_offset = skew_offset - skew_variance; | 1541 | clock_offset = skew_offset - skew_variance; |
1537 | GNUNET_TIME_set_offset (clock_offset); | 1542 | GNUNET_TIME_set_offset(clock_offset); |
1538 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %dll ms\n", clock_offset); | 1543 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %dll ms\n", clock_offset); |
1539 | } | 1544 | } |
1540 | /* actually run service */ | 1545 | /* actually run service */ |
1541 | err = 0; | 1546 | err = 0; |
1542 | GNUNET_SCHEDULER_run (&service_task, &sctx); | 1547 | GNUNET_SCHEDULER_run(&service_task, &sctx); |
1543 | /* shutdown */ | 1548 | /* shutdown */ |
1544 | if ((1 == do_daemonize) && (NULL != sctx.server)) | 1549 | if ((1 == do_daemonize) && (NULL != sctx.server)) |
1545 | pid_file_delete (&sctx); | 1550 | pid_file_delete(&sctx); |
1546 | GNUNET_free_non_null (sctx.my_handlers); | 1551 | GNUNET_free_non_null(sctx.my_handlers); |
1547 | 1552 | ||
1548 | shutdown: | 1553 | shutdown: |
1549 | if (-1 != sctx.ready_confirm_fd) | 1554 | if (-1 != sctx.ready_confirm_fd) |
1550 | { | 1555 | { |
1551 | if (1 != write (sctx.ready_confirm_fd, err ? "I" : "S", 1)) | 1556 | if (1 != write(sctx.ready_confirm_fd, err ? "I" : "S", 1)) |
1552 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "write"); | 1557 | LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, "write"); |
1553 | GNUNET_break (0 == close (sctx.ready_confirm_fd)); | 1558 | GNUNET_break(0 == close(sctx.ready_confirm_fd)); |
1554 | } | 1559 | } |
1555 | #if HAVE_MALLINFO | 1560 | #if HAVE_MALLINFO |
1556 | { | 1561 | { |
1557 | char *counter; | 1562 | char *counter; |
1558 | 1563 | ||
1559 | if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (sctx.cfg, | 1564 | if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value(sctx.cfg, |
1560 | service_name, | 1565 | service_name, |
1561 | "GAUGER_HEAP")) && | 1566 | "GAUGER_HEAP")) && |
1562 | (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (sctx.cfg, | 1567 | (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(sctx.cfg, |
1563 | service_name, | 1568 | service_name, |
1564 | "GAUGER_HEAP", | 1569 | "GAUGER_HEAP", |
1565 | &counter))) | 1570 | &counter))) |
1566 | { | 1571 | { |
1567 | struct mallinfo mi; | 1572 | struct mallinfo mi; |
1568 | 1573 | ||
1569 | mi = mallinfo (); | 1574 | mi = mallinfo(); |
1570 | GAUGER (service_name, counter, mi.usmblks, "blocks"); | 1575 | GAUGER(service_name, counter, mi.usmblks, "blocks"); |
1571 | GNUNET_free (counter); | 1576 | GNUNET_free(counter); |
1572 | } | 1577 | } |
1573 | } | 1578 | } |
1574 | #endif | 1579 | #endif |
1575 | GNUNET_CONFIGURATION_destroy (cfg); | 1580 | GNUNET_CONFIGURATION_destroy(cfg); |
1576 | i = 0; | 1581 | i = 0; |
1577 | if (NULL != sctx.addrs) | 1582 | if (NULL != sctx.addrs) |
1578 | while (NULL != sctx.addrs[i]) | 1583 | while (NULL != sctx.addrs[i]) |
1579 | GNUNET_free (sctx.addrs[i++]); | 1584 | GNUNET_free(sctx.addrs[i++]); |
1580 | GNUNET_free_non_null (sctx.addrs); | 1585 | GNUNET_free_non_null(sctx.addrs); |
1581 | GNUNET_free_non_null (sctx.addrlens); | 1586 | GNUNET_free_non_null(sctx.addrlens); |
1582 | GNUNET_free_non_null (logfile); | 1587 | GNUNET_free_non_null(logfile); |
1583 | GNUNET_free_non_null (loglev); | 1588 | GNUNET_free_non_null(loglev); |
1584 | GNUNET_free (cfg_fn); | 1589 | GNUNET_free(cfg_fn); |
1585 | GNUNET_free_non_null (opt_cfg_fn); | 1590 | GNUNET_free_non_null(opt_cfg_fn); |
1586 | GNUNET_free_non_null (sctx.v4_denied); | 1591 | GNUNET_free_non_null(sctx.v4_denied); |
1587 | GNUNET_free_non_null (sctx.v6_denied); | 1592 | GNUNET_free_non_null(sctx.v6_denied); |
1588 | GNUNET_free_non_null (sctx.v4_allowed); | 1593 | GNUNET_free_non_null(sctx.v4_allowed); |
1589 | GNUNET_free_non_null (sctx.v6_allowed); | 1594 | GNUNET_free_non_null(sctx.v6_allowed); |
1590 | 1595 | ||
1591 | return err ? GNUNET_SYSERR : sctx.ret; | 1596 | return err ? GNUNET_SYSERR : sctx.ret; |
1592 | } | 1597 | } |
@@ -1602,14 +1607,14 @@ shutdown: | |||
1602 | * @return NULL on error, service handle | 1607 | * @return NULL on error, service handle |
1603 | */ | 1608 | */ |
1604 | struct LEGACY_SERVICE_Context * | 1609 | struct LEGACY_SERVICE_Context * |
1605 | LEGACY_SERVICE_start (const char *service_name, | 1610 | LEGACY_SERVICE_start(const char *service_name, |
1606 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 1611 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1607 | enum LEGACY_SERVICE_Options options) | 1612 | enum LEGACY_SERVICE_Options options) |
1608 | { | 1613 | { |
1609 | int i; | 1614 | int i; |
1610 | struct LEGACY_SERVICE_Context *sctx; | 1615 | struct LEGACY_SERVICE_Context *sctx; |
1611 | 1616 | ||
1612 | sctx = GNUNET_new (struct LEGACY_SERVICE_Context); | 1617 | sctx = GNUNET_new(struct LEGACY_SERVICE_Context); |
1613 | sctx->ready_confirm_fd = -1; /* no daemonizing */ | 1618 | sctx->ready_confirm_fd = -1; /* no daemonizing */ |
1614 | sctx->ret = GNUNET_OK; | 1619 | sctx->ret = GNUNET_OK; |
1615 | sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL; | 1620 | sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL; |
@@ -1618,47 +1623,47 @@ LEGACY_SERVICE_start (const char *service_name, | |||
1618 | sctx->options = options; | 1623 | sctx->options = options; |
1619 | 1624 | ||
1620 | /* setup subsystems */ | 1625 | /* setup subsystems */ |
1621 | if (GNUNET_OK != setup_service (sctx)) | 1626 | if (GNUNET_OK != setup_service(sctx)) |
1622 | { | 1627 | { |
1623 | LEGACY_SERVICE_stop (sctx); | 1628 | LEGACY_SERVICE_stop(sctx); |
1624 | return NULL; | 1629 | return NULL; |
1625 | } | 1630 | } |
1626 | if (NULL != sctx->lsocks) | 1631 | if (NULL != sctx->lsocks) |
1627 | sctx->server = GNUNET_SERVER_create_with_sockets (&check_access, | 1632 | sctx->server = GNUNET_SERVER_create_with_sockets(&check_access, |
1628 | sctx, | 1633 | sctx, |
1629 | sctx->lsocks, | 1634 | sctx->lsocks, |
1630 | sctx->timeout, | 1635 | sctx->timeout, |
1631 | sctx->require_found); | 1636 | sctx->require_found); |
1632 | else | 1637 | else |
1633 | sctx->server = GNUNET_SERVER_create (&check_access, | 1638 | sctx->server = GNUNET_SERVER_create(&check_access, |
1634 | sctx, | 1639 | sctx, |
1635 | sctx->addrs, | 1640 | sctx->addrs, |
1636 | sctx->addrlens, | 1641 | sctx->addrlens, |
1637 | sctx->timeout, | 1642 | sctx->timeout, |
1638 | sctx->require_found); | 1643 | sctx->require_found); |
1639 | 1644 | ||
1640 | if (NULL == sctx->server) | 1645 | if (NULL == sctx->server) |
1641 | { | 1646 | { |
1642 | LEGACY_SERVICE_stop (sctx); | 1647 | LEGACY_SERVICE_stop(sctx); |
1643 | return NULL; | 1648 | return NULL; |
1644 | } | 1649 | } |
1645 | #ifndef WINDOWS | 1650 | #ifndef WINDOWS |
1646 | if (NULL != sctx->addrs) | 1651 | if (NULL != sctx->addrs) |
1647 | for (i = 0; NULL != sctx->addrs[i]; i++) | 1652 | for (i = 0; NULL != sctx->addrs[i]; i++) |
1648 | if ((AF_UNIX == sctx->addrs[i]->sa_family) && | 1653 | if ((AF_UNIX == sctx->addrs[i]->sa_family) && |
1649 | ('\0' != ((const struct sockaddr_un *) sctx->addrs[i])->sun_path[0])) | 1654 | ('\0' != ((const struct sockaddr_un *)sctx->addrs[i])->sun_path[0])) |
1650 | GNUNET_DISK_fix_permissions (((const struct sockaddr_un *) | 1655 | GNUNET_DISK_fix_permissions(((const struct sockaddr_un *) |
1651 | sctx->addrs[i]) | 1656 | sctx->addrs[i]) |
1652 | ->sun_path, | 1657 | ->sun_path, |
1653 | sctx->match_uid, | 1658 | sctx->match_uid, |
1654 | sctx->match_gid); | 1659 | sctx->match_gid); |
1655 | #endif | 1660 | #endif |
1656 | sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers)); | 1661 | sctx->my_handlers = GNUNET_malloc(sizeof(defhandlers)); |
1657 | GNUNET_memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers)); | 1662 | GNUNET_memcpy(sctx->my_handlers, defhandlers, sizeof(defhandlers)); |
1658 | i = 0; | 1663 | i = 0; |
1659 | while ((sctx->my_handlers[i].callback != NULL)) | 1664 | while ((sctx->my_handlers[i].callback != NULL)) |
1660 | sctx->my_handlers[i++].callback_cls = sctx; | 1665 | sctx->my_handlers[i++].callback_cls = sctx; |
1661 | GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers); | 1666 | GNUNET_SERVER_add_handlers(sctx->server, sctx->my_handlers); |
1662 | return sctx; | 1667 | return sctx; |
1663 | } | 1668 | } |
1664 | 1669 | ||
@@ -1671,7 +1676,7 @@ LEGACY_SERVICE_start (const char *service_name, | |||
1671 | * @return handle to the server for this service, NULL if there is none | 1676 | * @return handle to the server for this service, NULL if there is none |
1672 | */ | 1677 | */ |
1673 | struct GNUNET_SERVER_Handle * | 1678 | struct GNUNET_SERVER_Handle * |
1674 | LEGACY_SERVICE_get_server (struct LEGACY_SERVICE_Context *ctx) | 1679 | LEGACY_SERVICE_get_server(struct LEGACY_SERVICE_Context *ctx) |
1675 | { | 1680 | { |
1676 | return ctx->server; | 1681 | return ctx->server; |
1677 | } | 1682 | } |
@@ -1685,7 +1690,7 @@ LEGACY_SERVICE_get_server (struct LEGACY_SERVICE_Context *ctx) | |||
1685 | * array of listen sockets. | 1690 | * array of listen sockets. |
1686 | */ | 1691 | */ |
1687 | struct GNUNET_NETWORK_Handle *const * | 1692 | struct GNUNET_NETWORK_Handle *const * |
1688 | LEGACY_SERVICE_get_listen_sockets (struct LEGACY_SERVICE_Context *ctx) | 1693 | LEGACY_SERVICE_get_listen_sockets(struct LEGACY_SERVICE_Context *ctx) |
1689 | { | 1694 | { |
1690 | return ctx->lsocks; | 1695 | return ctx->lsocks; |
1691 | } | 1696 | } |
@@ -1697,7 +1702,7 @@ LEGACY_SERVICE_get_listen_sockets (struct LEGACY_SERVICE_Context *ctx) | |||
1697 | * @param sctx the service context returned from the start function | 1702 | * @param sctx the service context returned from the start function |
1698 | */ | 1703 | */ |
1699 | void | 1704 | void |
1700 | LEGACY_SERVICE_stop (struct LEGACY_SERVICE_Context *sctx) | 1705 | LEGACY_SERVICE_stop(struct LEGACY_SERVICE_Context *sctx) |
1701 | { | 1706 | { |
1702 | unsigned int i; | 1707 | unsigned int i; |
1703 | 1708 | ||
@@ -1705,43 +1710,43 @@ LEGACY_SERVICE_stop (struct LEGACY_SERVICE_Context *sctx) | |||
1705 | { | 1710 | { |
1706 | char *counter; | 1711 | char *counter; |
1707 | 1712 | ||
1708 | if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (sctx->cfg, | 1713 | if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value(sctx->cfg, |
1709 | sctx->service_name, | 1714 | sctx->service_name, |
1710 | "GAUGER_HEAP")) && | 1715 | "GAUGER_HEAP")) && |
1711 | (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (sctx->cfg, | 1716 | (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(sctx->cfg, |
1712 | sctx->service_name, | 1717 | sctx->service_name, |
1713 | "GAUGER_HEAP", | 1718 | "GAUGER_HEAP", |
1714 | &counter))) | 1719 | &counter))) |
1715 | { | 1720 | { |
1716 | struct mallinfo mi; | 1721 | struct mallinfo mi; |
1717 | 1722 | ||
1718 | mi = mallinfo (); | 1723 | mi = mallinfo(); |
1719 | GAUGER (sctx->service_name, counter, mi.usmblks, "blocks"); | 1724 | GAUGER(sctx->service_name, counter, mi.usmblks, "blocks"); |
1720 | GNUNET_free (counter); | 1725 | GNUNET_free(counter); |
1721 | } | 1726 | } |
1722 | } | 1727 | } |
1723 | #endif | 1728 | #endif |
1724 | if (NULL != sctx->shutdown_task) | 1729 | if (NULL != sctx->shutdown_task) |
1725 | { | 1730 | { |
1726 | GNUNET_SCHEDULER_cancel (sctx->shutdown_task); | 1731 | GNUNET_SCHEDULER_cancel(sctx->shutdown_task); |
1727 | sctx->shutdown_task = NULL; | 1732 | sctx->shutdown_task = NULL; |
1728 | } | 1733 | } |
1729 | if (NULL != sctx->server) | 1734 | if (NULL != sctx->server) |
1730 | GNUNET_SERVER_destroy (sctx->server); | 1735 | GNUNET_SERVER_destroy(sctx->server); |
1731 | GNUNET_free_non_null (sctx->my_handlers); | 1736 | GNUNET_free_non_null(sctx->my_handlers); |
1732 | if (NULL != sctx->addrs) | 1737 | if (NULL != sctx->addrs) |
1733 | { | 1738 | { |
1734 | i = 0; | 1739 | i = 0; |
1735 | while (NULL != sctx->addrs[i]) | 1740 | while (NULL != sctx->addrs[i]) |
1736 | GNUNET_free (sctx->addrs[i++]); | 1741 | GNUNET_free(sctx->addrs[i++]); |
1737 | GNUNET_free (sctx->addrs); | 1742 | GNUNET_free(sctx->addrs); |
1738 | } | 1743 | } |
1739 | GNUNET_free_non_null (sctx->addrlens); | 1744 | GNUNET_free_non_null(sctx->addrlens); |
1740 | GNUNET_free_non_null (sctx->v4_denied); | 1745 | GNUNET_free_non_null(sctx->v4_denied); |
1741 | GNUNET_free_non_null (sctx->v6_denied); | 1746 | GNUNET_free_non_null(sctx->v6_denied); |
1742 | GNUNET_free_non_null (sctx->v4_allowed); | 1747 | GNUNET_free_non_null(sctx->v4_allowed); |
1743 | GNUNET_free_non_null (sctx->v6_allowed); | 1748 | GNUNET_free_non_null(sctx->v6_allowed); |
1744 | GNUNET_free (sctx); | 1749 | GNUNET_free(sctx); |
1745 | } | 1750 | } |
1746 | 1751 | ||
1747 | 1752 | ||