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__
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 */
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);
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"
#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*/ ...)
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;
}
{
cp
if(!errstring)
- errstring = error_text[errno];
+ errstring = strerror(errno);
return send_request(cl, "%d %d %s", ERROR, errno, errstring);
}
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);
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;
}
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)
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;
}
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)
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. */
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;
}
{
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;
}