From: Guus Sliepen Date: Mon, 16 Oct 2000 16:33:30 +0000 (+0000) Subject: - Fixing little things X-Git-Tag: release-1.0pre3~82 X-Git-Url: https://tinc-vpn.org/git/browse?a=commitdiff_plain;h=bb3d18d56fa0dd2bc5146d0a0044b6ef0880bdb4;p=tinc - Fixing little things - Two tinc daemons can connect to eachother now (but they disconnect right after the ACKs). --- diff --git a/lib/utils.c b/lib/utils.c index e0bfe926..fc7abe4c 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -20,6 +20,7 @@ #include #include +#include #include "config.h" @@ -30,21 +31,22 @@ volatile int (cp_line[]) = {0, 0, 0, 0, 0, 0, 0, 0}; volatile char (*cp_file[]) = {"?", "?", "?", "?", "?", "?", "?", "?"}; volatile int cp_index = 0; -char *charbin2hex = "0123456789ABCDEF"; +char *hexadecimals = "0123456789ABCDEF"; int charhex2bin(char c) { if(isdigit(c)) return c - '0'; else - return tolower(c) - 'a' + 10; + return toupper(c) - 'A' + 10; } + void hex2bin(char *src, char *dst, int length) { int i; for(i=0; i=0; i--) { - dst[i*2+1] = charbin2hex[(unsigned char)src[i] & 15]; - dst[i*2] = charbin2hex[(unsigned char)src[i]>>4]; + dst[i*2+1] = hexadecimals[(unsigned char)src[i] & 15]; + dst[i*2] = hexadecimals[(unsigned char)src[i]>>4]; } } diff --git a/src/conf.c b/src/conf.c index 4fc374f8..72ef4081 100644 --- a/src/conf.c +++ b/src/conf.c @@ -19,7 +19,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: conf.c,v 1.9.4.14 2000/10/15 00:59:34 guus Exp $ + $Id: conf.c,v 1.9.4.15 2000/10/16 16:33:29 guus Exp $ */ @@ -90,7 +90,7 @@ add_config_val(config_t **cfg, int argtype, char *val) cp p = (config_t*)xmalloc(sizeof(*p)); p->data.val = 0; - + switch(argtype) { case TYPE_INT: @@ -225,7 +225,7 @@ cp const config_t *get_config_val(config_t *p, which_t type) { cp - for(p = config; p != NULL; p = p->next) + for(; p != NULL; p = p->next) if(p->which == type) break; cp @@ -239,7 +239,7 @@ cp const config_t *get_next_config_val(config_t *p, which_t type, int index) { cp - for(p = config; p != NULL; p = p->next) + for(; p != NULL; p = p->next) if(p->which == type) if(--index < 0) break; diff --git a/src/connlist.c b/src/connlist.c index b1e3146b..ed1467fa 100644 --- a/src/connlist.c +++ b/src/connlist.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: connlist.c,v 1.1.2.4 2000/10/15 00:59:34 guus Exp $ + $Id: connlist.c,v 1.1.2.5 2000/10/16 16:33:29 guus Exp $ */ #include @@ -120,7 +120,8 @@ void conn_list_add(conn_list_t *cl) cp cl->next = conn_list; cl->prev = NULL; - cl->next->prev = cl; + if(cl->next) + cl->next->prev = cl; conn_list = cl; cp } diff --git a/src/net.c b/src/net.c index c57fc198..e9d6ecba 100644 --- a/src/net.c +++ b/src/net.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: net.c,v 1.35.4.38 2000/10/15 20:30:39 guus Exp $ + $Id: net.c,v 1.35.4.39 2000/10/16 16:33:29 guus Exp $ */ #include "config.h" @@ -535,6 +535,8 @@ cp if(debug_lvl > 0) syslog(LOG_INFO, _("Connected to %s port %hd"), cl->hostname, cl->port); + + cl->status.meta = 1; cp return 0; } @@ -546,18 +548,42 @@ cp an authentication sequence during which we will do just that. */ -int setup_outgoing_connection(char *hostname) +int setup_outgoing_connection(char *name) { conn_list_t *ncn; struct hostent *h; + config_t *cfg; cp - if(!(h = gethostbyname(hostname))) + if(check_id(name)) { - syslog(LOG_ERR, _("Error looking up `%s': %m"), hostname); + syslog(LOG_ERR, _("Invalid name for outgoing connection")); return -1; } ncn = new_conn_list(); + asprintf(&ncn->name, "%s", name); + + if(read_host_config(ncn)) + { + syslog(LOG_ERR, _("Error reading host configuration file for %s")); + free_conn_list(ncn); + return -1; + } + + if(!(cfg = get_config_val(ncn->config, address))) + { + syslog(LOG_ERR, _("No address specified for %s")); + free_conn_list(ncn); + return -1; + } + + if(!(h = gethostbyname(cfg->data.ptr))) + { + syslog(LOG_ERR, _("Error looking up `%s': %m"), cfg->data.ptr); + free_conn_list(ncn); + return -1; + } + ncn->address = ntohl(*((ip_t*)(h->h_addr_list[0]))); ncn->hostname = hostlookup(htonl(ncn->address)); @@ -569,10 +595,15 @@ cp return -1; } - ncn->status.meta = 1; ncn->status.outgoing = 1; - ncn->next = conn_list; - conn_list = ncn; + ncn->buffer = xmalloc(MAXBUFSIZE); + ncn->buflen = 0; + ncn->last_ping_time = time(NULL); + ncn->want_ping = 0; + + conn_list_add(ncn); + + send_id(ncn); cp return 0; } @@ -596,7 +627,7 @@ cp return -1; } else - myself->name = (char*)cfg->data.val; + asprintf(&myself->name, "%s", (char*)cfg->data.val); if(check_id(myself->name)) { @@ -648,9 +679,12 @@ sigalrm_handler(int a) { config_t const *cfg; cp -/* FIXME! Use name instead of upstreamip. - cfg = get_next_config_val(config, upstreamip, upstreamindex++); -*/ + cfg = get_next_config_val(config, connectto, upstreamindex++); + + if(!upstreamindex && !cfg) + /* No upstream IP given, we're listen only. */ + return; + while(cfg) { if(!setup_outgoing_connection(cfg->data.ptr)) /* function returns 0 when there are no problems */ @@ -658,7 +692,7 @@ cp signal(SIGALRM, SIG_IGN); return; } -// cfg = get_next_config_val(config, upstreamip, upstreamindex++); /* Or else we try the next ConnectTo line */ + cfg = get_next_config_val(config, connectto, upstreamindex++); /* Or else we try the next ConnectTo line */ } signal(SIGALRM, sigalrm_handler); @@ -690,7 +724,7 @@ cp if(setup_myself() < 0) return -1; -// if((cfg = get_next_config_val(config, upstreamip, upstreamindex++)) == NULL) + if((cfg = get_next_config_val(config, connectto, upstreamindex++)) == NULL) /* No upstream IP given, we're listen only. */ return 0; @@ -698,7 +732,7 @@ cp { if(!setup_outgoing_connection(cfg->data.ptr)) /* function returns 0 when there are no problems */ return 0; -// cfg = get_next_config_val(config, upstreamip, upstreamindex++); /* Or else we try the next ConnectTo line */ + cfg = get_next_config_val(config, connectto, upstreamindex++); /* Or else we try the next ConnectTo line */ } signal(SIGALRM, sigalrm_handler); @@ -822,11 +856,7 @@ cp syslog(LOG_NOTICE, _("Connection from %s port %d"), p->hostname, htons(ci.sin_port)); - if(send_id(p) < 0) - { - free_conn_list(p); - return NULL; - } + p->allow_request = ID; cp return p; } diff --git a/src/protocol.c b/src/protocol.c index 97e35e3a..cb5c92fc 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: protocol.c,v 1.28.4.40 2000/10/15 00:59:35 guus Exp $ + $Id: protocol.c,v 1.28.4.41 2000/10/16 16:33:30 guus Exp $ */ #include "config.h" @@ -154,6 +154,8 @@ cp int send_id(conn_list_t *cl) { +cp + cl->allow_request = CHALLENGE; cp return send_request(cl, "%d %s %d %lx", ID, myself->name, myself->protocol_version, myself->options); } @@ -187,7 +189,7 @@ cp /* Load information about peer */ - if(!read_host_config(cl)) + if(read_host_config(cl)) { syslog(LOG_ERR, _("Peer %s had unknown identity (%s)"), cl->hostname, cl->name); return -1; @@ -202,6 +204,7 @@ cp if(cl->status.outgoing) { if((old = lookup_id(cl->name))) + if(old != cl) { if(debug_lvl > DEBUG_CONNECTIONS) syslog(LOG_NOTICE, _("Uplink %s (%s) is already in our connection list"), cl->name, cl->hostname); @@ -211,10 +214,6 @@ cp return 0; } } - - /* Send a challenge to verify the identity */ - - cl->allow_request = CHAL_REPLY; cp return send_challenge(cl); } @@ -313,7 +312,7 @@ int chal_reply_h(conn_list_t *cl) char *hishash; char myhash[SHA_DIGEST_LENGTH]; cp - if(sscanf(cl->buffer, "%*d %as", &hishash) != 2) + if(sscanf(cl->buffer, "%*d %as", &hishash) != 1) { syslog(LOG_ERR, _("Got bad CHAL_REPLY from %s (%s)"), cl->name, cl->hostname); free(hishash); @@ -339,7 +338,7 @@ cp /* Verify the incoming hash with the calculated hash */ - if(!memcmp(hishash, myhash, SHA_DIGEST_LENGTH)) + if(memcmp(hishash, myhash, SHA_DIGEST_LENGTH)) { syslog(LOG_ERR, _("Intruder: wrong challenge reply from %s (%s)"), cl->name, cl->hostname); free(hishash); @@ -354,19 +353,15 @@ cp */ cp if(cl->status.outgoing) - { - cl->allow_request = ACK; return send_ack(cl); - } else - { - cl->allow_request = CHALLENGE; return send_id(cl); - } } int send_ack(conn_list_t *cl) { +cp + cl->allow_request = ACK; cp return send_request(cl, "%d", ACK); } @@ -1051,11 +1046,11 @@ char (*request_name[]) = { /* Status strings */ char (*status_text[]) = { - "FIXME: status text", + "Warning", }; /* Error strings */ char (*error_text[]) = { - "FIXME: error text", + "Error", };