📄 interp.n
字号:
as the current names of the commands, if they have beenrenamed)..TP\fIslave \fBalias \fIsrcCmd\fRReturns a Tcl list whose elements are the \fItargetCmd\fR and\fIarg\fRs associated with the alias named \fIsrcCmd\fR(all of these are the values specified when the alias wascreated; it is possible that the actual source command in theslave is different from \fIsrcCmd\fR if it was renamed)..TP\fIslave \fBalias \fIsrcCmd \fB{}\fRDeletes the alias for \fIsrcCmd\fR in the slave interpreter.\fIsrcCmd\fR refers to the name under which the aliaswas created; if the source command has been renamed, the renamedcommand will be deleted..TP\fIslave \fBalias \fIsrcCmd targetCmd \fR?\fIarg ..\fR?Creates an alias such that whenever \fIsrcCmd\fR is invokedin \fIslave\fR, \fItargetCmd\fR is invoked in the master.The \fIarg\fR arguments will be passed to \fItargetCmd\fR as additionalarguments, prepended before any arguments passed in the invocation of\fIsrcCmd\fR.See ALIAS INVOCATION below for details..TP\fIslave \fBeval \fIarg \fR?\fIarg ..\fR?This command concatenates all of the \fIarg\fR arguments inthe same fashion as the \fBconcat\fR command, then evaluatesthe resulting string as a Tcl script in \fIslave\fR.The result of this evaluation (including error informationsuch as the \fBerrorInfo\fR and \fBerrorCode\fR variables, if anerror occurs) is returned to the invoking interpreter..VS "" BR.TP\fIslave \fBexpose \fIhiddenName \fR?\fIexposedCmdName\fR?This command exposes the hidden command \fIhiddenName\fR, eventually bringingit back under a new \fIexposedCmdName\fR name (this name is currentlyaccepted only if it is a valid global name space name without any ::),in \fIslave\fR.If an exposed command with the targetted name already exists, this commandfails.For more details on hidden commands, see HIDDEN COMMANDS, below..TP\fIslave \fBhide \fIexposedCmdName\fR ?\fIhiddenCmdName\fR?This command hides the exposed command \fIexposedCmdName\fR, renaming it to the hidden command \fIhiddenCmdName\fR, or keeping the same name if thethe argument is not given, in the \fIslave\fR interpreter.If a hidden command with the targetted name already exists, this commandfails.Currently both \fIexposedCmdName\fR and \fIhiddenCmdName\fR can not contain namespace qualifiers, or an error is raised.Commands to be hidden are looked up in the globalnamespace even if the current namespace is not the global one. Thisprevents slaves from fooling a master interpreter into hiding the wrongcommand, by making the current namespace be different from the global one.For more details on hidden commands, see HIDDEN COMMANDS, below..TP\fIslave \fBhidden\fRReturns a list of the names of all hidden commands in \fIslave\fR..TP\fIslave \fBinvokehidden\fR ?\fB-global\fR \fIhiddenName \fR?\fIarg ..\fR?This command invokes the hidden command \fIhiddenName\fR with thesupplied arguments, in \fIslave\fR. No substitutions or evaluations areapplied to the arguments.If the \fB-global\fR flag is given, the command is invoked at the globallevel in the slave; otherwise it is invoked at the current call frame andcan access local variables in that or outer call frames.For more details on hidden commands, see HIDDENCOMMANDS, below..VE.TP\fIslave \fBissafe\fRReturns \fB1\fR if the slave interpreter is safe, \fB0\fR otherwise..VS "" BR.TP\fIslave \fBmarktrusted\fRMarks the slave interpreter as trusted. Can only be invoked by atrusted interpreter. This command does not expose any hiddencommands in the slave interpreter. The command has no effect if the slaveis already trusted..VE.SH "SAFE INTERPRETERS".PPA safe interpreter is one with restricted functionality, so thatis safe to execute an arbitrary script from your worst enemy withoutfear of that script damaging the enclosing application or the restof your computing environment. In order to make an interpretersafe, certain commands and variables are removed from the interpreter.For example, commands to create files on disk are removed, and the\fBexec\fR command is removed, since it could be used to cause damagethrough subprocesses.Limited access to these facilities can be provided, by creatingaliases to the master interpreter which check their arguments carefullyand provide restricted access to a safe subset of facilities.For example, file creation might be allowed in a particular subdirectoryand subprocess invocation might be allowed for a carefully selected andfixed set of programs..PPA safe interpreter is created by specifying the \fB\-safe\fR switchto the \fBinterp create\fR command. Furthermore, any slave createdby a safe interpreter will also be safe..PPA safe interpreter is created with exactly the following set ofbuilt-in commands:.DS.ta 1.2i 2.4i 3.6i\fBafter append array breakcase catch clock closeconcat continue eof erroreval expr fblocked fileeventflush for foreach formatgets global history ifincr info interp joinlappend lindex linsert listllength lower lrange lreplacelsearch lsort package pidproc puts read renamereturn scan seek setsplit string subst switchtell trace unset updateuplevel upvar vwait while\fR.DE.VS "" BRThe following commands are hidden by \fBinterp create\fR when itcreates a safe interpreter:.DS.ta 1.2i 2.4i 3.6i\fBcd exec exit fconfigurefile glob load openpwd socket source vwait\fR.DEThese commands can be recreated later as Tcl procedures or aliases, orre-exposed by \fBinterp expose\fR..VE.PPIn addition, the \fBenv\fR variable is not present in a safe interpreter,so it cannot share environment variables with other interpreters. The\fBenv\fR variable poses a security risk, because users can storesensitive information in an environment variable. For example, the PGPmanual recommends storing the PGP private key protection password inthe environment variable \fIPGPPASS\fR. Making this variable availableto untrusted code executing in a safe interpreter would incur asecurity risk..PPIf extensions are loaded into a safe interpreter, they may also restricttheir own functionality to eliminate unsafe commands. For a discussion ofmanagement of extensions for safety see the manual entries for\fBSafe\-Tcl\fR and the \fBload\fR Tcl command..SH "ALIAS INVOCATION".PPThe alias mechanism has been carefully designed so that it canbe used safely when an untrusted script is executingin a safe slave and the target of the alias is a trustedmaster. The most important thing in guaranteeing safety is toensure that information passed from the slave to the master isnever evaluated or substituted in the master; if this were tooccur, it would enable an evil script in the slave to invokearbitrary functions in the master, which would compromise security..PPWhen the source for an alias is invoked in the slave interpreter, theusual Tcl substitutions are performed when parsing that command.These substitutions are carried out in the source interpreter justas they would be for any other command invoked in that interpreter.The command procedure for the source command takes its argumentsand merges them with the \fItargetCmd\fR and \fIarg\fRs for thealias to create a new array of arguments. If the wordsof \fIsrcCmd\fR were ``\fIsrcCmd arg1 arg2 ... argN\fR'',the new set of words will be``\fItargetCmd arg arg ... arg arg1 arg2 ... argN\fR'',where \fItargetCmd\fR and \fIarg\fRs are the values supplied when thealias was created. \fITargetCmd\fR is then used to locate a commandprocedure in the target interpreter, and that command procedureis invoked with the new set of arguments. An error occurs ifthere is no command named \fItargetCmd\fR in the target interpreter.No additional substitutions are performed on the words: thetarget command procedure is invoked directly, withoutgoing through the normal Tcl evaluation mechanism.Substitutions are thus performed on each word exactly once:\fItargetCmd\fR and \fIargs\fR were substituted when parsing the commandthat created the alias, and \fIarg1 - argN\fR are substituted whenthe alias's source command is parsed in the source interpreter..PPWhen writing the \fItargetCmd\fRs for aliases in safe interpreters,it is very important that the arguments to that command never beevaluated or substituted, since this would provide an escapemechanism whereby the slave interpreter could execute arbitrarycode in the master. This in turn would compromise the securityof the system..VS.SH "HIDDEN COMMANDS".PPSafe interpreters greatly restrict the functionality available to Tclprograms executing within them.Allowing the untrusted Tcl program to have direct access to thisfunctionality is unsafe, because it can be used for a variety ofattacks on the environment.However, there are times when there is a legitimate need to use thedangerous functionality in the context of the safe interpreter. Forexample, sometimes a program must be \fBsource\fRd into the interpreter.Another example is Tk, where windows are bound to the hierarchy of windowsfor a specific interpreter; some potentially dangerous functions, e.g.window management, must be performed on these windows within theinterpreter context..PPThe \fBinterp\fR command provides a solution to this problem in the form of\fIhidden commands\fR. Instead of removing the dangerous commands entirelyfrom a safe interpreter, these commands are hidden so they becomeunavailable to Tcl scripts executing in the interpreter. However, suchhidden commands can be invoked by any trusted ancestor of the safeinterpreter, in the context of the safe interpreter, using \fBinterpinvoke\fR. Hidden commands and exposed commands reside in separate namespaces. It is possible to define a hidden command and an exposed command bythe same name within one interpreter..PPHidden commands in a slave interpreter can be invoked in the body ofprocedures called in the master during alias invocation. For example, analias for \fBsource\fR could be created in a slave interpreter. When it isinvoked in the slave interpreter, a procedure is called in the masterinterpreter to check that the operation is allowable (e.g. it asks tosource a file that the slave interpreter is allowed to access). Theprocedure then it invokes the hidden \fBsource\fR command in the slaveinterpreter to actually source in the contents of the file. Note that twocommands named \fBsource\fR exist in the slave interpreter: the alias, andthe hidden command..PPBecause a master interpreter may invoke a hidden command as part ofhandling an alias invocation, great care must be taken to avoid evaluatingany arguments passed in through the alias invocation.Otherwise, malicious slave interpreters could cause a trusted masterinterpreter to execute dangerous commands on their behalf. See the sectionon ALIAS INVOCATION for a more complete discussion of this topic.To help avoid this problem, no substitutions or evaluations areapplied to arguments of \fBinterp invokehidden\fR..PPSafe interpreters are not allowed to invoke hidden commands in themselvesor in their descendants. This prevents safe slaves from gaining access tohidden functionality in themselves or their descendants..PPThe set of hidden commands in an interpreter can be manipulated by a trustedinterpreter using \fBinterp expose\fR and \fBinterp hide\fR. The \fBinterpexpose\fR command moves a hidden command to theset of exposed commands in the interpreter identified by \fIpath\fR,potentially renaming the command in the process. If an exposed command bythe targetted name already exists, the operation fails. Similarly,\fBinterp hide\fR moves an exposed command to the set of hidden commands inthat interpreter. Safe interpreters are not allowed to move commandsbetween the set of hidden and exposed commands, in either themselves ortheir descendants..PPCurrently, the names of hidden commands cannot contain namespacequalifiers, and you must first rename a command in a namespace to theglobal namespace before you can hide it.Commands to be hidden by \fBinterp hide\fR are looked up in the globalnamespace even if the current namespace is not the global one. Thisprevents slaves from fooling a master interpreter into hiding the wrongcommand, by making the current namespace be different from the global one..VE.SH CREDITS.PPThis mechanism is based on the Safe-Tcl prototype implementedby Nathaniel Borenstein and Marshall Rose..SH "SEE ALSO"load(n), safe(n), Tcl_CreateSlave(3).SH KEYWORDSalias, master interpreter, safe interpreter, slave interpreter
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -