]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
WARN if the permissions are different.
authorAlan T. DeKok <aland@freeradius.org>
Thu, 2 May 2019 17:00:31 +0000 (13:00 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 2 May 2019 17:00:31 +0000 (13:00 -0400)
But change them only if the permissions REMOVE the ones
we care about.

src/lib/server/exfile.c

index 796f7a6fb7aa22dbfee61abef8873180a1651187..d3b9acb6b0f98d1a7370aa5b1665bb11fa03781d 100644 (file)
@@ -472,15 +472,24 @@ try_lock:
         *      Sometimes the file permissions are changed externally.
         *      just be sure to update the permission if necessary.
         */
-       if ((st.st_mode & ~S_IFMT) != permissions) {
+       if ((st.st_mode & ~S_IFMT)  != permissions) {
                char str_need[10], oct_need[5];
+               char str_have[10], oct_have[5];
 
                rad_mode_to_oct(oct_need, permissions);
                rad_mode_to_str(str_need, permissions);
 
-               WARN("Correcting file %s permission to %s (%s)", filename, oct_need, str_need);
+               rad_mode_to_oct(oct_have, st.st_mode & ~S_IFMT);
+               rad_mode_to_str(str_have, st.st_mode & ~S_IFMT);
 
-               if (fchmod(ef->entries[i].fd, permissions) < 0) {
+               WARN("File %s permissions are %s (%s) not %s (%s))", filename,
+                    oct_have, str_have, oct_need, str_need);
+
+               if (((st.st_mode | permissions) != st.st_mode) &&
+                   (fchmod(ef->entries[i].fd, (st.st_mode & ~S_IFMT) | permissions) < 0)) {
+                       rad_mode_to_oct(oct_need, (st.st_mode & ~S_IFMT) | permissions);
+                       rad_mode_to_str(str_need, (st.st_mode & ~S_IFMT) | permissions);
+                       
                        WARN("Failed resetting file %s permissions to %s (%s): %s",
                             filename, oct_need, str_need, fr_syserror(errno));
                }