Second round of fixes

This commit is contained in:
Ivo Timmermans 2000-09-15 12:58:40 +00:00
parent ed397b6ac6
commit 7f3ab38c22
5 changed files with 75 additions and 32 deletions

View file

@ -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: encr.c,v 1.12.4.4 2000/08/18 11:17:09 guus Exp $
$Id: encr.c,v 1.12.4.5 2000/09/15 12:58:38 zarq Exp $
*/
#include "config.h"
@ -337,12 +337,12 @@ cp
/* We haven't received a key from this host (yet). */
continue;
ek = make_shared_key(p->public_key->key);
free_key(p->key);
p->key = xmalloc(sizeof(*p->key));
p->key->length = strlen(ek);
p->key->expiry = p->public_key->expiry;
p->key->key = xmalloc(strlen(ek) + 1);
strcpy(p->key->key, ek);
free_key(p->datakey);
p->datakey = xmalloc(sizeof(*p->datakey));
p->datakey->length = strlen(ek);
p->datakey->expiry = p->public_key->expiry;
p->datakey->key = xmalloc(strlen(ek) + 1);
strcpy(p->datakey->key, ek);
}
cp
}

View file

@ -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.29 2000/09/14 21:51:19 zarq Exp $
$Id: net.c,v 1.35.4.30 2000/09/15 12:58:39 zarq Exp $
*/
#include "config.h"
@ -93,11 +93,25 @@ cp
cp
}
int str2opt(const char *str) {
int r;
r = 0;
return r;
}
char *opt2str(int opt) {
static char s[50];
snprintf(s, 49, "%d", opt);
return &s;
}
int xsend(conn_list_t *cl, void *packet)
{
real_packet_t rp;
cp
do_encrypt((vpn_packet_t*)packet, &rp, cl->key);
do_encrypt((vpn_packet_t*)packet, &rp, cl->datakey);
rp.from = htonl(myself->vpn_ip);
rp.data.len = htons(rp.data.len);
rp.len = htons(rp.len);
@ -128,7 +142,7 @@ int xrecv(conn_list_t *cl, void *packet)
vpn_packet_t vp;
int lenin;
cp
do_decrypt((real_packet_t*)packet, &vp, cl->key);
do_decrypt((real_packet_t*)packet, &vp, cl->datakey);
add_mac_addresses(&vp);
if(debug_lvl > 3)

View file

@ -16,7 +16,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: net.h,v 1.9.4.11 2000/09/14 21:51:20 zarq Exp $
$Id: net.h,v 1.9.4.12 2000/09/15 12:58:40 zarq Exp $
*/
#ifndef __TINC_NET_H__
@ -133,13 +133,13 @@ typedef struct conn_list_t {
int meta_socket; /* our tcp meta socket */
int protocol_version; /* used protocol */
status_bits_t status; /* status info */
option_bits_t options; /* options turned on for this connection */
int options; /* options turned on for this connection */
passphrase_t *pp; /* encoded passphrase */
packet_queue_t *sq; /* pending outgoing packets */
packet_queue_t *rq; /* pending incoming packets (they have no
valid key to be decrypted with) */
enc_key_t *public_key; /* the other party's public key */
enc_key_t *key; /* encrypt with this key */
enc_key_t *datakey; /* encrypt data packets with this key */
char *buffer; /* metadata input buffer */
int buflen; /* bytes read into buffer */
int reqlen; /* length of first request in buffer */
@ -164,7 +164,10 @@ extern conn_list_t *conn_list;
extern conn_list_t *myself;
extern char *request_name[256];
extern char *status_text[10];
extern int str2opt(const char *);
extern char *opt2str(int);
extern int send_packet(ip_t, vpn_packet_t *);
extern int setup_network_connections(void);
extern void close_network_connections(void);

View file

@ -16,7 +16,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: netutl.c,v 1.12.4.9 2000/09/14 21:51:20 zarq Exp $
$Id: netutl.c,v 1.12.4.10 2000/09/15 12:58:40 zarq Exp $
*/
#include "config.h"
@ -95,7 +95,7 @@ cp
if(p->hostname)
free(p->hostname);
free_key(p->public_key);
free_key(p->key);
free_key(p->datakey);
free(p);
cp
}

View file

@ -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.31 2000/09/14 21:51:21 zarq Exp $
$Id: protocol.c,v 1.28.4.32 2000/09/15 12:58:40 zarq Exp $
*/
#include "config.h"
@ -46,6 +46,21 @@
#include "system.h"
int check_id(char *id)
{
int i;
for (i = 0; i < strlen(id); i++)
{
if(!isalpha(id[i]) && id[i] != '_')
{
return 0;
}
}
return 1;
}
/* Generic outgoing request routine - takes care of logging and error detection as well */
int send_request(conn_list_t *cl, const char *format, int request, /*args*/ ...)
@ -596,7 +611,8 @@ int status_h(conn_list_t *cl)
cp
if(sscanf(cl->buffer, "%*d %d %as", &statusno, &statusstring) != 2)
{
syslog(LOG_ERR, _("Got bad STATUS from %s (%s)"), cl->id, cl->hostname);
syslog(LOG_ERR, _("Got bad STATUS from %s (%s)"),
cl->name, cl->hostname);
return -1;
}
@ -615,7 +631,7 @@ int send_error(conn_list_t *cl, int errno, char *errstring)
{
cp
if(!errstring)
errstring = error_text[errno];
errstring = strerror(errno);
return send_request(cl, "%d %d %s", ERROR, errno, errstring);
}
@ -634,7 +650,7 @@ cp
if(debug_lvl > DEBUG_error)
{
syslog(LOG_NOTICE, _("Error message from %s (%s): %s: %s"),
cl->name, cl->hostname, error_text[errno], errorstring);
cl->name, cl->hostname, strerror(errno), errorstring);
}
free(errorstring);
@ -718,7 +734,8 @@ cp
if(!(from = lookup_id(from_id)))
{
syslog(LOG_ERR, _("Got KEY_CHANGED from %s (%s) origin %s which does not exist in our connection list"), cl->id, cl->hostname, from_id);
syslog(LOG_ERR, _("Got KEY_CHANGED from %s (%s) origin %s which does not exist in our connection list"),
cl->name, cl->hostname, from_id);
free(from_id);
return -1;
}
@ -736,7 +753,8 @@ cp
int send_req_key(conn_list_t *from, conn_list_t *to)
{
cp
return send_request(to->nexthop, "%d %s %s", REQ_KEY, from->id, to->id);
return send_request(to->nexthop, "%d %s %s", REQ_KEY,
from->name, to->name);
}
int req_key_h(conn_list_t *cl)
@ -746,28 +764,31 @@ int req_key_h(conn_list_t *cl)
cp
if(sscanf(cl->buffer, "%*d %as %as", &from_id, &to_id) != 2)
{
syslog(LOG_ERR, _("Got bad REQ_KEY from %s (%s)"), cl->id, cl->hostname);
syslog(LOG_ERR, _("Got bad REQ_KEY from %s (%s)"),
cl->name, cl->hostname);
return -1;
}
if(!(from = lookup_id(from_id)))
{
syslog(LOG_ERR, _("Got REQ_KEY from %s (%s) origin %s which does not exist in our connection list"), cl->id, cl->hostname, from_id);
syslog(LOG_ERR, _("Got REQ_KEY from %s (%s) origin %s which does not exist in our connection list"),
cl->name, cl->hostname, from_id);
free(from_id); free(to_id);
return -1;
}
/* Check if this key request is for us */
if(!strcmp(id, myself->strcmp))
if(!strcmp(to_id, myself->name))
{
send_ans_key(myself, from, myself->datakey);
send_ans_key(myself, from, myself->datakey->key);
}
else
{
if(!(to = lookup_id(to_id)))
{
syslog(LOG_ERR, _("Got REQ_KEY from %s (%s) destination %s which does not exist in our connection list"), cl->id, cl->hostname, to_id);
syslog(LOG_ERR, _("Got REQ_KEY from %s (%s) destination %s which does not exist in our connection list"),
cl->name, cl->hostname, to_id);
free(from_id); free(to_id);
return -1;
}
@ -782,7 +803,8 @@ cp
int send_ans_key(conn_list_t *from, conn_list_t *to, char *datakey)
{
cp
return send_request(to->nexthop, "%d %s %s %s", ANS_KEY, from->id, to->id, datakey);
return send_request(to->nexthop, "%d %s %s %s", ANS_KEY,
from->name, to->name, datakey);
}
int ans_key_h(conn_list_t *cl)
@ -793,20 +815,22 @@ int ans_key_h(conn_list_t *cl)
cp
if(sscanf(cl->buffer, "%*d %as %as %as", &from_id, &to_id, &datakey) != 3)
{
syslog(LOG_ERR, _("Got bad ANS_KEY from %s (%s)"), cl->id, cl->hostname);
syslog(LOG_ERR, _("Got bad ANS_KEY from %s (%s)"),
cl->name, cl->hostname);
return -1;
}
if(!(from = lookup_id(from_id)))
{
syslog(LOG_ERR, _("Got ANS_KEY from %s (%s) origin %s which does not exist in our connection list"), cl->id, cl->hostname, from_id);
syslog(LOG_ERR, _("Got ANS_KEY from %s (%s) origin %s which does not exist in our connection list"),
cl->name, cl->hostname, from_id);
free(from_id); free(to_id); free(datakey);
return -1;
}
/* Check if this key request is for us */
if(!strcmp(id, myself->strcmp))
if(!strcmp(to_id, myself->name))
{
/* It is for us, convert it to binary and set the key with it. */
@ -814,7 +838,8 @@ cp
if((keylength%2) || (keylength <= 0))
{
syslog(LOG_ERR, _("Got bad ANS_KEY from %s (%s) origin %s: invalid key"), cl->id, cl->hostname, from->id);
syslog(LOG_ERR, _("Got bad ANS_KEY from %s (%s) origin %s: invalid key"),
cl->name, cl->hostname, from->name);
free(from_id); free(to_id); free(datakey);
return -1;
}
@ -826,7 +851,8 @@ cp
{
if(!(to = lookup_id(to_id)))
{
syslog(LOG_ERR, _("Got ANS_KEY from %s (%s) destination %s which does not exist in our connection list"), cl->id, cl->hostname, to_id);
syslog(LOG_ERR, _("Got ANS_KEY from %s (%s) destination %s which does not exist in our connection list"),
cl->name, cl->hostname, to_id);
free(from_id); free(to_id); free(datakey);
return -1;
}