1999-05-11 17:53:45 +08:00
|
|
|
/*
|
|
|
|
* Rest in pieces - RIP protocol
|
|
|
|
*
|
|
|
|
* Copyright (c) 1999 Pavel Machek <pavel@ucw.cz>
|
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LOCAL_DEBUG
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "nest/bird.h"
|
|
|
|
#include "nest/iface.h"
|
|
|
|
#include "nest/protocol.h"
|
|
|
|
#include "nest/route.h"
|
|
|
|
#include "lib/socket.h"
|
|
|
|
#include "lib/resource.h"
|
|
|
|
#include "lib/lists.h"
|
|
|
|
#include "lib/timer.h"
|
1999-06-01 03:16:22 +08:00
|
|
|
#include "lib/md5.h"
|
1999-05-11 17:53:45 +08:00
|
|
|
|
|
|
|
#include "rip.h"
|
|
|
|
|
|
|
|
#define P ((struct rip_proto *) p)
|
|
|
|
#define P_CF ((struct rip_proto_config *)p->cf)
|
|
|
|
|
1999-06-01 01:12:38 +08:00
|
|
|
/* 1 == failed, 0 == ok */
|
1999-05-11 17:53:45 +08:00
|
|
|
int
|
1999-06-01 01:12:38 +08:00
|
|
|
rip_incoming_authentication( struct proto *p, struct rip_block_auth *block, struct rip_packet *packet, int num )
|
1999-05-11 17:53:45 +08:00
|
|
|
{
|
|
|
|
DBG( "Incoming authentication: " );
|
|
|
|
|
1999-06-01 01:12:38 +08:00
|
|
|
switch (block->authtype) { /* Authentication type */
|
1999-05-11 17:53:45 +08:00
|
|
|
case AT_PLAINTEXT:
|
|
|
|
DBG( "Plaintext passwd" );
|
1999-06-01 01:12:38 +08:00
|
|
|
if (!P_CF->passwords) {
|
|
|
|
log( L_AUTH "no passwords set and password authentication came\n" );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (strncmp( (char *) (&block->packetlen), P_CF->passwords->password, 16)) {
|
1999-05-11 17:53:45 +08:00
|
|
|
log( L_AUTH, "Passwd authentication failed!\n" );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
1999-06-01 01:12:38 +08:00
|
|
|
case AT_MD5:
|
|
|
|
DBG( "md5 password" );
|
|
|
|
{
|
|
|
|
struct password_item *head;
|
1999-06-01 03:16:22 +08:00
|
|
|
struct rip_md5_tail *tail;
|
|
|
|
|
1999-06-01 03:22:40 +08:00
|
|
|
tail = (struct rip_md5_tail *) ((char *) packet + (block->packetlen - sizeof(struct rip_block_auth)));
|
1999-06-01 03:16:22 +08:00
|
|
|
|
1999-06-01 01:12:38 +08:00
|
|
|
head = P_CF->passwords;
|
|
|
|
while (head) {
|
1999-06-01 03:16:22 +08:00
|
|
|
if (head->id == block->keyid) {
|
|
|
|
struct MD5Context ctxt;
|
|
|
|
char md5sum_packet[16];
|
|
|
|
char md5sum_computed[16];
|
|
|
|
|
1999-06-01 03:22:40 +08:00
|
|
|
memcpy(md5sum_packet, tail->md5, 16);
|
1999-06-01 03:16:22 +08:00
|
|
|
password_strncpy(tail->md5, head->password, 16);
|
|
|
|
|
|
|
|
MD5Init(&ctxt);
|
1999-06-01 03:22:40 +08:00
|
|
|
MD5Update(&ctxt, (char *) packet, block->packetlen );
|
1999-06-01 03:16:22 +08:00
|
|
|
MD5Final(md5sum_computed, &ctxt);
|
|
|
|
|
|
|
|
if (memcmp(md5sum_packet, md5sum_computed, 16))
|
|
|
|
return 1;
|
|
|
|
}
|
1999-06-01 01:12:38 +08:00
|
|
|
head = head->next;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
1999-05-11 17:53:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-06-01 01:12:38 +08:00
|
|
|
rip_outgoing_authentication( struct proto *p, struct rip_block_auth *block, struct rip_packet *packet, int num )
|
1999-05-11 17:53:45 +08:00
|
|
|
{
|
|
|
|
DBG( "Outgoing authentication: " );
|
|
|
|
|
1999-06-01 01:12:38 +08:00
|
|
|
block->authtype = P_CF->authtype;
|
1999-05-11 17:53:45 +08:00
|
|
|
switch (P_CF->authtype) {
|
|
|
|
case AT_PLAINTEXT:
|
1999-06-01 01:12:38 +08:00
|
|
|
if (!P_CF->passwords) {
|
|
|
|
log( L_ERR "no passwords set and password authentication requested\n" );
|
|
|
|
return;
|
|
|
|
}
|
1999-06-01 03:16:22 +08:00
|
|
|
password_strncpy( (char *) (&block->packetlen), P_CF->passwords->password, 16);
|
1999-05-11 17:53:45 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|