along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: protocol_auth.c,v 1.1.4.20 2003/07/06 17:15:25 guus Exp $
+ $Id: protocol_auth.c,v 1.1.4.22 2003/07/06 23:16:29 guus Exp $
*/
#include "config.h"
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <stdio.h>
#include <stdarg.h>
#include <errno.h>
#include "node.h"
#include "edge.h"
#include "graph.h"
+#include "logger.h"
#include "system.h"
cp();
if(sscanf(c->buffer, "%*d " MAX_STRING " %d", name, &c->protocol_version) != 2) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ID", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "ID", c->name,
c->hostname);
return -1;
}
/* Check if identity is a valid name */
if(check_id(name)) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s): %s"), "ID", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s): %s"), "ID", c->name,
c->hostname, "invalid name");
return -1;
}
if(c->name) {
if(strcmp(c->name, name)) {
- syslog(LOG_ERR, _("Peer %s is %s instead of %s"), c->hostname, name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Peer %s is %s instead of %s"), c->hostname, name,
c->name);
return -1;
}
/* Check if version matches */
if(c->protocol_version != myself->connection->protocol_version) {
- syslog(LOG_ERR, _("Peer %s (%s) uses incompatible version %d"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Peer %s (%s) uses incompatible version %d"),
c->name, c->hostname, c->protocol_version);
return -1;
}
bla = read_connection_config(c);
if(bla) {
- syslog(LOG_ERR, _("Peer %s had unknown identity (%s)"), c->hostname,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Peer %s had unknown identity (%s)"), c->hostname,
c->name);
return -1;
}
c->outkey[0] &= 0x7F;
- if(debug_lvl >= DEBUG_SCARY_THINGS) {
+ if(debug_level >= DEBUG_SCARY_THINGS) {
bin2hex(c->outkey, buffer, len);
buffer[len * 2] = '\0';
- syslog(LOG_DEBUG, _("Generated random meta key (unencrypted): %s"),
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Generated random meta key (unencrypted): %s"),
buffer);
}
*/
if(RSA_public_encrypt(len, c->outkey, buffer, c->rsa_key, RSA_NO_PADDING) != len) {
- syslog(LOG_ERR, _("Error during encryption of meta key for %s (%s)"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error during encryption of meta key for %s (%s)"),
c->name, c->hostname);
return -1;
}
cp();
if(sscanf(c->buffer, "%*d %d %d %d %d " MAX_STRING, &cipher, &digest, &maclength, &compression, buffer) != 5) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "METAKEY", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "METAKEY", c->name,
c->hostname);
return -1;
}
/* Check if the length of the meta key is all right */
if(strlen(buffer) != len * 2) {
- syslog(LOG_ERR, _("Possible intruder %s (%s): %s"), c->name, c->hostname, "wrong keylength");
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Possible intruder %s (%s): %s"), c->name, c->hostname, "wrong keylength");
return -1;
}
/* Decrypt the meta key */
if(RSA_private_decrypt(len, buffer, c->inkey, myself->connection->rsa_key, RSA_NO_PADDING) != len) { /* See challenge() */
- syslog(LOG_ERR, _("Error during encryption of meta key for %s (%s)"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error during encryption of meta key for %s (%s)"),
c->name, c->hostname);
return -1;
}
- if(debug_lvl >= DEBUG_SCARY_THINGS) {
+ if(debug_level >= DEBUG_SCARY_THINGS) {
bin2hex(c->inkey, buffer, len);
buffer[len * 2] = '\0';
- syslog(LOG_DEBUG, _("Received random meta key (unencrypted): %s"), buffer);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Received random meta key (unencrypted): %s"), buffer);
}
/* All incoming requests will now be encrypted. */
c->incipher = EVP_get_cipherbynid(cipher);
if(!c->incipher) {
- syslog(LOG_ERR, _("%s (%s) uses unknown cipher!"), c->name, c->hostname);
+ logger(DEBUG_ALWAYS, LOG_ERR, _("%s (%s) uses unknown cipher!"), c->name, c->hostname);
return -1;
}
c->indigest = EVP_get_digestbynid(digest);
if(!c->indigest) {
- syslog(LOG_ERR, _("Node %s (%s) uses unknown digest!"), c->name, c->hostname);
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Node %s (%s) uses unknown digest!"), c->name, c->hostname);
return -1;
}
if(c->inmaclength > c->indigest->md_size || c->inmaclength < 0) {
- syslog(LOG_ERR, _("%s (%s) uses bogus MAC length!"), c->name, c->hostname);
+ logger(DEBUG_ALWAYS, LOG_ERR, _("%s (%s) uses bogus MAC length!"), c->name, c->hostname);
return -1;
}
} else {
cp();
if(sscanf(c->buffer, "%*d " MAX_STRING, buffer) != 1) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "CHALLENGE", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "CHALLENGE", c->name,
c->hostname);
return -1;
}
/* Check if the length of the challenge is all right */
if(strlen(buffer) != len * 2) {
- syslog(LOG_ERR, _("Possible intruder %s (%s): %s"), c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Possible intruder %s (%s): %s"), c->name,
c->hostname, "wrong challenge length");
return -1;
}
cp();
if(sscanf(c->buffer, "%*d " MAX_STRING, hishash) != 1) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "CHAL_REPLY", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "CHAL_REPLY", c->name,
c->hostname);
return -1;
}
/* Check if the length of the hash is all right */
if(strlen(hishash) != c->outdigest->md_size * 2) {
- syslog(LOG_ERR, _("Possible intruder %s (%s): %s"), c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Possible intruder %s (%s): %s"), c->name,
c->hostname, _("wrong challenge reply length"));
return -1;
}
/* Verify the incoming hash with the calculated hash */
if(memcmp(hishash, myhash, c->outdigest->md_size)) {
- syslog(LOG_ERR, _("Possible intruder %s (%s): %s"), c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Possible intruder %s (%s): %s"), c->name,
c->hostname, _("wrong challenge reply"));
- if(debug_lvl >= DEBUG_SCARY_THINGS) {
+ if(debug_level >= DEBUG_SCARY_THINGS) {
bin2hex(myhash, hishash, SHA_DIGEST_LENGTH);
hishash[SHA_DIGEST_LENGTH * 2] = '\0';
- syslog(LOG_DEBUG, _("Expected challenge reply: %s"), hishash);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Expected challenge reply: %s"), hishash);
}
return -1;
return x;
}
-void send_everything(connection_t *c)
+static void send_everything(connection_t *c)
{
avl_node_t *node, *node2;
node_t *n;
cp();
- if(sscanf
- (c->buffer, "%*d " MAX_STRING " %d %lx", hisport, &weight, &options) != 3) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ACK", c->name,
+ if(sscanf(c->buffer, "%*d " MAX_STRING " %d %lx", hisport, &weight, &options) != 3) {
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "ACK", c->name,
c->hostname);
return -1;
}
} else {
if(n->connection) {
/* Oh dear, we already have a connection to this node. */
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_DEBUG, _("Established a second connection with %s (%s), closing old connection"),
+ logger(DEBUG_CONNECTIONS, LOG_DEBUG, _("Established a second connection with %s (%s), closing old connection"),
n->name, n->hostname);
terminate_connection(n->connection, 0);
/* Run graph algorithm to purge key and make sure up/down scripts are rerun with new IP addresses and stuff */
c->allow_request = ALL;
c->status.active = 1;
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_NOTICE, _("Connection with %s (%s) activated"), c->name,
+ logger(DEBUG_CONNECTIONS, LOG_NOTICE, _("Connection with %s (%s) activated"), c->name,
c->hostname);
/* Send him everything we know */