code
stringlengths
41
2.04k
label_name
stringclasses
2 values
label
int64
0
1
def update_fence_device(params, request, session) if not allowed_for_local_cluster(session, Permissions::WRITE) return 403, 'Permission denied' end $logger.info "Updating fence device" $logger.info params param_line = getParamList(params) $logger.info param_line if not params[:resource_id] out, ...
CWE-384
1
def add_group(params, request, session) if not allowed_for_local_cluster(session, Permissions::WRITE) return 403, 'Permission denied' end rg = params["resource_group"] resources = params["resources"] output, errout, retval = run_cmd( session, PCS, "resource", "group", "add", rg, *(resources.split(" ")...
CWE-384
1
def get_crm_mon_dom(session) begin stdout, _, retval = run_cmd( session, CRM_MON, '--one-shot', '-r', '--as-xml' ) if retval == 0 return REXML::Document.new(stdout.join("\n")) end rescue $logger.error 'Failed to parse crm_mon.' end return nil end
CWE-384
1
def config_restore(params, request, session) if params[:name] code, response = send_request_with_token( session, params[:name], 'config_restore', true, {:tarball => params[:tarball]} ) else if not allowed_for_local_cluster(session, Permissions::FULL) return 403, 'Permission denied' ...
CWE-384
1
def fence_device_metadata(params, request, session) if not allowed_for_local_cluster(session, Permissions::READ) return 403, 'Permission denied' end return 200 if not params[:resourcename] or params[:resourcename] == "" @fenceagent = FenceAgent.new(params[:resourcename]) @fenceagent.required_options, @fen...
CWE-384
1
def get_acls(session, cib_dom=nil) unless cib_dom cib_dom = get_cib_dom(session) return {} unless cib_dom end acls = { 'role' => {}, 'group' => {}, 'user' => {}, 'target' => {} } cib_dom.elements.each('/cib/configuration/acls/*') { |e| type = e.name[4..-1] if e.name == 'acl_r...
CWE-384
1
def resource_unclone(params, request, session) if not allowed_for_local_cluster(session, Permissions::WRITE) return 403, 'Permission denied' end unless params[:resource_id] return [400, 'resource_id has to be specified.'] end _, stderr, retval = run_cmd( session, PCS, 'resource', 'unclone', para...
CWE-384
1
def get_cluster_tokens(params, request, session) # pcsd runs as root thus always returns hacluster's tokens if not allowed_for_local_cluster(session, Permissions::FULL) return 403, "Permission denied" end on, off = get_nodes nodes = on + off nodes.uniq! return [200, JSON.generate(get_tokens_of_nodes(n...
CWE-384
1
def getFenceAgents(session, fence_agent = nil) fence_agent_list = {} agents = Dir.glob('/usr/sbin/fence_' + '*') agents.each { |a| fa = FenceAgent.new fa.name = a.sub(/.*\//,"") next if fa.name == "fence_ack_manual" if fence_agent and a.sub(/.*\//,"") == fence_agent.sub(/.*:/,"") required_...
CWE-384
1
def cluster_status_gui(session, cluster_name, dont_update_config=false) cluster_nodes = get_cluster_nodes(cluster_name) status = cluster_status_from_nodes(session, cluster_nodes, cluster_name) unless status return 403, 'Permission denied' end new_cluster_nodes = [] new_cluster_nodes += status[:corosync...
CWE-384
1
def get_stonith_agents_avail(session) code, result = send_cluster_request_with_token( session, params[:cluster], 'get_avail_fence_agents' ) return {} if 200 != code begin sa = JSON.parse(result) if (sa["noresponse"] == true) or (sa["notauthorized"] == "true") or (sa["notoken"] == true) or (sa["pacem...
CWE-384
1
def get_sync_capabilities(params, request, session) return JSON.generate({ 'syncable_configs' => Cfgsync::get_cfg_classes_by_name().keys, }) end
CWE-384
1
def initialize(session, configs, nodes, cluster_name, tokens={}) @configs = configs @nodes = nodes @cluster_name = cluster_name @published_configs_names = @configs.collect { |cfg| cfg.class.name } @additional_tokens = tokens @session = session end
CWE-384
1
def get_current_node_name() stdout, stderror, retval = run_cmd( PCSAuth.getSuperuserSession, CRM_NODE, "-n" ) if retval == 0 and stdout.length > 0 return stdout[0].chomp() end return "" end
CWE-384
1
def cluster_disable(params, request, session) if params[:name] code, response = send_request_with_token( session, params[:name], 'cluster_disable', true ) else if not allowed_for_local_cluster(session, Permissions::WRITE) return 403, 'Permission denied' end success = disable_cluster(...
CWE-384
1
def resource_master(params, request, session) if not allowed_for_local_cluster(session, Permissions::WRITE) return 403, 'Permission denied' end unless params[:resource_id] return [400, 'resource_id has to be specified.'] end _, stderr, retval = run_cmd( session, PCS, 'resource', 'master', params[...
CWE-384
1
def get_cman_version() begin stdout, stderror, retval = run_cmd( PCSAuth.getSuperuserSession, CMAN_TOOL, "-V" ) rescue stdout = [] end if retval == 0 match = /(\d+)\.(\d+)\.(\d+)/.match(stdout.join()) if match return match[1..3].collect { | x | x.to_i } end end return nil...
CWE-384
1
def protected! gui_request = ( # these are URLs for web pages request.path == '/' or request.path == '/manage' or request.path == '/permissions' or request.path.match('/managec/.+/main') ) if request.path.start_with?('/remote/') or request.path == '/run_pcs' unless PCSAuth.lo...
CWE-384
1
def add_meta_attr(session, resource, key, value) stdout, stderr, retval = run_cmd( session, PCS, "resource", "meta", resource, key.to_s + "=" + value.to_s ) return retval end
CWE-384
1
def add_order_constraint( session, resourceA, resourceB, actionA, actionB, score, symmetrical=true, force=false, autocorrect=true ) sym = symmetrical ? "symmetrical" : "nonsymmetrical" if score != "" score = "score=" + score end command = [ PCS, "constraint", "order", actionA, resourceA, "then",...
CWE-384
1
def set_resource_utilization(params, reqest, session) unless allowed_for_local_cluster(session, Permissions::WRITE) return 403, 'Permission denied' end unless params[:resource_id] and params[:name] return 400, 'resource_id and name are required' end res_id = params[:resource_id] name = params[:nam...
CWE-384
1
def add_fence_level_remote(params, request, session) if not allowed_for_local_cluster(session, Permissions::WRITE) return 403, 'Permission denied' end retval, stdout, stderr = add_fence_level( session, params["level"], params["devices"], params["node"], params["remove"] ) if retval == 0 return [20...
CWE-384
1
def get_cib(params, request, session) if not allowed_for_local_cluster(session, Permissions::READ) return 403, 'Permission denied' end cib, stderr, retval = run_cmd(session, CIBADMIN, "-Ql") if retval != 0 if not pacemaker_running? return [400, '{"pacemaker_not_running":true}'] end return ...
CWE-384
1
def remove_acl_usergroup(session, role_id, usergroup_id) stdout, stderror, retval = run_cmd( session, PCS, "acl", "role", "unassign", role_id.to_s, usergroup_id.to_s, "--autodelete" ) if retval != 0 if stderror.empty? return "Error removing user / group" else return stderror.join("\n")...
CWE-384
1
def get_cib_dom(session) begin stdout, _, retval = run_cmd(session, 'cibadmin', '-Q', '-l') if retval == 0 return REXML::Document.new(stdout.join("\n")) end rescue $logger.error 'Failed to parse cib.' end return nil end
CWE-384
1
def create_cluster(params, request, session) if not allowed_for_superuser(session) return 403, 'Permission denied' end if set_corosync_conf(params, request, session) cluster_start(params, request, session) else return "Failed" end end
CWE-384
1
def get_corosync_conf_remote(params, request, session) if not allowed_for_local_cluster(session, Permissions::READ) return 403, 'Permission denied' end return get_corosync_conf() end
CWE-384
1
def add_order_set_constraint( session, resource_set_list, force=false, autocorrect=true ) command = [PCS, "constraint", "order"] resource_set_list.each { |resource_set| command << "set" command.concat(resource_set) } command << '--force' if force command << '--autocorrect' if autocorrect stdout, s...
CWE-384
1
def get_quorum_info(params, request, session) if not allowed_for_local_cluster(session, Permissions::READ) return 403, 'Permission denied' end if ISRHEL6 stdout_status, stderr_status, retval = run_cmd( PCSAuth.getSuperuserSession, CMAN_TOOL, "status" ) stdout_nodes, stderr_nodes, retval = ru...
CWE-384
1
def get_corosync_nodes() stdout, stderror, retval = run_cmd( PCSAuth.getSuperuserSession, PCS, "status", "nodes", "corosync" ) if retval != 0 return [] end stdout.each {|x| x.strip!} corosync_online = stdout[1].sub(/^.*Online:/,"").strip corosync_offline = stdout[2].sub(/^.*Offline:/,"").strip ...
CWE-384
1
def need_ring1_address?() out, errout, retval = run_cmd(PCSAuth.getSuperuserSession, COROSYNC_CMAPCTL) if retval != 0 return false else udpu_transport = false rrp = false out.each { |line| # support both corosync-objctl and corosync-cmapctl format if /^\s*totem\.transport(\s+.*)?=\s*ud...
CWE-384
1
def get_nodes_status() corosync_online = [] corosync_offline = [] pacemaker_online = [] pacemaker_offline = [] pacemaker_standby = [] in_pacemaker = false stdout, stderr, retval = run_cmd( PCSAuth.getSuperuserSession, PCS, "status", "nodes", "both" ) stdout.each {|l| l = l.chomp if l.start...
CWE-384
1
def run_cmd_options(session, options, *args) $logger.info("Running: " + args.join(" ")) start = Time.now out = "" errout = "" proc_block = proc { |pid, stdin, stdout, stderr| if options and options.key?('stdin') stdin.puts(options['stdin']) stdin.close() end out = stdout.readlines() ...
CWE-384
1
def send_request_with_token(session, node, request, post=false, data={}, remote=true, raw_data=nil, timeout=30, additional_tokens={}) token = additional_tokens[node] || get_node_token(node) $logger.info "SRWT Node: #{node} Request: #{request}" if not token $logger.error "Unable to connect to node #{node}, no ...
CWE-384
1
def self.loginByToken(session, cookies) if username = validToken(cookies["token"]) if SUPERUSER == username if cookies['CIB_user'] and cookies['CIB_user'].strip != '' session[:username] = cookies['CIB_user'] if cookies['CIB_user_groups'] and cookies['CIB_user_groups'].strip != ''...
CWE-384
1
def resource_stop(params, request, session) if not allowed_for_local_cluster(session, Permissions::WRITE) return 403, 'Permission denied' end stdout, stderr, retval = run_cmd( session, PCS, "resource", "disable", params[:resource] ) if retval == 0 return JSON.generate({"success" => "true"}) else...
CWE-384
1
def remove_constraint_remote(params, request, session) if not allowed_for_local_cluster(session, Permissions::WRITE) return 403, 'Permission denied' end if params[:constraint_id] retval = remove_constraint(session, params[:constraint_id]) if retval == 0 return "Constraint #{params[:constraint_id...
CWE-384
1
def set_certs(params, request, session) if not allowed_for_local_cluster(session, Permissions::FULL) return 403, 'Permission denied' end ssl_cert = (params['ssl_cert'] || '').strip ssl_key = (params['ssl_key'] || '').strip if ssl_cert.empty? and !ssl_key.empty? return [400, 'cannot save ssl certifica...
CWE-384
1
def wizard_submit(params, request, session) if not allowed_for_local_cluster(session, Permissions::WRITE) return 403, 'Permission denied' end wizard = PCSDWizard.getWizard(params["wizard"]) if wizard != nil return erb wizard.process_responses(params) else return "Error finding Wizard - #{params["w...
CWE-384
1
def run_cmd(session, *args) options = {} return run_cmd_options(session, options, *args) end
CWE-384
1
def get_node_attributes(session, cib_dom=nil) unless cib_dom cib_dom = get_cib_dom(session) return {} unless cib_dom end node_attrs = {} cib_dom.elements.each( '/cib/configuration/nodes/node/instance_attributes/nvpair' ) { |e| node = e.parent.parent.attributes['uname'] node_attrs[node] ||=...
CWE-384
1
def set_configs(params, request, session) if not allowed_for_local_cluster(session, Permissions::FULL) return 403, 'Permission denied' end return JSON.generate({'status' => 'bad_json'}) if not params['configs'] begin configs_json = JSON.parse(params['configs']) rescue JSON::ParserError return JSON...
CWE-384
1
def get_avail_fence_agents(params, request, session) if not allowed_for_local_cluster(session, Permissions::READ) return 403, 'Permission denied' end agents = getFenceAgents(session) return JSON.generate(agents) end
CWE-384
1
def add_node(session, new_nodename, all=false, auto_start=true) if all command = [PCS, "cluster", "node", "add", new_nodename] if auto_start command << '--start' command << '--enable' end out, stderror, retval = run_cmd(session, *command) else out, stderror, retval = run_cmd( s...
CWE-384
1
def getResourceAgents(session) resource_agent_list = {} stdout, stderr, retval = run_cmd(session, PCS, "resource", "list", "--nodesc") if retval != 0 $logger.error("Error running 'pcs resource list --nodesc") $logger.error(stdout + stderr) return {} end agents = stdout agents.each { |a| ra ...
CWE-384
1
def get_cluster_properties_definition(params, request, session) unless allowed_for_local_cluster(session, Permissions::READ) return 403, 'Permission denied' end stdout, _, retval = run_cmd( session, PCS, 'property', 'get_cluster_properties_definition' ) if retval == 0 return [200, stdout] end ...
CWE-384
1
def set_corosync_conf(params, request, session) if not allowed_for_local_cluster(session, Permissions::FULL) return 403, 'Permission denied' end if params[:corosync_conf] != nil and params[:corosync_conf].strip != "" Cfgsync::CorosyncConf.backup() Cfgsync::CorosyncConf.from_text(params[:corosync_conf]...
CWE-384
1
def update_cluster_settings(params, request, session) properties = params['config'] to_update = [] current = getAllSettings(session) # We need to be able to set cluster properties also from older version GUI. # This code handles proper processing of checkboxes. # === backward compatibility layer start === ...
CWE-384
1
def resource_change_group(params, request, session) if not allowed_for_local_cluster(session, Permissions::WRITE) return 403, 'Permission denied' end if params[:resource_id].nil? or params[:group_id].nil? return [400, 'resource_id and group_id have to be specified.'] end if params[:group_id].empty? ...
CWE-384
1
def resource_status(params, request, session) if not allowed_for_local_cluster(session, Permissions::READ) return 403, 'Permission denied' end resource_id = params[:resource] @resources,@groups = getResourcesGroups(session) location = "" res_status = "" @resources.each {|r| if r.id == resource_id ...
CWE-384
1
def add_constraint_remote(params, request, session) if not allowed_for_local_cluster(session, Permissions::WRITE) return 403, 'Permission denied' end case params["c_type"] when "loc" retval, error = add_location_constraint( session, params["res_id"], params["node_id"], params["score"], param...
CWE-384
1
def remove_acl_remote(params, request, session) if not allowed_for_local_cluster(session, Permissions::GRANT) return 403, 'Permission denied' end if params["item"] == "permission" retval = remove_acl_permission(session, params["acl_perm_id"]) elsif params["item"] == "usergroup" retval = remove_acl_u...
CWE-384
1
def self.save_sync_new_version(config, nodes, cluster_name, fetch_on_conflict, tokens={}) if not cluster_name or cluster_name.empty? # we run on a standalone host, no config syncing config.version += 1 config.save() return true, {} else # we run in a cluster so we need to sync th...
CWE-384
1
def pcsd_restart_nodes(session, nodes) node_response = {} threads = [] nodes.each { |node| threads << Thread.new { code, response = send_request_with_token( session, node, '/pcsd_restart', true ) node_response[node] = [code, response] } } threads.each { |t| t.join } node_e...
CWE-384
1
def add_acl_remote(params, request, session) if not allowed_for_local_cluster(session, Permissions::GRANT) return 403, 'Permission denied' end if params["item"] == "permission" retval = add_acl_permission( session, params["role_id"], params["type"], params["xpath_id"], params["query_id"] )...
CWE-384
1
def node_restart(params, request, session) if params[:name] code, response = send_request_with_token( session, params[:name], 'node_restart', true ) else if not allowed_for_local_cluster(session, Permissions::WRITE) return 403, 'Permission denied' end $logger.info "Restarting Node" ...
CWE-384
1
def node_standby(params, request, session) if params[:name] code, response = send_request_with_token( session, params[:name], 'node_standby', true, {"node"=>params[:name]} ) # data={"node"=>params[:name]} for backward compatibility with older versions of pcs/pcsd else if not allowed_for_local_...
CWE-384
1
def check_gui_status_of_nodes(session, nodes, check_mutuality=false, timeout=10) options = {} options[:check_auth_only] = '' if not check_mutuality threads = [] not_authorized_nodes = [] online_nodes = [] offline_nodes = [] nodes = nodes.uniq.sort nodes.each { |node| threads << Thread.new { c...
CWE-384
1
def cluster_enable(params, request, session) if params[:name] code, response = send_request_with_token( session, params[:name], 'cluster_enable', true ) else if not allowed_for_local_cluster(session, Permissions::WRITE) return 403, 'Permission denied' end success = enable_cluster(ses...
CWE-384
1
def resource_metadata(params, request, session) if not allowed_for_local_cluster(session, Permissions::READ) return 403, 'Permission denied' end return 200 if not params[:resourcename] or params[:resourcename] == "" resource_name = params[:resourcename][params[:resourcename].rindex(':')+1..-1] class_provi...
CWE-384
1
def testLoginByToken users = [] users << {"username" => "user1", "token" => "token1"} users << {"username" => "user2", "token" => "token2"} users << {"username" => SUPERUSER, "token" => "tokenS"} password_file = File.open($user_pass_file, File::RDWR|File::CREAT) password_file.truncate(0) p...
CWE-384
1
def remove_resource(params, request, session) if not allowed_for_local_cluster(session, Permissions::WRITE) return 403, 'Permission denied' end force = params['force'] no_error_if_not_exists = params.include?('no_error_if_not_exists') errors = "" params.each { |k,v| if k.index("resid-") == 0 r...
CWE-384
1
def remove_acl_roles_remote(params, request, session) if not allowed_for_local_cluster(session, Permissions::GRANT) return 403, 'Permission denied' end errors = "" params.each { |name, value| if name.index("role-") == 0 out, errout, retval = run_cmd( session, PCS, "acl", "role", "delete", ...
CWE-384
1
def get_tokens(params, request, session) # pcsd runs as root thus always returns hacluster's tokens if not allowed_for_local_cluster(session, Permissions::FULL) return 403, 'Permission denied' end return [200, JSON.generate(read_tokens)] end
CWE-384
1
def self.save_sync_new_tokens(config, new_tokens, nodes, cluster_name) with_new_tokens = PCSTokens.new(config.text) with_new_tokens.tokens.update(new_tokens) config_new = PcsdTokens.from_text(with_new_tokens.text) if not cluster_name or cluster_name.empty? # we run on a standalone host, no confi...
CWE-384
1
def set_sync_options(params, request, session) if not allowed_for_local_cluster(session, Permissions::FULL) return 403, 'Permission denied' end options = [ 'sync_thread_pause', 'sync_thread_resume', 'sync_thread_disable', 'sync_thread_enable', ] if params.keys.count { |key| options.include?(key) ...
CWE-384
1
def protected! gui_request = ( # these are URLs for web pages request.path == '/' or request.path == '/manage' or request.path == '/permissions' or request.path.match('/managec/.+/main') ) if request.path.start_with?('/remote/') or request.path == '/run_pcs' @auth_user = PCSA...
CWE-384
1
def set_cluster_conf(params, request, session) if not allowed_for_local_cluster(session, Permissions::FULL) return 403, 'Permission denied' end if params[:cluster_conf] != nil and params[:cluster_conf].strip != "" Cfgsync::ClusterConf.backup() Cfgsync::ClusterConf.from_text(params[:cluster_conf]).save...
CWE-384
1
def verify_cert_key_pair(cert, key) errors = [] cert_modulus = nil key_modulus = nil stdout, stderr, retval = run_cmd_options( PCSAuth.getSuperuserSession(), { 'stdin' => cert, }, '/usr/bin/openssl', 'x509', '-modulus', '-noout' ) if retval != 0 errors << "Invalid certificate: #{s...
CWE-384
1
def add_colocation_constraint( session, resourceA, resourceB, score, force=false, autocorrect=true ) if score == "" or score == nil score = "INFINITY" end command = [ PCS, "constraint", "colocation", "add", resourceA, resourceB, score ] command << '--force' if force command << '--autocorrect' if a...
CWE-384
1
def get_pacemaker_version() begin stdout, stderror, retval = run_cmd( PCSAuth.getSuperuserSession, PACEMAKERD, "-$" ) rescue stdout = [] end if retval == 0 match = /(\d+)\.(\d+)\.(\d+)/.match(stdout.join()) if match return match[1..3].collect { | x | x.to_i } end end retu...
CWE-384
1
def protected! if not PCSAuth.loginByToken(session, cookies) and not PCSAuth.isLoggedIn(session) # If we're on /managec/<cluster_name>/main we redirect match_expr = "/managec/(.*)/(.*)" mymatch = request.path.match(match_expr) on_managec_main = false if mymatch and mymatch.length >= ...
CWE-352
0
def remove_constraint(session, constraint_id) stdout, stderror, retval = run_cmd( session, PCS, "constraint", "remove", constraint_id ) $logger.info stdout return retval end
CWE-384
1
def get_resource_agents_avail(session) code, result = send_cluster_request_with_token( session, params[:cluster], 'get_avail_resource_agents' ) return {} if 200 != code begin ra = JSON.parse(result) if (ra["noresponse"] == true) or (ra["notauthorized"] == "true") or (ra["notoken"] == true) or (ra["p...
CWE-384
1
def node_unstandby(params, request, session) if params[:name] code, response = send_request_with_token( session, params[:name], 'node_unstandby', true, {"node"=>params[:name]} ) # data={"node"=>params[:name]} for backward compatibility with older versions of pcs/pcsd else if not allowed_for_lo...
CWE-384
1
def self.getUsersGroups(username) stdout, stderr, retval = run_cmd( getSuperuserSession, "id", "-Gn", username ) if retval != 0 $logger.info( "Unable to determine groups of user '#{username}': #{stderr.join(' ').strip}" ) return [false, []] end return [true, stdout....
CWE-384
1
function cleaner() { setTimeout(() => { if (ids.length < 1) { return; } ActiveRooms.forEach((element, index) => { element.Players.forEach((element2, index2) => { if (!ids.includes(element2.Id)) { ActiveRooms[index].Players.splice(index2, 1); ActiveRooms[index].Players.forEach...
CWE-384
1
export async function execRequest(routes: Routers, ctx: AppContext) { const match = findMatchingRoute(ctx.path, routes); if (!match) throw new ErrorNotFound(); const endPoint = match.route.findEndPoint(ctx.request.method as HttpMethod, match.subPath.schema); if (ctx.URL && !isValidOrigin(ctx.URL.origin, baseUrl(en...
CWE-352
0
function RegisterUserName(socket, Data) { var userName = Data.UserName.split('>').join(' ').split('<').join(' ').split('/').join(' '); if (userName.length > 16) userName = userName.slice(0, 16); if (userName.toLowerCase().includes('você')) userName = '~' + userName; ActiveRooms.forEach((element, index) => { ...
CWE-384
1
triggerMassAction: function (massActionUrl, type) { const self = this.relatedListInstance; let validationResult = self.checkListRecordSelected(); if (validationResult != true) { let progressIndicatorElement = $.progressIndicator(), selectedIds = self.readSelectedIds(true), excludedIds = self.re...
CWE-352
0