sh runs a Windows command from the SD prompt. (The ! form, a shorter name for
the same verb, does not exist: write sh command.) OS.EXECUTE is the way from a program, and a program can also
reach the operating system by naming a file or directory outside the account.
All of it is off as delivered, and the administrator turns it on, in two
independent switches, with set.os.access.
The two switches#
| Switch | What it lets the account do |
|---|---|
sh |
the sh verb |
os |
OS.EXECUTE; OPENSEQ, OPENPATH, DIR(), DELETESEQ, OPENTEMP, DIGEST of a file and the file-system keys of OSPATH() on a path outside the account's own directory; a print unit's pathname (SETPTR ... AS PATHNAME, SETPU, a CSV report's TO pathname) outside it; the pathname of a socket trace log (set.socket.mode with skt$info.trace) outside it; the embedded Python; the screen editors edit and micro; and a VOC pointer to a file outside the account |
Both are off as delivered on a new install unless you said yes when the
installer asked; an upgrade keeps the switches the installation has. The account's own directory is never asked
about: inside it everything works whatever the switches say. The
administrator needs no switch: after admin the session passes both for as
long as it lasts.
What they run as, when they are on: your Windows user, on an ordinary unelevated token — even when your Windows account is an administrator, because SD drops those rights (see Running SD). A command that needs elevation fails as it would in any unelevated window. Turning a switch on is therefore not a small thing: whoever signs in to SD, at the keyboard, over ssh or through the API, can do what your Windows user can do.
One narrower door for files only. With the os switch off, an sd.conf line
NETDIRS=D:\Data\Sales;D:\Data\Shared lets the account read and write files in the folders it
names, and below them, by pathname, without turning the switch on. None is listed as
delivered, and listing one is a loosening for every session of the account. See
Configuration.
Looking and changing: set.os.access#
An administrator command (type admin first):
:set.os.access
Account sduser has SH no, OS.EXECUTE no
:set.os.access sh on
Account sduser has SH yes, OS.EXECUTE no
:set.os.access os on
Account sduser has SH yes, OS.EXECUTE yes
:set.os.access sh off
Account sduser has SH no, OS.EXECUTE yes
With no argument it shows the state and changes nothing. One switch, one
action, per command: a command that names both, one word, or anything but sh
or os followed by on or off prints Syntax: set.os.access ... and changes
nothing. Saying it a second time says sduser already had that access; nothing
changed. The answer always gives both switches, because sh off says
nothing about os. The change is written to the audit trail
(set.os.access sh on account=sduser), and it is kept in fields 7 and 8 of the
account's register record (yes is on; anything else is off, and
a record with fewer fields is off).
A change is seen at the next sign-on, never by a session that is already running: sign out and in again, or open a new ssh or API session. The API server reads the switches when it enters the account, as the sign-on does.
All the gates on one page: tool.gates#
tool.gates
A full-screen page, in any session (140 columns by 43 lines at least). It
lists the six gates this account has - Shell (sh), OS.EXECUTE (os),
Remote files (net, API access), AI (The AI
helper), File transfer (xfer, set.xfer.access;
Moving Files In and Out in the User documentation) and Scheduled jobs
(jobs, set.jobs.access; Scheduled jobs), the last
two read each time they are used, so "this session" is what the register says
now - with, for each: whether it is ON or off for this session, what the
register holds (shown to the administrator only), how it is delivered (off,
every one), whether it reaches beyond SD (every one does) and when a change
reaches you. A box under the list explains the row under the cursor in plain
sentences: what ON lets the account do, what it can still do with it off, and
the command that changes it.
| Key | What it does |
|---|---|
| Up, Down, Page Up, Page Down, Home, End, a click | move to a gate |
Enter, the space bar (after admin) |
turn the gate on the cursor's row ON, or off, through its own verb |
| F5 | ask the system again |
| F1, ?, a click on the [?] | explain the page |
| Ctrl-Q | leave |
What the columns say. This session is what the system holds for the
session you are typing in: sh, os and net were loaded when you signed on,
so a change made later shows there after the next sign-on, which is why the
Register column is there (what the next sign-on will load). The AI's gate is the
helper's own setting, looked at at every request, so the two columns agree; if the
helper is not running both show a dash and the row says so. xfer and jobs are
read each time they are used, so a change to either reaches you at once. The page
asks and does not try: it never tests an operation to find out whether it works.
What Enter does (administrator only). It builds one command - set.os.access
sh on, set.os.access os off, set.net.access on, set.ai gate on and so on -
shows it in a box with what it will do, and runs it only when you answer Run;
Cancel is what Enter chooses. Turning a gate ON asks you to type its name
(sh, os, net, ai, xfer or jobs),
because every one of them reaches beyond SD, and the box says that a gate off as
delivered is being turned on and that leaving it off is the tighter choice. The verb
asks for the administrator itself and writes its own audit line
(set.os.access sh on account=sduser); the page writes only the line that says it
was started (tool start app=tool.gates), and only for the administrator. After the
command it reads again and shows the verb's own last line in the status bar.
There is no key that turns everything on, and nothing is on as delivered. A
session that has not typed admin sees the page and cannot change anything: Enter
says so and opens no box.
What a refusal looks like#
With both switches off:
:sh echo hi
sduser is not permitted to use the operating system shell
A program's OS.EXECUTE is a run-time error, and a path outside the account is
the ELSE branch with status 3035 (the number of "permission"; it is the same
number as the VOC refusal, and the statement says what was refused):
<address>: sduser is not permitted to use OS.EXECUTE at line 2
openseq 'C:\Windows\win.ini' to f then crt 'opened' else crt 'refused ' : status()
refused 3035
x = dir('C:\Windows') ; crt dcount(x, @fm) : ' ' : status()
0 3035
DIGEST of an outside file, OSPATH() and OPENTEMP give nothing and status
3035; a print file or a SETPTR ... AS PATHNAME outside the account says
sduser has no OS access, so a file or directory outside its own account cannot
be reached by pathname (the administrator can give it: set.os.access os on);
edit and micro say that they need OS.EXECUTE permission and name
set.os.access os on. ed, SD's own line editor, needs none of it.
The verb#
sh command
With sh on, everything after the verb is the command. It runs in the
account's own folder, at the account's own Windows permissions:
:sh echo hello-from-the-shell
hello-from-the-shell
A bare sh, with nothing after it, starts an interactive shell (Windows
PowerShell; the filter below is for a typed command). exit brings you back
to the SD prompt. It needs the sh switch like any other sh: an account
without it is refused first, with "
Never type sh with nothing after it in a script. The configured shell for the
bare form is interactive (SH in config: powershell.exe -NoProfile -NoLogo), so a
bare sh in a piped session, a phantom or a scheduled job hands control to a shell
with nobody at the keyboard and waits for ever. The SH1 form, which is what
sh command uses, is -NonInteractive.
The shell you get is Windows PowerShell 5.1#
Not pwsh, and the difference bites:
&& and || do not exist in that PowerShell, and SD refuses a command that
holds one before PowerShell sees it (see the next section). Nor do the ternary,
null-coalescing or null-conditional operators. Chain with ; in a script, and
test with if ($?) { … }. Each sh is a new shell, but the working directory
persists between them.
One rule about the shape of the command, for everybody#
The verb refuses a command that contains ;, |, &, $, a backquote,
<, > or a newline, before anything runs:
:sh echo alpha-beta | findstr alpha
Error 2 executing operating system command
:sh echo gamma > zzsh.txt
Error 2 executing operating system command
That is a sanitizer on what a one-line command may look like — a safety
measure against an accidental injection, not a permission — and it applies to
everyone, the administrator included. No pipe, no redirection, no chaining
and no variable expansion is available from the prompt. What an account that has the switch can do about that is the
obvious thing: write the work into a script file and run the script
(sh powershell -File nightly.ps1, or sh nightly.cmd). The script's own
contents are not filtered. This is why turning sh on is a decision to give a
person a shell on the computer, not a decision to give them a restricted one.
SD refuses to nest#
:sh sd-solo
SD is already running in this session - type exit to return to it.
A shell that SD starts, with sh or with OS.EXECUTE, is marked, and sd-solo checks the mark before it
reads anything else, so every form of the command is refused inside it (sd-solo -status and sd-solo --version
too):
:sh Get-ChildItem Env:SD_SESSION
Name Value
---- -----
SD_SESSION 1
That is worth knowing when writing a script for sh to run: anything it
starts inherits SD_SESSION, so a script that starts SD as part of its work is
refused, wherever it is called from. It is a guard and not a boundary: the mark
is a variable of the shell, and a person with a shell can remove it there. A
shell you start yourself outside SD is not marked.
OS.EXECUTE is not filtered#
A program's OS.EXECUTE runs the string it is given as written, pipes and
all, with the same rights as sh, once the os switch is on:
os.execute 'echo alpha-beta | findstr alpha'
crt 'status=':status()
alpha-beta
status=0
That is the way to run a command SD's filter refuses. The form execute 'sh …'
from a program goes through the sh verb itself, and is filtered, and asked
about the sh switch, like a typed one.
The editors#
The screen editor micro runs as an ordinary Windows program, in your window,
with your permissions, and is behind the os switch (it is a way out of
SD), and so is edit; ed (SD's own line editor) and sed (SD's own
full-screen editor) are not. See
Development and file commands.
Over ssh and the API#
The switches are loaded the same way for a remote session. An ssh or API session signs in to the account, and the sign-on reads the register: with a switch off, it is off there too. With one on, anyone who has the account password — and, over ssh, your Windows sign-in — can run Windows commands as your Windows user. That is one reason every session asks for the account password; see Security.
At install and at upgrade#
The installer asks, on a new install only, on one page, Shell and OS
access, with two boxes, both unticked: Shell (SH) and OS access
(OS.EXECUTE, files outside the account, Python, editors). An upgrade does not
show the page: it keeps the switches the installation has, so it neither shuts
what the administrator opened nor opens what was shut. The answer can also be
given in the control file, os-access=none, sh, os or both, on a new
installation; with a silent install, or a page left unticked, nothing is turned
on. The installer writes the answer with set.os.access, and says in
install-summary.log what it was.
On a managed computer#
The SD Core for Linux server can put sh on the list of denied commands
(see Managed mode), and it then needs admin first. That list is separate from the switches: a
denied sh needs admin even when the switch is on, and set.os.access is
itself an administrator command.
Continued in#
Showing a Document with pdf — the one bypass of the os switch: showing a document with pdf, naming a reader, where the documents come from, and the context help