along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: net_setup.c,v 1.1.2.23 2002/09/04 13:48:52 guus Exp $
+ $Id: net_setup.c,v 1.1.2.24 2002/09/09 19:39:58 guus Exp $
*/
#include "config.h"
FILE *fp;
char *fname;
char *key;
-cp
+ cp();
if(!c->rsa_key)
c->rsa_key = RSA_new();
{
if(is_safe_path(fname))
{
- if((fp = fopen(fname, "r")) == NULL)
+ fp = fopen(fname, "r");
+ if(!fp)
{
syslog(LOG_ERR, _("Error reading RSA public key file `%s': %s"),
fname, strerror(errno));
return 0; /* Woohoo. */
/* If it fails, try PEM_read_RSA_PUBKEY. */
- if((fp = fopen(fname, "r")) == NULL)
+ fp = fopen(fname, "r");
+ if(!fp)
{
syslog(LOG_ERR, _("Error reading RSA public key file `%s': %s"),
fname, strerror(errno));
/* Else, check if a harnessed public key is in the config file */
asprintf(&fname, "%s/hosts/%s", confbase, c->name);
- if((fp = fopen(fname, "r")))
+ fp = fopen(fname, "r");
+
+ if(fp)
{
c->rsa_key = PEM_read_RSAPublicKey(fp, &c->rsa_key, NULL, NULL);
fclose(fp);
/* Try again with PEM_read_RSA_PUBKEY. */
asprintf(&fname, "%s/hosts/%s", confbase, c->name);
- if((fp = fopen(fname, "r")))
+ fp = fopen(fname, "r");
+
+ if(fp)
{
c->rsa_key = PEM_read_RSA_PUBKEY(fp, &c->rsa_key, NULL, NULL);
fclose(fp);
{
FILE *fp;
char *fname, *key;
-cp
+ cp();
if(get_config_string(lookup_config(config_tree, "PrivateKey"), &key))
{
myself->connection->rsa_key = RSA_new();
if(is_safe_path(fname))
{
- if((fp = fopen(fname, "r")) == NULL)
+ fp = fopen(fname, "r");
+ if(!fp)
{
syslog(LOG_ERR, _("Error reading RSA private key file `%s': %s"),
fname, strerror(errno));
char *address = NULL;
struct addrinfo hint, *ai, *aip;
int choice, err;
-cp
+ cp();
myself = new_node();
myself->connection = new_connection();
init_configuration(&myself->connection->config_tree);
myself->name = name;
myself->connection->name = xstrdup(name);
-cp
+ cp();
if(read_rsa_private_key())
return -1;
if(read_rsa_public_key(myself->connection))
return -1;
-cp
+ cp();
if(!get_config_string(lookup_config(myself->connection->config_tree, "Port"), &myport))
asprintf(&myport, "655");
cfg = lookup_config_next(myself->connection->config_tree, cfg);
}
-cp
+ cp();
/* Check some options */
if(get_config_bool(lookup_config(config_tree, "IndirectData"), &choice))
addressfamily = AF_INET;
get_config_bool(lookup_config(config_tree, "Hostnames"), &hostnames);
-cp
+ cp();
/* Generate packet encryption key */
if(get_config_string(lookup_config(myself->connection->config_tree, "Cipher"), &cipher))
}
else
{
- if(!(myself->cipher = EVP_get_cipherbyname(cipher)))
+ myself->cipher = EVP_get_cipherbyname(cipher);
+
+ if(!myself->cipher)
{
syslog(LOG_ERR, _("Unrecognized cipher type!"));
return -1;
}
else
{
- if(!(myself->digest = EVP_get_digestbyname(digest)))
+ myself->digest = EVP_get_digestbyname(digest);
+
+ if(!myself->digest)
{
syslog(LOG_ERR, _("Unrecognized digest type!"));
return -1;
myself->compression = 0;
myself->connection->outcompression = 0;
-cp
+ cp();
/* Done */
myself->nexthop = myself;
graph();
-cp
+ cp();
/* Open sockets */
memset(&hint, 0, sizeof(hint));
hint.ai_protocol = IPPROTO_TCP;
hint.ai_flags = AI_PASSIVE;
- if((err = getaddrinfo(address, myport, &hint, &ai)) || !ai)
+ err = getaddrinfo(address, myport, &hint, &ai);
+
+ if(err || !ai)
{
syslog(LOG_ERR, _("System call `%s' failed: %s"), "getaddrinfo", gai_strerror(err));
return -1;
for(aip = ai; aip; aip = aip->ai_next)
{
- if((listen_socket[listen_sockets].tcp = setup_listen_socket((sockaddr_t *)aip->ai_addr)) < 0)
+ listen_socket[listen_sockets].tcp = setup_listen_socket((sockaddr_t *)aip->ai_addr);
+
+ if(listen_socket[listen_sockets].tcp < 0)
continue;
- if((listen_socket[listen_sockets].udp = setup_vpn_in_socket((sockaddr_t *)aip->ai_addr)) < 0)
+ listen_socket[listen_sockets].udp = setup_vpn_in_socket((sockaddr_t *)aip->ai_addr);
+
+ if(listen_socket[listen_sockets].udp < 0)
continue;
if(debug_lvl >= DEBUG_CONNECTIONS)
syslog(LOG_ERR, _("Unable to create any listening socket!"));
return -1;
}
-cp
+ cp();
return 0;
}
{
char *envp[4];
int i;
-cp
+ cp();
now = time(NULL);
init_connections();
return -1;
/* Run tinc-up script to further initialize the tap interface */
- asprintf(&envp[0], "NETNAME=%s", netname?netname:"");
- asprintf(&envp[1], "DEVICE=%s", device?device:"");
- asprintf(&envp[2], "INTERFACE=%s", interface?interface:"");
+ asprintf(&envp[0], "NETNAME=%s", netname?:"");
+ asprintf(&envp[1], "DEVICE=%s", device?:"");
+ asprintf(&envp[2], "INTERFACE=%s", interface?:"");
envp[3] = NULL;
execute_script("tinc-up", envp);
return -1;
try_outgoing_connections();
-cp
+ cp();
return 0;
}
connection_t *c;
char *envp[4];
int i;
-cp
+ cp();
for(node = connection_tree->head; node; node = next)
{
next = node->next;
exit_nodes();
exit_connections();
- asprintf(&envp[0], "NETNAME=%s", netname?netname:"");
- asprintf(&envp[1], "DEVICE=%s", device?device:"");
- asprintf(&envp[2], "INTERFACE=%s", interface?interface:"");
+ asprintf(&envp[0], "NETNAME=%s", netname?:"");
+ asprintf(&envp[1], "DEVICE=%s", device?:"");
+ asprintf(&envp[2], "INTERFACE=%s", interface?:"");
envp[3] = NULL;
execute_script("tinc-down", envp);
free(envp[i]);
close_device();
-cp
+ cp();
return;
}