Skip to content

Commit 11880da

Browse files
committed
Read allowed change paths from stdin
1 parent 4b63d91 commit 11880da

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/headers/defs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#define OS_FLSIZE OS_SIZE_256 /* Maximum file size */
3333
#define OS_HEADER_SIZE OS_SIZE_128 /* Maximum header size */
3434
#define OS_LOG_HEADER OS_SIZE_256 /* Maximum log header size */
35+
#define OS_MAXPATH OS_SIZE_1024 /* Maximum filepath length */
3536
#define IPSIZE INET6_ADDRSTRLEN /* IP Address size */
3637

3738
/* Some global names */

src/syscheckd/syscheck.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static void read_internal(int debug_level)
7171
*/
7272
static int allowChange(char* filename, time_t timestamp)
7373
{
74-
char msg[1024*2];
74+
char msg[OS_MAXPATH*2];
7575
sprintf(msg, "%ld %s", timestamp, filename);
7676
if ((syscheck.queue = StartMQ(DEFAULTQPATH, WRITE)) < 0) {
7777
ErrorExit(QUEUE_FATAL, ARGV0, DEFAULTQPATH);
@@ -208,11 +208,12 @@ int main(int argc, char **argv)
208208
int test_config = 0, run_foreground = 0;
209209
int allow_change = 0;
210210
const char *cfg = DEFAULTCPATH;
211-
char *allow_filename = NULL;
211+
char allow_filename[OS_MAXPATH];
212212
time_t allow_timestamp = 0;
213213

214214
/* Set the name */
215215
OS_SetName(ARGV0);
216+
*allow_filename = '\0';
216217

217218
while ((c = getopt(argc, argv, "Vtdhfc:a:u:")) != -1) {
218219
switch (c) {
@@ -239,7 +240,7 @@ int main(int argc, char **argv)
239240
if (!optarg) {
240241
ErrorExit("%s: -a needs a filename", ARGV0);
241242
}
242-
allow_filename = optarg;
243+
strncpy(allow_filename, optarg, OS_MAXPATH);
243244
allow_change = 1;
244245
break;
245246
case 'u':
@@ -290,12 +291,22 @@ int main(int argc, char **argv)
290291

291292

292293
if (allow_change){
293-
if (allow_filename && allow_timestamp != 0) {
294-
allowChange(allow_filename, allow_timestamp);
295-
exit(0);
296-
} else {
297-
merror("%s: WARN: Missing parameter for allow change", ARGV0);
294+
if (allow_timestamp == 0){
295+
merror("%s: WARN: Missing timestamp for allow change", ARGV0);
298296
exit(1);
297+
} else if (*allow_filename != '\0') {
298+
allowChange(allow_filename, allow_timestamp);
299+
exit(0);
300+
} else {
301+
debug1("%s: Reading filenames from stdin, one path per line", ARGV0);
302+
while (fgets(allow_filename, OS_MAXPATH, stdin)) {
303+
/* Remove the newline character */
304+
if (allow_filename[strlen(allow_filename) - 1] == '\n') {
305+
allow_filename[strlen(allow_filename) - 1] = '\0';
306+
}
307+
allowChange(allow_filename, allow_timestamp);
308+
}
309+
exit(0);
299310
}
300311
}
301312

0 commit comments

Comments
 (0)