From: Christian Grothoff Date: Fri, 16 Dec 2011 11:16:26 +0000 (+0000) Subject: some very minor stylistic changes to gnunet-helper-nat-server based on suggestions... X-Git-Tag: initial-import-from-subversion-38251~15624 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=ac109f65ead8ae7aa01a99b100bebfac39d25ffa;p=oweals%2Fgnunet.git some very minor stylistic changes to gnunet-helper-nat-server based on suggestions from Jacob Applebaum --- diff --git a/configure.ac b/configure.ac index 50cc1d6be..464201f92 100644 --- a/configure.ac +++ b/configure.ac @@ -625,7 +625,7 @@ AC_FUNC_VPRINTF AC_HEADER_SYS_WAIT AC_TYPE_OFF_T AC_TYPE_UID_T -AC_CHECK_FUNCS([floor gethostname memmove rmdir strncasecmp strrchr strtol atoll dup2 fdatasync ftruncate gettimeofday memset mkdir mkfifo select socket strcasecmp strchr strdup strerror strstr clock_gettime getrusage rand uname setlocale getcwd mktime gmtime_r gmtime strlcpy strlcat ftruncate stat64 sbrk mmap mremap setrlimit sysconf gethostbyaddr initgroups getifaddrs freeifaddrs getnameinfo getaddrinfo inet_ntoa localtime_r nl_langinfo putenv realpath strndup gethostbyname2 gethostbyname getpeerucred getpeereid]) +AC_CHECK_FUNCS([floor gethostname memmove rmdir strncasecmp strrchr strtol atoll dup2 fdatasync ftruncate gettimeofday memset mkdir mkfifo select socket strcasecmp strchr strdup strerror strstr clock_gettime getrusage rand uname setlocale getcwd mktime gmtime_r gmtime strlcpy strlcat ftruncate stat64 sbrk mmap mremap setrlimit sysconf gethostbyaddr initgroups getifaddrs freeifaddrs getnameinfo getaddrinfo inet_ntoa localtime_r nl_langinfo putenv realpath strndup gethostbyname2 gethostbyname getpeerucred getpeereid setresuid]) # restore LIBS LIBS=$SAVE_LIBS diff --git a/src/nat/gnunet-helper-nat-server.c b/src/nat/gnunet-helper-nat-server.c index 684fa9706..f71c37fa8 100644 --- a/src/nat/gnunet-helper-nat-server.c +++ b/src/nat/gnunet-helper-nat-server.c @@ -472,7 +472,7 @@ make_raw_socket () /** - * Create a UDP socket for writinging. + * Create a UDP socket for writing. * * @param my_ip source address (our ip address) * @return -1 on error @@ -501,7 +501,8 @@ make_udp_socket (const struct in_addr *my_ip) { fprintf (stderr, "Error binding UDP socket to port %u: %s\n", NAT_TRAV_PORT, strerror (errno)); - /* likely problematic, but not certain, try to continue */ + close (ret); + return -1; } return ret; } @@ -539,19 +540,27 @@ main (int argc, char *const *argv) if (-1 == (rawsock = make_raw_socket ())) { close (icmpsock); - return 3; + return 4; } uid = getuid (); +#ifdef HAVE_SETRESUID if (0 != setresuid (uid, uid, uid)) { fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno)); - /* not critical, continue anyway */ + return 5; + } +#else + if (0 != (setuid (uid) | seteuid (uid))) + { + fprintf (stderr, "Failed to setuid: %s\n", strerror (errno)); + return 6; } +#endif if (-1 == (udpsock = make_udp_socket (&external))) { close (icmpsock); close (rawsock); - return 3; + return 7; } alt = 0; while (1) @@ -580,7 +589,7 @@ main (int argc, char *const *argv) close (icmpsock); close (rawsock); close (udpsock); - return 4; + return 8; }