From a40bed18d380f57b6f276534b42b6e57d3582fa5 Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Mon, 7 Sep 2015 17:28:59 +0100 Subject: [PATCH] Don't consider empty client.keys to be a failure condition on servers 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. --- src/os_crypto/shared/keys.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/os_crypto/shared/keys.c b/src/os_crypto/shared/keys.c index f7995fc4f..319465c67 100644 --- a/src/os_crypto/shared/keys.c +++ b/src/os_crypto/shared/keys.c @@ -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) { @@ -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 */ @@ -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 */