Programming Search⌘K

Conceptcore

File permissions

Also called permission bits, file mode, mode bits, chmod, umask, setuid, sticky bit, access control list, ACL, read-only attribute.

File permissions say who can read, write or execute a file. Unix keeps nine mode bits for the owner, the group and the others, with a umask for new files. Windows uses ACLs.

Applies to
core-languages

Idea

A system with many users must decide who can use each file. Unix gives each file an owner and a group, and nine bits: read, write and execute for the owner, for the members of the group, and for all other users. A process gets the access of the first class that it belongs to. A mask, the umask, removes bits from each new file, so a program can ask for wide permissions and the user can make them narrower.

import os
import stat

def show(path):
    m = os.stat(path).st_mode
    print(f"{path:8} {stat.S_IMODE(m):04o} {stat.filemode(m)}")

# The umask removes bits from the mode that the program asks for.
old = os.umask(0o027)
fd = os.open("new.txt", os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o666)
os.close(fd)
os.mkdir("dir", 0o777)
os.umask(old)
show("new.txt")
show("dir")

# chmod sets the bits as they are; the umask does not apply.
os.chmod("new.txt", 0o755)
show("new.txt")

# Three more bits: set-user-ID, set-group-ID and sticky.
os.chmod("new.txt", 0o4755)
os.chmod("dir", 0o1777)
show("new.txt")
show("dir")
Output
new.txt  0640 -rw-r-----
dir      0750 drwxr-x---
new.txt  0755 -rwxr-xr-x
new.txt  4755 -rwsr-xr-x
dir      1777 drwxrwxrwt

The program asks for the mode 0666 for a new file and 0777 for a new directory, but the umask 027 removes the write bit of the group and all of the bits of the others. So the file gets 0640 and the directory gets 0750. chmod then sets the mode as it is. Each octal digit is one class: 7 is read, write and execute, 5 is read and execute, and 4 is read only. The fourth digit holds the set-user-ID bit, shown as s, and the sticky bit, shown as t.

How it works

The nine bits. POSIX names each bit in <sys/stat.h>, from S_IRUSR to S_IXOTH1. For the three classes, "The file permission bits of a file contain read, write, and execute/search permissions for the file owner class, file group class, and file other class"2. Access "shall be granted if an alternate access control mechanism is not enabled and the requested access permission bit is set for the class (file owner class, file group class, or file other class) to which the process belongs"2. A process is in only one class. If it is the owner, the owner bits apply, even when the group bits give more.

Directories. On a directory, the bits mean other things. Read lets a process list the names. Write lets it make, rename and remove entries. Execute is "search", which "applies for directories, and means that entries within the directory can be accessed"6. So a file in a directory without the search bit cannot be opened, whatever its own bits are.

The three special bits. The mode has three more bits. S_ISUID is "Set-user-ID on execution", S_ISGID is "Set-group-ID on execution", and S_ISVTX is, "On directories, restricted deletion flag"1. A program with the set-user-ID bit runs with the user ID of the owner of the file, not of the user who starts it. The sticky bit on a directory "means that a file in that directory can be renamed or deleted only by the owner of the file, by the owner of the directory, and by a privileged process"5.

The umask. Each process has a file mode creation mask. POSIX says that "The file mode creation mask of the process is used to turn off permission bits in the mode argument supplied during calls to the following functions"4, which include open, creat and mkdir. A program asks for 0666 for a data file and 0777 for a directory or a program, and the umask of the user makes them narrower. The umask does not change existing files.

chmod. chmod changes the special bits "and the file permission bits of the file named by the pathname pointed to by the path argument to the corresponding bits in the mode argument"3. Only the owner or a privileged process can do this: "If the effective user ID of the process does not match the owner of the file and the process does not have appropriate privileges, the chmod () function shall fail"3.

Privileged processes. The root user does not need the bits. POSIX says that for a process with appropriate privileges, "If read, write, or directory search permission is requested, access shall be granted"2. Execute is the exception: it is granted only "if execute permission is granted to at least one user by the file permission bits or by an alternate access control mechanism"2.

