Dmitry V. Levin
08b6397d13
The switch-case statement is a gawk-specific feature which is not necessarily available, let's use traditional if-else statements instead. * tests/uid.awk: Rewrite without switch-case statements.
64 lines
1.8 KiB
Awk
64 lines
1.8 KiB
Awk
BEGIN {
|
|
r_uint = "(0|[1-9][0-9]*)"
|
|
regexp = "^getuid" suffix "\\(\\)[[:space:]]+= " r_uint "$"
|
|
expected = "getuid"
|
|
fail = 0
|
|
}
|
|
|
|
regexp == "" {
|
|
fail = 1
|
|
next
|
|
}
|
|
|
|
{
|
|
if (match($0, regexp, a)) {
|
|
if (expected == "getuid") {
|
|
uid = a[1]
|
|
expected = "setuid"
|
|
regexp = "^setuid" suffix "\\(" uid "\\)[[:space:]]+= 0$"
|
|
} else if (expected == "setuid") {
|
|
expected = "getresuid"
|
|
regexp = "^getresuid" suffix "\\(\\[" uid "\\], \\[" uid "\\], \\[" uid "\\]\\)[[:space:]]+= 0$"
|
|
} else if (expected == "getresuid") {
|
|
expected = "setreuid"
|
|
regexp = "^setreuid" suffix "\\(-1, -1\\)[[:space:]]+= 0$"
|
|
} else if (expected == "setreuid") {
|
|
expected = "setresuid"
|
|
regexp = "^setresuid" suffix "\\(-1, " uid ", -1\\)[[:space:]]+= 0$"
|
|
} else if (expected == "setresuid") {
|
|
expected = "chown"
|
|
regexp = "^chown" suffix "\\(\".\", -1, -1\\)[[:space:]]+= 0$"
|
|
} else if (expected == "chown") {
|
|
expected = "1st getgroups"
|
|
regexp = "^getgroups" suffix "\\(0, NULL\\)[[:space:]]+= " r_uint "$"
|
|
} else if (expected == "1st getgroups") {
|
|
ngroups = a[1]
|
|
if (ngroups == "0")
|
|
list=""
|
|
else if (ngroups == "1")
|
|
list=r_uint
|
|
else
|
|
list=r_uint "(, " r_uint "){" (ngroups - 1) "}"
|
|
expected = "2nd getgroups"
|
|
regexp = "^getgroups" suffix "\\(" ngroups ", \\[" list "\\]\\)[[:space:]]+= " ngroups "$"
|
|
} else if (expected == "2nd getgroups") {
|
|
expected = "the last line"
|
|
regexp = "^\\+\\+\\+ exited with 0 \\+\\+\\+$"
|
|
} else if (expected == "the last line") {
|
|
expected = "nothing"
|
|
regexp = ""
|
|
}
|
|
}
|
|
}
|
|
|
|
END {
|
|
if (fail) {
|
|
print "Unexpected output after exit"
|
|
exit 1
|
|
}
|
|
if (regexp == "")
|
|
exit 0
|
|
print "error: " expected " doesn't match"
|
|
exit 1
|
|
}
|