]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
feat: Added the `flags` parameter to allow for flags to be passed to open(2).
authorethan-thompson <ethan.thompson@networkradius.com>
Mon, 15 Dec 2025 15:47:05 +0000 (15:47 +0000)
committerAlan DeKok <aland@freeradius.org>
Mon, 15 Dec 2025 15:56:12 +0000 (10:56 -0500)
Signed-off-by: ethan-thompson <ethan.thompson@networkradius.com>
src/lib/server/exfile.c
src/lib/server/exfile.h
src/modules/rlm_detail/rlm_detail.c
src/modules/rlm_linelog/rlm_linelog.c
src/modules/rlm_sql/sql.c

index ca012f3b335ff7e5bd9171d00e5d71b89ad10bf5..f0bb77f025e53a0cc0dcd0ce25a12f3fe946730f 100644 (file)
@@ -232,11 +232,11 @@ void exfile_enable_triggers(exfile_t *ef, CONF_SECTION *conf, char const *trigge
  *     Try to open the file. It it doesn't exist, try to
  *     create it's parent directories.
  */
-static int exfile_open_mkdir(exfile_t *ef, char const *filename, mode_t permissions)
+static int exfile_open_mkdir(exfile_t *ef, char const *filename, mode_t permissions, int flags)
 {
        int fd;
 
-       fd = open(filename, O_RDWR | O_CREAT, permissions);
+       fd = open(filename, O_RDWR | O_CREAT | flags, permissions);
        if (fd < 0) {
                mode_t dirperm;
                char *p, *dir;
@@ -271,7 +271,7 @@ static int exfile_open_mkdir(exfile_t *ef, char const *filename, mode_t permissi
                }
                talloc_free(dir);
 
-               fd = open(filename, O_RDWR | O_CREAT, permissions);
+               fd = open(filename, O_RDWR | O_CREAT | flags, permissions);
                if (fd < 0) {
                        fr_strerror_printf("Failed to open file %s: %s", filename, fr_syserror(errno));
                        return -1;
@@ -286,7 +286,7 @@ static int exfile_open_mkdir(exfile_t *ef, char const *filename, mode_t permissi
  * to influence whether and which __coverity*__() functions are called. We therefore create a
  * separate function for the locking case which we *can* model.
  */
-static int exfile_open_lock(exfile_t *ef, char const *filename, mode_t permissions, off_t *offset)
+static int exfile_open_lock(exfile_t *ef, char const *filename, mode_t permissions, int flags, off_t *offset)
 {
        int i, tries, unused = -1, found = -1, oldest = -1;
        bool do_cleanup = false;
@@ -399,7 +399,7 @@ static int exfile_open_lock(exfile_t *ef, char const *filename, mode_t permissio
        ef->entries[i].fd = -1;
 
 reopen:
-       ef->entries[i].fd = exfile_open_mkdir(ef, filename, permissions);
+       ef->entries[i].fd = exfile_open_mkdir(ef, filename, permissions, flags);
        if (ef->entries[i].fd < 0) goto error;
 
        exfile_trigger(ef, &ef->entries[i], EXFILE_TRIGGER_OPEN);
@@ -432,7 +432,7 @@ try_lock:
                }
 
                close(ef->entries[i].fd);
-               ef->entries[i].fd = open(filename, O_RDWR | O_CREAT, permissions);
+               ef->entries[i].fd = open(filename, O_RDWR | O_CREAT | flags, permissions);
                if (ef->entries[i].fd < 0) {
                        fr_strerror_printf("Failed to open file %s: %s", filename, fr_syserror(errno));
                        goto error;
@@ -518,17 +518,18 @@ try_lock:
  * @param ef The logfile context returned from exfile_init().
  * @param filename the file to open.
  * @param permissions to use.
+ * @param flags flags to pass to open.
  * @param offset Optional pointer to store offset in when seeking the end of file.
  * @return
  *     - FD used to write to the file.
  *     - -1 on failure.
  */
-int exfile_open(exfile_t *ef, char const *filename, mode_t permissions, off_t *offset)
+int exfile_open(exfile_t *ef, char const *filename, mode_t permissions, int flags, off_t *offset)
 {
        if (!ef || !filename) return -1;
 
        if (!ef->locking) {
-               int found = exfile_open_mkdir(ef, filename, permissions);
+               int found = exfile_open_mkdir(ef, filename, permissions, flags);
                off_t real_offset;
 
                if (found < 0) return -1;
@@ -537,7 +538,7 @@ int exfile_open(exfile_t *ef, char const *filename, mode_t permissions, off_t *o
                return found;
        }
 
-       return exfile_open_lock(ef, filename, permissions, offset);
+       return exfile_open_lock(ef, filename, permissions, flags, offset);
 }
 
 /*
index 1fe9b15623b3a66ac71fd6a70c66337a4ee1b2de..cb95afbe101de7fb4c2a157ff2783ae1fe0f2185 100644 (file)
@@ -41,7 +41,7 @@ void          exfile_enable_triggers(exfile_t *ef, CONF_SECTION *cs, char const *trigger
                                       fr_pair_list_t *trigger_args);
 
 CC_ACQUIRE_HANDLE("exfile_fd")
-int            exfile_open(exfile_t *lf, char const *filename, mode_t permissions, off_t *offset);
+int            exfile_open(exfile_t *lf, char const *filename, mode_t permissions, int flags, off_t *offset);
 
 int            exfile_close(exfile_t *lf, CC_RELEASE_HANDLE("exfile_fd") int fd);
 
index c9507c96d10de4e59721783cdc692b86d836e4ca..5b310404347e1e92258345529d2007e4e2de5f6d 100644 (file)
@@ -319,7 +319,7 @@ static unlang_action_t CC_HINT(nonnull) detail_do(unlang_result_t *p_result, mod
 
        RDEBUG2("%s expands to %pV", env->filename_tmpl->name, &env->filename);
 
-       outfd = exfile_open(inst->ef, env->filename.vb_strvalue, inst->perm, NULL);
+       outfd = exfile_open(inst->ef, env->filename.vb_strvalue, inst->perm, 0, NULL);
        if (outfd < 0) {
                RPERROR("Couldn't open file %pV", &env->filename);
 
index f6ca556e9504f32f1a93efd70653a08cb91cb199..c4ff89cfba38e032c1bf59d8c3303332c9049c0f 100644 (file)
@@ -405,7 +405,7 @@ static int linelog_write(rlm_linelog_t const *inst, linelog_call_env_t const *ca
                        *p = '/';
                }
 
-               fd = exfile_open(inst->file.ef, path, inst->file.permissions, &offset);
+               fd = exfile_open(inst->file.ef, path, inst->file.permissions, 0, &offset);
                if (fd < 0) {
                        RERROR("Failed to open %pV: %s", call_env->filename, fr_syserror(errno));
 
index 9e893333697a4deca1f16dde0028a4d6caec3d5c..049e55d45bbbf2dd0f885f10c69bd4c907747160 100644 (file)
@@ -389,7 +389,7 @@ void rlm_sql_query_log(rlm_sql_t const *inst, char const *filename, char const *
        size_t len;
        bool failed = false;    /* Write the log message outside of the critical region */
 
-       fd = exfile_open(inst->ef, filename, 0640, NULL);
+       fd = exfile_open(inst->ef, filename, 0640, 0, NULL);
        if (fd < 0) {
                ERROR("Couldn't open logfile '%s': %s", filename, fr_syserror(errno));