Access control lists. Nine bits cannot give access to one more user. POSIX ACLs "are used to define more fine-grained discretionary access rights for files and directories"7. "An ACL entry specifies the access permissions on the associated object for an individual user or a group of users as a combination of read, write and search/execute permissions"7. A directory can also have a default ACL for the files that are made in it7.

Windows. Windows does not use mode bits. A file has a security descriptor, and its discretionary ACL "identifies the trustees that are allowed or denied access to a securable object"9. "If the object doesn't have a DACL, the system grants full access to everyone"9. Windows also has the read-only attribute: "Applications can read the file, but cannot write to it or delete it. This attribute is not honored on directories"10.

In languages

LanguageVerdictNote
PythonStandard library
C++Standard library
JavaStandard library
CLibrary
C#Standard library
JavaScriptStandard library
TypeScriptStandard libraryTypeScript on Node.js uses the node:fs module, with the types from @types/node, so chmod, access and process.umask are the same as in the JavaScript example. No example file exists.
GoStandard library
RustStandard library
KotlinStandard libraryKotlin on the JVM uses java.nio.file, and the kotlin.io.path package adds getPosixFilePermissions and setPosixFilePermissions as extensions of Path, so the PosixFilePermission set of the Java example does the work. No example file exists because kotlinc is not installed.
SQLDoes not applySQL has permissions on tables and other database objects, with GRANT and REVOKE, but it has no operations on the permissions of files.
BashNativeThe chmod command takes octal modes such as 640 and symbolic modes such as u+x, the umask builtin sets the mask of the shell, and the tests -r, -w and -x check the access of the shell. No example file exists.
PowerShellNativeGet-Acl and Set-Acl read and write the ACL of a file on Windows, and the IsReadOnly property of a FileInfo object sets the read-only attribute. On Unix, the chmod command and the UnixFileMode API of .NET do the work. No example file exists because pwsh is not installed.
HTMLDoes not applyA web page cannot read or set the permissions of a local file. The browser decides which files a page can see.
CSSDoes not applyStyle rules do not read files or their permissions.
Regular expressionsDoes not applyA regular expression matches text. It does not read or set the permissions of a file.
Language Verdict Mechanism
Python stdlib os.chmod, os.umask, os.access, the stat constants; shutil.copymode; on Windows only the read-only flag
JavaScript stdlib Node.js fs.chmod, fs.access, process.umask, fs.constants
TypeScript stdlib the node:fs module of Node.js, with the types of @types/node
Java stdlib PosixFilePermission and PosixFilePermissions; AclFileAttributeView for Windows ACLs
Kotlin stdlib kotlin.io.path extensions such as setPosixFilePermissions on java.nio.file.Path
C# stdlib UnixFileMode with File.SetUnixFileMode; FileAttributes.ReadOnly; FileStreamOptions.UnixCreateMode
Go stdlib os.Chmod with fs.FileMode; fs.ModeSetuid, fs.ModeSticky; syscall.Umask on Unix
Rust stdlib fs::Permissions with readonly; std::os::unix::fs::PermissionsExt for the mode bits
C library ISO C has no permissions; POSIX chmod, fchmod, umask, access and the mode argument of open
C++ stdlib std::filesystem::perms, permissions with perm_options::replace, add and remove
Bash native the chmod and umask commands; the tests -r, -w and -x
PowerShell native Get-Acl and Set-Acl on Windows; the IsReadOnly property of FileInfo
SQL n/a GRANT and REVOKE work on database objects, not on files
Regex n/a a pattern matches text and does not read files
HTML n/a a page cannot read or set the permissions of a local file
CSS n/a style rules do not read files

