Seth Woolley's Man Viewer

interp(n) - interp, interp - Create and manipulate Tcl interpreters - man n interp

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

interp(n)                    Tcl Built-In Commands                   interp(n)



NAME
       interp - Create and manipulate Tcl interpreters

SYNOPSIS
       interp option ?arg arg ...?


DESCRIPTION
       This  command  makes  it  possible to create one or more new Tcl inter-
       preters that co-exist with the creating interpreter in(1,8) the same  appli-
       cation.   The  creating  interpreter  is  called the master(5,8) and the new
       interpreter is called a slave.  A  master(5,8)  can  create  any  number  of
       slaves, and each slave can itself create additional slaves for which it
       is master(5,8), resulting in(1,8) a hierarchy of interpreters.

       Each interpreter is independent from the others: it has  its  own  name
       space  for commands, procedures, and global variables.  A master(5,8) inter-
       preter may create connections between its slaves  and  itself  using  a
       mechanism  called  an  alias.   An alias is a command in(1,8) a slave inter-
       preter which, when invoked, causes a command to be invoked in(1,8) its  mas-
       ter(5,8)  interpreter  or in(1,8) another slave interpreter.  The only other con-
       nections between interpreters are through  environment  variables  (the
       env(1,3)  variable), which are normally shared among all interpreters in(1,8) the
       application. Note that the name space for  files  (such  as  the  names
       returned by the open(2,3,n) command) is no longer shared between interpreters.
       Explicit commands are provided to share files and  to  transfer  refer-
       ences to open(2,3,n) files from one interpreter to another.

       The interp command also provides support for safe interpreters.  A safe
       interpreter is a slave whose functions have been greatly restricted, so
       that  it is safe to execute untrusted scripts without fear of them dam-
       aging other interpreters or the application's environment. For example,
       all  IO  channel creation commands and subprocess creation commands are
       made inaccessible to safe interpreters.  See  SAFE  INTERPRETERS  below
       for  more  information  on  what  features are present in(1,8) a safe inter-
       preter.  The dangerous functionality  is  not  removed  from  the  safe
       interpreter;  instead,  it is hidden, so that only trusted interpreters
       can obtain access(2,5) to it. For a detailed explanation of hidden commands,
       see  HIDDEN  COMMANDS, below.  The alias mechanism can be used for pro-
       tected communication (analogous to  a  kernel  call)  between  a  slave
       interpreter  and  its  master.  See  ALIAS  INVOCATION, below, for more
       details on how the alias mechanism works.

       A qualified interpreter name is a proper Tcl lists containing a  subset
       of its ancestors in(1,8) the interpreter hierarchy, terminated by the string(3,n)
       naming the interpreter in(1,8) its immediate master. Interpreter  names  are
       relative  to  the interpreter in(1,8) which they are used. For example, if(3,n) a
       is a slave of the current interpreter and it has a slave a1,  which  in(1,8)
       turn  has  a  slave  a11, the qualified name of a11 in(1,8) a is the list a1
       a11.

       The interp command,  described  below,  accepts  qualified  interpreter
       names as arguments; the interpreter in(1,8) which the command is being eval-
       uated can always be referred to as {} (the empty list or string(3,n)).  Note
       that  it  is  impossible to refer to a master(5,8) (ancestor) interpreter by
       name in(1,8) a slave interpreter except through aliases. Also, there  is  no
       global  name by which one can refer to the first interpreter created in(1,8)
       an application.  Both restrictions are motivated by safety concerns.


