273 lines
10 KiB
HTML
273 lines
10 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
|
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
|
|
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
|
|
<title>chown</title>
|
|
</head>
|
|
<body bgcolor="white">
|
|
|
|
<basefont size="3"> <a name="chown"></a> <a name="tag_03_71"></a><!-- chown -->
|
|
<!--header start-->
|
|
<center><font size="2">The Open Group Base Specifications Issue 6<br>
|
|
IEEE Std 1003.1-2001<br>
|
|
Copyright © 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
|
|
|
|
<!--header end-->
|
|
<hr size="2" noshade>
|
|
<h4><a name="tag_03_71_01"></a>NAME</h4>
|
|
|
|
<blockquote>chown - change owner and group of a file</blockquote>
|
|
|
|
<h4><a name="tag_03_71_02"></a>SYNOPSIS</h4>
|
|
|
|
<blockquote class="synopsis">
|
|
<p><code><tt>#include <<a href="../basedefs/unistd.h.html">unistd.h</a>><br>
|
|
<br>
|
|
int chown(const char *</tt><i>path</i><tt>, uid_t</tt> <i>owner</i><tt>, gid_t</tt> <i>group</i><tt>);<br>
|
|
</tt></code></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_71_03"></a>DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>chown</i>() function shall change the user and group ownership of a file.</p>
|
|
|
|
<p>The <i>path</i> argument points to a pathname naming a file. The user ID and group ID of the named file shall be set to the
|
|
numeric values contained in <i>owner</i> and <i>group</i>, respectively.</p>
|
|
|
|
<p>Only processes with an effective user ID equal to the user ID of the file or with appropriate privileges may change the
|
|
ownership of a file. If _POSIX_CHOWN_RESTRICTED is in effect for <i>path</i>:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>Changing the user ID is restricted to processes with appropriate privileges.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>Changing the group ID is permitted to a process with an effective user ID equal to the user ID of the file, but without
|
|
appropriate privileges, if and only if <i>owner</i> is equal to the file's user ID or ( <b>uid_t</b>)-1 and <i>group</i> is equal
|
|
either to the calling process' effective group ID or to one of its supplementary group IDs.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>If the specified file is a regular file, one or more of the S_IXUSR, S_IXGRP, or S_IXOTH bits of the file mode are set, and the
|
|
process does not have appropriate privileges, the set-user-ID (S_ISUID) and set-group-ID (S_ISGID) bits of the file mode shall be
|
|
cleared upon successful return from <i>chown</i>(). If the specified file is a regular file, one or more of the S_IXUSR, S_IXGRP,
|
|
or S_IXOTH bits of the file mode are set, and the process has appropriate privileges, it is implementation-defined whether the
|
|
set-user-ID and set-group-ID bits are altered. If the <i>chown</i>() function is successfully invoked on a file that is not a
|
|
regular file and one or more of the S_IXUSR, S_IXGRP, or S_IXOTH bits of the file mode are set, the set-user-ID and set-group-ID
|
|
bits may be cleared.</p>
|
|
|
|
<p>If <i>owner</i> or <i>group</i> is specified as ( <b>uid_t</b>)-1 or ( <b>gid_t</b>)-1, respectively, the corresponding ID of
|
|
the file shall not be changed. If both owner and group are -1, the times need not be updated.</p>
|
|
|
|
<p>Upon successful completion, <i>chown</i>() shall mark for update the <i>st_ctime</i> field of the file.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_71_04"></a>RETURN VALUE</h4>
|
|
|
|
<blockquote>
|
|
<p>Upon successful completion, 0 shall be returned; otherwise, -1 shall be returned and <i>errno</i> set to indicate the error. If
|
|
-1 is returned, no changes are made in the user ID and group ID of the file.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_71_05"></a>ERRORS</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>chown</i>() function shall fail if:</p>
|
|
|
|
<dl compact>
|
|
<dt>[EACCES]</dt>
|
|
|
|
<dd>Search permission is denied on a component of the path prefix.</dd>
|
|
|
|
<dt>[ELOOP]</dt>
|
|
|
|
<dd>A loop exists in symbolic links encountered during resolution of the <i>path</i> argument.</dd>
|
|
|
|
<dt>[ENAMETOOLONG]</dt>
|
|
|
|
<dd>
|
|
The length of the <i>path</i> argument exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX}.</dd>
|
|
|
|
<dt>[ENOTDIR]</dt>
|
|
|
|
<dd>A component of the path prefix is not a directory.</dd>
|
|
|
|
<dt>[ENOENT]</dt>
|
|
|
|
<dd>A component of <i>path</i> does not name an existing file or <i>path</i> is an empty string.</dd>
|
|
|
|
<dt>[EPERM]</dt>
|
|
|
|
<dd>The effective user ID does not match the owner of the file, or the calling process does not have appropriate privileges and
|
|
_POSIX_CHOWN_RESTRICTED indicates that such privilege is required.</dd>
|
|
|
|
<dt>[EROFS]</dt>
|
|
|
|
<dd>The named file resides on a read-only file system.</dd>
|
|
</dl>
|
|
|
|
<p>The <i>chown</i>() function may fail if:</p>
|
|
|
|
<dl compact>
|
|
<dt>[EIO]</dt>
|
|
|
|
<dd>An I/O error occurred while reading or writing to the file system.</dd>
|
|
|
|
<dt>[EINTR]</dt>
|
|
|
|
<dd>The <i>chown</i>() function was interrupted by a signal which was caught.</dd>
|
|
|
|
<dt>[EINVAL]</dt>
|
|
|
|
<dd>The owner or group ID supplied is not a value supported by the implementation.</dd>
|
|
|
|
<dt>[ELOOP]</dt>
|
|
|
|
<dd>More than {SYMLOOP_MAX} symbolic links were encountered during resolution of the <i>path</i> argument.</dd>
|
|
|
|
<dt>[ENAMETOOLONG]</dt>
|
|
|
|
<dd>
|
|
As a result of encountering a symbolic link in resolution of the <i>path</i> argument, the length of the substituted pathname
|
|
string exceeded {PATH_MAX}.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<hr>
|
|
<div class="box"><em>The following sections are informative.</em></div>
|
|
|
|
<h4><a name="tag_03_71_06"></a>EXAMPLES</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_71_07"></a>APPLICATION USAGE</h4>
|
|
|
|
<blockquote>
|
|
<p>Although <i>chown</i>() can be used on some implementations by the file owner to change the owner and group to any desired
|
|
values, the only portable use of this function is to change the group of a file to the effective GID of the calling process or to a
|
|
member of its group set.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_71_08"></a>RATIONALE</h4>
|
|
|
|
<blockquote>
|
|
<p>System III and System V allow a user to give away files; that is, the owner of a file may change its user ID to anything. This
|
|
is a serious problem for implementations that are intended to meet government security regulations. Version 7 and 4.3 BSD permit
|
|
only the superuser to change the user ID of a file. Some government agencies (usually not ones concerned directly with security)
|
|
find this limitation too confining. This volume of IEEE Std 1003.1-2001 uses <i>may</i> to permit secure implementations
|
|
while not disallowing System V.</p>
|
|
|
|
<p>System III and System V allow the owner of a file to change the group ID to anything. Version 7 permits only the superuser to
|
|
change the group ID of a file. 4.3 BSD permits the owner to change the group ID of a file to its effective group ID or to any of
|
|
the groups in the list of supplementary group IDs, but to no others.</p>
|
|
|
|
<p>The POSIX.1-1990 standard requires that the <i>chown</i>() function invoked by a non-appropriate privileged process clear the
|
|
S_ISGID and the S_ISUID bits for regular files, and permits them to be cleared for other types of files. This is so that changes in
|
|
accessibility do not accidentally cause files to become security holes. Unfortunately, requiring these bits to be cleared on
|
|
non-executable data files also clears the mandatory file locking bit (shared with S_ISGID), which is an extension on many
|
|
implementations (it first appeared in System V). These bits should only be required to be cleared on regular files that have one or
|
|
more of their execute bits set.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_71_09"></a>FUTURE DIRECTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_71_10"></a>SEE ALSO</h4>
|
|
|
|
<blockquote>
|
|
<p><a href="chmod.html"><i>chmod</i>()</a> , <a href="pathconf.html"><i>pathconf</i>()</a> , the Base Definitions volume of
|
|
IEEE Std 1003.1-2001, <a href="../basedefs/sys/types.h.html"><i><sys/types.h></i></a>, <a href=
|
|
"../basedefs/unistd.h.html"><i><unistd.h></i></a></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_71_11"></a>CHANGE HISTORY</h4>
|
|
|
|
<blockquote>
|
|
<p>First released in Issue 1. Derived from Issue 1 of the SVID.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_71_12"></a>Issue 6</h4>
|
|
|
|
<blockquote>
|
|
<p>The following changes are made for alignment with the ISO POSIX-1:1996 standard:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>The wording describing the optional dependency on _POSIX_CHOWN_RESTRICTED is restored.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The [EPERM] error is restored as an error dependent on _POSIX_CHOWN_RESTRICTED. This is since its operand is a pathname and
|
|
applications should be aware that the error may not occur for that pathname if the file system does not support
|
|
_POSIX_CHOWN_RESTRICTED.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>The requirement to include <a href="../basedefs/sys/types.h.html"><i><sys/types.h></i></a> has been removed. Although <a
|
|
href="../basedefs/sys/types.h.html"><i><sys/types.h></i></a> was required for conforming implementations of previous POSIX
|
|
specifications, it was not required for UNIX applications.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The value for <i>owner</i> of ( <b>uid_t</b>)-1 allows the use of -1 by the owner of a file to change the group ID only. A
|
|
corresponding change is made for group.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The [ELOOP] mandatory error condition is added.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The [EIO] and [EINTR] optional error conditions are added.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>A second [ENAMETOOLONG] is added as an optional error condition.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>The following changes were made to align with the IEEE P1003.1a draft standard:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>Clarification is added that the S_ISUID and S_ISGID bits do not need to be cleared when the process has appropriate
|
|
privileges.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The [ELOOP] optional error condition is added.</p>
|
|
</li>
|
|
</ul>
|
|
</blockquote>
|
|
|
|
<div class="box"><em>End of informative text.</em></div>
|
|
|
|
<hr>
|
|
<hr size="2" noshade>
|
|
<center><font size="2"><!--footer start-->
|
|
UNIX ® is a registered Trademark of The Open Group.<br>
|
|
POSIX ® is a registered Trademark of The IEEE.<br>
|
|
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
|
|
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
|
|
]</font></center>
|
|
|
|
<!--footer end-->
|
|
<hr size="2" noshade>
|
|
</body>
|
|
</html>
|
|
|