The languages split into two groups. Python, Node.js, C, Go and Rust's PermissionsExt use the Unix mode as a number. Java, .NET and C++ give the bits names: Java's enum "Defines the bits for use with the permissions attribute"14, .NET's UnixFileMode "Represents the Unix filesystem permissions"16, and C++'s perms "represents file access permissions"20. Go keeps its own layout: "The bits have the same definition on all systems, so that information about files can be moved from one system to another portably"18. Python's stat.S_IMODE returns "the file's permission bits, plus the sticky bit, set-group-id, and set-user-id bits"12.

The portable forms are small, because Windows has no mode bits. On Windows, Python's chmod can "only set the file's read-only flag"11, and in Node.js, "on Windows only the write permission can be changed"13. In .NET, "ReadOnly is supported on Windows, Linux, and macOS. On Linux and macOS, changing the ReadOnly flag is a permissions operation"17. For a full Windows ACL, Java has AclFileAttributeView, "A file attribute view that supports reading or updating a file's Access Control Lists (ACL) or file owner attributes"15.

The example files show the bits in each language: the stat constants and copymode of Python, the umask and access of Node.js, the PosixFilePermission set of Java, the UnixFileMode flags and UnixCreateMode of .NET, Go's own setuid and sticky bits, the set_readonly trap of Rust, the s and S of a setuid bit in C, and the add and remove options of C++.

PythonGitHub
import os
import shutil
import stat
from pathlib import Path

Path("a.txt").write_text("a", encoding="utf-8")
Path("b.txt").write_text("b", encoding="utf-8")

# The stat module names each bit. OR them to make a mode.
mode = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP
os.chmod("a.txt", mode)
st = os.stat("a.txt")
print("mode:", oct(stat.S_IMODE(st.st_mode)), stat.filemode(st.st_mode))

# Test one bit with &.
print("group can write:", bool(st.st_mode & stat.S_IWGRP))
print("owner can read:", bool(st.st_mode & stat.S_IRUSR))

# Add a bit to the current mode, as chmod u+x does.
os.chmod("a.txt", stat.S_IMODE(st.st_mode) | stat.S_IXUSR)
print("after u+x:", stat.filemode(os.stat("a.txt").st_mode))

# copymode copies only the permission bits to another file.
shutil.copymode("a.txt", "b.txt")
print("b.txt:", stat.filemode(os.stat("b.txt").st_mode))
Output
mode: 0o640 -rw-r-----
group can write: False
owner can read: True
after u+x: -rwxr-----
b.txt: -rwxr-----
  • Verdict: stdlib. The stat module has a constant for each bit, such as S_IRUSR and S_IXGRP, and S_IMODE keeps only the permission bits of st_mode. os.chmod sets the whole mode, so a program that adds one bit reads the mode first. shutil.copymode copies the permission bits from one file to another. On Windows, os.chmod can change only the read-only flag.
#include <filesystem>
#include <fstream>
#include <iostream>
#include <string>

namespace fs = std::filesystem;

static std::string text(fs::perms p) {
    std::string s;
    for (auto [bit, c] : {std::pair{fs::perms::owner_read, 'r'}, {fs::perms::owner_write, 'w'},
                          {fs::perms::owner_exec, 'x'}, {fs::perms::group_read, 'r'},
                          {fs::perms::group_write, 'w'}, {fs::perms::group_exec, 'x'},
                          {fs::perms::others_read, 'r'}, {fs::perms::others_write, 'w'},
                          {fs::perms::others_exec, 'x'}})
        s += (p & bit) != fs::perms::none ? c : '-';
    return s;
}

int main() {
    std::ofstream("data.txt") << "x";
    using fs::perms;

    // replace sets all of the bits, as chmod 640 does.
    fs::permissions("data.txt", perms::owner_read | perms::owner_write | perms::group_read);
    std::cout << "replace: " << text(fs::status("data.txt").permissions()) << "\n";

    // add and remove change only the given bits, as chmod u+x and g-r do.
    fs::permissions("data.txt", perms::owner_exec, fs::perm_options::add);
    std::cout << "add:     " << text(fs::status("data.txt").permissions()) << "\n";
    fs::permissions("data.txt", perms::group_read, fs::perm_options::remove);
    std::cout << "remove:  " << text(fs::status("data.txt").permissions()) << "\n";

    // perms has the octal values of POSIX.
    std::cout << "octal:   " << std::oct << static_cast<unsigned>(perms::owner_all) << " "
              << static_cast<unsigned>(perms::set_uid) << "\n";
}
Output
replace: rw-r-----
add:     rwxr-----
remove:  rwx------
octal:   700 4000
  • Verdict: stdlib. std::filesystem::perms is a bitmask type whose values are the POSIX bits, such as owner_read with the value 0400 and set_uid with the value 04000. permissions takes a perm_options value: replace sets all of the bits, and add and remove change only the given bits, so the program does not read the mode first. The standard has no umask and no ACLs.
JavaGitHub
import java.nio.file.*;
import java.nio.file.attribute.*;
import java.util.Set;

public class Main {
    public static void main(String[] args) throws Exception {
        Path p = Files.writeString(Path.of("data.txt"), "x");

        // A permission set is a Set of enum values.
        Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rw-r-----");
        Files.setPosixFilePermissions(p, perms);
        System.out.println("set: " + PosixFilePermissions.toString(Files.getPosixFilePermissions(p)));

        // Add one permission, as chmod u+x does.
        Set<PosixFilePermission> now = Files.getPosixFilePermissions(p);
        now.add(PosixFilePermission.OWNER_EXECUTE);
        Files.setPosixFilePermissions(p, now);
        System.out.println("after u+x: " + PosixFilePermissions.toString(Files.getPosixFilePermissions(p)));
        System.out.println("contains GROUP_WRITE: " + now.contains(PosixFilePermission.GROUP_WRITE));

        // The unix view gives the mode as a number, with the type bits.
        int mode = (Integer) Files.getAttribute(p, "unix:mode");
        System.out.println("unix:mode & 07777 = " + Integer.toOctalString(mode & 07777));

        // The views that the file system supports.
        Set<String> views = p.getFileSystem().supportedFileAttributeViews();
        System.out.println("posix view: " + views.contains("posix") + ", acl view: " + views.contains("acl"));
    }
}
Output
set: rw-r-----
after u+x: rwxr-----
contains GROUP_WRITE: false
unix:mode & 07777 = 740
posix view: true, acl view: false
  • Verdict: stdlib. PosixFilePermission is an enum with nine values, such as OWNER_READ and OTHERS_EXECUTE, and a set of them is the permission bits of a file. PosixFilePermissions.fromString and toString use the form of ls. The enum has no setuid, setgid or sticky bit, but the unix:mode attribute gives the whole mode as a number. On Windows, the file system has the acl view and not the posix view.
#define _POSIX_C_SOURCE 200809L
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>

static void show(const char *path) {
    struct stat st;
    stat(path, &st);
    char s[10] = "---------";
    const mode_t bits[9] = {S_IRUSR, S_IWUSR, S_IXUSR, S_IRGRP, S_IWGRP,
                            S_IXGRP, S_IROTH, S_IWOTH, S_IXOTH};
    for (int i = 0; i < 9; i++)
        if (st.st_mode & bits[i]) s[i] = "rwx"[i % 3];
    if (st.st_mode & S_ISUID) s[2] = (st.st_mode & S_IXUSR) ? 's' : 'S';
    printf("%-9s %04o %s\n", path, (unsigned)(st.st_mode & 07777), s);
}

int main(void) {
    // The umask removes bits from the mode argument of open and mkdir.
    mode_t old = umask(027);
    int fd = open("new.txt", O_WRONLY | O_CREAT | O_EXCL, 0666);
    close(fd);
    mkdir("dir", 0777);
    umask(old);
    show("new.txt");
    show("dir");

    // chmod sets the whole mode, with no umask.
    chmod("new.txt", 04755);
    show("new.txt");
    chmod("new.txt", 04644);
    show("new.txt");

    // access asks about the real user; no execute bit means no X_OK.
    printf("X_OK: %d\n", access("new.txt", X_OK));
    return 0;
}
Output
new.txt   0640 rw-r-----
dir       0750 rwxr-x---
new.txt   4755 rwsr-xr-x
new.txt   4644 rwSr--r--
X_OK: -1
  • Verdict: library. ISO C has no permissions. POSIX gives chmod, fchmod, umask and the mode argument of open and mkdir, with the bit names of <sys/stat.h>. The umask applies to new files only, and chmod sets the mode as it is. ls writes a setuid bit as s when the owner can execute the file, and as S when the owner cannot.
using System;
using System.IO;

File.WriteAllText("data.txt", "x");

// UnixFileMode is a set of flags with the octal values of Unix.
var mode = UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.GroupRead;
File.SetUnixFileMode("data.txt", mode);
Console.WriteLine($"mode: {Convert.ToString((int)File.GetUnixFileMode("data.txt"), 8)}");

// The read-only attribute removes the write bits on Unix.
var info = new FileInfo("data.txt");
info.IsReadOnly = true;
info.Refresh();
Console.WriteLine($"read-only: {info.IsReadOnly}, mode {Convert.ToString((int)info.UnixFileMode, 8)}");
info.IsReadOnly = false;
info.Refresh();
Console.WriteLine($"writable:  {!info.IsReadOnly}, mode {Convert.ToString((int)info.UnixFileMode, 8)}");

// A new file can get its mode at creation, through FileStreamOptions.
var options = new FileStreamOptions {
    Mode = FileMode.CreateNew, Access = FileAccess.Write,
    UnixCreateMode = UnixFileMode.UserRead | UnixFileMode.UserWrite,
};
using (new FileStream("secret.txt", options)) { }
Console.WriteLine($"secret.txt: {File.GetUnixFileMode("secret.txt")}");
Output
mode: 640
read-only: True, mode 440
writable:  True, mode 640
secret.txt: UserWrite, UserRead
  • Verdict: stdlib. UnixFileMode is an enum of flags whose values are the Unix bits, and File.SetUnixFileMode and File.GetUnixFileMode work on Unix only. FileInfo.IsReadOnly uses the read-only attribute of Windows, and on Unix, .NET maps it to the write bits. FileStreamOptions.UnixCreateMode gives the mode of a new file, and the umask of the process still removes bits from it.
JavaScriptGitHub
const fs = require("node:fs");

// The umask removes bits from the mode of each new file.
const old = process.umask(0o027);
fs.writeFileSync("new.txt", "x", { mode: 0o666 });
const show = (p) => (fs.statSync(p).mode & 0o7777).toString(8).padStart(4, "0");
console.log("new file with umask 027:", show("new.txt"));
process.umask(old);

// chmod takes a number or a string of octal digits.
fs.chmodSync("new.txt", "755");
console.log("after chmod 755:", show("new.txt"));

// fs.constants has the bits by name.
const { S_IXGRP, S_IXOTH } = fs.constants;
fs.chmodSync("new.txt", (fs.statSync("new.txt").mode & 0o777) & ~(S_IXGRP | S_IXOTH));
console.log("after go-x:", show("new.txt"));

// access with X_OK fails when no class has the execute bit.
fs.writeFileSync("data.txt", "x");
fs.chmodSync("data.txt", 0o644);
try {
  fs.accessSync("data.txt", fs.constants.X_OK);
  console.log("data.txt: executable");
} catch (e) {
  console.log("data.txt:", e.code);
}
Output
new file with umask 027: 0640
after chmod 755: 0755
after go-x: 0744
data.txt: EACCES
  • Verdict: stdlib. fs.chmod takes the mode as a number or as a string of octal digits, and fs.constants names the bits, such as S_IRUSR and S_IXOTH. process.umask reads and sets the mask of the process, which removes bits from the mode of each new file. fs.access checks the access of the process. On Windows, chmod changes only the write permission.
package main

import (
	"fmt"
	"io/fs"
	"os"
	"syscall"
)

func main() {
	// The umask removes bits from the mode of each new file.
	old := syscall.Umask(0o027)
	os.WriteFile("new.txt", []byte("x"), 0o666)
	os.Mkdir("dir", 0o777)
	syscall.Umask(old)

	for _, name := range []string{"new.txt", "dir"} {
		st, _ := os.Stat(name)
		fmt.Printf("%-8s %v %04o\n", name, st.Mode(), st.Mode().Perm())
	}

	// Go has its own bits for setuid, setgid and sticky. os.Chmod maps them.
	os.Chmod("new.txt", 0o755|fs.ModeSetuid)
	os.Chmod("dir", 0o777|fs.ModeSticky)
	a, _ := os.Stat("new.txt")
	b, _ := os.Stat("dir")
	fmt.Println(a.Mode(), b.Mode())
	fmt.Println("setuid:", a.Mode()&fs.ModeSetuid != 0)
}
Output
new.txt  -rw-r----- 0640
dir      drwxr-x--- 0750
urwxr-xr-x dtrwxrwxrwx
setuid: true
  • Verdict: stdlib. A fs.FileMode holds the nine permission bits in its low bits, and Perm keeps only them. Go does not use the Unix values for the setuid, setgid and sticky bits. It has its own bits, ModeSetuid, ModeSetgid and ModeSticky, which print as letters before the permissions, and os.Chmod maps them to the system bits. The umask is in the syscall package, which is not portable.
RustGitHub
use std::fs;
use std::os::unix::fs::PermissionsExt;

fn mode(path: &str) -> u32 {
    fs::metadata(path).unwrap().permissions().mode() & 0o7777
}

fn main() -> std::io::Result<()> {
    fs::write("data.txt", "x")?;
    fs::set_permissions("data.txt", fs::Permissions::from_mode(0o640))?;
    println!("from_mode: {:o}", mode("data.txt"));

    // set_readonly(true) removes all of the write bits.
    let mut p = fs::metadata("data.txt")?.permissions();
    p.set_readonly(true);
    fs::set_permissions("data.txt", p)?;
    println!("readonly:  {:o}", mode("data.txt"));

    // set_readonly(false) adds the write bit for all classes.
    let mut p = fs::metadata("data.txt")?.permissions();
    p.set_readonly(false);
    fs::set_permissions("data.txt", p)?;
    println!("writable:  {:o}  (others can write now)", mode("data.txt"));

    // Use PermissionsExt to change only the bits that you want.
    let mut p = fs::metadata("data.txt")?.permissions();
    p.set_mode(p.mode() & !0o022);
    fs::set_permissions("data.txt", p)?;
    println!("fixed:     {:o}", mode("data.txt"));
    Ok(())
}
Output
from_mode: 640
readonly:  440
writable:  662  (others can write now)
fixed:     640
  • Verdict: stdlib. The portable Permissions type has only readonly and set_readonly. On Unix, set_readonly(false) makes the file writable for all classes, so the trait std::os::unix::fs::PermissionsExt with mode, set_mode and from_mode is the safe way to change the bits. readonly looks only at the write bits, and not at the user, the groups or the ACLs.
  • Octal and symbolic modes. chmod 640 sets all of the bits, and chmod u+x or g-w changes some bits. A library call that takes a number works like the octal form, so a program that adds one bit must read the mode first. C++ has perm_options::add and perm_options::remove for the symbolic form.
  • Set-group-ID on a directory. On Linux, a directory with the set-group-ID bit makes "files created there inherit their group ID from the directory, not from the effective group ID of the creating process"5.
  • ACLs on Unix. POSIX ACLs come from a draft that was not finished: "While the work on 1003.1e has been abandoned, many UNIX style systems implement parts of POSIX.1e draft 17, or of earlier drafts"7.
  • Owner and group. The permissions depend on the owner and the group of the file, which chown changes. See File metadata.