THE INTERP COMMAND
       The interp command is used to  create,  delete,  and  manipulate  slave
       interpreters,  and  to share or transfer channels between interpreters.
       It can have any of several forms, depending on the option argument:

       interp alias srcPath srcCmd
              Returns a Tcl list whose elements are  the  targetCmd  and  args
              associated  with  the  alias  named(5,8) srcCmd (all of these are the
              values specified when the alias was created; it is possible that
              the  actual source command in(1,8) the slave is different from srcCmd
              if(3,n) it was renamed).

       interp alias srcPath srcCmd {}
              Deletes the alias for srcCmd in(1,8) the slave interpreter identified
              by srcPath.  srcCmd refers to the name under which the alias was
              created;  if(3,n) the source command has been  renamed,  the  renamed
              command will be deleted.

       interp alias srcPath srcCmd targetPath targetCmd ?arg arg ...?
              This command creates an alias between one slave and another (see
              the alias slave command below for  creating  aliases  between  a
              slave  and  its  master(5,8)).   In this command, either of the slave
              interpreters may be anywhere in(1,8) the  hierarchy  of  interpreters
              under  the interpreter invoking the command.  SrcPath and srcCmd
              identify the source of the alias.  SrcPath is a Tcl  list  whose
              elements  select(2,7,2 select_tut) a particular interpreter.  For example, ``a b''
              identifies an interpreter b, which is a slave of interpreter  a,
              which  is  a  slave  of the invoking interpreter.  An empty list
              specifies the interpreter invoking the  command.   srcCmd  gives
              the  name  of a new command, which will be created in(1,8) the source
              interpreter.  TargetPath and targetCmd specify a  target  inter-
              preter and command, and the arg arguments, if(3,n) any, specify addi-
              tional arguments to targetCmd which are prepended to  any  argu-
              ments  specified  in(1,8) the invocation of srcCmd.  TargetCmd may be
              undefined at the time(1,2,n) of this call, or it may already exist;  it
              is  not  created  by  this  command.  The alias arranges for the
              given target command to be invoked  in(1,8)  the  target  interpreter
              whenever  the  given  source  command  is  invoked in(1,8) the source
              interpreter.  See ALIAS INVOCATION below for more details.

       interp aliases ?path?
              This command returns a Tcl list of the names of all  the  source
              commands  for  aliases  defined in(1,8) the interpreter identified by
              path.

       interp create ?-safe? ?--? ?path?
              Creates a slave interpreter identified by path and  a  new  com-
              mand,  called  a slave command. The name of the slave command is
              the last component of path. The new slave  interpreter  and  the
              slave  command  are created in(1,8) the interpreter identified by the
              path obtained by removing the  last  component  from  path.  For
              example, if(3,n) path is a b c then a new slave interpreter and slave
              command named(5,8) c are created in(1,8) the interpreter identified by the
              path  a  b.  The slave command may be used to manipulate the new
              interpreter as described below. If path is omitted, Tcl  creates
              a  unique  name  of the form interpx, where x is an integer, and
              uses it for the interpreter and the slave command. If the  -safe
              switch(1,n)  is  specified  (or  if(3,n)  the master(5,8) interpreter is a safe
              interpreter), the new slave interpreter will  be  created  as  a
              safe interpreter with limited functionality; otherwise the slave
              will include the full set(7,n,1 builtins) of Tcl  built-in  commands  and  vari-
              ables.  The  --  switch(1,n) can be used to mark the end of switches;
              it may be needed if(3,n) path is an unusual value such as -safe.  The
              result  of  the  command is the name of the new interpreter. The
              name of a slave interpreter must be unique among all the  slaves
              for  its  master(5,8);  an error(8,n) occurs if(3,n) a slave interpreter by the
              given name already exists in(1,8) this master.  The initial recursion
              limit  of  the slave interpreter is set(7,n,1 builtins) to the current recursion
              limit of its parent interpreter.

       interp delete ?path ...?
              Deletes zero or more interpreters given  by  the  optional  path
              arguments, and for each interpreter, it also deletes its slaves.
              The command also deletes the slave command for each  interpreter
              deleted.  For each path argument, if(3,n) no interpreter by that name
              exists, the command raises an error.

       interp eval path arg ?arg ...?
              This command concatenates all of the arg arguments in(1,8)  the  same
              fashion  as  the  concat  command,  then evaluates the resulting
              string(3,n) as a Tcl script in(1,8) the slave  interpreter  identified  by
              path. The result of this evaluation (including error(8,n) information
              such as the errorInfo  and  errorCode  variables,  if(3,n)  an  error(8,n)
              occurs) is returned to the invoking interpreter.

       interp exists path
              Returns   1  if(3,n) a slave interpreter by the specified path exists
              in(1,8) this master(5,8), 0 otherwise. If path is  omitted,  the  invoking
              interpreter is used.

       interp expose path hiddenName ?exposedCmdName?
              Makes the hidden command hiddenName exposed, eventually bringing
              it back under a new exposedCmdName name (this name is  currently
              accepted  only  if(3,n)  it is a valid global name space name without
              any ::), in(1,8) the interpreter denoted by path.  If an exposed com-
              mand  with the targeted name already exists, this command fails.
              Hidden commands are explained in(1,8) more detail in(1,8) HIDDEN COMMANDS,
              below.

       interp hide path exposedCmdName ?hiddenCmdName?
              Makes  the exposed command exposedCmdName hidden, renaming it to
              the hidden command hiddenCmdName, or keeping the  same  name  if(3,n)
              hiddenCmdName  is not given, in(1,8) the interpreter denoted by path.
              If a hidden command with the targeted name already exists,  this
              command  fails.  Currently both exposedCmdName and hiddenCmdName
              can not contain namespace qualifiers, or  an  error(8,n)  is  raised.
              Commands to be hidden by interp hide are looked up in(1,8) the global
              namespace even if(3,n) the current namespace is not the  global  one.
              This prevents slaves from fooling a master(5,8) interpreter into hid-
              ing the wrong command, by making the current namespace  be  dif-
              ferent  from  the  global one.  Hidden commands are explained in(1,8)
              more detail in(1,8) HIDDEN COMMANDS, below.

       interp hidden path
              Returns a list of the names of all hidden commands in(1,8) the inter-
              preter identified by path.

       interp invokehidden path ?-global? hiddenCmdName ?arg ...?
              Invokes the hidden command hiddenCmdName with the arguments sup-
              plied in(1,8) the interpreter denoted by path.  No  substitutions  or
              evaluation are applied to the arguments.  If the -global flag is
              present, the hidden command is invoked at the  global  level  in(1,8)
              the  target  interpreter; otherwise it is invoked at the current
              call frame and can access(2,5) local variables in(1,8) that and outer call
              frames.   Hidden commands are explained in(1,8) more detail in(1,8) HIDDEN
              COMMANDS, below.

       interp issafe ?path?
              Returns 1 if(3,n) the interpreter identified by the specified path is
              safe, 0 otherwise.

       interp marktrusted path
              Marks  the  interpreter  identified by path as trusted. Does not
              expose the hidden commands. This command  can  only  be  invoked
              from  a  trusted  interpreter.  The command has no effect if(3,n) the
              interpreter identified by path is already trusted.

       interp recursionlimit path ?newlimit?
              Returns the maximum allowable nesting depth for the  interpreter
              specified  by  path.   If newlimit is specified, the interpreter
              recursion limit will  be  set(7,n,1 builtins)  so  that  nesting  of  more  than
              newlimit  calls  to  Tcl_Eval()  and  related procedures in(1,8) that
              interpreter will return an error.  The newlimit  value  is  also
              returned.  The newlimit value must be a positive integer between
              1 and the maximum value of a non-long integer on the platform.

              The command sets the maximum size of the Tcl call stack only. It
              cannot  by  itself  prevent stack overflows on the C stack being
              used by the application. If your machine has a limit on the size
              of  the C stack, you may get stack overflows before reaching the
              limit set(7,n,1 builtins) by the command. If this happens, see  if(3,n)  there  is  a
              mechanism  in(1,8) your system for increasing the maximum size of the
              C stack.

       interp share srcPath channelId destPath
              Causes the IO channel identified by channelId to  become  shared
              between  the  interpreter  identified  by srcPath and the inter-
              preter identified by destPath. Both interpreters have  the  same
              permissions  on the IO channel.  Both interpreters must close(2,7,n) it
              to close(2,7,n) the underlying IO channel; IO channels accessible in(1,8) an
              interpreter  are  automatically  closed  when  an interpreter is
              destroyed.

       interp slaves ?path?
              Returns a Tcl list of the names of all  the  slave  interpreters
              associated  with  the interpreter identified by path. If path is
              omitted, the invoking interpreter is used.

       interp target path alias
              Returns a Tcl list describing  the  target  interpreter  for  an
              alias.  The  alias  is  specified  with  an interpreter path and
              source command name, just as in(1,8) interp alias above. The name  of
              the target interpreter is returned as an interpreter path, rela-
              tive to the invoking interpreter.  If the target interpreter for
              the  alias  is  the  invoking  interpreter then an empty list is
              returned. If the target interpreter for the  alias  is  not  the
              invoking  interpreter or one of its descendants then an error(8,n) is
              generated.  The target command does not have to  be  defined  at
              the time(1,2,n) of this invocation.

       interp transfer srcPath channelId destPath
              Causes  the  IO channel identified by channelId to become avail-
              able in(1,8) the interpreter identified by destPath  and  unavailable
              in(1,8) the interpreter identified by srcPath.


