Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/os_auth/main-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,7 @@ int main(int argc, char **argv)
FILE *fp;
fp = fopen(KEYSFILE_PATH, "w");
if (!fp) {
printf("ERROR: Unable to open key file: %s", KEYSFILE_PATH);
exit(1);
ErrorExit(FOPEN_ERROR, ARGV0, KEYSFILE_PATH, errno, strerror(errno));
}
fprintf(fp, "%s\n", key);
fclose(fp);
Expand Down
3 changes: 1 addition & 2 deletions src/os_auth/main-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,7 @@ int main(int argc, char **argv)

fp = fopen(KEYSFILE_PATH, "a");
if (!fp) {
merror("%s: ERROR: Unable to open %s (key file)", ARGV0, KEYSFILE_PATH);
exit(1);
ErrorExit(FOPEN_ERROR, ARGV0, KEYSFILE_PATH, errno, strerror(errno));
}
fclose(fp);

Expand Down
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_keys(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_keys(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(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(keys);
}
}

/* Add additional entry for sender == keysize */
Expand Down
8 changes: 8 additions & 0 deletions src/remoted/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ static void help_remoted()

int main(int argc, char **argv)
{
FILE *fp;
int i = 0, c = 0;
uid_t uid;
gid_t gid;
Expand Down Expand Up @@ -127,6 +128,13 @@ int main(int argc, char **argv)
exit(0);
}

/* Touch client.keys */
fp = fopen(KEYSFILE_PATH, "a");
if (!fp) {
ErrorExit(FOPEN_ERROR, ARGV0, KEYSFILE_PATH, errno, strerror(errno));
}
fclose(fp);

/* Check if the user and group given are valid */
uid = Privsep_GetUser(user);
gid = Privsep_GetGroup(group);
Expand Down