summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile1
-rw-r--r--src/linux/tun.c16
-rw-r--r--src/sysexec.c83
-rw-r--r--src/sysexec.h39
4 files changed, 92 insertions, 47 deletions
diff --git a/src/Makefile b/src/Makefile
index 358c612..e4b6a92 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -43,6 +43,7 @@ CRYPT_OBJ := key_derivation.o \
OBJ := log.o \
string_list.o \
sig_handler.o \
+ sysexec.o \
options.o \
tun.o \
udp.o \
diff --git a/src/linux/tun.c b/src/linux/tun.c
index c2187a6..e46e5ee 100644
--- a/src/linux/tun.c
+++ b/src/linux/tun.c
@@ -54,6 +54,7 @@
#define DEFAULT_DEVICE "/dev/net/tun"
#include "log.h"
+#include "sysexec.h"
int tun_init(tun_device_t* dev, const char* dev_name, const char* dev_type, const char* ifcfg_addr, u_int16_t ifcfg_prefix){
if(!dev)
@@ -189,18 +190,15 @@ void tun_do_ifconfig(tun_device_t* dev)
if(!dev || !dev->actual_name_ || !dev->net_addr_ || !dev->net_mask_)
return;
- char* command = NULL;
- asprintf(&command, "/sbin/ifconfig %s %s netmask %s mtu %d", dev->actual_name_, dev->net_addr_, dev->net_mask_, dev->mtu_);
- if(!command) {
+ char* mtu_str = NULL;
+ asprintf(&mtu_str, "%d", dev->mtu_);
+ if(!mtu_str) {
log_printf(ERROR, "Execution of ifconfig failed");
return;
}
- int result = system(command);
- if(result == -1)
- log_printf(ERROR, "Execution of ifconfig failed");
- else
- log_printf(NOTICE, "ifconfig returned %d", WEXITSTATUS(result));
+ char* const argv[] = { dev->actual_name_, dev->net_addr_, "netmask", dev->net_mask_, "mtu", mtu_str, NULL };
+ uanytun_exec("/sbin/ifconfig", argv, NULL);
- free(command);
+ free(mtu_str);
}
diff --git a/src/sysexec.c b/src/sysexec.c
new file mode 100644
index 0000000..2ef1d50
--- /dev/null
+++ b/src/sysexec.c
@@ -0,0 +1,83 @@
+/*
+ * uAnytun
+ *
+ * uAnytun is a tiny implementation of SATP. Unlike Anytun which is a full
+ * featured implementation uAnytun has no support for multiple connections
+ * or synchronisation. It is a small single threaded implementation intended
+ * to act as a client on small platforms.
+ * The secure anycast tunneling protocol (satp) defines a protocol used
+ * for communication between any combination of unicast and anycast
+ * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel
+ * mode and allows tunneling of every ETHER TYPE protocol (e.g.
+ * ethernet, ip, arp ...). satp directly includes cryptography and
+ * message authentication based on the methodes used by SRTP. It is
+ * intended to deliver a generic, scaleable and secure solution for
+ * tunneling and relaying of packets of any protocol.
+ *
+ *
+ * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ *
+ * This file is part of uAnytun.
+ *
+ * uAnytun is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * uAnytun is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with uAnytun. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "datatypes.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/wait.h>
+
+#include "sysexec.h"
+#include "log.h"
+
+int uanytun_exec(const char* script, char* const argv[], char* const evp[])
+{
+ if(!script)
+ return -1;
+
+ pid_t pid;
+ pid = fork();
+ if(!pid) {
+ int fd;
+ for (fd=getdtablesize();fd>=0;--fd) // close all file descriptors
+ close(fd);
+
+ fd = open("/dev/null",O_RDWR); // stdin
+ if(fd == -1)
+ log_printf(WARNING, "can't open stdin");
+ else {
+ if(dup(fd) == -1) // stdout
+ log_printf(WARNING, "can't open stdout");
+ if(dup(fd) == -1) // stderr
+ log_printf(WARNING, "can't open stderr");
+ }
+ execve(script, argv, evp);
+ // if execl return, an error occurred
+ log_printf(ERROR, "error on executing script: %s", strerror(errno));
+ return -1;
+ }
+ int status = 0;
+ waitpid(pid, &status, 0);
+ if(WIFEXITED(status))
+ log_printf(NOTICE, "script '%s' returned %d", script, WEXITSTATUS(status));
+ else if(WIFSIGNALED(status))
+ log_printf(NOTICE, "script '%s' terminated after signal %d", script, WTERMSIG(status));
+ else
+ log_printf(ERROR, "executing script '%s': unkown error");
+
+ return status;
+
+}
diff --git a/src/sysexec.h b/src/sysexec.h
index 23a84d0..5872454 100644
--- a/src/sysexec.h
+++ b/src/sysexec.h
@@ -35,43 +35,6 @@
#ifndef _SYSEXEC_H_
#define _SYSEXEC_H_
-int uanytun_exec(const char* script, char* const argv[], char* const evp[])
-{
- if(!script)
- return -1;
-
- pid_t pid;
- pid = fork();
- if(!pid) {
- int fd;
- for (fd=getdtablesize();fd>=0;--fd) // close all file descriptors
- close(fd);
-
- fd = open("/dev/null",O_RDWR); // stdin
- if(fd == -1)
- log_printf(WARNING, "can't open stdin");
- else {
- if(dup(fd) == -1) // stdout
- log_printf(WARNING, "can't open stdout");
- if(dup(fd) == -1) // stderr
- log_printf(WARNING, "can't open stderr");
- }
- execve(script, argv, evp);
- // if execl return, an error occurred
- log_printf(ERROR, "error on executing script: %s", strerror(errno));
- return -1;
- }
- int status = 0;
- waitpid(pid, &status, 0);
- if(WIFEXITED(status))
- log_printf(NOTICE, "script '%s' returned %d", script, WEXITSTATUS(status));
- else if(WIFSIGNALED(status))
- log_printf(NOTICE, "script '%s' terminated after signal %d", script, WTERMSIG(status));
- else
- log_printf(ERROR, "executing script: unkown error");
-
- return status;
-
-}
+int uanytun_exec(const char* script, char* const argv[], char* const evp[]);
#endif