SLAVE COMMAND
       For  each  slave interpreter created with the interp command, a new Tcl
       command is created in(1,8) the master(5,8) interpreter with the same name as  the
       new  interpreter. This command may be used to invoke various operations
       on the interpreter.  It has the following general form:  slave  command
       ?arg  arg  ...?   Slave is the name of the interpreter, and command and
       the args determine the exact behavior of the command.  The valid  forms
       of this command are:

       slave aliases
              Returns  a  Tcl  list  whose  elements  are the names of all the
              aliases in(1,8) slave.  The names returned are the srcCmd values used
              when  the aliases were created (which may not be the same as the
              current names of the commands, if(3,n) they have been renamed).

       slave alias srcCmd
              Returns a Tcl list whose elements are  the  targetCmd  and  args
              associated  with  the  alias  named(5,8) srcCmd (all of these are the
              values specified when the alias was created; it is possible that
              the  actual source command in(1,8) the slave is different from srcCmd
              if(3,n) it was renamed).

       slave alias srcCmd {}
              Deletes the alias for srcCmd in(1,8) the slave  interpreter.   srcCmd
              refers  to  the  name under which the alias was created;  if(3,n) the
              source command has been renamed, the  renamed  command  will  be
              deleted.

       slave alias srcCmd targetCmd ?arg ..?
              Creates  an alias such that whenever srcCmd is invoked in(1,8) slave,
              targetCmd is invoked in(1,8) the master.  The arg arguments  will  be
              passed  to  targetCmd  as additional arguments, prepended before
              any arguments passed in(1,8) the invocation  of  srcCmd.   See  ALIAS
              INVOCATION below for details.

       slave eval arg ?arg ..?
              This  command  concatenates all of the arg arguments in(1,8) the same
              fashion as the concat  command,  then  evaluates  the  resulting
              string(3,n)  as a Tcl script in(1,8) slave.  The result of this evaluation
              (including error(8,n) information such as the errorInfo and errorCode
              variables,  if(3,n)  an  error(8,n)  occurs)  is  returned to the invoking
              interpreter.

       slave expose hiddenName ?exposedCmdName?
              This command exposes the hidden command  hiddenName,  eventually
              bringing  it  back under a new exposedCmdName name (this name is
              currently accepted only if(3,n) it is a valid global name space  name
              without  any ::), in(1,8) slave.  If an exposed command with the tar-
              geted name already exists, this command fails.  For more details
              on hidden commands, see HIDDEN COMMANDS, below.

       slave hide exposedCmdName ?hiddenCmdName?
              This  command hides the exposed command exposedCmdName, renaming
              it to the hidden command hiddenCmdName, or keeping the same name
              if(3,n)  the the argument is not given, in(1,8) the slave interpreter.  If
              a hidden command with the targeted  name  already  exists,  this
              command  fails.  Currently both exposedCmdName and hiddenCmdName
              can not contain namespace qualifiers, or  an  error(8,n)  is  raised.
              Commands to be hidden are looked up in(1,8) the global namespace even
              if(3,n) the current namespace is not the global  one.  This  prevents
              slaves  from  fooling a master(5,8) interpreter into hiding the wrong
              command, by making the current namespace be different  from  the
              global  one.   For  more  details on hidden commands, see HIDDEN
              COMMANDS, below.

       slave hidden
              Returns a list of the names of all hidden commands in(1,8) slave.

       slave invokehidden ?-global hiddenName ?arg ..?
              This command invokes the hidden command hiddenName with the sup-
              plied  arguments,  in(1,8) slave. No substitutions or evaluations are
              applied to the arguments.  If the -global  flag  is  given,  the
              command  is  invoked at the global level in(1,8) the slave; otherwise
              it is invoked at the current call frame  and  can  access(2,5)  local
              variables  in(1,8)  that  or  outer call frames.  For more details on
              hidden commands, see HIDDEN COMMANDS, below.

       slave issafe
              Returns  1 if(3,n) the slave interpreter is safe, 0 otherwise.

       slave marktrusted
              Marks the slave interpreter as trusted. Can only be invoked by a
              trusted  interpreter.  This  command  does not expose any hidden
              commands in(1,8) the slave interpreter. The command has no effect  if(3,n)
              the slave is already trusted.

       slave recursionlimit ?newlimit?
              Returns the maximum allowable nesting depth for the slave inter-
              preter.  If newlimit is specified, the recursion limit in(1,8)  slave
              will  be  set(7,n,1 builtins)  so  that  nesting  of more than newlimit calls to
              Tcl_Eval() and related procedures in(1,8) slave will return an error.
              The newlimit value is also returned.  The newlimit value must be
              a positive integer between 1 and the maximum value of a non-long
              integer on the platform.

              The command sets the maximum size of the Tcl call stack only. It
              cannot by itself prevent stack overflows on the  C  stack  being
              used by the application. If your machine has a limit on the size
              of the C stack, you may get stack overflows before reaching  the
              limit  set(7,n,1 builtins)  by  the  command. If this happens, see if(3,n) there is a
              mechanism in(1,8) your system for increasing the maximum size of  the
              C stack.

