static void free_known_addresses(struct addrinfo *ai) {
for(struct addrinfo *aip = ai, *next; aip; aip = next) {
next = aip->ai_next;
+ free(aip->ai_addr);
free(aip);
}
}
// Something is seriously wrong here. If we can access the directory with tinc.conf in it, we should certainly be able to stat() an existing file.
fprintf(stderr, "ERROR: cannot read %s: %s\n", fname, strerror(errno));
fprintf(stderr, "Please correct this error.\n");
+ free(name);
return 1;
}
} else {
if(!f) {
fprintf(stderr, "ERROR: could not open %s: %s\n", fname, strerror(errno));
+ free(name);
return 1;
}
fprintf(stderr, "ERROR: No key or unusable key found in %s.\n", fname);
fprintf(stderr, "You can generate a new RSA key with:\n\n");
print_tinc_cmd(argv0, "generate-rsa-keys");
+ free(name);
return 1;
}
// Something is seriously wrong here. If we can access the directory with tinc.conf in it, we should certainly be able to stat() an existing file.
fprintf(stderr, "ERROR: cannot read %s: %s\n", fname, strerror(errno));
fprintf(stderr, "Please correct this error.\n");
+ free(name);
return 1;
}
} else {
if(!f) {
fprintf(stderr, "ERROR: could not open %s: %s\n", fname, strerror(errno));
+ free(name);
return 1;
}
fprintf(stderr, "ERROR: No key or unusable key found in %s.\n", fname);
fprintf(stderr, "You can generate a new Ed25519 key with:\n\n");
print_tinc_cmd(argv0, "generate-ed25519-keys");
+ free(name);
return 1;
}
#endif
fprintf(stderr, "You can generate new keys with:\n\n");
print_tinc_cmd(argv0, "generate-keys");
+ free(name);
return 1;
}
snprintf(fname, sizeof(fname), "%s/hosts/%s", confbase, name);
+ free(name);
+
if(access(fname, R_OK)) {
fprintf(stderr, "WARNING: cannot read %s\n", fname);
}
if(len != rsa_size(rsa_pub)) {
fprintf(stderr, "ERROR: public and private RSA keys do not match.\n");
+ rsa_free(rsa_pub);
+ rsa_free(rsa_priv);
+ free(ecdsa_priv);
return 1;
}
fprintf(stderr, "ERROR: public RSA key does not work.\n");
}
+
+ rsa_free(rsa_pub);
+ rsa_pub = NULL;
+
free(buf3);
free(buf2);
free(buf1);
if(!result) {
+ rsa_free(rsa_priv);
+ free(ecdsa_priv);
return 1;
}
-
}
+
+ rsa_free(rsa_priv);
+ rsa_priv = NULL;
} else {
if(rsa_pub) {
fprintf(stderr, "WARNING: A public RSA key was found but no private key is known.\n");
+ rsa_free(rsa_pub);
+ rsa_pub = NULL;
}
}
// TODO: suggest remedies
char *key1 = ecdsa_get_base64_public_key(ecdsa_pub);
+ free(ecdsa_pub);
+ ecdsa_pub = NULL;
+
if(!key1) {
fprintf(stderr, "ERROR: public Ed25519 key does not work.\n");
+ free(ecdsa_priv);
return 1;
}
char *key2 = ecdsa_get_base64_public_key(ecdsa_priv);
if(!key2) {
- free(key1);
fprintf(stderr, "ERROR: private Ed25519 key does not work.\n");
+ free(ecdsa_priv);
+ free(key1);
return 1;
}
if(result) {
fprintf(stderr, "ERROR: public and private Ed25519 keys do not match.\n");
+ free(ecdsa_priv);
return 1;
}
}
+
+ free(ecdsa_priv);
+ ecdsa_priv = NULL;
} else {
if(ecdsa_pub) {
fprintf(stderr, "WARNING: A public Ed25519 key was found but no private key is known.\n");
+ free(ecdsa_pub);
+ ecdsa_pub = NULL;
}
}
return 1;
}
+ free(myname);
myname = get_my_name(true);
if(!myname) {
devops_t devops;
bool device_standby = false;
-char *proxyhost;
-char *proxyport;
-char *proxyuser;
-char *proxypass;
+char *proxyhost = NULL;
+char *proxyport = NULL;
+char *proxyuser = NULL;
+char *proxypass = NULL;
+
proxytype_t proxytype;
bool autoconnect;
bool disablebuggypeers;
}
bool setup_myself_reloadable(void) {
- char *proxy = NULL;
- char *rmode = NULL;
- char *fmode = NULL;
- char *bmode = NULL;
- char *afname = NULL;
- char *space;
- bool choice;
-
free(scriptinterpreter);
scriptinterpreter = NULL;
- get_config_string(lookup_config(config_tree, "ScriptsInterpreter"), &scriptinterpreter);
+ get_config_string(lookup_config(config_tree, "ScriptsInterpreter"), &scriptinterpreter);
free(scriptextension);
scriptextension = xstrdup("");
}
+ char *proxy = NULL;
+
get_config_string(lookup_config(config_tree, "Proxy"), &proxy);
if(proxy) {
+ char *space;
+
if((space = strchr(proxy, ' '))) {
*space++ = 0;
}
proxytype = PROXY_EXEC;
} else {
logger(DEBUG_ALWAYS, LOG_ERR, "Unknown proxy type %s!", proxy);
+ free(proxy);
return false;
}
+ free(proxyhost);
+ proxyhost = NULL;
+
+ free(proxyport);
+ proxyport = NULL;
+
+ free(proxyuser);
+ proxyuser = NULL;
+
+ free(proxypass);
+ proxypass = NULL;
+
switch(proxytype) {
case PROXY_NONE:
default:
case PROXY_EXEC:
if(!space || !*space) {
logger(DEBUG_ALWAYS, LOG_ERR, "Argument expected for proxy type exec!");
+ free(proxy);
return false;
}
- proxyhost = xstrdup(space);
+ proxyhost = xstrdup(space);
break;
case PROXY_SOCKS4:
*space++ = 0, proxyport = space;
}
+ if(!proxyhost || !*proxyhost || !proxyport || !*proxyport) {
+ logger(DEBUG_ALWAYS, LOG_ERR, "Host and port argument expected for proxy!");
+ proxyport = NULL;
+ proxyhost = NULL;
+ free(proxy);
+ return false;
+ }
+
if(space && (space = strchr(space, ' '))) {
*space++ = 0, proxyuser = space;
}
*space++ = 0, proxypass = space;
}
- if(!proxyhost || !*proxyhost || !proxyport || !*proxyport) {
- logger(DEBUG_ALWAYS, LOG_ERR, "Host and port argument expected for proxy!");
- return false;
- }
-
proxyhost = xstrdup(proxyhost);
proxyport = xstrdup(proxyport);
free(proxy);
}
+ bool choice;
+
if(get_config_bool(lookup_config(config_tree, "IndirectData"), &choice) && choice) {
myself->options |= OPTION_INDIRECT;
}
get_config_bool(lookup_config(config_tree, "DirectOnly"), &directonly);
get_config_bool(lookup_config(config_tree, "LocalDiscovery"), &localdiscovery);
+ char *rmode = NULL;
+
if(get_config_string(lookup_config(config_tree, "Mode"), &rmode)) {
if(!strcasecmp(rmode, "router")) {
routing_mode = RMODE_ROUTER;
routing_mode = RMODE_HUB;
} else {
logger(DEBUG_ALWAYS, LOG_ERR, "Invalid routing mode!");
+ free(rmode);
return false;
}
free(rmode);
}
+ char *fmode = NULL;
+
if(get_config_string(lookup_config(config_tree, "Forwarding"), &fmode)) {
if(!strcasecmp(fmode, "off")) {
forwarding_mode = FMODE_OFF;
forwarding_mode = FMODE_KERNEL;
} else {
logger(DEBUG_ALWAYS, LOG_ERR, "Invalid forwarding mode!");
+ free(fmode);
return false;
}
get_config_bool(lookup_config(config_tree, "PriorityInheritance"), &priorityinheritance);
get_config_bool(lookup_config(config_tree, "DecrementTTL"), &decrement_ttl);
+ char *bmode = NULL;
+
if(get_config_string(lookup_config(config_tree, "Broadcast"), &bmode)) {
if(!strcasecmp(bmode, "no")) {
broadcast_mode = BMODE_NONE;
broadcast_mode = BMODE_DIRECT;
} else {
logger(DEBUG_ALWAYS, LOG_ERR, "Invalid broadcast mode!");
+ free(bmode);
return false;
}
abort();
}
- subnet_add(NULL, s);
+ if(splay_search(subnet_tree, s)) {
+ free(s);
+ } else {
+ subnet_add(NULL, s);
+ }
}
for(config_t *cfg = lookup_config(config_tree, "BroadcastSubnet"); cfg; cfg = lookup_config_next(config_tree, cfg)) {
continue;
}
- subnet_add(NULL, s);
+ if(splay_search(subnet_tree, s)) {
+ free(s);
+ } else {
+ subnet_add(NULL, s);
+ }
}
#if !defined(IP_TOS)
maxtimeout = 900;
}
+ char *afname = NULL;
+
if(get_config_string(lookup_config(config_tree, "AddressFamily"), &afname)) {
if(!strcasecmp(afname, "IPv4")) {
addressfamily = AF_INET;
addressfamily = AF_UNSPEC;
} else {
logger(DEBUG_ALWAYS, LOG_ERR, "Invalid address family!");
+ free(afname);
return false;
}
if(listen_sockets >= MAXSOCKETS) {
logger(DEBUG_ALWAYS, LOG_ERR, "Too many listening sockets");
+ freeaddrinfo(ai);
return false;
}
node_add(n);
}
+ free(name);
+
outgoing->node = n;
list_insert_tail(outgoing_list, outgoing);
setup_outgoing_connection(outgoing, true);
environment_add(&env, "REMOTEADDRESS=%s", address);
environment_add(&env, "NAME=%s", myself->name);
+ free(address);
+ free(port);
+
execute_script("invitation-accepted", &env);
environment_exit(&env);
char *node = NULL;
char *variable;
char *value;
- int len;
+ size_t len;
len = strcspn(line, "\t =");
value = line + len;
int sock[2];
char buf[1024];
- struct addrinfo *ai, hint;
- memset(&hint, 0, sizeof(hint));
-
- hint.ai_family = AF_UNSPEC;
- hint.ai_socktype = SOCK_STREAM;
- hint.ai_protocol = IPPROTO_TCP;
- hint.ai_flags = 0;
+ const struct addrinfo hint = {
+ .ai_family = AF_UNSPEC,
+ .ai_socktype = SOCK_STREAM,
+ .ai_protocol = IPPROTO_TCP,
+ .ai_flags = 0,
+ };
for(int i = 0; i < 2; i++) {
+ struct addrinfo *ai;
+
if(getaddrinfo(argv[2 + 3 * i], argv[3 + 3 * i], &hint, &ai) || !ai) {
fprintf(stderr, "getaddrinfo() failed: %s\n", sockstrerror(sockerrno));
return 1;
if(sock[i] == -1) {
fprintf(stderr, "Could not create socket: %s\n", sockstrerror(sockerrno));
+ freeaddrinfo(ai);
return 1;
}
if(connect(sock[i], ai->ai_addr, ai->ai_addrlen)) {
fprintf(stderr, "Could not connect to %s: %s\n", argv[i + 3 * i], sockstrerror(sockerrno));
+ freeaddrinfo(ai);
return 1;
}
+ freeaddrinfo(ai);
+
fprintf(stderr, "Connected to %s\n", argv[1 + 3 * i]);
/* Pretend to be the other one */