Why does sudo return success for bad password?

Jeffrey Walton <[email protected]> Sat, 21 Mar 2020 00:30:41 -0400
Newsgroups gmane.comp.tools.sudo.user
Message-ID <CAH8yC8kHY2rQLcjB_RsGJYaF=cxY9umh4svd-JVFHwf-_JT06Q@mail.gmail.com>
Hi Everyone,

Please forgive my ignorance. I don't see a discussion of return values
in the sudo(1) man page.

I'm trying to smoke test an optional user password in a script. The
script can be long running, so testing the user's password before hand
makes for a good UI experience.

The following is reporting success even with a bad password:

    if [ -n "$SUDO_PASSWORD" ]
    then
        if printf "%s\n" "$SUDO_PASSWORD" | sudo -S ls 2>&1;
        then
            :
        else
            echo "It appears the sudo password is incorrect"
            ...
        fi
    fi

As I understand things, the exit status of the pipeline is the exit
status of the last command in the pipeline.

How can I obtain an accurate result of the 'sudo ls' command?
____________________________________________________________
sudo-users mailing list <[email protected]>
For list information, options, or to unsubscribe, visit:
https://www.sudo.ws/mailman/listinfo/sudo-users