some very minor stylistic changes to gnunet-helper-nat-server based on suggestions...
authorChristian Grothoff <christian@grothoff.org>
Fri, 16 Dec 2011 11:16:26 +0000 (11:16 +0000)
committerChristian Grothoff <christian@grothoff.org>
Fri, 16 Dec 2011 11:16:26 +0000 (11:16 +0000)
configure.ac
src/nat/gnunet-helper-nat-server.c

index 50cc1d6be9b0da4690008e2098476482255e16dc..464201f92a976dcdd056edd172af19de12319ddd 100644 (file)
@@ -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
index 684fa970664722c6fef550f717f4d4efa124ab89..f71c37fa8723f4686b2a84697aafd117c4f89acf 100644 (file)
@@ -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;
 }