📄 safe.n
字号:
'\"'\" Copyright (c) 1995-1996 Sun Microsystems, Inc.'\"'\" See the file "license.terms" for information on usage and redistribution'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.'\" '\" RCS: @(#) $Id: safe.n,v 1.4 2002/07/01 18:24:39 jenglish Exp $'\" .so man.macros.TH "Safe Tcl" n 8.0 Tcl "Tcl Built-In Commands".BS'\" Note: do not modify the .SH NAME line immediately below!.SH NAMESafe\ Base \- A mechanism for creating and manipulating safe interpreters..SH SYNOPSIS\fB::safe::interpCreate\fR ?\fIslave\fR? ?\fIoptions...\fR?.sp\fB::safe::interpInit\fR \fIslave\fR ?\fIoptions...\fR?.sp\fB::safe::interpConfigure\fR \fIslave\fR ?\fIoptions...\fR?.sp\fB::safe::interpDelete\fR \fIslave\fR.sp\fB::safe::interpAddToAccessPath\fR \fIslave\fR \fIdirectory\fR.sp\fB::safe::interpFindInAccessPath\fR \fIslave\fR \fIdirectory\fR.sp\fB::safe::setLogCmd\fR ?\fIcmd arg...\fR?.SH OPTIONS.PP?\fB\-accessPath\fR \fIpathList\fR??\fB\-statics\fR \fIboolean\fR? ?\fB\-noStatics\fR??\fB\-nested\fR \fIboolean\fR? ?\fB\-nestedLoadOk\fR??\fB\-deleteHook\fR \fIscript\fR?.BE.SH DESCRIPTIONSafe Tcl is a mechanism for executing untrusted Tcl scriptssafely and for providing mediated access by such scripts topotentially dangerous functionality..PPThe Safe Base ensures that untrusted Tcl scripts cannot harm thehosting application.The Safe Base prevents integrity and privacy attacks. Untrusted Tclscripts are prevented from corrupting the state of the hostingapplication or computer. Untrusted scripts are also prevented fromdisclosing information stored on the hosting computer or in thehosting application to any party..PPThe Safe Base allows a master interpreter to create safe, restrictedinterpreters that contain a set of predefined aliases for the \fBsource\fR,\fBload\fR, \fBfile\fR, \fBencoding\fR, and \fBexit\fR commands andare able to use the auto-loading and package mechanisms..PPNo knowledge of the file system structure is leaked to thesafe interpreter, because it has access only to a virtualized pathcontaining tokens. When the safe interpreter requests to source a file, ituses the token in the virtual path as part of the file name to source; themaster interpreter transparently translates the token into a real directory name and executes the requested operation (see the section \fBSECURITY\fR below for details).Different levels of security can be selected by using the optional flagsof the commands described below..PPAll commands provided in the master interpreter by the Safe Base reside inthe \fBsafe\fR namespace:.SH COMMANDSThe following commands are provided in the master interpreter:.TP\fB::safe::interpCreate\fR ?\fIslave\fR? ?\fIoptions...\fR?Creates a safe interpreter, installs the aliases described in the section\fBALIASES\fR and initializes the auto-loading and package mechanism asspecified by the supplied \fBoptions\fR.See the \fBOPTIONS\fR section below for a description of theoptional arguments.If the \fIslave\fR argument is omitted, a name will be generated.\fB::safe::interpCreate\fR always returns the interpreter name..TP\fB::safe::interpInit\fR \fIslave\fR ?\fIoptions...\fR?This command is similar to \fBinterpCreate\fR except it that does notcreate the safe interpreter. \fIslave\fR must have been created by someother means, like \fBinterp create \-safe\fR..TP\fB::safe::interpConfigure\fR \fIslave\fR ?\fIoptions...\fR?If no \fIoptions\fR are given, returns the settings for all options for thenamed safe interpreter as a list of options and their current valuesfor that \fIslave\fR. If a single additional argument is provided,it will return a list of 2 elements \fIname\fR and \fIvalue\fR where\fIname\fR is the full name of that option and \fIvalue\fR the current valuefor that option and the \fIslave\fR.If more than two additional arguments are provided, it will reconfigure thesafe interpreter and change each and only the provided options.See the section on \fBOPTIONS\fR below for options description.Example of use:.RS.CS# Create a new interp with the same configuration as "$i0" :set i1 [eval safe::interpCreate [safe::interpConfigure $i0]]# Get the current deleteHookset dh [safe::interpConfigure $i0 \-del]# Change (only) the statics loading ok attribute of an interp# and its deleteHook (leaving the rest unchanged) :safe::interpConfigure $i0 \-delete {foo bar} \-statics 0 ;.CE.RE.TP\fB::safe::interpDelete\fR \fIslave\fRDeletes the safe interpreter and cleans up the corresponding master interpreter data structures.If a \fIdeleteHook\fR script was specified for this interpreter it isevaluated before the interpreter is deleted, with the name of theinterpreter as an additional argument..TP\fB::safe::interpFindInAccessPath\fR \fIslave\fR \fIdirectory\fRThis command finds and returns the token for the real directory\fIdirectory\fR in the safe interpreter's current virtual access path.It generates an error if the directory is not found.Example of use:.RS.CS$slave eval [list set tk_library [::safe::interpFindInAccessPath $name $tk_library]].CE.RE.TP\fB::safe::interpAddToAccessPath\fR \fIslave\fR \fIdirectory\fRThis command adds \fIdirectory\fR to the virtual path maintained for thesafe interpreter in the master, and returns the token that can be used inthe safe interpreter to obtain access to files in that directory.If the directory is already in the virtual path, it only returns the tokenwithout adding the directory to the virtual path again.Example of use:.RS.CS$slave eval [list set tk_library [::safe::interpAddToAccessPath $name $tk_library]].CE.RE.TP\fB::safe::setLogCmd\fR ?\fIcmd arg...\fR?This command installs a script that will be called when interestinglife cycle events occur for a safe interpreter.When called with no arguments, it returns the currently installed script.When called with one argument, an empty string, the currently installedscript is removed and logging is turned off.The script will be invoked with one additional argument, a stringdescribing the event of interest.The main purpose is to help in debugging safe interpreters.Using this facility you can get complete error messages while the safeinterpreter gets only generic error messages.This prevents a safe interpreter from seeing messages about failuresand other events that might contain sensitive information such as realdirectory names..RSExample of use:.CS::safe::setLogCmd puts stderr.CEBelow is the output of a sample session in which a safe interpreterattempted to source a file not found in its virtual access path.Note that the safe interpreter only received an error message saying thatthe file was not found:.CSNOTICE for slave interp10 : CreatedNOTICE for slave interp10 : Setting accessPath=(/foo/bar) staticsok=1 nestedok=0 deletehook=()NOTICE for slave interp10 : auto_path in interp10 has been set to {$p(:0:)}ERROR for slave interp10 : /foo/bar/init.tcl: no such file or directory.CE.RE.SH OPTIONSThe following options are common to \fB::safe::interpCreate\fR, \fB::safe::interpInit\fR, and \fB::safe::interpConfigure\fR.Any option name can be abbreviated to its minimal non-ambiguous name.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -