Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_clearLog_unreadable(self):
supervisord = DummySupervisor()
interface = self._makeOne(supervisord)
self._assertRPCError(xmlrpc.Faults.NO_FILE, interface.clearLog)
def traverse(ob, method, params):
dotted_parts = method.split('.')
# security (CVE-2017-11610, don't allow object traversal)
if len(dotted_parts) != 2:
raise RPCError(Faults.UNKNOWN_METHOD)
namespace, method = dotted_parts
# security (don't allow methods that start with an underscore to
# be called remotely)
if method.startswith('_'):
raise RPCError(Faults.UNKNOWN_METHOD)
rpcinterface = getattr(ob, namespace, None)
if rpcinterface is None:
raise RPCError(Faults.UNKNOWN_METHOD)
func = getattr(rpcinterface, method, None)
if not isinstance(func, types.MethodType):
raise RPCError(Faults.UNKNOWN_METHOD)
try:
def multi(remaining_calls=remaining_calls,
callbacks=callbacks,
results=results):
# if waiting on a callback, call it, then remove it if it's done
if callbacks:
try:
value = callbacks[0]()
except RPCError as exc:
value = {'faultCode': exc.code,
'faultString': exc.text}
except:
info = sys.exc_info()
errmsg = "%s:%s" % (info[0], info[1])
value = {'faultCode': Faults.FAILED,
'faultString': 'FAILED: ' + errmsg}
if value is not NOT_DONE_YET:
callbacks.pop(0)
results.append(value)
# if we don't have a callback now, pop calls and call them in
# order until one returns a callback.
while (not callbacks) and remaining_calls:
call = remaining_calls.pop(0)
name = call.get('methodName', None)
params = call.get('params', [])
try:
if name is None:
raise RPCError(Faults.INCORRECT_PARAMETERS,
'No methodName')
def _update(self, text):
self.update_text = text # for unit tests, mainly
if ( isinstance(self.supervisord.options.mood, int) and
self.supervisord.options.mood < SupervisorStates.RUNNING ):
raise RPCError(Faults.SHUTDOWN_STATE)
def upcheck(self):
try:
supervisor = self.get_supervisor()
api = supervisor.getVersion() # deprecated
from supervisor import rpcinterface
if api != rpcinterface.API_VERSION:
self.output(
'Sorry, this version of supervisorctl expects to '
'talk to a server with API version %s, but the '
'remote version is %s.' % (rpcinterface.API_VERSION, api))
return False
except xmlrpclib.Fault, e:
if e.faultCode == xmlrpc.Faults.UNKNOWN_METHOD:
self.output(
'Sorry, supervisord responded but did not recognize '
'the supervisor namespace commands that supervisorctl '
'uses to control it. Please check that the '
'[rpcinterface:supervisor] section is enabled in the '
'configuration file (see sample.conf).')
return False
raise
except socket.error, why:
if why.args[0] == errno.ECONNREFUSED:
self.output('%s refused connection' % self.options.serverurl)
return False
elif why.args[0] == errno.ENOENT:
self.output('%s no such file' % self.options.serverurl)
return False
raise
@param int offset offset to start reading from.
@param int length number of bytes to read from the log.
@return string result Bytes of log
"""
self._update('readLog')
logfile = self.supervisord.options.logfile
if logfile is None or not os.path.exists(logfile):
raise RPCError(Faults.NO_FILE, logfile)
try:
return readFile(logfile, int(offset), int(length))
except ValueError, inst:
why = inst.args[0]
raise RPCError(getattr(Faults, why))
return wrong
process = group.processes.get(process_name)
if process is None:
return wrong
if action == 'start':
try:
bool_or_callback = (
rpcinterface.supervisor.startProcess(namespec)
)
except RPCError as e:
if e.code == Faults.NO_FILE:
msg = 'no such file'
elif e.code == Faults.NOT_EXECUTABLE:
msg = 'file not executable'
elif e.code == Faults.ALREADY_STARTED:
msg = 'already started'
elif e.code == Faults.SPAWN_ERROR:
msg = 'spawn error'
elif e.code == Faults.ABNORMAL_TERMINATION:
msg = 'abnormal termination'
else:
msg = 'unexpected rpc fault [%d] %s' % (
e.code, e.text)
def starterr():
return 'ERROR: Process %s: %s' % (namespec, msg)
starterr.delay = 0.05
return starterr
if callable(bool_or_callback):
def startprocess():
try:
def _startresult(self, result):
name = make_namespec(result['group'], result['name'])
code = result['status']
template = '%s: ERROR (%s)'
if code == xmlrpc.Faults.BAD_NAME:
return template % (name, 'no such process')
elif code == xmlrpc.Faults.NO_FILE:
return template % (name, 'no such file')
elif code == xmlrpc.Faults.NOT_EXECUTABLE:
return template % (name, 'file is not executable')
elif code == xmlrpc.Faults.ALREADY_STARTED:
return template % (name, 'already started')
elif code == xmlrpc.Faults.SPAWN_ERROR:
return template % (name, 'spawn error')
elif code == xmlrpc.Faults.ABNORMAL_TERMINATION:
return template % (name, 'abnormal termination')
elif code == xmlrpc.Faults.SUCCESS:
return '%s: started' % name
# assertion
raise ValueError('Unknown result code %s for %s' % (code, name))
wrong.delay = 0.05
group_name, process_name = split_namespec(namespec)
group = supervisord.process_groups.get(group_name)
if group is None:
return wrong
process = group.processes.get(process_name)
if process is None:
return wrong
if action == 'start':
try:
bool_or_callback = (
rpcinterface.supervisor.startProcess(namespec)
)
except RPCError as e:
if e.code == Faults.NO_FILE:
msg = 'no such file'
elif e.code == Faults.NOT_EXECUTABLE:
msg = 'file not executable'
elif e.code == Faults.ALREADY_STARTED:
msg = 'already started'
elif e.code == Faults.SPAWN_ERROR:
msg = 'spawn error'
elif e.code == Faults.ABNORMAL_TERMINATION:
msg = 'abnormal termination'
else:
msg = 'unexpected rpc fault [%d] %s' % (
e.code, e.text)
def starterr():
return 'ERROR: Process %s: %s' % (namespec, msg)
starterr.delay = 0.05
return starterr
def _update(self, text):
self.update_text = text # for unit tests, mainly
if ( isinstance(self.supervisord.options.mood, int) and
self.supervisord.options.mood < SupervisorStates.RUNNING ):
raise RPCError(Faults.SHUTDOWN_STATE)