Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/openfortivpn.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ openfortivpn \- Client for PPP+TLS VPN tunnel services
[\fB\-\-cipher\-list=\fI<ciphers>\fR]
[\fB\-\-min\-tls=\fI<version>\fR]
[\fB\-\-seclevel\-1\fR]
[\fB\-\-ifup\-hook=\fI<command>\fR]
[\fB\-\-pppd\-use\-peerdns=\fI<bool>\fR]
[\fB\-\-pppd\-no\-peerdns\fR]
[\fB\-\-pppd\-log=\fI<file>\fR]
Expand Down Expand Up @@ -207,6 +208,10 @@ ciphers. This lowers limits on dh key.

\fBApplies to TLS v1.2 or lower only.\fR
.TP
\fB\-\-ifup\-hook=\fI<command>\fR
Execute the supplied command once the tunnel has been established and
routes and DNS have been configured (if applicable).
.TP
\fB\-\-pppd\-use\-peerdns=\fI<bool>\fR, \fB\-\-pppd\-no\-peerdns\fR
Whether to ask peer ppp server for DNS server addresses and let pppd
rewrite /etc/resolv.conf. There is no mechanism to tell the dns\-suffix
Expand Down Expand Up @@ -400,6 +405,10 @@ cipher\-list = HIGH:!aNULL:!kRSA:!PSK:!SRP:!MD5:!RC4
persistent = 0
.br
seclevel-1 = 0
.br
# Invoke command once the tunnel has been established.
.br
# ifup-hook = command

.SH SEE ALSO

Expand Down
8 changes: 8 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const struct vpn_config invalid_cfg = {
.cipher_list = NULL,
.min_tls = -1,
.seclevel_1 = -1,
.ifup_hook = NULL,
.cert_whitelist = NULL,
.use_engine = -1,
.user_agent = NULL,
Expand Down Expand Up @@ -476,6 +477,9 @@ int load_config(struct vpn_config *cfg, const char *filename)
} else if (strcmp(key, "check-virtual-desktop") == 0) {
free(cfg->check_virtual_desktop);
cfg->check_virtual_desktop = strdup(val);
} else if (strcmp(key, "ifup-hook") == 0) {
free(cfg->ifup_hook);
cfg->ifup_hook = strdup(val);
} else {
log_warn("Bad key in configuration file: \"%s\".\n", key);
goto err_free;
Expand Down Expand Up @@ -630,6 +634,10 @@ void merge_config(struct vpn_config *dst, struct vpn_config *src)
dst->min_tls = src->min_tls;
if (src->seclevel_1 != invalid_cfg.seclevel_1)
dst->seclevel_1 = src->seclevel_1;
if (src->ifup_hook) {
free(dst->ifup_hook);
dst->ifup_hook = src->ifup_hook;
}
if (src->cert_whitelist) {
while (dst->cert_whitelist != NULL) {
struct x509_digest *tmp = dst->cert_whitelist->next;
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ struct vpn_config {
char *user_agent;
char *hostcheck;
char *check_virtual_desktop;
char *ifup_hook;
};

int add_trusted_cert(struct vpn_config *cfg, const char *digest);
Expand Down
10 changes: 10 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ PPPD_USAGE \
" --seclevel-1 If --cipher-list is not specified, add @SECLEVEL=1 to\n" \
" (compiled in) list of ciphers. This lowers limits on\n" \
" dh key." help_seclevel_1 "\n" \
" --ifup-hook=<command> Execute the supplied command once the tunnel has been\n" \
" established and routes and DNS have been configured (if\n" \
" applicable).\n" \
" --persistent=<interval> Run the vpn persistently in a loop and try to re-\n" \
" connect every <interval> seconds when dropping out.\n" \
" -v Increase verbosity. Can be used multiple times\n" \
Expand Down Expand Up @@ -313,6 +316,7 @@ int main(int argc, char *argv[])
{"cipher-list", required_argument, NULL, 0},
{"min-tls", required_argument, NULL, 0},
{"seclevel-1", no_argument, &cli_cfg.seclevel_1, 1},
{"ifup-hook", required_argument, NULL, 0},
#if HAVE_USR_SBIN_PPPD
{"pppd-use-peerdns", required_argument, NULL, 0},
{"pppd-no-peerdns", no_argument, &cli_cfg.pppd_use_peerdns, 0},
Expand Down Expand Up @@ -513,6 +517,12 @@ int main(int argc, char *argv[])
}
break;
}
if (strcmp(long_options[option_index].name,
"ifup-hook") == 0) {
free(cli_cfg.ifup_hook);
cli_cfg.ifup_hook = strdup(optarg);
break;
}
if (strcmp(long_options[option_index].name,
"otp-prompt") == 0) {
free(cli_cfg.otp_prompt);
Expand Down
10 changes: 10 additions & 0 deletions src/tunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include <signal.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>


struct ofv_varr {
Expand Down Expand Up @@ -125,6 +126,15 @@ static int on_ppp_if_up(struct tunnel *tunnel)
ipv4_add_nameservers_to_resolv_conf(tunnel);
}

if (tunnel->config->ifup_hook) {
log_info("Executing ifup hook...\n");

int code = system(tunnel->config->ifup_hook);

if (code != 0)
log_warn("ifup hook failed with exit code %i\n", code);
}

log_info("Tunnel is up and running.\n");

#if HAVE_SYSTEMD
Expand Down