From dcf0e0225afb86e19eb79873ec14705aef393286 Mon Sep 17 00:00:00 2001 From: Eygene Ryabinkin Date: Sun, 5 Oct 2008 18:04:10 +0400 Subject: [PATCH 1/4] Avoid usage of global variables $N in the print_affected I will need this functionality in the next commits: some invocations of print_affected will be called with shifted variables $N. But this is good anyway: globals are always been bad and now functions are looking more sanely -- one does not need to guess the meaning of $1, $2 and $3. Signed-off-by: Eygene Ryabinkin --- ports-mgmt/portaudit/files/portaudit-cmd.sh | 68 ++++++++++++++------------- 1 files changed, 35 insertions(+), 33 deletions(-) diff --git a/ports-mgmt/portaudit/files/portaudit-cmd.sh b/ports-mgmt/portaudit/files/portaudit-cmd.sh index c0eb67b..b7f5dad 100755 --- a/ports-mgmt/portaudit/files/portaudit-cmd.sh +++ b/ports-mgmt/portaudit/files/portaudit-cmd.sh @@ -140,7 +140,8 @@ audit_installed() $1 ~ /^FreeBSD[<=>!]/ { if (fixedre && $2 ~ fixedre) next if (!system("'"$pkg_version"' -T \"FreeBSD-'"$osversion"'\" \"" $1 "\"")) { - print_affected("FreeBSD-'"$osversion"'", \ + print_affected("FreeBSD-'"$osversion"'", + $1, $2, $3, \ "To disable this check add the uuid to \`portaudit_fixed'"'"' in %%PREFIX%%/etc/portaudit.conf") } next @@ -152,7 +153,7 @@ audit_installed() cmd="'"$pkg_info"' -E \"" $1 "\"" while((cmd | getline pkg) > 0) { vul++ - print_affected(pkg, "") + print_affected(pkg, $1, $2, $3, "") } close(cmd) } @@ -207,7 +208,7 @@ audit_file() if ($2 !~ /'"$opt_restrict"'/) continue vul++ - print_affected(pkg, "") + print_affected(pkg, $1, $2, $3, "") } close(cmd) } @@ -244,7 +245,8 @@ audit_args() ' | $pkg_version -T "$1" -`; then VULCNT=$(($VULCNT+1)) echo "$VLIST" | awk -F\| "$PRINTAFFECTED_AWK"' - { print_affected("'"$1"'", "") } + { print_affected("'"$1"'", + $1, $2, $3, "") } ' fi ;; @@ -277,7 +279,7 @@ audit_cwd() { print } ' | $pkg_version -T "$PKGNAME" -`; then echo "$VLIST" | awk -F\| "$PRINTAFFECTED_AWK"' - { print_affected("'"$PKGNAME"'", "") } + { print_affected("'"$PKGNAME"'", $1, $2, $3, "") } ' return 1 fi @@ -425,38 +427,38 @@ prerequisites_checked=false if $opt_quiet; then PRINTAFFECTED_AWK=' - function print_affected(apkg, note) { - print apkg - } - ' +function print_affected(apkg, glob, refs, descr, note) { + print apkg +} +' elif $opt_verbose; then PRINTAFFECTED_AWK=' - function print_affected(apkg, note) { - split(apkg, thepkg) - print "Affected package: " thepkg[1] " (matched by " $1 ")" - print "Type of problem: " $3 "." - split($2, ref, / /) - for (r in ref) - print "Reference: <" ref[r] ">" - if (note) - print "Note: " note - print "" - } - ' +function print_affected(apkg, glob, refs, descr, note) { + split(apkg, thepkg) + print "Affected package: " thepkg[1] " (matched by " glob ")" + print "Type of problem: " descr "." + split(refs, ref, / /) + for (r in ref) + print "Reference: <" ref[r] ">" + if (note) + print "Note: " note + print "" +} +' else PRINTAFFECTED_AWK=' - function print_affected(apkg, note) { - split(apkg, thepkg) - print "Affected package: " thepkg[1] - print "Type of problem: " $3 "." - split($2, ref, / /) - for (r in ref) - print "Reference: <" ref[r] ">" - if (note) - print "Note: " note - print "" - } - ' +function print_affected(apkg, glob, refs, descr, note) { + split(apkg, thepkg) + print "Affected package: " thepkg[1] + print "Type of problem: " descr "." + split(refs, ref, / /) + for (r in ref) + print "Reference: <" ref[r] ">" + if (note) + print "Note: " note + print "" +} +' fi if $opt_audit; then -- 1.6.2.4