#!/bin/sh
#
# remctl backend for testing password change via remctl.
#
# The password change call should get "password" as its only argument (the
# subcommand) and the new password on standard input.  Create a file named
# password-input in $BUILD/tmp and store the authenticated user and the
# password in that file.
#
# Written by Russ Allbery <eagle@eyrie.org>
# Copyright 2014
#     The Board of Trustees of the Leland Stanford Junior University
#
# See LICENSE for licensing terms.

set -e

. "${SOURCE}/tap/libtap.sh"

# Verify that the argument is correct.
if [ "$1" != 'password' ] ; then
    echo "First argument is '$1', not password" >&2
    exit 1
fi
if [ $# -ne 1 ] ; then
    echo "Saw $# arguments instead of 1" >&2
    exit 1
fi

# Create the temporary directory in which to store our results.
tmpdir=`test_tmpdir`

# Save the authenticated user and the input.
echo "$REMOTE_USER" >"${tmpdir}/password-input"
cat >>"${tmpdir}/password-input"
exit 0
