summaryrefslogtreecommitdiff
path: root/nchan.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>1999-11-25 00:26:21 +1100
committerDamien Miller <djm@mindrot.org>1999-11-25 00:26:21 +1100
commit95def09838fc61b37b6ea7cd5c234a465b4b129b (patch)
tree042744f76f40a326b873cb1c3690a6d7d966bc3e /nchan.c
parent4d2f15f895f4c795afc008aeff3fd2ceffbc44f4 (diff)
- Merged very large OpenBSD source code reformat
- OpenBSD CVS updates - [channels.c cipher.c compat.c log-client.c scp.c serverloop.c] [ssh.h sshd.8 sshd.c] syslog changes: * Unified Logmessage for all auth-types, for success and for failed * Standard connections get only ONE line in the LOG when level==LOG: Auth-attempts are logged only, if authentication is: a) successfull or b) with passwd or c) we had more than AUTH_FAIL_LOG failues * many log() became verbose() * old behaviour with level=VERBOSE - [readconf.c readconf.h ssh.1 ssh.h sshconnect.c sshd.c] tranfer s/key challenge/response data in SSH_SMSG_AUTH_TIS_CHALLENGE messages. allows use of s/key in windows (ttssh, securecrt) and ssh-1.2.27 clients without 'ssh -v', ok: niels@ - [sshd.8] -V, for fallback to openssh in SSH2 compatibility mode - [sshd.c] fix sigchld race; cjc5@po.cwru.edu
Diffstat (limited to 'nchan.c')
-rw-r--r--nchan.c119
1 files changed, 67 insertions, 52 deletions
diff --git a/nchan.c b/nchan.c
index fcaeae405..b9a8ba49c 100644
--- a/nchan.c
+++ b/nchan.c
@@ -1,5 +1,5 @@
1#include "includes.h" 1#include "includes.h"
2RCSID("$Id: nchan.c,v 1.1 1999/10/27 03:42:44 damien Exp $"); 2RCSID("$Id: nchan.c,v 1.2 1999/11/24 13:26:22 damien Exp $");
3 3
4#include "ssh.h" 4#include "ssh.h"
5 5
@@ -15,122 +15,131 @@ static void chan_shutdown_read(Channel *c);
15static void chan_delele_if_full_closed(Channel *c); 15static void chan_delele_if_full_closed(Channel *c);
16 16
17/* 17/*
18 * EVENTS: update channel input/output states 18 * EVENTS update channel input/output states execute ACTIONS
19 * execute ACTIONS
20 */ 19 */
20
21/* events concerning the INPUT from socket for channel (istate) */ 21/* events concerning the INPUT from socket for channel (istate) */
22void 22void
23chan_rcvd_oclose(Channel *c){ 23chan_rcvd_oclose(Channel *c)
24 switch(c->istate){ 24{
25 switch (c->istate) {
25 case CHAN_INPUT_WAIT_OCLOSE: 26 case CHAN_INPUT_WAIT_OCLOSE:
26 debug("channel %d: INPUT_WAIT_OCLOSE -> INPUT_CLOSED [rcvd OCLOSE]", c->self); 27 debug("channel %d: INPUT_WAIT_OCLOSE -> INPUT_CLOSED [rcvd OCLOSE]", c->self);
27 c->istate=CHAN_INPUT_CLOSED; 28 c->istate = CHAN_INPUT_CLOSED;
28 chan_delele_if_full_closed(c); 29 chan_delele_if_full_closed(c);
29 break; 30 break;
30 case CHAN_INPUT_OPEN: 31 case CHAN_INPUT_OPEN:
31 debug("channel %d: INPUT_OPEN -> INPUT_CLOSED [rvcd OCLOSE, send IEOF]", c->self); 32 debug("channel %d: INPUT_OPEN -> INPUT_CLOSED [rvcd OCLOSE, send IEOF]", c->self);
32 chan_shutdown_read(c); 33 chan_shutdown_read(c);
33 chan_send_ieof(c); 34 chan_send_ieof(c);
34 c->istate=CHAN_INPUT_CLOSED; 35 c->istate = CHAN_INPUT_CLOSED;
35 chan_delele_if_full_closed(c); 36 chan_delele_if_full_closed(c);
36 break; 37 break;
37 default: 38 default:
38 debug("protocol error: chan_rcvd_oclose %d for istate %d",c->self,c->istate); 39 debug("protocol error: chan_rcvd_oclose %d for istate %d", c->self, c->istate);
39 break; 40 break;
40 } 41 }
41} 42}
42void 43void
43chan_read_failed(Channel *c){ 44chan_read_failed(Channel *c)
44 switch(c->istate){ 45{
46 switch (c->istate) {
45 case CHAN_INPUT_OPEN: 47 case CHAN_INPUT_OPEN:
46 debug("channel %d: INPUT_OPEN -> INPUT_WAIT_DRAIN [read failed]", c->self); 48 debug("channel %d: INPUT_OPEN -> INPUT_WAIT_DRAIN [read failed]", c->self);
47 chan_shutdown_read(c); 49 chan_shutdown_read(c);
48 c->istate=CHAN_INPUT_WAIT_DRAIN; 50 c->istate = CHAN_INPUT_WAIT_DRAIN;
49 break; 51 break;
50 default: 52 default:
51 debug("internal error: we do not read, but chan_read_failed %d for istate %d", 53 debug("internal error: we do not read, but chan_read_failed %d for istate %d",
52 c->self,c->istate); 54 c->self, c->istate);
53 break; 55 break;
54 } 56 }
55} 57}
56void 58void
57chan_ibuf_empty(Channel *c){ 59chan_ibuf_empty(Channel *c)
58 if(buffer_len(&c->input)){ 60{
59 debug("internal error: chan_ibuf_empty %d for non empty buffer",c->self); 61 if (buffer_len(&c->input)) {
62 debug("internal error: chan_ibuf_empty %d for non empty buffer", c->self);
60 return; 63 return;
61 } 64 }
62 switch(c->istate){ 65 switch (c->istate) {
63 case CHAN_INPUT_WAIT_DRAIN: 66 case CHAN_INPUT_WAIT_DRAIN:
64 debug("channel %d: INPUT_WAIT_DRAIN -> INPUT_WAIT_OCLOSE [inbuf empty, send IEOF]", c->self); 67 debug("channel %d: INPUT_WAIT_DRAIN -> INPUT_WAIT_OCLOSE [inbuf empty, send IEOF]", c->self);
65 chan_send_ieof(c); 68 chan_send_ieof(c);
66 c->istate=CHAN_INPUT_WAIT_OCLOSE; 69 c->istate = CHAN_INPUT_WAIT_OCLOSE;
67 break; 70 break;
68 default: 71 default:
69 debug("internal error: chan_ibuf_empty %d for istate %d",c->self,c->istate); 72 debug("internal error: chan_ibuf_empty %d for istate %d", c->self, c->istate);
70 break; 73 break;
71 } 74 }
72} 75}
76
73/* events concerning the OUTPUT from channel for socket (ostate) */ 77/* events concerning the OUTPUT from channel for socket (ostate) */
74void 78void
75chan_rcvd_ieof(Channel *c){ 79chan_rcvd_ieof(Channel *c)
76 switch(c->ostate){ 80{
81 switch (c->ostate) {
77 case CHAN_OUTPUT_OPEN: 82 case CHAN_OUTPUT_OPEN:
78 debug("channel %d: OUTPUT_OPEN -> OUTPUT_WAIT_DRAIN [rvcd IEOF]", c->self); 83 debug("channel %d: OUTPUT_OPEN -> OUTPUT_WAIT_DRAIN [rvcd IEOF]", c->self);
79 c->ostate=CHAN_OUTPUT_WAIT_DRAIN; 84 c->ostate = CHAN_OUTPUT_WAIT_DRAIN;
80 break; 85 break;
81 case CHAN_OUTPUT_WAIT_IEOF: 86 case CHAN_OUTPUT_WAIT_IEOF:
82 debug("channel %d: OUTPUT_WAIT_IEOF -> OUTPUT_CLOSED [rvcd IEOF]", c->self); 87 debug("channel %d: OUTPUT_WAIT_IEOF -> OUTPUT_CLOSED [rvcd IEOF]", c->self);
83 c->ostate=CHAN_OUTPUT_CLOSED; 88 c->ostate = CHAN_OUTPUT_CLOSED;
84 chan_delele_if_full_closed(c); 89 chan_delele_if_full_closed(c);
85 break; 90 break;
86 default: 91 default:
87 debug("protocol error: chan_rcvd_ieof %d for ostate %d", c->self,c->ostate); 92 debug("protocol error: chan_rcvd_ieof %d for ostate %d", c->self, c->ostate);
88 break; 93 break;
89 } 94 }
90} 95}
91void 96void
92chan_write_failed(Channel *c){ 97chan_write_failed(Channel *c)
93 switch(c->ostate){ 98{
99 switch (c->ostate) {
94 case CHAN_OUTPUT_OPEN: 100 case CHAN_OUTPUT_OPEN:
95 debug("channel %d: OUTPUT_OPEN -> OUTPUT_WAIT_IEOF [write failed]", c->self); 101 debug("channel %d: OUTPUT_OPEN -> OUTPUT_WAIT_IEOF [write failed]", c->self);
96 chan_send_oclose(c); 102 chan_send_oclose(c);
97 c->ostate=CHAN_OUTPUT_WAIT_IEOF; 103 c->ostate = CHAN_OUTPUT_WAIT_IEOF;
98 break; 104 break;
99 case CHAN_OUTPUT_WAIT_DRAIN: 105 case CHAN_OUTPUT_WAIT_DRAIN:
100 debug("channel %d: OUTPUT_WAIT_DRAIN -> OUTPUT_CLOSED [write failed]", c->self); 106 debug("channel %d: OUTPUT_WAIT_DRAIN -> OUTPUT_CLOSED [write failed]", c->self);
101 chan_send_oclose(c); 107 chan_send_oclose(c);
102 c->ostate=CHAN_OUTPUT_CLOSED; 108 c->ostate = CHAN_OUTPUT_CLOSED;
103 chan_delele_if_full_closed(c); 109 chan_delele_if_full_closed(c);
104 break; 110 break;
105 default: 111 default:
106 debug("internal error: chan_write_failed %d for ostate %d",c->self,c->ostate); 112 debug("internal error: chan_write_failed %d for ostate %d", c->self, c->ostate);
107 break; 113 break;
108 } 114 }
109} 115}
110void 116void
111chan_obuf_empty(Channel *c){ 117chan_obuf_empty(Channel *c)
112 if(buffer_len(&c->output)){ 118{
113 debug("internal error: chan_obuf_empty %d for non empty buffer",c->self); 119 if (buffer_len(&c->output)) {
120 debug("internal error: chan_obuf_empty %d for non empty buffer", c->self);
114 return; 121 return;
115 } 122 }
116 switch(c->ostate){ 123 switch (c->ostate) {
117 case CHAN_OUTPUT_WAIT_DRAIN: 124 case CHAN_OUTPUT_WAIT_DRAIN:
118 debug("channel %d: OUTPUT_WAIT_DRAIN -> OUTPUT_CLOSED [obuf empty, send OCLOSE]", c->self); 125 debug("channel %d: OUTPUT_WAIT_DRAIN -> OUTPUT_CLOSED [obuf empty, send OCLOSE]", c->self);
119 chan_send_oclose(c); 126 chan_send_oclose(c);
120 c->ostate=CHAN_OUTPUT_CLOSED; 127 c->ostate = CHAN_OUTPUT_CLOSED;
121 chan_delele_if_full_closed(c); 128 chan_delele_if_full_closed(c);
122 break; 129 break;
123 default: 130 default:
124 debug("internal error: chan_obuf_empty %d for ostate %d",c->self,c->ostate); 131 debug("internal error: chan_obuf_empty %d for ostate %d", c->self, c->ostate);
125 break; 132 break;
126 } 133 }
127} 134}
135
128/* 136/*
129 * ACTIONS: should never update c->istate or c->ostate 137 * ACTIONS: should never update the channel states: c->istate or c->ostate
130 */ 138 */
131static void 139static void
132chan_send_ieof(Channel *c){ 140chan_send_ieof(Channel *c)
133 switch(c->istate){ 141{
142 switch (c->istate) {
134 case CHAN_INPUT_OPEN: 143 case CHAN_INPUT_OPEN:
135 case CHAN_INPUT_WAIT_DRAIN: 144 case CHAN_INPUT_WAIT_DRAIN:
136 packet_start(SSH_MSG_CHANNEL_INPUT_EOF); 145 packet_start(SSH_MSG_CHANNEL_INPUT_EOF);
@@ -138,13 +147,14 @@ chan_send_ieof(Channel *c){
138 packet_send(); 147 packet_send();
139 break; 148 break;
140 default: 149 default:
141 debug("internal error: channel %d: cannot send IEOF for istate %d",c->self,c->istate); 150 debug("internal error: channel %d: cannot send IEOF for istate %d", c->self, c->istate);
142 break; 151 break;
143 } 152 }
144} 153}
145static void 154static void
146chan_send_oclose(Channel *c){ 155chan_send_oclose(Channel *c)
147 switch(c->ostate){ 156{
157 switch (c->ostate) {
148 case CHAN_OUTPUT_OPEN: 158 case CHAN_OUTPUT_OPEN:
149 case CHAN_OUTPUT_WAIT_DRAIN: 159 case CHAN_OUTPUT_WAIT_DRAIN:
150 chan_shutdown_write(c); 160 chan_shutdown_write(c);
@@ -154,34 +164,39 @@ chan_send_oclose(Channel *c){
154 packet_send(); 164 packet_send();
155 break; 165 break;
156 default: 166 default:
157 debug("internal error: channel %d: cannot send OCLOSE for ostate %d",c->self,c->istate); 167 debug("internal error: channel %d: cannot send OCLOSE for ostate %d", c->self, c->istate);
158 break; 168 break;
159 } 169 }
160} 170}
171
161/* helper */ 172/* helper */
162static void 173static void
163chan_shutdown_write(Channel *c){ 174chan_shutdown_write(Channel *c)
175{
164 debug("channel %d: shutdown_write", c->self); 176 debug("channel %d: shutdown_write", c->self);
165 if(shutdown(c->sock, SHUT_WR)<0) 177 if (shutdown(c->sock, SHUT_WR) < 0)
166 error("chan_shutdown_write failed for #%d/fd%d: %.100s", 178 error("chan_shutdown_write failed for #%d/fd%d: %.100s",
167 c->self, c->sock, strerror(errno)); 179 c->self, c->sock, strerror(errno));
168} 180}
169static void 181static void
170chan_shutdown_read(Channel *c){ 182chan_shutdown_read(Channel *c)
183{
171 debug("channel %d: shutdown_read", c->self); 184 debug("channel %d: shutdown_read", c->self);
172 if(shutdown(c->sock, SHUT_RD)<0) 185 if (shutdown(c->sock, SHUT_RD) < 0)
173 error("chan_shutdown_read failed for #%d/fd%d: %.100s", 186 error("chan_shutdown_read failed for #%d/fd%d: %.100s",
174 c->self, c->sock, strerror(errno)); 187 c->self, c->sock, strerror(errno));
175} 188}
176static void 189static void
177chan_delele_if_full_closed(Channel *c){ 190chan_delele_if_full_closed(Channel *c)
178 if(c->istate==CHAN_INPUT_CLOSED && c->ostate==CHAN_OUTPUT_CLOSED){ 191{
192 if (c->istate == CHAN_INPUT_CLOSED && c->ostate == CHAN_OUTPUT_CLOSED) {
179 debug("channel %d: closing", c->self); 193 debug("channel %d: closing", c->self);
180 channel_free(c->self); 194 channel_free(c->self);
181 } 195 }
182} 196}
183void 197void
184chan_init_iostates(Channel *c){ 198chan_init_iostates(Channel *c)
185 c->ostate=CHAN_OUTPUT_OPEN; 199{
186 c->istate=CHAN_INPUT_OPEN; 200 c->ostate = CHAN_OUTPUT_OPEN;
201 c->istate = CHAN_INPUT_OPEN;
187} 202}