Mercurial > dropbear
annotate common-session.c @ 1938:77bc00dcc19f default tip main master
Bump version to 2022.82
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 01 Apr 2022 14:43:27 +0800 |
parents | 8b4274d34fe8 |
children |
rev | line source |
---|---|
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1 /* |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
2 * Dropbear - a SSH2 server |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
3 * |
1079 | 4 * Copyright (c) Matt Johnston |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
5 * All rights reserved. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
6 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
7 * Permission is hereby granted, free of charge, to any person obtaining a copy |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
8 * of this software and associated documentation files (the "Software"), to deal |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
9 * in the Software without restriction, including without limitation the rights |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
11 * copies of the Software, and to permit persons to whom the Software is |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
12 * furnished to do so, subject to the following conditions: |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
13 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
14 * The above copyright notice and this permission notice shall be included in |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
15 * all copies or substantial portions of the Software. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
16 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
23 * SOFTWARE. */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
24 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
25 #include "includes.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
26 #include "session.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
27 #include "dbutil.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
28 #include "packet.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
29 #include "algo.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
30 #include "buffer.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
31 #include "dss.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
32 #include "ssh.h" |
858
220f55d540ae
rename random.h to dbrandom.h since some OSes have a system random.h
Matt Johnston <matt@ucc.asn.au>
parents:
857
diff
changeset
|
33 #include "dbrandom.h" |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
34 #include "kex.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
35 #include "channel.h" |
454
7e43f5e473b9
- Add -K keepalive flag for dropbear and dbclient
Matt Johnston <matt@ucc.asn.au>
parents:
452
diff
changeset
|
36 #include "runopts.h" |
1032
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
1031
diff
changeset
|
37 #include "netio.h" |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
38 |
1276
9169e4e7cbee
fix empty C prototypes
Francois Perrad <francois.perrad@gadz.org>
parents:
1191
diff
changeset
|
39 static void checktimeouts(void); |
9169e4e7cbee
fix empty C prototypes
Francois Perrad <francois.perrad@gadz.org>
parents:
1191
diff
changeset
|
40 static long select_timeout(void); |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
41 static int ident_readln(int fd, char* buf, int count); |
1276
9169e4e7cbee
fix empty C prototypes
Francois Perrad <francois.perrad@gadz.org>
parents:
1191
diff
changeset
|
42 static void read_session_identification(void); |
26 | 43 |
24 | 44 struct sshsession ses; /* GLOBAL */ |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
45 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
46 /* called only at the start of a session, set up initial state */ |
568
005530560594
Rearrange getaddrstring() etc
Matt Johnston <matt@ucc.asn.au>
parents:
537
diff
changeset
|
47 void common_session_init(int sock_in, int sock_out) { |
939
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
48 time_t now; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
49 |
1295
750ec4ec4cbe
Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents:
1292
diff
changeset
|
50 #if DEBUG_TRACE |
1021
24135c8e1d46
Add envirnonment variable for debug timestamps to roughly match
Matt Johnston <matt@ucc.asn.au>
parents:
1020
diff
changeset
|
51 debug_start_net(); |
24135c8e1d46
Add envirnonment variable for debug timestamps to roughly match
Matt Johnston <matt@ucc.asn.au>
parents:
1020
diff
changeset
|
52 #endif |
24135c8e1d46
Add envirnonment variable for debug timestamps to roughly match
Matt Johnston <matt@ucc.asn.au>
parents:
1020
diff
changeset
|
53 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
135
diff
changeset
|
54 TRACE(("enter session_init")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
55 |
479
e3db1f7a2e43
- Split main socket var into ses.sock_in/ses.sock_out in preparation
Matt Johnston <matt@ucc.asn.au>
parents:
454
diff
changeset
|
56 ses.sock_in = sock_in; |
e3db1f7a2e43
- Split main socket var into ses.sock_in/ses.sock_out in preparation
Matt Johnston <matt@ucc.asn.au>
parents:
454
diff
changeset
|
57 ses.sock_out = sock_out; |
e3db1f7a2e43
- Split main socket var into ses.sock_in/ses.sock_out in preparation
Matt Johnston <matt@ucc.asn.au>
parents:
454
diff
changeset
|
58 ses.maxfd = MAX(sock_in, sock_out); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
59 |
1074
10f198d4a308
Make main socket nonblocking. Limit writequeue size.
Matt Johnston <matt@ucc.asn.au>
parents:
1060
diff
changeset
|
60 if (sock_in >= 0) { |
10f198d4a308
Make main socket nonblocking. Limit writequeue size.
Matt Johnston <matt@ucc.asn.au>
parents:
1060
diff
changeset
|
61 setnonblocking(sock_in); |
10f198d4a308
Make main socket nonblocking. Limit writequeue size.
Matt Johnston <matt@ucc.asn.au>
parents:
1060
diff
changeset
|
62 } |
10f198d4a308
Make main socket nonblocking. Limit writequeue size.
Matt Johnston <matt@ucc.asn.au>
parents:
1060
diff
changeset
|
63 if (sock_out >= 0) { |
10f198d4a308
Make main socket nonblocking. Limit writequeue size.
Matt Johnston <matt@ucc.asn.au>
parents:
1060
diff
changeset
|
64 setnonblocking(sock_out); |
10f198d4a308
Make main socket nonblocking. Limit writequeue size.
Matt Johnston <matt@ucc.asn.au>
parents:
1060
diff
changeset
|
65 } |
10f198d4a308
Make main socket nonblocking. Limit writequeue size.
Matt Johnston <matt@ucc.asn.au>
parents:
1060
diff
changeset
|
66 |
1859
1d86a58fb52d
Leave non-interactive at default QoS class
Matt Johnston <matt@ucc.asn.au>
parents:
1752
diff
changeset
|
67 ses.socket_prio = DROPBEAR_PRIO_NORMAL; |
941
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
68 /* Sets it to lowdelay */ |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
69 update_channel_prio(); |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
70 |
1634
aabde6f57fce
Add a sanity check for DROPBEAR_SVR_MULTIUSER==0 mode
Matt Johnston <matt@ucc.asn.au>
parents:
1596
diff
changeset
|
71 #if !DROPBEAR_SVR_MULTIUSER |
aabde6f57fce
Add a sanity check for DROPBEAR_SVR_MULTIUSER==0 mode
Matt Johnston <matt@ucc.asn.au>
parents:
1596
diff
changeset
|
72 /* A sanity check to prevent an accidental configuration option |
aabde6f57fce
Add a sanity check for DROPBEAR_SVR_MULTIUSER==0 mode
Matt Johnston <matt@ucc.asn.au>
parents:
1596
diff
changeset
|
73 leaving multiuser systems exposed */ |
aabde6f57fce
Add a sanity check for DROPBEAR_SVR_MULTIUSER==0 mode
Matt Johnston <matt@ucc.asn.au>
parents:
1596
diff
changeset
|
74 errno = 0; |
aabde6f57fce
Add a sanity check for DROPBEAR_SVR_MULTIUSER==0 mode
Matt Johnston <matt@ucc.asn.au>
parents:
1596
diff
changeset
|
75 getuid(); |
aabde6f57fce
Add a sanity check for DROPBEAR_SVR_MULTIUSER==0 mode
Matt Johnston <matt@ucc.asn.au>
parents:
1596
diff
changeset
|
76 if (errno != ENOSYS) { |
aabde6f57fce
Add a sanity check for DROPBEAR_SVR_MULTIUSER==0 mode
Matt Johnston <matt@ucc.asn.au>
parents:
1596
diff
changeset
|
77 dropbear_exit("Non-multiuser Dropbear requires a non-multiuser kernel"); |
aabde6f57fce
Add a sanity check for DROPBEAR_SVR_MULTIUSER==0 mode
Matt Johnston <matt@ucc.asn.au>
parents:
1596
diff
changeset
|
78 } |
aabde6f57fce
Add a sanity check for DROPBEAR_SVR_MULTIUSER==0 mode
Matt Johnston <matt@ucc.asn.au>
parents:
1596
diff
changeset
|
79 #endif |
aabde6f57fce
Add a sanity check for DROPBEAR_SVR_MULTIUSER==0 mode
Matt Johnston <matt@ucc.asn.au>
parents:
1596
diff
changeset
|
80 |
939
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
81 now = monotonic_now(); |
1139
43a8ea69b24c
Fix problem where auth timeout wasn't checked when waiting for ident
Matt Johnston <matt@ucc.asn.au>
parents:
1124
diff
changeset
|
82 ses.connect_time = now; |
939
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
83 ses.last_packet_time_keepalive_recv = now; |
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
84 ses.last_packet_time_idle = now; |
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
85 ses.last_packet_time_any_sent = 0; |
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
86 ses.last_packet_time_keepalive_sent = 0; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
87 |
1558
2f64cb3d3007
- #if not #ifdef for DROPBEAR_FUZZ
Matt Johnston <matt@ucc.asn.au>
parents:
1546
diff
changeset
|
88 #if DROPBEAR_FUZZ |
1358
6b89eb92f872
glaring wrapfd problems fixed
Matt Johnston <matt@ucc.asn.au>
parents:
1357
diff
changeset
|
89 if (!fuzz.fuzzing) |
6b89eb92f872
glaring wrapfd problems fixed
Matt Johnston <matt@ucc.asn.au>
parents:
1357
diff
changeset
|
90 #endif |
6b89eb92f872
glaring wrapfd problems fixed
Matt Johnston <matt@ucc.asn.au>
parents:
1357
diff
changeset
|
91 { |
416
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
373
diff
changeset
|
92 if (pipe(ses.signal_pipe) < 0) { |
594
a98a2138364a
Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents:
568
diff
changeset
|
93 dropbear_exit("Signal pipe failed"); |
416
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
373
diff
changeset
|
94 } |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
373
diff
changeset
|
95 setnonblocking(ses.signal_pipe[0]); |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
373
diff
changeset
|
96 setnonblocking(ses.signal_pipe[1]); |
537
7de2f22ea759
- Add the signal pipe to maxfd
Matt Johnston <matt@ucc.asn.au>
parents:
534
diff
changeset
|
97 ses.maxfd = MAX(ses.maxfd, ses.signal_pipe[0]); |
7de2f22ea759
- Add the signal pipe to maxfd
Matt Johnston <matt@ucc.asn.au>
parents:
534
diff
changeset
|
98 ses.maxfd = MAX(ses.maxfd, ses.signal_pipe[1]); |
416
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
373
diff
changeset
|
99 } |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
373
diff
changeset
|
100 |
448
9c61e7af0156
Rearrange the channel buffer sizes into three neat use-editable values in
Matt Johnston <matt@ucc.asn.au>
parents:
416
diff
changeset
|
101 ses.writepayload = buf_new(TRANS_MAX_PAYLOAD_LEN); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
102 ses.transseq = 0; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
103 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
104 ses.readbuf = NULL; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
105 ses.payload = NULL; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
106 ses.recvseq = 0; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
107 |
135
d663445c1533
Initialise the outgoing packet queue
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
108 initqueue(&ses.writequeue); |
d663445c1533
Initialise the outgoing packet queue
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
109 |
886
cbc73a5aefb0
requirenext doesn't need two values
Matt Johnston <matt@ucc.asn.au>
parents:
858
diff
changeset
|
110 ses.requirenext = SSH_MSG_KEXINIT; |
452
4cab61369879
Prevent invalid packets being sent during key-exchange, instead queue
Matt Johnston <matt@ucc.asn.au>
parents:
448
diff
changeset
|
111 ses.dataallowed = 1; /* we can send data until we actually |
4cab61369879
Prevent invalid packets being sent during key-exchange, instead queue
Matt Johnston <matt@ucc.asn.au>
parents:
448
diff
changeset
|
112 send the SSH_MSG_KEXINIT */ |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
113 ses.ignorenext = 0; |
34
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
114 ses.lastpacket = 0; |
452
4cab61369879
Prevent invalid packets being sent during key-exchange, instead queue
Matt Johnston <matt@ucc.asn.au>
parents:
448
diff
changeset
|
115 ses.reply_queue_head = NULL; |
4cab61369879
Prevent invalid packets being sent during key-exchange, instead queue
Matt Johnston <matt@ucc.asn.au>
parents:
448
diff
changeset
|
116 ses.reply_queue_tail = NULL; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
117 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
118 /* set all the algos to none */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
119 ses.keys = (struct key_context*)m_malloc(sizeof(struct key_context)); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
120 ses.newkeys = NULL; |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
531
diff
changeset
|
121 ses.keys->recv.algo_crypt = &dropbear_nocipher; |
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
531
diff
changeset
|
122 ses.keys->trans.algo_crypt = &dropbear_nocipher; |
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
531
diff
changeset
|
123 ses.keys->recv.crypt_mode = &dropbear_mode_none; |
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
531
diff
changeset
|
124 ses.keys->trans.crypt_mode = &dropbear_mode_none; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
125 |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
531
diff
changeset
|
126 ses.keys->recv.algo_mac = &dropbear_nohash; |
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
531
diff
changeset
|
127 ses.keys->trans.algo_mac = &dropbear_nohash; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
128 |
761
ac2158e3e403
ecc kind of works, needs fixing/testing
Matt Johnston <matt@ucc.asn.au>
parents:
705
diff
changeset
|
129 ses.keys->algo_kex = NULL; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
130 ses.keys->algo_hostkey = -1; |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
531
diff
changeset
|
131 ses.keys->recv.algo_comp = DROPBEAR_COMP_NONE; |
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
531
diff
changeset
|
132 ses.keys->trans.algo_comp = DROPBEAR_COMP_NONE; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
133 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
134 #ifndef DISABLE_ZLIB |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
531
diff
changeset
|
135 ses.keys->recv.zstream = NULL; |
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
531
diff
changeset
|
136 ses.keys->trans.zstream = NULL; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
137 #endif |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
138 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
139 /* key exchange buffers */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
140 ses.session_id = NULL; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
141 ses.kexhashbuf = NULL; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
142 ses.transkexinit = NULL; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
143 ses.dh_K = NULL; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
144 ses.remoteident = NULL; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
145 |
6
ab00ef513e97
Sorted out the first channel init issues.
Matt Johnston <matt@ucc.asn.au>
parents:
4
diff
changeset
|
146 ses.chantypes = NULL; |
ab00ef513e97
Sorted out the first channel init issues.
Matt Johnston <matt@ucc.asn.au>
parents:
4
diff
changeset
|
147 |
21
d7cc5b484a2e
- Port restriction code back in
Matt Johnston <matt@ucc.asn.au>
parents:
6
diff
changeset
|
148 ses.allowprivport = 0; |
d7cc5b484a2e
- Port restriction code back in
Matt Johnston <matt@ucc.asn.au>
parents:
6
diff
changeset
|
149 |
1654 | 150 #if DROPBEAR_PLUGIN |
151 ses.plugin_session = NULL; | |
1653
76189c9ffea2
External Public-Key Authentication API (#72)
fabriziobertocci <fabriziobertocci@gmail.com>
parents:
1634
diff
changeset
|
152 #endif |
76189c9ffea2
External Public-Key Authentication API (#72)
fabriziobertocci <fabriziobertocci@gmail.com>
parents:
1634
diff
changeset
|
153 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
135
diff
changeset
|
154 TRACE(("leave session_init")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
155 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
156 |
1531
fa733a314bee
use a full prototype (#56)
François Perrad <francois.perrad@gadz.org>
parents:
1495
diff
changeset
|
157 void session_loop(void(*loophandler)(void)) { |
26 | 158 |
159 fd_set readfd, writefd; | |
160 struct timeval timeout; | |
161 int val; | |
162 | |
163 /* main loop, select()s for all sockets in use */ | |
164 for(;;) { | |
1074
10f198d4a308
Make main socket nonblocking. Limit writequeue size.
Matt Johnston <matt@ucc.asn.au>
parents:
1060
diff
changeset
|
165 const int writequeue_has_space = (ses.writequeue_len <= 2*TRANS_MAX_PAYLOAD_LEN); |
26 | 166 |
454
7e43f5e473b9
- Add -K keepalive flag for dropbear and dbclient
Matt Johnston <matt@ucc.asn.au>
parents:
452
diff
changeset
|
167 timeout.tv_sec = select_timeout(); |
26 | 168 timeout.tv_usec = 0; |
1596
60fceff95858
workaround memory sanitizer FD_ZERO false positives
Matt Johnston <matt@ucc.asn.au>
parents:
1577
diff
changeset
|
169 DROPBEAR_FD_ZERO(&writefd); |
60fceff95858
workaround memory sanitizer FD_ZERO false positives
Matt Johnston <matt@ucc.asn.au>
parents:
1577
diff
changeset
|
170 DROPBEAR_FD_ZERO(&readfd); |
60fceff95858
workaround memory sanitizer FD_ZERO false positives
Matt Johnston <matt@ucc.asn.au>
parents:
1577
diff
changeset
|
171 |
241
c5d3ef11155f
* use own assertions which should get logged properly
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
172 dropbear_assert(ses.payload == NULL); |
726
78eda530c000
send out our kexinit packet before blocking to read the SSH version string
Matt Johnston <matt@ucc.asn.au>
parents:
705
diff
changeset
|
173 |
1151
a550e1e2e2a9
make sure that the test for queued packets to write occurs after
Matt Johnston <matt@ucc.asn.au>
parents:
1143
diff
changeset
|
174 /* We get woken up when signal handlers write to this pipe. |
a550e1e2e2a9
make sure that the test for queued packets to write occurs after
Matt Johnston <matt@ucc.asn.au>
parents:
1143
diff
changeset
|
175 SIGCHLD in svr-chansession is the only one currently. */ |
1558
2f64cb3d3007
- #if not #ifdef for DROPBEAR_FUZZ
Matt Johnston <matt@ucc.asn.au>
parents:
1546
diff
changeset
|
176 #if DROPBEAR_FUZZ |
1357 | 177 if (!fuzz.fuzzing) |
178 #endif | |
179 { | |
1151
a550e1e2e2a9
make sure that the test for queued packets to write occurs after
Matt Johnston <matt@ucc.asn.au>
parents:
1143
diff
changeset
|
180 FD_SET(ses.signal_pipe[0], &readfd); |
1357 | 181 } |
1151
a550e1e2e2a9
make sure that the test for queued packets to write occurs after
Matt Johnston <matt@ucc.asn.au>
parents:
1143
diff
changeset
|
182 |
a550e1e2e2a9
make sure that the test for queued packets to write occurs after
Matt Johnston <matt@ucc.asn.au>
parents:
1143
diff
changeset
|
183 /* set up for channels which can be read/written */ |
a550e1e2e2a9
make sure that the test for queued packets to write occurs after
Matt Johnston <matt@ucc.asn.au>
parents:
1143
diff
changeset
|
184 setchannelfds(&readfd, &writefd, writequeue_has_space); |
a550e1e2e2a9
make sure that the test for queued packets to write occurs after
Matt Johnston <matt@ucc.asn.au>
parents:
1143
diff
changeset
|
185 |
a550e1e2e2a9
make sure that the test for queued packets to write occurs after
Matt Johnston <matt@ucc.asn.au>
parents:
1143
diff
changeset
|
186 /* Pending connections to test */ |
a550e1e2e2a9
make sure that the test for queued packets to write occurs after
Matt Johnston <matt@ucc.asn.au>
parents:
1143
diff
changeset
|
187 set_connect_fds(&writefd); |
a550e1e2e2a9
make sure that the test for queued packets to write occurs after
Matt Johnston <matt@ucc.asn.au>
parents:
1143
diff
changeset
|
188 |
1060
4c733310c21d
reword comment for clarity
Matt Johnston <matt@ucc.asn.au>
parents:
1050
diff
changeset
|
189 /* We delay reading from the input socket during initial setup until |
4c733310c21d
reword comment for clarity
Matt Johnston <matt@ucc.asn.au>
parents:
1050
diff
changeset
|
190 after we have written out our initial KEXINIT packet (empty writequeue). |
4c733310c21d
reword comment for clarity
Matt Johnston <matt@ucc.asn.au>
parents:
1050
diff
changeset
|
191 This means our initial packet can be in-flight while we're doing a blocking |
1074
10f198d4a308
Make main socket nonblocking. Limit writequeue size.
Matt Johnston <matt@ucc.asn.au>
parents:
1060
diff
changeset
|
192 read for the remote ident. |
10f198d4a308
Make main socket nonblocking. Limit writequeue size.
Matt Johnston <matt@ucc.asn.au>
parents:
1060
diff
changeset
|
193 We also avoid reading from the socket if the writequeue is full, that avoids |
10f198d4a308
Make main socket nonblocking. Limit writequeue size.
Matt Johnston <matt@ucc.asn.au>
parents:
1060
diff
changeset
|
194 replies backing up */ |
10f198d4a308
Make main socket nonblocking. Limit writequeue size.
Matt Johnston <matt@ucc.asn.au>
parents:
1060
diff
changeset
|
195 if (ses.sock_in != -1 |
10f198d4a308
Make main socket nonblocking. Limit writequeue size.
Matt Johnston <matt@ucc.asn.au>
parents:
1060
diff
changeset
|
196 && (ses.remoteident || isempty(&ses.writequeue)) |
10f198d4a308
Make main socket nonblocking. Limit writequeue size.
Matt Johnston <matt@ucc.asn.au>
parents:
1060
diff
changeset
|
197 && writequeue_has_space) { |
479
e3db1f7a2e43
- Split main socket var into ses.sock_in/ses.sock_out in preparation
Matt Johnston <matt@ucc.asn.au>
parents:
454
diff
changeset
|
198 FD_SET(ses.sock_in, &readfd); |
e3db1f7a2e43
- Split main socket var into ses.sock_in/ses.sock_out in preparation
Matt Johnston <matt@ucc.asn.au>
parents:
454
diff
changeset
|
199 } |
1151
a550e1e2e2a9
make sure that the test for queued packets to write occurs after
Matt Johnston <matt@ucc.asn.au>
parents:
1143
diff
changeset
|
200 |
a550e1e2e2a9
make sure that the test for queued packets to write occurs after
Matt Johnston <matt@ucc.asn.au>
parents:
1143
diff
changeset
|
201 /* Ordering is important, this test must occur after any other function |
a550e1e2e2a9
make sure that the test for queued packets to write occurs after
Matt Johnston <matt@ucc.asn.au>
parents:
1143
diff
changeset
|
202 might have queued packets (such as connection handlers) */ |
479
e3db1f7a2e43
- Split main socket var into ses.sock_in/ses.sock_out in preparation
Matt Johnston <matt@ucc.asn.au>
parents:
454
diff
changeset
|
203 if (ses.sock_out != -1 && !isempty(&ses.writequeue)) { |
e3db1f7a2e43
- Split main socket var into ses.sock_in/ses.sock_out in preparation
Matt Johnston <matt@ucc.asn.au>
parents:
454
diff
changeset
|
204 FD_SET(ses.sock_out, &writefd); |
26 | 205 } |
1025 | 206 |
26 | 207 val = select(ses.maxfd+1, &readfd, &writefd, NULL, &timeout); |
208 | |
1495
0c16b4ccbd54
make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents:
1316
diff
changeset
|
209 if (ses.exitflag) { |
26 | 210 dropbear_exit("Terminated by signal"); |
211 } | |
212 | |
373
70caa99bfe3a
Tidy up behaviour when select() is interrupted. We follow normal
Matt Johnston <matt@ucc.asn.au>
parents:
344
diff
changeset
|
213 if (val < 0 && errno != EINTR) { |
70caa99bfe3a
Tidy up behaviour when select() is interrupted. We follow normal
Matt Johnston <matt@ucc.asn.au>
parents:
344
diff
changeset
|
214 dropbear_exit("Error in select"); |
70caa99bfe3a
Tidy up behaviour when select() is interrupted. We follow normal
Matt Johnston <matt@ucc.asn.au>
parents:
344
diff
changeset
|
215 } |
70caa99bfe3a
Tidy up behaviour when select() is interrupted. We follow normal
Matt Johnston <matt@ucc.asn.au>
parents:
344
diff
changeset
|
216 |
70caa99bfe3a
Tidy up behaviour when select() is interrupted. We follow normal
Matt Johnston <matt@ucc.asn.au>
parents:
344
diff
changeset
|
217 if (val <= 0) { |
70caa99bfe3a
Tidy up behaviour when select() is interrupted. We follow normal
Matt Johnston <matt@ucc.asn.au>
parents:
344
diff
changeset
|
218 /* If we were interrupted or the select timed out, we still |
70caa99bfe3a
Tidy up behaviour when select() is interrupted. We follow normal
Matt Johnston <matt@ucc.asn.au>
parents:
344
diff
changeset
|
219 * want to iterate over channels etc for reading, to handle |
70caa99bfe3a
Tidy up behaviour when select() is interrupted. We follow normal
Matt Johnston <matt@ucc.asn.au>
parents:
344
diff
changeset
|
220 * server processes exiting etc. |
70caa99bfe3a
Tidy up behaviour when select() is interrupted. We follow normal
Matt Johnston <matt@ucc.asn.au>
parents:
344
diff
changeset
|
221 * We don't want to read/write FDs. */ |
1596
60fceff95858
workaround memory sanitizer FD_ZERO false positives
Matt Johnston <matt@ucc.asn.au>
parents:
1577
diff
changeset
|
222 DROPBEAR_FD_ZERO(&writefd); |
60fceff95858
workaround memory sanitizer FD_ZERO false positives
Matt Johnston <matt@ucc.asn.au>
parents:
1577
diff
changeset
|
223 DROPBEAR_FD_ZERO(&readfd); |
26 | 224 } |
416
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
373
diff
changeset
|
225 |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
373
diff
changeset
|
226 /* We'll just empty out the pipe if required. We don't do |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
373
diff
changeset
|
227 any thing with the data, since the pipe's purpose is purely to |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
373
diff
changeset
|
228 wake up the select() above. */ |
1495
0c16b4ccbd54
make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents:
1316
diff
changeset
|
229 ses.channel_signal_pending = 0; |
416
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
373
diff
changeset
|
230 if (FD_ISSET(ses.signal_pipe[0], &readfd)) { |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
373
diff
changeset
|
231 char x; |
1191
b370b4b172d0
Fix ses.channel_signal_pending race
Matt Johnston <matt@ucc.asn.au>
parents:
1151
diff
changeset
|
232 TRACE(("signal pipe set")) |
416
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
373
diff
changeset
|
233 while (read(ses.signal_pipe[0], &x, 1) > 0) {} |
1191
b370b4b172d0
Fix ses.channel_signal_pending race
Matt Johnston <matt@ucc.asn.au>
parents:
1151
diff
changeset
|
234 ses.channel_signal_pending = 1; |
416
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
373
diff
changeset
|
235 } |
26 | 236 |
237 /* check for auth timeout, rekeying required etc */ | |
238 checktimeouts(); | |
239 | |
929
9d40ed1da686
Experiment of always writing data if available. Might waste a writev() with
Matt Johnston <matt@ucc.asn.au>
parents:
928
diff
changeset
|
240 /* process session socket's incoming data */ |
479
e3db1f7a2e43
- Split main socket var into ses.sock_in/ses.sock_out in preparation
Matt Johnston <matt@ucc.asn.au>
parents:
454
diff
changeset
|
241 if (ses.sock_in != -1) { |
e3db1f7a2e43
- Split main socket var into ses.sock_in/ses.sock_out in preparation
Matt Johnston <matt@ucc.asn.au>
parents:
454
diff
changeset
|
242 if (FD_ISSET(ses.sock_in, &readfd)) { |
726
78eda530c000
send out our kexinit packet before blocking to read the SSH version string
Matt Johnston <matt@ucc.asn.au>
parents:
705
diff
changeset
|
243 if (!ses.remoteident) { |
78eda530c000
send out our kexinit packet before blocking to read the SSH version string
Matt Johnston <matt@ucc.asn.au>
parents:
705
diff
changeset
|
244 /* blocking read of the version string */ |
78eda530c000
send out our kexinit packet before blocking to read the SSH version string
Matt Johnston <matt@ucc.asn.au>
parents:
705
diff
changeset
|
245 read_session_identification(); |
78eda530c000
send out our kexinit packet before blocking to read the SSH version string
Matt Johnston <matt@ucc.asn.au>
parents:
705
diff
changeset
|
246 } else { |
78eda530c000
send out our kexinit packet before blocking to read the SSH version string
Matt Johnston <matt@ucc.asn.au>
parents:
705
diff
changeset
|
247 read_packet(); |
78eda530c000
send out our kexinit packet before blocking to read the SSH version string
Matt Johnston <matt@ucc.asn.au>
parents:
705
diff
changeset
|
248 } |
26 | 249 } |
250 | |
251 /* Process the decrypted packet. After this, the read buffer | |
252 * will be ready for a new packet */ | |
253 if (ses.payload != NULL) { | |
254 process_packet(); | |
255 } | |
256 } | |
1025 | 257 |
452
4cab61369879
Prevent invalid packets being sent during key-exchange, instead queue
Matt Johnston <matt@ucc.asn.au>
parents:
448
diff
changeset
|
258 /* if required, flush out any queued reply packets that |
4cab61369879
Prevent invalid packets being sent during key-exchange, instead queue
Matt Johnston <matt@ucc.asn.au>
parents:
448
diff
changeset
|
259 were being held up during a KEX */ |
4cab61369879
Prevent invalid packets being sent during key-exchange, instead queue
Matt Johnston <matt@ucc.asn.au>
parents:
448
diff
changeset
|
260 maybe_flush_reply_queue(); |
26 | 261 |
1025 | 262 handle_connect_fds(&writefd); |
263 | |
1495
0c16b4ccbd54
make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents:
1316
diff
changeset
|
264 /* loop handler prior to channelio, in case the server loophandler closes |
0c16b4ccbd54
make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents:
1316
diff
changeset
|
265 channels on process exit */ |
0c16b4ccbd54
make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents:
1316
diff
changeset
|
266 loophandler(); |
0c16b4ccbd54
make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents:
1316
diff
changeset
|
267 |
26 | 268 /* process pipes etc for the channels, ses.dataallowed == 0 |
269 * during rekeying ) */ | |
896
a1a97e98b0c1
Read (and enqueue) packets from interactive input even when
Matt Johnston <matt@ucc.asn.au>
parents:
891
diff
changeset
|
270 channelio(&readfd, &writefd); |
26 | 271 |
929
9d40ed1da686
Experiment of always writing data if available. Might waste a writev() with
Matt Johnston <matt@ucc.asn.au>
parents:
928
diff
changeset
|
272 /* process session socket's outgoing data */ |
9d40ed1da686
Experiment of always writing data if available. Might waste a writev() with
Matt Johnston <matt@ucc.asn.au>
parents:
928
diff
changeset
|
273 if (ses.sock_out != -1) { |
9d40ed1da686
Experiment of always writing data if available. Might waste a writev() with
Matt Johnston <matt@ucc.asn.au>
parents:
928
diff
changeset
|
274 if (!isempty(&ses.writequeue)) { |
9d40ed1da686
Experiment of always writing data if available. Might waste a writev() with
Matt Johnston <matt@ucc.asn.au>
parents:
928
diff
changeset
|
275 write_packet(); |
9d40ed1da686
Experiment of always writing data if available. Might waste a writev() with
Matt Johnston <matt@ucc.asn.au>
parents:
928
diff
changeset
|
276 } |
9d40ed1da686
Experiment of always writing data if available. Might waste a writev() with
Matt Johnston <matt@ucc.asn.au>
parents:
928
diff
changeset
|
277 } |
9d40ed1da686
Experiment of always writing data if available. Might waste a writev() with
Matt Johnston <matt@ucc.asn.au>
parents:
928
diff
changeset
|
278 |
26 | 279 } /* for(;;) */ |
280 | |
281 /* Not reached */ | |
282 } | |
283 | |
1040
2b4fd440399d
Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
284 static void cleanup_buf(buffer **buf) { |
2b4fd440399d
Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
285 if (!*buf) { |
2b4fd440399d
Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
286 return; |
2b4fd440399d
Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
287 } |
1912
8b4274d34fe8
Use buf_burn_free() instead of two calls
Matt Johnston <matt@ucc.asn.au>
parents:
1894
diff
changeset
|
288 buf_burn_free(*buf); |
1040
2b4fd440399d
Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
289 *buf = NULL; |
2b4fd440399d
Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
290 } |
2b4fd440399d
Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
291 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
292 /* clean up a session on exit */ |
733
70811267715c
Run the cleanup handler also when we close due to TCP connection being closed
Matt Johnston <matt@ucc.asn.au>
parents:
726
diff
changeset
|
293 void session_cleanup() { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
294 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
135
diff
changeset
|
295 TRACE(("enter session_cleanup")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
296 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
297 /* we can't cleanup if we don't know the session state */ |
1495
0c16b4ccbd54
make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents:
1316
diff
changeset
|
298 if (!ses.init_done) { |
0c16b4ccbd54
make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents:
1316
diff
changeset
|
299 TRACE(("leave session_cleanup: !ses.init_done")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
300 return; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
301 } |
733
70811267715c
Run the cleanup handler also when we close due to TCP connection being closed
Matt Johnston <matt@ucc.asn.au>
parents:
726
diff
changeset
|
302 |
1079 | 303 /* BEWARE of changing order of functions here. */ |
1041
3fb883a6aa81
Some additional cleanup functions
Matt Johnston <matt@ucc.asn.au>
parents:
1040
diff
changeset
|
304 |
3fb883a6aa81
Some additional cleanup functions
Matt Johnston <matt@ucc.asn.au>
parents:
1040
diff
changeset
|
305 /* Must be before extra_session_cleanup() */ |
3fb883a6aa81
Some additional cleanup functions
Matt Johnston <matt@ucc.asn.au>
parents:
1040
diff
changeset
|
306 chancleanup(); |
3fb883a6aa81
Some additional cleanup functions
Matt Johnston <matt@ucc.asn.au>
parents:
1040
diff
changeset
|
307 |
733
70811267715c
Run the cleanup handler also when we close due to TCP connection being closed
Matt Johnston <matt@ucc.asn.au>
parents:
726
diff
changeset
|
308 if (ses.extra_session_cleanup) { |
70811267715c
Run the cleanup handler also when we close due to TCP connection being closed
Matt Johnston <matt@ucc.asn.au>
parents:
726
diff
changeset
|
309 ses.extra_session_cleanup(); |
70811267715c
Run the cleanup handler also when we close due to TCP connection being closed
Matt Johnston <matt@ucc.asn.au>
parents:
726
diff
changeset
|
310 } |
891
e78f5ce6e7bb
cleanup before clearing keys
Matt Johnston <matt@ucc.asn.au>
parents:
886
diff
changeset
|
311 |
1079 | 312 /* After these are freed most functions will fail */ |
1295
750ec4ec4cbe
Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents:
1292
diff
changeset
|
313 #if DROPBEAR_CLEANUP |
1040
2b4fd440399d
Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
314 /* listeners call cleanup functions, this should occur before |
2b4fd440399d
Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
315 other session state is freed. */ |
2b4fd440399d
Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
316 remove_all_listeners(); |
2b4fd440399d
Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
317 |
1050 | 318 remove_connect_pending(); |
319 | |
1040
2b4fd440399d
Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
320 while (!isempty(&ses.writequeue)) { |
2b4fd440399d
Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
321 buf_free(dequeue(&ses.writequeue)); |
761
ac2158e3e403
ecc kind of works, needs fixing/testing
Matt Johnston <matt@ucc.asn.au>
parents:
705
diff
changeset
|
322 } |
1040
2b4fd440399d
Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
323 |
1358
6b89eb92f872
glaring wrapfd problems fixed
Matt Johnston <matt@ucc.asn.au>
parents:
1357
diff
changeset
|
324 m_free(ses.newkeys); |
6b89eb92f872
glaring wrapfd problems fixed
Matt Johnston <matt@ucc.asn.au>
parents:
1357
diff
changeset
|
325 #ifndef DISABLE_ZLIB |
6b89eb92f872
glaring wrapfd problems fixed
Matt Johnston <matt@ucc.asn.au>
parents:
1357
diff
changeset
|
326 if (ses.keys->recv.zstream != NULL) { |
6b89eb92f872
glaring wrapfd problems fixed
Matt Johnston <matt@ucc.asn.au>
parents:
1357
diff
changeset
|
327 if (inflateEnd(ses.keys->recv.zstream) == Z_STREAM_ERROR) { |
6b89eb92f872
glaring wrapfd problems fixed
Matt Johnston <matt@ucc.asn.au>
parents:
1357
diff
changeset
|
328 dropbear_exit("Crypto error"); |
6b89eb92f872
glaring wrapfd problems fixed
Matt Johnston <matt@ucc.asn.au>
parents:
1357
diff
changeset
|
329 } |
6b89eb92f872
glaring wrapfd problems fixed
Matt Johnston <matt@ucc.asn.au>
parents:
1357
diff
changeset
|
330 m_free(ses.keys->recv.zstream); |
6b89eb92f872
glaring wrapfd problems fixed
Matt Johnston <matt@ucc.asn.au>
parents:
1357
diff
changeset
|
331 } |
6b89eb92f872
glaring wrapfd problems fixed
Matt Johnston <matt@ucc.asn.au>
parents:
1357
diff
changeset
|
332 #endif |
6b89eb92f872
glaring wrapfd problems fixed
Matt Johnston <matt@ucc.asn.au>
parents:
1357
diff
changeset
|
333 |
1040
2b4fd440399d
Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
334 m_free(ses.remoteident); |
2b4fd440399d
Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
335 m_free(ses.authstate.pw_dir); |
2b4fd440399d
Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
336 m_free(ses.authstate.pw_name); |
2b4fd440399d
Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
337 m_free(ses.authstate.pw_shell); |
2b4fd440399d
Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
338 m_free(ses.authstate.pw_passwd); |
2b4fd440399d
Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
339 m_free(ses.authstate.username); |
2b4fd440399d
Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
340 #endif |
2b4fd440399d
Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
341 |
2b4fd440399d
Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
342 cleanup_buf(&ses.session_id); |
2b4fd440399d
Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
343 cleanup_buf(&ses.hash); |
2b4fd440399d
Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
344 cleanup_buf(&ses.payload); |
2b4fd440399d
Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
345 cleanup_buf(&ses.readbuf); |
2b4fd440399d
Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
346 cleanup_buf(&ses.writepayload); |
1041
3fb883a6aa81
Some additional cleanup functions
Matt Johnston <matt@ucc.asn.au>
parents:
1040
diff
changeset
|
347 cleanup_buf(&ses.kexhashbuf); |
3fb883a6aa81
Some additional cleanup functions
Matt Johnston <matt@ucc.asn.au>
parents:
1040
diff
changeset
|
348 cleanup_buf(&ses.transkexinit); |
3fb883a6aa81
Some additional cleanup functions
Matt Johnston <matt@ucc.asn.au>
parents:
1040
diff
changeset
|
349 if (ses.dh_K) { |
3fb883a6aa81
Some additional cleanup functions
Matt Johnston <matt@ucc.asn.au>
parents:
1040
diff
changeset
|
350 mp_clear(ses.dh_K); |
3fb883a6aa81
Some additional cleanup functions
Matt Johnston <matt@ucc.asn.au>
parents:
1040
diff
changeset
|
351 } |
3fb883a6aa81
Some additional cleanup functions
Matt Johnston <matt@ucc.asn.au>
parents:
1040
diff
changeset
|
352 m_free(ses.dh_K); |
1040
2b4fd440399d
Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
353 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
354 m_burn(ses.keys, sizeof(struct key_context)); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
355 m_free(ses.keys); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
356 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
135
diff
changeset
|
357 TRACE(("leave session_cleanup")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
358 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
359 |
726
78eda530c000
send out our kexinit packet before blocking to read the SSH version string
Matt Johnston <matt@ucc.asn.au>
parents:
705
diff
changeset
|
360 void send_session_identification() { |
751
685d05f1cc5c
Just put the version string on the queue, don't use atomicio
Matt Johnston <matt@ucc.asn.au>
parents:
733
diff
changeset
|
361 buffer *writebuf = buf_new(strlen(LOCAL_IDENT "\r\n") + 1); |
1094
c45d65392c1a
Fix pointer differ in signess warnings [-Werror=pointer-sign]
Gaël PORTAY <gael.portay@gmail.com>
parents:
1079
diff
changeset
|
362 buf_putbytes(writebuf, (const unsigned char *) LOCAL_IDENT "\r\n", strlen(LOCAL_IDENT "\r\n")); |
1577
399d8eb961b5
get rid of unused packet_type in encrypted write queue
Matt Johnston <matt@ucc.asn.au>
parents:
1558
diff
changeset
|
363 writebuf_enqueue(writebuf); |
726
78eda530c000
send out our kexinit packet before blocking to read the SSH version string
Matt Johnston <matt@ucc.asn.au>
parents:
705
diff
changeset
|
364 } |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
365 |
726
78eda530c000
send out our kexinit packet before blocking to read the SSH version string
Matt Johnston <matt@ucc.asn.au>
parents:
705
diff
changeset
|
366 static void read_session_identification() { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
367 /* max length of 255 chars */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
368 char linebuf[256]; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
369 int len = 0; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
370 char done = 0; |
103
8aeac62a968f
Allow leading lines before the ident banner when connecting
Matt Johnston <matt@ucc.asn.au>
parents:
41
diff
changeset
|
371 int i; |
1715
3974f087d9c0
Disallow leading lines before the ident for server (#102)
Vladislav Grishenko <themiron@users.noreply.github.com>
parents:
1654
diff
changeset
|
372 |
3974f087d9c0
Disallow leading lines before the ident for server (#102)
Vladislav Grishenko <themiron@users.noreply.github.com>
parents:
1654
diff
changeset
|
373 /* Servers may send other lines of data before sending the |
3974f087d9c0
Disallow leading lines before the ident for server (#102)
Vladislav Grishenko <themiron@users.noreply.github.com>
parents:
1654
diff
changeset
|
374 * version string, client must be able to process such lines. |
3974f087d9c0
Disallow leading lines before the ident for server (#102)
Vladislav Grishenko <themiron@users.noreply.github.com>
parents:
1654
diff
changeset
|
375 * If they send more than 50 lines, something is wrong */ |
3974f087d9c0
Disallow leading lines before the ident for server (#102)
Vladislav Grishenko <themiron@users.noreply.github.com>
parents:
1654
diff
changeset
|
376 for (i = IS_DROPBEAR_CLIENT ? 50 : 1; i > 0; i--) { |
479
e3db1f7a2e43
- Split main socket var into ses.sock_in/ses.sock_out in preparation
Matt Johnston <matt@ucc.asn.au>
parents:
454
diff
changeset
|
377 len = ident_readln(ses.sock_in, linebuf, sizeof(linebuf)); |
103
8aeac62a968f
Allow leading lines before the ident banner when connecting
Matt Johnston <matt@ucc.asn.au>
parents:
41
diff
changeset
|
378 |
8aeac62a968f
Allow leading lines before the ident banner when connecting
Matt Johnston <matt@ucc.asn.au>
parents:
41
diff
changeset
|
379 if (len < 0 && errno != EINTR) { |
8aeac62a968f
Allow leading lines before the ident banner when connecting
Matt Johnston <matt@ucc.asn.au>
parents:
41
diff
changeset
|
380 /* It failed */ |
8aeac62a968f
Allow leading lines before the ident banner when connecting
Matt Johnston <matt@ucc.asn.au>
parents:
41
diff
changeset
|
381 break; |
8aeac62a968f
Allow leading lines before the ident banner when connecting
Matt Johnston <matt@ucc.asn.au>
parents:
41
diff
changeset
|
382 } |
8aeac62a968f
Allow leading lines before the ident banner when connecting
Matt Johnston <matt@ucc.asn.au>
parents:
41
diff
changeset
|
383 |
8aeac62a968f
Allow leading lines before the ident banner when connecting
Matt Johnston <matt@ucc.asn.au>
parents:
41
diff
changeset
|
384 if (len >= 4 && memcmp(linebuf, "SSH-", 4) == 0) { |
8aeac62a968f
Allow leading lines before the ident banner when connecting
Matt Johnston <matt@ucc.asn.au>
parents:
41
diff
changeset
|
385 /* start of line matches */ |
8aeac62a968f
Allow leading lines before the ident banner when connecting
Matt Johnston <matt@ucc.asn.au>
parents:
41
diff
changeset
|
386 done = 1; |
8aeac62a968f
Allow leading lines before the ident banner when connecting
Matt Johnston <matt@ucc.asn.au>
parents:
41
diff
changeset
|
387 break; |
8aeac62a968f
Allow leading lines before the ident banner when connecting
Matt Johnston <matt@ucc.asn.au>
parents:
41
diff
changeset
|
388 } |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
389 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
390 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
391 if (!done) { |
1302
6a14b1f6dc04
better TRACE of failed remote ident
Matt Johnston <matt@ucc.asn.au>
parents:
1276
diff
changeset
|
392 TRACE(("error reading remote ident: %s\n", strerror(errno))) |
344
bf29e6659fb9
Just use the normal "remote closed" handler when reading ident stings
Matt Johnston <matt@ucc.asn.au>
parents:
275
diff
changeset
|
393 ses.remoteclosed(); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
394 } else { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
395 /* linebuf is already null terminated */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
396 ses.remoteident = m_malloc(len); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
397 memcpy(ses.remoteident, linebuf, len); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
398 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
399 |
513
a3748e54273c
Idle timeout patch from Farrell Aultman. Needs testing, unsure if server
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
400 /* Shall assume that 2.x will be backwards compatible. */ |
a3748e54273c
Idle timeout patch from Farrell Aultman. Needs testing, unsure if server
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
401 if (strncmp(ses.remoteident, "SSH-2.", 6) != 0 |
a3748e54273c
Idle timeout patch from Farrell Aultman. Needs testing, unsure if server
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
402 && strncmp(ses.remoteident, "SSH-1.99-", 9) != 0) { |
a3748e54273c
Idle timeout patch from Farrell Aultman. Needs testing, unsure if server
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
403 dropbear_exit("Incompatible remote version '%s'", ses.remoteident); |
a3748e54273c
Idle timeout patch from Farrell Aultman. Needs testing, unsure if server
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
404 } |
275
7f9adaf85fca
Exit with a message if the ssh protocol version is incompatible
Matt Johnston <matt@ucc.asn.au>
parents:
242
diff
changeset
|
405 |
1894
62e4baa059c3
changed TRACE to DEBUG1 for dbclient
HansH111 <hans@atbas.org>
parents:
1859
diff
changeset
|
406 DEBUG1(("remoteident: %s", ses.remoteident)) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
407 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
408 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
409 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
410 /* returns the length including null-terminating zero on success, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
411 * or -1 on failure */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
412 static int ident_readln(int fd, char* buf, int count) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
413 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
414 char in; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
415 int pos = 0; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
416 int num = 0; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
417 fd_set fds; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
418 struct timeval timeout; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
419 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
135
diff
changeset
|
420 TRACE(("enter ident_readln")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
421 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
422 if (count < 1) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
423 return -1; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
424 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
425 |
1596
60fceff95858
workaround memory sanitizer FD_ZERO false positives
Matt Johnston <matt@ucc.asn.au>
parents:
1577
diff
changeset
|
426 DROPBEAR_FD_ZERO(&fds); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
427 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
428 /* select since it's a non-blocking fd */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
429 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
430 /* leave space to null-terminate */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
431 while (pos < count-1) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
432 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
433 FD_SET(fd, &fds); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
434 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
435 timeout.tv_sec = 1; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
436 timeout.tv_usec = 0; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
437 if (select(fd+1, &fds, NULL, NULL, &timeout) < 0) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
438 if (errno == EINTR) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
439 continue; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
440 } |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
135
diff
changeset
|
441 TRACE(("leave ident_readln: select error")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
442 return -1; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
443 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
444 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
445 checktimeouts(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
446 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
447 /* Have to go one byte at a time, since we don't want to read past |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
448 * the end, and have to somehow shove bytes back into the normal |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
449 * packet reader */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
450 if (FD_ISSET(fd, &fds)) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
451 num = read(fd, &in, 1); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
452 /* a "\n" is a newline, "\r" we want to read in and keep going |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
453 * so that it won't be read as part of the next line */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
454 if (num < 0) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
455 /* error */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
456 if (errno == EINTR) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
457 continue; /* not a real error */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
458 } |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
135
diff
changeset
|
459 TRACE(("leave ident_readln: read error")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
460 return -1; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
461 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
462 if (num == 0) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
463 /* EOF */ |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
135
diff
changeset
|
464 TRACE(("leave ident_readln: EOF")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
465 return -1; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
466 } |
1751
3b9b427925a0
Load password and key for client fuzzer.
Matt Johnston <matt@ucc.asn.au>
parents:
1715
diff
changeset
|
467 |
1752
36e77a51d5e4
Fix #ifdef DROPBEAR_FUZZ (caught by linter)
Matt Johnston <matt@ucc.asn.au>
parents:
1751
diff
changeset
|
468 #if DROPBEAR_FUZZ |
1751
3b9b427925a0
Load password and key for client fuzzer.
Matt Johnston <matt@ucc.asn.au>
parents:
1715
diff
changeset
|
469 fuzz_dump(&in, 1); |
3b9b427925a0
Load password and key for client fuzzer.
Matt Johnston <matt@ucc.asn.au>
parents:
1715
diff
changeset
|
470 #endif |
3b9b427925a0
Load password and key for client fuzzer.
Matt Johnston <matt@ucc.asn.au>
parents:
1715
diff
changeset
|
471 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
472 if (in == '\n') { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
473 /* end of ident string */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
474 break; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
475 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
476 /* we don't want to include '\r's */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
477 if (in != '\r') { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
478 buf[pos] = in; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
479 pos++; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
480 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
481 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
482 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
483 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
484 buf[pos] = '\0'; |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
135
diff
changeset
|
485 TRACE(("leave ident_readln: return %d", pos+1)) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
486 return pos+1; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
487 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
488 |
970
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
968
diff
changeset
|
489 void ignore_recv_response() { |
1038
d3925ed45a85
Fix for old compilers, variable declarations at beginning of functions
Thorsten Horstmann <thorsten.horstmann@web.de>
parents:
1021
diff
changeset
|
490 /* Do nothing */ |
970
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
968
diff
changeset
|
491 TRACE(("Ignored msg_request_response")) |
968
f7f6c15b0ec3
Don't send SSH_MSG_UNIMPLEMENTED for keepalive responses
Matt Johnston <matt@ucc.asn.au>
parents:
941
diff
changeset
|
492 } |
f7f6c15b0ec3
Don't send SSH_MSG_UNIMPLEMENTED for keepalive responses
Matt Johnston <matt@ucc.asn.au>
parents:
941
diff
changeset
|
493 |
939
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
494 static void send_msg_keepalive() { |
1038
d3925ed45a85
Fix for old compilers, variable declarations at beginning of functions
Thorsten Horstmann <thorsten.horstmann@web.de>
parents:
1021
diff
changeset
|
495 time_t old_time_idle = ses.last_packet_time_idle; |
d3925ed45a85
Fix for old compilers, variable declarations at beginning of functions
Thorsten Horstmann <thorsten.horstmann@web.de>
parents:
1021
diff
changeset
|
496 struct Channel *chan = get_any_ready_channel(); |
d3925ed45a85
Fix for old compilers, variable declarations at beginning of functions
Thorsten Horstmann <thorsten.horstmann@web.de>
parents:
1021
diff
changeset
|
497 |
454
7e43f5e473b9
- Add -K keepalive flag for dropbear and dbclient
Matt Johnston <matt@ucc.asn.au>
parents:
452
diff
changeset
|
498 CHECKCLEARTOWRITE(); |
970
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
968
diff
changeset
|
499 |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
968
diff
changeset
|
500 if (chan) { |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
968
diff
changeset
|
501 /* Channel requests are preferable, more implementations |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
968
diff
changeset
|
502 handle them than SSH_MSG_GLOBAL_REQUEST */ |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
968
diff
changeset
|
503 TRACE(("keepalive channel request %d", chan->index)) |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
968
diff
changeset
|
504 start_send_channel_request(chan, DROPBEAR_KEEPALIVE_STRING); |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
968
diff
changeset
|
505 } else { |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
968
diff
changeset
|
506 TRACE(("keepalive global request")) |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
968
diff
changeset
|
507 /* Some peers will reply with SSH_MSG_REQUEST_FAILURE, |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
968
diff
changeset
|
508 some will reply with SSH_MSG_UNIMPLEMENTED, some will exit. */ |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
968
diff
changeset
|
509 buf_putbyte(ses.writepayload, SSH_MSG_GLOBAL_REQUEST); |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
968
diff
changeset
|
510 buf_putstring(ses.writepayload, DROPBEAR_KEEPALIVE_STRING, |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
968
diff
changeset
|
511 strlen(DROPBEAR_KEEPALIVE_STRING)); |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
968
diff
changeset
|
512 } |
939
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
513 buf_putbyte(ses.writepayload, 1); /* want_reply */ |
454
7e43f5e473b9
- Add -K keepalive flag for dropbear and dbclient
Matt Johnston <matt@ucc.asn.au>
parents:
452
diff
changeset
|
514 encrypt_packet(); |
939
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
515 |
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
516 ses.last_packet_time_keepalive_sent = monotonic_now(); |
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
517 |
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
518 /* keepalives shouldn't update idle timeout, reset it back */ |
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
519 ses.last_packet_time_idle = old_time_idle; |
454
7e43f5e473b9
- Add -K keepalive flag for dropbear and dbclient
Matt Johnston <matt@ucc.asn.au>
parents:
452
diff
changeset
|
520 } |
7e43f5e473b9
- Add -K keepalive flag for dropbear and dbclient
Matt Johnston <matt@ucc.asn.au>
parents:
452
diff
changeset
|
521 |
26 | 522 /* Check all timeouts which are required. Currently these are the time for |
523 * user authentication, and the automatic rekeying. */ | |
524 static void checktimeouts() { | |
525 | |
454
7e43f5e473b9
- Add -K keepalive flag for dropbear and dbclient
Matt Johnston <matt@ucc.asn.au>
parents:
452
diff
changeset
|
526 time_t now; |
928
7cd89d4e0335
Add new monotonic_now() wrapper so that timeouts are unaffected by
Matt Johnston <matt@ucc.asn.au>
parents:
927
diff
changeset
|
527 now = monotonic_now(); |
26 | 528 |
1139
43a8ea69b24c
Fix problem where auth timeout wasn't checked when waiting for ident
Matt Johnston <matt@ucc.asn.au>
parents:
1124
diff
changeset
|
529 if (IS_DROPBEAR_SERVER && ses.connect_time != 0 |
43a8ea69b24c
Fix problem where auth timeout wasn't checked when waiting for ident
Matt Johnston <matt@ucc.asn.au>
parents:
1124
diff
changeset
|
530 && now - ses.connect_time >= AUTH_TIMEOUT) { |
43a8ea69b24c
Fix problem where auth timeout wasn't checked when waiting for ident
Matt Johnston <matt@ucc.asn.au>
parents:
1124
diff
changeset
|
531 dropbear_close("Timeout before auth"); |
43a8ea69b24c
Fix problem where auth timeout wasn't checked when waiting for ident
Matt Johnston <matt@ucc.asn.au>
parents:
1124
diff
changeset
|
532 } |
43a8ea69b24c
Fix problem where auth timeout wasn't checked when waiting for ident
Matt Johnston <matt@ucc.asn.au>
parents:
1124
diff
changeset
|
533 |
26 | 534 /* we can't rekey if we haven't done remote ident exchange yet */ |
535 if (ses.remoteident == NULL) { | |
536 return; | |
537 } | |
538 | |
539 if (!ses.kexstate.sentkexinit | |
454
7e43f5e473b9
- Add -K keepalive flag for dropbear and dbclient
Matt Johnston <matt@ucc.asn.au>
parents:
452
diff
changeset
|
540 && (now - ses.kexstate.lastkextime >= KEX_REKEY_TIMEOUT |
7e43f5e473b9
- Add -K keepalive flag for dropbear and dbclient
Matt Johnston <matt@ucc.asn.au>
parents:
452
diff
changeset
|
541 || ses.kexstate.datarecv+ses.kexstate.datatrans >= KEX_REKEY_DATA)) { |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
135
diff
changeset
|
542 TRACE(("rekeying after timeout or max data reached")) |
26 | 543 send_msg_kexinit(); |
544 } | |
454
7e43f5e473b9
- Add -K keepalive flag for dropbear and dbclient
Matt Johnston <matt@ucc.asn.au>
parents:
452
diff
changeset
|
545 |
970
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
968
diff
changeset
|
546 if (opts.keepalive_secs > 0 && ses.authstate.authdone) { |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
968
diff
changeset
|
547 /* Avoid sending keepalives prior to auth - those are |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
968
diff
changeset
|
548 not valid pre-auth packet types */ |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
968
diff
changeset
|
549 |
939
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
550 /* Send keepalives if we've been idle */ |
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
551 if (now - ses.last_packet_time_any_sent >= opts.keepalive_secs) { |
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
552 send_msg_keepalive(); |
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
553 } |
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
554 |
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
555 /* Also send an explicit keepalive message to trigger a response |
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
556 if the remote end hasn't sent us anything */ |
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
557 if (now - ses.last_packet_time_keepalive_recv >= opts.keepalive_secs |
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
558 && now - ses.last_packet_time_keepalive_sent >= opts.keepalive_secs) { |
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
559 send_msg_keepalive(); |
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
560 } |
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
561 |
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
562 if (now - ses.last_packet_time_keepalive_recv |
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
563 >= opts.keepalive_secs * DEFAULT_KEEPALIVE_LIMIT) { |
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
564 dropbear_exit("Keepalive timeout"); |
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
565 } |
454
7e43f5e473b9
- Add -K keepalive flag for dropbear and dbclient
Matt Johnston <matt@ucc.asn.au>
parents:
452
diff
changeset
|
566 } |
513
a3748e54273c
Idle timeout patch from Farrell Aultman. Needs testing, unsure if server
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
567 |
939
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
568 if (opts.idle_timeout_secs > 0 |
a0819ecfee0b
Make -K keepalive behave like OpenSSH's ServerAliveInterval
Matt Johnston <matt@ucc.asn.au>
parents:
929
diff
changeset
|
569 && now - ses.last_packet_time_idle >= opts.idle_timeout_secs) { |
513
a3748e54273c
Idle timeout patch from Farrell Aultman. Needs testing, unsure if server
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
570 dropbear_close("Idle timeout"); |
a3748e54273c
Idle timeout patch from Farrell Aultman. Needs testing, unsure if server
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
571 } |
26 | 572 } |
573 | |
1140
f6d3a16ecc71
set timeouts to time remaining rather than timeout duration
Matt Johnston <matt@ucc.asn.au>
parents:
1139
diff
changeset
|
574 static void update_timeout(long limit, long now, long last_event, long * timeout) { |
1143
924ff1b959a2
only update keepalive timeout post-auth (when keepalives are sent)
Matt Johnston <matt@ucc.asn.au>
parents:
1140
diff
changeset
|
575 TRACE2(("update_timeout limit %ld, now %ld, last %ld, timeout %ld", |
1140
f6d3a16ecc71
set timeouts to time remaining rather than timeout duration
Matt Johnston <matt@ucc.asn.au>
parents:
1139
diff
changeset
|
576 limit, now, last_event, *timeout)) |
f6d3a16ecc71
set timeouts to time remaining rather than timeout duration
Matt Johnston <matt@ucc.asn.au>
parents:
1139
diff
changeset
|
577 if (last_event > 0 && limit > 0) { |
f6d3a16ecc71
set timeouts to time remaining rather than timeout duration
Matt Johnston <matt@ucc.asn.au>
parents:
1139
diff
changeset
|
578 *timeout = MIN(*timeout, last_event+limit-now); |
1143
924ff1b959a2
only update keepalive timeout post-auth (when keepalives are sent)
Matt Johnston <matt@ucc.asn.au>
parents:
1140
diff
changeset
|
579 TRACE2(("new timeout %ld", *timeout)) |
1140
f6d3a16ecc71
set timeouts to time remaining rather than timeout duration
Matt Johnston <matt@ucc.asn.au>
parents:
1139
diff
changeset
|
580 } |
f6d3a16ecc71
set timeouts to time remaining rather than timeout duration
Matt Johnston <matt@ucc.asn.au>
parents:
1139
diff
changeset
|
581 } |
f6d3a16ecc71
set timeouts to time remaining rather than timeout duration
Matt Johnston <matt@ucc.asn.au>
parents:
1139
diff
changeset
|
582 |
454
7e43f5e473b9
- Add -K keepalive flag for dropbear and dbclient
Matt Johnston <matt@ucc.asn.au>
parents:
452
diff
changeset
|
583 static long select_timeout() { |
7e43f5e473b9
- Add -K keepalive flag for dropbear and dbclient
Matt Johnston <matt@ucc.asn.au>
parents:
452
diff
changeset
|
584 /* determine the minimum timeout that might be required, so |
7e43f5e473b9
- Add -K keepalive flag for dropbear and dbclient
Matt Johnston <matt@ucc.asn.au>
parents:
452
diff
changeset
|
585 as to avoid waking when unneccessary */ |
1310
090033317ca1
Avoid busy loop while waiting for rekey response
Matt Johnston <matt@ucc.asn.au>
parents:
1302
diff
changeset
|
586 long timeout = KEX_REKEY_TIMEOUT; |
1140
f6d3a16ecc71
set timeouts to time remaining rather than timeout duration
Matt Johnston <matt@ucc.asn.au>
parents:
1139
diff
changeset
|
587 long now = monotonic_now(); |
f6d3a16ecc71
set timeouts to time remaining rather than timeout duration
Matt Johnston <matt@ucc.asn.au>
parents:
1139
diff
changeset
|
588 |
1310
090033317ca1
Avoid busy loop while waiting for rekey response
Matt Johnston <matt@ucc.asn.au>
parents:
1302
diff
changeset
|
589 if (!ses.kexstate.sentkexinit) { |
090033317ca1
Avoid busy loop while waiting for rekey response
Matt Johnston <matt@ucc.asn.au>
parents:
1302
diff
changeset
|
590 update_timeout(KEX_REKEY_TIMEOUT, now, ses.kexstate.lastkextime, &timeout); |
090033317ca1
Avoid busy loop while waiting for rekey response
Matt Johnston <matt@ucc.asn.au>
parents:
1302
diff
changeset
|
591 } |
1140
f6d3a16ecc71
set timeouts to time remaining rather than timeout duration
Matt Johnston <matt@ucc.asn.au>
parents:
1139
diff
changeset
|
592 |
f6d3a16ecc71
set timeouts to time remaining rather than timeout duration
Matt Johnston <matt@ucc.asn.au>
parents:
1139
diff
changeset
|
593 if (ses.authstate.authdone != 1 && IS_DROPBEAR_SERVER) { |
f6d3a16ecc71
set timeouts to time remaining rather than timeout duration
Matt Johnston <matt@ucc.asn.au>
parents:
1139
diff
changeset
|
594 /* AUTH_TIMEOUT is only relevant before authdone */ |
f6d3a16ecc71
set timeouts to time remaining rather than timeout duration
Matt Johnston <matt@ucc.asn.au>
parents:
1139
diff
changeset
|
595 update_timeout(AUTH_TIMEOUT, now, ses.connect_time, &timeout); |
f6d3a16ecc71
set timeouts to time remaining rather than timeout duration
Matt Johnston <matt@ucc.asn.au>
parents:
1139
diff
changeset
|
596 } |
f6d3a16ecc71
set timeouts to time remaining rather than timeout duration
Matt Johnston <matt@ucc.asn.au>
parents:
1139
diff
changeset
|
597 |
1143
924ff1b959a2
only update keepalive timeout post-auth (when keepalives are sent)
Matt Johnston <matt@ucc.asn.au>
parents:
1140
diff
changeset
|
598 if (ses.authstate.authdone) { |
924ff1b959a2
only update keepalive timeout post-auth (when keepalives are sent)
Matt Johnston <matt@ucc.asn.au>
parents:
1140
diff
changeset
|
599 update_timeout(opts.keepalive_secs, now, |
924ff1b959a2
only update keepalive timeout post-auth (when keepalives are sent)
Matt Johnston <matt@ucc.asn.au>
parents:
1140
diff
changeset
|
600 MAX(ses.last_packet_time_keepalive_recv, ses.last_packet_time_keepalive_sent), |
924ff1b959a2
only update keepalive timeout post-auth (when keepalives are sent)
Matt Johnston <matt@ucc.asn.au>
parents:
1140
diff
changeset
|
601 &timeout); |
924ff1b959a2
only update keepalive timeout post-auth (when keepalives are sent)
Matt Johnston <matt@ucc.asn.au>
parents:
1140
diff
changeset
|
602 } |
1140
f6d3a16ecc71
set timeouts to time remaining rather than timeout duration
Matt Johnston <matt@ucc.asn.au>
parents:
1139
diff
changeset
|
603 |
f6d3a16ecc71
set timeouts to time remaining rather than timeout duration
Matt Johnston <matt@ucc.asn.au>
parents:
1139
diff
changeset
|
604 update_timeout(opts.idle_timeout_secs, now, ses.last_packet_time_idle, |
f6d3a16ecc71
set timeouts to time remaining rather than timeout duration
Matt Johnston <matt@ucc.asn.au>
parents:
1139
diff
changeset
|
605 &timeout); |
f6d3a16ecc71
set timeouts to time remaining rather than timeout duration
Matt Johnston <matt@ucc.asn.au>
parents:
1139
diff
changeset
|
606 |
f6d3a16ecc71
set timeouts to time remaining rather than timeout duration
Matt Johnston <matt@ucc.asn.au>
parents:
1139
diff
changeset
|
607 /* clamp negative timeouts to zero - event has already triggered */ |
f6d3a16ecc71
set timeouts to time remaining rather than timeout duration
Matt Johnston <matt@ucc.asn.au>
parents:
1139
diff
changeset
|
608 return MAX(timeout, 0); |
454
7e43f5e473b9
- Add -K keepalive flag for dropbear and dbclient
Matt Johnston <matt@ucc.asn.au>
parents:
452
diff
changeset
|
609 } |
482
7ad49f34a122
- Add run_shell_command() function to run a "sh -c" command, handling
Matt Johnston <matt@ucc.asn.au>
parents:
479
diff
changeset
|
610 |
7ad49f34a122
- Add run_shell_command() function to run a "sh -c" command, handling
Matt Johnston <matt@ucc.asn.au>
parents:
479
diff
changeset
|
611 const char* get_user_shell() { |
7ad49f34a122
- Add run_shell_command() function to run a "sh -c" command, handling
Matt Johnston <matt@ucc.asn.au>
parents:
479
diff
changeset
|
612 /* an empty shell should be interpreted as "/bin/sh" */ |
7ad49f34a122
- Add run_shell_command() function to run a "sh -c" command, handling
Matt Johnston <matt@ucc.asn.au>
parents:
479
diff
changeset
|
613 if (ses.authstate.pw_shell[0] == '\0') { |
7ad49f34a122
- Add run_shell_command() function to run a "sh -c" command, handling
Matt Johnston <matt@ucc.asn.au>
parents:
479
diff
changeset
|
614 return "/bin/sh"; |
7ad49f34a122
- Add run_shell_command() function to run a "sh -c" command, handling
Matt Johnston <matt@ucc.asn.au>
parents:
479
diff
changeset
|
615 } else { |
7ad49f34a122
- Add run_shell_command() function to run a "sh -c" command, handling
Matt Johnston <matt@ucc.asn.au>
parents:
479
diff
changeset
|
616 return ses.authstate.pw_shell; |
7ad49f34a122
- Add run_shell_command() function to run a "sh -c" command, handling
Matt Johnston <matt@ucc.asn.au>
parents:
479
diff
changeset
|
617 } |
7ad49f34a122
- Add run_shell_command() function to run a "sh -c" command, handling
Matt Johnston <matt@ucc.asn.au>
parents:
479
diff
changeset
|
618 } |
483
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
482
diff
changeset
|
619 void fill_passwd(const char* username) { |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
482
diff
changeset
|
620 struct passwd *pw = NULL; |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
482
diff
changeset
|
621 if (ses.authstate.pw_name) |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
482
diff
changeset
|
622 m_free(ses.authstate.pw_name); |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
482
diff
changeset
|
623 if (ses.authstate.pw_dir) |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
482
diff
changeset
|
624 m_free(ses.authstate.pw_dir); |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
482
diff
changeset
|
625 if (ses.authstate.pw_shell) |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
482
diff
changeset
|
626 m_free(ses.authstate.pw_shell); |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
482
diff
changeset
|
627 if (ses.authstate.pw_passwd) |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
482
diff
changeset
|
628 m_free(ses.authstate.pw_passwd); |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
482
diff
changeset
|
629 |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
482
diff
changeset
|
630 pw = getpwnam(username); |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
482
diff
changeset
|
631 if (!pw) { |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
482
diff
changeset
|
632 return; |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
482
diff
changeset
|
633 } |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
482
diff
changeset
|
634 ses.authstate.pw_uid = pw->pw_uid; |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
482
diff
changeset
|
635 ses.authstate.pw_gid = pw->pw_gid; |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
482
diff
changeset
|
636 ses.authstate.pw_name = m_strdup(pw->pw_name); |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
482
diff
changeset
|
637 ses.authstate.pw_dir = m_strdup(pw->pw_dir); |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
482
diff
changeset
|
638 ses.authstate.pw_shell = m_strdup(pw->pw_shell); |
676
0edf08895a33
Return immediate success for blank passwords if allowed
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
639 { |
0edf08895a33
Return immediate success for blank passwords if allowed
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
640 char *passwd_crypt = pw->pw_passwd; |
0edf08895a33
Return immediate success for blank passwords if allowed
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
641 #ifdef HAVE_SHADOW_H |
0edf08895a33
Return immediate success for blank passwords if allowed
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
642 /* get the shadow password if possible */ |
0edf08895a33
Return immediate success for blank passwords if allowed
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
643 struct spwd *spasswd = getspnam(ses.authstate.pw_name); |
0edf08895a33
Return immediate success for blank passwords if allowed
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
644 if (spasswd && spasswd->sp_pwdp) { |
0edf08895a33
Return immediate success for blank passwords if allowed
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
645 passwd_crypt = spasswd->sp_pwdp; |
0edf08895a33
Return immediate success for blank passwords if allowed
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
646 } |
0edf08895a33
Return immediate success for blank passwords if allowed
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
647 #endif |
705
2e573f39b88e
Android returns NULL for pw_crypt, set it to something else
Matt Johnston <matt@ucc.asn.au>
parents:
676
diff
changeset
|
648 if (!passwd_crypt) { |
2e573f39b88e
Android returns NULL for pw_crypt, set it to something else
Matt Johnston <matt@ucc.asn.au>
parents:
676
diff
changeset
|
649 /* android supposedly returns NULL */ |
2e573f39b88e
Android returns NULL for pw_crypt, set it to something else
Matt Johnston <matt@ucc.asn.au>
parents:
676
diff
changeset
|
650 passwd_crypt = "!!"; |
2e573f39b88e
Android returns NULL for pw_crypt, set it to something else
Matt Johnston <matt@ucc.asn.au>
parents:
676
diff
changeset
|
651 } |
676
0edf08895a33
Return immediate success for blank passwords if allowed
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
652 ses.authstate.pw_passwd = m_strdup(passwd_crypt); |
0edf08895a33
Return immediate success for blank passwords if allowed
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
653 } |
483
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
482
diff
changeset
|
654 } |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
482
diff
changeset
|
655 |
941
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
656 /* Called when channels are modified */ |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
657 void update_channel_prio() { |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
658 enum dropbear_prio new_prio; |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
659 int any = 0; |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
660 unsigned int i; |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
661 |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
662 TRACE(("update_channel_prio")) |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
663 |
1031
64c0aa01e2b6
Update priority once the socket is open
Matt Johnston <matt@ucc.asn.au>
parents:
1025
diff
changeset
|
664 if (ses.sock_out < 0) { |
64c0aa01e2b6
Update priority once the socket is open
Matt Johnston <matt@ucc.asn.au>
parents:
1025
diff
changeset
|
665 TRACE(("leave update_channel_prio: no socket")) |
64c0aa01e2b6
Update priority once the socket is open
Matt Johnston <matt@ucc.asn.au>
parents:
1025
diff
changeset
|
666 return; |
64c0aa01e2b6
Update priority once the socket is open
Matt Johnston <matt@ucc.asn.au>
parents:
1025
diff
changeset
|
667 } |
64c0aa01e2b6
Update priority once the socket is open
Matt Johnston <matt@ucc.asn.au>
parents:
1025
diff
changeset
|
668 |
1859
1d86a58fb52d
Leave non-interactive at default QoS class
Matt Johnston <matt@ucc.asn.au>
parents:
1752
diff
changeset
|
669 new_prio = DROPBEAR_PRIO_NORMAL; |
941
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
670 for (i = 0; i < ses.chansize; i++) { |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
671 struct Channel *channel = ses.channels[i]; |
1859
1d86a58fb52d
Leave non-interactive at default QoS class
Matt Johnston <matt@ucc.asn.au>
parents:
1752
diff
changeset
|
672 if (!channel) { |
941
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
673 continue; |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
674 } |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
675 any = 1; |
1859
1d86a58fb52d
Leave non-interactive at default QoS class
Matt Johnston <matt@ucc.asn.au>
parents:
1752
diff
changeset
|
676 if (channel->prio == DROPBEAR_PRIO_LOWDELAY) { |
941
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
677 new_prio = DROPBEAR_PRIO_LOWDELAY; |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
678 break; |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
679 } |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
680 } |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
681 |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
682 if (any == 0) { |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
683 /* lowdelay during setup */ |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
684 TRACE(("update_channel_prio: not any")) |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
685 new_prio = DROPBEAR_PRIO_LOWDELAY; |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
686 } |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
687 |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
688 if (new_prio != ses.socket_prio) { |
1020
363c0feca5d4
Fix print that no longer works since we're not using fourCCs
Matt Johnston <matt@ucc.asn.au>
parents:
970
diff
changeset
|
689 TRACE(("Dropbear priority transitioning %d -> %d", ses.socket_prio, new_prio)) |
941
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
690 set_sock_priority(ses.sock_out, new_prio); |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
691 ses.socket_prio = new_prio; |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
692 } |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
693 } |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
940
diff
changeset
|
694 |