diff options
Diffstat (limited to 'cpukit/libcsupport/src')
-rw-r--r-- | cpukit/libcsupport/src/fchmod.c | 11 | ||||
-rw-r--r-- | cpukit/libcsupport/src/fchown.c | 13 | ||||
-rw-r--r-- | cpukit/libcsupport/src/sup_fs_eval_path.c | 42 |
3 files changed, 40 insertions, 26 deletions
diff --git a/cpukit/libcsupport/src/fchmod.c b/cpukit/libcsupport/src/fchmod.c index e651066a77..14fb416f68 100644 --- a/cpukit/libcsupport/src/fchmod.c +++ b/cpukit/libcsupport/src/fchmod.c @@ -28,9 +28,14 @@ int fchmod( int fd, mode_t mode ) iop = rtems_libio_iop( fd ); rtems_libio_check_is_open(iop); - rtems_filesystem_instance_lock( &iop->pathinfo ); - rv = (*iop->pathinfo.ops->fchmod_h)( &iop->pathinfo, mode ); - rtems_filesystem_instance_unlock( &iop->pathinfo ); + if (iop->pathinfo.mt_entry->writeable) { + rtems_filesystem_instance_lock( &iop->pathinfo ); + rv = (*iop->pathinfo.ops->fchmod_h)( &iop->pathinfo, mode ); + rtems_filesystem_instance_unlock( &iop->pathinfo ); + } else { + errno = EROFS; + rv = -1; + } return rv; } diff --git a/cpukit/libcsupport/src/fchown.c b/cpukit/libcsupport/src/fchown.c index b5891bf36d..d0d04005d8 100644 --- a/cpukit/libcsupport/src/fchown.c +++ b/cpukit/libcsupport/src/fchown.c @@ -28,11 +28,14 @@ int fchown( int fd, uid_t owner, gid_t group ) iop = rtems_libio_iop( fd ); rtems_libio_check_is_open(iop); - rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); - - rtems_filesystem_instance_lock( &iop->pathinfo ); - rv = (*iop->pathinfo.ops->chown_h)( &iop->pathinfo, owner, group ); - rtems_filesystem_instance_unlock( &iop->pathinfo ); + if (iop->pathinfo.mt_entry->writeable) { + rtems_filesystem_instance_lock( &iop->pathinfo ); + rv = (*iop->pathinfo.ops->chown_h)( &iop->pathinfo, owner, group ); + rtems_filesystem_instance_unlock( &iop->pathinfo ); + } else { + errno = EROFS; + rv = -1; + } return rv; } diff --git a/cpukit/libcsupport/src/sup_fs_eval_path.c b/cpukit/libcsupport/src/sup_fs_eval_path.c index 1940cce745..c827ba72f8 100644 --- a/cpukit/libcsupport/src/sup_fs_eval_path.c +++ b/cpukit/libcsupport/src/sup_fs_eval_path.c @@ -68,26 +68,32 @@ static void check_access( ) { const rtems_filesystem_location_info_t *currentloc = &ctx->currentloc; - struct stat st; - int rv; - - st.st_mode = 0; - st.st_uid = 0; - st.st_gid = 0; - rv = (*currentloc->handlers->fstat_h)(currentloc, &st); - if (rv == 0) { - bool access_ok = rtems_filesystem_check_access( - eval_flags, - st.st_mode, - st.st_uid, - st.st_gid - ); - - if (!access_ok) { - rtems_filesystem_eval_path_error(ctx, EACCES); + const rtems_filesystem_mount_table_entry_t *mt_entry = currentloc->mt_entry; + + if ((eval_flags & RTEMS_LIBIO_PERMS_WRITE) == 0 || mt_entry->writeable) { + struct stat st; + int rv; + + st.st_mode = 0; + st.st_uid = 0; + st.st_gid = 0; + rv = (*currentloc->handlers->fstat_h)(currentloc, &st); + if (rv == 0) { + bool access_ok = rtems_filesystem_check_access( + eval_flags, + st.st_mode, + st.st_uid, + st.st_gid + ); + + if (!access_ok) { + rtems_filesystem_eval_path_error(ctx, EACCES); + } + } else { + rtems_filesystem_eval_path_error(ctx, 0); } } else { - rtems_filesystem_eval_path_error(ctx, 0); + rtems_filesystem_eval_path_error(ctx, EROFS); } } |