]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
allow opening /dev/stdout and /dev/stderr
authorAlan T. DeKok <aland@freeradius.org>
Tue, 23 Jan 2024 14:19:40 +0000 (09:19 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 23 Jan 2024 14:19:40 +0000 (09:19 -0500)
src/lib/bio/fd.c
src/lib/bio/fd_open.c

index 03130772dac67606d11058ffe3b5d6fe22111a1d..563ae91fac956d4d8df75b0e167a9388ea6c5049 100644 (file)
@@ -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? */
index 2dc75d967579ab80cc5f7174960def00e4388665..a98c70a467e4e78058d08cab7488c169e3d6abee 100644 (file)
@@ -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;