Changeset d2da61a in rtems


Ignore:
Timestamp:
Sep 11, 2013, 8:59:06 AM (6 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
2477a39
Parents:
b6657c39
git-author:
Sebastian Huber <sebastian.huber@…> (09/11/13 08:59:06)
git-committer:
Sebastian Huber <sebastian.huber@…> (09/12/13 13:31:23)
Message:

Filesystem: Change rtems_filesystem_chown()

Implement POSIX requirements in the high-level file system layer. Use
common implementation for all change owner variants.

Location:
cpukit/libcsupport
Files:
4 edited

Legend:

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

    rb6657c39 rd2da61a  
    573573
    574574int rtems_filesystem_chown(
    575   const char *path,
     575  const rtems_filesystem_location_info_t *loc,
    576576  uid_t owner,
    577   gid_t group,
    578   int eval_follow_link
     577  gid_t group
    579578);
    580579
  • cpukit/libcsupport/src/chown.c

    rb6657c39 rd2da61a  
    2626#include <rtems/libio_.h>
    2727
    28 int rtems_filesystem_chown(
    29   const char *path,
    30   uid_t owner,
    31   gid_t group,
    32   int eval_follow_link
    33 )
     28/**
     29 *  POSIX 1003.1b 5.6.5 - Change Owner and Group of a File
     30 */
     31int chown( const char *path, uid_t owner, gid_t group )
    3432{
    35   int rv = 0;
     33  int rv;
    3634  rtems_filesystem_eval_path_context_t ctx;
    37   int eval_flags = eval_follow_link;
     35  int eval_flags = RTEMS_FS_FOLLOW_LINK;
    3836  const rtems_filesystem_location_info_t *currentloc =
    3937    rtems_filesystem_eval_path_start( &ctx, path, eval_flags );
    40   const rtems_filesystem_operations_table *ops = currentloc->mt_entry->ops;
    4138
    42   rv = (*ops->chown_h)( currentloc, owner, group );
     39  rv = rtems_filesystem_chown( currentloc, owner, group );
    4340
    4441  rtems_filesystem_eval_path_cleanup( &ctx );
     
    4643  return rv;
    4744}
    48 
    49 /**
    50  *  POSIX 1003.1b 5.6.5 - Change Owner and Group of a File
    51  */
    52 int chown( const char *path, uid_t owner, gid_t group )
    53 {
    54   return rtems_filesystem_chown( path, owner, group, RTEMS_FS_FOLLOW_LINK );
    55 }
  • cpukit/libcsupport/src/fchown.c

    rb6657c39 rd2da61a  
    2323#include <rtems/libio_.h>
    2424
    25 /**
    26  *  POSIX 1003.1b 5.6.5 - Change Owner and Group of a File
    27  */
    28 int fchown( int fd, uid_t owner, gid_t group )
     25int rtems_filesystem_chown(
     26  const rtems_filesystem_location_info_t *loc,
     27  uid_t owner,
     28  gid_t group
     29)
    2930{
    30   int rv = 0;
    31   rtems_libio_t *iop;
     31  const rtems_filesystem_mount_table_entry_t *mt_entry = loc->mt_entry;
     32  int rv;
    3233
    33   rtems_libio_check_fd( fd );
    34   iop = rtems_libio_iop( fd );
    35   rtems_libio_check_is_open(iop);
     34  if ( mt_entry->writeable || rtems_filesystem_location_is_null( loc ) ) {
     35    struct stat st;
    3636
    37   if (iop->pathinfo.mt_entry->writeable) {
    38     rtems_filesystem_instance_lock( &iop->pathinfo );
    39     rv = (*iop->pathinfo.mt_entry->ops->chown_h)(
    40       &iop->pathinfo,
    41       owner,
    42       group
    43     );
    44     rtems_filesystem_instance_unlock( &iop->pathinfo );
     37    memset( &st, 0, sizeof(st) );
     38
     39    rv = (*loc->handlers->fstat_h)( loc, &st );
     40    if ( rv == 0 ) {
     41      uid_t uid = geteuid();
     42
     43      if ( uid == 0 || st.st_uid == uid ) {
     44        rv = (*mt_entry->ops->chown_h)( loc, owner, group );
     45      } else {
     46        errno = EPERM;
     47        rv = -1;
     48      }
     49    }
    4550  } else {
    4651    errno = EROFS;
     
    5055  return rv;
    5156}
     57
     58/**
     59 *  POSIX 1003.1b 5.6.5 - Change Owner and Group of a File
     60 */
     61int fchown( int fd, uid_t owner, gid_t group )
     62{
     63  int rv;
     64  rtems_libio_t *iop;
     65
     66  rtems_libio_check_fd( fd );
     67  iop = rtems_libio_iop( fd );
     68  rtems_libio_check_is_open(iop);
     69
     70  rtems_filesystem_instance_lock( &iop->pathinfo );
     71
     72  rv = rtems_filesystem_chown( &iop->pathinfo, owner, group );
     73
     74  rtems_filesystem_instance_unlock( &iop->pathinfo );
     75
     76  return rv;
     77}
  • cpukit/libcsupport/src/lchown.c

    rb6657c39 rd2da61a  
    2020int lchown( const char *path, uid_t owner, gid_t group )
    2121{
    22   return rtems_filesystem_chown(
    23     path,
    24     owner,
    25     group,
    26     RTEMS_FS_FOLLOW_HARD_LINK
    27   );
     22  int rv;
     23  rtems_filesystem_eval_path_context_t ctx;
     24  int eval_flags = RTEMS_FS_FOLLOW_HARD_LINK;
     25  const rtems_filesystem_location_info_t *currentloc =
     26    rtems_filesystem_eval_path_start( &ctx, path, eval_flags );
     27
     28  rv = rtems_filesystem_chown( currentloc, owner, group );
     29
     30  rtems_filesystem_eval_path_cleanup( &ctx );
     31
     32  return rv;
    2833}
Note: See TracChangeset for help on using the changeset viewer.