diff --git a/NEWS b/NEWS index b8fcba42..2a623b1f 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,8 @@ +* Version 0.1.2 (unreleased) + +- Several updates to allow compilation in FreeBSD. + + * Version 0.1.1 (released 2013-04-03) - MTU discovery was simplified. diff --git a/src/Makefile.am b/src/Makefile.am index 138cffbc..9ca8a53b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,7 +18,7 @@ ocserv_SOURCES = main.c main-auth.c worker-vpn.c worker-auth.c tlslib.c \ config.c pam.c pam.h worker-resume.c worker.h main-resume.c main.h \ main-user.c cookies-gdbm.c cookies-hash.c worker-misc.c setproctitle.h \ setproctitle.c worker-privs.c plain.c plain.h common.h common.c \ - sec-mod.c sec-mod.h script-list.h \ + sec-mod.c sec-mod.h script-list.h die.c die.h \ $(CCAN_SOURCES) ocserv_SOURCES += ocserv-args.def ocserv-args.c ocserv-args.h diff --git a/src/cookies-gdbm.c b/src/cookies-gdbm.c index 09f5ee92..8a85c656 100644 --- a/src/cookies-gdbm.c +++ b/src/cookies-gdbm.c @@ -30,7 +30,6 @@ #include #include #include -#include #include #include "setproctitle.h" #include @@ -38,6 +37,8 @@ #ifdef HAVE_GDBM +# include + /* Note that it receives allocated data and stores them. Do not * free the sc. */ diff --git a/src/cookies.c b/src/cookies.c index 4f80f528..c2e2e332 100644 --- a/src/cookies.c +++ b/src/cookies.c @@ -30,7 +30,6 @@ #include #include #include -#include #include #include diff --git a/src/die.c b/src/die.c new file mode 100644 index 00000000..6c84df74 --- /dev/null +++ b/src/die.c @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2013 Nikos Mavrogiannopoulos + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +#include + +#include +#ifdef __linux__ +# include +#endif + +void kill_on_parent_kill(int sig) +{ +#ifdef __linux__ + prctl(PR_SET_PDEATHSIG, sig); +#endif +} diff --git a/src/die.h b/src/die.h new file mode 100644 index 00000000..579a7bd4 --- /dev/null +++ b/src/die.h @@ -0,0 +1,6 @@ +#ifndef DIE_H +# define DIE_H + +void kill_on_parent_kill(int sig); + +#endif diff --git a/src/main-misc.c b/src/main-misc.c index 6cfd5365..90ecf14b 100644 --- a/src/main-misc.c +++ b/src/main-misc.c @@ -35,7 +35,7 @@ #include #include #include -#include +#include "die.h" #include #include "ipc.h" #include "setproctitle.h" @@ -397,7 +397,7 @@ const char *p; pid = fork(); if (pid == 0) { /* child */ clear_lists(s); - prctl(PR_SET_PDEATHSIG, SIGTERM); + kill_on_parent_kill(SIGTERM); setproctitle(PACKAGE_NAME"-secmod"); sec_mod_server(s->config, p); diff --git a/src/main-user.c b/src/main-user.c index d321f06b..b8c4056f 100644 --- a/src/main-user.c +++ b/src/main-user.c @@ -134,10 +134,12 @@ add_utmp_entry(main_server_st *s, struct proc_st* proc) entry.ut_pid = proc->pid; snprintf(entry.ut_line, sizeof(entry.ut_line), "%s", proc->lease->name); snprintf(entry.ut_user, sizeof(entry.ut_user), "%s", proc->username); +#ifdef __linux__ if (proc->remote_addr_len == sizeof(struct sockaddr_in)) memcpy(entry.ut_addr_v6, SA_IN_P(&proc->remote_addr), sizeof(struct in_addr)); else memcpy(entry.ut_addr_v6, SA_IN6_P(&proc->remote_addr), sizeof(struct in6_addr)); +#endif gettime(&tv); entry.ut_tv.tv_sec = tv.tv_sec; diff --git a/src/main.c b/src/main.c index 2f22307b..2326a53e 100644 --- a/src/main.c +++ b/src/main.c @@ -32,13 +32,13 @@ #include #include #include -#include #include #include #include #include #include "ipc.h" +#include "die.h" #include "setproctitle.h" #ifdef HAVE_LIBWRAP # include @@ -122,7 +122,7 @@ int _listen_ports(struct cfg_st* config, struct addrinfo *res, struct listen_lis if (ptr->ai_socktype == SOCK_DGRAM) { #if defined(IP_DONTFRAG) y = 1; - if (setsockopt(s, IPPROTO_IP, IP_DONTFRAG, + if (setsockopt(s, SOL_IP, IP_DONTFRAG, (const void *) &y, sizeof(y)) < 0) perror("setsockopt(IP_DF) failed"); #elif defined(IP_MTU_DISCOVER) @@ -801,7 +801,7 @@ int main(int argc, char** argv) erase_cookies(&s); setproctitle(PACKAGE_NAME"-worker"); - prctl(PR_SET_PDEATHSIG, SIGTERM); + kill_on_parent_kill(SIGTERM); ws.config = &config; ws.cmd_fd = cmd_fd[1]; diff --git a/src/pam.c b/src/pam.c index 60969681..105358ca 100644 --- a/src/pam.c +++ b/src/pam.c @@ -18,6 +18,7 @@ #include #include +#include #include #include diff --git a/src/setproctitle.c b/src/setproctitle.c index 1844aa39..76201441 100644 --- a/src/setproctitle.c +++ b/src/setproctitle.c @@ -19,7 +19,10 @@ #include #include #include -#include +#if !defined(HAVE_SETPROCTITLE) + +# if defined(__linux__) +# include /* This sets the proccess title as shown in top, but not in ps (*@#%@). * To change the ps name in Linux, one needs to do master black magic @@ -27,7 +30,7 @@ */ void setproctitle (const char *fmt, ...) { -#ifdef PR_SET_NAME +# ifdef PR_SET_NAME char name[16]; va_list args; @@ -36,5 +39,15 @@ void setproctitle (const char *fmt, ...) va_end(args); prctl (PR_SET_NAME, name); -#endif +# endif } +# else /* not linux */ + +void setproctitle (const char *fmt, ...) +{ + +} + +# endif /* __linux__ */ + +#endif /* HAVE_SETPROCTITLE */ diff --git a/src/setproctitle.h b/src/setproctitle.h index 182eeff6..08a93e9c 100644 --- a/src/setproctitle.h +++ b/src/setproctitle.h @@ -1,7 +1,18 @@ #ifndef SETPROCTITLE_H # define SETPROCTITLE_H +# include + +# ifndef HAVE_SETPROCTILE + void __attribute__ ((format(printf, 1, 2))) setproctitle(const char *fmt, ...); +# else + +# include +# include + +# endif + #endif diff --git a/src/tun.c b/src/tun.c index d282a397..1cb661b7 100644 --- a/src/tun.c +++ b/src/tun.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -31,6 +30,12 @@ #include #include +#ifdef __linux__ +# include +#else +# include +#endif + #include #include @@ -347,6 +352,7 @@ int open_tun(main_server_st* s, struct lease_st** l) /* No need to free the lease after this point. */ +#ifdef __linux__ tunfd = open("/dev/net/tun", O_RDWR); if (tunfd < 0) { int e = errno; @@ -387,7 +393,7 @@ int open_tun(main_server_st* s, struct lease_st** l) } } -#ifdef TUNSETGROUP +# ifdef TUNSETGROUP if (s->config->gid != -1) { t = s->config->uid; ret = ioctl(tunfd, TUNSETGROUP, t); @@ -398,6 +404,17 @@ int open_tun(main_server_st* s, struct lease_st** l) goto fail; } } +# endif +#else /* freebsd */ + tunfd = open("/dev/tun", O_RDWR); + if (tunfd < 0) { + int e = errno; + mslog(s, NULL, LOG_ERR, "Can't open /dev/tun: %s\n", + strerror(e)); + return -1; + } + + set_cloexec_flag (tunfd, 1); #endif /* set IP/mask */ diff --git a/src/vpn.h b/src/vpn.h index 01267a5f..2cfb4c57 100644 --- a/src/vpn.h +++ b/src/vpn.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #define AC_PKT_DATA 0 /* Uncompressed data */