aboutsummaryrefslogtreecommitdiff
path: root/src/exit/gnunet-helper-exit.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/exit/gnunet-helper-exit.c')
-rw-r--r--src/exit/gnunet-helper-exit.c50
1 files changed, 25 insertions, 25 deletions
diff --git a/src/exit/gnunet-helper-exit.c b/src/exit/gnunet-helper-exit.c
index e2a0fd416..e87aac559 100644
--- a/src/exit/gnunet-helper-exit.c
+++ b/src/exit/gnunet-helper-exit.c
@@ -19,7 +19,7 @@
19*/ 19*/
20 20
21/** 21/**
22 * @file exit/gnunet-helper-exit.c 22 * @file exit/gnunet-helper-exit.c
23 * 23 *
24 * @brief the helper for exit nodes. Opens a virtual 24 * @brief the helper for exit nodes. Opens a virtual
25 * network-interface, sends data received on the if to stdout, sends 25 * network-interface, sends data received on the if to stdout, sends
@@ -109,7 +109,7 @@ open_dev_null (int target_fd,
109 if (fd == target_fd) 109 if (fd == target_fd)
110 return; 110 return;
111 if (-1 == dup2 (fd, target_fd)) 111 if (-1 == dup2 (fd, target_fd))
112 { 112 {
113 (void) close (fd); 113 (void) close (fd);
114 abort (); 114 abort ();
115 } 115 }
@@ -119,13 +119,13 @@ open_dev_null (int target_fd,
119 119
120/** 120/**
121 * Run the given command and wait for it to complete. 121 * Run the given command and wait for it to complete.
122 * 122 *
123 * @param file name of the binary to run 123 * @param file name of the binary to run
124 * @param cmd command line arguments (as given to 'execv') 124 * @param cmd command line arguments (as given to 'execv')
125 * @return 0 on success, 1 on any error 125 * @return 0 on success, 1 on any error
126 */ 126 */
127static int 127static int
128fork_and_exec (const char *file, 128fork_and_exec (const char *file,
129 char *const cmd[]) 129 char *const cmd[])
130{ 130{
131 int status; 131 int status;
@@ -135,8 +135,8 @@ fork_and_exec (const char *file,
135 pid = fork (); 135 pid = fork ();
136 if (-1 == pid) 136 if (-1 == pid)
137 { 137 {
138 fprintf (stderr, 138 fprintf (stderr,
139 "fork failed: %s\n", 139 "fork failed: %s\n",
140 strerror (errno)); 140 strerror (errno));
141 return 1; 141 return 1;
142 } 142 }
@@ -145,25 +145,25 @@ fork_and_exec (const char *file,
145 /* we are the child process */ 145 /* we are the child process */
146 /* close stdin/stdout to not cause interference 146 /* close stdin/stdout to not cause interference
147 with the helper's main protocol! */ 147 with the helper's main protocol! */
148 (void) close (0); 148 (void) close (0);
149 open_dev_null (0, O_RDONLY); 149 open_dev_null (0, O_RDONLY);
150 (void) close (1); 150 (void) close (1);
151 open_dev_null (1, O_WRONLY); 151 open_dev_null (1, O_WRONLY);
152 (void) execv (file, cmd); 152 (void) execv (file, cmd);
153 /* can only get here on error */ 153 /* can only get here on error */
154 fprintf (stderr, 154 fprintf (stderr,
155 "exec `%s' failed: %s\n", 155 "exec `%s' failed: %s\n",
156 file, 156 file,
157 strerror (errno)); 157 strerror (errno));
158 _exit (1); 158 _exit (1);
159 } 159 }
160 /* keep running waitpid as long as the only error we get is 'EINTR' */ 160 /* keep running waitpid as long as the only error we get is 'EINTR' */
161 while ( (-1 == (ret = waitpid (pid, &status, 0))) && 161 while ( (-1 == (ret = waitpid (pid, &status, 0))) &&
162 (errno == EINTR) ); 162 (errno == EINTR) );
163 if (-1 == ret) 163 if (-1 == ret)
164 { 164 {
165 fprintf (stderr, 165 fprintf (stderr,
166 "waitpid failed: %s\n", 166 "waitpid failed: %s\n",
167 strerror (errno)); 167 strerror (errno));
168 return 1; 168 return 1;
169 } 169 }
@@ -215,7 +215,7 @@ init_tun (char *dev)
215 215
216 if (-1 == ioctl (fd, TUNSETIFF, (void *) &ifr)) 216 if (-1 == ioctl (fd, TUNSETIFF, (void *) &ifr))
217 { 217 {
218 fprintf (stderr, 218 fprintf (stderr,
219 "Error with ioctl on `%s': %s\n", "/dev/net/tun", 219 "Error with ioctl on `%s': %s\n", "/dev/net/tun",
220 strerror (errno)); 220 strerror (errno));
221 (void) close (fd); 221 (void) close (fd);
@@ -255,7 +255,7 @@ set_address6 (const char *dev, const char *address, unsigned long prefix_len)
255 255
256 if (-1 == (fd = socket (PF_INET6, SOCK_DGRAM, 0))) 256 if (-1 == (fd = socket (PF_INET6, SOCK_DGRAM, 0)))
257 { 257 {
258 fprintf (stderr, "Error creating socket: %s\n", strerror (errno)); 258 fprintf (stderr, "Error creating socket: %s\n", strerror (errno));
259 exit (1); 259 exit (1);
260 } 260 }
261 261
@@ -669,7 +669,7 @@ main (int argc, char **argv)
669 sbin_iptables = "/usr/sbin/iptables"; 669 sbin_iptables = "/usr/sbin/iptables";
670 else 670 else
671 { 671 {
672 fprintf (stderr, 672 fprintf (stderr,
673 "Fatal: executable iptables not found in approved directories: %s\n", 673 "Fatal: executable iptables not found in approved directories: %s\n",
674 strerror (errno)); 674 strerror (errno));
675 return 1; 675 return 1;
@@ -691,7 +691,7 @@ main (int argc, char **argv)
691 691
692 if (-1 == (fd_tun = init_tun (dev))) 692 if (-1 == (fd_tun = init_tun (dev)))
693 { 693 {
694 fprintf (stderr, 694 fprintf (stderr,
695 "Fatal: could not initialize tun-interface `%s' with IPv6 %s/%s and IPv4 %s/%s\n", 695 "Fatal: could not initialize tun-interface `%s' with IPv6 %s/%s and IPv4 %s/%s\n",
696 dev, 696 dev,
697 argv[3], 697 argv[3],
@@ -706,13 +706,13 @@ main (int argc, char **argv)
706 { 706 {
707 const char *address = argv[3]; 707 const char *address = argv[3];
708 long prefix_len = atol (argv[4]); 708 long prefix_len = atol (argv[4]);
709 709
710 if ((prefix_len < 1) || (prefix_len > 127)) 710 if ((prefix_len < 1) || (prefix_len > 127))
711 { 711 {
712 fprintf (stderr, "Fatal: prefix_len out of range\n"); 712 fprintf (stderr, "Fatal: prefix_len out of range\n");
713 return 1; 713 return 1;
714 } 714 }
715 set_address6 (dev, address, prefix_len); 715 set_address6 (dev, address, prefix_len);
716 } 716 }
717 { 717 {
718 char *const sysctl_args[] = 718 char *const sysctl_args[] =
@@ -724,7 +724,7 @@ main (int argc, char **argv)
724 { 724 {
725 fprintf (stderr, 725 fprintf (stderr,
726 "Failed to enable IPv6 forwarding. Will continue anyway.\n"); 726 "Failed to enable IPv6 forwarding. Will continue anyway.\n");
727 } 727 }
728 } 728 }
729 } 729 }
730 730
@@ -733,7 +733,7 @@ main (int argc, char **argv)
733 { 733 {
734 const char *address = argv[5]; 734 const char *address = argv[5];
735 const char *mask = argv[6]; 735 const char *mask = argv[6];
736 736
737 set_address4 (dev, address, mask); 737 set_address4 (dev, address, mask);
738 } 738 }
739 { 739 {
@@ -746,7 +746,7 @@ main (int argc, char **argv)
746 { 746 {
747 fprintf (stderr, 747 fprintf (stderr,
748 "Failed to enable IPv4 forwarding. Will continue anyway.\n"); 748 "Failed to enable IPv4 forwarding. Will continue anyway.\n");
749 } 749 }
750 } 750 }
751 if (0 != strcmp (argv[2], "-")) 751 if (0 != strcmp (argv[2], "-"))
752 { 752 {
@@ -759,10 +759,10 @@ main (int argc, char **argv)
759 { 759 {
760 fprintf (stderr, 760 fprintf (stderr,
761 "Failed to enable IPv4 masquerading (NAT). Will continue anyway.\n"); 761 "Failed to enable IPv4 masquerading (NAT). Will continue anyway.\n");
762 } 762 }
763 } 763 }
764 } 764 }
765 765
766 uid_t uid = getuid (); 766 uid_t uid = getuid ();
767#ifdef HAVE_SETRESUID 767#ifdef HAVE_SETRESUID
768 if (0 != setresuid (uid, uid, uid)) 768 if (0 != setresuid (uid, uid, uid))