]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
fix: Use the more optimized openat method to open a directory since we already can... master
authorEthan Thompson <77711716+ethan-thompson@users.noreply.github.com>
Fri, 6 Feb 2026 01:30:37 +0000 (20:30 -0500)
committerGitHub <noreply@github.com>
Fri, 6 Feb 2026 01:30:37 +0000 (17:30 -0800)
Signed-off-by: ethan-thompson <ethan.thompson@networkradius.com>
src/lib/server/exfile.c

index 1d3826b5ddb6bce9d37eb1ccb66d05e26bff8dc8..63f77cc40e390ffe341a398b0d41692fb23c4993 100644 (file)
@@ -241,6 +241,7 @@ static int exfile_open_mkdir(exfile_t *ef, char const *filename, mode_t permissi
 
        fd = open(filename, O_RDWR | O_CREAT | flags, permissions);
        if (fd < 0) {
+               int dirfd;
                mode_t dirperm;
                char *p, *dir;
 
@@ -267,14 +268,15 @@ static int exfile_open_mkdir(exfile_t *ef, char const *filename, mode_t permissi
                if ((dirperm & 0060) != 0) dirperm |= 0010;
                if ((dirperm & 0006) != 0) dirperm |= 0001;
 
-               if (fr_mkdir(NULL, dir, -1, dirperm, NULL, NULL) < 0) {
+               if (fr_mkdir(&dirfd, dir, -1, dirperm, NULL, NULL) < 0) {
                        fr_strerror_printf("Failed to create directory %s: %s", dir, fr_syserror(errno));
                        talloc_free(dir);
                        return -1;
                }
                talloc_free(dir);
 
-               fd = open(filename, O_RDWR | O_CREAT | flags, permissions);
+               fd = openat(dirfd, p+1, O_RDWR | O_CREAT | flags, permissions);
+               close(dirfd);
                if (fd < 0) {
                        fr_strerror_printf("Failed to open file %s: %s", filename, fr_syserror(errno));
                        return -1;