SAFE INTERPRETERS
       A  safe  interpreter  is  one with restricted functionality, so that is
       safe to execute an arbitrary script from your worst enemy without  fear
       of  that  script damaging the enclosing application or the rest of your
       computing environment.  In order to make an interpreter  safe,  certain
       commands  and variables are removed from the interpreter.  For example,
       commands to create files on disk are removed, and the exec(3,n,1 builtins)  command  is
       removed,  since  it could be used to cause damage through subprocesses.
       Limited access(2,5) to these facilities can be provided, by creating aliases
       to  the  master(5,8)  interpreter  which check their arguments carefully and
       provide restricted access(2,5) to a safe subset of facilities.  For example,
       file(1,n) creation might be allowed in(1,8) a particular subdirectory and subpro-
       cess invocation might be allowed for a carefully selected and fixed set(7,n,1 builtins)
       of programs.

       A  safe  interpreter  is  created by specifying the -safe switch(1,n) to the
       interp create command.  Furthermore, any slave created by a safe inter-
       preter will also be safe.

       A  safe interpreter is created with exactly the following set(7,n,1 builtins) of built-
       in(1,8)         commands:         after       append      array       binary
       break       case        catch       clock(3,n)  close(2,7,n)       concat      con-
       tinue    eof               error(8,n)       eval        expr(1,3,n)        fblocked
       fcopy       fileevent   flush(8,n)       for                foreach     for-
       mat      gets(3,n)        global  if(3,n)          incr        info(1,5,n)        interp
       join(1,n)        lappend     lindex      linsert
       list        llength     lrange      lreplace
       lsearch(3,n)     lsort       namespace   package
       pid         proc(5,n)        puts(3,n)        read(2,n,1 builtins)               regexp(3,n)      reg-
       sub      rename(1,2,n)      return   scan        seek        set(7,n,1 builtins)         split(1,n)
       string(3,n)      subst       switch(1,n)      tell
       time(1,2,n)        trace(3x,n,3x _nc_tracebits)       unset       update(7,n)
       uplevel     upvar       variable    vwait while The following  commands
       are  hidden  by  interp  create  when  it  creates  a safe interpreter:
       cd          encoding(3,n)    exec(3,n,1 builtins)        exit(3,n,1 builtins)                     fconfigure
       file(1,n)         glob(1,3,7,n)        load(7,n)
       open(2,3,n)        pwd(1,n,1 builtins)         socket(2,7,n)      source These commands can be recre-
       ated  later  as  Tcl  procedures  or  aliases,  or re-exposed by interp
       expose.

       The following commands from Tcl's library of support procedures are not
       present            in(1,8)           a           safe           interpreter:
       auto_exec_ok    auto_import     auto_load    auto_load_index auto_qual-
       ify    unknown  Note  in(1,8)  particular  that  safe  interpreters  have no
       default unknown command, so Tcl's default  autoloading  facilities  are
       not  available.   Autoload  access(2,5)  to Tcl's commands that are normally
       autoloaded:                       auto_mkindex         auto_mkindex_old
       auto_reset           history(1,3,n,1 builtins)           parray               pkg_mkIndex
       ::pkg::create        ::safe::interpAddToAccessPath   ::safe::interpCre-
       ate ::safe::interpConfigure   ::safe::interpDelete ::safe::interpFindI-
       nAccessPath      ::safe::interpInit   ::safe::setLogCmd      tcl_endOf-
       Word        tcl_findLibrary   tcl_startOfNextWord  tcl_startOfPrevious-
       Word tcl_wordBreakAfter   tcl_wordBreakBefore can only be  provided  by
       explicit  definition  of  an  unknown  command in(1,8) the safe interpreter.
       This will involve exposing the source command.   This  is  most  easily
       accomplished by creating the safe interpreter with Tcl's Safe-Tcl mech-
       anism.  Safe-Tcl provides safe versions of source, load(7,n), and other  Tcl
       commands  needed  to support autoloading of commands and the loading of
       packages.

       In addition, the env(1,3) variable is not present in(1,8) a safe interpreter,  so
       it  cannot share environment variables with other interpreters. The env(1,3)
       variable poses a security  risk,  because  users(1,5)  can  store  sensitive
       information  in(1,8)  an  environment  variable. For example, the PGP manual
       recommends storing the PGP private key protection password in(1,8) the envi-
       ronment  variable  PGPPASS. Making this variable available to untrusted
       code executing in(1,8) a safe interpreter would incur a security risk.

       If extensions are  loaded  into  a  safe  interpreter,  they  may  also
       restrict  their  own  functionality to eliminate unsafe commands. For a
       discussion of management  of  extensions  for  safety  see  the  manual
       entries for Safe-Tcl and the load(7,n) Tcl command.

       A  safe  interpreter  may  not  alter the recursion limit of any inter-
       preter, including itself.


