Changeset 98156


Ignore:
Timestamp:
Sep 26, 2012, 4:16:41 PM (12 years ago)
Author:
jmr@…
Message:

add rudimentary sandboxing support for commands run via system proc

Location:
trunk/base
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/base/configure

    r97235 r98156  
    711711SVN
    712712SED
     713SANDBOX_EXEC
    713714RSYNC
    714715RMDIR
     
    55455546
    55465547
     5548# Extract the first word of "sandbox-exec", so it can be a program name with args.
     5549set dummy sandbox-exec; ac_word=$2
     5550{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
     5551$as_echo_n "checking for $ac_word... " >&6; }
     5552if ${ac_cv_path_SANDBOX_EXEC+:} false; then :
     5553  $as_echo_n "(cached) " >&6
     5554else
     5555  case $SANDBOX_EXEC in
     5556  [\\/]* | ?:[\\/]*)
     5557  ac_cv_path_SANDBOX_EXEC="$SANDBOX_EXEC" # Let the user override the test with a path.
     5558  ;;
     5559  *)
     5560  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
     5561for as_dir in /usr/bin
     5562do
     5563  IFS=$as_save_IFS
     5564  test -z "$as_dir" && as_dir=.
     5565    for ac_exec_ext in '' $ac_executable_extensions; do
     5566  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     5567    ac_cv_path_SANDBOX_EXEC="$as_dir/$ac_word$ac_exec_ext"
     5568    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     5569    break 2
     5570  fi
     5571done
     5572  done
     5573IFS=$as_save_IFS
     5574
     5575  ;;
     5576esac
     5577fi
     5578SANDBOX_EXEC=$ac_cv_path_SANDBOX_EXEC
     5579if test -n "$SANDBOX_EXEC"; then
     5580  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $SANDBOX_EXEC" >&5
     5581$as_echo "$SANDBOX_EXEC" >&6; }
     5582else
     5583  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
     5584$as_echo "no" >&6; }
     5585fi
     5586
     5587
    55475588# Extract the first word of "sed", so it can be a program name with args.
    55485589set dummy sed; ac_word=$2
  • trunk/base/configure.ac

    r93255 r98156  
    134134AC_PATH_PROG(RMDIR, [rmdir], [])
    135135AC_PATH_PROG(RSYNC, [rsync], [])
     136AC_PATH_PROG(SANDBOX_EXEC, [sandbox-exec], [], [/usr/bin])
    136137AC_PATH_PROG(SED, [sed])
    137138AC_PATH_PROG(SVN, [svn], [])
  • trunk/base/src/pextlib1.0/system.c

    r91557 r98156  
    7878};
    7979
     80static int check_sandboxing(Tcl_Interp *interp, char **sandbox_exec_path, char **profilestr)
     81{
     82    Tcl_Obj *tcl_result;
     83    int supported;
     84    int len;
     85
     86    tcl_result = Tcl_GetVar2Ex(interp, "portsandbox_supported", NULL, TCL_GLOBAL_ONLY);
     87    if (!tcl_result || Tcl_GetBooleanFromObj(interp, tcl_result, &supported) != TCL_OK || !supported) {
     88        return 0;
     89    }
     90
     91    tcl_result = Tcl_GetVar2Ex(interp, "portutil::autoconf::sandbox_exec_path", NULL, TCL_GLOBAL_ONLY);
     92    if (!tcl_result || !(*sandbox_exec_path = Tcl_GetString(tcl_result))) {
     93        return 0;
     94    }
     95
     96    tcl_result = Tcl_GetVar2Ex(interp, "portsandbox_profile", NULL, TCL_GLOBAL_ONLY);
     97    if (!tcl_result || !(*profilestr = Tcl_GetStringFromObj(tcl_result, &len))
     98        || len == 0) {
     99        return 0;
     100    }
     101
     102    return 1;
     103}
     104
    80105/* usage: system ?-notty? ?-nice value? ?-W path? command */
    81106int SystemCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
     
    84109    struct linebuf circbuf[CBUFSIZ];
    85110    size_t linelen;
    86     char *args[4];
     111    char *args[7];
    87112    char *cmdstring;
     113    int sandbox = 0;
     114    char *sandbox_exec_path;
     115    char *profilestr;
    88116    FILE *pdes;
    89117    int fdset[2], nullfd;
     
    129157    }
    130158
     159#if 0
     160    /* check if and how we should use sandbox-exec */
     161    sandbox = check_sandboxing(interp, &sandbox_exec_path, &profilestr);
     162#endif
     163
    131164    /*
    132165     * Fork a child to run the command, in a popen() like fashion -
     
    179212
    180213        /* XXX ugly string constants */
    181         args[0] = "sh";
    182         args[1] = "-c";
    183         args[2] = cmdstring;
    184         args[3] = NULL;
    185         execve("/bin/sh", args, environ);
     214        if (sandbox) {
     215            args[0] = "sandbox-exec";
     216            args[1] = "-p";
     217            args[2] = profilestr;
     218            args[3] = "sh";
     219            args[4] = "-c";
     220            args[5] = cmdstring;
     221            args[6] = NULL;
     222            execve(sandbox_exec_path, args, environ);
     223        } else {
     224            args[0] = "sh";
     225            args[1] = "-c";
     226            args[2] = cmdstring;
     227            args[3] = NULL;
     228            execve("/bin/sh", args, environ);
     229        }
    186230        _exit(1);
    187231        break;
  • trunk/base/src/port1.0/Makefile

    r93261 r98156  
    77        portdeactivate.tcl portsubmit.tcl port_autoconf.tcl portstartupitem.tcl \
    88        porttrace.tcl portlivecheck.tcl portdistcheck.tcl portmirror.tcl \
    9         portload.tcl portunload.tcl portdistfiles.tcl fetch_common.tcl
     9        portload.tcl portunload.tcl portdistfiles.tcl fetch_common.tcl \
     10        portsandbox.tcl
    1011
    1112include ../../Mk/macports.subdir.mk
  • trunk/base/src/port1.0/port.tcl

    r79593 r98156  
    5959
    6060package require portdistfiles 1.0
     61package require portsandbox 1.0
  • trunk/base/src/port1.0/port_autoconf.tcl.in

    r88721 r98156  
    6666        variable xcodebuild_path "@XCODEBUILD@"
    6767        variable xcrun_path "@XCRUN@"
     68        variable sandbox_exec_path "@SANDBOX_EXEC@"
    6869        variable sed_command "@SED@"
    6970        variable sed_ext_flag "@SED_EXT@"
Note: See TracChangeset for help on using the changeset viewer.