summaryrefslogtreecommitdiff
path: root/src/transport/tcp_service_legacy.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/tcp_service_legacy.c')
-rw-r--r--src/transport/tcp_service_legacy.c1639
1 files changed, 820 insertions, 819 deletions
diff --git a/src/transport/tcp_service_legacy.c b/src/transport/tcp_service_legacy.c
index 129511fec..54020b642 100644
--- a/src/transport/tcp_service_legacy.c
+++ b/src/transport/tcp_service_legacy.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 */
47static int 47static int
48check_ipv4_listed(const struct GNUNET_STRINGS_IPv4NetworkPolicy *list, 48check_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 */
74static int 74static int
75check_ipv6_listed(const struct GNUNET_STRINGS_IPv6NetworkPolicy *list, 75check_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;
86NEXT: 86NEXT:
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,7 +105,8 @@ NEXT:
105/** 105/**
106 * Context for "service_task". 106 * Context for "service_task".
107 */ 107 */
108struct LEGACY_SERVICE_Context { 108struct LEGACY_SERVICE_Context
109{
109 /** 110 /**
110 * Our configuration. 111 * Our configuration.
111 */ 112 */
@@ -237,20 +238,20 @@ struct LEGACY_SERVICE_Context {
237 * @return number of bytes written to 'buf' 238 * @return number of bytes written to 'buf'
238 */ 239 */
239static size_t 240static size_t
240write_test(void *cls, size_t size, void *buf) 241write_test (void *cls, size_t size, void *buf)
241{ 242{
242 struct GNUNET_SERVER_Client *client = cls; 243 struct GNUNET_SERVER_Client *client = cls;
243 struct GNUNET_MessageHeader *msg; 244 struct GNUNET_MessageHeader *msg;
244 245
245 if (size < sizeof(struct GNUNET_MessageHeader)) 246 if (size < sizeof(struct GNUNET_MessageHeader))
246 { 247 {
247 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 248 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
248 return 0; /* client disconnected */ 249 return 0; /* client disconnected */
249 } 250 }
250 msg = (struct GNUNET_MessageHeader *)buf; 251 msg = (struct GNUNET_MessageHeader *) buf;
251 msg->type = htons(GNUNET_MESSAGE_TYPE_TEST); 252 msg->type = htons (GNUNET_MESSAGE_TYPE_TEST);
252 msg->size = htons(sizeof(struct GNUNET_MessageHeader)); 253 msg->size = htons (sizeof(struct GNUNET_MessageHeader));
253 GNUNET_SERVER_receive_done(client, GNUNET_OK); 254 GNUNET_SERVER_receive_done (client, GNUNET_OK);
254 return sizeof(struct GNUNET_MessageHeader); 255 return sizeof(struct GNUNET_MessageHeader);
255} 256}
256 257
@@ -263,18 +264,18 @@ write_test(void *cls, size_t size, void *buf)
263 * @param message the actual message 264 * @param message the actual message
264 */ 265 */
265static void 266static void
266handle_test(void *cls, 267handle_test (void *cls,
267 struct GNUNET_SERVER_Client *client, 268 struct GNUNET_SERVER_Client *client,
268 const struct GNUNET_MessageHeader *message) 269 const struct GNUNET_MessageHeader *message)
269{ 270{
270 /* simply bounce message back to acknowledge */ 271 /* simply bounce message back to acknowledge */
271 if (NULL == 272 if (NULL ==
272 GNUNET_SERVER_notify_transmit_ready(client, 273 GNUNET_SERVER_notify_transmit_ready (client,
273 sizeof(struct GNUNET_MessageHeader), 274 sizeof(struct GNUNET_MessageHeader),
274 GNUNET_TIME_UNIT_FOREVER_REL, 275 GNUNET_TIME_UNIT_FOREVER_REL,
275 &write_test, 276 &write_test,
276 client)) 277 client))
277 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 278 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
278} 279}
279 280
280 281
@@ -305,10 +306,10 @@ static const struct GNUNET_SERVER_MessageHandler defhandlers[] =
305 * for unknown address family (will be denied). 306 * for unknown address family (will be denied).
306 */ 307 */
307static int 308static int
308check_access(void *cls, 309check_access (void *cls,
309 const struct GNUNET_CONNECTION_Credentials *uc, 310 const struct GNUNET_CONNECTION_Credentials *uc,
310 const struct sockaddr *addr, 311 const struct sockaddr *addr,
311 socklen_t addrlen) 312 socklen_t addrlen)
312{ 313{
313 struct LEGACY_SERVICE_Context *sctx = cls; 314 struct LEGACY_SERVICE_Context *sctx = cls;
314 const struct sockaddr_in *i4; 315 const struct sockaddr_in *i4;
@@ -316,42 +317,42 @@ check_access(void *cls,
316 int ret; 317 int ret;
317 318
318 switch (addr->sa_family) 319 switch (addr->sa_family)
319 { 320 {
320 case AF_INET: 321 case AF_INET:
321 GNUNET_assert(addrlen == sizeof(struct sockaddr_in)); 322 GNUNET_assert (addrlen == sizeof(struct sockaddr_in));
322 i4 = (const struct sockaddr_in *)addr; 323 i4 = (const struct sockaddr_in *) addr;
323 ret = ((NULL == sctx->v4_allowed) || 324 ret = ((NULL == sctx->v4_allowed) ||
324 (check_ipv4_listed(sctx->v4_allowed, &i4->sin_addr))) && 325 (check_ipv4_listed (sctx->v4_allowed, &i4->sin_addr))) &&
325 ((NULL == sctx->v4_denied) || 326 ((NULL == sctx->v4_denied) ||
326 (!check_ipv4_listed(sctx->v4_denied, &i4->sin_addr))); 327 (! check_ipv4_listed (sctx->v4_denied, &i4->sin_addr)));
327 break; 328 break;
328 329
329 case AF_INET6: 330 case AF_INET6:
330 GNUNET_assert(addrlen == sizeof(struct sockaddr_in6)); 331 GNUNET_assert (addrlen == sizeof(struct sockaddr_in6));
331 i6 = (const struct sockaddr_in6 *)addr; 332 i6 = (const struct sockaddr_in6 *) addr;
332 ret = ((NULL == sctx->v6_allowed) || 333 ret = ((NULL == sctx->v6_allowed) ||
333 (check_ipv6_listed(sctx->v6_allowed, &i6->sin6_addr))) && 334 (check_ipv6_listed (sctx->v6_allowed, &i6->sin6_addr))) &&
334 ((NULL == sctx->v6_denied) || 335 ((NULL == sctx->v6_denied) ||
335 (!check_ipv6_listed(sctx->v6_denied, &i6->sin6_addr))); 336 (! check_ipv6_listed (sctx->v6_denied, &i6->sin6_addr)));
336 break; 337 break;
337 338
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 342
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 */
366static char * 367static char *
367get_pid_file_name(struct LEGACY_SERVICE_Context *sctx) 368get_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 */
389static int 390static int
390process_acl4(struct GNUNET_STRINGS_IPv4NetworkPolicy **ret, 391process_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 */
430static int 431static int
431process_acl6(struct GNUNET_STRINGS_IPv6NetworkPolicy **ret, 432process_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 */
472static void 473static void
473add_unixpath(struct sockaddr **saddrs, 474add_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 */
521int 522int
522LEGACY_SERVICE_get_server_addresses( 523LEGACY_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 {
549 if (GNUNET_SYSERR == 550 if (GNUNET_SYSERR ==
550 (disablev6 = GNUNET_CONFIGURATION_get_value_yesno(cfg, 551 (disablev6 = GNUNET_CONFIGURATION_get_value_yesno (cfg,
551 service_name, 552 service_name,
552 "DISABLEV6"))) 553 "DISABLEV6")))
553 return GNUNET_SYSERR; 554 return GNUNET_SYSERR;
554 } 555 }
555 else 556 else
556 disablev6 = GNUNET_NO; 557 disablev6 = GNUNET_NO;
557 558
558 if (!disablev6) 559 if (! disablev6)
560 {
561 /* probe IPv6 support */
562 desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
563 if (NULL == desc)
559 { 564 {
560 /* probe IPv6 support */ 565 if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
561 desc = GNUNET_NETWORK_socket_create(PF_INET6, SOCK_STREAM, 0); 566 (EACCES == errno))
562 if (NULL == desc) 567 {
563 { 568 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
564 if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) || 569 return GNUNET_SYSERR;
565 (EACCES == errno)) 570 }
566 { 571 LOG (GNUNET_ERROR_TYPE_INFO,
567 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "socket"); 572 _ (
568 return GNUNET_SYSERR; 573 "Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"),
569 } 574 service_name,
570 LOG(GNUNET_ERROR_TYPE_INFO, 575 strerror (errno));
571 _( 576 disablev6 = GNUNET_YES;
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 }
577 else
578 {
579 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(desc));
580 desc = NULL;
581 }
582 } 577 }
578 else
579 {
580 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc));
581 desc = NULL;
582 }
583 }
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"))
587 {
588 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
589 service_name,
590 "PORT",
591 &port))
586 { 592 {
587 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg, 593 LOG (GNUNET_ERROR_TYPE_ERROR,
588 service_name, 594 _ ("Require valid port number for service `%s' in configuration!\n"),
589 "PORT", 595 service_name);
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 {
598 LOG(GNUNET_ERROR_TYPE_ERROR,
599 _("Require valid port number for service `%s' in configuration!\n"),
600 service_name);
601 return GNUNET_SYSERR;
602 }
603 } 596 }
604 597 if (port > 65535)
605 if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "BINDTO"))
606 { 598 {
607 GNUNET_break(GNUNET_OK == 599 LOG (GNUNET_ERROR_TYPE_ERROR,
608 GNUNET_CONFIGURATION_get_value_string(cfg, 600 _ ("Require valid port number for service `%s' in configuration!\n"),
601 service_name);
602 return GNUNET_SYSERR;
603 }
604 }
605
606 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO"))
607 {
608 GNUNET_break (GNUNET_OK ==
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)))
627 {
628 /* probe UNIX support */
629 struct sockaddr_un s_un;
630
631 if (strlen (unixpath) >= sizeof(s_un.sun_path))
626 { 632 {
627 /* probe UNIX support */ 633 LOG (GNUNET_ERROR_TYPE_WARNING,
628 struct sockaddr_un s_un; 634 _ ("UNIXPATH `%s' too long, maximum length is %llu\n"),
629 635 unixpath,
630 if (strlen(unixpath) >= sizeof(s_un.sun_path)) 636 (unsigned long long) sizeof(s_un.sun_path));
631 { 637 unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath);
632 LOG(GNUNET_ERROR_TYPE_WARNING, 638 LOG (GNUNET_ERROR_TYPE_INFO, _ ("Using `%s' instead\n"), unixpath);
633 _("UNIXPATH `%s' too long, maximum length is %llu\n"), 639 }
634 unixpath,
635 (unsigned long long)sizeof(s_un.sun_path));
636 unixpath = GNUNET_NETWORK_shorten_unixpath(unixpath);
637 LOG(GNUNET_ERROR_TYPE_INFO, _("Using `%s' instead\n"), unixpath);
638 }
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 }
650 if (NULL != unixpath) 651 if (NULL != unixpath)
652 {
653 desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
654 if (NULL == desc)
651 { 655 {
652 desc = GNUNET_NETWORK_socket_create(AF_UNIX, SOCK_STREAM, 0); 656 if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
653 if (NULL == desc) 657 (EACCES == errno))
654 { 658 {
655 if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) || 659 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
656 (EACCES == errno)) 660 GNUNET_free_non_null (hostname);
657 { 661 GNUNET_free (unixpath);
658 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "socket"); 662 return GNUNET_SYSERR;
659 GNUNET_free_non_null(hostname); 663 }
660 GNUNET_free(unixpath); 664 LOG (GNUNET_ERROR_TYPE_INFO,
661 return GNUNET_SYSERR; 665 _ (
662 } 666 "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
663 LOG(GNUNET_ERROR_TYPE_INFO, 667 service_name,
664 _( 668 strerror (errno));
665 "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"), 669 GNUNET_free (unixpath);
666 service_name, 670 unixpath = NULL;
667 strerror(errno));
668 GNUNET_free(unixpath);
669 unixpath = NULL;
670 }
671 else
672 {
673 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(desc));
674 desc = NULL;
675 }
676 } 671 }
672 else
673 {
674 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc));
675 desc = NULL;
676 }
677 }
677#endif 678#endif
678 679
679 if ((0 == port) && (NULL == unixpath)) 680 if ((0 == port) && (NULL == unixpath))
681 {
682 LOG (GNUNET_ERROR_TYPE_ERROR,
683 _ (
684 "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
685 service_name);
686 GNUNET_free_non_null (hostname);
687 return GNUNET_SYSERR;
688 }
689 if (0 == port)
690 {
691 saddrs = GNUNET_malloc (2 * sizeof(struct sockaddr *));
692 saddrlens = GNUNET_malloc (2 * sizeof(socklen_t));
693 add_unixpath (saddrs, saddrlens, unixpath, abstract);
694 GNUNET_free_non_null (unixpath);
695 GNUNET_free_non_null (hostname);
696 *addrs = saddrs;
697 *addr_lens = saddrlens;
698 return 1;
699 }
700
701 if (NULL != hostname)
702 {
703 LOG (GNUNET_ERROR_TYPE_DEBUG,
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))
680 { 713 {
681 LOG(GNUNET_ERROR_TYPE_ERROR, 714 LOG (GNUNET_ERROR_TYPE_ERROR,
682 _( 715 _ ("Failed to resolve `%s': %s\n"),
683 "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"), 716 hostname,
684 service_name); 717 gai_strerror (ret));
685 GNUNET_free_non_null(hostname); 718 GNUNET_free (hostname);
719 GNUNET_free_non_null (unixpath);
686 return GNUNET_SYSERR; 720 return GNUNET_SYSERR;
687 } 721 }
688 if (0 == port) 722 next = res;
723 i = 0;
724 while (NULL != (pos = next))
689 { 725 {
690 saddrs = GNUNET_malloc(2 * sizeof(struct sockaddr *)); 726 next = pos->ai_next;
691 saddrlens = GNUNET_malloc(2 * sizeof(socklen_t)); 727 if ((disablev6) && (pos->ai_family == AF_INET6))
692 add_unixpath(saddrs, saddrlens, unixpath, abstract); 728 continue;
693 GNUNET_free_non_null(unixpath); 729 i++;
694 GNUNET_free_non_null(hostname);
695 *addrs = saddrs;
696 *addr_lens = saddrlens;
697 return 1;
698 } 730 }
699 731 if (0 == i)
700 if (NULL != hostname)
701 { 732 {
702 LOG(GNUNET_ERROR_TYPE_DEBUG, 733 LOG (GNUNET_ERROR_TYPE_ERROR,
703 "Resolving `%s' since that is where `%s' will bind to.\n", 734 _ ("Failed to find %saddress for `%s'.\n"),
704 hostname, 735 disablev6 ? "IPv4 " : "",
705 service_name); 736 hostname);
706 memset(&hints, 0, sizeof(struct addrinfo)); 737 freeaddrinfo (res);
707 if (disablev6) 738 GNUNET_free (hostname);
708 hints.ai_family = AF_INET; 739 GNUNET_free_non_null (unixpath);
709 hints.ai_protocol = IPPROTO_TCP; 740 return GNUNET_SYSERR;
710 if ((0 != (ret = getaddrinfo(hostname, NULL, &hints, &res))) || 741 }
711 (NULL == res)) 742 resi = i;
712 { 743 if (NULL != unixpath)
713 LOG(GNUNET_ERROR_TYPE_ERROR, 744 resi++;
714 _("Failed to resolve `%s': %s\n"), 745 saddrs = GNUNET_malloc ((resi + 1) * sizeof(struct sockaddr *));
715 hostname, 746 saddrlens = GNUNET_malloc ((resi + 1) * sizeof(socklen_t));
716 gai_strerror(ret)); 747 i = 0;
717 GNUNET_free(hostname); 748 if (NULL != unixpath)
718 GNUNET_free_non_null(unixpath); 749 {
719 return GNUNET_SYSERR; 750 add_unixpath (saddrs, saddrlens, unixpath, abstract);
720 } 751 i++;
721 next = res; 752 }
722 i = 0; 753 next = res;
723 while (NULL != (pos = next)) 754 while (NULL != (pos = next))
724 { 755 {
725 next = pos->ai_next; 756 next = pos->ai_next;
726 if ((disablev6) && (pos->ai_family == AF_INET6)) 757 if ((disablev6) && (AF_INET6 == pos->ai_family))
727 continue; 758 continue;
728 i++; 759 if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol))
729 } 760 continue; /* not TCP */
730 if (0 == i) 761 if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype))
731 { 762 continue; /* huh? */
732 LOG(GNUNET_ERROR_TYPE_ERROR, 763 LOG (GNUNET_ERROR_TYPE_DEBUG,
733 _("Failed to find %saddress for `%s'.\n"), 764 "Service `%s' will bind to `%s'\n",
734 disablev6 ? "IPv4 " : "", 765 service_name,
735 hostname); 766 GNUNET_a2s (pos->ai_addr, pos->ai_addrlen));
736 freeaddrinfo(res); 767 if (AF_INET == pos->ai_family)
737 GNUNET_free(hostname); 768 {
738 GNUNET_free_non_null(unixpath); 769 GNUNET_assert (sizeof(struct sockaddr_in) == pos->ai_addrlen);
739 return GNUNET_SYSERR; 770 saddrlens[i] = pos->ai_addrlen;
740 } 771 saddrs[i] = GNUNET_malloc (saddrlens[i]);
741 resi = 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;
789 }
790 else
791 {
792 /* will bind against everything, just set port */
793 if (disablev6)
794 {
795 /* V4-only */
796 resi = 1;
742 if (NULL != unixpath) 797 if (NULL != unixpath)
743 resi++; 798 resi++;
744 saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *));
745 saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t));
746 i = 0; 799 i = 0;
800 saddrs = GNUNET_malloc ((resi + 1) * sizeof(struct sockaddr *));
801 saddrlens = GNUNET_malloc ((resi + 1) * sizeof(socklen_t));
747 if (NULL != unixpath) 802 if (NULL != unixpath)
748 { 803 {
749 add_unixpath(saddrs, saddrlens, unixpath, abstract); 804 add_unixpath (saddrs, saddrlens, unixpath, abstract);
750 i++; 805 i++;
751 } 806 }
752 next = res; 807 saddrlens[i] = sizeof(struct sockaddr_in);
753 while (NULL != (pos = next)) 808 saddrs[i] = GNUNET_malloc (saddrlens[i]);
754 {
755 next = pos->ai_next;
756 if ((disablev6) && (AF_INET6 == pos->ai_family))
757 continue;
758 if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol))
759 continue; /* not TCP */
760 if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype))
761 continue; /* huh? */
762 LOG(GNUNET_ERROR_TYPE_DEBUG,
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 }
785 GNUNET_free(hostname);
786 freeaddrinfo(res);
787 resi = i;
788 }
789 else
790 {
791 /* will bind against everything, just set port */
792 if (disablev6)
793 {
794 /* V4-only */
795 resi = 1;
796 if (NULL != unixpath)
797 resi++;
798 i = 0;
799 saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *));
800 saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t));
801 if (NULL != unixpath)
802 {
803 add_unixpath(saddrs, saddrlens, unixpath, abstract);
804 i++;
805 }
806 saddrlens[i] = sizeof(struct sockaddr_in);
807 saddrs[i] = GNUNET_malloc(saddrlens[i]);
808#if HAVE_SOCKADDR_IN_SIN_LEN 809#if HAVE_SOCKADDR_IN_SIN_LEN
809 ((struct sockaddr_in *)saddrs[i])->sin_len = saddrlens[i]; 810 ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i];
810#endif 811#endif
811 ((struct sockaddr_in *)saddrs[i])->sin_family = AF_INET; 812 ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
812 ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port); 813 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
813 } 814 }
814 else 815 else
815 { 816 {
816 /* dual stack */ 817 /* dual stack */
817 resi = 2; 818 resi = 2;
818 if (NULL != unixpath) 819 if (NULL != unixpath)
819 resi++; 820 resi++;
820 saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *)); 821 saddrs = GNUNET_malloc ((resi + 1) * sizeof(struct sockaddr *));
821 saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t)); 822 saddrlens = GNUNET_malloc ((resi + 1) * sizeof(socklen_t));
822 i = 0; 823 i = 0;
823 if (NULL != unixpath) 824 if (NULL != unixpath)
824 { 825 {
825 add_unixpath(saddrs, saddrlens, unixpath, abstract); 826 add_unixpath (saddrs, saddrlens, unixpath, abstract);
826 i++; 827 i++;
827 } 828 }
828 saddrlens[i] = sizeof(struct sockaddr_in6); 829 saddrlens[i] = sizeof(struct sockaddr_in6);
829 saddrs[i] = GNUNET_malloc(saddrlens[i]); 830 saddrs[i] = GNUNET_malloc (saddrlens[i]);
830#if HAVE_SOCKADDR_IN_SIN_LEN 831#if HAVE_SOCKADDR_IN_SIN_LEN
831 ((struct sockaddr_in6 *)saddrs[i])->sin6_len = saddrlens[0]; 832 ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0];
832#endif 833#endif
833 ((struct sockaddr_in6 *)saddrs[i])->sin6_family = AF_INET6; 834 ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6;
834 ((struct sockaddr_in6 *)saddrs[i])->sin6_port = htons(port); 835 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
835 i++; 836 i++;
836 saddrlens[i] = sizeof(struct sockaddr_in); 837 saddrlens[i] = sizeof(struct sockaddr_in);
837 saddrs[i] = GNUNET_malloc(saddrlens[i]); 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);
843 }
844 } 844 }
845 GNUNET_free_non_null(unixpath); 845 }
846 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;
@@ -868,7 +869,7 @@ LEGACY_SERVICE_get_server_addresses(
868 * @return #GNUNET_OK if configuration succeeded 869 * @return #GNUNET_OK if configuration succeeded
869 */ 870 */
870static int 871static int
871setup_service(struct LEGACY_SERVICE_Context *sctx) 872setup_service (struct LEGACY_SERVICE_Context *sctx)
872{ 873{
873 struct GNUNET_TIME_Relative idleout; 874 struct GNUNET_TIME_Relative idleout;
874 int tolerant; 875 int tolerant;
@@ -876,91 +877,91 @@ setup_service(struct LEGACY_SERVICE_Context *sctx)
876 unsigned int cnt; 877 unsigned int cnt;
877 int flags; 878 int flags;
878 879
879 if (GNUNET_CONFIGURATION_have_value(sctx->cfg, 880 if (GNUNET_CONFIGURATION_have_value (sctx->cfg,
880 sctx->service_name, 881 sctx->service_name,
881 "TIMEOUT")) 882 "TIMEOUT"))
883 {
884 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (sctx->cfg,
885 sctx->service_name,
886 "TIMEOUT",
887 &idleout))
882 { 888 {
883 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(sctx->cfg, 889 LOG (GNUNET_ERROR_TYPE_ERROR,
884 sctx->service_name, 890 _ ("Specified value for `%s' of service `%s' is invalid\n"),
885 "TIMEOUT", 891 "TIMEOUT",
886 &idleout)) 892 sctx->service_name);
887 { 893 return GNUNET_SYSERR;
888 LOG(GNUNET_ERROR_TYPE_ERROR,
889 _("Specified value for `%s' of service `%s' is invalid\n"),
890 "TIMEOUT",
891 sctx->service_name);
892 return GNUNET_SYSERR;
893 }
894 sctx->timeout = idleout;
895 } 894 }
895 sctx->timeout = idleout;
896 }
896 else 897 else
897 sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL; 898 sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
898 899
899 if (GNUNET_CONFIGURATION_have_value(sctx->cfg, 900 if (GNUNET_CONFIGURATION_have_value (sctx->cfg,
900 sctx->service_name, 901 sctx->service_name,
901 "TOLERANT")) 902 "TOLERANT"))
903 {
904 if (GNUNET_SYSERR ==
905 (tolerant = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg,
906 sctx->service_name,
907 "TOLERANT")))
902 { 908 {
903 if (GNUNET_SYSERR == 909 LOG (GNUNET_ERROR_TYPE_ERROR,
904 (tolerant = GNUNET_CONFIGURATION_get_value_yesno(sctx->cfg, 910 _ ("Specified value for `%s' of service `%s' is invalid\n"),
905 sctx->service_name, 911 "TOLERANT",
906 "TOLERANT"))) 912 sctx->service_name);
907 { 913 return GNUNET_SYSERR;
908 LOG(GNUNET_ERROR_TYPE_ERROR,
909 _("Specified value for `%s' of service `%s' is invalid\n"),
910 "TOLERANT",
911 sctx->service_name);
912 return GNUNET_SYSERR;
913 }
914 } 914 }
915 }
915 else 916 else
916 tolerant = GNUNET_NO; 917 tolerant = GNUNET_NO;
917 918
918 errno = 0; 919 errno = 0;
919 if ((NULL != (nfds = getenv("LISTEN_FDS"))) && 920 if ((NULL != (nfds = getenv ("LISTEN_FDS"))) &&
920 (1 == sscanf(nfds, "%u", &cnt)) && (cnt > 0) && (cnt < FD_SETSIZE) && 921 (1 == sscanf (nfds, "%u", &cnt)) && (cnt > 0) && (cnt < FD_SETSIZE) &&
921 (cnt + 4 < FD_SETSIZE)) 922 (cnt + 4 < FD_SETSIZE))
923 {
924 sctx->lsocks =
925 GNUNET_malloc (sizeof(struct GNUNET_NETWORK_Handle *) * (cnt + 1));
926 while (0 < cnt--)
922 { 927 {
923 sctx->lsocks = 928 flags = fcntl (3 + cnt, F_GETFD);
924 GNUNET_malloc(sizeof(struct GNUNET_NETWORK_Handle *) * (cnt + 1)); 929 if ((flags < 0) || (0 != (flags & FD_CLOEXEC)) ||
925 while (0 < cnt--) 930 (NULL ==
926 { 931 (sctx->lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt))))
927 flags = fcntl(3 + cnt, F_GETFD); 932 {
928 if ((flags < 0) || (0 != (flags & FD_CLOEXEC)) || 933 LOG (GNUNET_ERROR_TYPE_ERROR,
929 (NULL == 934 _ (
930 (sctx->lsocks[cnt] = GNUNET_NETWORK_socket_box_native(3 + cnt)))) 935 "Could not access pre-bound socket %u, will try to bind myself\n"),
931 { 936 (unsigned int) 3 + cnt);
932 LOG(GNUNET_ERROR_TYPE_ERROR, 937 cnt++;
933 _( 938 while (sctx->lsocks[cnt] != NULL)
934 "Could not access pre-bound socket %u, will try to bind myself\n"), 939 GNUNET_break (0 == GNUNET_NETWORK_socket_close (sctx->lsocks[cnt++]));
935 (unsigned int)3 + cnt); 940 GNUNET_free (sctx->lsocks);
936 cnt++; 941 sctx->lsocks = NULL;
937 while (sctx->lsocks[cnt] != NULL) 942 break;
938 GNUNET_break(0 == GNUNET_NETWORK_socket_close(sctx->lsocks[cnt++])); 943 }
939 GNUNET_free(sctx->lsocks);
940 sctx->lsocks = NULL;
941 break;
942 }
943 }
944 unsetenv("LISTEN_FDS");
945 } 944 }
945 unsetenv ("LISTEN_FDS");
946 }
946 947
947 if ((NULL == sctx->lsocks) && 948 if ((NULL == sctx->lsocks) &&
948 (GNUNET_SYSERR == LEGACY_SERVICE_get_server_addresses(sctx->service_name, 949 (GNUNET_SYSERR == LEGACY_SERVICE_get_server_addresses (sctx->service_name,
949 sctx->cfg, 950 sctx->cfg,
950 &sctx->addrs, 951 &sctx->addrs,
951 &sctx->addrlens))) 952 &sctx->addrlens)))
952 return GNUNET_SYSERR; 953 return GNUNET_SYSERR;
953 sctx->require_found = tolerant ? GNUNET_NO : GNUNET_YES; 954 sctx->require_found = tolerant ? GNUNET_NO : GNUNET_YES;
954 sctx->match_uid = GNUNET_CONFIGURATION_get_value_yesno(sctx->cfg, 955 sctx->match_uid = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg,
955 sctx->service_name, 956 sctx->service_name,
956 "UNIX_MATCH_UID"); 957 "UNIX_MATCH_UID");
957 sctx->match_gid = GNUNET_CONFIGURATION_get_value_yesno(sctx->cfg, 958 sctx->match_gid = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg,
958 sctx->service_name, 959 sctx->service_name,
959 "UNIX_MATCH_GID"); 960 "UNIX_MATCH_GID");
960 process_acl4(&sctx->v4_denied, sctx, "REJECT_FROM"); 961 process_acl4 (&sctx->v4_denied, sctx, "REJECT_FROM");
961 process_acl4(&sctx->v4_allowed, sctx, "ACCEPT_FROM"); 962 process_acl4 (&sctx->v4_allowed, sctx, "ACCEPT_FROM");
962 process_acl6(&sctx->v6_denied, sctx, "REJECT_FROM6"); 963 process_acl6 (&sctx->v6_denied, sctx, "REJECT_FROM6");
963 process_acl6(&sctx->v6_allowed, sctx, "ACCEPT_FROM6"); 964 process_acl6 (&sctx->v6_allowed, sctx, "ACCEPT_FROM6");
964 965
965 return GNUNET_OK; 966 return GNUNET_OK;
966} 967}
@@ -974,14 +975,14 @@ setup_service(struct LEGACY_SERVICE_Context *sctx)
974 * @return value of the 'USERNAME' option 975 * @return value of the 'USERNAME' option
975 */ 976 */
976static char * 977static char *
977get_user_name(struct LEGACY_SERVICE_Context *sctx) 978get_user_name (struct LEGACY_SERVICE_Context *sctx)
978{ 979{
979 char *un; 980 char *un;
980 981
981 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(sctx->cfg, 982 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (sctx->cfg,
982 sctx->service_name, 983 sctx->service_name,
983 "USERNAME", 984 "USERNAME",
984 &un)) 985 &un))
985 return NULL; 986 return NULL;
986 return un; 987 return un;
987} 988}
@@ -995,7 +996,7 @@ get_user_name(struct LEGACY_SERVICE_Context *sctx)
995 * @return #GNUNET_OK on success (including no work to be done) 996 * @return #GNUNET_OK on success (including no work to be done)
996 */ 997 */
997static int 998static int
998write_pid_file(struct LEGACY_SERVICE_Context *sctx, pid_t pid) 999write_pid_file (struct LEGACY_SERVICE_Context *sctx, pid_t pid)
999{ 1000{
1000 FILE *pidfd; 1001 FILE *pidfd;
1001 char *pif; 1002 char *pif;
@@ -1003,46 +1004,46 @@ write_pid_file(struct LEGACY_SERVICE_Context *sctx, pid_t pid)
1003 char *rdir; 1004 char *rdir;
1004 int len; 1005 int len;
1005 1006
1006 if (NULL == (pif = get_pid_file_name(sctx))) 1007 if (NULL == (pif = get_pid_file_name (sctx)))
1007 return GNUNET_OK; /* no file desired */ 1008 return GNUNET_OK; /* no file desired */
1008 user = get_user_name(sctx); 1009 user = get_user_name (sctx);
1009 rdir = GNUNET_strdup(pif); 1010 rdir = GNUNET_strdup (pif);
1010 len = strlen(rdir); 1011 len = strlen (rdir);
1011 while ((len > 0) && (rdir[len] != DIR_SEPARATOR)) 1012 while ((len > 0) && (rdir[len] != DIR_SEPARATOR))
1012 len--; 1013 len--;
1013 rdir[len] = '\0'; 1014 rdir[len] = '\0';
1014 if (0 != access(rdir, F_OK)) 1015 if (0 != access (rdir, F_OK))
1015 { 1016 {
1016 /* we get to create a directory -- and claim it 1017 /* we get to create a directory -- and claim it
1017 * as ours! */ 1018 * as ours! */
1018 (void)GNUNET_DISK_directory_create(rdir); 1019 (void) GNUNET_DISK_directory_create (rdir);
1019 if ((NULL != user) && (0 < strlen(user))) 1020 if ((NULL != user) && (0 < strlen (user)))
1020 GNUNET_DISK_file_change_owner(rdir, user); 1021 GNUNET_DISK_file_change_owner (rdir, user);
1021 } 1022 }
1022 if (0 != access(rdir, W_OK | X_OK)) 1023 if (0 != access (rdir, W_OK | X_OK))
1023 { 1024 {
1024 LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_ERROR, "access", rdir); 1025 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", rdir);
1025 GNUNET_free(rdir); 1026 GNUNET_free (rdir);
1026 GNUNET_free_non_null(user); 1027 GNUNET_free_non_null (user);
1027 GNUNET_free(pif); 1028 GNUNET_free (pif);
1028 return GNUNET_SYSERR; 1029 return GNUNET_SYSERR;
1029 } 1030 }
1030 GNUNET_free(rdir); 1031 GNUNET_free (rdir);
1031 pidfd = fopen(pif, "w"); 1032 pidfd = fopen (pif, "w");
1032 if (NULL == pidfd) 1033 if (NULL == pidfd)
1033 { 1034 {
1034 LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_ERROR, "fopen", pif); 1035 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "fopen", pif);
1035 GNUNET_free(pif); 1036 GNUNET_free (pif);
1036 GNUNET_free_non_null(user); 1037 GNUNET_free_non_null (user);
1037 return GNUNET_SYSERR; 1038 return GNUNET_SYSERR;
1038 } 1039 }
1039 if (0 > fprintf(pidfd, "%u", pid)) 1040 if (0 > fprintf (pidfd, "%u", pid))
1040 LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_WARNING, "fprintf", pif); 1041 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fprintf", pif);
1041 GNUNET_break(0 == fclose(pidfd)); 1042 GNUNET_break (0 == fclose (pidfd));
1042 if ((NULL != user) && (0 < strlen(user))) 1043 if ((NULL != user) && (0 < strlen (user)))
1043 GNUNET_DISK_file_change_owner(pif, user); 1044 GNUNET_DISK_file_change_owner (pif, user);
1044 GNUNET_free_non_null(user); 1045 GNUNET_free_non_null (user);
1045 GNUNET_free(pif); 1046 GNUNET_free (pif);
1046 return GNUNET_OK; 1047 return GNUNET_OK;
1047} 1048}
1048 1049
@@ -1053,16 +1054,16 @@ write_pid_file(struct LEGACY_SERVICE_Context *sctx, pid_t pid)
1053 * @param cls the `struct LEGACY_SERVICE_Context` 1054 * @param cls the `struct LEGACY_SERVICE_Context`
1054 */ 1055 */
1055static void 1056static void
1056shutdown_task(void *cls) 1057shutdown_task (void *cls)
1057{ 1058{
1058 struct LEGACY_SERVICE_Context *service = cls; 1059 struct LEGACY_SERVICE_Context *service = cls;
1059 struct GNUNET_SERVER_Handle *server = service->server; 1060 struct GNUNET_SERVER_Handle *server = service->server;
1060 1061
1061 service->shutdown_task = NULL; 1062 service->shutdown_task = NULL;
1062 if (0 != (service->options & LEGACY_SERVICE_OPTION_SOFT_SHUTDOWN)) 1063 if (0 != (service->options & LEGACY_SERVICE_OPTION_SOFT_SHUTDOWN))
1063 GNUNET_SERVER_stop_listening(server); 1064 GNUNET_SERVER_stop_listening (server);
1064 else 1065 else
1065 GNUNET_SERVER_destroy(server); 1066 GNUNET_SERVER_destroy (server);
1066} 1067}
1067 1068
1068 1069
@@ -1072,79 +1073,79 @@ shutdown_task(void *cls)
1072 * @param cls service context 1073 * @param cls service context
1073 */ 1074 */
1074static void 1075static void
1075service_task(void *cls) 1076service_task (void *cls)
1076{ 1077{
1077 struct LEGACY_SERVICE_Context *sctx = cls; 1078 struct LEGACY_SERVICE_Context *sctx = cls;
1078 unsigned int i; 1079 unsigned int i;
1079 1080
1080 GNUNET_RESOLVER_connect(sctx->cfg); 1081 GNUNET_RESOLVER_connect (sctx->cfg);
1081 if (NULL != sctx->lsocks) 1082 if (NULL != sctx->lsocks)
1082 sctx->server = GNUNET_SERVER_create_with_sockets(&check_access, 1083 sctx->server = GNUNET_SERVER_create_with_sockets (&check_access,
1083 sctx, 1084 sctx,
1084 sctx->lsocks, 1085 sctx->lsocks,
1085 sctx->timeout, 1086 sctx->timeout,
1086 sctx->require_found); 1087 sctx->require_found);
1087 else 1088 else
1088 sctx->server = GNUNET_SERVER_create(&check_access, 1089 sctx->server = GNUNET_SERVER_create (&check_access,
1089 sctx, 1090 sctx,
1090 sctx->addrs, 1091 sctx->addrs,
1091 sctx->addrlens, 1092 sctx->addrlens,
1092 sctx->timeout, 1093 sctx->timeout,
1093 sctx->require_found); 1094 sctx->require_found);
1094 if (NULL == sctx->server) 1095 if (NULL == sctx->server)
1095 { 1096 {
1096 if (NULL != sctx->addrs) 1097 if (NULL != sctx->addrs)
1097 for (i = 0; NULL != sctx->addrs[i]; i++) 1098 for (i = 0; NULL != sctx->addrs[i]; i++)
1098 LOG(GNUNET_ERROR_TYPE_INFO, 1099 LOG (GNUNET_ERROR_TYPE_INFO,
1099 _("Failed to start `%s' at `%s'\n"), 1100 _ ("Failed to start `%s' at `%s'\n"),
1100 sctx->service_name, 1101 sctx->service_name,
1101 GNUNET_a2s(sctx->addrs[i], sctx->addrlens[i])); 1102 GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i]));
1102 sctx->ret = GNUNET_SYSERR; 1103 sctx->ret = GNUNET_SYSERR;
1103 return; 1104 return;
1104 } 1105 }
1105 1106
1106 if (NULL != sctx->addrs) 1107 if (NULL != sctx->addrs)
1107 for (i = 0; NULL != sctx->addrs[i]; i++) 1108 for (i = 0; NULL != sctx->addrs[i]; i++)
1108 if ((AF_UNIX == sctx->addrs[i]->sa_family) && 1109 if ((AF_UNIX == sctx->addrs[i]->sa_family) &&
1109 ('\0' != ((const struct sockaddr_un *)sctx->addrs[i])->sun_path[0])) 1110 ('\0' != ((const struct sockaddr_un *) sctx->addrs[i])->sun_path[0]))
1110 GNUNET_DISK_fix_permissions(((const struct sockaddr_un *) 1111 GNUNET_DISK_fix_permissions (((const struct sockaddr_un *)
1111 sctx->addrs[i]) 1112 sctx->addrs[i])
1112 ->sun_path, 1113 ->sun_path,
1113 sctx->match_uid, 1114 sctx->match_uid,
1114 sctx->match_gid); 1115 sctx->match_gid);
1115 1116
1116 if (0 == (sctx->options & LEGACY_SERVICE_OPTION_MANUAL_SHUTDOWN)) 1117 if (0 == (sctx->options & LEGACY_SERVICE_OPTION_MANUAL_SHUTDOWN))
1117 { 1118 {
1118 /* install a task that will kill the server 1119 /* install a task that will kill the server
1119 * process if the scheduler ever gets a shutdown signal */ 1120 * process if the scheduler ever gets a shutdown signal */
1120 sctx->shutdown_task = GNUNET_SCHEDULER_add_shutdown(&shutdown_task, sctx); 1121 sctx->shutdown_task = GNUNET_SCHEDULER_add_shutdown (&shutdown_task, sctx);
1121 } 1122 }
1122 sctx->my_handlers = GNUNET_malloc(sizeof(defhandlers)); 1123 sctx->my_handlers = GNUNET_malloc (sizeof(defhandlers));
1123 GNUNET_memcpy(sctx->my_handlers, defhandlers, sizeof(defhandlers)); 1124 GNUNET_memcpy (sctx->my_handlers, defhandlers, sizeof(defhandlers));
1124 i = 0; 1125 i = 0;
1125 while (NULL != sctx->my_handlers[i].callback) 1126 while (NULL != sctx->my_handlers[i].callback)
1126 sctx->my_handlers[i++].callback_cls = sctx; 1127 sctx->my_handlers[i++].callback_cls = sctx;
1127 GNUNET_SERVER_add_handlers(sctx->server, sctx->my_handlers); 1128 GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers);
1128 if (-1 != sctx->ready_confirm_fd) 1129 if (-1 != sctx->ready_confirm_fd)
1129 { 1130 {
1130 GNUNET_break(1 == write(sctx->ready_confirm_fd, ".", 1)); 1131 GNUNET_break (1 == write (sctx->ready_confirm_fd, ".", 1));
1131 GNUNET_break(0 == close(sctx->ready_confirm_fd)); 1132 GNUNET_break (0 == close (sctx->ready_confirm_fd));
1132 sctx->ready_confirm_fd = -1; 1133 sctx->ready_confirm_fd = -1;
1133 write_pid_file(sctx, getpid()); 1134 write_pid_file (sctx, getpid ());
1134 } 1135 }
1135 if (NULL != sctx->addrs) 1136 if (NULL != sctx->addrs)
1137 {
1138 i = 0;
1139 while (NULL != sctx->addrs[i])
1136 { 1140 {
1137 i = 0; 1141 LOG (GNUNET_ERROR_TYPE_INFO,
1138 while (NULL != sctx->addrs[i]) 1142 _ ("Service `%s' runs at %s\n"),
1139 { 1143 sctx->service_name,
1140 LOG(GNUNET_ERROR_TYPE_INFO, 1144 GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i]));
1141 _("Service `%s' runs at %s\n"), 1145 i++;
1142 sctx->service_name,
1143 GNUNET_a2s(sctx->addrs[i], sctx->addrlens[i]));
1144 i++;
1145 }
1146 } 1146 }
1147 sctx->task(sctx->task_cls, sctx->server, sctx->cfg); 1147 }
1148 sctx->task (sctx->task_cls, sctx->server, sctx->cfg);
1148} 1149}
1149 1150
1150 1151
@@ -1155,73 +1156,73 @@ service_task(void *cls)
1155 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 1156 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1156 */ 1157 */
1157static int 1158static int
1158detach_terminal(struct LEGACY_SERVICE_Context *sctx) 1159detach_terminal (struct LEGACY_SERVICE_Context *sctx)
1159{ 1160{
1160 pid_t pid; 1161 pid_t pid;
1161 int nullfd; 1162 int nullfd;
1162 int filedes[2]; 1163 int filedes[2];
1163 1164
1164 if (0 != pipe(filedes)) 1165 if (0 != pipe (filedes))
1165 { 1166 {
1166 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "pipe"); 1167 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe");
1167 return GNUNET_SYSERR; 1168 return GNUNET_SYSERR;
1168 } 1169 }
1169 pid = fork(); 1170 pid = fork ();
1170 if (pid < 0) 1171 if (pid < 0)
1171 { 1172 {
1172 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "fork"); 1173 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork");
1173 return GNUNET_SYSERR; 1174 return GNUNET_SYSERR;
1174 } 1175 }
1175 if (0 != pid) 1176 if (0 != pid)
1177 {
1178 /* Parent */
1179 char c;
1180
1181 GNUNET_break (0 == close (filedes[1]));
1182 c = 'X';
1183 if (1 != read (filedes[0], &c, sizeof(char)))
1184 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "read");
1185 fflush (stdout);
1186 switch (c)
1176 { 1187 {
1177 /* Parent */ 1188 case '.':
1178 char c; 1189 exit (0);
1179 1190
1180 GNUNET_break(0 == close(filedes[1])); 1191 case 'I':
1181 c = 'X'; 1192 LOG (GNUNET_ERROR_TYPE_INFO,
1182 if (1 != read(filedes[0], &c, sizeof(char))) 1193 _ ("Service process failed to initialize\n"));
1183 LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, "read"); 1194 break;
1184 fflush(stdout); 1195
1185 switch (c) 1196 case 'S':
1186 { 1197 LOG (GNUNET_ERROR_TYPE_INFO,
1187 case '.': 1198 _ ("Service process could not initialize server function\n"));
1188 exit(0); 1199 break;
1189 1200
1190 case 'I': 1201 case 'X':
1191 LOG(GNUNET_ERROR_TYPE_INFO, 1202 LOG (GNUNET_ERROR_TYPE_INFO,
1192 _("Service process failed to initialize\n")); 1203 _ ("Service process failed to report status\n"));
1193 break; 1204 break;
1194
1195 case 'S':
1196 LOG(GNUNET_ERROR_TYPE_INFO,
1197 _("Service process could not initialize server function\n"));
1198 break;
1199
1200 case 'X':
1201 LOG(GNUNET_ERROR_TYPE_INFO,
1202 _("Service process failed to report status\n"));
1203 break;
1204 }
1205 exit(1); /* child reported error */
1206 } 1205 }
1207 GNUNET_break(0 == close(0)); 1206 exit (1); /* child reported error */
1208 GNUNET_break(0 == close(1)); 1207 }
1209 GNUNET_break(0 == close(filedes[0])); 1208 GNUNET_break (0 == close (0));
1210 nullfd = open("/dev/null", O_RDWR | O_APPEND); 1209 GNUNET_break (0 == close (1));
1210 GNUNET_break (0 == close (filedes[0]));
1211 nullfd = open ("/dev/null", O_RDWR | O_APPEND);
1211 if (nullfd < 0) 1212 if (nullfd < 0)
1212 return GNUNET_SYSERR; 1213 return GNUNET_SYSERR;
1213 /* set stdin/stdout to /dev/null */ 1214 /* set stdin/stdout to /dev/null */
1214 if ((dup2(nullfd, 0) < 0) || (dup2(nullfd, 1) < 0)) 1215 if ((dup2 (nullfd, 0) < 0) || (dup2 (nullfd, 1) < 0))
1215 { 1216 {
1216 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "dup2"); 1217 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2");
1217 (void)close(nullfd); 1218 (void) close (nullfd);
1218 return GNUNET_SYSERR; 1219 return GNUNET_SYSERR;
1219 } 1220 }
1220 (void)close(nullfd); 1221 (void) close (nullfd);
1221 /* Detach from controlling terminal */ 1222 /* Detach from controlling terminal */
1222 pid = setsid(); 1223 pid = setsid ();
1223 if (-1 == pid) 1224 if (-1 == pid)
1224 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "setsid"); 1225 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "setsid");
1225 sctx->ready_confirm_fd = filedes[1]; 1226 sctx->ready_confirm_fd = filedes[1];
1226 1227
1227 return GNUNET_OK; 1228 return GNUNET_OK;
@@ -1235,45 +1236,45 @@ detach_terminal(struct LEGACY_SERVICE_Context *sctx)
1235 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 1236 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1236 */ 1237 */
1237static int 1238static int
1238set_user_id(struct LEGACY_SERVICE_Context *sctx) 1239set_user_id (struct LEGACY_SERVICE_Context *sctx)
1239{ 1240{
1240 char *user; 1241 char *user;
1241 1242
1242 if (NULL == (user = get_user_name(sctx))) 1243 if (NULL == (user = get_user_name (sctx)))
1243 return GNUNET_OK; /* keep */ 1244 return GNUNET_OK; /* keep */
1244 1245
1245 struct passwd *pws; 1246 struct passwd *pws;
1246 1247
1247 errno = 0; 1248 errno = 0;
1248 pws = getpwnam(user); 1249 pws = getpwnam (user);
1249 if (NULL == pws) 1250 if (NULL == pws)
1250 { 1251 {
1251 LOG(GNUNET_ERROR_TYPE_ERROR, 1252 LOG (GNUNET_ERROR_TYPE_ERROR,
1252 _("Cannot obtain information about user `%s': %s\n"), 1253 _ ("Cannot obtain information about user `%s': %s\n"),
1253 user, 1254 user,
1254 errno == 0 ? _("No such user") : strerror(errno)); 1255 errno == 0 ? _ ("No such user") : strerror (errno));
1255 GNUNET_free(user); 1256 GNUNET_free (user);
1256 return GNUNET_SYSERR; 1257 return GNUNET_SYSERR;
1257 } 1258 }
1258 if ((0 != setgid(pws->pw_gid)) || (0 != setegid(pws->pw_gid)) || 1259 if ((0 != setgid (pws->pw_gid)) || (0 != setegid (pws->pw_gid)) ||
1259#if HAVE_INITGROUPS 1260#if HAVE_INITGROUPS
1260 (0 != initgroups(user, pws->pw_gid)) || 1261 (0 != initgroups (user, pws->pw_gid)) ||
1261#endif 1262#endif
1262 (0 != setuid(pws->pw_uid)) || (0 != seteuid(pws->pw_uid))) 1263 (0 != setuid (pws->pw_uid)) || (0 != seteuid (pws->pw_uid)))
1264 {
1265 if ((0 != setregid (pws->pw_gid, pws->pw_gid)) ||
1266 (0 != setreuid (pws->pw_uid, pws->pw_uid)))
1263 { 1267 {
1264 if ((0 != setregid(pws->pw_gid, pws->pw_gid)) || 1268 LOG (GNUNET_ERROR_TYPE_ERROR,
1265 (0 != setreuid(pws->pw_uid, pws->pw_uid))) 1269 _ ("Cannot change user/group to `%s': %s\n"),
1266 { 1270 user,
1267 LOG(GNUNET_ERROR_TYPE_ERROR, 1271 strerror (errno));
1268 _("Cannot change user/group to `%s': %s\n"), 1272 GNUNET_free (user);
1269 user, 1273 return GNUNET_SYSERR;
1270 strerror(errno));
1271 GNUNET_free(user);
1272 return GNUNET_SYSERR;
1273 }
1274 } 1274 }
1275 }
1275 1276
1276 GNUNET_free(user); 1277 GNUNET_free (user);
1277 return GNUNET_OK; 1278 return GNUNET_OK;
1278} 1279}
1279 1280
@@ -1284,15 +1285,15 @@ set_user_id(struct LEGACY_SERVICE_Context *sctx)
1284 * @param sctx service context 1285 * @param sctx service context
1285 */ 1286 */
1286static void 1287static void
1287pid_file_delete(struct LEGACY_SERVICE_Context *sctx) 1288pid_file_delete (struct LEGACY_SERVICE_Context *sctx)
1288{ 1289{
1289 char *pif = get_pid_file_name(sctx); 1290 char *pif = get_pid_file_name (sctx);
1290 1291
1291 if (NULL == pif) 1292 if (NULL == pif)
1292 return; /* no PID file */ 1293 return; /* no PID file */
1293 if (0 != unlink(pif)) 1294 if (0 != unlink (pif))
1294 LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_WARNING, "unlink", pif); 1295 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", pif);
1295 GNUNET_free(pif); 1296 GNUNET_free (pif);
1296} 1297}
1297 1298
1298 1299
@@ -1310,19 +1311,19 @@ pid_file_delete(struct LEGACY_SERVICE_Context *sctx)
1310 * if we shutdown nicely 1311 * if we shutdown nicely
1311 */ 1312 */
1312int 1313int
1313LEGACY_SERVICE_run(int argc, 1314LEGACY_SERVICE_run (int argc,
1314 char *const *argv, 1315 char *const *argv,
1315 const char *service_name, 1316 const char *service_name,
1316 enum LEGACY_SERVICE_Options options, 1317 enum LEGACY_SERVICE_Options options,
1317 LEGACY_SERVICE_Main task, 1318 LEGACY_SERVICE_Main task,
1318 void *task_cls) 1319 void *task_cls)
1319{ 1320{
1320#define HANDLE_ERROR \ 1321#define HANDLE_ERROR \
1321 do \ 1322 do \
1322 { \ 1323 { \
1323 GNUNET_break(0); \ 1324 GNUNET_break (0); \
1324 goto shutdown; \ 1325 goto shutdown; \
1325 } while (0) 1326 } while (0)
1326 1327
1327 int err; 1328 int err;
1328 int ret; 1329 int ret;
@@ -1340,32 +1341,32 @@ LEGACY_SERVICE_run(int argc,
1340 const char *xdg; 1341 const char *xdg;
1341 1342
1342 struct GNUNET_GETOPT_CommandLineOption service_options[] = 1343 struct GNUNET_GETOPT_CommandLineOption service_options[] =
1343 { GNUNET_GETOPT_option_cfgfile(&opt_cfg_fn), 1344 { GNUNET_GETOPT_option_cfgfile (&opt_cfg_fn),
1344 GNUNET_GETOPT_option_flag('d', 1345 GNUNET_GETOPT_option_flag ('d',
1345 "daemonize", 1346 "daemonize",
1346 gettext_noop( 1347 gettext_noop (
1347 "do daemonize (detach from terminal)"), 1348 "do daemonize (detach from terminal)"),
1348 &do_daemonize), 1349 &do_daemonize),
1349 GNUNET_GETOPT_option_help(NULL), 1350 GNUNET_GETOPT_option_help (NULL),
1350 GNUNET_GETOPT_option_loglevel(&loglev), 1351 GNUNET_GETOPT_option_loglevel (&loglev),
1351 GNUNET_GETOPT_option_logfile(&logfile), 1352 GNUNET_GETOPT_option_logfile (&logfile),
1352 GNUNET_GETOPT_option_version(PACKAGE_VERSION " " VCS_VERSION), 1353 GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION),
1353 GNUNET_GETOPT_OPTION_END }; 1354 GNUNET_GETOPT_OPTION_END };
1354 err = 1; 1355 err = 1;
1355 do_daemonize = 0; 1356 do_daemonize = 0;
1356 logfile = NULL; 1357 logfile = NULL;
1357 loglev = NULL; 1358 loglev = NULL;
1358 opt_cfg_fn = NULL; 1359 opt_cfg_fn = NULL;
1359 xdg = getenv("XDG_CONFIG_HOME"); 1360 xdg = getenv ("XDG_CONFIG_HOME");
1360 if (NULL != xdg) 1361 if (NULL != xdg)
1361 GNUNET_asprintf(&cfg_fn, 1362 GNUNET_asprintf (&cfg_fn,
1362 "%s%s%s", 1363 "%s%s%s",
1363 xdg, 1364 xdg,
1364 DIR_SEPARATOR_STR, 1365 DIR_SEPARATOR_STR,
1365 GNUNET_OS_project_data_get()->config_file); 1366 GNUNET_OS_project_data_get ()->config_file);
1366 else 1367 else
1367 cfg_fn = GNUNET_strdup(GNUNET_OS_project_data_get()->user_config_file); 1368 cfg_fn = GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file);
1368 memset(&sctx, 0, sizeof(sctx)); 1369 memset (&sctx, 0, sizeof(sctx));
1369 sctx.options = options; 1370 sctx.options = options;
1370 sctx.ready_confirm_fd = -1; 1371 sctx.ready_confirm_fd = -1;
1371 sctx.ret = GNUNET_OK; 1372 sctx.ret = GNUNET_OK;
@@ -1373,117 +1374,117 @@ LEGACY_SERVICE_run(int argc,
1373 sctx.task = task; 1374 sctx.task = task;
1374 sctx.task_cls = task_cls; 1375 sctx.task_cls = task_cls;
1375 sctx.service_name = service_name; 1376 sctx.service_name = service_name;
1376 sctx.cfg = cfg = GNUNET_CONFIGURATION_create(); 1377 sctx.cfg = cfg = GNUNET_CONFIGURATION_create ();
1377 1378
1378 /* setup subsystems */ 1379 /* setup subsystems */
1379 ret = GNUNET_GETOPT_run(service_name, service_options, argc, argv); 1380 ret = GNUNET_GETOPT_run (service_name, service_options, argc, argv);
1380 if (GNUNET_SYSERR == ret) 1381 if (GNUNET_SYSERR == ret)
1381 goto shutdown; 1382 goto shutdown;
1382 if (GNUNET_NO == ret) 1383 if (GNUNET_NO == ret)
1383 { 1384 {
1384 err = 0; 1385 err = 0;
1385 goto shutdown; 1386 goto shutdown;
1386 } 1387 }
1387 if (GNUNET_OK != GNUNET_log_setup(service_name, loglev, logfile)) 1388 if (GNUNET_OK != GNUNET_log_setup (service_name, loglev, logfile))
1388 HANDLE_ERROR; 1389 HANDLE_ERROR;
1389 if (NULL == opt_cfg_fn) 1390 if (NULL == opt_cfg_fn)
1390 opt_cfg_fn = GNUNET_strdup(cfg_fn); 1391 opt_cfg_fn = GNUNET_strdup (cfg_fn);
1391 if (GNUNET_YES == GNUNET_DISK_file_test(opt_cfg_fn)) 1392 if (GNUNET_YES == GNUNET_DISK_file_test (opt_cfg_fn))
1393 {
1394 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, opt_cfg_fn))
1392 { 1395 {
1393 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load(cfg, opt_cfg_fn)) 1396 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1394 { 1397 _ ("Malformed configuration file `%s', exit ...\n"),
1395 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1398 opt_cfg_fn);
1396 _("Malformed configuration file `%s', exit ...\n"), 1399 goto shutdown;
1397 opt_cfg_fn);
1398 goto shutdown;
1399 }
1400 } 1400 }
1401 }
1401 else 1402 else
1403 {
1404 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, NULL))
1402 { 1405 {
1403 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load(cfg, NULL)) 1406 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1404 { 1407 _ ("Malformed configuration, exit ...\n"));
1405 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1408 goto shutdown;
1406 _("Malformed configuration, exit ...\n"));
1407 goto shutdown;
1408 }
1409 if (0 != strcmp(opt_cfg_fn, cfg_fn))
1410 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1411 _("Could not access configuration file `%s'\n"),
1412 opt_cfg_fn);
1413 } 1409 }
1414 if (GNUNET_OK != setup_service(&sctx)) 1410 if (0 != strcmp (opt_cfg_fn, cfg_fn))
1411 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1412 _ ("Could not access configuration file `%s'\n"),
1413 opt_cfg_fn);
1414 }
1415 if (GNUNET_OK != setup_service (&sctx))
1415 goto shutdown; 1416 goto shutdown;
1416 if ((1 == do_daemonize) && (GNUNET_OK != detach_terminal(&sctx))) 1417 if ((1 == do_daemonize) && (GNUNET_OK != detach_terminal (&sctx)))
1417 HANDLE_ERROR; 1418 HANDLE_ERROR;
1418 if (GNUNET_OK != set_user_id(&sctx)) 1419 if (GNUNET_OK != set_user_id (&sctx))
1419 goto shutdown; 1420 goto shutdown;
1420 LOG(GNUNET_ERROR_TYPE_DEBUG, 1421 LOG (GNUNET_ERROR_TYPE_DEBUG,
1421 "Service `%s' runs with configuration from `%s'\n", 1422 "Service `%s' runs with configuration from `%s'\n",
1422 service_name, 1423 service_name,
1423 opt_cfg_fn); 1424 opt_cfg_fn);
1424 if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(sctx.cfg, 1425 if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sctx.cfg,
1425 "TESTING", 1426 "TESTING",
1426 "SKEW_OFFSET", 1427 "SKEW_OFFSET",
1427 &skew_offset)) && 1428 &skew_offset)) &&
1428 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(sctx.cfg, 1429 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sctx.cfg,
1429 "TESTING", 1430 "TESTING",
1430 "SKEW_VARIANCE", 1431 "SKEW_VARIANCE",
1431 &skew_variance))) 1432 &skew_variance)))
1432 { 1433 {
1433 clock_offset = skew_offset - skew_variance; 1434 clock_offset = skew_offset - skew_variance;
1434 GNUNET_TIME_set_offset(clock_offset); 1435 GNUNET_TIME_set_offset (clock_offset);
1435 LOG(GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %dll ms\n", clock_offset); 1436 LOG (GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %dll ms\n", clock_offset);
1436 } 1437 }
1437 /* actually run service */ 1438 /* actually run service */
1438 err = 0; 1439 err = 0;
1439 GNUNET_SCHEDULER_run(&service_task, &sctx); 1440 GNUNET_SCHEDULER_run (&service_task, &sctx);
1440 /* shutdown */ 1441 /* shutdown */
1441 if ((1 == do_daemonize) && (NULL != sctx.server)) 1442 if ((1 == do_daemonize) && (NULL != sctx.server))
1442 pid_file_delete(&sctx); 1443 pid_file_delete (&sctx);
1443 GNUNET_free_non_null(sctx.my_handlers); 1444 GNUNET_free_non_null (sctx.my_handlers);
1444 1445
1445shutdown: 1446shutdown:
1446 if (-1 != sctx.ready_confirm_fd) 1447 if (-1 != sctx.ready_confirm_fd)
1447 { 1448 {
1448 if (1 != write(sctx.ready_confirm_fd, err ? "I" : "S", 1)) 1449 if (1 != write (sctx.ready_confirm_fd, err ? "I" : "S", 1))
1449 LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, "write"); 1450 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "write");
1450 GNUNET_break(0 == close(sctx.ready_confirm_fd)); 1451 GNUNET_break (0 == close (sctx.ready_confirm_fd));
1451 } 1452 }
1452#if HAVE_MALLINFO 1453#if HAVE_MALLINFO
1453 { 1454 {
1454 char *counter; 1455 char *counter;
1455 1456
1456 if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value(sctx.cfg, 1457 if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (sctx.cfg,
1457 service_name, 1458 service_name,
1458 "GAUGER_HEAP")) && 1459 "GAUGER_HEAP")) &&
1459 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(sctx.cfg, 1460 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (sctx.cfg,
1460 service_name, 1461 service_name,
1461 "GAUGER_HEAP", 1462 "GAUGER_HEAP",
1462 &counter))) 1463 &counter)))
1463 { 1464 {
1464 struct mallinfo mi; 1465 struct mallinfo mi;
1465 1466
1466 mi = mallinfo(); 1467 mi = mallinfo ();
1467 GAUGER(service_name, counter, mi.usmblks, "blocks"); 1468 GAUGER (service_name, counter, mi.usmblks, "blocks");
1468 GNUNET_free(counter); 1469 GNUNET_free (counter);
1469 } 1470 }
1470 } 1471 }
1471#endif 1472#endif
1472 GNUNET_CONFIGURATION_destroy(cfg); 1473 GNUNET_CONFIGURATION_destroy (cfg);
1473 i = 0; 1474 i = 0;
1474 if (NULL != sctx.addrs) 1475 if (NULL != sctx.addrs)
1475 while (NULL != sctx.addrs[i]) 1476 while (NULL != sctx.addrs[i])
1476 GNUNET_free(sctx.addrs[i++]); 1477 GNUNET_free (sctx.addrs[i++]);
1477 GNUNET_free_non_null(sctx.addrs); 1478 GNUNET_free_non_null (sctx.addrs);
1478 GNUNET_free_non_null(sctx.addrlens); 1479 GNUNET_free_non_null (sctx.addrlens);
1479 GNUNET_free_non_null(logfile); 1480 GNUNET_free_non_null (logfile);
1480 GNUNET_free_non_null(loglev); 1481 GNUNET_free_non_null (loglev);
1481 GNUNET_free(cfg_fn); 1482 GNUNET_free (cfg_fn);
1482 GNUNET_free_non_null(opt_cfg_fn); 1483 GNUNET_free_non_null (opt_cfg_fn);
1483 GNUNET_free_non_null(sctx.v4_denied); 1484 GNUNET_free_non_null (sctx.v4_denied);
1484 GNUNET_free_non_null(sctx.v6_denied); 1485 GNUNET_free_non_null (sctx.v6_denied);
1485 GNUNET_free_non_null(sctx.v4_allowed); 1486 GNUNET_free_non_null (sctx.v4_allowed);
1486 GNUNET_free_non_null(sctx.v6_allowed); 1487 GNUNET_free_non_null (sctx.v6_allowed);
1487 1488
1488 return err ? GNUNET_SYSERR : sctx.ret; 1489 return err ? GNUNET_SYSERR : sctx.ret;
1489} 1490}
@@ -1499,14 +1500,14 @@ shutdown:
1499 * @return NULL on error, service handle 1500 * @return NULL on error, service handle
1500 */ 1501 */
1501struct LEGACY_SERVICE_Context * 1502struct LEGACY_SERVICE_Context *
1502LEGACY_SERVICE_start(const char *service_name, 1503LEGACY_SERVICE_start (const char *service_name,
1503 const struct GNUNET_CONFIGURATION_Handle *cfg, 1504 const struct GNUNET_CONFIGURATION_Handle *cfg,
1504 enum LEGACY_SERVICE_Options options) 1505 enum LEGACY_SERVICE_Options options)
1505{ 1506{
1506 int i; 1507 int i;
1507 struct LEGACY_SERVICE_Context *sctx; 1508 struct LEGACY_SERVICE_Context *sctx;
1508 1509
1509 sctx = GNUNET_new(struct LEGACY_SERVICE_Context); 1510 sctx = GNUNET_new (struct LEGACY_SERVICE_Context);
1510 sctx->ready_confirm_fd = -1; /* no daemonizing */ 1511 sctx->ready_confirm_fd = -1; /* no daemonizing */
1511 sctx->ret = GNUNET_OK; 1512 sctx->ret = GNUNET_OK;
1512 sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL; 1513 sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
@@ -1515,47 +1516,47 @@ LEGACY_SERVICE_start(const char *service_name,
1515 sctx->options = options; 1516 sctx->options = options;
1516 1517
1517 /* setup subsystems */ 1518 /* setup subsystems */
1518 if (GNUNET_OK != setup_service(sctx)) 1519 if (GNUNET_OK != setup_service (sctx))
1519 { 1520 {
1520 LEGACY_SERVICE_stop(sctx); 1521 LEGACY_SERVICE_stop (sctx);
1521 return NULL; 1522 return NULL;
1522 } 1523 }
1523 if (NULL != sctx->lsocks) 1524 if (NULL != sctx->lsocks)
1524 sctx->server = GNUNET_SERVER_create_with_sockets(&check_access, 1525 sctx->server = GNUNET_SERVER_create_with_sockets (&check_access,
1525 sctx, 1526 sctx,
1526 sctx->lsocks, 1527 sctx->lsocks,
1527 sctx->timeout, 1528 sctx->timeout,
1528 sctx->require_found); 1529 sctx->require_found);
1529 else 1530 else
1530 sctx->server = GNUNET_SERVER_create(&check_access, 1531 sctx->server = GNUNET_SERVER_create (&check_access,
1531 sctx, 1532 sctx,
1532 sctx->addrs, 1533 sctx->addrs,
1533 sctx->addrlens, 1534 sctx->addrlens,
1534 sctx->timeout, 1535 sctx->timeout,
1535 sctx->require_found); 1536 sctx->require_found);
1536 1537
1537 if (NULL == sctx->server) 1538 if (NULL == sctx->server)
1538 { 1539 {
1539 LEGACY_SERVICE_stop(sctx); 1540 LEGACY_SERVICE_stop (sctx);
1540 return NULL; 1541 return NULL;
1541 } 1542 }
1542 1543
1543 if (NULL != sctx->addrs) 1544 if (NULL != sctx->addrs)
1544 for (i = 0; NULL != sctx->addrs[i]; i++) 1545 for (i = 0; NULL != sctx->addrs[i]; i++)
1545 if ((AF_UNIX == sctx->addrs[i]->sa_family) && 1546 if ((AF_UNIX == sctx->addrs[i]->sa_family) &&
1546 ('\0' != ((const struct sockaddr_un *)sctx->addrs[i])->sun_path[0])) 1547 ('\0' != ((const struct sockaddr_un *) sctx->addrs[i])->sun_path[0]))
1547 GNUNET_DISK_fix_permissions(((const struct sockaddr_un *) 1548 GNUNET_DISK_fix_permissions (((const struct sockaddr_un *)
1548 sctx->addrs[i]) 1549 sctx->addrs[i])
1549 ->sun_path, 1550 ->sun_path,
1550 sctx->match_uid, 1551 sctx->match_uid,
1551 sctx->match_gid); 1552 sctx->match_gid);
1552 1553
1553 sctx->my_handlers = GNUNET_malloc(sizeof(defhandlers)); 1554 sctx->my_handlers = GNUNET_malloc (sizeof(defhandlers));
1554 GNUNET_memcpy(sctx->my_handlers, defhandlers, sizeof(defhandlers)); 1555 GNUNET_memcpy (sctx->my_handlers, defhandlers, sizeof(defhandlers));
1555 i = 0; 1556 i = 0;
1556 while ((sctx->my_handlers[i].callback != NULL)) 1557 while ((sctx->my_handlers[i].callback != NULL))
1557 sctx->my_handlers[i++].callback_cls = sctx; 1558 sctx->my_handlers[i++].callback_cls = sctx;
1558 GNUNET_SERVER_add_handlers(sctx->server, sctx->my_handlers); 1559 GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers);
1559 return sctx; 1560 return sctx;
1560} 1561}
1561 1562
@@ -1568,7 +1569,7 @@ LEGACY_SERVICE_start(const char *service_name,
1568 * @return handle to the server for this service, NULL if there is none 1569 * @return handle to the server for this service, NULL if there is none
1569 */ 1570 */
1570struct GNUNET_SERVER_Handle * 1571struct GNUNET_SERVER_Handle *
1571LEGACY_SERVICE_get_server(struct LEGACY_SERVICE_Context *ctx) 1572LEGACY_SERVICE_get_server (struct LEGACY_SERVICE_Context *ctx)
1572{ 1573{
1573 return ctx->server; 1574 return ctx->server;
1574} 1575}
@@ -1582,7 +1583,7 @@ LEGACY_SERVICE_get_server(struct LEGACY_SERVICE_Context *ctx)
1582 * array of listen sockets. 1583 * array of listen sockets.
1583 */ 1584 */
1584struct GNUNET_NETWORK_Handle *const * 1585struct GNUNET_NETWORK_Handle *const *
1585LEGACY_SERVICE_get_listen_sockets(struct LEGACY_SERVICE_Context *ctx) 1586LEGACY_SERVICE_get_listen_sockets (struct LEGACY_SERVICE_Context *ctx)
1586{ 1587{
1587 return ctx->lsocks; 1588 return ctx->lsocks;
1588} 1589}
@@ -1594,7 +1595,7 @@ LEGACY_SERVICE_get_listen_sockets(struct LEGACY_SERVICE_Context *ctx)
1594 * @param sctx the service context returned from the start function 1595 * @param sctx the service context returned from the start function
1595 */ 1596 */
1596void 1597void
1597LEGACY_SERVICE_stop(struct LEGACY_SERVICE_Context *sctx) 1598LEGACY_SERVICE_stop (struct LEGACY_SERVICE_Context *sctx)
1598{ 1599{
1599 unsigned int i; 1600 unsigned int i;
1600 1601
@@ -1602,43 +1603,43 @@ LEGACY_SERVICE_stop(struct LEGACY_SERVICE_Context *sctx)
1602 { 1603 {
1603 char *counter; 1604 char *counter;
1604 1605
1605 if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value(sctx->cfg, 1606 if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (sctx->cfg,
1606 sctx->service_name, 1607 sctx->service_name,
1607 "GAUGER_HEAP")) && 1608 "GAUGER_HEAP")) &&
1608 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(sctx->cfg, 1609 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (sctx->cfg,
1609 sctx->service_name, 1610 sctx->service_name,
1610 "GAUGER_HEAP", 1611 "GAUGER_HEAP",
1611 &counter))) 1612 &counter)))
1612 { 1613 {
1613 struct mallinfo mi; 1614 struct mallinfo mi;
1614 1615
1615 mi = mallinfo(); 1616 mi = mallinfo ();
1616 GAUGER(sctx->service_name, counter, mi.usmblks, "blocks"); 1617 GAUGER (sctx->service_name, counter, mi.usmblks, "blocks");
1617 GNUNET_free(counter); 1618 GNUNET_free (counter);
1618 } 1619 }
1619 } 1620 }
1620#endif 1621#endif
1621 if (NULL != sctx->shutdown_task) 1622 if (NULL != sctx->shutdown_task)
1622 { 1623 {
1623 GNUNET_SCHEDULER_cancel(sctx->shutdown_task); 1624 GNUNET_SCHEDULER_cancel (sctx->shutdown_task);
1624 sctx->shutdown_task = NULL; 1625 sctx->shutdown_task = NULL;
1625 } 1626 }
1626 if (NULL != sctx->server) 1627 if (NULL != sctx->server)
1627 GNUNET_SERVER_destroy(sctx->server); 1628 GNUNET_SERVER_destroy (sctx->server);
1628 GNUNET_free_non_null(sctx->my_handlers); 1629 GNUNET_free_non_null (sctx->my_handlers);
1629 if (NULL != sctx->addrs) 1630 if (NULL != sctx->addrs)
1630 { 1631 {
1631 i = 0; 1632 i = 0;
1632 while (NULL != sctx->addrs[i]) 1633 while (NULL != sctx->addrs[i])
1633 GNUNET_free(sctx->addrs[i++]); 1634 GNUNET_free (sctx->addrs[i++]);
1634 GNUNET_free(sctx->addrs); 1635 GNUNET_free (sctx->addrs);
1635 } 1636 }
1636 GNUNET_free_non_null(sctx->addrlens); 1637 GNUNET_free_non_null (sctx->addrlens);
1637 GNUNET_free_non_null(sctx->v4_denied); 1638 GNUNET_free_non_null (sctx->v4_denied);
1638 GNUNET_free_non_null(sctx->v6_denied); 1639 GNUNET_free_non_null (sctx->v6_denied);
1639 GNUNET_free_non_null(sctx->v4_allowed); 1640 GNUNET_free_non_null (sctx->v4_allowed);
1640 GNUNET_free_non_null(sctx->v6_allowed); 1641 GNUNET_free_non_null (sctx->v6_allowed);
1641 GNUNET_free(sctx); 1642 GNUNET_free (sctx);
1642} 1643}
1643 1644
1644 1645