ALIAS INVOCATION
       The alias mechanism has been carefully designed so that it can be  used
       safely  when  an  untrusted script is executing in(1,8) a safe slave and the
       target of the alias is a trusted master.  The most important  thing  in(1,8)
       guaranteeing safety is to ensure that information passed from the slave
       to the master(5,8) is never evaluated or substituted in(1,8) the master(5,8);  if(3,n) this
       were  to  occur,  it would enable an evil script in(1,8) the slave to invoke
       arbitrary functions in(1,8) the master(5,8), which would compromise security.

       When the source for an alias is invoked in(1,8) the slave  interpreter,  the
       usual Tcl substitutions are performed when parsing that command.  These
       substitutions are carried out in(1,8) the source interpreter  just  as  they
       would  be  for any other command invoked in(1,8) that interpreter.  The com-
       mand procedure for the source command takes its  arguments  and  merges
       them with the targetCmd and args for the alias to create a new array of
       arguments.  If the words of srcCmd were ``srcCmd arg1 arg2 ...  argN'',
       the  new set(7,n,1 builtins) of words will be ``targetCmd arg arg ... arg arg1 arg2 ...
       argN'', where targetCmd and args are the values supplied when the alias
       was  created.   TargetCmd is then used to locate a command procedure in(1,8)
       the target interpreter, and that command procedure is invoked with  the
       new  set(7,n,1 builtins)  of  arguments.   An error(8,n) occurs if(3,n) there is no command named(5,8)
       targetCmd in(1,8) the target interpreter.  No additional  substitutions  are
       performed  on  the  words:   the  target  command  procedure is invoked
       directly, without going through the normal  Tcl  evaluation  mechanism.
       Substitutions  are  thus performed on each word exactly once: targetCmd
       and args were substituted when parsing the  command  that  created  the
       alias,  and arg1 - argN are substituted when the alias's source command
       is parsed in(1,8) the source interpreter.

       When writing the targetCmds for aliases in(1,8)  safe  interpreters,  it  is
       very important that the arguments to that command never be evaluated or
       substituted, since this would provide an escape mechanism  whereby  the
       slave  interpreter could execute arbitrary code in(1,8) the master.  This in(1,8)
       turn would compromise the security of the system.


