Skip to content

Commit 041cf01

Browse files
committed
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.
1 parent 866b65e commit 041cf01

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

src/os_auth/main-client.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,7 @@ int main(int argc, char **argv)
343343
FILE *fp;
344344
fp = fopen(KEYSFILE_PATH, "w");
345345
if (!fp) {
346-
printf("ERROR: Unable to open key file: %s", KEYSFILE_PATH);
347-
exit(1);
346+
ErrorExit(FOPEN_ERROR, ARGV0, KEYSFILE_PATH, errno, strerror(errno));
348347
}
349348
fprintf(fp, "%s\n", key);
350349
fclose(fp);

src/os_auth/main-server.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,7 @@ int main(int argc, char **argv)
306306

307307
fp = fopen(KEYSFILE_PATH, "a");
308308
if (!fp) {
309-
merror("%s: ERROR: Unable to open %s (key file)", ARGV0, KEYSFILE_PATH);
310-
exit(1);
309+
ErrorExit(FOPEN_ERROR, ARGV0, KEYSFILE_PATH, errno, strerror(errno));
311310
}
312311
fclose(fp);
313312

src/os_crypto/shared/keys.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,21 @@
1313
#include "os_crypto/blowfish/bf_op.h"
1414

1515
/* Prototypes */
16+
static void __realloc_keys(keystore *keys) __attribute((nonnull));
1617
static void __memclear(char *id, char *name, char *ip, char *key, size_t size) __attribute((nonnull));
1718
static void __chash(keystore *keys, const char *id, const char *name, char *ip, const char *key) __attribute((nonnull));
1819

1920

21+
static void __realloc_keys(keystore *keys)
22+
{
23+
/* Allocate for the whole structure */
24+
keys->keyentries = (keyentry **)realloc(keys->keyentries,
25+
(keys->keysize + 2) * sizeof(keyentry *));
26+
if (!keys->keyentries) {
27+
ErrorExit(MEM_ERROR, __local_name, errno, strerror(errno));
28+
}
29+
}
30+
2031
/* Clear keys entries */
2132
static void __memclear(char *id, char *name, char *ip, char *key, size_t size)
2233
{
@@ -35,12 +46,7 @@ static void __chash(keystore *keys, const char *id, const char *name, char *ip,
3546
char *tmp_str;
3647
char _finalstr[KEYSIZE];
3748

38-
/* Allocate for the whole structure */
39-
keys->keyentries = (keyentry **)realloc(keys->keyentries,
40-
(keys->keysize + 2) * sizeof(keyentry *));
41-
if (!keys->keyentries) {
42-
ErrorExit(MEM_ERROR, __local_name, errno, strerror(errno));
43-
}
49+
__realloc_keys(keys);
4450
os_calloc(1, sizeof(keyentry), keys->keyentries[keys->keysize]);
4551

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

253-
/* Check if there are any agents available */
259+
/* Check if there are any keys available, except on remoted
260+
* because more keys could be added later */
254261
if (keys->keysize == 0) {
255-
ErrorExit(NO_REM_CONN, __local_name);
262+
if (strcmp(__local_name, "ossec-remoted") != 0) {
263+
ErrorExit(NO_REM_CONN, __local_name);
264+
} else {
265+
__realloc_keys(keys);
266+
}
256267
}
257268

258269
/* Add additional entry for sender == keysize */

src/remoted/main.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ static void help_remoted()
3636

3737
int main(int argc, char **argv)
3838
{
39+
FILE *fp;
3940
int i = 0, c = 0;
4041
uid_t uid;
4142
gid_t gid;
@@ -127,6 +128,13 @@ int main(int argc, char **argv)
127128
exit(0);
128129
}
129130

131+
/* Touch client.keys */
132+
fp = fopen(KEYSFILE_PATH, "a");
133+
if (!fp) {
134+
ErrorExit(FOPEN_ERROR, ARGV0, KEYSFILE_PATH, errno, strerror(errno));
135+
}
136+
fclose(fp);
137+
130138
/* Check if the user and group given are valid */
131139
uid = Privsep_GetUser(user);
132140
gid = Privsep_GetGroup(group);

0 commit comments

Comments
 (0)