blob: c2e762e5ad67a6e044431eb37b79d768ea5ace35 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#!/bin/bash
# arch-tag: 3d2f498c-aba5-4400-a867-0fc7bcc8623e
# interface:
# CLI: ssh-sendmail <remoteHost> <options>
# Ubuntu uses "ssh-sendmail -d -s <remoteHost> <options>" instead
# stdin:
# <envelope sender address>
# <rcpt address 1>
# <rcpt address 2>
# <rcpt address ...>
# <empty line>
# <mail incl. headers>
#
# stdout:
# ssh-sendmail: (Failed: <error message>|Succeeded: <remote accept message>)
#
# 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} <ssh-options> <remoteHost>
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 "$@"
|