source: rtems/cpukit/libcsupport/src/fchown.c @ baef823c

5
Last change on this file since baef823c was baef823c, checked in by Sebastian Huber <sebastian.huber@…>, on 09/13/17 at 07:22:19

libio: Add hold/drop iop reference

Check iop reference count in close() and return -1 with errno set to
EBUSY in case the file descriptor is still in use.

Update #3132.

  • Property mode set to 100644
File size: 1.5 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief Change Owner and Group of a File
5 *  @ingroup libcsupport
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-1999.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18  #include "config.h"
19#endif
20
21#include <string.h>
22#include <unistd.h>
23
24#include <rtems/libio_.h>
25
26int rtems_filesystem_chown(
27  const rtems_filesystem_location_info_t *loc,
28  uid_t owner,
29  gid_t group
30)
31{
32  const rtems_filesystem_mount_table_entry_t *mt_entry = loc->mt_entry;
33  int rv;
34
35  if ( mt_entry->writeable || rtems_filesystem_location_is_null( loc ) ) {
36    struct stat st;
37
38    memset( &st, 0, sizeof(st) );
39
40    rv = (*loc->handlers->fstat_h)( loc, &st );
41    if ( rv == 0 ) {
42      uid_t uid = geteuid();
43
44      if ( uid == 0 || st.st_uid == uid ) {
45        rv = (*mt_entry->ops->chown_h)( loc, owner, group );
46      } else {
47        errno = EPERM;
48        rv = -1;
49      }
50    }
51  } else {
52    errno = EROFS;
53    rv = -1;
54  }
55
56  return rv;
57}
58
59/**
60 *  POSIX 1003.1b 5.6.5 - Change Owner and Group of a File
61 */
62int fchown( int fd, uid_t owner, gid_t group )
63{
64  int rv;
65  rtems_libio_t *iop;
66
67  LIBIO_GET_IOP( fd, iop );
68
69  rtems_filesystem_instance_lock( &iop->pathinfo );
70
71  rv = rtems_filesystem_chown( &iop->pathinfo, owner, group );
72
73  rtems_filesystem_instance_unlock( &iop->pathinfo );
74
75  rtems_libio_iop_drop( iop );
76
77  return rv;
78}
Note: See TracBrowser for help on using the repository browser.