update for rename of docs/user/DebugKernelCrashDumps.mdwn to docs/user/list/DebugKern...
[ikiwiki.git] / docs / handbook / handbook-permissions.mdwn
1 \r
2 \r
3 ## Permissions \r
4 \r
5 DragonFly, being a direct descendant of BSD UNIX®, is based on several key UNIX concepts. The first and most pronounced is that DragonFly is a multi-user operating system. The system can handle several users all working simultaneously on completely unrelated tasks. The system is responsible for properly sharing and managing requests for hardware devices, peripherals, memory, and CPU time fairly to each user.\r
6 \r
7 Because the system is capable of supporting multiple users, everything the system manages has a set of permissions governing who can read, write, and execute the resource. These permissions are stored as three octets broken into three pieces, one for the owner of the file, one for the group that the file belongs to, and one for everyone else. This numerical representation works like this:\r
8 \r
9 [[!table  data="""
10 |<tablestyle="width:100%"> Value | Permission | Directory Listing 
11 <tablestyle="width:100%"> 0 | No read, no write, no execute | `---` 
12  1 | No read, no write, execute | `--x` 
13  2 | No read, write, no execute | `-w-` 
14  3 | No read, write, execute | `-wx` 
15  4 | Read, no write, no execute | `r--` 
16  5 | Read, no write, execute | `r-x` 
17  6 | Read, write, no execute | `rw-` 
18  7 | Read, write, execute | `rwx` |\r
19 """]]\r
20 You can use the `-l` command line argument to [ls(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#ls&amp;section1) to view a long directory listing that includes a column with information about a file's permissions for the owner, group, and everyone else. For example, a `ls -l` in an arbitrary directory may show:\r
21 \r
22     \r
23     % ls -l\r
24     total 530\r
25     -rw-r--r--  1 root  wheel     512 Sep  5 12:31 myfile\r
26     -rw-r--r--  1 root  wheel     512 Sep  5 12:31 otherfile\r
27     -rw-r--r--  1 root  wheel    7680 Sep  5 12:31 email.txt\r
28     ...\r
29 \r
30 \r
31 Here is how the first column of `ls -l` is broken up:\r
32 \r
33     \r
34     -rw-r--r--\r
35 \r
36 \r
37 The first (leftmost) character tells if this file is a regular file, a directory, a special character device, a socket, or any other special pseudo-file device. In this case, the `-` indicates a regular file. The next three characters, `rw-` in this example, give the permissions for the owner of the file. The next three characters, `r--`, give the permissions for the group that the file belongs to. The final three characters, `r--`, give the permissions for the rest of the world. A dash means that the permission is turned off. In the case of this file, the permissions are set so the owner can read and write to the file, the group can read the file, and the rest of the world can only read the file. According to the table above, the permissions for this file would be `644`, where each digit represents the three parts of the file's permission.\r
38 \r
39 This is all well and good, but how does the system control permissions on devices? DragonFly actually treats most hardware devices as a file that programs can open, read, and write data to just like any other file. These special device files are stored on the `/dev` directory.\r
40 \r
41 Directories are also treated as files. They have read, write, and execute permissions. The executable bit for a directory has a slightly different meaning than that of files. When a directory is marked executable, it means it can be traversed into, that is, it is possible to ***cd*** (change directory) into it. This also means that within the directory it is possible to access files whose names are known (subject, of course, to the permissions on the files themselves).\r
42 \r
43 In particular, in order to perform a directory listing, read permission must be set on the directory, whilst to delete a file that one knows the name of, it is necessary to have write ***and*** execute permissions to the directory containing the file.\r
44 \r
45 There are more permission bits, but they are primarily used in special circumstances such as setuid binaries and sticky directories. If you want more information on file permissions and how to set them, be sure to look at the [chmod(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#chmod&amp;section1) manual page.\r
46 \r
47 ### Symbolic Permissions \r
48 \r
49 ***Contributed by Tom Rhodes. ***\r
50 \r
51 Symbolic permissions, sometimes referred to as symbolic expressions, use characters in place of octal values to assign permissions to files or directories. Symbolic expressions use the syntax of (who) (action) (permissions), where the following values are available:\r
52 \r
53 [[!table  data="""
54 |<tablestyle="width:100%"> Option | Letter | Represents 
55 <tablestyle="width:100%"> (who) | u | User 
56  (who) | g | Group owner 
57  (who) | o | Other 
58  (who) | a | All (***world***) 
59  (action) | + | Adding permissions 
60  (action) | - | Removing permissions 
61  (action) | = | Explicitly set permissions 
62  (permissions) | r | Read 
63  (permissions) | w | Write 
64  (permissions) | x | Execute 
65  (permissions) | t | Sticky bit 
66  (permissions) | s | Set UID or GID |\r
67 """]]\r
68 These values are used with the [chmod(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#chmod&amp;section1) command just like before, but with letters. For an example, you could use the following command to block other users from accessing `FILE`:\r
69 \r
70     \r
71     % chmod go=FILE\r
72 \r
73 \r
74 A comma separated list can be provided when more than one set of changes to a file must be made. For example the following command will remove the groups and ***world*** write permission on `FILE`, then it adds the execute permissions for everyone:\r
75 \r
76     \r
77     % chmod go-w,a+x FILE\r
78 \r
79 \r
80 ### DragonFly File Flags \r
81 \r
82 ***Contributed by Tom Rhodes. ***\r
83 \r
84 In addition to file permissions discussed previously, DragonFly supports the use of ***file flags.*** These flags add an additional level of security and control over files, but not directories. These file flags add an additional level of control over files, helping to ensure that in some cases not even the `root` can remove or alter files.  File flags are altered by using the [chflags(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#chflags&amp;section1) utility, using a simple interface. For example, to enable the system undeletable flag on the file `file1`, issue the following command:\r
85 \r
86     \r
87     # chflags sunlink file1\r
88 \r
89 \r
90 And to disable the system undeletable flag, simply issue the previous command with ***no*** in front of the `sunlink`. Observe:\r
91 \r
92     \r
93     # chflags nosunlink file1\r
94 \r
95 \r
96 To view the flags of this file, use the [ls(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#ls&amp;section1) with the `-lo` flags:\r
97 \r
98     \r
99     # ls -lo file1\r
100 \r
101 \r
102 The output should look like the following:\r
103 \r
104     \r
105     -rw-r--r--  1 trhodes  trhodes  sunlnk 0 Mar  1 05:54 file1\r
106 \r
107 \r
108 Several flags may only added or removed to files by the `root` user. In other cases, the file owner may set these flags. It is recommended an administrator read over the [chflags(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#chflags&amp;section1) and [chflags(2)](http://leaf.dragonflybsd.org/cgi/web-man?command=chflags&amp;section=2) manual pages for more information.\r