⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 safe.n

📁 linux系统下的音频通信
💻 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.'\" '\" SCCS: @(#) safe.n 1.11 97/10/31 12:51:13'\" .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.PP\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 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.Option names are not case sensitive..TP \fB\-accessPath\fR \fIdirectoryList\fRThis option sets the list of directories from which the safe interpretercan \fBsource\fR and \fBload\fR files.If this option is not specified, or if it is given as theempty list, the safe interpreter will use the same directories as itsmaster for auto-loading.See the section \fBSECURITY\fR below for more detail about virtual paths, tokens and access control..TP\fB\-statics\fR \fIboolean\fRThis option specifies if the safe interpreter will be allowedto load statically linked packages (like \fBload {} Tk\fR).The default value is \fBtrue\fR : safe interpreters are allowed to load statically linked packages..TP\fB\-noStatics\fRThis option is a convenience shortcut for \fB-statics false\fR andthus specifies that the safe interpreter will not be allowedto load statically linked packages..TP\fB\-nested\fR \fIboolean\fRThis option specifies if the safe interpreter will be allowedto load packages into its own sub-interpreters.The default value is \fBfalse\fR : safe interpreters are not allowed to load packages intotheir own sub-interpreters..TP\fB\-nestedLoadOk\fRThis option is a convenience shortcut for \fB-nested true\fR andthus specifies the safe interpreter will be allowedto load packages into its own sub-interpreters..TP \fB\-deleteHook\fR \fIscript\fRWhen this option is given an non empty \fIscript\fR, it will beevaluated in the master with the name ofthe safe interpreter as an additional argumentjust before actually deleting the safe interpreter.Giving an empty value removes any currently installed deletion hookscript for that safe interpreter.The default value (\fB{}\fR) is not to have any deletion call back..SH ALIASESThe following aliases are provided in a safe interpreter:.TP\fBsource\fR \fIfileName\fRThe requested file, a Tcl source file, is sourced into the safe interpreterif it is found.The \fBsource\fR alias can only source files from directories inthe virtual path for the safe interpreter. The \fBsource\fR alias requiresthe safe interpreter touse one of the token names in its virtual path to denote the directory inwhich the file to be sourced can be found.See the section on \fBSECURITY\fR for more discussion of restrictions onvalid filenames..TP\fBload\fR \fIfileName\fRThe requested file, a shared object file, is dynamically loaded into thesafe interpreter if it is found.The filename must contain a token name mentioned in the virtual path forthe safe interpreter for it to be found successfully.Additionally, the shared object file must contain a safe entry point; seethe manual page for the \fBload\fR command for more details..TP\fBfile\fR ?\fIsubCmd args...\fR?The \fBfile\fR alias provides access to a safe subset of the subcommands ofthe \fBfile\fR command; it allows only \fBdirname\fR, \fBjoin\fR,\fBextension\fR, \fBroot\fR, \fBtail\fR, \fBpathname\fR and \fBsplit\fRsubcommands. For more details on what these subcommands do see the manualpage for the \fBfile\fR command..TP\fBexit\fRThe calling interpreter is deleted and its computation is stopped, but theTcl process in which this interpreter exists is not terminated..SH SECURITYThe Safe Base does not attempt to completely prevent annoyance anddenial of service attacks. These forms of attack prevent theapplication or user from temporarily using the computer to performuseful work, for example by consuming all available CPU time orall available screen real estate.These attacks, while aggravating, are deemed to be of lesser importancein general than integrity and privacy attacks that the Safe Baseis to prevent..PPThe commands available in a safe interpreter, in addition tothe safe set as defined in \fBinterp\fR manual page, are mediated aliasesfor \fBsource\fR, \fBload\fR, \fBexit\fR, and a safe subset of \fBfile\fR.The safe interpreter can also auto-load code and it can request thatpackages be loaded..PPBecause some of these commands access the local file system, there is apotential for information leakage about its directory structure.To prevent this, commands that take file names as arguments in a safeinterpreter use tokens instead of the real directory names.These tokens are translated to the real directory name while a request to,e.g., source a file is mediated by the master interpreter.This virtual path system is maintained in the master interpreter for each safeinterpreter created by \fB::safe::interpCreate\fR or initialized by\fB::safe::interpInit\fR andthe path maps tokens accessible in the safe interpreter into real pathnames on the local file system thus preventing safe interpreters from gaining knowledge about thestructure of the file system of the host on which the interpreter isexecuting.The only valid file names argumentsfor the \fBsource\fR and \fBload\fR aliases provided to the slaveare path in the form of \fB[file join \fR\fItoken filename\fR\fB]\fR (ie, when using thenative file path formats: \fItoken\fR\fB/\fR\fIfilename\fRon Unix, \fItoken\fR\fB\\\fIfilename\fR on Windows, and \fItoken\fR\fB:\fR\fIfilename\fR on the Mac),where \fItoken\fR is representing one of the directories of the \fIaccessPath\fR list and \fIfilename\fR isone file in that directory (no sub directories access are allowed)..PPWhen a token is used in a safe interpreter in a request to source orload a file, the token is checked andtranslated to a real path name and the file to besourced or loaded is located on the file system.The safe interpreter never gains knowledge of the actual path name underwhich the file is stored on the file system..PPTo further prevent potential information leakage from sensitive files thatare accidentally included in the set of files that can be sourced by a safeinterpreter, the \fBsource\fR alias restricts access to filesmeeting the following constraints: the file name mustfourteen characters or shorter, must not contain more than one dot ("\fB.\fR"),must end up with the extension \fB.tcl\fR or be called \fBtclIndex\fR..PPEach element of the initial access pathlist will be assigned a token that will be set inthe slave \fBauto_path\fR and the first element of that list will be set asthe \fBtcl_library\fR for that slave..PPIf the access path argument is not given or is the empty list, the default behavior is to let the slave access the same packagesas the master has access to (Or to be more precise: only packages written in Tcl (which by definition can't be dangerousas they run in the slave interpreter) and C extensions thatprovides a Safe_Init entry point). For that purpose, the master's \fBauto_path\fR will be used to construct the slave access path. In order that the slave successfully loads the Tcl library files(which includes the auto-loading mechanism itself) the \fBtcl_library\fR will beadded or moved to the first position if necessary, in the slave access path, so the slave\fBtcl_library\fR will be the same as the master's (its realpath will still be invisible to the slave though). In order that auto-loading works the same for the slave andthe master in this by default case, the first-levelsub directories of each directory in the master \fBauto_path\fR willalso be added (if not already included) to the slave access path.You can always specify a morerestrictive path for which sub directories will never be searched by explicitly specifying your directory list with the \fB\-accessPath\fR flaginstead of relying on this default mechanism..PPWhen the \fIaccessPath\fR is changed after the first creation orinitialization (ie through \fBinterpConfigure -accessPath \fR\fIlist\fR),an \fBauto_reset\fR is automatically evaluated in the safe interpreterto synchronize its \fBauto_index\fR with the new token list..SH "SEE ALSO"interp(n), library(n), load(n), package(n), source(n), unknown(n) .SH KEYWORDSalias, auto\-loading, auto_mkindex, load, master interpreter, safeinterpreter, slave interpreter, source

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -