]> gitweb.factorcode.org Git - factor.git/blob - extra/elevate/elevate-docs.factor
gamelib.demos.sokoban: removing unused resources
[factor.git] / extra / elevate / elevate-docs.factor
1 USING: arrays elevate elevate.private help.markup help.syntax
2 io.launcher kernel sequences strings system words ;
3 IN: elevate
4
5 <PRIVATE
6 : $resolve? ( children -- ) 
7     first2 2dup swap lookup-word dup word? [ 2nip ($link) ] [ drop ":" glue $snippet ] if ; 
8 PRIVATE>
9
10 ABOUT: "elevate"
11
12 ARTICLE: "elevate" "Elevated permissions API"
13     "The " { $vocab-link "elevate" } " vocabulary provides abstractions for running programs with elevated (administrator) privileges (permissions). It allows code to relaunch itself or other programs with administrator privileges after requiring a password."
14     $nl
15      "This vocabulary is inspired by and ported from " { $url "https://github.com/barneygale/elevate" "Barney Gale's elevate.py" } "."
16     $nl
17     { $subsections already-root? elevate elevated lowered }
18     "However, there are many caveats: " { $link "elevate.bugs" } "." ;
19
20 ARTICLE: "elevate.bugs" "Elevate bugs and caveats"
21     "There are many inherent platform-specific limitations and workarounds in the " { $vocab-link "elevate" } " elevated privileges API. This article explains and documents them for the curious, future maintainers, or those who run into problems."
22     { $heading "macOS" }
23     "On Apple macOS, an Applescript command is attempted for a graphical method before " { $snippet "sudo" } ". Sometimes, this command appears to execute incorrectly due to the group of the user owning the calling process. On macOS, " { $snippet "sudo" } " suffers the drawback mentioned below for applications which do not have a TTY connected."
24     { $heading "Linux, *BSD and other Unix-likes" }
25     "On Linux, " { $snippet "gksudo" } ", " { $snippet "kdesudo" } ", and " { $snippet "pkexec" } " are all attempted graphical methods before " { $snippet "sudo" } "."
26     { $list
27         { { $snippet "pkexec" } " is the preferred and most secure graphical authentication method on Linux. It is undesirable for Factor applications, because unless a certain rare global registry value is set, " { $snippet "pkexec" } " does not set the " { $snippet "$DISPLAY" } " environment variable for child processes, and thus cannot launch graphical applications despite being a graphical program itself. It is tried after " { $snippet "gksudo" } " and " { $snippet "kdesudo" } " but before " { $snippet "sudo" } "." }
28         { { $snippet "gksudo" } " and " { $snippet "kdesudo" } " are deprecated, but still present on most GTK- and KDE-based systems, respectively. GTK is more widespread than KDE so " { $snippet "gksudo" } " is tried before " { $snippet "kdesudo" } ". These old-fashioned methods ensure that the launched application can be graphical, so they are preferred for Factor." }
29         { { $snippet "sudo" } " is the final and most robust strategy tried on Linux. It is text-based, so it requires the calling process to have an active and accessible terminal (TTY) for user authentication. If the calling Factor application was started from the desktop graphical shell rather than from a TTY, this method will fail." }
30     }
31     "On other Unix-like or POSIX-like operating systems, " { $snippet "sudo" } " is the only consistently popular method of authentication, and it suffers the same drawback on other Unix-likes as on Linux." 
32     { $heading "Windows" }
33     { "On Windows, the FFI word " { $resolve? "windows.shell32" "ShellExecuteW" } " is used with the verb " { $snippet "runas" } " to force the new process to run with User Account Control. Windows provides no " { $snippet "exec" } " equivalent to replace a running process' image, so a new process will always be spawned, optionally killing the original Factor process." }
34 ;
35
36 HELP: elevated
37 { $values { "command" { $or array string } } { "replace?" boolean } { "win-console?" boolean } { "posix-graphical?" boolean } { "process" process } }
38 { $description
39     "Spawn a process from the command " { $slot "command" } " with superuser (administrator) privileges. If the calling process does not already have superuser privileges, it will request them by a number of platform-specific methods."
40     $nl
41     "If " { $slot "replace?" } " is " { $link t } ", the calling Factor process will be replaced with the command (but see Notes)."
42     $nl
43     { $link windows } ": if " { $slot "win-console?" } " is " { $link t } ", a new console window will " { $emphasis "always" } " be spawned for the resulting process, regardless of " { $slot "replace?" } "."
44     $nl
45     { $link unix } ": if " { $slot "posix-graphical?" } " is " { $link t } ", a graphical password method will be attempted before " { $snippet "sudo" } "."
46     $nl
47     "If the calling process is already run as superuser, nothing happens. The input command is left on the stack, placed into a " { $link process } " inside an " { $link array } "."
48 }
49 { $notes
50     { $list
51         { "On " { $link windows } ", " { $slot "replace?" } " has the effect of ending (with " { $link exit } ") the calling Factor process after spawning the command because Windows provides no way to replace a running process' image, like " { $snippet "exec" } " does in POSIX." }
52         { "On POSIX (" { $link unix } "), " { $slot "replace?" } " does not cause a graceful shutdown of the calling Factor VM or thread. Instead, the " { $emphasis "entire" } " executable program image will be immediately replaced in memory by the new command prefixed by a privilege elevation strategy. For more information, see " { $resolve? "unix.process" "exec-with-path" } " and the Unix " { $snippet "man" } " page for " { $resolve? "unix.process" "execvp" } " (" { $resolve? "unix.process" "exec" } ") in section 3." }
53         { { $link "elevate.bugs" } " details problems and pitfalls of this word." }
54     }
55 }
56 { $errors
57     { $link elevated-failed } " when all strategies fail."
58     $nl
59     "When " { $slot "replace?" } " is " { $link t } ":any errors thrown by " { $link run-process } "."
60 } ;
61
62 HELP: elevate
63 { $values { "win-console?" boolean } { "posix-graphical?" boolean } }
64 { $description "Relaunch the current Factor process with superuser privileges. See " { $link elevated } " for an explanation, as the semantics are identical." } ;
65
66 HELP: lowered
67 { $description "Give up all superuser rights, returning the calling Factor process to normal userspace." }
68 { $notes
69     { $list 
70         { "On " { $link windows } " this word is a no-op, because there Windows provides no " { $snippet "setuid" } " equivalent to change the access token of a running process. It does not throw an error, so that it may be used in cross-platform code." }  
71         { "If the process is running as \"real superuser\", (not an impersonation), nothing happens." $nl "If the process is running as an unprivileged user, nothing happens." }
72     } 
73 }
74 { $errors { $link lowered-failed } " when giving up superuser rights failed." } ;
75
76 HELP: already-root? 
77 { $values { "?" boolean } }
78 { $description "Determine whether the current Factor process (on " { $link unix } ") or hardware thread {on " { $link windows } ") has administrator or elevated (root) privileges." } ; 
79 HELP: lowered-failed 
80 { $error-description "Thrown by " { $link lowered } " when giving up elevated privileges resulted in an error or failure by the operating system." } ;
81 HELP: elevated-failed 
82 { $error-description "Thrown by " { $link elevated } " when all strategies to elevating privileges failed. See " { $link elevated } "." } ;
83