Skip to content

Commit

Permalink
supply the SVPNCOOKIE via environment
Browse files Browse the repository at this point in the history
if the SVPNCOOKIE is set in the enviroment authentication is skipped and
the cookie is taken from the environment instead. (addresses adrienverge#46)
  • Loading branch information
mrbaseman committed Apr 20, 2018
1 parent 68d24bd commit 1d51578
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
8 changes: 8 additions & 0 deletions doc/openfortivpn.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ VPN_ROUTE_MASK_... the network mask for this route
.br
VPN_ROUTE_GATEWAY_... the gateway for the current route entry

If an environment variable
.B SVPNCOOKIE
is present
.B openfortivpn
will skip the authentication step and use that value as cookie. It assumes
that some other mechanism (a surrounding GUI or scripting framework) has
already performed the login and recieved this cookie from the remote side.

.SH CONFIG FILE
Options can be taken from a configuration file. Options passed in the command
line will override those from the config file, though. The default config file
Expand Down
20 changes: 13 additions & 7 deletions src/tunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ int run_tunnel(struct vpn_config *config)
.on_ppp_if_up = on_ppp_if_up,
.on_ppp_if_down = on_ppp_if_down
};
char *cookie;

// Step 0: get gateway host IP
ret = get_gateway_host_ip(&tunnel);
Expand All @@ -785,14 +786,19 @@ int run_tunnel(struct vpn_config *config)

// Step 2: connect to the HTTP interface and authenticate to get a
// cookie
ret = auth_log_in(&tunnel);
if (ret != 1) {
log_error("Could not authenticate to gateway (%s).\n",
err_http_str(ret));
ret = 1;
goto err_tunnel;
cookie = getenv("SVPNCOOKIE");
if (cookie != NULL){
strncpy(config->cookie, cookie, strlen(cookie)+1);
} else {
ret = auth_log_in(&tunnel);
if (ret != 1) {
log_error("Could not authenticate to gateway (%s).\n",
err_http_str(ret));
ret = 1;
goto err_tunnel;
}
log_info("Authenticated.\n");
}
log_info("Authenticated.\n");
log_debug("Cookie: %s\n", config->cookie);

ret = auth_request_vpn_allocation(&tunnel);
Expand Down

0 comments on commit 1d51578

Please sign in to comment.