Pitfalls

  • chmod replaces the whole mode. os.chmod(path, stat.S_IXUSR) does not add one bit. It removes all of the other bits. Read the mode, change the bits, and then write it.
  • The umask applies to the mode of a new file. A program that gives 0666 to open does not get 0666 if the umask is 022. A file for secrets must get the mode 0600 when it is made, not with a later chmod, because another process can open it between the two calls.
  • Rust's set_readonly(false) opens the file to all users. The Rust documentation says: "set_readonly(false) makes the file world-writable on Unix"19. Use PermissionsExt::set_mode to change one bit.
  • The bits do not tell you that an operation will work. Rust warns that readonly "does not take Access Control Lists (ACLs), Unix group membership and other nuances into account"19, and that it ignores "That root user can write to files that do not have any write bits set"19. A test that a process can write a file, followed by a write, also has a race. Try the operation and handle the error.
  • Root can read a file with the mode 0000. For a privileged process, read and write access "shall be granted"2. Tests that check a "permission denied" error fail when they run as root, for example in a container.
  • Windows ignores most of the bits. Code that sets 0700 to keep a file private does nothing on Windows, where only the read-only flag changes11. Use the ACL calls of the system, or keep the file in a directory of the user.

Cost

A permission check is part of each open, so it has no extra cost for the program. The kernel checks the search bit of each directory in the path, and the bits of the file. chmod and umask are one system call each.

History

Ritchie and Thompson described the protection of Unix in 1974: "When a file is created, it is marked with the user ID of its owner. Also given for new files is a set of ten protection bits. Nine of these specify independently read, write, and execute permission for the owner of the file, for other members of his group, and for all remaining users"8. With the tenth bit, "the system will temporarily change the user identification (hereafter, user ID) of the current user to that of the creator of the file whenever the file is executed as a program"8. The paper explains why: "The set-user-ID feature provides for privileged programs that may use files inaccessible to other users"8. POSIX has the same nine bits and the set-user-ID bit, and also the set-group-ID bit and the restricted deletion flag1. Many Unix systems have ACLs from the POSIX.1e drafts7, and Windows uses ACLs9.

References

  1. The Open Group, POSIX.1-2024, sys/stat.h, Description, the file mode bits
  2. The Open Group, POSIX.1-2024, Base Definitions, Chapter 4, General Concepts, 4.7 File Access Permissions
  3. The Open Group, POSIX.1-2024, chmod, Description
  4. The Open Group, POSIX.1-2024, umask, Description
  5. inode(7), Linux manual page, The file type and mode
  6. chmod(2), Linux manual page, Description
  7. acl(5), Linux manual page, Description; ACL entries; Standards
  8. D. M. Ritchie and K. Thompson, The UNIX Time-Sharing System (1974, the BSTJ version), 3.5 Protection
  9. Access Control Lists, Win32 apps, Microsoft Learn, DACLs and SACLs
  10. File Attribute Constants, Win32 apps, Microsoft Learn, FILE_ATTRIBUTE_READONLY
  11. The Python Standard Library, os, os.chmod, os.access
  12. The Python Standard Library, stat, S_IMODE
  13. Node.js, File system, fs.chmod, File modes
  14. Java SE 25 API, java.nio.file.attribute.PosixFilePermission, enum description
  15. Java SE 25 API, java.nio.file.attribute.AclFileAttributeView, interface description
  16. UnixFileMode Enum (System.IO), .NET API, Microsoft Learn, Fields
  17. FileAttributes Enum (System.IO), .NET API, Microsoft Learn, Fields, ReadOnly
  18. Go standard library, package io/fs, type FileMode, type FileMode
  19. The Rust Standard Library, std::fs::Permissions, readonly, set_readonly
  20. std::filesystem::perms, cppreference.com, description

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/78QPZ3/text.yaml