Support O_NOFOLLOW open() flag

Close #3546.
This commit is contained in:
Sebastian Huber
2018-10-22 08:06:05 +02:00
parent 3825926601
commit 1ad26cdcf7
2 changed files with 73 additions and 1 deletions
+6 -1
View File
@@ -74,7 +74,12 @@ static int do_open(
bool exclusive = (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL);
bool truncate = (oflag & O_TRUNC) == O_TRUNC;
bool open_dir;
int eval_flags = RTEMS_FS_FOLLOW_LINK
#ifdef O_NOFOLLOW
int follow = (oflag & O_NOFOLLOW) == O_NOFOLLOW ? 0 : RTEMS_FS_FOLLOW_LINK;
#else
int follow = RTEMS_FS_FOLLOW_LINK;
#endif
int eval_flags = follow
| (read_access ? RTEMS_FS_PERMS_READ : 0)
| (write_access ? RTEMS_FS_PERMS_WRITE : 0)
| (make ? RTEMS_FS_MAKE : 0)
+67
View File
@@ -59,6 +59,8 @@ rtems_filesystem_operations_table IMFS_ops_no_rename;
static const char somefile[] = "somefile";
static const char somelink[] = "somelink";
/*
* File test support routines.
*/
@@ -152,6 +154,11 @@ static void test_open_directory(void)
status = unlink( somefile );
rtems_test_assert( status == 0 );
errno = 0;
fd = open( somefile, O_RDONLY );
rtems_test_assert( fd == -1 );
rtems_test_assert( errno == ENOENT );
}
static void test_open_cloexec(void)
@@ -174,6 +181,65 @@ static void test_open_cloexec(void)
status = unlink( somefile );
rtems_test_assert( status == 0 );
errno = 0;
fd = open( somefile, O_RDONLY );
rtems_test_assert( fd == -1 );
rtems_test_assert( errno == ENOENT );
}
static void test_open_nofollow(void)
{
int status;
int fd;
struct stat st;
fd = open( somefile, O_CREAT, S_IRWXU );
rtems_test_assert( fd >= 0 );
status = close( fd );
rtems_test_assert( status == 0 );
status = symlink( somefile, somelink );
rtems_test_assert( status == 0 );
fd = open( somelink, O_RDONLY );
rtems_test_assert( fd >= 0 );
status = fstat( fd, &st );
rtems_test_assert( status == 0 );
rtems_test_assert( S_ISREG( st.st_mode ) );
status = close( fd );
rtems_test_assert( status == 0 );
#ifdef O_NOFOLLOW
fd = open( somelink, O_RDONLY | O_NOFOLLOW );
rtems_test_assert( fd >= 0 );
status = fstat( fd, &st );
rtems_test_assert( status == 0 );
rtems_test_assert( S_ISLNK( st.st_mode ) );
status = close( fd );
rtems_test_assert( status == 0 );
#endif
status = unlink( somelink );
rtems_test_assert( status == 0 );
errno = 0;
fd = open( somelink, O_RDONLY );
rtems_test_assert( fd == -1 );
rtems_test_assert( errno == ENOENT );
status = unlink( somefile );
rtems_test_assert( status == 0 );
errno = 0;
fd = open( somefile, O_RDONLY );
rtems_test_assert( fd == -1 );
rtems_test_assert( errno == ENOENT );
}
/*
@@ -209,6 +275,7 @@ int main(
test_open_directory();
test_open_cloexec();
test_open_nofollow();
/*
* Grab the maximum size of an in-memory file.