Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit be50e21

Browse files
committed
I think it'll work now...
1 parent 01c4bda commit be50e21

File tree

3 files changed

+60
-21
lines changed

3 files changed

+60
-21
lines changed

clientproxy.tcl

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4141
package require tls
4242

4343
if {[llength $::argv] < 2} {
44-
puts stdout "Oi, you gotta specify both the port AND the hostname - try: ./${argv0} 27070 127.0.0.1"
44+
puts stdout "Oi, you gotta specify both the port AND the hostname - try: ${argv0} 27070 127.0.0.1"
4545
exit
4646
}
4747
socket -myaddr [lindex $::argv 1] -server acceptconn [lindex $::argv 0]
4848
set proxyhost [lindex $::argv 1]
4949

5050
proc acceptconn {c a p} {
51-
#puts stdout "received connection from 1/$p/$a"
51+
puts stdout "received connection from 1/$p/$a"
5252
chan configure $c -blocking 0 -buffering line -translation {auto crlf}
5353
chan event $c readable [list tgp:read $c $a $p]
5454
}
@@ -62,25 +62,25 @@ proc tgp:fmt-line {type selector path host {port 70} {plus {}}} {
6262

6363
proc tgp:read {c a p} {
6464
set gotten [gets $c line]
65-
#puts stdout $line
65+
puts stdout $line
6666
if {[string index $line 0] == "/"} {set line [string range $line 1 end]}
6767
set req [split $line "/"]
6868
if {[llength $req] < 3} {
6969
puts $c [tgp:fmt-line 3 "Error: insufficient path length" "/" [lindex $::argv 1] [lindex $::argv 0]]
7070
close $c
7171
return
7272
}
73-
#puts stdout $req
73+
puts stdout $req
7474
set sendsel [lassign $req stype tp ta]
75-
set socketc ::socket
75+
set socketc [list ::socket]
7676
if {[llength $sendsel] > 0 || ([lindex $sendsel 0] != {} && [lindex $sendsel 0] != "")} {set sendsel [join $sendsel "/"]} {set sendsel ""}
7777
if {[string length $stype] > 1} {
7878
set stype [string index $stype 0]
79-
set socketc [list ::tls::socket -require 0]
79+
set socketc [list ::tls::socket -require 0 -ssl2 0 -ssl3 0]
8080
}
8181
if {$tp > 100000} {
8282
set tp [expr {$tp - 100000}]
83-
set socketc [list ::tls::socket -require 0]
83+
set socketc [list ::tls::socket -require 0 -ssl2 0 -ssl3 0]
8484
}
8585
if {$stype == "1" || $stype == "7"} {
8686
set socketrcb tgp:smread
@@ -91,13 +91,16 @@ proc tgp:read {c a p} {
9191
}
9292
if {[set errval [catch [list {*}$socketc $ta $tp] err]] != 0} {
9393
puts $c [tgp:fmt-line 3 "Error: connection did not synchronise" "/" "127.0.0.1" [lindex $::argv 0]]
94-
#puts stdout [format "%s/%s %s;%s/%s %s %s - failed" $p $a $ta $tp $stype $sendsel $socketc]
94+
puts stdout [format "%s/%s %s;%s/%s %s %s - failed" $p $a $ta $tp $stype $sendsel $socketc]
9595
close $c
9696
return
9797
} {
98-
chan configure $err -blocking 0 -buffering line -buffersize 64
99-
puts $err $sendsel
100-
#puts stdout [format "%s/%s %s;%s/%s %s %s - fetching" $p $a $ta $tp $stype $sendsel $socketrcb]
98+
chan configure $err -blocking 1 -buffering none -translation binary
99+
if {[lindex $socketc 0] == "::tls::socket"} {tls::handshake $err}
100+
chan configure $c -blocking 0 -buffering line -translation {auto crlf}
101+
chan configure $err -blocking 0 -buffering line -translation {auto crlf}
102+
puts -nonewline $err [format "%s\r\n" $sendsel]
103+
puts stdout [format "%s/%s %s;%s/%s %s %s - fetching" $p $a $ta $tp $stype $sendsel $socketrcb]
101104
#chan event $c readable [list tgp:getitinthere $err $c]
102105
chan event $err readable [list $socketrcb $c $err]
103106
return
@@ -152,11 +155,13 @@ proc tgp:smread {channel fp} {
152155
if {[catch [list chan tell $fp] err] != 0} {
153156
close $channel
154157
}
155-
fconfigure $channel -translation {auto crlf} -buffering line -buffersize 2048
156-
fconfigure $fp -translation {auto crlf} -buffering line -buffersize 2048
157-
while {[gets $fp text] > 0} {
158+
fconfigure $channel -translation {auto crlf} -buffering line
159+
fconfigure $fp -translation {crlf crlf} -buffering none
160+
puts stdout [format "%s %s spinning the read" $channel $fp]
161+
while {[set nn [gets $fp text]] > 0} {
162+
puts stdout $nn
158163
set gopherplus [lassign [tgd:split $text] st sn ts ta tp]
159-
#puts stdout [format "/%s/ -> g+/%s/ st/%s/ sn/%s/ ts/%s/ ta/%s/ tp/%s/" $text $gopherplus $st $sn $ts $ta $tp]
164+
puts stdout [format "/%s/ -> g+/%s/ st/%s/ sn/%s/ ts/%s/ ta/%s/ tp/%s/" $text $gopherplus $st $sn $ts $ta $tp]
160165
if {$st != "i" && $st != "."} {
161166
if {$tp > 100000} {
162167
set iss "t"
@@ -173,6 +178,7 @@ proc tgp:smread {channel fp} {
173178
}
174179
puts $channel $otext
175180
}
181+
puts stdout $nn
176182
flush $channel
177183
if {[fblocked $fp] == 0} {close $fp; close $channel}
178184
}

ssl.c

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ char *ssl_fgets (char *buf, size_t count, void *sockst)
7474
{
7575
size_t donecount;
7676
char ourbuf[BUFSIZE];
77+
memset(&ourbuf, 0, BUFSIZE);
7778
char *ours = ourbuf;
7879
char osslerr[BUFSIZE];
7980
sockstate *ss = (sockstate *)sockst;
8081
int i, j;
82+
syslog(LOG_ERR, "reading up to %lu bytes", count);
8183

8284
for (i = 0; i < count && i < BUFSIZE; i++) {
8385
continuate:
@@ -96,23 +98,54 @@ char *ssl_fgets (char *buf, size_t count, void *sockst)
9698
goto continuate;
9799
break;
98100
case SSL_ERROR_SYSCALL:
99-
if (errno == 0) goto continuate;
101+
if (errno == EAGAIN) goto continuate;
100102
syslog(LOG_ERR, "Unrecoverable SSL error in fgets: syscall error %s, and here's the cruft in errcode and osslerr: %i, %s", strerror(errno), errcode, osslerr);
101103
break;
102104
case SSL_ERROR_SSL:
103105
syslog(LOG_ERR, "Unrecoverable SSL error in fgets: SSL protocol error. And, %s.", errcode == 0 ? "No SSL error." : osslerr);
104106
break;
105107
}
106108
} else {
107-
ours = ours + j + 1;
109+
ours = ours + j;
110+
syslog(LOG_ERR, "reading bytes - number read == %i - this part of the buffer: %s - our buffer so far: %s", ourbuf[i], ours, ourbuf);
108111
i = i + j;
109-
if (ourbuf[i] == '\n') {
112+
if (ourbuf[i-1] == '\n' || ourbuf[i-1] == '\0') {
113+
break;
114+
}
115+
}
116+
}
117+
strlcpy(buf, ourbuf, i);
118+
return buf;
119+
};
120+
121+
char *emulating_ssl_fgets (char *buf, size_t count, void *sockst)
122+
{
123+
size_t donecount;
124+
char ourbuf[BUFSIZE];
125+
memset(&ourbuf, 0, BUFSIZE);
126+
char *ours = ourbuf;
127+
char osslerr[BUFSIZE];
128+
sockstate *ss = (sockstate *)sockst;
129+
int i, j;
130+
syslog(LOG_ERR, "reading up to %lu bytes", count);
131+
132+
for (i = 0; i < count && i < BUFSIZE; i++) {
133+
continuate:
134+
if ((j = read( ss->rfd, ours, BUFSIZE - i - 1)) <= 0) {
135+
int errcode = errno;
136+
syslog(LOG_ERR, "Error in fgets: %s.", errcode == 0 ? "No error." : osslerr);
137+
if (ourbuf[i-1] == '\n' || ourbuf[i-1] == '\0') {
138+
break;
139+
}
140+
} else {
141+
ours = ours + j;
142+
syslog(LOG_ERR, "reading a byte 0x%x - our buffer so far: %s", ourbuf[i], ourbuf);
143+
i = i + j;
144+
if (ourbuf[i-1] == '\n' || ourbuf[i-1] == '\0') {
110145
break;
111146
}
112147
}
113148
}
114-
if (i+1 < BUFSIZE) ourbuf[i+1] = 0;
115-
else ourbuf[BUFSIZE-1] = 0;
116149
strlcpy(buf, ourbuf, i);
117150
return buf;
118151
};

ugopherserver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ int main(int argc, char *argv[])
624624
st.ss.rfd = 0;
625625
st.read = &plain_read;
626626
st.write = &plain_write;
627-
st.fgets = &plain_fgets;
627+
st.fgets = &emulating_ssl_fgets;
628628
}
629629

630630
#ifdef HAVE_PASSWD

0 commit comments

Comments
 (0)