1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-16 22:50:10 +03:00

B #1165: check if GID/UID exist in DB (#2207)

This commit is contained in:
Alejandro Huertas Herrero 2022-06-30 19:32:27 +02:00 committed by GitHub
parent 56e4cff8f6
commit 4150c8e21d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 46 additions and 4 deletions

View File

@ -150,6 +150,26 @@ EOT
true
end
# Check if object UID/GID exist
#
# @param doc [XML] XML document
def check_ugid(doc)
obj = doc.root.name
id = doc.root.at_xpath('ID').text
uid = Integer(doc.root.at_xpath('UID').text)
gid = Integer(doc.root.at_xpath('GID').text)
return if @users.include?(uid) && @groups.include?(gid)
if !@users.include?(uid)
log_error("#{obj} ID=#{id}, UID=#{uid} doesn't exist", false)
end
if !@groups.include?(gid)
log_error("#{obj} ID=#{id}, GID=#{uid} doesn't exist", false)
end
end
########################################################################
# Acl
########################################################################
@ -241,6 +261,15 @@ EOT
end
def fsck
# ----------------------------------------------------------------------
# Read existing UIDs and GIDs
# ----------------------------------------------------------------------
@users = []
@groups = []
@db.fetch('SELECT oid FROM user_pool') do |r| @users << r[:oid] end
@db.fetch('SELECT oid FROM group_pool') do |r| @groups << r[:oid] end
init_log_time()
@errors = 0

View File

@ -23,6 +23,8 @@ module OneDBFsck
images_elem = doc.root.xpath('IMAGES').remove
images_new_elem = doc.create_element('IMAGES')
check_ugid(doc)
doc.root.add_child(images_new_elem)
datastore[ds_id][:images].each do |id|

View File

@ -35,9 +35,10 @@ module OneDBFsck
@db.transaction do
@db[:image_pool].each do |row|
doc = nokogiri_doc(row[:body], 'image_pool')
oid = row[:oid]
check_ugid(doc)
persistent = ( doc.root.xpath('PERSISTENT').text == "1" )
current_state = doc.root.xpath('STATE').text.to_i

View File

@ -19,6 +19,8 @@ module OneDBFsck
market_id = row[:oid]
doc = nokogiri_doc(row[:body], 'marketplace_pool')
check_ugid(doc)
apps_elem = doc.root.at_xpath("MARKETPLACEAPPS")
apps_elem.remove if !apps_elem.nil?

View File

@ -24,6 +24,8 @@ module OneDBFsck
@db.fetch("SELECT oid,body FROM marketplaceapp_pool") do |row|
doc = nokogiri_doc(row[:body], 'marketplaceapp_pool')
check_ugid(doc)
market_id = doc.root.xpath('MARKETPLACE_ID').text.to_i
market_name = doc.root.xpath('MARKETPLACE').text

View File

@ -36,6 +36,8 @@ module OneDBFsck
doc = nokogiri_doc(row[:body])
oid = row[:oid]
check_ugid(doc)
used_leases = doc.root.at_xpath('USED_LEASES').text.to_i
counter_no_ar = counters[:vnet][row[:oid]][:no_ar_leases]
ar_leases = counters[:vnet][row[:oid]][:ar_leases]

View File

@ -4,11 +4,11 @@ module OneDBFsck
templates_fix = @fixes_template = {}
@db[:template_pool].each do |row|
doc = nokogiri_doc(row[:body], 'template_pool')
doc = nokogiri_doc(row[:body], 'template_pool')
boot = doc.root.at_xpath("TEMPLATE/OS/BOOT")
uid = doc.root.at_xpath('UID').content
uid = doc.root.at_xpath('UID').content
check_ugid(doc)
if boot.nil? || boot.text.downcase.match(/fd|hd|cdrom|network/).nil?
next

View File

@ -13,6 +13,8 @@ module OneDBFsck
@db.fetch("SELECT oid,body FROM vm_pool WHERE state<>6") do |row|
vm_doc = nokogiri_doc(row[:body])
check_ugid(vm_doc)
state = vm_doc.root.at_xpath('STATE').text.to_i
lcm_state = vm_doc.root.at_xpath('LCM_STATE').text.to_i

View File

@ -7,6 +7,8 @@ module OneDBFsck
@db.fetch("SELECT oid,body FROM vrouter_pool") do |row|
vrouter_doc = nokogiri_doc(row[:body])
check_ugid(vrouter_doc)
# DATA: VNets used by this Virtual Router
vrouter_doc.root.xpath("TEMPLATE/NIC").each do |nic|
net_id = nil