X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fnet.c;h=e7297d19a0f9cf1a0f6381d91d212bed0459b40b;hp=0a23212be98646e056f85da32e81af5887091869;hb=e118ba0a648000c48d6a401c9b9249a844d6dbcf;hpb=5055e1dedc9fe984c497448c1b2ffc4afdf18aa3 diff --git a/src/net.c b/src/net.c index 0a23212b..e7297d19 100644 --- a/src/net.c +++ b/src/net.c @@ -17,17 +17,13 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: net.c,v 1.35.4.70 2000/11/08 17:56:34 guus Exp $ + $Id: net.c,v 1.35.4.73 2000/11/15 13:33:26 guus Exp $ */ #include "config.h" -#include #include #include -/* SunOS really wants sys/socket.h BEFORE net/if.h */ -#include -#include #include #include #include @@ -39,9 +35,29 @@ #include #include #include -#include -#include -#include +/* SunOS really wants sys/socket.h BEFORE net/if.h, + and FreeBSD wants these lines below the rest. */ +#include +#include +#include + +#ifdef HAVE_OPENSSL_RAND_H +# include +#else +# include +#endif + +#ifdef HAVE_OPENSSL_EVP_H +# include +#else +# include +#endif + +#ifdef HAVE_OPENSSL_ERR_H +# include +#else +# include +#endif #ifdef HAVE_TUNTAP #include LINUX_IF_TUN_H @@ -86,6 +102,7 @@ int execute_script(const char *name) char *scriptname; pid_t pid; char *s; + int error; if((pid = fork()) < 0) { @@ -101,6 +118,8 @@ int execute_script(const char *name) /* Child here */ + error = 0; + if(netname) { asprintf(&s, "NETNAME=%s", netname); @@ -113,18 +132,55 @@ int execute_script(const char *name) } #endif - chdir(confbase); /* This cannot fail since we already read config files from this directory. */ + if(chdir(confbase) < 0) + /* This cannot fail since we already read config files from this + directory. - Guus */ + /* Yes this can fail, somebody could have removed this directory + when we didn't pay attention. - Ivo */ + { + if(chdir("/") < 0) + /* Now if THIS fails, something wicked is going on. - Ivo */ + syslog(LOG_ERR, _("Couldn't chdir to `/': %m")); + + /* Continue anyway. */ + } asprintf(&scriptname, "%s/%s", confbase, name); - execl(scriptname, NULL); + /* Close all file descriptors */ + closelog(); + fcloseall(); + + /* Open standard input */ + if(open("/dev/null", O_RDONLY) < 0) + { + syslog(LOG_ERR, _("Opening `/dev/null' failed: %m")); + error = 1; + } + + if(!error) + { + /* Standard output directly goes to syslog */ + openlog(name, LOG_CONS | LOG_PID, LOG_DAEMON); + /* Standard error as well */ + if(dup2(1, 2) < 0) + { + syslog(LOG_ERR, _("System call `%s' failed: %m"), + "dup2"); + error = 1; + } + } + + if(error && debug_lvl > 1) + syslog(LOG_INFO, _("This means that any output the script generates will not be shown in syslog.")); + + execl(scriptname, NULL); /* No return on success */ if(errno != ENOENT) /* Ignore if the file does not exist */ syslog(LOG_WARNING, _("Error executing `%s': %m"), scriptname); /* No need to free things */ - exit(0); } @@ -1042,7 +1098,7 @@ conn_list_t *create_new_connection(int sfd) cp p = new_conn_list(); - if(getpeername(sfd, &ci, &len) < 0) + if(getpeername(sfd, (struct sockaddr *) &ci, (socklen_t *) &len) < 0) { syslog(LOG_ERR, _("System call `%s' failed: %m"), "getpeername");