<?Pub UDT _bookmark _target?><?Pub EntList bsol dash hellip gt lt minus?><?Pub CX solbook(book(title()bookinfo()part()part(title()partintro()chapter()?><chapter id="secfile-1"><?Pub Tag atict:info tracking="off" ref="0"
restricted="off"?><?Pub Tag atict:user user="sharonr" fullname="Sharon Veach"?><title>Controlling Access to Files (Tasks)</title><highlights><para>This chapter describes how to protect files in the Solaris Operating System (Solaris OS).
The chapter also describes how to protect against files whose permissions
could compromise the system.</para><para>The following is a list of the information in this chapter.</para><itemizedlist><listitem><para><olink targetptr="secfile-60" remap="internal">Using UNIX Permissions to Protect
Files</olink></para>
</listitem><listitem><para><olink targetptr="secfile-37" remap="internal">Using Access Control Lists to
Protect Files</olink></para>
</listitem><listitem><para><olink targetptr="secfile-68" remap="internal">Preventing Executable Files
From Compromising Security</olink></para>
</listitem><listitem><para><olink targetptr="secfile-10" remap="internal">Protecting Files (Task Map)</olink></para>
</listitem><listitem><para><olink targetptr="secfile-15" remap="internal">Protecting Files With UNIX Permissions
(Task Map)</olink></para>
</listitem><listitem><para><olink targetptr="secfile-30" remap="internal">Protecting Files With ACLs (Task
Map)</olink></para>
</listitem><listitem><para><olink targetptr="secfile-40" remap="internal">Protecting Against Programs
With Security Risk (Task Map)</olink></para>
</listitem>
</itemizedlist>
</highlights><sect1 id="secfile-60"><title>Using UNIX Permissions to Protect Files</title><indexterm><primary>directories</primary><seealso>files</seealso>
</indexterm><indexterm><primary>UNIX file permissions</primary><see>files, permissions</see>
</indexterm><indexterm><primary>files</primary><secondary>security</secondary><tertiary>UNIX permissions</tertiary>
</indexterm><indexterm><primary>protecting files</primary><secondary>with UNIX permissions</secondary>
</indexterm><para>Files can be secured through UNIX file permissions and through ACLs.
Files with sticky bits, and files that are executable, require special security
measures.</para><sect2 id="concept-17"><title>Commands for Viewing and Securing Files</title><para><indexterm><primary>commands</primary><secondary>file protection commands</secondary></indexterm>This table describes the commands for monitoring and securing
files and directories.</para><table frame="topbot" id="concept-62"><title>Commands for Securing Files and
Directories</title><tgroup cols="3" colsep="0" rowsep="0"><colspec colname="column1" colwidth="84.62*"/><colspec colname="column2" colwidth="420.65*"/><colspec colname="colspec0" colwidth="110.73*"/><thead><row rowsep="1"><entry><para>Command</para>
</entry><entry><para>Description</para>
</entry><entry><para>Man Page</para>
</entry>
</row>
</thead><tbody><row><entry><para><indexterm><primary>files</primary><secondary>security</secondary><tertiary>displaying file information</tertiary></indexterm><indexterm><primary>directories</primary><secondary>displaying files and related information</secondary></indexterm><indexterm><primary>files</primary><secondary>displaying information about</secondary></indexterm><indexterm><primary>displaying</primary><secondary>files and related information</secondary></indexterm><command>ls</command></para>
</entry><entry><para>Lists the files in a directory and information about the files.</para>
</entry><entry><para><olink targetdoc="group-refman" targetptr="ls-1" remap="external"><citerefentry><refentrytitle>ls</refentrytitle><manvolnum>1</manvolnum></citerefentry></olink></para>
</entry>
</row><row><entry><para><indexterm><primary>ownership of files</primary><secondary>changing</secondary></indexterm><indexterm><primary><command>chown</command> command</primary><secondary>description</secondary></indexterm><indexterm><primary>files</primary><secondary>changing ownership</secondary></indexterm><command>chown</command></para>
</entry><entry><para>Changes the ownership of a file.</para>
</entry><entry><para><olink targetdoc="group-refman" targetptr="chown-1" remap="external"><citerefentry><refentrytitle>chown</refentrytitle><manvolnum>1</manvolnum></citerefentry></olink></para>
</entry>
</row><row><entry><para><indexterm><primary><command>chgrp</command> command</primary><secondary>description</secondary></indexterm><command>chgrp</command></para>
</entry><entry><para>Changes the group ownership of a file.</para>
</entry><entry><para><olink targetdoc="group-refman" targetptr="chgrp-1" remap="external"><citerefentry><refentrytitle>chgrp</refentrytitle><manvolnum>1</manvolnum></citerefentry></olink></para>
</entry>
</row><row><entry><para><indexterm><primary>permissions</primary><secondary>changing file permissions</secondary><tertiary><command>chmod</command> command</tertiary></indexterm><indexterm><primary><command>chmod</command> command</primary><secondary>description</secondary></indexterm><indexterm><primary>files</primary><secondary>permissions</secondary><tertiary>changing</tertiary></indexterm><command>chmod</command></para>
</entry><entry><para>Changes permissions on a file. You can use either symbolic mode, which
uses letters and symbols, or absolute mode, which uses octal numbers, to change
permissions on a file.</para>
</entry><entry><para><olink targetdoc="group-refman" targetptr="chmod-1" remap="external"><citerefentry><refentrytitle>chmod</refentrytitle><manvolnum>1</manvolnum></citerefentry></olink></para>
</entry>
</row>
</tbody>
</tgroup>
</table>
</sect2><sect2 id="secfile-16"><title>File and Directory Ownership</title><indexterm><primary>files</primary><secondary>security</secondary><tertiary>user classes</tertiary>
</indexterm><indexterm><primary>user classes of files</primary>
</indexterm><indexterm><primary>permissions</primary><secondary>user classes and</secondary>
</indexterm><itemizedlist><para>Traditional UNIX file permissions can assign ownership to three classes
of users:</para><listitem><para><emphasis role="strong">user &ndash;</emphasis> The file or
directory owner, which is usually the user who created the file. The owner
of a file can decide who has the right to read the file, to write to the file
(make changes to it), or, if the file is a command, to execute the file.</para>
</listitem><listitem><para><emphasis role="strong">group &ndash;</emphasis> Members of
a group of users.</para>
</listitem><listitem><para><emphasis role="strong">others &ndash;</emphasis> All other
users who are not the file owner and are not members of the group.</para>
</listitem>
</itemizedlist><para>The owner of the file can usually assign or modify file permissions.
Additionally, users or roles with administrative capabilities, such as superuser
or the Primary Administrator role, can change a file's ownership. To override
system policy, see <olink targetptr="secfile-3" remap="internal">Example&nbsp;7&ndash;2</olink>.</para><para><indexterm><primary>files</primary><secondary>security</secondary><tertiary>file types</tertiary></indexterm><indexterm><primary>files</primary><secondary>symbols of file type</secondary></indexterm><indexterm><primary>files</primary><secondary>file types</secondary></indexterm>A file can be one of seven types. Each type is displayed by a
symbol:</para><variablelist><varlistentry><term><emphasis role="strong">-</emphasis> (Minus symbol)</term><listitem><para><indexterm><primary>- (minus sign)</primary><secondary>file type symbol</secondary></indexterm><indexterm><primary>minus sign (-)</primary><secondary>symbol of file type</secondary></indexterm>Text or program</para>
</listitem>
</varlistentry><varlistentry><term><emphasis role="strong">b</emphasis></term><listitem><para>Block special file</para>
</listitem>
</varlistentry><varlistentry><term><emphasis role="strong">c</emphasis></term><listitem><para>Character special file</para>
</listitem>
</varlistentry><varlistentry><term><emphasis role="strong">d</emphasis></term><listitem><para>Directory</para>
</listitem>
</varlistentry><varlistentry><term><emphasis role="strong">l</emphasis></term><listitem><para>Symbolic link</para>
</listitem>
</varlistentry><varlistentry><term><emphasis role="strong">s</emphasis></term><listitem><para>Socket</para>
</listitem>
</varlistentry><varlistentry><term><emphasis role="strong">D</emphasis></term><listitem><para>Door</para>
</listitem>
</varlistentry><varlistentry><term><emphasis role="strong">P</emphasis></term><listitem><para>Named pipe (FIFO)</para>
</listitem>
</varlistentry>
</variablelist>
</sect2><sect2 id="secfile-18"><title>UNIX File Permissions</title><indexterm><primary>files</primary><secondary>permissions</secondary><tertiary>description</tertiary>
</indexterm><indexterm><primary>files</primary><secondary>security</secondary><tertiary>file permissions</tertiary>
</indexterm><indexterm><primary>permissions</primary><secondary>file permissions</secondary><tertiary>description</tertiary>
</indexterm><indexterm><primary>directories</primary><secondary>permissions</secondary><tertiary>description</tertiary>
</indexterm><indexterm><primary>files</primary><secondary>security</secondary><tertiary>directory permissions</tertiary>
</indexterm><indexterm><primary>permissions</primary><secondary>directory permissions</secondary>
</indexterm><para>The following table lists and describes the permissions that you can
give to each class of user for a file or directory.</para><table frame="topbot" id="secfile-tbl-1"><title>File and Directory Permissions</title><tgroup cols="4" colsep="0" rowsep="0"><colspec colname="column1" colwidth="35.10*"/><colspec colname="colspec1" colwidth="46.80*"/><colspec colname="colspec0" colwidth="46.80*"/><colspec colname="column3" colwidth="280.09*"/><thead><row rowsep="1"><entry><para>Symbol</para>
</entry><entry><para>Permission</para>
</entry><entry><para>Object</para>
</entry><entry><para>Description</para>
</entry>
</row>
</thead><tbody><row><entry><para><literal>r</literal></para>
</entry><entry><para>Read</para>
</entry><entry><para>File</para>
</entry><entry><para>Designated users can open and read the contents of a file.</para>
</entry>
</row><row><entry><para></para>
</entry><entry><para></para>
</entry><entry><para>Directory</para>
</entry><entry><para>Designated users can list files in the directory.</para>
</entry>
</row><row><entry><para><literal>w</literal></para>
</entry><entry><para>Write</para>
</entry><entry><para>File</para>
</entry><entry><para>Designated users can modify the contents of the file or delete the file.</para>
</entry>
</row><row><entry><para></para>
</entry><entry><para></para>
</entry><entry><para>Directory</para>
</entry><entry><para>Designated users can add files or add links in the directory. They can
also remove files or remove links in the directory.</para>
</entry>
</row><row><entry><para><literal>x</literal></para>
</entry><entry><para>Execute</para>
</entry><entry><para>File</para>
</entry><entry><para>Designated users can execute the file, if it is a program or shell script.
They also can run the program with one of the <command>exec(2)</command> system
calls.</para>
</entry>
</row><row><entry><para></para>
</entry><entry><para></para>
</entry><entry><para>Directory</para>
</entry><entry><para>Designated users can open files or execute files in the directory. They
also can make the directory and the directories beneath it current.</para>
</entry>
</row><row><entry><para><literal>-</literal></para>
</entry><entry><para>Denied</para>
</entry><entry><para>File and Directory</para>
</entry><entry><para>Designated users cannot read, write, or execute the file.</para>
</entry>
</row>
</tbody>
</tgroup>
</table><para>These file permissions apply to regular files, and to special files
such as devices, sockets, and named pipes (FIFOs).</para><para><indexterm><primary>symbolic links</primary><secondary>file permissions</secondary></indexterm>For a symbolic link, the permissions that apply are the permissions
of the file that the link points to.</para><para>You can protect the files in a directory and its subdirectories by setting
restrictive file permissions on that directory. Note, however, that superuser
has access to all files and directories on the system.</para>
</sect2><sect2 id="secfile-69"><title>Special File Permissions (<command>setuid</command>, <command>setgid</command> and Sticky Bit)</title><indexterm><primary>files</primary><secondary>special files</secondary>
</indexterm><indexterm><primary>permissions</primary><secondary>special file permissions</secondary>
</indexterm><para>Three special types of permissions are available for executable files
and public directories: <command>setuid</command>, <command>setgid</command>,
and sticky bit. When these permissions are set, any user who runs that executable
file assumes the ID of the owner (or group) of the executable file.</para><para>You must be extremely careful when you set special permissions, because
special permissions constitute a security risk. For example, a user can gain
superuser capabilities by executing a program that sets the user ID (UID)
to <literal>0</literal>, which is the UID of <literal>root</literal>. Also,
all users can set special permissions for files that they own, which constitutes
another security concern.</para><para>You should monitor your system for any unauthorized use of the <command>setuid</command> permission and the <command>setgid</command> permission to gain
superuser capabilities. A suspicious permission grants ownership of an administrative
program to a user rather than to <literal>root</literal> or <literal>bin</literal>.
To search for and list all files that use this special permission, see <olink targetptr="secfile-23" remap="internal">How to Find Files With Special File Permissions</olink>.</para><sect3 id="secfile-64"><title><command>setuid</command> Permission</title><indexterm><primary>files</primary><secondary>ownership</secondary><tertiary>and <command>setuid</command> permission</tertiary>
</indexterm><indexterm><primary>files</primary><secondary>permissions</secondary><tertiary><command>setuid</command></tertiary>
</indexterm><indexterm><primary>permissions</primary><secondary><command>setuid</command> permissions</secondary><tertiary>description</tertiary>
</indexterm><indexterm><primary><command>setuid</command> permissions</primary><secondary>description</secondary>
</indexterm><indexterm><primary>special permissions</primary><secondary><command>setuid</command> permissions</secondary>
</indexterm><para>When <command>setuid</command> permission is set on an executable file,
a process that runs this file is granted access on the basis of the owner
of the file. The access is <emphasis>not</emphasis> based on the user who
is running the executable file. This special permission allows a user to access
files and directories that are normally available only to the owner.</para><para>For example, the <command>setuid</command> permission on the <command>passwd</command> command makes it possible for users to change passwords. A <command>passwd</command> command with <command>setuid</command> permission would resemble
the following:</para><screen>-r-<emphasis role="strong">s</emphasis>r-sr-x   3 root     sys       28144 Jun 17 12:02 /usr/bin/passwd</screen><para><indexterm><primary>permissions</primary><secondary><command>setuid</command> permissions</secondary><tertiary>security risks</tertiary></indexterm><indexterm><primary><command>setuid</command> permissions</primary><secondary>security risks</secondary></indexterm>This special permission presents a security risk. Some determined
users can find a way to maintain the permissions that are granted to them
by the <command>setuid</command> process even after the process has finished
executing.</para><note><para>The use of <command>setuid</command> permissions with the reserved
UIDs (0&ndash;100) from a program might not set the effective UID correctly.
Use a shell script, or avoid using the reserved UIDs with <command>setuid</command> permissions.</para>
</note>
</sect3><sect3 id="secfile-65"><title><command>setgid</command> Permission</title><indexterm><primary>files</primary><secondary>ownership</secondary><tertiary>and <command>setgid</command> permission</tertiary>
</indexterm><indexterm><primary>files</primary><secondary>permissions</secondary><tertiary><command>setgid</command></tertiary>
</indexterm><indexterm><primary>permissions</primary><secondary><command>setgid</command> permissions</secondary><tertiary>description</tertiary>
</indexterm><indexterm><primary><command>setgid</command> permissions</primary><secondary>description</secondary>
</indexterm><indexterm><primary>special permissions</primary><secondary><command>setgid</command> permissions</secondary>
</indexterm><para>The <command>setgid</command> permission is similar to the <command>setuid</command> permission.
The process's effective group ID (GID) is changed to the group that owns the
file, and a user is granted access based on the permissions that are granted
to that group. The <filename>/usr/bin/mail</filename> command has <command>setgid</command> permissions: </para><screen>-r-x--<emphasis role="strong">s</emphasis>--x   1 root   mail     67504 Jun 17 12:01 /usr/bin/mail</screen><para>When the <command>setgid</command> permission is applied to a directory,
files that were created in this directory belong to the group to which the
directory belongs. The files do not belong to the group to which the creating
process belongs. Any user who has write and execute permissions in the directory
can create a file there. However, the file belongs to the group that owns
the directory, not to the group that the user belongs to.</para><para><indexterm><primary><command>setgid</command> permissions</primary><secondary>security risks</secondary></indexterm>You should monitor your system for any unauthorized use of the <command>setgid</command> permission to gain superuser capabilities. A suspicious permission
grants group access to such a program to an unusual group rather than to <literal>root</literal> or <literal>bin</literal>. To search for and list all files
that use this permission, see <olink targetptr="secfile-23" remap="internal">How to Find Files
With Special File Permissions</olink>.</para>
</sect3><sect3 id="secfile-66"><title>Sticky Bit</title><indexterm><primary>files</primary><secondary>permissions</secondary><tertiary>sticky bit</tertiary>
</indexterm><indexterm><primary>permissions</primary><secondary>sticky bit</secondary>
</indexterm><indexterm><primary>sticky bit permissions</primary><secondary>description</secondary>
</indexterm><indexterm><primary>special permissions</primary><secondary>sticky bit</secondary>
</indexterm><para>The <emphasis>sticky bit</emphasis> is a permission bit that protects
the files within a directory. If the directory has the sticky bit set, a file
can be deleted only by the file owner, the directory owner, or by a privileged
user. The <literal>root</literal> user and the Primary Administrator role
are examples of privileged users. The sticky bit prevents a user from deleting
other users' files from public directories such as <filename>/tmp</filename>:</para><screen>drwxrwxrw<emphasis role="strong">t</emphasis> 7  root  sys   400 Sep  3 13:37 tmp</screen><para><indexterm><primary>directories</primary><secondary>public directories</secondary></indexterm><indexterm><primary>public directories</primary><secondary>sticky bit and</secondary></indexterm><indexterm><primary>TMPFS file system</primary><secondary>security</secondary></indexterm><indexterm><primary>file systems</primary><secondary>security</secondary><tertiary>TMPFS file system</tertiary></indexterm><indexterm><primary>file systems</primary><secondary>TMPFS</secondary></indexterm><indexterm><primary>permissions</primary><secondary>file permissions</secondary><tertiary>special permissions</tertiary></indexterm><indexterm><primary>permissions</primary><secondary>special file permissions</secondary></indexterm>Be sure to set the sticky bit manually when you set up a public
directory on a TMPFS file system. For instructions, see <olink targetptr="secfile-21" remap="internal">Example&nbsp;7&ndash;5</olink>.</para>
</sect3>
</sect2><sect2 id="secfile-62"><title>Default <command>umask</command> Value</title><indexterm><primary>directories</primary><secondary>permissions</secondary><tertiary>defaults</tertiary>
</indexterm><indexterm><primary>files</primary><secondary>permissions</secondary><tertiary>defaults</tertiary>
</indexterm><indexterm><primary>files</primary><secondary>permissions</secondary><tertiary><command>umask</command> value</tertiary>
</indexterm><indexterm><primary>files</primary><secondary>security</secondary><tertiary><command>umask</command> default</tertiary>
</indexterm><indexterm><primary>permissions</primary><secondary>defaults</secondary>
</indexterm><indexterm><primary>permissions</primary><secondary><command>umask</command> value</secondary>
</indexterm><indexterm><primary><command>umask</command> value</primary><secondary>and file creation</secondary>
</indexterm><indexterm><primary>defaults</primary><secondary><command>umask</command> value</secondary>
</indexterm><para>When you create a file or directory, you create it with a default set
of permissions. The system defaults are open. A text file has <literal>666</literal> permissions,
which grants read and write permission to everyone. A directory and an executable
file have <literal>777</literal> permissions, which grants read, write, and
execute permission to everyone. Typically, users override the system defaults
in their <filename>/etc/profile</filename> file, <filename>.cshrc</filename> file,
or <filename>.login</filename> file.</para><para>The value assigned by the <command>umask</command> command is subtracted
from the default. This process has the effect of denying permissions in the
same way that the <command>chmod</command> command grants them. For example,
the <command>chmod 022</command> command grants write permission to group
and others. The <command>umask 022</command> command denies write permission
to group and others.</para><para><indexterm><primary><command>umask</command> value</primary><secondary>typical settings</secondary></indexterm>The following table shows some typical <command>umask</command> settings
and their effect on an executable file.</para><table frame="topbot" id="secfile-22"><title><command>umask</command> Settings
for Different Security Levels</title><tgroup cols="3" colsep="0" rowsep="0"><colspec colname="column1" colwidth="131.63*"/><colspec colname="column2" colwidth="76.83*"/><colspec colname="column3" colwidth="151.54*"/><thead><row rowsep="1"><entry><para>Level of Security</para>
</entry><entry><para><command>umask</command> Setting</para>
</entry><entry><para>Permissions Disallowed</para>
</entry>
</row>
</thead><tbody><row><entry><para>Permissive (<literal>744</literal>)</para>
</entry><entry><para><literal>022</literal></para>
</entry><entry><para><literal>w</literal> for group and others</para>
</entry>
</row><row><entry><para>Moderate (<literal>740</literal>)</para>
</entry><entry><para><literal>027</literal></para>
</entry><entry><para><literal>w</literal> for group, <literal>rwx</literal> for others</para>
</entry>
</row><row><entry><para>Moderate (<literal>741</literal>)</para>
</entry><entry><para><literal>026</literal></para>
</entry><entry><para><literal>w</literal> for group, <literal>rw</literal> for others</para>
</entry>
</row><row><entry><para>Severe (<literal>700</literal>)</para>
</entry><entry><para><literal>077</literal></para>
</entry><entry><para><literal>rwx</literal> for group and others</para>
</entry>
</row>
</tbody>
</tgroup>
</table><para>For more information on setting the <command>umask</command> value,
see the <olink targetdoc="group-refman" targetptr="umask-1" remap="external"><citerefentry><refentrytitle>umask</refentrytitle><manvolnum>1</manvolnum></citerefentry></olink> man
page.</para>
</sect2><sect2 id="secfile-14"><title>File Permission Modes</title><indexterm><primary>files</primary><secondary>permissions</secondary><tertiary>changing</tertiary>
</indexterm><indexterm><primary>files</primary><secondary>security</secondary><tertiary>changing permissions</tertiary>
</indexterm><indexterm><primary>permissions</primary><secondary>file permissions</secondary><tertiary>changing</tertiary>
</indexterm><para>The <command>chmod</command> command enables you to change the permissions
on a file. You must be superuser or the owner of a file or directory to change
its permissions.</para><itemizedlist><para>You can use the <command>chmod</command> command to set permissions
in either of two modes:</para><listitem><para><indexterm><primary>absolute mode</primary><secondary>description</secondary></indexterm><indexterm><primary>files</primary><secondary>permissions</secondary><tertiary>absolute mode</tertiary></indexterm><indexterm><primary>permissions</primary><secondary>changing file permissions</secondary><tertiary>absolute mode</tertiary></indexterm><indexterm><primary>permissions</primary><secondary>file permissions</secondary><tertiary>absolute mode</tertiary></indexterm><emphasis role="strong">Absolute Mode &ndash;</emphasis> Use numbers
to represent file permissions. When you change permissions by using the absolute
mode, you represent permissions for each triplet by an octal mode number.
Absolute mode is the method most commonly used to set permissions.</para>
</listitem><listitem><para><indexterm><primary>permissions</primary><secondary>file permissions</secondary><tertiary>symbolic mode</tertiary></indexterm><indexterm><primary>files</primary><secondary>permissions</secondary><tertiary>symbolic mode</tertiary></indexterm><indexterm><primary>permissions</primary><secondary>changing file permissions</secondary><tertiary>symbolic mode</tertiary></indexterm><indexterm><primary>symbolic mode</primary><secondary>description</secondary></indexterm><emphasis role="strong">Symbolic Mode &ndash;</emphasis> Use combinations
of letters and symbols to add permissions or remove permissions.</para>
</listitem>
</itemizedlist><para><indexterm><primary>absolute mode</primary><secondary>changing file permissions</secondary></indexterm><indexterm><primary>file permission modes</primary><secondary>absolute mode</secondary></indexterm>The following table lists the octal values for setting file permissions
in absolute mode. You use these numbers in sets of three to set permissions
for owner, group, and other, in that order. For example, the value <literal>644</literal> sets
read and write permissions for owner, and read-only permissions for group
and other.</para><table frame="topbot" id="secfile-26"><title>Setting File Permissions in Absolute
Mode</title><tgroup cols="3" colsep="0" rowsep="0"><colspec colname="column1" colwidth="73*"/><colspec colname="column2" colwidth="106*"/><colspec colname="column3" colwidth="183*"/><thead><row rowsep="1"><entry><para>Octal Value</para>
</entry><entry><para>File Permissions Set</para>
</entry><entry><para>Permissions Description</para>
</entry>
</row>
</thead><tbody><row><entry><para><literal>0</literal></para>
</entry><entry><para><literal>---</literal></para>
</entry><entry><para>No permissions</para>
</entry>
</row><row><entry><para><literal>1</literal></para>
</entry><entry><para><literal>--x</literal></para>
</entry><entry><para>Execute permission only</para>
</entry>
</row><row><entry><para><literal>2</literal></para>
</entry><entry><para><literal>-w-</literal></para>
</entry><entry><para>Write permission only</para>
</entry>
</row><row><entry><para><literal>3</literal></para>
</entry><entry><para><literal>-wx</literal></para>
</entry><entry><para>Write and execute permissions</para>
</entry>
</row><row><entry><para><literal>4</literal></para>
</entry><entry><para><literal>r--</literal></para>
</entry><entry><para>Read permission only</para>
</entry>
</row><row><entry><para><literal>5</literal></para>
</entry><entry><para><literal>r-x</literal></para>
</entry><entry><para>Read and execute permissions</para>
</entry>
</row><row><entry><para><literal>6</literal></para>
</entry><entry><para><literal>rw-</literal></para>
</entry><entry><para>Read and write permissions</para>
</entry>
</row><row><entry><para><literal>7</literal></para>
</entry><entry><para><literal>rwx</literal></para>
</entry><entry><para>Read, write, and execute permissions</para>
</entry>
</row>
</tbody>
</tgroup>
</table><para><indexterm><primary>files</primary><secondary>permissions</secondary><tertiary>symbolic mode</tertiary></indexterm><indexterm><primary>permissions</primary><secondary>changing file permissions</secondary><tertiary>symbolic mode</tertiary></indexterm><indexterm><primary>permissions</primary><secondary>file permissions</secondary><tertiary>symbolic mode</tertiary></indexterm><indexterm><primary>symbolic mode</primary><secondary>changing file permissions</secondary></indexterm><indexterm><primary>equal sign (=)</primary><secondary>file permissions symbol</secondary></indexterm><indexterm><primary>plus sign (+)</primary><secondary>file permissions symbol</secondary></indexterm><indexterm><primary>minus sign (-)</primary><secondary>file permissions symbol</secondary></indexterm><indexterm><primary>= (equal sign)</primary><secondary>file permissions symbol</secondary></indexterm><indexterm><primary>+ (plus sign)</primary><secondary>file permissions symbol</secondary></indexterm><indexterm><primary>- (minus sign)</primary><secondary>file permissions symbol</secondary></indexterm><indexterm><primary>read permissions</primary><secondary>symbolic mode</secondary></indexterm><indexterm><primary>write permissions</primary><secondary>symbolic mode</secondary></indexterm><indexterm><primary>execute permissions</primary><secondary>symbolic mode</secondary></indexterm><indexterm><primary><command>setgid</command> permissions</primary><secondary>symbolic mode</secondary></indexterm><indexterm><primary>permissions</primary><secondary><command>setgid</command> permissions</secondary><tertiary>symbolic mode</tertiary></indexterm><indexterm><primary><command>setuid</command> permissions</primary><secondary>symbolic mode</secondary></indexterm><indexterm><primary>permissions</primary><secondary><command>setuid</command> permissions</secondary><tertiary>symbolic mode</tertiary></indexterm><indexterm><primary>sticky bit permissions</primary><secondary>symbolic mode</secondary></indexterm><indexterm><primary>file permission modes</primary><secondary>symbolic mode</secondary></indexterm>The following table lists the symbols for setting file permissions
in symbolic mode. Symbols can specify whose permissions are to be set or changed,
the operation to be performed, and the permissions that are being assigned
or changed.</para><table frame="topbot" id="secfile-53"><title>Setting File Permissions in Symbolic
Mode</title><tgroup cols="3" colsep="0" rowsep="0"><colspec colname="column1" colwidth="55*"/><colspec colname="column2" colwidth="73*"/><colspec colname="column3" colwidth="236*"/><thead><row rowsep="1"><entry><para>Symbol</para>
</entry><entry><para>Function</para>
</entry><entry><para>Description</para>
</entry>
</row>
</thead><tbody><row><entry><para><literal>u</literal></para>
</entry><entry><para><replaceable>who</replaceable></para>
</entry><entry><para>User (owner)</para>
</entry>
</row><row><entry><para><literal>g</literal></para>
</entry><entry><para><replaceable>who</replaceable></para>
</entry><entry><para>Group</para>
</entry>
</row><row><entry><para><literal>o</literal></para>
</entry><entry><para><replaceable>who</replaceable></para>
</entry><entry><para>Others</para>
</entry>
</row><row><entry><para><literal>a</literal></para>
</entry><entry><para><replaceable>who</replaceable></para>
</entry><entry><para>All</para>
</entry>
</row><row><entry><para><literal>=</literal></para>
</entry><entry><para><replaceable>operator</replaceable></para>
</entry><entry><para>Assign</para>
</entry>
</row><row><entry><para><literal>+</literal></para>
</entry><entry><para><replaceable>operator</replaceable></para>
</entry><entry><para>Add</para>
</entry>
</row><row><entry><para><literal>-</literal></para>
</entry><entry><para><replaceable>operator</replaceable></para>
</entry><entry><para>Remove</para>
</entry>
</row><row><entry><para><literal>r</literal></para>
</entry><entry><para><replaceable>permissions</replaceable></para>
</entry><entry><para>Read</para>
</entry>
</row><row><entry><para><literal>w</literal></para>
</entry><entry><para><replaceable>permissions</replaceable></para>
</entry><entry><para>Write</para>
</entry>
</row><row><entry><para><literal>x</literal></para>
</entry><entry><para><replaceable>permissions</replaceable></para>
</entry><entry><para>Execute</para>
</entry>
</row><row><entry><para><literal>l</literal></para>
</entry><entry><para><replaceable>permissions</replaceable></para>
</entry><entry><para>Mandatory locking, <command>setgid</command> bit is on, group execution
bit is off</para>
</entry>
</row><row><entry><para><literal>s</literal></para>
</entry><entry><para><replaceable>permissions</replaceable></para>
</entry><entry><para><command>setuid</command> or <command>setgid</command> bit is on</para>
</entry>
</row><row><entry><para><literal>t</literal></para>
</entry><entry><para><replaceable>permissions</replaceable></para>
</entry><entry><para>Sticky bit is on, execution bit for others is on</para>
</entry>
</row>
</tbody>
</tgroup>
</table><para>The <replaceable>who operator permissions</replaceable> designations
in the function column specify the symbols that change the permissions on
the file or directory.</para><variablelist><varlistentry><term><replaceable>who</replaceable></term><listitem><para>Specifies whose permissions are to be changed.</para>
</listitem>
</varlistentry><varlistentry><term><replaceable>operator</replaceable></term><listitem><para>Specifies the operation to be performed.</para>
</listitem>
</varlistentry><varlistentry><term><replaceable>permissions</replaceable></term><listitem><para>Specifies what permissions are to be changed.</para>
</listitem>
</varlistentry>
</variablelist><para><indexterm><primary>files</primary><secondary>security</secondary><tertiary>special file permissions</tertiary></indexterm><indexterm><primary>permissions</primary><secondary>file permissions</secondary><tertiary>special permissions</tertiary></indexterm><indexterm><primary>permissions</primary><secondary><command>setgid</command> permissions</secondary><tertiary>absolute mode</tertiary></indexterm><indexterm><primary>permissions</primary><secondary><command>setuid</command> permissions</secondary><tertiary>absolute mode</tertiary></indexterm><indexterm><primary>permissions</primary><secondary>special file permissions</secondary></indexterm><indexterm><primary><command>setgid</command> permissions</primary><secondary>absolute mode</secondary></indexterm><indexterm><primary><command>setuid</command> permissions</primary><secondary>absolute mode</secondary></indexterm><indexterm><primary>sticky bit permissions</primary><secondary>absolute mode</secondary></indexterm><indexterm><primary>absolute mode</primary><secondary>setting special permissions</secondary></indexterm>You can set special permissions on a file in absolute mode or
symbolic mode. However, you must use symbolic mode to set or remove <command>setuid</command> permissions on a directory. In absolute mode, you set special permissions
by adding a new octal value to the left of the permission triplet. The following
table lists the octal values for setting special permissions on a file.</para><table frame="topbot" id="secfile-tbl-2"><title>Setting Special File Permissions
in Absolute Mode</title><tgroup cols="2" colsep="0" rowsep="0"><colspec colname="column1" colwidth="109*"/><colspec colname="column2" colwidth="255*"/><thead><row rowsep="1"><entry><para>Octal Value</para>
</entry><entry><para>Special File Permissions</para>
</entry>
</row>
</thead><tbody><row><entry><para><literal>1</literal></para>
</entry><entry><para>Sticky bit</para>
</entry>
</row><row><entry><para><literal>2</literal></para>
</entry><entry><para><command>setgid</command></para>
</entry>
</row><row><entry><para><literal>4</literal></para>
</entry><entry><para><command>setuid</command></para>
</entry>
</row>
</tbody>
</tgroup>
</table>
</sect2>
</sect1><sect1 id="secfile-37"><title>Using Access Control Lists to Protect Files</title><indexterm><primary>Access Control Lists (ACLs)</primary><see>ACL</see>
</indexterm><indexterm><primary>ownership of files</primary><secondary>ACLs and</secondary>
</indexterm><indexterm><primary>permissions</primary><secondary>ACLs and</secondary>
</indexterm><indexterm><primary>access</primary><secondary>security</secondary><tertiary>ACLs</tertiary>
</indexterm><indexterm><primary>ACL</primary><secondary>description</secondary>
</indexterm><indexterm><primary>system security</primary><secondary>ACL</secondary>
</indexterm><indexterm><primary>ACL</primary><secondary>format of entries</secondary>
</indexterm><indexterm><primary>protecting files</primary><secondary>with ACLs</secondary>
</indexterm><itemizedlist><para>Traditional UNIX file protection provides read, write, and execute permissions
for the three user classes: file owner, file group, and other. An access control
list (ACL) provides better file security by enabling you to do the following:</para><listitem><para>Define file permissions for the file owner, the group, other,
specific users and groups</para>
</listitem><listitem><para>Define default permissions for each of the preceding categories</para>
</listitem>
</itemizedlist><para>For example, if you want everyone in a group to be able to read a file,
you can simply grant group read permissions on that file. Now, assume that
you want only one person in the group to be able to write to that file. Standard
UNIX does not provide that level of file security. However, an ACL provides
this level of file security.</para><para>ACL entries define an ACL on a file. The entries are set through the <command>setfacl</command> command. ACL entries consist of the following fields separated
by colons:</para><screen><replaceable>entry-type:</replaceable>[<replaceable>uid</replaceable>|<replaceable>gid</replaceable>]<replaceable>:perms</replaceable></screen><variablelist><varlistentry><term><replaceable>entry-type</replaceable></term><listitem><para>Is the type of ACL entry on which to set file permissions.
For example, <replaceable>entry-type</replaceable> can be <filename>user</filename> (the
owner of a file) or <filename>mask</filename> (the ACL mask). For a listing
of ACL entries, see <olink targetptr="secfile-35" remap="internal">Table&nbsp;7&ndash;7</olink> and <olink targetptr="secfile-52" remap="internal">Table&nbsp;7&ndash;8</olink>.</para>
</listitem>
</varlistentry><varlistentry><term><replaceable>uid</replaceable></term><listitem><para>Is the user name or user ID (UID).</para>
</listitem>
</varlistentry><varlistentry><term><replaceable>gid</replaceable></term><listitem><para>Is the group name or group ID (GID).</para>
</listitem>
</varlistentry><varlistentry><term><replaceable>perms</replaceable></term><listitem><para>Represents the permissions that are set on <replaceable>entry-type</replaceable>. <replaceable>perms</replaceable> can be indicated by the symbolic
characters <literal>rwx</literal> or an octal number. These are the same numbers
that are used with the <command>chmod</command> command.</para>
</listitem>
</varlistentry>
</variablelist><para>In the following example, an ACL entry sets read and write permissions
for the user <literal>stacey</literal>.</para><screen>user:stacey:rw-</screen><caution><para><indexterm><primary>ACL</primary><secondary>restrictions on copying entries</secondary></indexterm>UFS file system attributes such as ACLs are supported in UFS file
systems only. Thus, if you restore or copy files with ACL entries into the <filename>/tmp</filename> directory, which is usually mounted as a TMPFS file system,
the ACL entries will be lost. Use the <filename>/var/tmp</filename> directory
for temporary storage of UFS files.</para>
</caution><sect2 id="secfile-38"><title>ACL Entries for Files</title><indexterm><primary>ACL</primary><secondary>valid file entries</secondary>
</indexterm><indexterm><primary>files</primary><secondary>ACL entries</secondary><tertiary>valid entries</tertiary>
</indexterm><indexterm><primary>user ACL entries</primary><secondary>description</secondary>
</indexterm><indexterm><primary>group ACL entries</primary><secondary>description</secondary>
</indexterm><indexterm><primary>mask ACL entries</primary><secondary>description</secondary>
</indexterm><indexterm><primary>other ACL entries</primary><secondary>description</secondary>
</indexterm><para>The following table lists the valid ACL entries that you might use when
setting ACLs on files. The first three ACL entries provide the basic UNIX
file protection.</para><table frame="topbot" id="secfile-35"><title>ACL Entries for Files</title><tgroup cols="2" colsep="0" rowsep="0"><colspec colname="column1" colwidth="77.52*"/><colspec colname="column2" colwidth="284.48*"/><thead><row rowsep="1"><entry><para>ACL Entry</para>
</entry><entry><para>Description</para>
</entry>
</row>
</thead><tbody><row><entry><para><literal>u[ser]::</literal><replaceable>perms</replaceable></para>
</entry><entry><para>File owner permissions.</para>
</entry>
</row><row><entry><para><literal>g[roup]::</literal><replaceable>perms</replaceable></para>
</entry><entry><para>File group permissions.</para>
</entry>
</row><row><entry><para><literal>o[ther]:</literal><replaceable>perms</replaceable></para>
</entry><entry><para>Permissions for users other than the file owner or members of the file
group.</para>
</entry>
</row><row><entry><para><literal>m[ask]:</literal><replaceable>perms</replaceable></para>
</entry><entry><para>The ACL mask. The mask entry indicates the maximum permissions that
are allowed for users (other than the owner) and for groups. The mask is a
quick way to change permissions on all the users and groups.</para><para>For example, the <literal>mask:r--</literal> mask entry indicates that
users and groups cannot have more than read permissions, even though they
might have write and execute permissions.</para>
</entry>
</row><row><entry><para><literal>u[ser]:</literal><replaceable>uid:perms</replaceable></para>
</entry><entry><para>Permissions for a specific user. For <replaceable>uid</replaceable>,
you can specify either a user name or a numeric UID.</para>
</entry>
</row><row><entry><para><literal>g[roup]:</literal><replaceable>gid:perms</replaceable></para>
</entry><entry><para>Permissions for a specific group. For <replaceable>gid</replaceable>,
you can specify either a group name or a numeric GID.</para>
</entry>
</row>
</tbody>
</tgroup>
</table>
</sect2><sect2 id="secfile-39"><title>ACL Entries for Directories</title><indexterm><primary>ACL</primary><secondary>default entries for directories</secondary>
</indexterm><indexterm><primary>ACL</primary><secondary>directory entries</secondary>
</indexterm><indexterm><primary>defaults</primary><secondary>ACL entries for directories</secondary>
</indexterm><indexterm><primary>directories</primary><secondary>ACL entries</secondary>
</indexterm><indexterm><primary>user ACL entries</primary><secondary>default entries for directories</secondary>
</indexterm><indexterm><primary>group ACL entries</primary><secondary>default entries for directories</secondary>
</indexterm><indexterm><primary>mask ACL entries</primary><secondary>default entries for directories</secondary>
</indexterm><indexterm><primary>ACL</primary><secondary>default entries for directories</secondary>
</indexterm><indexterm><primary>ACL</primary><secondary>directory entries</secondary>
</indexterm><indexterm><primary>defaults</primary><secondary>ACL entries for directories</secondary>
</indexterm><indexterm><primary>directories</primary><secondary>ACL entries</secondary>
</indexterm><para>In addition to the ACL entries that are described in <olink targetptr="secfile-35" remap="internal">Table&nbsp;7&ndash;7</olink>, you can set default ACL entries
on a directory. Files or directories created in a directory that has default
ACL entries will have the same ACL entries as the default ACL entries. <olink targetptr="secfile-52" remap="internal">Table&nbsp;7&ndash;8</olink> lists the default ACL entries
for directories.</para><para>When you set default ACL entries for specific users and groups on a
directory for the first time, you must also set default ACL entries for the
file owner, file group, others, and the ACL mask. These entries are required.
They are the first four default ACL entries in the following table.</para><table frame="topbot" id="secfile-52"><title>Default ACL Entries for Directories</title><tgroup cols="2" colsep="0" rowsep="0"><colspec colname="column1" colwidth="130.89*"/><colspec colname="column2" colwidth="233.11*"/><thead><row rowsep="1"><entry><para>Default ACL Entry</para>
</entry><entry><para>Description</para>
</entry>
</row>
</thead><tbody><row><entry><para><literal>d[efault]:u[ser]::</literal><replaceable>perms</replaceable></para>
</entry><entry><para>Default file owner permissions.</para>
</entry>
</row><row><entry><para><literal>d[efault]:g[roup]::</literal><replaceable>perms</replaceable></para>
</entry><entry><para>Default file group permissions.</para>
</entry>
</row><row><entry><para><literal>d[efault]:o[ther]:</literal><replaceable>perms</replaceable></para>
</entry><entry><para>Default permissions for users other than the file owner or members of
the file group.</para>
</entry>
</row><row><entry><para><literal>d[efault]:m[ask]:</literal><replaceable>perms</replaceable></para>
</entry><entry><para>Default ACL mask.</para>
</entry>
</row><row><entry><para><literal>d[efault]:u[ser]:</literal><replaceable>uid:perms</replaceable></para>
</entry><entry><para>Default permissions for a specific user. For <replaceable>uid</replaceable>,
you can specify either a user name or a numeric UID.</para>
</entry>
</row><row><entry><para><literal>d[efault]:g[roup]:</literal><replaceable>gid:perms</replaceable></para>
</entry><entry><para>Default permissions for a specific group. For <replaceable>gid</replaceable>,
you can specify either a group name or a numeric GID.</para>
</entry>
</row>
</tbody>
</tgroup>
</table>
</sect2><sect2 id="secfile-24"><title>Commands for Administering ACLs</title><indexterm><primary>ACL</primary><secondary>commands</secondary>
</indexterm><indexterm><primary><command>setfacl</command> command</primary><secondary>description</secondary>
</indexterm><indexterm><primary>files</primary><secondary>ACL entries</secondary><tertiary>deleting</tertiary>
</indexterm><indexterm><primary>ACL</primary><secondary>deleting entries</secondary>
</indexterm><indexterm><primary>deleting</primary><secondary>ACL entries</secondary>
</indexterm><indexterm><primary><command>getfacl</command> command</primary><secondary>description</secondary>
</indexterm><indexterm><primary>files</primary><secondary>ACL entries</secondary><tertiary>displaying</tertiary>
</indexterm><indexterm><primary>ACL</primary><secondary>displaying entries</secondary>
</indexterm><indexterm><primary>displaying</primary><secondary>ACL entries</secondary>
</indexterm><indexterm><primary>commands</primary><secondary>ACL commands</secondary>
</indexterm><para>The following commands administer ACLs on files or directories.</para><variablelist><varlistentry><term><command>setfacl</command> command</term><listitem><para>Sets, adds, modifies, and deletes ACL entries. For more information,
see the <olink targetdoc="group-refman" targetptr="setfacl-1" remap="external"><citerefentry><refentrytitle>setfacl</refentrytitle><manvolnum>1</manvolnum></citerefentry></olink> man
page.</para>
</listitem>
</varlistentry><varlistentry><term><command>getfacl</command> command</term><listitem><para>Displays ACL entries. For more information, see the <olink targetdoc="group-refman" targetptr="getfacl-1" remap="external"><citerefentry><refentrytitle>getfacl</refentrytitle><manvolnum>1</manvolnum></citerefentry></olink> man page.</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
</sect1><sect1 id="secfile-68"><title>Preventing Executable Files From Compromising
Security</title><indexterm><primary>preventing</primary><secondary>executables from compromising security</secondary>
</indexterm><indexterm><primary>disabling</primary><secondary>executables that compromise security</secondary>
</indexterm><para><indexterm><primary>executable stacks</primary><secondary>protecting against</secondary></indexterm>A number of security bugs are related to default executable stacks
when their permissions are set to read, write, and execute. While stacks with
execute permissions are allowed, most programs can function correctly without
using executable stacks.</para><para><indexterm><primary><literal>noexec_user_stack</literal> variable</primary></indexterm><indexterm><primary>variables</primary><secondary><literal>noexec_user_stack</literal></secondary></indexterm>The <literal>noexec_user_stack</literal> variable enables you
to specify whether stack mappings are executable. The variable is available
as of the Solaris 2.6 release. By default, the variable is set to zero, except
on 64-bit applications, which provides ABI-compliant behavior. If the variable
is set to a non-zero value, the system marks the stack of every process in
the system as readable and writable, but not executable.</para><para>Once this variable is set, programs that attempt to execute code on
their stack are sent a <literal>SIGSEGV</literal> signal. This signal usually
results in the program terminating with a core dump. Such programs also generate
a warning message that includes the name of the offending program, the process
ID, and the real UID of the user who ran the program. For example:</para><screen>a.out[347] attempt to execute code on stack by uid 555 </screen><para><indexterm><primary><filename>/etc/syslog.conf</filename> file</primary><secondary>executable stack messages and</secondary></indexterm><indexterm><primary><filename>syslog.conf</filename> file</primary><secondary><literal>kern.notice</literal> level</secondary></indexterm><indexterm><primary><literal>kern.notice</literal> entry</primary><secondary><filename>syslog.conf</filename> file</secondary></indexterm><indexterm><primary><filename>syslog.conf</filename> file</primary><secondary>executable stack messages</secondary></indexterm><indexterm><primary><filename>/var/adm/messages</filename> file</primary><secondary>executable stack messages</secondary></indexterm><indexterm><primary><filename>messages</filename> file</primary><secondary>executable stack messages</secondary></indexterm>The message is logged by the <command>syslog</command> daemon
when the <literal>syslog</literal> <literal>kern</literal> facility is set
to <literal>notice</literal> level. This logging is set by default in the <filename>syslog.conf</filename> file, which means that the message is sent to both
the console and the <filename>/var/adm/messages</filename> file. For more
information, see the <olink targetdoc="group-refman" targetptr="syslogd-1m" remap="external"><citerefentry><refentrytitle>syslogd</refentrytitle><manvolnum>1M</manvolnum></citerefentry></olink> and <olink targetdoc="group-refman" targetptr="syslog.conf-4" remap="external"><citerefentry><refentrytitle>syslog.conf</refentrytitle><manvolnum>4</manvolnum></citerefentry></olink> man pages.</para><para><indexterm><primary><literal>noexec_user_stack_log</literal> variable</primary></indexterm><indexterm><primary>variables</primary><secondary><literal>noexec_user_stack_log</literal></secondary></indexterm><indexterm><primary>executable stacks</primary><secondary>logging messages</secondary></indexterm>The <literal>syslog</literal> message is useful for observing
potential security problems. The message also identifies valid programs that
depend upon executable stacks that have been prevented from correct operation
by setting this variable. If you do not want any messages logged, then set
the <literal>noexec_user_stack_log</literal> variable to zero in the <filename>/etc/system</filename>  file. Even though messages are not being logged, the SIGSEGV
signal can continue to cause the executing program to terminate with a core
dump.</para><para>You can use the <function>mprotect</function> function if you want programs
to explicitly mark their stack as executable. For more information, see the <olink targetdoc="refman" targetptr="mprotect-2" remap="external"><citerefentry><refentrytitle>mprotect</refentrytitle><manvolnum>2</manvolnum></citerefentry></olink> man page.</para><para>Because of hardware limitations, the capability of catching and reporting
executable stack problems is not available on most x86 based systems. Systems
in the AMD64 product family can catch  and report executable stack problems.</para>
</sect1><sect1 id="secfile-10"><title>Protecting Files (Task Map)</title><indexterm><primary>administering</primary><secondary>file permissions</secondary>
</indexterm><indexterm><primary>managing</primary><secondary>file permissions</secondary>
</indexterm><indexterm><primary>using</primary><secondary>file permissions</secondary>
</indexterm><para><indexterm><primary>task maps</primary><secondary>protecting files</secondary></indexterm><indexterm><primary>protecting files</primary><secondary>task map</secondary></indexterm>The following task map points to sets of procedures for protecting
files.</para><informaltable frame="all" pgwide="1"><tgroup cols="3" colsep="1" rowsep="1"><colspec colname="colspec0" colwidth="110*"/><colspec colname="col2" colwidth="167*"/><colspec colname="colspec1" colwidth="119*"/><thead><row><entry><para>Task</para>
</entry><entry><para>Description</para>
</entry><entry><para>For Instructions</para>
</entry>
</row>
</thead><tbody><row><entry><para>Use UNIX permissions to protect files</para>
</entry><entry><para>Views UNIX permissions on files. Protects files with UNIX permissions.</para>
</entry><entry><para><olink targetptr="secfile-15" remap="internal">Protecting Files With UNIX Permissions
(Task Map)</olink></para>
</entry>
</row><row><entry><para>Use ACLs to protect files</para>
</entry><entry><para>Adds ACLs to protect files at a more granular level than UNIX permissions
can.</para>
</entry><entry><para><olink targetptr="secfile-30" remap="internal">Protecting Files With ACLs (Task Map)</olink></para>
</entry>
</row><row><entry><para>Protect system from files that pose a security risk</para>
</entry><entry><para>Finds executable files that have suspicious ownership. Disables files
that can damage the system.</para>
</entry><entry><para><olink targetptr="secfile-40" remap="internal">Protecting Against Programs With Security
Risk (Task Map)</olink></para>
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</sect1><sect1 id="secfile-15"><title>Protecting Files With UNIX Permissions (Task
Map)</title><indexterm><primary>administering</primary><secondary>file permissions</secondary>
</indexterm><indexterm><primary>protecting files</primary><secondary>with UNIX permissions</secondary>
</indexterm><indexterm><primary>files</primary><secondary>protecting with UNIX permissions</secondary>
</indexterm><indexterm><primary>user procedures</primary><secondary>protecting files</secondary>
</indexterm><indexterm><primary>protecting files</primary><secondary>user procedures</secondary>
</indexterm><para><indexterm><primary>task maps</primary><secondary>protecting files with UNIX permissions</secondary></indexterm><indexterm><primary>protecting files</primary><secondary>with UNIX permissions task map</secondary></indexterm>The following task map points to procedures that list file permissions,
change file permissions, and protect files with special file permissions.</para><informaltable frame="all" pgwide="1"><tgroup cols="2" colsep="1" rowsep="1"><colspec colname="colspec0" colwidth="63.46*"/><colspec colname="colspec1" colwidth="165.54*"/><thead><row><entry><para>Task</para>
</entry><entry><para>For Instructions</para>
</entry>
</row>
</thead><tbody><row><entry><para>Display file information</para>
</entry><entry><para><olink targetptr="secfile-43" remap="internal">How to Display File Information</olink></para>
</entry>
</row><row><entry><para>Change file ownership</para>
</entry><entry><para><olink targetptr="secfile-20" remap="internal">How to Change the Owner of a File</olink></para><para><olink targetptr="secfile-54" remap="internal">How to Change Group Ownership of a File</olink></para>
</entry>
</row><row><entry><para>Change file permissions</para>
</entry><entry><para><olink targetptr="secfile-11" remap="internal">How to Change File Permissions in Symbolic
Mode</olink></para><para><olink targetptr="secfile-46" remap="internal">How to Change File Permissions in Absolute
Mode</olink></para><para><olink targetptr="secfile-45" remap="internal">How to Change Special File Permissions
in Absolute Mode</olink></para>
</entry>
</row>
</tbody>
</tgroup>
</informaltable><task id="secfile-43"><title>How to Display File Information</title><indexterm><primary>directories</primary><secondary>displaying files and related information</secondary>
</indexterm><indexterm><primary>displaying</primary><secondary>file information</secondary>
</indexterm><indexterm><primary>viewing</primary><secondary>file permissions</secondary>
</indexterm><indexterm><primary>files</primary><secondary>displaying file information</secondary>
</indexterm><tasksummary><para>Display information about all the files in a directory by using the <command>ls</command> command.</para>
</tasksummary><procedure remap="single-step"><step><para><indexterm><primary>. (dot)</primary><secondary>displaying hidden files</secondary></indexterm><indexterm><primary>dot (<literal>.</literal>)</primary><secondary>displaying hidden files</secondary></indexterm><indexterm><primary>files</primary><secondary>displaying hidden files</secondary></indexterm>Type the following command to display a long listing of all files
in the current directory.</para><screen>% <userinput>ls -la</userinput></screen><variablelist><varlistentry><term><option>l</option></term><listitem><para>Displays the long format that includes user ownership, group
ownership, and file permissions.</para>
</listitem>
</varlistentry><varlistentry><term><option>a</option></term><listitem><para>Displays all files, including hidden files that begin with
a dot (<literal>.</literal>).</para>
</listitem>
</varlistentry>
</variablelist>
</step>
</procedure><example id="secfile-56"><title>Displaying File Information</title><indexterm><primary>files</primary><secondary>security</secondary><tertiary>displaying file information</tertiary>
</indexterm><para>In the following example, a partial list of the files in the <filename>/sbin</filename> directory is displayed.</para><screen>% <userinput>cd /sbin</userinput>
% <userinput>ls -la</userinput>
total 13456
drwxr-xr-x   2 root     sys          512 Sep  1 14:11 .
drwxr-xr-x  29 root     root        1024 Sep  1 15:40 ..
-r-xr-xr-x   1 root     bin       218188 Aug 18 15:17 autopush
lrwxrwxrwx   1 root     root          21 Sep  1 14:11 bpgetfile -&gt; ...
-r-xr-xr-x   1 root     bin       505556 Aug 20 13:24 dhcpagent
-r-xr-xr-x   1 root     bin       456064 Aug 20 13:25 dhcpinfo
-r-xr-xr-x   1 root     bin       272360 Aug 18 15:19 fdisk
-r-xr-xr-x   1 root     bin       824728 Aug 20 13:29 hostconfig
-r-xr-xr-x   1 root     bin       603528 Aug 20 13:21 ifconfig
-r-xr-xr-x   1 root     sys       556008 Aug 20 13:21 init
-r-xr-xr-x   2 root     root      274020 Aug 18 15:28 jsh
-r-xr-xr-x   1 root     bin       238736 Aug 21 19:46 mount
-r-xr-xr-x   1 root     sys         7696 Aug 18 15:20 mountall
   .
   .
   .</screen><itemizedlist><para>Each line displays information about a file in the following order:</para><listitem><para>Type of file &ndash; For example, <literal>d</literal>. For
list of file types, see <olink targetptr="secfile-16" remap="internal">File and Directory Ownership</olink>.</para>
</listitem><listitem><para>Permissions &ndash; For example, <literal>r-xr-xr-x</literal>.
For description, see <olink targetptr="secfile-16" remap="internal">File and Directory Ownership</olink>.</para>
</listitem><listitem><para>Number of hard links &ndash; For example, <literal>2</literal>.</para>
</listitem><listitem><para>Owner of the file &ndash; For example, <literal>root</literal>.</para>
</listitem><listitem><para>Group of the file &ndash; For example, <literal>bin</literal>.</para>
</listitem><listitem><para>Size of the file, in bytes &ndash; For example, <literal>7696</literal>.</para>
</listitem><listitem><para>Date the file was created or the last date that the file was
changed &ndash; For example, <literal>Aug 18 15:20</literal>.</para>
</listitem><listitem><para>Name of the file &ndash; For example, <literal>mountall</literal>.</para>
</listitem>
</itemizedlist>
</example>
</task><task id="secfile-20"><title>How to Change the Owner of a File</title><indexterm><primary>changing</primary><secondary>file ownership</secondary>
</indexterm><indexterm><primary>files</primary><secondary>changing ownership</secondary>
</indexterm><indexterm><primary>files</primary><secondary>security</secondary><tertiary>changing ownership</tertiary>
</indexterm><indexterm><primary>ownership of files</primary><secondary>changing</secondary>
</indexterm><tasksummary><para>The file owner, the Primary Administrator role, or superuser can change
any file's ownership.</para>
</tasksummary><procedure><step><para>Display the permissions on a file.</para><screen>% <userinput>ls -l example-file</userinput>
-rw-r--r--   1 janedoe   staff   112640 May 24 10:49 example-file</screen>
</step>&rolePAstep;<step><para>Change the owner of the file.</para><screen># <userinput>chown stacey example-file</userinput></screen>
</step><step><para>Verify that the owner of the file has changed.</para><screen># <userinput>ls -l example-file</userinput>
-rw-r--r--   1 stacey   staff   112640 May 26 08:50 example-file </screen>
</step>
</procedure><example id="secfile-3"><title>Enabling Users to Change the Ownership of Files That Others Own</title><para><emphasis role="strong">Security Consideration &ndash;</emphasis> You
should have good reason to override system security policy by changing the
setting of the <envar>rstchown</envar> variable to zero. Any user who accesses
the system can change the ownership of any file on the system.</para><para><indexterm><primary><envar>rstchown</envar> system variable</primary></indexterm><indexterm><primary>system variables</primary><secondary><envar>rstchown</envar></secondary></indexterm><indexterm><primary>variables</primary><secondary><envar>rstchown</envar></secondary></indexterm>In this example, the value of the <envar>rstchown</envar> variable
is set to zero in the <filename>/etc/system</filename> file. This setting
enables the owner of a file to use the <command>chown</command> command to
change the file's ownership to another user. This setting also enables the
owner to use the <command>chgrp</command> command to set the group ownership
of a file to a group that the owner does not belong to. The change goes into
effect when the system is rebooted.</para><screen>set rstchown = 0</screen><para>For more information, see the <olink targetdoc="group-refman" targetptr="chown-1" remap="external"><citerefentry><refentrytitle>chown</refentrytitle><manvolnum>1</manvolnum></citerefentry></olink> and <olink targetdoc="group-refman" targetptr="chgrp-1" remap="external"><citerefentry><refentrytitle>chgrp</refentrytitle><manvolnum>1</manvolnum></citerefentry></olink> man pages.</para><para>Also, be aware that NFS-mounted file systems have further restrictions
on changing ownership and groups. For more information on restricting access
to NFS-mounted systems, see <olink targetdoc="group-sa" targetptr="rfsrefer-1" remap="external">Chapter 6, <citetitle remap="chapter">Accessing Network File Systems (Reference),</citetitle> in <citetitle remap="book">System Administration Guide: Network Services</citetitle></olink>.</para>
</example>
</task><task id="secfile-54"><title>How to Change Group Ownership of a File</title><indexterm><primary>changing</primary><secondary>group ownership of file</secondary>
</indexterm><indexterm><primary>files</primary><secondary>changing group ownership</secondary>
</indexterm><indexterm><primary>groups</primary><secondary>changing file ownership</secondary>
</indexterm><indexterm><primary>ownership of files</primary><secondary>changing group ownership</secondary>
</indexterm><procedure>&rolePAstep;<step><para><indexterm><primary><command>chgrp</command> command</primary><secondary>syntax</secondary></indexterm>Change the group ownership of a file.</para><screen>$ <userinput>chgrp scifi example-file</userinput></screen><para>For information on setting up groups, see <olink targetdoc="group-sa" targetptr="userconcept-97366" remap="external">Chapter 4, <citetitle remap="chapter">Managing User Accounts and Groups (Overview),</citetitle> in <citetitle remap="book">System Administration Guide: Basic Administration</citetitle></olink>.</para>
</step><step><para>Verify that the group ownership of the file has changed.</para><screen>$ <userinput>ls -l example-file</userinput>
 -rw-r--r--   1 stacey   scifi   112640 June 20 08:55  example-file</screen><para>Also see <olink targetptr="secfile-3" remap="internal">Example&nbsp;7&ndash;2</olink>.</para>
</step>
</procedure>
</task><task id="secfile-11"><title>How to Change File Permissions in Symbolic Mode</title><indexterm><primary>symbolic mode</primary><secondary>changing file permissions</secondary>
</indexterm><indexterm><primary>files</primary><secondary>permissions</secondary><tertiary>symbolic mode</tertiary>
</indexterm><indexterm><primary>permissions</primary><secondary>changing file permissions</secondary><tertiary>symbolic mode</tertiary>
</indexterm><indexterm><primary>permissions</primary><secondary>file permissions</secondary><tertiary>symbolic mode</tertiary>
</indexterm><indexterm><primary>changing</primary><secondary>file permissions</secondary><tertiary>symbolic mode</tertiary>
</indexterm><procedure><step><para>If you are not the owner of the file or directory, become superuser
or assume an equivalent role.</para><para>Only the current owner or superuser
can use the <command>chmod</command> command to change file permissions on
a file or directory.</para>
</step><step><para>Change permissions in symbolic mode.</para><screen>% chmod <replaceable>who operator permissions filename</replaceable></screen><variablelist><varlistentry><term><replaceable>who</replaceable></term><listitem><para>Specifies whose permissions are to be changed.</para>
</listitem>
</varlistentry><varlistentry><term><replaceable>operator</replaceable></term><listitem><para>Specifies the operation to be performed.</para>
</listitem>
</varlistentry><varlistentry><term><replaceable>permissions</replaceable></term><listitem><para>Specifies what permissions are to be changed. For the list
of valid symbols, see <olink targetptr="secfile-53" remap="internal">Table&nbsp;7&ndash;5</olink>.</para>
</listitem>
</varlistentry><varlistentry><term><replaceable>filename</replaceable></term><listitem><para>Specifies the file or directory.</para>
</listitem>
</varlistentry>
</variablelist>
</step><step><para>Verify that the permissions of the file have changed.</para><screen>% ls -l <replaceable>filename</replaceable></screen>
</step>
</procedure><example id="secfile-47"><title>Changing Permissions in Symbolic Mode</title><indexterm><primary>files</primary><secondary>permissions</secondary><tertiary>changing</tertiary>
</indexterm><indexterm><primary>files</primary><secondary>security</secondary><tertiary>changing permissions</tertiary>
</indexterm><indexterm><primary>permissions</primary><secondary>file permissions</secondary><tertiary>changing</tertiary>
</indexterm><indexterm><primary>files</primary><secondary>permissions</secondary><tertiary>symbolic mode</tertiary>
</indexterm><indexterm><primary>permissions</primary><secondary>changing file permissions</secondary><tertiary>symbolic mode</tertiary>
</indexterm><indexterm><primary>permissions</primary><secondary>file permissions</secondary><tertiary>symbolic mode</tertiary>
</indexterm><indexterm><primary>symbolic mode</primary><secondary>changing file permissions</secondary>
</indexterm><para>In the following example, read permission is taken away from others.</para><screen>% <userinput>chmod o-r example-file1</userinput></screen><para>In the following example, read and execute permissions are added for
user, group, and others.</para><screen>$ <userinput>chmod a+rx example-file2</userinput></screen><para>In the following example, read, write, and execute permissions are assigned
to group.</para><screen>$ <userinput>chmod g=rwx example-file3</userinput></screen>
</example>
</task><task id="secfile-46"><title>How to Change File Permissions in Absolute Mode</title><indexterm><primary>absolute mode</primary><secondary>changing file permissions</secondary>
</indexterm><indexterm><primary>files</primary><secondary>permissions</secondary><tertiary>absolute mode</tertiary>
</indexterm><indexterm><primary>permissions</primary><secondary>changing file permissions</secondary><tertiary>absolute mode</tertiary>
</indexterm><indexterm><primary>permissions</primary><secondary>file permissions</secondary><tertiary>absolute mode</tertiary>
</indexterm><indexterm><primary>changing</primary><secondary>file permissions</secondary><tertiary>absolute mode</tertiary>
</indexterm><procedure><step><para>If you are not the owner of the file or directory, become superuser
or assume an equivalent role.</para><para>Only the current owner or superuser
can use the <command>chmod</command> command to change file permissions on
a file or directory.</para>
</step><step><para>Change permissions in absolute mode.</para><screen>% chmod <replaceable>nnn</replaceable> <replaceable>filename</replaceable></screen><variablelist><varlistentry><term><replaceable>nnn</replaceable></term><listitem><para>Specifies the octal values that represent the permissions
for the file owner, file group, and others, in that order. For the list of
valid octal values, see <olink targetptr="secfile-26" remap="internal">Table&nbsp;7&ndash;4</olink>.</para>
</listitem>
</varlistentry><varlistentry><term><replaceable>filename</replaceable></term><listitem><para>Specifies the file or directory.</para>
</listitem>
</varlistentry>
</variablelist><note><para>When you use the <command>chmod</command> command to change the
file group permissions on a file with ACL entries, both the file group permissions
and the ACL mask are changed to the new permissions. Be aware that the new
ACL mask permissions can change the permissions for other users and groups
who have ACL entries on the file. Use the <command>getfacl</command> command
to make sure that the appropriate permissions are set for all ACL entries.
For more information, see the <olink targetdoc="group-refman" targetptr="getfacl-1" remap="external"><citerefentry><refentrytitle>getfacl</refentrytitle><manvolnum>1</manvolnum></citerefentry></olink> man
page.</para>
</note>
</step><step><para>Verify that the permissions of the file have changed.</para><screen>% ls -l <replaceable>filename</replaceable></screen>
</step>
</procedure><example id="secfile-44"><title>Changing Permissions in Absolute Mode</title><para>In the following example, the permissions of a public directory are
changed from <literal>744</literal> (read, write, execute; read-only; and
read-only) to <literal>755</literal> (read, write, execute; read and execute;
and read and execute).</para><screen># <userinput>ls -ld public_dir</userinput>
drwxr--r--  1 ignatz   staff    6023 Aug  5 12:06 public_dir
# <userinput>chmod 755 public_dir</userinput>
# <userinput>ls -ld public_dir</userinput>
drwxr-xr-x  1 ignatz   staff    6023 Aug  5 12:06 public_dir</screen><para>In the following example, the permissions of an executable shell script
are changed from read and write to read, write, and execute.</para><screen>% <userinput>ls -l my_script</userinput>
-rw------- 1 ignatz   staff    6023 Aug  5 12:06 my_script
% <userinput>chmod 700 my_script</userinput>
% <userinput>ls -l my_script</userinput>
-rwx------ 1 ignatz   staff    6023 Aug  5 12:06 my_script</screen>
</example>
</task><task id="secfile-45"><title>How to Change Special File Permissions in Absolute
Mode</title><indexterm><primary>changing</primary><secondary>special file permissions</secondary>
</indexterm><indexterm><primary>changing</primary><secondary>file permissions</secondary><tertiary>special</tertiary>
</indexterm><indexterm><primary>absolute mode</primary><secondary>changing special file permissions</secondary>
</indexterm><indexterm><primary>files</primary><secondary>changing special file permissions</secondary>
</indexterm><indexterm><primary><command>chmod</command> command</primary><secondary>changing special permissions</secondary>
</indexterm><procedure><step><para>If you are not the owner of the file or directory, become superuser
or assume an equivalent role.</para><para>Only the current owner or a user
with superuser capabilities can use the <command>chmod</command> command to
change the special permissions on a file or directory.</para>
</step><step><para><indexterm><primary><command>chmod</command> command</primary><secondary>syntax</secondary></indexterm>Change special permissions in absolute mode.</para><screen>% chmod <replaceable>nnnn</replaceable> <replaceable>filename</replaceable></screen><variablelist><varlistentry><term><replaceable>nnnn</replaceable></term><listitem><para>Specifies the octal values that change the permissions on
the file or directory. The leftmost octal value sets the special permissions
on the file. For the list of valid octal values for special permissions, see <olink targetptr="secfile-tbl-2" remap="internal">Table&nbsp;7&ndash;6</olink>.</para>
</listitem>
</varlistentry><varlistentry><term><replaceable>filename</replaceable></term><listitem><para>Specifies the file or directory.</para>
</listitem>
</varlistentry>
</variablelist><note><para>When you use the <command>chmod</command> command to change the
file group permissions on a file with ACL entries, both the file group permissions
and the ACL mask are changed to the new permissions. Be aware that the new
ACL mask permissions can change the permissions for additional users and groups
who have ACL entries on the file. Use the <command>getfacl</command> command
to make sure that the appropriate permissions are set for all ACL entries.
For more information, see the <olink targetdoc="group-refman" targetptr="getfacl-1" remap="external"><citerefentry><refentrytitle>getfacl</refentrytitle><manvolnum>1</manvolnum></citerefentry></olink> man
page.</para>
</note>
</step><step><para>Verify that the permissions of the file have changed.</para><screen>% ls -l <replaceable>filename</replaceable></screen>
</step>
</procedure><example id="secfile-21"><title>Setting Special File Permissions in Absolute Mode</title><para>In the following example, the <command>setuid</command> permission is
set on the <filename>dbprog</filename> file.</para><screen># <userinput>chmod 4555 dbprog</userinput>
# <userinput>ls -l dbprog</userinput>
-r-sr-xr-x   1 db     staff        12095 May  6 09:29 dbprog</screen><para>In the following example, the <command>setgid</command> permission is
set on the <filename>dbprog2</filename> file.</para><screen># <userinput>chmod 2551 dbprog2</userinput>
# <userinput>ls -l dbprog2</userinput>
-r-xr-s--x   1 db     staff       24576 May  6 09:30 dbprog2</screen><para><indexterm><primary>permissions</primary><secondary><command>setgid</command> permissions</secondary><tertiary>absolute mode</tertiary></indexterm><indexterm><primary>permissions</primary><secondary><command>setuid</command> permissions</secondary><tertiary>absolute mode</tertiary></indexterm><indexterm><primary><command>setgid</command> permissions</primary><secondary>absolute mode</secondary></indexterm><indexterm><primary><command>setuid</command> permissions</primary><secondary>absolute mode</secondary></indexterm><indexterm><primary>sticky bit permissions</primary><secondary>absolute mode</secondary></indexterm><indexterm><primary><command>chmod</command> command</primary><secondary>changing special permissions</secondary></indexterm>In the following example, the sticky bit permission is set on
the <filename>public_dir</filename> directory.</para><screen># <userinput>chmod 1777 public_dir</userinput>
# <userinput>ls -ld public_dir</userinput>
drwxrwxrwt   2 ignatz   staff          512 May 15 15:27 public_dir</screen>
</example>
</task>
</sect1><sect1 id="secfile-30"><title>Protecting Files With ACLs (Task Map)</title><indexterm><primary>ACL</primary><secondary>task map</secondary>
</indexterm><indexterm><primary>administering</primary><secondary>ACLs</secondary>
</indexterm><indexterm><primary>protecting files</primary><secondary>with ACLs</secondary>
</indexterm><indexterm><primary>files</primary><secondary>protecting with ACLs</secondary>
</indexterm><indexterm><primary>user procedures</primary><secondary>using ACLs</secondary>
</indexterm><indexterm><primary>ACL</primary><secondary>user procedures</secondary>
</indexterm><para><indexterm><primary>task maps</primary><secondary>protecting files with ACLs</secondary></indexterm><indexterm><primary>protecting files</primary><secondary>with ACLs task map</secondary></indexterm>The following task map points to procedures that list the ACLs
on a file, change the ACLs, and copy the ACLs to another file.</para><informaltable frame="all" pgwide="1"><tgroup cols="2" colsep="1" rowsep="1"><colspec colname="colspec0" colwidth="110*"/><colspec colname="colspec1" colwidth="119*"/><thead><row><entry><para>Task</para>
</entry><entry><para>For Instructions</para>
</entry>
</row>
</thead><tbody><row><entry><para>Determine if a file has an ACL</para>
</entry><entry><para><olink targetptr="secfile-17" remap="internal">How to Check if a File Has an ACL</olink></para>
</entry>
</row><row><entry><para>Add an ACL to a file</para>
</entry><entry><para><olink targetptr="secfile-51" remap="internal">How to Add ACL Entries to a File</olink></para>
</entry>
</row><row><entry><para>Copy an ACL</para>
</entry><entry><para><olink targetptr="secfile-75" remap="internal">How to Copy an ACL</olink></para>
</entry>
</row><row><entry><para>Modify an ACL</para>
</entry><entry><para><olink targetptr="secfile-48" remap="internal">How to Change ACL Entries on a File</olink></para>
</entry>
</row><row><entry><para>Remove ACLs from a file</para>
</entry><entry><para><olink targetptr="secfile-49" remap="internal">How to Delete ACL Entries From a File</olink></para>
</entry>
</row><row><entry><para>Display the ACLs on a file</para>
</entry><entry><para><olink targetptr="secfile-12" remap="internal">How to Display ACL Entries for a File</olink></para>
</entry>
</row>
</tbody>
</tgroup>
</informaltable><task id="secfile-17"><title>How to Check if a File Has an ACL</title><indexterm><primary>determining</primary><secondary>if file has ACL</secondary>
</indexterm><indexterm><primary>files</primary><secondary>determining if has ACL</secondary>
</indexterm><indexterm><primary>ACL</primary><secondary>checking entries</secondary>
</indexterm><indexterm><primary>files</primary><secondary>ACL entries</secondary><tertiary>checking</tertiary>
</indexterm><indexterm><primary>displaying</primary><secondary>ACL entries</secondary>
</indexterm><procedure remap="single-step"><step><para><indexterm><primary>ACL</primary><secondary>checking entries</secondary></indexterm>Check if a file has an ACL.</para><screen>% ls -l <replaceable>filename</replaceable></screen><para>where <replaceable>filename</replaceable> specifies the file or directory.</para><para>In the output, a plus sign (<literal>+</literal>) to the right of the
mode field indicates that the file has an ACL.</para><note><para><indexterm><primary>+ (plus sign)</primary><secondary>ACL entry</secondary></indexterm><indexterm><primary>plus sign (+)</primary><secondary>ACL entry</secondary></indexterm>Unless you have added ACL entries that extend UNIX file permissions,
a file is considered to have a &ldquo;trivial&rdquo; ACL and the plus sign
(<literal>+</literal>) does not display.</para>
</note>
</step>
</procedure><example id="secfile-42"><title>Checking if a File Has an ACL</title><para>In the following example, the <filename>ch1.sgm</filename> file has
an ACL. The ACL is indicated by the plus sign (<literal>+</literal>) to the
right of the mode field.</para><screen>% <userinput>ls -l ch1.sgm</userinput>
-rwxr-----+  1 stacey   techpubs      167 Nov 11 11:13 ch1.sgm</screen>
</example>
</task><task id="secfile-51"><title>How to Add ACL Entries to a File</title><indexterm><primary>files</primary><secondary>setting ACL</secondary>
</indexterm><indexterm><primary>using</primary><secondary>ACLs</secondary>
</indexterm><indexterm><primary><command>setfacl</command> command</primary><secondary>syntax</secondary>
</indexterm><indexterm><primary>ACL</primary><secondary>setting entries</secondary>
</indexterm><indexterm><primary>files</primary><secondary>ACL entries</secondary><tertiary>setting</tertiary>
</indexterm><indexterm><primary>group ACL entries</primary><secondary>setting</secondary>
</indexterm><indexterm><primary>user ACL entries</primary><secondary>setting</secondary>
</indexterm><indexterm><primary>mask ACL entries</primary><secondary>setting</secondary>
</indexterm><indexterm><primary>adding</primary><secondary>ACL entries</secondary>
</indexterm><procedure><step><para><indexterm><primary>ACL</primary><secondary>setting on a file</secondary></indexterm>Set an ACL on a file by using the <command>setfacl</command> command.</para><screen>% setfacl -s user::<replaceable>perms</replaceable>,group::<replaceable>perms</replaceable>,other:<replaceable>perms</replaceable>,mask:<replaceable>perms</replaceable>,<replaceable>acl-entry-list</replaceable> <replaceable>filename ...</replaceable></screen><variablelist><varlistentry><term><option>s</option></term><listitem><para>Sets an ACL on the file. If a file already has an ACL, it
is replaced. This option requires at least the <literal>user::</literal>, <literal>group::</literal>, and <literal>other::</literal> entries.</para>
</listitem>
</varlistentry><varlistentry><term><literal>user::</literal><replaceable>perms</replaceable></term><listitem><para>Specifies the file owner permissions.</para>
</listitem>
</varlistentry><varlistentry><term><literal>group::</literal><replaceable>perms</replaceable></term><listitem><para>Specifies the group ownership permissions.</para>
</listitem>
</varlistentry><varlistentry><term><literal>other:</literal><replaceable>perms</replaceable></term><listitem><para>Specifies the permissions for users other than the file owner
or members of the group.</para>
</listitem>
</varlistentry><varlistentry><term><literal>mask:</literal><replaceable>perms</replaceable></term><listitem><para>Specifies the permissions for the ACL mask. The mask indicates
the maximum permissions that are allowed for users (other than the owner)
and for groups.</para>
</listitem>
</varlistentry><varlistentry><term><replaceable>acl-entry-list</replaceable></term><listitem><para>Specifies the list of one or more ACL entries to set for specific
users and groups on the file or directory. You can also set default ACL entries
on a directory. <olink targetptr="secfile-35" remap="internal">Table&nbsp;7&ndash;7</olink> and <olink targetptr="secfile-52" remap="internal">Table&nbsp;7&ndash;8</olink> show the valid ACL entries.</para>
</listitem>
</varlistentry><varlistentry><term><replaceable>filename ...</replaceable></term><listitem><para>Specifies one or more files or directories on which to set
the ACL. Multiple <replaceable>filename</replaceable>s are separated by spaces.</para>
</listitem>
</varlistentry>
</variablelist><caution><para>If an ACL already exists on the file, the <option>s</option> option
replaces the entire ACL with the new ACL.</para>
</caution><para>For more information, see the <olink targetdoc="group-refman" targetptr="setfacl-1" remap="external"><citerefentry><refentrytitle>setfacl</refentrytitle><manvolnum>1</manvolnum></citerefentry></olink> man page.</para>
</step><step><para><indexterm><primary><command>getfacl</command> command</primary><secondary>verifying ACL entries</secondary></indexterm>Verify that the ACL entries were set on the file.</para><screen>% getfacl <replaceable>filename</replaceable></screen><para>For more information, see <olink targetptr="secfile-17" remap="internal">How to Check
if a File Has an ACL</olink>.</para>
</step>
</procedure><example id="secfile-31"><title>Setting an ACL on a File</title><para>In the following example, the file owner permissions are set to read
and write, file group permissions are set to read only, and other permissions
are set to none on the <filename>ch1.sgm</filename> file. In addition, the
user <literal>anusha</literal> is given read and write permissions on the
file. The ACL mask permissions are set to read and write, which means that
no user or group can have execute permissions.</para><screen>% <userinput>setfacl -s user::rw-,group::r--,other:---,mask:rw-,user:anusha:rw- ch1.sgm</userinput>
% <userinput>ls -l</userinput>
total 124
-rw-r-----+  1 stacey  techpubs   34816 Nov 11 14:16 ch1.sgm
-rw-r--r--   1 stacey  techpubs   20167 Nov 11 14:16 ch2.sgm
-rw-r--r--   1 stacey  techpubs    8192 Nov 11 14:16 notes
% <userinput>getfacl ch1.sgm</userinput>
# file: ch1.sgm
# owner: stacey
# group: techpubs
user::rw-
user:anusha:rw-    #effective:rw-
group::r--         #effective:r--
mask:rw-
other:---</screen><para>In the following example, the file owner permissions are set to read,
write, and execute, file group permissions are set to read only, other permissions
are set to none. In addition, the ACL mask permissions are set to read on
the <filename>ch2.sgm</filename> file. Finally, the user <literal>anusha</literal> is
given read and write permissions. However, due to the ACL mask, the permissions
for <literal>anusha</literal> are read only.</para><screen>% <userinput>setfacl -s u::7,g::4,o:0,m:4,u:anusha:7 ch2.sgm</userinput>
% <userinput>getfacl ch2.sgm</userinput>
# file: ch2.sgm
# owner: stacey
# group: techpubs
user::rwx
user:anusha:rwx         #effective:r--
group::r--              #effective:r--
mask:r--
other:---</screen>
</example>
</task><task id="secfile-75"><title>How to Copy an ACL</title><indexterm><primary>copying</primary><secondary>ACL entries</secondary>
</indexterm><indexterm><primary>files</primary><secondary>copying ACL entries</secondary>
</indexterm><indexterm><primary>ACL</primary><secondary>copying ACL entries</secondary>
</indexterm><procedure remap="single-step"><step><para>Copy a file's ACL to another file by redirecting the <command>getfacl</command> output.</para><screen>% getfacl <replaceable>filename1</replaceable> | setfacl -f - <replaceable>filename2</replaceable> </screen><variablelist><varlistentry><term><replaceable>filename1</replaceable></term><listitem><para>Specifies the file from which to copy the ACL.</para>
</listitem>
</varlistentry><varlistentry><term><replaceable>filename2</replaceable></term><listitem><para>Specifies the file on which to set the copied ACL.</para>
</listitem>
</varlistentry>
</variablelist>
</step>
</procedure><example id="secfile-32"><title>Copying an ACL</title><para><indexterm><primary><command>setfacl</command> command</primary><secondary><option>f</option> option</secondary></indexterm><indexterm><primary sortas="f1"><option>f</option> option</primary><secondary><command>setfacl</command> command</secondary></indexterm>In the following example, the ACL on <filename>ch2.sgm</filename> is
copied to <filename>ch3.sgm</filename>.</para><screen>% <userinput>getfacl ch2.sgm | setfacl -f - ch3.sgm</userinput></screen>
</example>
</task><task id="secfile-48"><title>How to Change ACL Entries on a File</title><indexterm><primary>changing</primary><secondary>ACL entries</secondary>
</indexterm><indexterm><primary>files</primary><secondary>changing ACL</secondary>
</indexterm><indexterm><primary>ACL</primary><secondary>changing entries</secondary>
</indexterm><indexterm><primary>files</primary><secondary>ACL entries</secondary><tertiary>adding or modifying</tertiary>
</indexterm><procedure><step><para><indexterm><primary>ACL</primary><secondary>modifying entries</secondary></indexterm>Modify ACL entries on a file by using the <command>setfacl</command> command.</para><screen>% setfacl -m <replaceable>acl-entry-list filename ...</replaceable> </screen><variablelist><varlistentry><term><option>m</option></term><listitem><para>Modifies the existing ACL entry.</para>
</listitem>
</varlistentry><varlistentry><term><replaceable>acl-entry-list</replaceable></term><listitem><para>Specifies the list of one or more ACL entries to modify on
the file or directory. You can also modify default ACL entries on a directory. <olink targetptr="secfile-35" remap="internal">Table&nbsp;7&ndash;7</olink> and <olink targetptr="secfile-52" remap="internal">Table&nbsp;7&ndash;8</olink> show the valid ACL entries.</para>
</listitem>
</varlistentry><varlistentry><term><replaceable>filename ...</replaceable></term><listitem><para>Specifies one or more files or directories, separated by a
space.</para>
</listitem>
</varlistentry>
</variablelist>
</step><step><para>Verify that the ACL entries were modified on the file.</para><screen>% getfacl <replaceable>filename</replaceable></screen>
</step>
</procedure><example id="secfile-33"><title>Modifying ACL Entries on a File</title><indexterm><primary><command>setfacl</command> command</primary><secondary>examples</secondary>
</indexterm><para>In the following example, the permissions for the user <literal>anusha</literal> are
modified to read and write.</para><screen>% <userinput>setfacl -m user:anusha:6 ch3.sgm</userinput>
% <userinput>getfacl ch3.sgm</userinput>
# file: ch3.sgm
# owner: stacey
# group: techpubs
user::rw-				
user::anusha:rw-        #effective:r--
group::r-               #effective:r--
mask:r--
other:r-</screen><para>In the following example, the default permissions for the group <literal>staff</literal> are modified to read on the <filename>book</filename> directory.
In addition, the default ACL mask permissions are modified to read and write.</para><screen>% <userinput>setfacl -m default:group:staff:4,default:mask:6 book</userinput></screen>
</example>
</task><task id="secfile-49"><title>How to Delete ACL Entries From a File</title><indexterm><primary>deleting</primary><secondary>ACL entries</secondary>
</indexterm><indexterm><primary>files</primary><secondary>deleting ACL</secondary>
</indexterm><indexterm><primary>ACL</primary><secondary>deleting entries</secondary>
</indexterm><indexterm><primary>removing</primary><secondary>ACL entries</secondary>
</indexterm><indexterm><primary>files</primary><secondary>ACL entries</secondary><tertiary>deleting</tertiary>
</indexterm><procedure><step><para>Delete ACL entries from a file.</para><screen>% setfacl -d <replaceable>acl-entry-list  filename ...</replaceable> </screen><variablelist><varlistentry><term><option>d</option></term><listitem><para>Deletes the specified ACL entries.</para>
</listitem>
</varlistentry><varlistentry><term><replaceable>acl-entry-list</replaceable></term><listitem><para>Specifies the list of ACL entries (without specifying the
permissions) to delete from the file or directory. You can only delete ACL
entries and default ACL entries for specific users and groups. <olink targetptr="secfile-35" remap="internal">Table&nbsp;7&ndash;7</olink> and <olink targetptr="secfile-52" remap="internal">Table&nbsp;7&ndash;8</olink> show the valid ACL entries.</para>
</listitem>
</varlistentry><varlistentry><term><replaceable>filename ...</replaceable></term><listitem><para>Specifies one or more files or directories, separated by a
space.</para>
</listitem>
</varlistentry>
</variablelist><para>Alternatively, you can use the <command>setfacl -s</command> command
to delete all the ACL entries on a file and replace them with the new ACL
entries that are specified.</para>
</step><step><para>Verify that the ACL entries were deleted from the file.</para><screen>% getfacl <replaceable>filename</replaceable></screen>
</step>
</procedure><example id="secfile-34"><title>Deleting ACL Entries on a File</title><para><indexterm><primary><command>setfacl</command> command</primary><secondary><option>d</option> option</secondary></indexterm><indexterm><primary><option>d</option> option</primary><secondary><command>setfacl</command> command</secondary></indexterm>In the following example, the user <literal>anusha</literal> is
deleted from the <filename>ch4.sgm</filename> file.</para><screen>% <userinput>setfacl -d user:anusha ch4.sgm</userinput></screen>
</example>
</task><task id="secfile-12"><title>How to Display ACL Entries for a File</title><indexterm><primary>displaying</primary><secondary>ACL entries</secondary>
</indexterm><indexterm><primary>viewing</primary><secondary>ACL entries</secondary>
</indexterm><indexterm><primary>files</primary><secondary>displaying ACL entries</secondary>
</indexterm><indexterm><primary>ACL</primary><secondary>displaying entries</secondary>
</indexterm><indexterm><primary>files</primary><secondary>ACL entries</secondary><tertiary>displaying</tertiary>
</indexterm><indexterm><primary><command>getfacl</command> command</primary><secondary>displaying ACL entries</secondary>
</indexterm><indexterm><primary><command>getfacl</command> command</primary><secondary>examples</secondary>
</indexterm><procedure remap="single-step"><step><para><indexterm><primary><command>getfacl</command> command</primary><secondary><option>a</option> option</secondary></indexterm><indexterm><primary><option>a</option> option</primary><secondary><command>getfacl</command> command</secondary></indexterm>Display ACL entries for a file by using the <command>getfacl</command> command.</para><screen>% getfacl [-a | -d] <replaceable>filename ...</replaceable></screen><variablelist><varlistentry><term><option>a</option></term><listitem><para>Displays the file name, file owner, file group, and ACL entries
for the specified file or directory.</para>
</listitem>
</varlistentry><varlistentry><term><option>d</option></term><listitem><para>Displays the file name, file owner, file group, and the default
ACL entries, if they exist, for the specified directory.</para>
</listitem>
</varlistentry><varlistentry><term><replaceable>filename ...</replaceable></term><listitem><para>Specifies one or more files or directories, separated by a
space.</para>
</listitem>
</varlistentry>
</variablelist><para>If you specify multiple file names on the command line, the ACL entries
are displayed with a blank line between each entry.</para>
</step>
</procedure><example id="secfile-41"><title>Displaying ACL Entries for a File</title><para>In the following example, all the ACL entries for the <filename>ch1.sgm</filename> file
are displayed. The <literal>#effective:</literal> note beside the user and
group entries indicates what the permissions are after being modified by the
ACL mask.</para><screen>% <userinput>getfacl ch1.sgm</userinput>

# file: ch1.sgm
# owner: stacey
# group: techpubs
user::rw-
user:anusha:r-        #effective:r--
group::rw-            #effective:rw-
mask:rw-
other:---</screen><para><indexterm><primary><command>getfacl</command> command</primary><secondary><option>d</option> option</secondary></indexterm><indexterm><primary><option>d</option> option</primary><secondary><command>getfacl</command> command</secondary></indexterm>In the following example, the default ACL entries for the <filename>book</filename> directory are displayed.</para><screen>% <userinput>getfacl -d book</userinput>

# file: book
# owner: stacey
# group: techpubs
user::rwx
user:anusha:r-x       #effective:r-x
group::rwx            #effective:rwx
mask:rwx
other:---
default:user::rw-
default:user:anusha:r--
default:group::rw-
default:mask:rw-
default:other:---</screen>
</example>
</task>
</sect1><sect1 id="secfile-40"><title>Protecting Against Programs With Security
Risk (Task Map)</title><indexterm><primary>protecting</primary><secondary>system from risky programs</secondary>
</indexterm><indexterm><primary>system security</primary><secondary>protecting from risky programs</secondary>
</indexterm><indexterm><primary>systems</primary><secondary>protecting from risky programs</secondary>
</indexterm><para><indexterm><primary>system security</primary><secondary>task map</secondary></indexterm><indexterm><primary>task maps</primary><secondary>protecting against programs with security risk</secondary></indexterm>The following task map points to procedures that find risky executables
on the system, and that prevent programs from exploiting an executable stack.</para><informaltable frame="all" pgwide="1"><tgroup cols="3" colsep="1" rowsep="1"><colspec colname="colspec0" colwidth="110*"/><colspec colname="col2" colwidth="167*"/><colspec colname="colspec1" colwidth="119*"/><thead><row><entry><para>Task</para>
</entry><entry><para>Description</para>
</entry><entry><para>For Instructions</para>
</entry>
</row>
</thead><tbody><row><entry><para>Find files with special permissions</para>
</entry><entry><para>Locates files with the <command>setuid</command> bit set, but that are
not owned by the <literal>root</literal> user.</para>
</entry><entry><para><olink targetptr="secfile-23" remap="internal">How to Find Files With Special File Permissions</olink></para>
</entry>
</row><row><entry><para>Prevent executable stack from overflowing</para>
</entry><entry><para>Prevents programs from exploiting an executable stack.</para>
</entry><entry><para><olink targetptr="secfile-71" remap="internal">How to Disable Programs From Using Executable
Stacks</olink></para>
</entry>
</row><row><entry><para>Prevent logging of executable stack messages</para>
</entry><entry><para>Turns off logging of executable stack messages.</para>
</entry><entry><para><olink targetptr="secfile-70" remap="internal">Example&nbsp;7&ndash;13</olink></para>
</entry>
</row>
</tbody>
</tgroup>
</informaltable><task id="secfile-23"><title>How to Find Files With Special File
Permissions</title><tasksummary><para><indexterm><primary>files</primary><secondary>finding files with <command>setuid</command> permissions</secondary></indexterm><indexterm><primary><command>find</command> command</primary><secondary>finding files with <command>setuid</command> permissions</secondary></indexterm><indexterm><primary>permissions</primary><secondary>finding files with <command>setuid</command> permissions</secondary></indexterm><indexterm><primary>determining</primary><secondary>files with <command>setuid</command> permissions</secondary></indexterm><indexterm><primary><command>setuid</command> permissions</primary><secondary>finding files with permissions set</secondary></indexterm>You should monitor your system for any unauthorized use of the <command>setuid</command> and <command>setgid</command> permissions on programs. The <command>setuid</command> and <command>setgid</command> permissions enable ordinary
users to gain superuser capabilities. A suspicious executable file grants
ownership to a user rather than to <literal>root</literal> or <literal>bin</literal>.</para>
</tasksummary><procedure>&rolePAstep;<step><para>Find files with <command>setuid</command> permissions by using
the <command>find</command> command.</para><screen># find <replaceable>directory</replaceable> -user root -perm -4000 -exec ls -ldb {} \; &gt;/tmp/<replaceable>filename</replaceable></screen><variablelist><varlistentry><term><command>find</command> <replaceable>directory</replaceable></term><listitem><para>Checks all mounted paths starting at the specified <replaceable>directory</replaceable>, which can be root (<filename>/</filename>), <filename>sys</filename>, <filename>bin</filename>, or <filename>mail</filename>.</para>
</listitem>
</varlistentry><varlistentry><term><option>user</option> <literal>root</literal></term><listitem><para>Displays files owned only by <literal>root</literal>.</para>
</listitem>
</varlistentry><varlistentry><term><option>perm</option> <option>4000</option></term><listitem><para>Displays files only with permissions set to <literal>4000</literal>.</para>
</listitem>
</varlistentry><varlistentry><term><option>exec</option> <command>ls</command> <option>ldb</option></term><listitem><para>Displays the output of the <command>find</command> command
in  <command>ls -ldb</command> format.</para>
</listitem>
</varlistentry><varlistentry><term><filename>&gt;/tmp/</filename><replaceable>filename</replaceable></term><listitem><para>Is the file that contains the results of the <command>find</command> command.</para>
</listitem>
</varlistentry>
</variablelist>
</step><step><para>Display the results in <filename>/tmp/</filename><replaceable>filename</replaceable>.</para><screen># more <filename>/tmp/</filename><replaceable>filename</replaceable></screen><para>For background information on <command>setuid</command> permissions,
see <olink targetptr="secfile-64" remap="internal">setuid Permission</olink>.</para>
</step>
</procedure><example id="secfile-36"><title>Finding Files With <command>setuid</command> Permissions</title><para>The output from the following example shows that a user named <literal>rar</literal> has
made a personal copy of <filename>/usr/bin/sh</filename>, and has set the
permissions as <command>setuid</command> to <literal>root</literal>. As a
result, the <filename>/usr/rar/bin/sh</filename> program runs with <literal>root</literal> permissions. </para><para>This output was saved for future reference by moving the file out of
the <filename>/tmp</filename> directory.</para><screen># <userinput>find / -user root -perm -4000 -exec ls -ldb {} \; &gt; /var/tmp/ckprm</userinput>
# <userinput>cat /var/tmp/ckprm</userinput>
-r-sr-xr-x 1 root bin 38836 Aug 10 16:16 /usr/bin/at
-r-sr-xr-x 1 root bin 19812 Aug 10 16:16 /usr/bin/crontab
---s--x--x 1 root sys 46040 Aug 10 15:18 /usr/bin/ct
-r-sr-xr-x 1 root sys 12092 Aug 11 01:29 /usr/lib/mv_dir
-r-sr-sr-x 1 root bin 33208 Aug 10 15:55 /usr/lib/lpadmin
-r-sr-sr-x 1 root bin 38696 Aug 10 15:55 /usr/lib/lpsched
---s--x--- 1 root rar 45376 Aug 18 15:11 /usr/rar/bin/sh
-r-sr-xr-x 1 root bin 12524 Aug 11 01:27 /usr/bin/df
-rwsr-xr-x 1 root sys 21780 Aug 11 01:27 /usr/bin/newgrp
-r-sr-sr-x 1 root sys 23000 Aug 11 01:27 /usr/bin/passwd
-r-sr-xr-x 1 root sys 23824 Aug 11 01:27 /usr/bin/su
# <userinput>mv /var/tmp/ckprm /export/sysreports/ckprm</userinput></screen>
</example>
</task><task id="secfile-71"><title>How to Disable Programs From Using Executable
Stacks</title><indexterm><primary>disabling</primary><secondary>programs from using executable stacks</secondary>
</indexterm><indexterm><primary>disabling</primary><secondary>executable stacks</secondary>
</indexterm><indexterm><primary>executable stacks</primary><secondary>protecting against</secondary>
</indexterm><tasksummary><para>For a description of the security risks of executable stacks, see <olink targetptr="secfile-68" remap="internal">Preventing Executable Files From Compromising Security</olink>.</para>
</tasksummary><procedure>&rolePAstep;<step><para><indexterm><primary><literal>noexec_user_stack</literal> variable</primary></indexterm><indexterm><primary>system variables</primary><secondary><literal>noexec_user_stack</literal></secondary></indexterm>Edit the <filename>/etc/system</filename> file, and add the following
line:</para><screen>set noexec_user_stack=1</screen>
</step><step><para>Reboot the system.</para><screen># <userinput>init 6</userinput></screen>
</step>
</procedure><example id="secfile-70"><title>Disabling the Logging of Executable Stack Messages</title><indexterm><primary>disabling</primary><secondary>logging of executable stack messages</secondary>
</indexterm><indexterm><primary>executable stacks</primary><secondary>disabling logging messages</secondary>
</indexterm><indexterm><primary><literal>noexec_user_stack_log</literal> variable</primary>
</indexterm><indexterm><primary>system variables</primary><secondary><literal>noexec_user_stack_log</literal></secondary>
</indexterm><para>In this example, the logging of executable stack messages is disabled,
and then the system is rebooted.</para><screen># <userinput>cat /etc/system</userinput>
set noexec_user_stack=1
<userinput>set noexec_user_stack_log=0</userinput>
# <userinput>init 6</userinput></screen>
</example>
</task>
</sect1>
</chapter><?Pub *0000106325 0?>