Changeset b6657c39 in rtems


Ignore:
Timestamp:
Sep 11, 2013, 8:34:02 AM (6 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
d2da61a
Parents:
3dbb68d
git-author:
Sebastian Huber <sebastian.huber@…> (09/11/13 08:34:02)
git-committer:
Sebastian Huber <sebastian.huber@…> (09/12/13 13:31:12)
Message:

Filesystem: Add and use rtems_filesystem_chmod()

Implement POSIX requirements in the high-level file system layer.

Location:
cpukit
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libcsupport/include/rtems/libio_.h

    r3dbb68d rb6657c39  
    567567int rtems_filesystem_chdir( rtems_filesystem_location_info_t *loc );
    568568
     569int rtems_filesystem_chmod(
     570  const rtems_filesystem_location_info_t *loc,
     571  mode_t mode
     572);
     573
    569574int rtems_filesystem_chown(
    570575  const char *path,
  • cpukit/libcsupport/src/chmod.c

    r3dbb68d rb6657c39  
    3434    rtems_filesystem_eval_path_start( &ctx, path, eval_flags );
    3535
    36   rv = (*currentloc->mt_entry->ops->fchmod_h)( currentloc, mode );
     36  rv = rtems_filesystem_chmod( currentloc, mode );
    3737
    3838  rtems_filesystem_eval_path_cleanup( &ctx );
  • cpukit/libcsupport/src/fchmod.c

    r3dbb68d rb6657c39  
    2323#include <rtems/libio_.h>
    2424
     25int rtems_filesystem_chmod(
     26  const rtems_filesystem_location_info_t *loc,
     27  mode_t mode
     28)
     29{
     30  const rtems_filesystem_mount_table_entry_t *mt_entry = loc->mt_entry;
     31  int rv;
     32
     33  if ( mt_entry->writeable || rtems_filesystem_location_is_null( loc ) ) {
     34    struct stat st;
     35
     36    memset( &st, 0, sizeof(st) );
     37
     38    rv = (*loc->handlers->fstat_h)( loc, &st );
     39    if ( rv == 0 ) {
     40      uid_t uid = geteuid();
     41
     42      if ( uid == 0 || st.st_uid == uid ) {
     43        mode_t mask = S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX;
     44
     45        mode = (st.st_mode & ~mask) | (mode & mask);
     46
     47        rv = (*mt_entry->ops->fchmod_h)( loc, mode );
     48      } else {
     49        errno = EPERM;
     50        rv = -1;
     51      }
     52    }
     53  } else {
     54    errno = EROFS;
     55    rv = -1;
     56  }
     57
     58  return rv;
     59}
     60
    2561/**
    2662 *  POSIX 1003.1b 5.6.4 - Change File Modes
     
    3571  rtems_libio_check_is_open(iop);
    3672
    37   if (iop->pathinfo.mt_entry->writeable) {
    38     rtems_filesystem_instance_lock( &iop->pathinfo );
    39     rv = (*iop->pathinfo.mt_entry->ops->fchmod_h)( &iop->pathinfo, mode );
    40     rtems_filesystem_instance_unlock( &iop->pathinfo );
    41   } else {
    42     errno = EROFS;
    43     rv = -1;
    44   }
     73  rtems_filesystem_instance_lock( &iop->pathinfo );
     74
     75  rv = rtems_filesystem_chmod( &iop->pathinfo, mode );
     76
     77  rtems_filesystem_instance_unlock( &iop->pathinfo );
    4578
    4679  return rv;
  • cpukit/libfs/src/imfs/imfs_fchmod.c

    r3dbb68d rb6657c39  
    2727{
    2828  IMFS_jnode_t  *jnode;
    29 #if defined(RTEMS_POSIX_API)
    30   uid_t          st_uid;
    31 #endif
    3229
    3330  jnode = loc->node_access;
    3431
    35   /*
    36    *  Verify I am the owner of the node or the super user.
    37    */
    38 #if defined(RTEMS_POSIX_API)
    39   st_uid = geteuid();
    40 
    41   if ( ( st_uid != jnode->st_uid ) && ( st_uid != 0 ) )
    42     rtems_set_errno_and_return_minus_one( EPERM );
    43 #endif
    44 
    45   /*
    46    * Change only the RWX permissions on the jnode to mode.
    47    */
    48 
    49   jnode->st_mode &= ~(S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX);
    50   jnode->st_mode |= mode & (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX);
     32  jnode->st_mode = mode;
    5133
    5234  IMFS_update_ctime( jnode );
  • cpukit/libfs/src/rfs/rtems-rfs-rtems.c

    r3dbb68d rb6657c39  
    469469  rtems_rfs_ino           ino = rtems_rfs_rtems_get_pathloc_ino (pathloc);
    470470  rtems_rfs_inode_handle  inode;
    471   uint16_t                imode;
    472 #if defined (RTEMS_POSIX_API)
    473   uid_t                   uid;
    474 #endif
    475471  int                     rc;
    476472
     
    485481  }
    486482
    487   imode = rtems_rfs_inode_get_mode (&inode);
    488 
    489   /*
    490    *  Verify I am the owner of the node or the super user.
    491    */
    492 #if defined (RTEMS_POSIX_API)
    493   uid = geteuid();
    494 
    495   if ((uid != rtems_rfs_inode_get_uid (&inode)) && (uid != 0))
    496   {
    497     rtems_rfs_inode_close (fs, &inode);
    498     return rtems_rfs_rtems_error ("fchmod: checking uid", EPERM);
    499   }
    500 #endif
    501 
    502   imode &= ~(S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX);
    503   imode |= mode & (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX);
    504 
    505   rtems_rfs_inode_set_mode (&inode, imode);
     483  rtems_rfs_inode_set_mode (&inode, mode);
    506484
    507485  rc = rtems_rfs_inode_close (fs, &inode);
Note: See TracChangeset for help on using the changeset viewer.