Beispiel #1
0
def run_one_command(execname, config, filters, userargs):
    # Execute command if it matches any of the loaded filters
    try:
        obj = wrapper.start_subprocess(filters,
                                       userargs,
                                       exec_dirs=config.exec_dirs,
                                       log=config.use_syslog,
                                       stdin=sys.stdin,
                                       stdout=sys.stdout,
                                       stderr=sys.stderr)
        returncode = obj.wait()
        # Fix returncode of Popen
        if returncode < 0:
            returncode = SIGNAL_BASE - returncode
        sys.exit(returncode)

    except wrapper.FilterMatchNotExecutable as exc:
        msg = ("Executable not found: %s (filter match = %s)" %
               (exc.match.exec_path, exc.match.name))
        _exit_error(execname, msg, RC_NOEXECFOUND, log=config.use_syslog)

    except wrapper.NoFilterMatched:
        msg = ("Unauthorized command: %s (no filter matched)" %
               ' '.join(userargs))
        _exit_error(execname, msg, RC_UNAUTHORIZED, log=config.use_syslog)
Beispiel #2
0
def run_one_command(execname, config, filters, userargs):
    # Execute command if it matches any of the loaded filters
    try:
        obj = wrapper.start_subprocess(
            filters, userargs,
            exec_dirs=config.exec_dirs,
            log=config.use_syslog,
            stdin=sys.stdin,
            stdout=sys.stdout,
            stderr=sys.stderr)
        returncode = obj.wait()
        # Fix returncode of Popen
        if returncode < 0:
            returncode = SIGNAL_BASE - returncode
        sys.exit(returncode)

    except wrapper.FilterMatchNotExecutable as exc:
        msg = ("Executable not found: %s (filter match = %s)"
               % (exc.match.exec_path, exc.match.name))
        _exit_error(execname, msg, RC_NOEXECFOUND, log=config.use_syslog)

    except wrapper.NoFilterMatched:
        msg = ("Unauthorized command: %s (no filter matched)"
               % ' '.join(userargs))
        _exit_error(execname, msg, RC_UNAUTHORIZED, log=config.use_syslog)
Beispiel #3
0
    def run_one_command(self, userargs, stdin=None):
        self.reset_timer()
        try:
            obj = wrapper.start_subprocess(
                self.filters, userargs,
                exec_dirs=self.config.exec_dirs,
                log=self.config.use_syslog,
                close_fds=True,
                stdin=subprocess.PIPE,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE)
        except wrapper.FilterMatchNotExecutable:
            LOG.warning("Executable not found for: %s",
                        ' '.join(userargs))
            return cmd.RC_NOEXECFOUND, "", ""

        except wrapper.NoFilterMatched:
            LOG.warning("Unauthorized command: %s (no filter matched)",
                        ' '.join(userargs))
            return cmd.RC_UNAUTHORIZED, "", ""

        if six.PY3 and stdin is not None:
            stdin = os.fsencode(stdin)
        out, err = obj.communicate(stdin)
        if six.PY3:
            out = os.fsdecode(out)
            err = os.fsdecode(err)
        return obj.returncode, out, err
Beispiel #4
0
 def run_one_command(self, userargs, stdin=None):
     obj = wrapper.start_subprocess(self.filters,
                                    userargs,
                                    exec_dirs=self.config.exec_dirs,
                                    log=self.config.use_syslog,
                                    close_fds=True,
                                    stdin=subprocess.PIPE,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE)
     out, err = obj.communicate(stdin)
     return obj.returncode, out, err
Beispiel #5
0
 def run_one_command(self, userargs, stdin=None):
     obj = wrapper.start_subprocess(
         self.filters, userargs,
         exec_dirs=self.config.exec_dirs,
         log=self.config.use_syslog,
         close_fds=True,
         stdin=subprocess.PIPE,
         stdout=subprocess.PIPE,
         stderr=subprocess.PIPE)
     out, err = obj.communicate(stdin)
     return obj.returncode, out, err
Beispiel #6
0
 def run_one_command(self, userargs, stdin=None):
     obj = wrapper.start_subprocess(self.filters,
                                    userargs,
                                    exec_dirs=self.config.exec_dirs,
                                    log=self.config.use_syslog,
                                    close_fds=True,
                                    stdin=subprocess.PIPE,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE)
     if six.PY3 and stdin is not None:
         stdin = os.fsencode(stdin)
     out, err = obj.communicate(stdin)
     if six.PY3:
         out = os.fsdecode(out)
         err = os.fsdecode(err)
     return obj.returncode, out, err
Beispiel #7
0
 def run_one_command(self, userargs, stdin=None):
     obj = wrapper.start_subprocess(
         self.filters, userargs,
         exec_dirs=self.config.exec_dirs,
         log=self.config.use_syslog,
         close_fds=True,
         stdin=subprocess.PIPE,
         stdout=subprocess.PIPE,
         stderr=subprocess.PIPE)
     if six.PY3 and stdin is not None:
         stdin = os.fsencode(stdin)
     out, err = obj.communicate(stdin)
     if six.PY3:
         out = os.fsdecode(out)
         err = os.fsdecode(err)
     return obj.returncode, out, err