#!/bin/bash # arch-tag: 3d2f498c-aba5-4400-a867-0fc7bcc8623e # interface: # CLI: ssh-sendmail # Ubuntu uses "ssh-sendmail -d -s " instead # stdin: # # # # # # # # stdout: # ssh-sendmail: (Failed: |Succeeded: ) # # exit code: # 0 successful # error code otherwise (see nullmailer source for details) myName="`basename \"${0}\"`" # skip nullmailer options while [ $# -gt 0 -a "${1}" != "--" ] ; do shift done if [ $# -gt 0 ] ; then shift fi remoteHost="${1}" printSyntax() { cat << EOT Syntax: ${myName} Sample: ${myName} mail.sascha.silbe.org -l alias -i /etc/nullmailer/id_dsa EOT exit 1 } getEnvelope() { read envSender envRcpts="" read curLine while [ -n "${curLine}" ] ; do # FIXME: curLine might contain malicious chars envRcpts="${envRcpts} ${curLine}" read curLine done } sendMail() { # reads mail from stdin if sshOutput="`ssh \"${@}\" /usr/lib/sendmail -f \"${envSender}\" ${envRcpts} 2>&1`" ; then echo "${myName}: Succeeded: ${sshOutput}" exit 0 else echo "${myName}: Failed: ${sshOutput}" # temporary error exit 17 fi } if [ -z "${1}" ] ; then printSyntax fi getEnvelope sendMail "$@"