mirror of
https://gitlab.com/openconnect/ocserv.git
synced 2026-02-10 00:37:00 +08:00
several updates to allow compilation on FreeBSD
This commit is contained in:
5
NEWS
5
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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include <gdbm.h>
|
||||
#include <sys/stat.h>
|
||||
#include "setproctitle.h"
|
||||
#include <main.h>
|
||||
@@ -38,6 +37,8 @@
|
||||
|
||||
#ifdef HAVE_GDBM
|
||||
|
||||
# include <gdbm.h>
|
||||
|
||||
/* Note that it receives allocated data and stores them. Do not
|
||||
* free the sc.
|
||||
*/
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include <gdbm.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <main.h>
|
||||
|
||||
30
src/die.c
Normal file
30
src/die.c
Normal file
@@ -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 <config.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#ifdef __linux__
|
||||
# include <sys/prctl.h>
|
||||
#endif
|
||||
|
||||
void kill_on_parent_kill(int sig)
|
||||
{
|
||||
#ifdef __linux__
|
||||
prctl(PR_SET_PDEATHSIG, sig);
|
||||
#endif
|
||||
}
|
||||
6
src/die.h
Normal file
6
src/die.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef DIE_H
|
||||
# define DIE_H
|
||||
|
||||
void kill_on_parent_kill(int sig);
|
||||
|
||||
#endif
|
||||
@@ -35,7 +35,7 @@
|
||||
#include <gnutls/crypto.h>
|
||||
#include <tlslib.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/prctl.h>
|
||||
#include "die.h"
|
||||
#include <cloexec.h>
|
||||
#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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -32,13 +32,13 @@
|
||||
#include <errno.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/prctl.h>
|
||||
#include <cloexec.h>
|
||||
#include <script-list.h>
|
||||
|
||||
#include <gnutls/x509.h>
|
||||
#include <tlslib.h>
|
||||
#include "ipc.h"
|
||||
#include "die.h"
|
||||
#include "setproctitle.h"
|
||||
#ifdef HAVE_LIBWRAP
|
||||
# include <tcpd.h>
|
||||
@@ -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];
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <config.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
|
||||
|
||||
@@ -19,7 +19,10 @@
|
||||
#include <config.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/prctl.h>
|
||||
#if !defined(HAVE_SETPROCTITLE)
|
||||
|
||||
# if defined(__linux__)
|
||||
# include <sys/prctl.h>
|
||||
|
||||
/* 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 */
|
||||
|
||||
@@ -1,7 +1,18 @@
|
||||
#ifndef SETPROCTITLE_H
|
||||
# define SETPROCTITLE_H
|
||||
|
||||
# include <config.h>
|
||||
|
||||
# ifndef HAVE_SETPROCTILE
|
||||
|
||||
void __attribute__ ((format(printf, 1, 2)))
|
||||
setproctitle(const char *fmt, ...);
|
||||
|
||||
# else
|
||||
|
||||
# include <sys/types.h>
|
||||
# include <unistd.h>
|
||||
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
21
src/tun.c
21
src/tun.c
@@ -22,7 +22,6 @@
|
||||
#include <sys/types.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/socket.h>
|
||||
#include <linux/if_tun.h>
|
||||
#include <net/if.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <stdio.h>
|
||||
@@ -31,6 +30,12 @@
|
||||
#include <errno.h>
|
||||
#include <cloexec.h>
|
||||
|
||||
#ifdef __linux__
|
||||
# include <linux/if_tun.h>
|
||||
#else
|
||||
# include <net/if_tun.h>
|
||||
#endif
|
||||
|
||||
#include <netdb.h>
|
||||
|
||||
#include <vpn.h>
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user