From: Alan T. DeKok Date: Tue, 23 Jan 2024 14:19:40 +0000 (-0500) Subject: allow opening /dev/stdout and /dev/stderr X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19e47c3e45af358f5401504b321aa7cc560618d9;p=thirdparty%2Ffreeradius-server.git allow opening /dev/stdout and /dev/stderr --- diff --git a/src/lib/bio/fd.c b/src/lib/bio/fd.c index 03130772dac..563ae91fac9 100644 --- a/src/lib/bio/fd.c +++ b/src/lib/bio/fd.c @@ -722,7 +722,10 @@ static int fr_bio_fd_init_file(fr_bio_fd_t *my) my->info.read_blocked = false; my->info.write_blocked = false; - switch (my->info.cfg->flags) { + /* + * Other flags may be O_CREAT, etc. + */ + switch (my->info.cfg->flags & (O_RDONLY | O_WRONLY | O_RDWR)) { case O_RDONLY: my->bio.read = fr_bio_fd_read_stream; my->bio.write = fr_bio_null_write; /* @todo - error on write? */ diff --git a/src/lib/bio/fd_open.c b/src/lib/bio/fd_open.c index 2dc75d96757..a98c70a467e 100644 --- a/src/lib/bio/fd_open.c +++ b/src/lib/bio/fd_open.c @@ -775,7 +775,26 @@ int fr_bio_fd_open(fr_bio_t *bio, fr_bio_fd_config_t const *cfg) my->info.socket.type = SOCK_STREAM; my->info.socket.unix.path = cfg->filename; - fd = open(cfg->filename, cfg->flags); + /* + * Allow hacks for stdout and stderr + */ + if (strcmp(cfg->filename, "/dev/stdout") == 0) { + if (cfg->flags != O_WRONLY) { + fail_dev: + fr_strerror_printf("Cannot read from %s", cfg->filename); + return -1; + } + + fd = dup(STDOUT_FILENO); + + } else if (strcmp(cfg->filename, "/dev/stderr") == 0) { + if (cfg->flags != O_WRONLY) goto fail_dev; + + fd = dup(STDERR_FILENO); + + } else { + fd = open(cfg->filename, cfg->flags, cfg->perm); + } if (fd < 0) { fr_strerror_printf("Failed opening file %s: %s", cfg->filename, fr_syserror(errno)); return -1;