File: 03exitcodes

package info (click to toggle)
tinyssh 20190101-1%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,208 kB
  • sloc: ansic: 11,914; sh: 1,005; python: 385; makefile: 18
file content (78 lines) | stat: -rw-r--r-- 2,226 bytes parent folder | download | duplicates (2)
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
71
72
73
74
75
76
77
78
#!/bin/sh
# 20181027
# Jan Mojzis
# Public domain.


# change directory to $AUTOPKGTEST_TMP
cd "${AUTOPKGTEST_TMP}"

# we need tools from /usr/sbin
PATH="/usr/sbin:${PATH}"
export PATH

# backup ~/.ssh
rm -rf ~/.ssh.tinysshtest.bk
[ -d ~/.ssh ] && mv ~/.ssh ~/.ssh.tinysshtest.bk
mkdir -p ~/.ssh
chmod 700 ~/.ssh

# run tinysshd on port 10000
rm -rf sshkeydir
tinysshd-makekey -q sshkeydir
tcpserver -HRDl0 127.0.0.1 10000 tinysshd -- sshkeydir &
tcpserverpid=$!

cleanup() {
  ex=$?
  rm -rf ~/.ssh sshkeydir
  [ -d ~/.ssh.tinysshtest.bk ] && mv ~/.ssh.tinysshtest.bk ~/.ssh
  #kill tcpserver
  kill -TERM "${tcpserverpid}" 1>/dev/null 2>/dev/null || :
  kill -KILL "${tcpserverpid}" 1>/dev/null 2>/dev/null || :
  exit "${ex}"
}
trap "cleanup" EXIT TERM INT

# tries login without authorization key
# must fail
ssh -o StrictHostKeyChecking=no -p 10000 127.0.0.1 'exit 0'
exitcode=$?
if [ x"${exitcode}" = x0 ]; then
  echo "ssh 127.0.0.1:10000 login without authorization key with exit status 0, too bad" >&2
  exit 3
else
  echo "ssh 127.0.0.1:10000 login without authorization key failed, this is ok" >&2
fi

# create authorization keys
ssh-keygen -t ed25519 -q -N '' -f ~/.ssh/id_ed25519 || exit 2
cp -pr ~/.ssh/id_ed25519.pub ~/.ssh/authorized_keys || exit 3

# runs remote command which exits with exit status 0 - 255
# and tests if tinyssh server sends the status do the client
for code in `seq 0 255`; do
  ssh -o StrictHostKeyChecking=no -p 10000 127.0.0.1 "exit ${code}"
  exitcode=$?
  if [ x"${exitcode}" != x"${code}" ]; then
    echo "ssh 127.0.0.1:10000 "'"'"exit ${code}"'"'" failed: tinyssd exited with exit code: ${exitcode}" >&2
    exit 4
  else
    echo "ssh 127.0.0.1:10000 "'"'"exit ${code}"'"'" works" >&2
  fi
done

# runs command which is killed by signal 9 and 15
# and tests if tinyssh server sends the status do the client
for signal in 9 15 ; do
  ssh -o StrictHostKeyChecking=no -p 10000 127.0.0.1 "kill -${signal} \$\$"
  exitcode=$?
  if [ x"${exitcode}" != x255 ]; then
    echo "ssh 127.0.0.1:10000 "'"'"kill -${signal} "'$$"'" failed: tinyssd exited with exit code: ${exitcode}" >&2
    exit 5
  else
    echo "ssh 127.0.0.1:10000 "'"'"kill -${signal} "'$$"'" works" >&2
  fi
done

exit 0