From: ethan-thompson Date: Mon, 15 Dec 2025 15:47:05 +0000 (+0000) Subject: feat: Added the `flags` parameter to allow for flags to be passed to open(2). X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d7206c6901a20e04de4d25f3abb3207bb0ca9d75;p=thirdparty%2Ffreeradius-server.git feat: Added the `flags` parameter to allow for flags to be passed to open(2). Signed-off-by: ethan-thompson --- diff --git a/src/lib/server/exfile.c b/src/lib/server/exfile.c index ca012f3b335..f0bb77f025e 100644 --- a/src/lib/server/exfile.c +++ b/src/lib/server/exfile.c @@ -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); } /* diff --git a/src/lib/server/exfile.h b/src/lib/server/exfile.h index 1fe9b15623b..cb95afbe101 100644 --- a/src/lib/server/exfile.h +++ b/src/lib/server/exfile.h @@ -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); diff --git a/src/modules/rlm_detail/rlm_detail.c b/src/modules/rlm_detail/rlm_detail.c index c9507c96d10..5b310404347 100644 --- a/src/modules/rlm_detail/rlm_detail.c +++ b/src/modules/rlm_detail/rlm_detail.c @@ -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); diff --git a/src/modules/rlm_linelog/rlm_linelog.c b/src/modules/rlm_linelog/rlm_linelog.c index f6ca556e950..c4ff89cfba3 100644 --- a/src/modules/rlm_linelog/rlm_linelog.c +++ b/src/modules/rlm_linelog/rlm_linelog.c @@ -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)); diff --git a/src/modules/rlm_sql/sql.c b/src/modules/rlm_sql/sql.c index 9e893333697..049e55d45bb 100644 --- a/src/modules/rlm_sql/sql.c +++ b/src/modules/rlm_sql/sql.c @@ -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));