HIDDEN COMMANDS
       Safe interpreters greatly restrict the functionality available  to  Tcl
       programs  executing within them.  Allowing the untrusted Tcl program to
       have direct access(2,5) to this functionality is unsafe, because it  can  be
       used  for  a variety of attacks on the environment.  However, there are
       times when there is a legitimate need to use the dangerous  functional-
       ity  in(1,8)  the  context of the safe interpreter. For example, sometimes a
       program must be sourced into the interpreter.  Another example  is  Tk,
       where  windows  are  bound  to  the hierarchy of windows for a specific
       interpreter; some potentially dangerous functions, e.g.  window manage-
       ment,  must  be  performed on these windows within the interpreter con-
       text.

       The interp command provides a solution to this problem in(1,8) the  form  of
       hidden  commands.  Instead  of removing the dangerous commands entirely
       from a safe interpreter, these  commands  are  hidden  so  they  become
       unavailable  to Tcl scripts executing in(1,8) the interpreter. However, such
       hidden commands can be invoked by any  trusted  ancestor  of  the  safe
       interpreter,  in(1,8)  the  context  of  the  safe interpreter, using interp
       invoke. Hidden commands and exposed commands reside  in(1,8)  separate  name
       spaces.  It  is possible to define a hidden command and an exposed com-
       mand by the same name within one interpreter.

       Hidden commands in(1,8) a slave interpreter can be invoked in(1,8)  the  body  of
       procedures  called  in(1,8) the master(5,8) during alias invocation. For example,
       an alias for source could be created in(1,8) a slave interpreter. When it is
       invoked  in(1,8)  the slave interpreter, a procedure is called in(1,8) the master(5,8)
       interpreter to check that the operation is allowable (e.g. it  asks  to
       source  a  file(1,n)  that  the slave interpreter is allowed to access(2,5)). The
       procedure then it invokes the hidden source command in(1,8) the slave inter-
       preter  to  actually  source in(1,8) the contents of the file. Note that two
       commands named(5,8) source exist in(1,8) the slave interpreter:  the  alias,  and
       the hidden command.

       Because  a  master(5,8)  interpreter  may invoke a hidden command as part of
       handling an alias invocation, great care must be taken to avoid  evalu-
       ating any arguments passed in(1,8) through the alias invocation.  Otherwise,
       malicious slave interpreters could cause a trusted  master(5,8)  interpreter
       to execute dangerous commands on their behalf. See the section on ALIAS
       INVOCATION for a more complete discussion of this topic.  To help avoid
       this  problem, no substitutions or evaluations are applied to arguments
       of interp invokehidden.

       Safe interpreters are not allowed to invoke hidden  commands  in(1,8)  them-
       selves  or in(1,8) their descendants. This prevents safe slaves from gaining
       access(2,5) to hidden functionality in(1,8) themselves or their descendants.

       The set(7,n,1 builtins) of hidden commands in(1,8) an interpreter can be  manipulated  by  a
       trusted  interpreter  using  interp  expose and interp hide. The interp
       expose command moves a hidden command to the set(7,n,1 builtins) of exposed commands in(1,8)
       the interpreter identified by path, potentially renaming the command in(1,8)
       the process. If an exposed command by the targeted name already exists,
       the operation fails. Similarly, interp hide moves an exposed command to
       the set(7,n,1 builtins) of hidden commands in(1,8) that interpreter. Safe  interpreters  are
       not allowed to move(3x,7,3x curs_move) commands between the set(7,n,1 builtins) of hidden and exposed com-
       mands, in(1,8) either themselves or their descendants.

       Currently, the names of hidden commands cannot contain namespace quali-
       fiers, and you must first rename(1,2,n) a command in(1,8) a namespace to the global
       namespace before you can hide it.  Commands to be hidden by interp hide
       are  looked up in(1,8) the global namespace even if(3,n) the current namespace is
       not the global one. This prevents slaves from fooling a  master(5,8)  inter-
       preter  into  hiding the wrong command, by making the current namespace
       be different from the global one.

CREDITS
       This mechanism is  based  on  the  Safe-Tcl  prototype  implemented  by
       Nathaniel Borenstein and Marshall Rose.


SEE ALSO
       load(7,n)(n), safe(n), Tcl_CreateSlave(3)


KEYWORDS
       alias, master(5,8) interpreter, safe interpreter, slave interpreter



Tcl                                   7.6                            interp(n)

References for this manual (incoming links)