Bug #8687

macchanger failure logs the incorrect exit code

Added by anonym 2015-01-13 14:54:46 . Updated 2015-03-31 19:02:20 .

Status:
Resolved
Priority:
Normal
Assignee:
Category:
Spoof MAC
Target version:
Start date:
2015-01-13
Due date:
% Done:

100%

Feature Branch:
bugfix/8687-macchanger-return-status
Type of work:
Code
Blueprint:

Starter:
Affected tool:
Deliverable for:

Description

Look at this code from tails-spoof-mac:

spoof_mac() {
    local msg
    if ! msg=$(macchanger -e "${1}" 2>&1); then
        log "macchanger failed for NIC ${1}, returned ${?} and said: ${msg}"
        exit 1
    fi
}


If macchanger fails, the if-statement’s body will be executed as expected, but the ${?} will not refer to macchanger’s exit status, but to the if-statement’s test expression, i.e. the ! ... stuff, which means we’ll always log an exit status of 0.

To be able to capture but the output and exit status of macchanger we probably will have to do something like this:

spoof_mac() {
    local msg
    set +e
    msg=$(macchanger -e "${1}" 2>&1)
    ret=$?
    set -e
    if [ "${ret} != 0 ]; then
        log "macchanger failed for NIC ${1}, returned ${ret} and said: ${msg}"
        exit 1
    fi
}

Subtasks


Related issues

Related to Tails - Bug #9531: MAC spoofing failure doesn't result in panic mode (module removal), bis Resolved 2015-06-04

History

#1 Updated by intrigeri 2015-01-13 16:17:39

  • Assignee set to anonym
  • Target version changed from Tails_1.3 to Tails_1.3.2

#2 Updated by anonym 2015-03-25 12:20:30

  • Status changed from Confirmed to In Progress

Applied in changeset commit:4ea050abcbdcc64899d5051ec1d02a9b4799dbf1.

#3 Updated by anonym 2015-03-25 12:24:15

  • Assignee deleted (anonym)
  • % Done changed from 0 to 50
  • QA Check set to Ready for QA
  • Feature Branch set to https://labs.riseup.net/code/issues/9011

Easiest way to test is probably to:

1. boot with some passwd= set on the kernel cmdline
2. switch to some VT when Tails Greeter start, login as root
3. replace /usr/bin/macchanger with:

#!/bin/sh
echo "Log to stdout"
echo "Log to stderr" >&2
exit 42


4. Login via Tails Greeter
5. grep spoof-mac /var/log/syslog and make verify that the expected exit status is logged (and message, while we’re at it)

#4 Updated by anonym 2015-03-25 12:26:10

  • Feature Branch changed from https://labs.riseup.net/code/issues/9011 to bugfix/8687-macchanger-return-status

#5 Updated by bertagaz 2015-03-27 15:14:30

  • Status changed from In Progress to Fix committed
  • % Done changed from 50 to 100
  • QA Check changed from Ready for QA to Pass

Works, merged!

#6 Updated by anonym 2015-03-31 19:02:20

  • Status changed from Fix committed to Resolved

#7 Updated by intrigeri 2015-07-08 11:54:13

  • related to Bug #9531: MAC spoofing failure doesn't result in panic mode (module removal), bis added