]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Revert "Unecessary fileno(), just do as cf_file_input()"
authorAlan T. DeKok <aland@freeradius.org>
Thu, 25 Jun 2015 15:28:37 +0000 (11:28 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 26 Jun 2015 01:38:07 +0000 (21:38 -0400)
This reverts commit 44fc841929934a55f690422ee1d25c3190c5c900.

stat() is not the same as fstat().  The first one checks a
file which has the same name as the one we opened.  The second
checks the file which we just opened.

The cf_file_input() checks just check if the filename for
security (globally writeable, etc.).  cf_file_open() will
open the file and read it's contents

src/main/conffile.c

index 235c456f8785c02c4e254080fd5070d3e95af59d..95d6bddc19bb87ca5092eb386b9b8b8e155c60e3 100644 (file)
@@ -305,6 +305,7 @@ static FILE *cf_file_open(CONF_SECTION *cs, char const *filename)
        CONF_DATA *cd;
        CONF_SECTION *top;
        rbtree_t *tree;
+       int fd;
        FILE *fp;
 
        top = cf_top_section(cs);
@@ -320,6 +321,8 @@ static FILE *cf_file_open(CONF_SECTION *cs, char const *filename)
                return NULL;
        }
 
+       fd = fileno(fp);
+
        file = talloc(tree, cf_file_t);
        if (!file) {
                fclose(fp);
@@ -330,7 +333,7 @@ static FILE *cf_file_open(CONF_SECTION *cs, char const *filename)
        file->cs = cs;
        file->input = true;
 
-       if (stat(filename, &file->buf) < 0) {
+       if (fstat(fd, &file->buf) == 0) {
 #ifdef S_IWOTH
                if ((file->buf.st_mode & S_IWOTH) != 0) {
                        ERROR("Configuration file %s is globally writable.  "
@@ -372,6 +375,7 @@ static bool cf_file_input(CONF_SECTION *cs, char const *filename)
        if (!cd) return false;
 
        tree = cd->data;
+
        file = talloc(tree, cf_file_t);
        if (!file) return false;