Skip to content

Commit

Permalink
Don't consider empty client.keys to be a failure condition on servers
Browse files Browse the repository at this point in the history
client.keys is already reloaded each time a given key is not found in
memory so there's no harm in this file being empty. In fact, it's
downright annoying if you're using authd because you have to wait for
the first agent to register and then manually restart the server
before they can start communicating. Removing this check would make
the Chef cookbook less clunky.
  • Loading branch information
chewi committed Nov 16, 2015
1 parent aaf2001 commit a40bed1
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/os_crypto/shared/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,21 @@
#include "os_crypto/blowfish/bf_op.h"

/* Prototypes */
static void __realloc(keystore *keys) __attribute((nonnull));
static void __memclear(char *id, char *name, char *ip, char *key, size_t size) __attribute((nonnull));
static void __chash(keystore *keys, const char *id, const char *name, char *ip, const char *key) __attribute((nonnull));


static void __realloc(keystore *keys)
{
/* Allocate for the whole structure */
keys->keyentries = (keyentry **)realloc(keys->keyentries,
(keys->keysize + 2) * sizeof(keyentry *));
if (!keys->keyentries) {
ErrorExit(MEM_ERROR, __local_name, errno, strerror(errno));
}
}

/* Clear keys entries */
static void __memclear(char *id, char *name, char *ip, char *key, size_t size)
{
Expand All @@ -35,12 +46,7 @@ static void __chash(keystore *keys, const char *id, const char *name, char *ip,
char *tmp_str;
char _finalstr[KEYSIZE];

/* Allocate for the whole structure */
keys->keyentries = (keyentry **)realloc(keys->keyentries,
(keys->keysize + 2) * sizeof(keyentry *));
if (!keys->keyentries) {
ErrorExit(MEM_ERROR, __local_name, errno, strerror(errno));
}
__realloc(keys);
os_calloc(1, sizeof(keyentry), keys->keyentries[keys->keysize]);

/* Set configured values for id */
Expand Down Expand Up @@ -250,9 +256,14 @@ void OS_ReadKeys(keystore *keys)
/* Clear one last time before leaving */
__memclear(id, name, ip, key, KEYSIZE + 1);

/* Check if there are any agents available */
/* Check if there are any keys available, except on remoted
* because more keys could be added later */
if (keys->keysize == 0) {
ErrorExit(NO_REM_CONN, __local_name);
if (strcmp(__local_name, "ossec-remoted") != 0) {
ErrorExit(NO_REM_CONN, __local_name);
} else {
__realloc(keys);
}
}

/* Add additional entry for sender == keysize */
Expand Down

0 comments on commit a40bed1

Please sign in to comment.