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

5
Last change on this file since b2ed712 was b2ed712, checked in by Sebastian Huber <sebastian.huber@…>, on 08/25/17 at 08:58:58

Include missing <string.h>

Update #2133.

  • 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  rtems_libio_check_fd( fd );
68  iop = rtems_libio_iop( fd );
69  rtems_libio_check_is_open(iop);
70
71  rtems_filesystem_instance_lock( &iop->pathinfo );
72
73  rv = rtems_filesystem_chown( &iop->pathinfo, owner, group );
74
75  rtems_filesystem_instance_unlock( &iop->pathinfo );
76
77  return rv;
78}
Note: See TracBrowser for help on using the repository browser.