summaryrefslogtreecommitdiffstats
path: root/cpukit/libcsupport/src/fchown.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2013-09-11 10:59:06 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2013-09-12 15:31:23 +0200
commitd2da61aa0cf73dadc31eb3fd4202c04faf0e7653 (patch)
tree65156db0a2ec463e6a7f2752e3e7c8463f2bc35b /cpukit/libcsupport/src/fchown.c
parentFilesystem: Add and use rtems_filesystem_chmod() (diff)
downloadrtems-d2da61aa0cf73dadc31eb3fd4202c04faf0e7653.tar.bz2
Filesystem: Change rtems_filesystem_chown()
Implement POSIX requirements in the high-level file system layer. Use common implementation for all change owner variants.
Diffstat (limited to 'cpukit/libcsupport/src/fchown.c')
-rw-r--r--cpukit/libcsupport/src/fchown.c52
1 files changed, 39 insertions, 13 deletions
diff --git a/cpukit/libcsupport/src/fchown.c b/cpukit/libcsupport/src/fchown.c
index ec84fe4f47..2e741592da 100644
--- a/cpukit/libcsupport/src/fchown.c
+++ b/cpukit/libcsupport/src/fchown.c
@@ -22,30 +22,56 @@
#include <rtems/libio_.h>
+int rtems_filesystem_chown(
+ const rtems_filesystem_location_info_t *loc,
+ uid_t owner,
+ gid_t group
+)
+{
+ const rtems_filesystem_mount_table_entry_t *mt_entry = loc->mt_entry;
+ int rv;
+
+ if ( mt_entry->writeable || rtems_filesystem_location_is_null( loc ) ) {
+ struct stat st;
+
+ memset( &st, 0, sizeof(st) );
+
+ rv = (*loc->handlers->fstat_h)( loc, &st );
+ if ( rv == 0 ) {
+ uid_t uid = geteuid();
+
+ if ( uid == 0 || st.st_uid == uid ) {
+ rv = (*mt_entry->ops->chown_h)( loc, owner, group );
+ } else {
+ errno = EPERM;
+ rv = -1;
+ }
+ }
+ } else {
+ errno = EROFS;
+ rv = -1;
+ }
+
+ return rv;
+}
+
/**
* POSIX 1003.1b 5.6.5 - Change Owner and Group of a File
*/
int fchown( int fd, uid_t owner, gid_t group )
{
- int rv = 0;
+ int rv;
rtems_libio_t *iop;
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
rtems_libio_check_is_open(iop);
- if (iop->pathinfo.mt_entry->writeable) {
- rtems_filesystem_instance_lock( &iop->pathinfo );
- rv = (*iop->pathinfo.mt_entry->ops->chown_h)(
- &iop->pathinfo,
- owner,
- group
- );
- rtems_filesystem_instance_unlock( &iop->pathinfo );
- } else {
- errno = EROFS;
- rv = -1;
- }
+ rtems_filesystem_instance_lock( &iop->pathinfo );
+
+ rv = rtems_filesystem_chown( &iop->pathinfo, owner, group );
+
+ rtems_filesystem_instance_unlock( &iop->pathinfo );
return rv;
}