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

4.115
Last change on this file since e22af78 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • 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 <unistd.h>
22
23#include <rtems/libio_.h>
24
25int rtems_filesystem_chown(
26  const rtems_filesystem_location_info_t *loc,
27  uid_t owner,
28  gid_t group
29)
30{
31  const rtems_filesystem_mount_table_entry_t *mt_entry = loc->mt_entry;
32  int rv;
33
34  if ( mt_entry->writeable || rtems_filesystem_location_is_null( loc ) ) {
35    struct stat st;
36
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    }
50  } else {
51    errno = EROFS;
52    rv = -1;
53  }
54
55  return rv;
56}
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}
Note: See TracBrowser for help on using the repository browser.