Fix warnings from cppcheck.
This commit is contained in:
parent
5d0812d492
commit
d93a37928b
6 changed files with 103 additions and 88 deletions
|
@ -411,8 +411,7 @@ bool append_config_file(const char *name, const char *key, const char *value) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
free(fname);
|
free(fname);
|
||||||
|
|
||||||
return fp;
|
return fp != NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ static struct addrinfo *ai = NULL;
|
||||||
static mac_t ignore_src = {{0}};
|
static mac_t ignore_src = {{0}};
|
||||||
|
|
||||||
static bool setup_device(void) {
|
static bool setup_device(void) {
|
||||||
char *host;
|
char *host = NULL;
|
||||||
char *port;
|
char *port;
|
||||||
char *space;
|
char *space;
|
||||||
int ttl = 1;
|
int ttl = 1;
|
||||||
|
@ -49,14 +49,14 @@ static bool setup_device(void) {
|
||||||
|
|
||||||
if(!get_config_string(lookup_config(config_tree, "Device"), &device)) {
|
if(!get_config_string(lookup_config(config_tree, "Device"), &device)) {
|
||||||
logger(DEBUG_ALWAYS, LOG_ERR, "Device variable required for %s", device_info);
|
logger(DEBUG_ALWAYS, LOG_ERR, "Device variable required for %s", device_info);
|
||||||
return false;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
host = xstrdup(device);
|
host = xstrdup(device);
|
||||||
space = strchr(host, ' ');
|
space = strchr(host, ' ');
|
||||||
if(!space) {
|
if(!space) {
|
||||||
logger(DEBUG_ALWAYS, LOG_ERR, "Port number required for %s", device_info);
|
logger(DEBUG_ALWAYS, LOG_ERR, "Port number required for %s", device_info);
|
||||||
return false;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
*space++ = 0;
|
*space++ = 0;
|
||||||
|
@ -70,12 +70,12 @@ static bool setup_device(void) {
|
||||||
|
|
||||||
ai = str2addrinfo(host, port, SOCK_DGRAM);
|
ai = str2addrinfo(host, port, SOCK_DGRAM);
|
||||||
if(!ai)
|
if(!ai)
|
||||||
return false;
|
goto error;
|
||||||
|
|
||||||
device_fd = socket(ai->ai_family, SOCK_DGRAM, IPPROTO_UDP);
|
device_fd = socket(ai->ai_family, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
if(device_fd < 0) {
|
if(device_fd < 0) {
|
||||||
logger(DEBUG_ALWAYS, LOG_ERR, "Creating socket failed: %s", sockstrerror(sockerrno));
|
logger(DEBUG_ALWAYS, LOG_ERR, "Creating socket failed: %s", sockstrerror(sockerrno));
|
||||||
return false;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FD_CLOEXEC
|
#ifdef FD_CLOEXEC
|
||||||
|
@ -86,9 +86,8 @@ static bool setup_device(void) {
|
||||||
setsockopt(device_fd, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof one);
|
setsockopt(device_fd, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof one);
|
||||||
|
|
||||||
if(bind(device_fd, ai->ai_addr, ai->ai_addrlen)) {
|
if(bind(device_fd, ai->ai_addr, ai->ai_addrlen)) {
|
||||||
closesocket(device_fd);
|
|
||||||
logger(DEBUG_ALWAYS, LOG_ERR, "Can't bind to %s %s: %s", host, port, sockstrerror(sockerrno));
|
logger(DEBUG_ALWAYS, LOG_ERR, "Can't bind to %s %s: %s", host, port, sockstrerror(sockerrno));
|
||||||
return false;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(ai->ai_family) {
|
switch(ai->ai_family) {
|
||||||
|
@ -101,8 +100,7 @@ static bool setup_device(void) {
|
||||||
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
|
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
|
||||||
if(setsockopt(device_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&mreq, sizeof mreq)) {
|
if(setsockopt(device_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&mreq, sizeof mreq)) {
|
||||||
logger(DEBUG_ALWAYS, LOG_ERR, "Cannot join multicast group %s %s: %s", host, port, sockstrerror(sockerrno));
|
logger(DEBUG_ALWAYS, LOG_ERR, "Cannot join multicast group %s %s: %s", host, port, sockstrerror(sockerrno));
|
||||||
closesocket(device_fd);
|
goto error;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
#ifdef IP_MULTICAST_LOOP
|
#ifdef IP_MULTICAST_LOOP
|
||||||
setsockopt(device_fd, IPPROTO_IP, IP_MULTICAST_LOOP, (const void *)&one, sizeof one);
|
setsockopt(device_fd, IPPROTO_IP, IP_MULTICAST_LOOP, (const void *)&one, sizeof one);
|
||||||
|
@ -122,8 +120,7 @@ static bool setup_device(void) {
|
||||||
mreq.ipv6mr_interface = in6.sin6_scope_id;
|
mreq.ipv6mr_interface = in6.sin6_scope_id;
|
||||||
if(setsockopt(device_fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, (void *)&mreq, sizeof mreq)) {
|
if(setsockopt(device_fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, (void *)&mreq, sizeof mreq)) {
|
||||||
logger(DEBUG_ALWAYS, LOG_ERR, "Cannot join multicast group %s %s: %s", host, port, sockstrerror(sockerrno));
|
logger(DEBUG_ALWAYS, LOG_ERR, "Cannot join multicast group %s %s: %s", host, port, sockstrerror(sockerrno));
|
||||||
closesocket(device_fd);
|
goto error;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
#ifdef IPV6_MULTICAST_LOOP
|
#ifdef IPV6_MULTICAST_LOOP
|
||||||
setsockopt(device_fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, (const void *)&one, sizeof one);
|
setsockopt(device_fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, (const void *)&one, sizeof one);
|
||||||
|
@ -136,13 +133,23 @@ static bool setup_device(void) {
|
||||||
|
|
||||||
default:
|
default:
|
||||||
logger(DEBUG_ALWAYS, LOG_ERR, "Multicast for address family %hx unsupported", ai->ai_family);
|
logger(DEBUG_ALWAYS, LOG_ERR, "Multicast for address family %hx unsupported", ai->ai_family);
|
||||||
closesocket(device_fd);
|
goto error;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
freeaddrinfo(ai);
|
||||||
|
|
||||||
logger(DEBUG_ALWAYS, LOG_INFO, "%s is a %s", device, device_info);
|
logger(DEBUG_ALWAYS, LOG_INFO, "%s is a %s", device, device_info);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
error:
|
||||||
|
if(device_fd >= 0)
|
||||||
|
closesocket(device_fd);
|
||||||
|
if(ai)
|
||||||
|
freeaddrinfo(ai);
|
||||||
|
free(host);
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void close_device(void) {
|
static void close_device(void) {
|
||||||
|
|
|
@ -148,6 +148,9 @@ typedef enum proxytype_t {
|
||||||
} proxytype_t;
|
} proxytype_t;
|
||||||
extern proxytype_t proxytype;
|
extern proxytype_t proxytype;
|
||||||
|
|
||||||
|
extern char *scriptinterpreter;
|
||||||
|
extern char *scriptextension;
|
||||||
|
|
||||||
/* Yes, very strange placement indeed, but otherwise the typedefs get all tangled up */
|
/* Yes, very strange placement indeed, but otherwise the typedefs get all tangled up */
|
||||||
#include "connection.h"
|
#include "connection.h"
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
|
|
|
@ -52,20 +52,23 @@ char *proxyuser;
|
||||||
char *proxypass;
|
char *proxypass;
|
||||||
proxytype_t proxytype;
|
proxytype_t proxytype;
|
||||||
|
|
||||||
|
char *scriptinterpreter;
|
||||||
|
char *scriptextension;
|
||||||
|
|
||||||
bool node_read_ecdsa_public_key(node_t *n) {
|
bool node_read_ecdsa_public_key(node_t *n) {
|
||||||
if(ecdsa_active(&n->ecdsa))
|
if(ecdsa_active(&n->ecdsa))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
splay_tree_t *config_tree;
|
splay_tree_t *config_tree;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char *fname;
|
char *pubname = NULL, *hcfname = NULL;
|
||||||
char *p;
|
char *p;
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, n->name);
|
xasprintf(&hcfname, "%s" SLASH "hosts" SLASH "%s", confbase, n->name);
|
||||||
|
|
||||||
init_configuration(&config_tree);
|
init_configuration(&config_tree);
|
||||||
if(!read_config_file(config_tree, fname))
|
if(!read_config_file(config_tree, hcfname))
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
/* First, check for simple ECDSAPublicKey statement */
|
/* First, check for simple ECDSAPublicKey statement */
|
||||||
|
@ -78,15 +81,13 @@ bool node_read_ecdsa_public_key(node_t *n) {
|
||||||
|
|
||||||
/* Else, check for ECDSAPublicKeyFile statement and read it */
|
/* Else, check for ECDSAPublicKeyFile statement and read it */
|
||||||
|
|
||||||
free(fname);
|
if(!get_config_string(lookup_config(config_tree, "ECDSAPublicKeyFile"), &pubname))
|
||||||
|
xasprintf(&pubname, "%s" SLASH "hosts" SLASH "%s", confbase, n->name);
|
||||||
|
|
||||||
if(!get_config_string(lookup_config(config_tree, "ECDSAPublicKeyFile"), &fname))
|
fp = fopen(pubname, "r");
|
||||||
xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, n->name);
|
|
||||||
|
|
||||||
fp = fopen(fname, "r");
|
|
||||||
|
|
||||||
if(!fp) {
|
if(!fp) {
|
||||||
logger(DEBUG_ALWAYS, LOG_ERR, "Error reading ECDSA public key file `%s': %s", fname, strerror(errno));
|
logger(DEBUG_ALWAYS, LOG_ERR, "Error reading ECDSA public key file `%s': %s", pubname, strerror(errno));
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +96,8 @@ bool node_read_ecdsa_public_key(node_t *n) {
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
exit_configuration(&config_tree);
|
exit_configuration(&config_tree);
|
||||||
free(fname);
|
free(hcfname);
|
||||||
|
free(pubname);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,11 +388,26 @@ char *get_name(void) {
|
||||||
|
|
||||||
bool setup_myself_reloadable(void) {
|
bool setup_myself_reloadable(void) {
|
||||||
char *proxy = NULL;
|
char *proxy = NULL;
|
||||||
char *mode = NULL;
|
char *rmode = NULL;
|
||||||
|
char *fmode = NULL;
|
||||||
|
char *bmode = NULL;
|
||||||
char *afname = NULL;
|
char *afname = NULL;
|
||||||
char *space;
|
char *space;
|
||||||
bool choice;
|
bool choice;
|
||||||
|
|
||||||
|
free(scriptinterpreter);
|
||||||
|
scriptinterpreter = NULL;
|
||||||
|
get_config_string(lookup_config(config_tree, "ScriptsInterpreter"), &scriptinterpreter);
|
||||||
|
|
||||||
|
|
||||||
|
free(scriptextension);
|
||||||
|
if(!get_config_string(lookup_config(config_tree, "ScriptsExtension"), &scriptextension))
|
||||||
|
#ifdef HAVE_MINGW
|
||||||
|
scriptextension = xstrdup(".bat");
|
||||||
|
#else
|
||||||
|
scriptextension = xstrdup("");
|
||||||
|
#endif
|
||||||
|
|
||||||
get_config_string(lookup_config(config_tree, "Proxy"), &proxy);
|
get_config_string(lookup_config(config_tree, "Proxy"), &proxy);
|
||||||
if(proxy) {
|
if(proxy) {
|
||||||
if((space = strchr(proxy, ' ')))
|
if((space = strchr(proxy, ' ')))
|
||||||
|
@ -465,32 +482,32 @@ bool setup_myself_reloadable(void) {
|
||||||
get_config_bool(lookup_config(config_tree, "DirectOnly"), &directonly);
|
get_config_bool(lookup_config(config_tree, "DirectOnly"), &directonly);
|
||||||
get_config_bool(lookup_config(config_tree, "LocalDiscovery"), &localdiscovery);
|
get_config_bool(lookup_config(config_tree, "LocalDiscovery"), &localdiscovery);
|
||||||
|
|
||||||
if(get_config_string(lookup_config(config_tree, "Mode"), &mode)) {
|
if(get_config_string(lookup_config(config_tree, "Mode"), &rmode)) {
|
||||||
if(!strcasecmp(mode, "router"))
|
if(!strcasecmp(rmode, "router"))
|
||||||
routing_mode = RMODE_ROUTER;
|
routing_mode = RMODE_ROUTER;
|
||||||
else if(!strcasecmp(mode, "switch"))
|
else if(!strcasecmp(rmode, "switch"))
|
||||||
routing_mode = RMODE_SWITCH;
|
routing_mode = RMODE_SWITCH;
|
||||||
else if(!strcasecmp(mode, "hub"))
|
else if(!strcasecmp(rmode, "hub"))
|
||||||
routing_mode = RMODE_HUB;
|
routing_mode = RMODE_HUB;
|
||||||
else {
|
else {
|
||||||
logger(DEBUG_ALWAYS, LOG_ERR, "Invalid routing mode!");
|
logger(DEBUG_ALWAYS, LOG_ERR, "Invalid routing mode!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
free(mode);
|
free(rmode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(get_config_string(lookup_config(config_tree, "Forwarding"), &mode)) {
|
if(get_config_string(lookup_config(config_tree, "Forwarding"), &fmode)) {
|
||||||
if(!strcasecmp(mode, "off"))
|
if(!strcasecmp(fmode, "off"))
|
||||||
forwarding_mode = FMODE_OFF;
|
forwarding_mode = FMODE_OFF;
|
||||||
else if(!strcasecmp(mode, "internal"))
|
else if(!strcasecmp(fmode, "internal"))
|
||||||
forwarding_mode = FMODE_INTERNAL;
|
forwarding_mode = FMODE_INTERNAL;
|
||||||
else if(!strcasecmp(mode, "kernel"))
|
else if(!strcasecmp(fmode, "kernel"))
|
||||||
forwarding_mode = FMODE_KERNEL;
|
forwarding_mode = FMODE_KERNEL;
|
||||||
else {
|
else {
|
||||||
logger(DEBUG_ALWAYS, LOG_ERR, "Invalid forwarding mode!");
|
logger(DEBUG_ALWAYS, LOG_ERR, "Invalid forwarding mode!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
free(mode);
|
free(fmode);
|
||||||
}
|
}
|
||||||
|
|
||||||
choice = true;
|
choice = true;
|
||||||
|
@ -505,18 +522,18 @@ bool setup_myself_reloadable(void) {
|
||||||
|
|
||||||
get_config_bool(lookup_config(config_tree, "PriorityInheritance"), &priorityinheritance);
|
get_config_bool(lookup_config(config_tree, "PriorityInheritance"), &priorityinheritance);
|
||||||
get_config_bool(lookup_config(config_tree, "DecrementTTL"), &decrement_ttl);
|
get_config_bool(lookup_config(config_tree, "DecrementTTL"), &decrement_ttl);
|
||||||
if(get_config_string(lookup_config(config_tree, "Broadcast"), &mode)) {
|
if(get_config_string(lookup_config(config_tree, "Broadcast"), &bmode)) {
|
||||||
if(!strcasecmp(mode, "no"))
|
if(!strcasecmp(bmode, "no"))
|
||||||
broadcast_mode = BMODE_NONE;
|
broadcast_mode = BMODE_NONE;
|
||||||
else if(!strcasecmp(mode, "yes") || !strcasecmp(mode, "mst"))
|
else if(!strcasecmp(bmode, "yes") || !strcasecmp(bmode, "mst"))
|
||||||
broadcast_mode = BMODE_MST;
|
broadcast_mode = BMODE_MST;
|
||||||
else if(!strcasecmp(mode, "direct"))
|
else if(!strcasecmp(bmode, "direct"))
|
||||||
broadcast_mode = BMODE_DIRECT;
|
broadcast_mode = BMODE_DIRECT;
|
||||||
else {
|
else {
|
||||||
logger(DEBUG_ALWAYS, LOG_ERR, "Invalid broadcast mode!");
|
logger(DEBUG_ALWAYS, LOG_ERR, "Invalid broadcast mode!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
free(mode);
|
free(bmode);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(SOL_IP) || !defined(IP_TOS)
|
#if !defined(SOL_IP) || !defined(IP_TOS)
|
||||||
|
|
|
@ -226,58 +226,40 @@ bool detach(void) {
|
||||||
|
|
||||||
bool execute_script(const char *name, char **envp) {
|
bool execute_script(const char *name, char **envp) {
|
||||||
#ifdef HAVE_SYSTEM
|
#ifdef HAVE_SYSTEM
|
||||||
int status, len;
|
|
||||||
char *scriptname;
|
char *scriptname;
|
||||||
int i;
|
char *command;
|
||||||
char *interpreter = NULL;
|
|
||||||
|
|
||||||
#ifndef HAVE_MINGW
|
xasprintf(&scriptname, "%s" SLASH "%s%s", confbase, name, scriptextension);
|
||||||
len = xasprintf(&scriptname, "\"%s" SLASH "%s\"", confbase, name);
|
|
||||||
#else
|
|
||||||
len = xasprintf(&scriptname, "\"%s" SLASH "%s.bat\"", confbase, name);
|
|
||||||
#endif
|
|
||||||
if(len < 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
scriptname[len - 1] = '\0';
|
|
||||||
|
|
||||||
#ifndef HAVE_TUNEMU
|
|
||||||
/* First check if there is a script */
|
/* First check if there is a script */
|
||||||
|
|
||||||
if(access(scriptname + 1, F_OK)) {
|
if(access(scriptname, F_OK)) {
|
||||||
free(scriptname);
|
free(scriptname);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
// Custom scripts interpreter
|
|
||||||
if(get_config_string(lookup_config(config_tree, "ScriptsInterpreter"), &interpreter)) {
|
|
||||||
// Force custom scripts interpreter allowing execution of scripts on android without execution flag (such as on /sdcard)
|
|
||||||
free(scriptname);
|
|
||||||
len = xasprintf(&scriptname, "%s \"%s/%s\"", interpreter, confbase, name);
|
|
||||||
free(interpreter);
|
|
||||||
if(len < 0)
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
logger(DEBUG_STATUS, LOG_INFO, "Executing script %s", name);
|
logger(DEBUG_STATUS, LOG_INFO, "Executing script %s", name);
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_PUTENV
|
#ifdef HAVE_PUTENV
|
||||||
/* Set environment */
|
/* Set environment */
|
||||||
|
|
||||||
for(i = 0; envp[i]; i++)
|
for(int i = 0; envp[i]; i++)
|
||||||
putenv(envp[i]);
|
putenv(envp[i]);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
scriptname[len - 1] = '\"';
|
if(scriptinterpreter)
|
||||||
status = system(scriptname);
|
xasprintf(&command, "%s \"%s\"", scriptinterpreter, scriptname);
|
||||||
|
else
|
||||||
|
xasprintf(&command, "\"%s\"", scriptname);
|
||||||
|
|
||||||
|
int status = system(command);
|
||||||
|
|
||||||
|
free(command);
|
||||||
free(scriptname);
|
free(scriptname);
|
||||||
|
|
||||||
/* Unset environment */
|
/* Unset environment */
|
||||||
|
|
||||||
for(i = 0; envp[i]; i++) {
|
for(int i = 0; envp[i]; i++) {
|
||||||
char *e = strchr(envp[i], '=');
|
char *e = strchr(envp[i], '=');
|
||||||
if(e) {
|
if(e) {
|
||||||
char p[e - envp[i] + 1];
|
char p[e - envp[i] + 1];
|
||||||
|
|
|
@ -355,7 +355,7 @@ static FILE *ask_and_open(const char *filename, const char *what, const char *mo
|
||||||
static bool ecdsa_keygen(bool ask) {
|
static bool ecdsa_keygen(bool ask) {
|
||||||
ecdsa_t key;
|
ecdsa_t key;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
char *filename;
|
char *pubname, *privname;
|
||||||
|
|
||||||
fprintf(stderr, "Generating ECDSA keypair:\n");
|
fprintf(stderr, "Generating ECDSA keypair:\n");
|
||||||
|
|
||||||
|
@ -365,8 +365,9 @@ static bool ecdsa_keygen(bool ask) {
|
||||||
} else
|
} else
|
||||||
fprintf(stderr, "Done.\n");
|
fprintf(stderr, "Done.\n");
|
||||||
|
|
||||||
xasprintf(&filename, "%s" SLASH "ecdsa_key.priv", confbase);
|
xasprintf(&privname, "%s" SLASH "ecdsa_key.priv", confbase);
|
||||||
f = ask_and_open(filename, "private ECDSA key", "a", ask);
|
f = ask_and_open(privname, "private ECDSA key", "a", ask);
|
||||||
|
free(privname);
|
||||||
|
|
||||||
if(!f)
|
if(!f)
|
||||||
return false;
|
return false;
|
||||||
|
@ -379,14 +380,14 @@ static bool ecdsa_keygen(bool ask) {
|
||||||
ecdsa_write_pem_private_key(&key, f);
|
ecdsa_write_pem_private_key(&key, f);
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
free(filename);
|
|
||||||
|
|
||||||
if(name)
|
if(name)
|
||||||
xasprintf(&filename, "%s" SLASH "hosts" SLASH "%s", confbase, name);
|
xasprintf(&pubname, "%s" SLASH "hosts" SLASH "%s", confbase, name);
|
||||||
else
|
else
|
||||||
xasprintf(&filename, "%s" SLASH "ecdsa_key.pub", confbase);
|
xasprintf(&pubname, "%s" SLASH "ecdsa_key.pub", confbase);
|
||||||
|
|
||||||
f = ask_and_open(filename, "public ECDSA key", "a", ask);
|
f = ask_and_open(pubname, "public ECDSA key", "a", ask);
|
||||||
|
free(pubname);
|
||||||
|
|
||||||
if(!f)
|
if(!f)
|
||||||
return false;
|
return false;
|
||||||
|
@ -396,7 +397,6 @@ static bool ecdsa_keygen(bool ask) {
|
||||||
free(pubkey);
|
free(pubkey);
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
free(filename);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -408,7 +408,7 @@ static bool ecdsa_keygen(bool ask) {
|
||||||
static bool rsa_keygen(int bits, bool ask) {
|
static bool rsa_keygen(int bits, bool ask) {
|
||||||
rsa_t key;
|
rsa_t key;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
char *filename;
|
char *pubname, *privname;
|
||||||
|
|
||||||
fprintf(stderr, "Generating %d bits keys:\n", bits);
|
fprintf(stderr, "Generating %d bits keys:\n", bits);
|
||||||
|
|
||||||
|
@ -418,8 +418,9 @@ static bool rsa_keygen(int bits, bool ask) {
|
||||||
} else
|
} else
|
||||||
fprintf(stderr, "Done.\n");
|
fprintf(stderr, "Done.\n");
|
||||||
|
|
||||||
xasprintf(&filename, "%s" SLASH "rsa_key.priv", confbase);
|
xasprintf(&privname, "%s" SLASH "rsa_key.priv", confbase);
|
||||||
f = ask_and_open(filename, "private RSA key", "a", ask);
|
f = ask_and_open(privname, "private RSA key", "a", ask);
|
||||||
|
free(privname);
|
||||||
|
|
||||||
if(!f)
|
if(!f)
|
||||||
return false;
|
return false;
|
||||||
|
@ -432,14 +433,14 @@ static bool rsa_keygen(int bits, bool ask) {
|
||||||
rsa_write_pem_private_key(&key, f);
|
rsa_write_pem_private_key(&key, f);
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
free(filename);
|
|
||||||
|
|
||||||
if(name)
|
if(name)
|
||||||
xasprintf(&filename, "%s" SLASH "hosts" SLASH "%s", confbase, name);
|
xasprintf(&pubname, "%s" SLASH "hosts" SLASH "%s", confbase, name);
|
||||||
else
|
else
|
||||||
xasprintf(&filename, "%s" SLASH "rsa_key.pub", confbase);
|
xasprintf(&pubname, "%s" SLASH "rsa_key.pub", confbase);
|
||||||
|
|
||||||
f = ask_and_open(filename, "public RSA key", "a", ask);
|
f = ask_and_open(pubname, "public RSA key", "a", ask);
|
||||||
|
free(pubname);
|
||||||
|
|
||||||
if(!f)
|
if(!f)
|
||||||
return false;
|
return false;
|
||||||
|
@ -447,7 +448,6 @@ static bool rsa_keygen(int bits, bool ask) {
|
||||||
rsa_write_pem_public_key(&key, f);
|
rsa_write_pem_public_key(&key, f);
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
free(filename);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -833,12 +833,15 @@ static int cmd_start(int argc, char *argv[]) {
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
if(pid == -1) {
|
if(pid == -1) {
|
||||||
fprintf(stderr, "Could not fork: %s\n", strerror(errno));
|
fprintf(stderr, "Could not fork: %s\n", strerror(errno));
|
||||||
|
free(nargv);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!pid)
|
if(!pid)
|
||||||
exit(execvp(c, nargv));
|
exit(execvp(c, nargv));
|
||||||
|
|
||||||
|
free(nargv);
|
||||||
|
|
||||||
int status = -1;
|
int status = -1;
|
||||||
if(waitpid(pid, &status, 0) != pid || !WIFEXITED(status) || WEXITSTATUS(status)) {
|
if(waitpid(pid, &status, 0) != pid || !WIFEXITED(status) || WEXITSTATUS(status)) {
|
||||||
fprintf(stderr, "Error starting %s\n", c);
|
fprintf(stderr, "Error starting %s\n", c);
|
||||||
|
@ -1226,7 +1229,7 @@ static struct {
|
||||||
{"ECDSAPrivateKeyFile", VAR_SERVER},
|
{"ECDSAPrivateKeyFile", VAR_SERVER},
|
||||||
{"ExperimentalProtocol", VAR_SERVER},
|
{"ExperimentalProtocol", VAR_SERVER},
|
||||||
{"Forwarding", VAR_SERVER},
|
{"Forwarding", VAR_SERVER},
|
||||||
{"GraphDumpFile", VAR_SERVER},
|
{"GraphDumpFile", VAR_SERVER | VAR_OBSOLETE},
|
||||||
{"Hostnames", VAR_SERVER},
|
{"Hostnames", VAR_SERVER},
|
||||||
{"IffOneQueue", VAR_SERVER},
|
{"IffOneQueue", VAR_SERVER},
|
||||||
{"Interface", VAR_SERVER},
|
{"Interface", VAR_SERVER},
|
||||||
|
@ -1245,6 +1248,8 @@ static struct {
|
||||||
{"ProcessPriority", VAR_SERVER},
|
{"ProcessPriority", VAR_SERVER},
|
||||||
{"Proxy", VAR_SERVER},
|
{"Proxy", VAR_SERVER},
|
||||||
{"ReplayWindow", VAR_SERVER},
|
{"ReplayWindow", VAR_SERVER},
|
||||||
|
{"ScriptsExtension", VAR_SERVER},
|
||||||
|
{"ScriptsInterpreter", VAR_SERVER},
|
||||||
{"StrictSubnets", VAR_SERVER},
|
{"StrictSubnets", VAR_SERVER},
|
||||||
{"TunnelServer", VAR_SERVER},
|
{"TunnelServer", VAR_SERVER},
|
||||||
{"UDPRcvBuf", VAR_SERVER},
|
{"UDPRcvBuf", VAR_SERVER},
|
||||||
|
@ -2133,6 +2138,8 @@ static int cmd_shell(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(nargv);
|
||||||
|
|
||||||
if(tty)
|
if(tty)
|
||||||
printf("\n");
|
printf("\n");
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Reference in a new issue