#include <sys/types.h>
#include <ctype.h>
+#include <string.h>
#include "config.h"
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<length; i++)
- dst[i] = charhex2bin(src[i*2])<<4 || charhex2bin(src[i*2+1]);
+ dst[i] = charhex2bin(src[i*2])*16 + charhex2bin(src[i*2+1]);
}
void bin2hex(char *src, char *dst, int length)
int i;
for(i=length-1; 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];
}
}
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 $
*/
cp
p = (config_t*)xmalloc(sizeof(*p));
p->data.val = 0;
-
+
switch(argtype)
{
case TYPE_INT:
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
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;
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 <syslog.h>
cp
cl->next = conn_list;
cl->prev = NULL;
- cl->next->prev = cl;
+ if(cl->next)
+ cl->next->prev = cl;
conn_list = cl;
cp
}
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"
if(debug_lvl > 0)
syslog(LOG_INFO, _("Connected to %s port %hd"),
cl->hostname, cl->port);
+
+ cl->status.meta = 1;
cp
return 0;
}
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));
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;
}
return -1;
}
else
- myself->name = (char*)cfg->data.val;
+ asprintf(&myself->name, "%s", (char*)cfg->data.val);
if(check_id(myself->name))
{
{
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 */
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);
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;
{
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);
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;
}
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"
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);
}
/* 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;
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);
return 0;
}
}
-
- /* Send a challenge to verify the identity */
-
- cl->allow_request = CHAL_REPLY;
cp
return send_challenge(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);
/* 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);
*/
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);
}
/* Status strings */
char (*status_text[]) = {
- "FIXME: status text",
+ "Warning",
};
/* Error strings */
char (*error_text[]) = {
- "FIXME: error text",
+ "Error",
};