## The File Security System

Every file (including directory files) has properties called ownership and attributes which determine who may access the file and how it many be used.

OS-9 automatically stores with each file the user number associated with the process that created it. This user is considered to be the “owner” of the file.

Usage and security functions are based on “attributes”, which define how and by whom the file can be accessed. There are a total of seven attributes, each of which can be turned “off” or “on” independently. The “d” attribute is used to indicate (when on) that the file is a directory file. The other six attributes control whether the file can be read, written to, or executed, by either the owner or by the “public” (all other users). Specifically, these six attributes are:

WRITE PERMISSION FOR OWNER: If on, the owner may write to the file or delete it. This permission can be used to protect important files from accidental deletion or modification.

READ PERMISSION FOR OWNER: If on, the owner is allowed to read from the file. This can be used to prevent “binary” files from being used as “text” files

EXECUTE PERMISSION FOR OWNER: If on, the owner can load the file into memory and execute it. Note that the file must contain one or more valid OS-9 format memory modules in order to actually load

The following “public permissions” work the same way as the “owner permissions” above but are applied to processes having DIFFERENT user numbers than the file's owner.

WRITE PERMISSION FOR PUBLIC - If on, any other user may write to or delete the file.

READ PERMISSION FOR PUBLIC - If on, any other user may read (and possibly copy) the file.

EXECUTE PERMISSION FOR PUBLIC - If on, any other user may execute the file.

For example, if a particular file had all permissions on except “write permit to public” and “read permit to public”, the owner would have unrestricted access to the file, but other users could execute it, but not read, copy, delete, or alter it.

### Examining and Changing File Attributes

The dir command may be used to examine the security permissions of the files in any particular directory when the “e” option is used. An example using the dir e command to show the detailed attributes of the files in the current working directory is:

       Directory of .  10:20:44

    Owner Last Modified Attributes Sector Bytecount Name
    ----- ------------- ---------- ------ --------- ----
       1  81/05/29 1402  --e--e-r      47        42 file1
       0  81/10/12 0215  ---wr-wr      48        43 file2
       3  81/04/29 2335  -s----wr      51        22 file3
       1  82/01/06 1619  d-ewrewr      6D       800 NEWDIR

This display is fairly self-explanatory. The “attributes” column shows which attributes are currently on by the presence or absence of associated characters in the following format:

dsewrewr

The character positions correspond to from left to right: directory; sharable; public execute; public write; public read; owner execute; owner write; owner read. The attr command is used to examine or change a file's attributes. Typing attr followed by a file name will result in the present attributes to be displayed, for example:

    OS9: attr file2
    -s-wr-ewr

If the command is used with a list of one or more attribute abbreviations, the file's attributes will be changed accordingly (if legal). For example, the command:

    OS9: attr file2 pw pr -e -pe

enables public write and public read permissions and removes execute permission for both the owner and the public.

The “directory” attribute behaves somewhat differently than the read, write, and execute permissions. This is because it would be quite dangerous to be able to change directory files to normal files, and creation of a directory requires special initialization. Therefore, the attr command cannot be used to turn the directory (d) attribute on (only makdir can), and can be used to turn it off only if the directory is empty.