Fix: Parse complete Terra repository state
This commit is contained in:
@@ -383,9 +383,10 @@ _effective_terra_key() {
|
||||
delete seen
|
||||
in_block = 0
|
||||
id = ""
|
||||
terra_like = 0
|
||||
}
|
||||
function finish_block( key) {
|
||||
if (!in_block) return
|
||||
if (!in_block || !terra_like) return
|
||||
if (seen["enabled"] != 1) {
|
||||
bad = 1
|
||||
return
|
||||
@@ -410,29 +411,46 @@ _effective_terra_key() {
|
||||
/^======== ".*" repository configuration: ========$/ {
|
||||
finish_block()
|
||||
reset_block()
|
||||
saw_nonempty = 1
|
||||
header_count++
|
||||
id = $0
|
||||
sub(/^======== "/, "", id)
|
||||
sub(/" repository configuration: ========$/, "", id)
|
||||
if (id == "" || id !~ /^terra/) bad = 1
|
||||
if (id == "") bad = 1
|
||||
terra_like = (tolower(id) ~ /^terra/)
|
||||
in_block = 1
|
||||
next
|
||||
}
|
||||
{
|
||||
if (!in_block || $0 == "") next
|
||||
if ($0 == "") next
|
||||
saw_nonempty = 1
|
||||
if (!in_block || $0 ~ /^========/) {
|
||||
bad = 1
|
||||
next
|
||||
}
|
||||
separator = index($0, " = ")
|
||||
if (separator > 0) {
|
||||
key = substr($0, 1, separator - 1)
|
||||
if (key in required) {
|
||||
seen[key]++
|
||||
values[key] = substr($0, separator + 3)
|
||||
}
|
||||
} else if ($0 == "mirrorlist") {
|
||||
seen["mirrorlist"]++
|
||||
values["mirrorlist"] = ""
|
||||
value = substr($0, separator + 3)
|
||||
} else if ($0 ~ /^[[:alnum:]_.-]+$/) {
|
||||
key = $0
|
||||
value = ""
|
||||
} else {
|
||||
bad = 1
|
||||
next
|
||||
}
|
||||
if (key !~ /^[[:alnum:]_.-]+$/) {
|
||||
bad = 1
|
||||
next
|
||||
}
|
||||
if (terra_like && key in required) {
|
||||
seen[key]++
|
||||
values[key] = value
|
||||
}
|
||||
}
|
||||
END {
|
||||
finish_block()
|
||||
if (saw_nonempty && header_count == 0) bad = 1
|
||||
if (bad || enabled_count > 1) exit 2
|
||||
if (enabled_count == 0) exit 1
|
||||
print trusted_key
|
||||
@@ -444,7 +462,7 @@ _effective_terra_key() {
|
||||
# identity, and 2 is an unsafe, duplicated, or unreadable effective state.
|
||||
_terra_effective_status() {
|
||||
local dump gpgkey parse_status=0 local_key
|
||||
dump="$(dnf --quiet --no-plugins --dump-repo-config='terra*')" || return 2
|
||||
dump="$(LC_ALL=C dnf --quiet --no-plugins --dump-repo-config='*')" || return 2
|
||||
gpgkey="$(printf '%s\n' "$dump" | _effective_terra_key)" || parse_status=$?
|
||||
(( parse_status == 0 )) || return "$parse_status"
|
||||
[[ "$gpgkey" == 'file:///etc/pki/rpm-gpg/RPM-GPG-KEY-terra44-panama' ]] || return 2
|
||||
|
||||
Reference in New Issue
Block a user