def main(client_id, user_arguments_dict): """Main function used by front end""" (configuration, logger, output_objects, op_name) = \ initialize_main_variables(client_id, op_header=False, op_title=False, op_menu=client_id) defaults = signature()[1] (validate_status, accepted) = validate_input(user_arguments_dict, defaults, output_objects, allow_rejects=False) if not validate_status: return (accepted, returnvalues.CLIENT_ERROR) remote_ip = str(os.getenv('REMOTE_ADDR')) res_type = accepted['type'][-1] unique_resource_name = accepted['unique_resource_name'][-1] exe_name = accepted['exe_name'][-1] pgid = accepted['pgid'][-1] status = returnvalues.OK # Web format for cert access and no header for SID access if client_id: output_objects.append({ 'object_type': 'title', 'text': 'Load resource script PGID' }) output_objects.append({ 'object_type': 'header', 'text': 'Load resource script PGID' }) else: output_objects.append({'object_type': 'start'}) # Please note that base_dir must end in slash to avoid access to other # resource dirs when own name is a prefix of another resource name base_dir = os.path.abspath( os.path.join(configuration.resource_home, unique_resource_name)) + os.sep # We do not have a trusted base dir here since there's no certificate data. # Manually check input variables if not valid_dir_input(configuration.resource_home, unique_resource_name): # out of bounds - rogue resource!?!? msg = 'invalid unique_resource_name! %s' % unique_resource_name logger.error('putrespgid FE called with illegal parameter(s) in what appears to be an illegal directory traversal attempt!: unique_resource_name %s, exe %s, client_id %s' \ % (unique_resource_name, exe_name, client_id)) return (output_objects, returnvalues.CLIENT_ERROR) if not valid_dir_input(base_dir, 'EXE_%s.PGID' % exe_name): # out of bounds - rogue resource!?!? msg = 'invalid unique_resource_name / exe_name! %s / %s' \ % (unique_resource_name, exe_name) logger.error('putrespgid EXE called with illegal parameter(s) in what appears to be an illegal directory traversal attempt!: unique_resource_name %s, exe %s, client_id %s' \ % (unique_resource_name, exe_name, client_id)) return (output_objects, returnvalues.CLIENT_ERROR) (load_status, resource_conf) = \ get_resource_configuration(configuration.resource_home, unique_resource_name, logger) if not load_status: logger.error("Invalid putrespgid - no resouce_conf for: %s : %s" % \ (unique_resource_name, resource_conf)) output_objects.append({ 'object_type': 'error_text', 'text': 'invalid request: no such resource!' }) return (output_objects, returnvalues.CLIENT_ERROR) # Check that resource address matches request source to make DoS harder proxy_fqdn = resource_conf.get('FRONTENDPROXY', None) try: check_source_ip(remote_ip, unique_resource_name, proxy_fqdn) except ValueError, vae: logger.error("Invalid put pgid: %s" % vae) output_objects.append({ 'object_type': 'error_text', 'text': 'invalid request: %s' % vae }) return (output_objects, returnvalues.CLIENT_ERROR)
def main(client_id, user_arguments_dict): """Main function used by front end""" (configuration, logger, output_objects, op_name) = \ initialize_main_variables(client_id, op_header=False, op_title=False, op_menu=client_id) defaults = signature()[1] (validate_status, accepted) = validate_input(user_arguments_dict, defaults, output_objects, allow_rejects=False) if not validate_status: return (accepted, returnvalues.CLIENT_ERROR) remote_ip = str(os.getenv('REMOTE_ADDR')) res_type = accepted['type'][-1] unique_resource_name = accepted['unique_resource_name'][-1] exe_name = accepted['exe_name'][-1] status = returnvalues.OK # Web format for cert access and no header for SID access if client_id: output_objects.append({'object_type': 'title', 'text' : 'Load resource script PGID'}) output_objects.append({'object_type': 'header', 'text' : 'Load resource script PGID'}) else: output_objects.append({'object_type': 'start'}) # Please note that base_dir must end in slash to avoid access to other # resource dirs when own name is a prefix of another resource name base_dir = os.path.abspath(os.path.join(configuration.resource_home, unique_resource_name)) + os.sep if not is_owner(client_id, unique_resource_name, configuration.resource_home, logger): output_objects.append( {'object_type': 'error_text', 'text': "Failure: You must be an owner of '%s' to get the PGID!" % \ unique_resource_name}) return (output_objects, returnvalues.CLIENT_ERROR) # is_owner incorporates unique_resource_name verification - no need to # specifically check for illegal directory traversal on that variable. # exe_name is not automatically checked however - do it manually if not valid_dir_input(base_dir, 'EXE_' + exe_name + '.PGID'): # out of bounds - rogue resource!?!? output_objects.append({'object_type': 'error_text', 'text': 'invalid exe_name! %s' % exe_name}) logger.error('''getrespgid called with illegal parameter(s) in what appears to be an illegal directory traversal attempt!: unique_resource_name %s, exe %s, client_id %s''' % (unique_resource_name, exe_name, client_id)) return (output_objects, returnvalues.CLIENT_ERROR) # Check that resource address matches request source to make DoS harder try: check_source_ip(remote_ip, unique_resource_name) except ValueError, vae: output_objects.append({'object_type': 'error_text', 'text': 'invalid request: %s' % vae}) logger.error("Invalid put pgid: %s" % vae) return (output_objects, returnvalues.CLIENT_ERROR)
def main(client_id, user_arguments_dict): """Main function used by front end""" (configuration, logger, output_objects, op_name) = \ initialize_main_variables(client_id, op_header=False, op_title=False, op_menu=client_id) defaults = signature()[1] (validate_status, accepted) = validate_input(user_arguments_dict, defaults, output_objects, allow_rejects=False) if not validate_status: return (accepted, returnvalues.CLIENT_ERROR) remote_ip = str(os.getenv('REMOTE_ADDR')) res_type = accepted['type'][-1] unique_resource_name = accepted['unique_resource_name'][-1] exe_name = accepted['exe_name'][-1] status = returnvalues.OK # Web format for cert access and no header for SID access if client_id: output_objects.append({ 'object_type': 'title', 'text': 'Load resource script PGID' }) output_objects.append({ 'object_type': 'header', 'text': 'Load resource script PGID' }) else: output_objects.append({'object_type': 'start'}) # Please note that base_dir must end in slash to avoid access to other # resource dirs when own name is a prefix of another resource name base_dir = os.path.abspath( os.path.join(configuration.resource_home, unique_resource_name)) + os.sep if not is_owner(client_id, unique_resource_name, configuration.resource_home, logger): output_objects.append( {'object_type': 'error_text', 'text': "Failure: You must be an owner of '%s' to get the PGID!" % \ unique_resource_name}) return (output_objects, returnvalues.CLIENT_ERROR) # is_owner incorporates unique_resource_name verification - no need to # specifically check for illegal directory traversal on that variable. # exe_name is not automatically checked however - do it manually if not valid_dir_input(base_dir, 'EXE_' + exe_name + '.PGID'): # out of bounds - rogue resource!?!? output_objects.append({ 'object_type': 'error_text', 'text': 'invalid exe_name! %s' % exe_name }) logger.error('''getrespgid called with illegal parameter(s) in what appears to be an illegal directory traversal attempt!: unique_resource_name %s, exe %s, client_id %s''' % (unique_resource_name, exe_name, client_id)) return (output_objects, returnvalues.CLIENT_ERROR) # Check that resource address matches request source to make DoS harder try: check_source_ip(remote_ip, unique_resource_name) except ValueError, vae: output_objects.append({ 'object_type': 'error_text', 'text': 'invalid request: %s' % vae }) logger.error("Invalid put pgid: %s" % vae) return (output_objects, returnvalues.CLIENT_ERROR)
def main(client_id, user_arguments_dict): """Main function used by front end""" (configuration, logger, output_objects, op_name) = \ initialize_main_variables(client_id, op_header=False, op_title=False, op_menu=client_id) defaults = signature()[1] (validate_status, accepted) = validate_input(user_arguments_dict, defaults, output_objects, allow_rejects=False) if not validate_status: return (accepted, returnvalues.CLIENT_ERROR) remote_ip = str(os.getenv('REMOTE_ADDR')) res_type = accepted['type'][-1] unique_resource_name = accepted['unique_resource_name'][-1] exe_name = accepted['exe_name'][-1] pgid = accepted['pgid'][-1] status = returnvalues.OK # Web format for cert access and no header for SID access if client_id: output_objects.append({'object_type': 'title', 'text' : 'Load resource script PGID'}) output_objects.append({'object_type': 'header', 'text' : 'Load resource script PGID'}) else: output_objects.append({'object_type': 'start'}) # Please note that base_dir must end in slash to avoid access to other # resource dirs when own name is a prefix of another resource name base_dir = os.path.abspath(os.path.join(configuration.resource_home, unique_resource_name)) + os.sep # We do not have a trusted base dir here since there's no certificate data. # Manually check input variables if not valid_dir_input(configuration.resource_home, unique_resource_name): # out of bounds - rogue resource!?!? msg = 'invalid unique_resource_name! %s' % unique_resource_name logger.error('putrespgid FE called with illegal parameter(s) in what appears to be an illegal directory traversal attempt!: unique_resource_name %s, exe %s, client_id %s' \ % (unique_resource_name, exe_name, client_id)) return (output_objects, returnvalues.CLIENT_ERROR) if not valid_dir_input(base_dir, 'EXE_%s.PGID' % exe_name): # out of bounds - rogue resource!?!? msg = 'invalid unique_resource_name / exe_name! %s / %s' \ % (unique_resource_name, exe_name) logger.error('putrespgid EXE called with illegal parameter(s) in what appears to be an illegal directory traversal attempt!: unique_resource_name %s, exe %s, client_id %s' \ % (unique_resource_name, exe_name, client_id)) return (output_objects, returnvalues.CLIENT_ERROR) # Check that resource address matches request source to make DoS harder try: check_source_ip(remote_ip, unique_resource_name) except ValueError, vae: output_objects.append({'object_type': 'error_text', 'text': 'invalid request: %s' % vae}) logger.error("Invalid put pgid: %s" % vae) return (output_objects, returnvalues.CLIENT_ERROR)
def main(client_id, user_arguments_dict): """Main function used by front end""" (configuration, logger, output_objects, op_name) = \ initialize_main_variables(client_id, op_header=False, op_title=False, op_menu=client_id) defaults = signature()[1] (validate_status, accepted) = validate_input(user_arguments_dict, defaults, output_objects, allow_rejects=False) if not validate_status: return (accepted, returnvalues.CLIENT_ERROR) remote_ip = str(os.getenv('REMOTE_ADDR')) unique_resource_name = accepted['unique_resource_name'][-1] exe = accepted['exe'][-1] cputime = int(accepted['cputime'][-1]) nodecount = int(accepted['nodecount'][-1]) localjobname = accepted['localjobname'][-1] sandboxkey = accepted['sandboxkey'][-1] execution_delay = int(accepted['execution_delay'][-1]) exe_pgid = int(accepted['exe_pgid'][-1]) status = returnvalues.OK # No header and footer here output_objects.append({'object_type': 'start'}) output_objects.append({'object_type': 'script_status', 'text': ''}) # Please note that base_dir must end in slash to avoid access to other # resource dirs when own name is a prefix of another resource name base_dir = os.path.abspath(os.path.join(configuration.resource_home, unique_resource_name)) + os.sep if not is_resource(unique_resource_name, configuration.resource_home): output_objects.append( {'object_type': 'error_text', 'text': "Failure: You must be an owner of '%s' to get the PGID!" % \ unique_resource_name}) return (output_objects, returnvalues.CLIENT_ERROR) # is_resource incorporates unique_resource_name verification - no need to # specifically check for illegal directory traversal on that variable. (load_status, resource_conf) = \ get_resource_configuration(configuration.resource_home, unique_resource_name, logger) if not load_status: logger.error("Invalid requestnewjob - no resouce_conf for: %s : %s" % \ (unique_resource_name, resource_conf)) output_objects.append({'object_type': 'error_text', 'text': 'invalid request: no such resource!'}) return (output_objects, returnvalues.CLIENT_ERROR) # Check that resource address matches request source to make DoS harder proxy_fqdn = resource_conf.get('FRONTENDPROXY', None) try: check_source_ip(remote_ip, unique_resource_name, proxy_fqdn) except ValueError, vae: logger.error("Invalid requestnewjob: %s (%s)" % (vae, accepted)) output_objects.append({'object_type': 'error_text', 'text': 'invalid request: %s' % vae}) return (output_objects, returnvalues.CLIENT_ERROR)
# No owner check here so we need to specifically check for illegal # directory traversals if not valid_dir_input(configuration.resource_home, unique_resource_name): # out of bounds - rogue resource!?!? o.out('invalid unique_resource_name! %s' % unique_resource_name) o.internal('requestinteractivejob called with illegal parameter(s) in what appears to be an illegal directory traversal attempt!: unique_resource_name %s, exe %s, client_id %s' % (unique_resource_name, exe, client_id)) o.reply_and_exit(o.CLIENT_ERROR) # Check that resource address matches request source to make DoS harder try: check_source_ip(remote_ip, unique_resource_name) except ValueError, vae: o.out("Warning: interactive job request not sent from expected resource address!") o.internal("invalid interactive job request: %s" % vae) o.reply_and_exit(o.CLIENT_ERROR) # TODO: add full session ID check here if exe == '': o.out('requestinteractivejob error! exe was not specified in the query string. Looks like a mis-configured resource!' ) o.reply_and_exit(o.ERROR) if jobid == '': o.out('requestinteractivejob error! jobid was not specified in the query string. Looks like a mis-configured resource!' )