Commit 4d0840afcb6900ae282ada74e49082591a834862
1 parent
4aa7a83f
Exists in
master
and in
3 other branches
Corrigindo problemas encontrados durante teste do sub-módulo.
Showing
4 changed files
with
35 additions
and
1037 deletions
Show diff stats
Makefile.in
| @@ -39,6 +39,9 @@ CC=@CC@ | @@ -39,6 +39,9 @@ CC=@CC@ | ||
| 39 | LD=@CC@ | 39 | LD=@CC@ |
| 40 | LN_S=@LN_S@ | 40 | LN_S=@LN_S@ |
| 41 | MKDIR=@MKDIR_P@ | 41 | MKDIR=@MKDIR_P@ |
| 42 | +INSTALL=@INSTALL@ | ||
| 43 | +INSTALL_DATA=@INSTALL_DATA@ | ||
| 44 | +INSTALL_PROGRAM=@INSTALL_PROGRAM@ | ||
| 42 | 45 | ||
| 43 | #---[ Paths ]---------------------------------------------------------------------------- | 46 | #---[ Paths ]---------------------------------------------------------------------------- |
| 44 | 47 | ||
| @@ -148,6 +151,15 @@ $(BINRLS)/@DLLPREFIX@$(LIBNAME)@DLLEXT@.@PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_V | @@ -148,6 +151,15 @@ $(BINRLS)/@DLLPREFIX@$(LIBNAME)@DLLEXT@.@PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_V | ||
| 148 | $(LDFLAGS) \ | 151 | $(LDFLAGS) \ |
| 149 | $(LIBS) | 152 | $(LIBS) |
| 150 | 153 | ||
| 154 | +#---[ Misc Targets ]--------------------------------------------------------------------- | ||
| 155 | + | ||
| 156 | +src/lib3270/version.c: \ | ||
| 157 | + Makefile | ||
| 158 | + | ||
| 159 | + @echo $(basename $@) ... | ||
| 160 | + @chmod +x src/lib3270/mkversion.sh | ||
| 161 | + @./src/lib3270/mkversion.sh | ||
| 162 | + | ||
| 151 | #---[ Install Targets ]------------------------------------------------------------------ | 163 | #---[ Install Targets ]------------------------------------------------------------------ |
| 152 | 164 | ||
| 153 | 165 | ||
| @@ -182,6 +194,7 @@ $(BINDBG)/@DLLPREFIX@$(LIBNAME)@DLLEXT@.@PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_V | @@ -182,6 +194,7 @@ $(BINDBG)/@DLLPREFIX@$(LIBNAME)@DLLEXT@.@PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_V | ||
| 182 | -shared -Wl,-soname,$(@F) \ | 194 | -shared -Wl,-soname,$(@F) \ |
| 183 | -o $@ \ | 195 | -o $@ \ |
| 184 | $(LDFLAGS) \ | 196 | $(LDFLAGS) \ |
| 197 | + $(foreach SRC, $(basename $(SOURCES)), $(OBJDBG)/$(SRC).o) \ | ||
| 185 | $(LIBS) | 198 | $(LIBS) |
| 186 | 199 | ||
| 187 | #---[ Clean Targets ]-------------------------------------------------------------------- | 200 | #---[ Clean Targets ]-------------------------------------------------------------------- |
configure.ac
| @@ -146,6 +146,19 @@ AC_SUBST(PACKAGE_RELEASE,$app_cv_release) | @@ -146,6 +146,19 @@ AC_SUBST(PACKAGE_RELEASE,$app_cv_release) | ||
| 146 | AC_SUBST(PACKAGE_MAJOR_RELEASE,$app_rls_major) | 146 | AC_SUBST(PACKAGE_MAJOR_RELEASE,$app_rls_major) |
| 147 | AC_SUBST(PACKAGE_MINOR_RELEASE,$app_rls_minor) | 147 | AC_SUBST(PACKAGE_MINOR_RELEASE,$app_rls_minor) |
| 148 | 148 | ||
| 149 | +rpq_build_date=`LANG=C date` | ||
| 150 | +rpq_timestamp=`date +%Y%m%d%H%M%S` | ||
| 151 | +rpq_revision=`date +"%Y%m%d"` | ||
| 152 | +sccs_date=`date +%Y/%m/%d` | ||
| 153 | +sccs_user=$USER | ||
| 154 | + | ||
| 155 | +AC_SUBST(RPQ_BUILD_DATE,$rpq_build_date) | ||
| 156 | +AC_SUBST(RPQ_TIMESTAMP,$rpq_timestamp) | ||
| 157 | +AC_SUBST(RPQ_REVISION,$rpq_revision) | ||
| 158 | + | ||
| 159 | +AC_SUBST(SCCS_USER,$USER) | ||
| 160 | +AC_SUBST(SCCS_DATE,$sccs_date) | ||
| 161 | + | ||
| 149 | dnl --------------------------------------------------------------------------- | 162 | dnl --------------------------------------------------------------------------- |
| 150 | dnl Check for libintl | 163 | dnl Check for libintl |
| 151 | dnl --------------------------------------------------------------------------- | 164 | dnl --------------------------------------------------------------------------- |
| @@ -368,6 +381,7 @@ dnl Configure which files to generate. | @@ -368,6 +381,7 @@ dnl Configure which files to generate. | ||
| 368 | dnl --------------------------------------------------------------------------- | 381 | dnl --------------------------------------------------------------------------- |
| 369 | 382 | ||
| 370 | AC_CONFIG_FILES(sdk/lib3270.pc) | 383 | AC_CONFIG_FILES(sdk/lib3270.pc) |
| 384 | +AC_CONFIG_FILES(src/lib3270/version.c) | ||
| 371 | AC_CONFIG_FILES(Makefile) | 385 | AC_CONFIG_FILES(Makefile) |
| 372 | 386 | ||
| 373 | dnl --------------------------------------------------------------------------- | 387 | dnl --------------------------------------------------------------------------- |
src/lib3270/proxy.c
| @@ -1,1037 +0,0 @@ | @@ -1,1037 +0,0 @@ | ||
| 1 | -/* | ||
| 2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | ||
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | ||
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. Registro no INPI sob o nome G3270. | ||
| 5 | - * | ||
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | ||
| 7 | - * | ||
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | ||
| 9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | ||
| 10 | - * Free Software Foundation. | ||
| 11 | - * | ||
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | ||
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | ||
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | ||
| 15 | - * obter mais detalhes. | ||
| 16 | - * | ||
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | ||
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | ||
| 19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | - * | ||
| 21 | - * Este programa está nomeado como proxy.c e possui - linhas de código. | ||
| 22 | - * | ||
| 23 | - * Contatos: | ||
| 24 | - * | ||
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | ||
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | ||
| 27 | - * licinio@bb.com.br (Licínio Luis Branco) | ||
| 28 | - * kraucer@bb.com.br (Kraucer Fernandes Mazuco) | ||
| 29 | - * | ||
| 30 | - */ | ||
| 31 | - | ||
| 32 | - | ||
| 33 | -/** | ||
| 34 | - * @file proxy.c | ||
| 35 | - * | ||
| 36 | - * This module implements various kinds of proxies. | ||
| 37 | - * | ||
| 38 | - */ | ||
| 39 | - | ||
| 40 | -#ifdef _WIN32 | ||
| 41 | - #include <winsock2.h> | ||
| 42 | - #include <windows.h> | ||
| 43 | -#endif // _WIN32 | ||
| 44 | - | ||
| 45 | -#include "private.h" | ||
| 46 | -#include "utilc.h" | ||
| 47 | - | ||
| 48 | -//#include "appres.h" | ||
| 49 | -#include "resources.h" | ||
| 50 | - | ||
| 51 | -#ifndef ANDROID | ||
| 52 | - #include <stdlib.h> | ||
| 53 | -#endif | ||
| 54 | - | ||
| 55 | -#if defined(_WIN32) | ||
| 56 | - #include <ws2tcpip.h> | ||
| 57 | - #include "w3miscc.h" | ||
| 58 | -#else | ||
| 59 | - | ||
| 60 | - #include <sys/socket.h> | ||
| 61 | - #include <sys/ioctl.h> | ||
| 62 | - #include <netinet/in.h> | ||
| 63 | - #include <netdb.h> | ||
| 64 | - #include <arpa/inet.h> | ||
| 65 | - | ||
| 66 | -// #if defined(HAVE_SYS_SELECT_H) | ||
| 67 | -// #include <sys/select.h> | ||
| 68 | -// #endif | ||
| 69 | - | ||
| 70 | -#endif | ||
| 71 | - | ||
| 72 | -#include "api.h" | ||
| 73 | - | ||
| 74 | -#include "3270ds.h" | ||
| 75 | -#include "popupsc.h" | ||
| 76 | -#include "proxyc.h" | ||
| 77 | -#include "resolverc.h" | ||
| 78 | -#include "telnetc.h" | ||
| 79 | -#include "trace_dsc.h" | ||
| 80 | -#include "w3miscc.h" | ||
| 81 | -#include "screen.h" | ||
| 82 | - | ||
| 83 | -// #if defined(PR3287) | ||
| 84 | -// extern char *proxy_spec; | ||
| 85 | -// #endif | ||
| 86 | - | ||
| 87 | -/* | ||
| 88 | - * Supported proxy types. | ||
| 89 | - * | ||
| 90 | - * At some point we will add SOCKS. | ||
| 91 | - */ | ||
| 92 | -enum | ||
| 93 | -{ | ||
| 94 | - PT_NONE, | ||
| 95 | - PT_PASSTHRU, /**< Sun telnet-passthru */ | ||
| 96 | - PT_HTTP, /**< RFC 2817 CONNECT tunnel */ | ||
| 97 | - PT_TELNET, /**< 'connect host port' proxy */ | ||
| 98 | - PT_SOCKS4, /**< SOCKS version 4 (or 4A if necessary) */ | ||
| 99 | - PT_SOCKS4A, /**< SOCKS version 4A (force remote name resolution) */ | ||
| 100 | - PT_SOCKS5, /**< SOCKS version 5 (RFC 1928) */ | ||
| 101 | - PT_SOCKS5D, /**< SOCKS version 5 (force remote name resolution) */ | ||
| 102 | - PT_MAX | ||
| 103 | -} proxytype_t; | ||
| 104 | - | ||
| 105 | -#define PROXY_PASSTHRU "passthru" | ||
| 106 | -#define PORT_PASSTHRU "3514" | ||
| 107 | - | ||
| 108 | -#define PROXY_HTTP "http" | ||
| 109 | -#define PORT_HTTP "3128" | ||
| 110 | - | ||
| 111 | -#define PROXY_TELNET "telnet" | ||
| 112 | - | ||
| 113 | -#define PROXY_SOCKS4 "socks4" | ||
| 114 | -#define PORT_SOCKS4 "1080" | ||
| 115 | - | ||
| 116 | -#define PROXY_SOCKS4A "socks4a" | ||
| 117 | -#define PORT_SOCKS4A "1080" | ||
| 118 | - | ||
| 119 | -#define PROXY_SOCKS5 "socks5" | ||
| 120 | -#define PORT_SOCKS5 "1080" | ||
| 121 | - | ||
| 122 | -#define PROXY_SOCKS5D "socks5d" | ||
| 123 | -#define PORT_SOCKS5D "1080" | ||
| 124 | - | ||
| 125 | -static int parse_host_port(H3270 *hSession, char *s, char **phost, char **pport); | ||
| 126 | - | ||
| 127 | -static int proxy_passthru(H3270 *hSession, int fd, char *host, unsigned short port); | ||
| 128 | -static int proxy_http(H3270 *hSession, int fd, char *host, unsigned short port); | ||
| 129 | -static int proxy_telnet(H3270 *hSession, int fd, char *host, unsigned short port); | ||
| 130 | -static int proxy_socks4(H3270 *hSession, int fd, char *host, unsigned short port, int force_a); | ||
| 131 | -static int proxy_socks5(H3270 *hSession, int fd, char *host, unsigned short port, int force_d); | ||
| 132 | - | ||
| 133 | - | ||
| 134 | -const char * proxy_type_name(int type) | ||
| 135 | -{ | ||
| 136 | - /* proxy type names -- keep these in sync with proxytype_t! */ | ||
| 137 | - const char *type_name[] = | ||
| 138 | - { | ||
| 139 | - "unknown", | ||
| 140 | - "passthru", | ||
| 141 | - "HTTP", | ||
| 142 | - "TELNET", | ||
| 143 | - "SOCKS4", | ||
| 144 | - "SOCKS4A", | ||
| 145 | - "SOCKS5", | ||
| 146 | - "SOCKS5D" | ||
| 147 | - }; | ||
| 148 | - | ||
| 149 | - | ||
| 150 | - if (type < 1 || type >= PT_MAX) | ||
| 151 | - return "unknown"; | ||
| 152 | - else | ||
| 153 | - return type_name[type]; | ||
| 154 | -} | ||
| 155 | - | ||
| 156 | -/** | ||
| 157 | - * Resolve the type, hostname and port for a proxy. | ||
| 158 | - * | ||
| 159 | - * @return -1 for failure, 0 for no proxy, >0 (the proxy type) for success. | ||
| 160 | - */ | ||
| 161 | -int proxy_setup(H3270 *hSession, char **phost, char **pport) | ||
| 162 | -{ | ||
| 163 | - char * proxy = hSession->proxy; | ||
| 164 | - char * colon; | ||
| 165 | - int sl; | ||
| 166 | - | ||
| 167 | - if(!proxy) | ||
| 168 | - return PT_NONE; | ||
| 169 | - | ||
| 170 | - if ((colon = strchr(proxy, ':')) == CN || (colon == proxy)) | ||
| 171 | - { | ||
| 172 | - popup_an_error(hSession,_( "Invalid proxy syntax" ) ); | ||
| 173 | - return -1; | ||
| 174 | - } | ||
| 175 | - | ||
| 176 | - sl = colon - proxy; | ||
| 177 | - if (sl == strlen(PROXY_PASSTHRU) && !strncasecmp(proxy, PROXY_PASSTHRU, sl)) | ||
| 178 | - { | ||
| 179 | - if (parse_host_port(hSession, colon + 1, phost, pport) < 0) | ||
| 180 | - return -1; | ||
| 181 | - | ||
| 182 | - if (*pport == CN) | ||
| 183 | - *pport = NewString(PORT_PASSTHRU); | ||
| 184 | - | ||
| 185 | - return PT_PASSTHRU; | ||
| 186 | - } | ||
| 187 | - | ||
| 188 | - if (sl == strlen(PROXY_HTTP) && !strncasecmp(proxy, PROXY_HTTP, sl)) | ||
| 189 | - { | ||
| 190 | - | ||
| 191 | - if (parse_host_port(hSession, colon + 1, phost, pport) < 0) | ||
| 192 | - return -1; | ||
| 193 | - if (*pport == CN) | ||
| 194 | - *pport = NewString(PORT_HTTP); | ||
| 195 | - return PT_HTTP; | ||
| 196 | - } | ||
| 197 | - | ||
| 198 | - if (sl == strlen(PROXY_TELNET) && !strncasecmp(proxy, PROXY_TELNET, sl)) | ||
| 199 | - { | ||
| 200 | - | ||
| 201 | - if (parse_host_port(hSession, colon + 1, phost, pport) < 0) | ||
| 202 | - return -1; | ||
| 203 | - if (*pport == CN) | ||
| 204 | - { | ||
| 205 | - popup_an_error(hSession,_( "Must specify port for telnet proxy" ) ); | ||
| 206 | - return -1; | ||
| 207 | - } | ||
| 208 | - return PT_TELNET; | ||
| 209 | - } | ||
| 210 | - | ||
| 211 | - if (sl == strlen(PROXY_SOCKS4) && !strncasecmp(proxy, PROXY_SOCKS4, sl)) | ||
| 212 | - { | ||
| 213 | - if (parse_host_port(hSession, colon + 1, phost, pport) < 0) | ||
| 214 | - return -1; | ||
| 215 | - | ||
| 216 | - if (*pport == CN) | ||
| 217 | - *pport = NewString(PORT_SOCKS4); | ||
| 218 | - | ||
| 219 | - return PT_SOCKS4; | ||
| 220 | - } | ||
| 221 | - | ||
| 222 | - if (sl == strlen(PROXY_SOCKS4A) && !strncasecmp(proxy, PROXY_SOCKS4A, sl)) | ||
| 223 | - { | ||
| 224 | - if (parse_host_port(hSession, colon + 1, phost, pport) < 0) | ||
| 225 | - return -1; | ||
| 226 | - | ||
| 227 | - if (*pport == CN) | ||
| 228 | - *pport = NewString(PORT_SOCKS4A); | ||
| 229 | - | ||
| 230 | - return PT_SOCKS4A; | ||
| 231 | - } | ||
| 232 | - | ||
| 233 | - if (sl == strlen(PROXY_SOCKS5) && !strncasecmp(proxy, PROXY_SOCKS5, sl)) | ||
| 234 | - { | ||
| 235 | - if (parse_host_port(hSession, colon + 1, phost, pport) < 0) | ||
| 236 | - return -1; | ||
| 237 | - | ||
| 238 | - if (*pport == CN) | ||
| 239 | - *pport = NewString(PORT_SOCKS5); | ||
| 240 | - | ||
| 241 | - return PT_SOCKS5; | ||
| 242 | - } | ||
| 243 | - | ||
| 244 | - if (sl == strlen(PROXY_SOCKS5D) && !strncasecmp(proxy, PROXY_SOCKS5D, sl)) | ||
| 245 | - { | ||
| 246 | - if (parse_host_port(hSession, colon + 1, phost, pport) < 0) | ||
| 247 | - return -1; | ||
| 248 | - | ||
| 249 | - if (*pport == CN) | ||
| 250 | - *pport = NewString(PORT_SOCKS5D); | ||
| 251 | - | ||
| 252 | - return PT_SOCKS5D; | ||
| 253 | - } | ||
| 254 | - | ||
| 255 | - popup_an_error(hSession,_( "Invalid proxy type '%.*s'" ), sl, proxy); | ||
| 256 | - | ||
| 257 | - return -1; | ||
| 258 | -} | ||
| 259 | - | ||
| 260 | -/** | ||
| 261 | - * Parse host[:port] from a string. | ||
| 262 | - * | ||
| 263 | - * 'host' can be in square brackets to allow numeric IPv6 addresses. | ||
| 264 | - * Returns the host name and port name in heap memory. | ||
| 265 | - * | ||
| 266 | - * @return -1 for failure, 0 for success. | ||
| 267 | - */ | ||
| 268 | -static int parse_host_port(H3270 *hSession, char *s, char **phost, char **pport) | ||
| 269 | -{ | ||
| 270 | - char *colon; | ||
| 271 | - char *hstart; | ||
| 272 | - int hlen; | ||
| 273 | - | ||
| 274 | - if (*s == '[') { | ||
| 275 | - char *rbrack; | ||
| 276 | - | ||
| 277 | - /* Hostname in square brackets. */ | ||
| 278 | - hstart = s + 1; | ||
| 279 | - rbrack = strchr(s, ']'); | ||
| 280 | - if (rbrack == CN || | ||
| 281 | - rbrack == s + 1 || | ||
| 282 | - (*(rbrack + 1) != '\0' && *(rbrack + 1) != ':')) { | ||
| 283 | - | ||
| 284 | - popup_an_error(hSession,_( "Invalid proxy hostname syntax")); | ||
| 285 | - return -1; | ||
| 286 | - } | ||
| 287 | - if (*(rbrack + 1) == ':') | ||
| 288 | - colon = rbrack + 1; | ||
| 289 | - else | ||
| 290 | - colon = NULL; | ||
| 291 | - hlen = rbrack - (s + 1); | ||
| 292 | - } else { | ||
| 293 | - hstart = s; | ||
| 294 | - colon = strchr(s, ':'); | ||
| 295 | - if (colon == s) { | ||
| 296 | - popup_an_error(hSession,_("Invalid proxy hostname syntax")); | ||
| 297 | - return -1; | ||
| 298 | - } | ||
| 299 | - if (colon == NULL) | ||
| 300 | - hlen = strlen(s); | ||
| 301 | - else | ||
| 302 | - hlen = colon - s; | ||
| 303 | - } | ||
| 304 | - | ||
| 305 | - /* Parse the port. */ | ||
| 306 | - if (colon == CN || !*(colon + 1)) | ||
| 307 | - *pport = CN; | ||
| 308 | - else | ||
| 309 | - *pport = NewString(colon + 1); | ||
| 310 | - | ||
| 311 | - /* Copy out the hostname. */ | ||
| 312 | - *phost = lib3270_malloc(hlen + 1); | ||
| 313 | - strncpy(*phost, hstart, hlen); | ||
| 314 | - (*phost)[hlen] = '\0'; | ||
| 315 | - return 0; | ||
| 316 | -} | ||
| 317 | - | ||
| 318 | -/** | ||
| 319 | - * Negotiate with the proxy server. | ||
| 320 | - * | ||
| 321 | - * @return -1 for failure, 0 for success. | ||
| 322 | - */ | ||
| 323 | -int proxy_negotiate(H3270 *hSession, int type, int fd, char *host, unsigned short port) | ||
| 324 | -{ | ||
| 325 | - switch (type) | ||
| 326 | - { | ||
| 327 | - case PT_NONE: | ||
| 328 | - return 0; | ||
| 329 | - case PT_PASSTHRU: | ||
| 330 | - return proxy_passthru(hSession, fd, host, port); | ||
| 331 | - case PT_HTTP: | ||
| 332 | - return proxy_http(hSession, fd, host, port); | ||
| 333 | - case PT_TELNET: | ||
| 334 | - return proxy_telnet(hSession, fd, host, port); | ||
| 335 | - case PT_SOCKS4: | ||
| 336 | - return proxy_socks4(hSession, fd, host, port, 0); | ||
| 337 | - case PT_SOCKS4A: | ||
| 338 | - return proxy_socks4(hSession, fd, host, port, 1); | ||
| 339 | - case PT_SOCKS5: | ||
| 340 | - return proxy_socks5(hSession, fd, host, port, 0); | ||
| 341 | - case PT_SOCKS5D: | ||
| 342 | - return proxy_socks5(hSession, fd, host, port, 1); | ||
| 343 | - default: | ||
| 344 | - return -1; | ||
| 345 | - } | ||
| 346 | -} | ||
| 347 | - | ||
| 348 | -/* Sun PASSTHRU proxy. */ | ||
| 349 | -static int proxy_passthru(H3270 *hSession, int fd, char *host, unsigned short port) | ||
| 350 | -{ | ||
| 351 | - char *buf; | ||
| 352 | - | ||
| 353 | - buf = lib3270_malloc(strlen(host) + 32); | ||
| 354 | - (void) sprintf(buf, "%s %u\r\n", host, port); | ||
| 355 | - | ||
| 356 | -#if defined(X3270_TRACE) /*[*/ | ||
| 357 | - trace_dsn(hSession,"Passthru Proxy: xmit '%.*s'", (int) (strlen(buf) - 2), buf); | ||
| 358 | - trace_netdata(hSession,'>', (unsigned char *)buf, (int) strlen(buf)); | ||
| 359 | -#endif /*]*/ | ||
| 360 | - | ||
| 361 | - if (send(fd, buf, strlen(buf), 0) < 0) | ||
| 362 | - { | ||
| 363 | - popup_a_sockerr(hSession,_( "Passthru Proxy: send error" )); | ||
| 364 | - lib3270_free(buf); | ||
| 365 | - return -1; | ||
| 366 | - } | ||
| 367 | - lib3270_free(buf); | ||
| 368 | - | ||
| 369 | - return 0; | ||
| 370 | -} | ||
| 371 | - | ||
| 372 | -/* HTTP (RFC 2817 CONNECT tunnel) proxy. */ | ||
| 373 | -static int | ||
| 374 | -proxy_http(H3270 *hSession, int fd, char *host, unsigned short port) | ||
| 375 | -{ | ||
| 376 | - char *buf; | ||
| 377 | - char *colon; | ||
| 378 | - char rbuf[1024]; | ||
| 379 | - int nr; | ||
| 380 | - int nread = 0; | ||
| 381 | - char *space; | ||
| 382 | - | ||
| 383 | - /* Send the CONNECT request. */ | ||
| 384 | - buf = lib3270_malloc(64 + strlen(host)); | ||
| 385 | - colon = strchr(host, ':'); | ||
| 386 | - sprintf(buf, "CONNECT %s%s%s:%u HTTP/1.1\r\n", | ||
| 387 | - (colon? "[": ""), | ||
| 388 | - host, | ||
| 389 | - (colon? "]": ""), | ||
| 390 | - port); | ||
| 391 | - | ||
| 392 | -#if defined(X3270_TRACE) /*[*/ | ||
| 393 | - trace_dsn(hSession,"HTTP Proxy: xmit '%.*s'\n", (int) (strlen(buf) - 2), buf); | ||
| 394 | - trace_netdata(hSession, '>', (unsigned char *)buf, (int) strlen(buf)); | ||
| 395 | -#endif /*]*/ | ||
| 396 | - | ||
| 397 | - if (send(fd, buf, strlen(buf), 0) < 0) | ||
| 398 | - { | ||
| 399 | - popup_a_sockerr(hSession,_( "HTTP Proxy: send error" )); | ||
| 400 | - lib3270_free(buf); | ||
| 401 | - return -1; | ||
| 402 | - } | ||
| 403 | - | ||
| 404 | - sprintf(buf, "Host: %s%s%s:%u\r\n", | ||
| 405 | - (colon? "[": ""), | ||
| 406 | - host, | ||
| 407 | - (colon? "]": ""), | ||
| 408 | - port); | ||
| 409 | - | ||
| 410 | -#if defined(X3270_TRACE) /*[*/ | ||
| 411 | - trace_dsn(hSession,"HTTP Proxy: xmit '%.*s'\n", (int) (strlen(buf) - 2), buf); | ||
| 412 | - trace_netdata(hSession, '>', (unsigned char *)buf, (int) strlen(buf)); | ||
| 413 | -#endif /*]*/ | ||
| 414 | - | ||
| 415 | - if (send(fd, buf, strlen(buf), 0) < 0) | ||
| 416 | - { | ||
| 417 | - popup_a_sockerr(hSession,_( "HTTP Proxy: send error")); | ||
| 418 | - lib3270_free(buf); | ||
| 419 | - return -1; | ||
| 420 | - } | ||
| 421 | - | ||
| 422 | - strcpy(buf, "\r\n"); | ||
| 423 | -#if defined(X3270_TRACE) /*[*/ | ||
| 424 | - trace_dsn(hSession,"HTTP Proxy: xmit ''\n"); | ||
| 425 | - trace_netdata(hSession, '>', (unsigned char *)buf, strlen(buf)); | ||
| 426 | -#endif /*]*/ | ||
| 427 | - | ||
| 428 | - if (send(fd, buf, strlen(buf), 0) < 0) | ||
| 429 | - { | ||
| 430 | - popup_a_sockerr(hSession,_( "HTTP Proxy: send error" )); | ||
| 431 | - lib3270_free(buf); | ||
| 432 | - return -1; | ||
| 433 | - } | ||
| 434 | - lib3270_free(buf); | ||
| 435 | - | ||
| 436 | - /* | ||
| 437 | - * Process the reply. | ||
| 438 | - * Read a byte at a time until \n or EOF. | ||
| 439 | - */ | ||
| 440 | - for (;;) | ||
| 441 | - { | ||
| 442 | - fd_set rfds; | ||
| 443 | - struct timeval tv; | ||
| 444 | - | ||
| 445 | - FD_ZERO(&rfds); | ||
| 446 | - FD_SET(fd, &rfds); | ||
| 447 | - tv.tv_sec = 15; | ||
| 448 | - tv.tv_usec = 0; | ||
| 449 | - if (select(fd + 1, &rfds, NULL, NULL, &tv) < 0) { | ||
| 450 | - popup_an_error(hSession,_( "HTTP Proxy: server timeout" )); | ||
| 451 | -#if defined(X3270_TRACE) /*[*/ | ||
| 452 | - if (nread) | ||
| 453 | - trace_netdata(hSession, '<', (unsigned char *)rbuf, nread); | ||
| 454 | -#endif /*]*/ | ||
| 455 | - return -1; | ||
| 456 | - } | ||
| 457 | - | ||
| 458 | - nr = recv(fd, &rbuf[nread], 1, 0); | ||
| 459 | - if (nr < 0) { | ||
| 460 | - popup_a_sockerr(hSession,_( "HTTP Proxy: receive error" )); | ||
| 461 | -#if defined(X3270_TRACE) /*[*/ | ||
| 462 | - if (nread) | ||
| 463 | - trace_netdata(hSession, '<', (unsigned char *)rbuf, nread); | ||
| 464 | -#endif /*]*/ | ||
| 465 | - return -1; | ||
| 466 | - } | ||
| 467 | - if (nr == 0) | ||
| 468 | - { | ||
| 469 | -#if defined(X3270_TRACE) /*[*/ | ||
| 470 | - if (nread) | ||
| 471 | - trace_netdata(hSession, '<', (unsigned char *)rbuf, nread); | ||
| 472 | -#endif /*]*/ | ||
| 473 | - popup_an_error(hSession,_( "HTTP Proxy: unexpected EOF" )); | ||
| 474 | - return -1; | ||
| 475 | - } | ||
| 476 | - if (rbuf[nread] == '\r') | ||
| 477 | - continue; | ||
| 478 | - if (rbuf[nread] == '\n') | ||
| 479 | - break; | ||
| 480 | - if (++nread >= sizeof(rbuf)) { | ||
| 481 | - nread = sizeof(rbuf) - 1; | ||
| 482 | - break; | ||
| 483 | - } | ||
| 484 | - } | ||
| 485 | - rbuf[nread] = '\0'; | ||
| 486 | - | ||
| 487 | -#if defined(X3270_TRACE) /*[*/ | ||
| 488 | - trace_netdata(hSession, '<', (unsigned char *)rbuf, nread); | ||
| 489 | - trace_dsn(hSession,"HTTP Proxy: recv '%s'\n", rbuf); | ||
| 490 | -#endif /*]*/ | ||
| 491 | - | ||
| 492 | - if (strncmp(rbuf, "HTTP/", 5) || (space = strchr(rbuf, ' ')) == CN) | ||
| 493 | - { | ||
| 494 | - popup_an_error(hSession,_( "HTTP Proxy: unrecognized reply" )); | ||
| 495 | - return -1; | ||
| 496 | - } | ||
| 497 | - if (*(space + 1) != '2') | ||
| 498 | - { | ||
| 499 | - popup_an_error(hSession,_( "HTTP Proxy: CONNECT failed:\n%s"), rbuf); | ||
| 500 | - return -1; | ||
| 501 | - } | ||
| 502 | - | ||
| 503 | - return 0; | ||
| 504 | -} | ||
| 505 | - | ||
| 506 | -/* TELNET proxy. */ | ||
| 507 | -static int | ||
| 508 | -proxy_telnet(H3270 *hSession, int fd, char *host, unsigned short port) | ||
| 509 | -{ | ||
| 510 | - char *buf; | ||
| 511 | - | ||
| 512 | - buf = lib3270_malloc(strlen(host) + 32); | ||
| 513 | - (void) sprintf(buf, "connect %s %u\r\n", host, port); | ||
| 514 | - | ||
| 515 | -#if defined(X3270_TRACE) /*[*/ | ||
| 516 | - trace_dsn(hSession,"TELNET Proxy: xmit '%.*s'", (int) (strlen(buf) - 2), buf); | ||
| 517 | - trace_netdata(hSession, '>', (unsigned char *)buf, (int) strlen(buf)); | ||
| 518 | -#endif /*]*/ | ||
| 519 | - | ||
| 520 | - if (send(fd, buf, strlen(buf), 0) < 0) | ||
| 521 | - { | ||
| 522 | - popup_a_sockerr(hSession,_( "TELNET Proxy: send error")); | ||
| 523 | - lib3270_free(buf); | ||
| 524 | - return -1; | ||
| 525 | - } | ||
| 526 | - lib3270_free(buf); | ||
| 527 | - | ||
| 528 | - return 0; | ||
| 529 | -} | ||
| 530 | - | ||
| 531 | -/* SOCKS version 4 proxy. */ | ||
| 532 | -#if defined(HAVE_GETADDRINFO) | ||
| 533 | -static int proxy_socks4(H3270 *hSession, int fd, char *host, unsigned short port, int force_a) | ||
| 534 | -{ | ||
| 535 | - popup_an_error(hSession,"%s", _( "Unsupported socks 4 proxy" ) ); | ||
| 536 | - return 0; | ||
| 537 | -} | ||
| 538 | -#else | ||
| 539 | -static int proxy_socks4(H3270 *hSession, int fd, char *host, unsigned short port, int force_a) | ||
| 540 | -{ | ||
| 541 | - struct hostent *hp; | ||
| 542 | - struct in_addr ipaddr; | ||
| 543 | - int use_4a = 0; | ||
| 544 | - char *user; | ||
| 545 | - char *buf; | ||
| 546 | - char *s; | ||
| 547 | - char rbuf[8]; | ||
| 548 | - int nr; | ||
| 549 | - int nread = 0; | ||
| 550 | -#if defined(X3270_TRACE) /*[*/ | ||
| 551 | - unsigned short rport; | ||
| 552 | -#endif | ||
| 553 | - | ||
| 554 | - /* Resolve the hostname to an IPv4 address. */ | ||
| 555 | - if (force_a) | ||
| 556 | - use_4a = 1; | ||
| 557 | - else { | ||
| 558 | - hp = gethostbyname(host); | ||
| 559 | - if (hp != NULL) { | ||
| 560 | - memcpy(&ipaddr, hp->h_addr, hp->h_length); | ||
| 561 | - } else { | ||
| 562 | - ipaddr.s_addr = inet_addr(host); | ||
| 563 | - if (ipaddr.s_addr == -1) | ||
| 564 | - use_4a = 1; | ||
| 565 | - } | ||
| 566 | - } | ||
| 567 | - | ||
| 568 | - /* Resolve the username. */ | ||
| 569 | -#ifdef ANDROID | ||
| 570 | - user = "android"; | ||
| 571 | -#else | ||
| 572 | - user = getenv("USER"); | ||
| 573 | - if (user == CN) | ||
| 574 | - user = "nobody"; | ||
| 575 | -#endif // ANDROID | ||
| 576 | - | ||
| 577 | - /* Send the request to the server. */ | ||
| 578 | - if (use_4a) { | ||
| 579 | - buf = lib3270_malloc(32 + strlen(user) + strlen(host)); | ||
| 580 | - s = buf; | ||
| 581 | - *s++ = 0x04; | ||
| 582 | - *s++ = 0x01; | ||
| 583 | - SET16(s, port); | ||
| 584 | - SET32(s, 0x00000001); | ||
| 585 | - strcpy(s, user); | ||
| 586 | - s += strlen(user) + 1; | ||
| 587 | - strcpy(s, host); | ||
| 588 | - s += strlen(host) + 1; | ||
| 589 | - | ||
| 590 | -#if defined(X3270_TRACE) /*[*/ | ||
| 591 | - trace_dsn(hSession,"SOCKS4 Proxy: version 4 connect port %u address 0.0.0.1 user '%s' host '%s'\n",port, user, host); | ||
| 592 | - trace_netdata(hSession,'>', (unsigned char *)buf, s - buf); | ||
| 593 | -#endif /*]*/ | ||
| 594 | - | ||
| 595 | - if (send(fd, buf, s - buf, 0) < 0) | ||
| 596 | - { | ||
| 597 | - popup_a_sockerr(hSession,_( "SOCKS4 Proxy: send error" )); | ||
| 598 | - lib3270_free(buf); | ||
| 599 | - return -1; | ||
| 600 | - } | ||
| 601 | - lib3270_free(buf); | ||
| 602 | - } else { | ||
| 603 | - unsigned long u; | ||
| 604 | - | ||
| 605 | - buf = lib3270_malloc(32 + strlen(user)); | ||
| 606 | - s = buf; | ||
| 607 | - *s++ = 0x04; | ||
| 608 | - *s++ = 0x01; | ||
| 609 | - SET16(s, port); | ||
| 610 | - u = ntohl(ipaddr.s_addr); | ||
| 611 | - SET32(s, u); | ||
| 612 | - strcpy(s, user); | ||
| 613 | - s += strlen(user) + 1; | ||
| 614 | - | ||
| 615 | -#if defined(X3270_TRACE) /*[*/ | ||
| 616 | - trace_dsn(hSession,_( "SOCKS4 Proxy: xmit version 4 connect port %u address %s user '%s'\n"),port, inet_ntoa(ipaddr), user); | ||
| 617 | - trace_netdata(hSession,'>', (unsigned char *)buf, s - buf); | ||
| 618 | -#endif /*]*/ | ||
| 619 | - | ||
| 620 | - if (send(fd, buf, s - buf, 0) < 0) | ||
| 621 | - { | ||
| 622 | - lib3270_free(buf); | ||
| 623 | - popup_a_sockerr(hSession,_("SOCKS4 Proxy: send error")); | ||
| 624 | - return -1; | ||
| 625 | - } | ||
| 626 | - lib3270_free(buf); | ||
| 627 | - } | ||
| 628 | - | ||
| 629 | - /* | ||
| 630 | - * Process the reply. | ||
| 631 | - * Read 8 bytes of response. | ||
| 632 | - */ | ||
| 633 | - for (;;) { | ||
| 634 | - fd_set rfds; | ||
| 635 | - struct timeval tv; | ||
| 636 | - | ||
| 637 | - FD_ZERO(&rfds); | ||
| 638 | - FD_SET(fd, &rfds); | ||
| 639 | - tv.tv_sec = 15; | ||
| 640 | - tv.tv_usec = 0; | ||
| 641 | - if (select(fd + 1, &rfds, NULL, NULL, &tv) < 0) | ||
| 642 | - { | ||
| 643 | - popup_an_error(hSession,_("SOCKS4 Proxy: server timeout")); | ||
| 644 | - return -1; | ||
| 645 | - } | ||
| 646 | - | ||
| 647 | - nr = recv(fd, &rbuf[nread], 1, 0); | ||
| 648 | - | ||
| 649 | - if (nr < 0) | ||
| 650 | - { | ||
| 651 | - popup_a_sockerr(hSession,_("SOCKS4 Proxy: receive error")); | ||
| 652 | - return -1; | ||
| 653 | - } | ||
| 654 | - if (nr == 0) | ||
| 655 | - break; | ||
| 656 | - | ||
| 657 | - if (++nread >= sizeof(rbuf)) | ||
| 658 | - break; | ||
| 659 | - } | ||
| 660 | - | ||
| 661 | -#if defined(X3270_TRACE) /*[*/ | ||
| 662 | - trace_netdata(hSession,'<', (unsigned char *)rbuf, nread); | ||
| 663 | - if (use_4a) | ||
| 664 | - { | ||
| 665 | - struct in_addr a; | ||
| 666 | - | ||
| 667 | - rport = (rbuf[2] << 8) | rbuf[3]; | ||
| 668 | - memcpy(&a, &rbuf[4], 4); | ||
| 669 | - trace_dsn(hSession,_("SOCKS4 Proxy: recv status 0x%02x port %u address %s\n"),rbuf[1],rport,inet_ntoa(a)); | ||
| 670 | - | ||
| 671 | - } else | ||
| 672 | - trace_dsn(hSession,_("SOCKS4 Proxy: recv status 0x%02x\n"), rbuf[1]); | ||
| 673 | -#endif /*]*/ | ||
| 674 | - | ||
| 675 | - switch (rbuf[1]) | ||
| 676 | - { | ||
| 677 | - case 0x5a: | ||
| 678 | - break; | ||
| 679 | - case 0x5b: | ||
| 680 | - popup_an_error(hSession,_("SOCKS4 Proxy: request rejected or failed")); | ||
| 681 | - return -1; | ||
| 682 | - case 0x5c: | ||
| 683 | - popup_an_error(hSession,_("SOCKS4 Proxy: client is not reachable")); | ||
| 684 | - return -1; | ||
| 685 | - case 0x5d: | ||
| 686 | - popup_an_error(hSession,_("SOCKS4 Proxy: userid error")); | ||
| 687 | - return -1; | ||
| 688 | - default: | ||
| 689 | - popup_an_error(hSession,_("SOCKS4 Proxy: unknown status 0x%02x"),rbuf[1]); | ||
| 690 | - return -1; | ||
| 691 | - } | ||
| 692 | - | ||
| 693 | - return 0; | ||
| 694 | -} | ||
| 695 | -#endif // HAVE_GETADDRINFO | ||
| 696 | - | ||
| 697 | -/* SOCKS version 5 (RFC 1928) proxy. */ /* | ||
| 698 | -static int proxy_socks5(H3270 *hSession, int fd, char *host, unsigned short port, int force_d) | ||
| 699 | -{ | ||
| 700 | - union { | ||
| 701 | - struct sockaddr sa; | ||
| 702 | - struct sockaddr_in sin; | ||
| 703 | -#if defined(AF_INET6) | ||
| 704 | - struct sockaddr_in6 sin6; | ||
| 705 | -#endif | ||
| 706 | - } ha; | ||
| 707 | - socklen_t ha_len = 0; | ||
| 708 | - int use_name = 0; | ||
| 709 | - char *buf; | ||
| 710 | - char *s; | ||
| 711 | - unsigned char rbuf[8]; | ||
| 712 | - int nr; | ||
| 713 | - int nread = 0; | ||
| 714 | - int n2read = 0; | ||
| 715 | - char nbuf[256]; | ||
| 716 | - int done = 0; | ||
| 717 | - | ||
| 718 | -#if defined(X3270_TRACE) | ||
| 719 | - const char *atype_name[] = | ||
| 720 | - { | ||
| 721 | - "", | ||
| 722 | - "IPv4", | ||
| 723 | - "", | ||
| 724 | - "domainname", | ||
| 725 | - "IPv6" | ||
| 726 | - }; | ||
| 727 | - unsigned char *portp; | ||
| 728 | -#endif | ||
| 729 | - unsigned short rport; | ||
| 730 | - | ||
| 731 | - if (force_d) | ||
| 732 | - use_name = 1; | ||
| 733 | - else { | ||
| 734 | - char errmsg[1024]; | ||
| 735 | - int rv; | ||
| 736 | - | ||
| 737 | - // Resolve the hostname. | ||
| 738 | - rv = resolve_host_and_port(hSession,host, CN, &rport, &ha.sa, &ha_len,errmsg, sizeof(errmsg)); | ||
| 739 | - if (rv == -2) | ||
| 740 | - use_name = 1; | ||
| 741 | - else if (rv < 0) { | ||
| 742 | - popup_an_error(hSession,_("SOCKS5 proxy: %s/%u: %s"), host, port,errmsg); | ||
| 743 | - return -1; | ||
| 744 | - } | ||
| 745 | - } | ||
| 746 | - | ||
| 747 | - // Send the authentication request to the server. | ||
| 748 | - strcpy((char *)rbuf, "\005\001\000"); | ||
| 749 | -#if defined(X3270_TRACE) | ||
| 750 | - trace_dsn(hSession,_("SOCKS5 Proxy: xmit version 5 nmethods 1 (no auth)\n")); | ||
| 751 | - trace_netdata(hSession, '>', rbuf, 3); | ||
| 752 | -#endif | ||
| 753 | - if (send(fd, (const char *) rbuf, 3, 0) < 0) | ||
| 754 | - { | ||
| 755 | - popup_a_sockerr(hSession,_("SOCKS5 Proxy: send error")); | ||
| 756 | - return -1; | ||
| 757 | - } | ||
| 758 | - | ||
| 759 | - // | ||
| 760 | - // Wait for the server reply. | ||
| 761 | - // Read 2 bytes of response. | ||
| 762 | - // | ||
| 763 | - nread = 0; | ||
| 764 | - for (;;) { | ||
| 765 | - fd_set rfds; | ||
| 766 | - struct timeval tv; | ||
| 767 | - | ||
| 768 | - FD_ZERO(&rfds); | ||
| 769 | - FD_SET(fd, &rfds); | ||
| 770 | - tv.tv_sec = 15; | ||
| 771 | - tv.tv_usec = 0; | ||
| 772 | - if (select(fd + 1, &rfds, NULL, NULL, &tv) < 0) | ||
| 773 | - { | ||
| 774 | - popup_an_error(hSession,_("SOCKS5 Proxy: server timeout")); | ||
| 775 | -#if defined(X3270_TRACE) | ||
| 776 | - if (nread) | ||
| 777 | - trace_netdata(hSession, '<', rbuf, nread); | ||
| 778 | -#endif | ||
| 779 | - return -1; | ||
| 780 | - } | ||
| 781 | - | ||
| 782 | - nr = recv(fd, (char *) &rbuf[nread], 1, 0); | ||
| 783 | - if (nr < 0) | ||
| 784 | - { | ||
| 785 | - popup_a_sockerr(hSession,_("SOCKS5 Proxy: receive error")); | ||
| 786 | -#if defined(X3270_TRACE) | ||
| 787 | - if (nread) | ||
| 788 | - trace_netdata(hSession, '<', rbuf, nread); | ||
| 789 | -#endif | ||
| 790 | - return -1; | ||
| 791 | - } | ||
| 792 | - if (nr == 0) | ||
| 793 | - { | ||
| 794 | - popup_a_sockerr(hSession,_("SOCKS5 Proxy: unexpected EOF")); | ||
| 795 | -#if defined(X3270_TRACE) | ||
| 796 | - if (nread) | ||
| 797 | - trace_netdata(hSession, '<', rbuf, nread); | ||
| 798 | -#endif | ||
| 799 | - return -1; | ||
| 800 | - } | ||
| 801 | - if (++nread >= 2) | ||
| 802 | - break; | ||
| 803 | - } | ||
| 804 | - | ||
| 805 | -#if defined(X3270_TRACE) | ||
| 806 | - trace_netdata(hSession, '<', rbuf, nread); | ||
| 807 | -#endif | ||
| 808 | - | ||
| 809 | - if (rbuf[0] != 0x05 || (rbuf[1] != 0 && rbuf[1] != 0xff)) | ||
| 810 | - { | ||
| 811 | - popup_an_error(hSession,_("SOCKS5 Proxy: bad authentication response")); | ||
| 812 | - return -1; | ||
| 813 | - } | ||
| 814 | - | ||
| 815 | -#if defined(X3270_TRACE) | ||
| 816 | - trace_dsn(hSession,"SOCKS5 Proxy: recv version %d method %d\n", rbuf[0],rbuf[1]); | ||
| 817 | -#endif | ||
| 818 | - | ||
| 819 | - if (rbuf[1] == 0xff) | ||
| 820 | - { | ||
| 821 | - popup_an_error(hSession,_("SOCKS5 Proxy: authentication failure")); | ||
| 822 | - return -1; | ||
| 823 | - } | ||
| 824 | - | ||
| 825 | - // Send the request to the server. | ||
| 826 | - buf = lib3270_malloc(32 + strlen(host)); | ||
| 827 | - s = buf; | ||
| 828 | - *s++ = 0x05; // protocol version 5 | ||
| 829 | - *s++ = 0x01; // CONNECT | ||
| 830 | - *s++ = 0x00; // reserved | ||
| 831 | - if (use_name) { | ||
| 832 | - *s++ = 0x03; // domain name | ||
| 833 | - *s++ = strlen(host); | ||
| 834 | - strcpy(s, host); | ||
| 835 | - s += strlen(host); | ||
| 836 | - } else if (ha.sa.sa_family == AF_INET) { | ||
| 837 | - *s++ = 0x01; // IPv4 | ||
| 838 | - memcpy(s, &ha.sin.sin_addr, 4); | ||
| 839 | - s += 4; | ||
| 840 | - strcpy(nbuf, inet_ntoa(ha.sin.sin_addr)); | ||
| 841 | -#if defined(AF_INET6) | ||
| 842 | - } else { | ||
| 843 | - *s++ = 0x04; // IPv6 | ||
| 844 | - memcpy(s, &ha.sin6.sin6_addr, sizeof(struct in6_addr)); | ||
| 845 | - s += sizeof(struct in6_addr); | ||
| 846 | - (void) inet_ntop(AF_INET6, &ha.sin6.sin6_addr, nbuf, sizeof(nbuf)); | ||
| 847 | -#endif | ||
| 848 | - } | ||
| 849 | - SET16(s, port); | ||
| 850 | - | ||
| 851 | -#if defined(X3270_TRACE) | ||
| 852 | - trace_dsn(hSession,"SOCKS5 Proxy: xmit version 5 connect %s %s port %u\n", | ||
| 853 | - use_name? "domainname": | ||
| 854 | - ((ha.sa.sa_family == AF_INET)? "IPv4": "IPv6"), | ||
| 855 | - use_name? host: nbuf, | ||
| 856 | - port); | ||
| 857 | - trace_netdata(hSession, '>', (unsigned char *)buf, s - buf); | ||
| 858 | -#endif | ||
| 859 | - | ||
| 860 | - if (send(fd, buf, s - buf, 0) < 0) { | ||
| 861 | - popup_a_sockerr(hSession,_("SOCKS5 Proxy: send error")); | ||
| 862 | - lib3270_free(buf); | ||
| 863 | - return -1; | ||
| 864 | - } | ||
| 865 | - lib3270_free(buf); | ||
| 866 | - | ||
| 867 | - // | ||
| 868 | - // Process the reply. | ||
| 869 | - // Only the first two bytes of the response are interesting; | ||
| 870 | - // skip the rest. | ||
| 871 | - // | ||
| 872 | - nread = 0; | ||
| 873 | - done = 0; | ||
| 874 | - buf = NULL; | ||
| 875 | - while (!done) | ||
| 876 | - { | ||
| 877 | - fd_set rfds; | ||
| 878 | - struct timeval tv; | ||
| 879 | - unsigned char r; | ||
| 880 | - | ||
| 881 | - FD_ZERO(&rfds); | ||
| 882 | - FD_SET(fd, &rfds); | ||
| 883 | - tv.tv_sec = 15; | ||
| 884 | - tv.tv_usec = 0; | ||
| 885 | - if (select(fd + 1, &rfds, NULL, NULL, &tv) < 0) | ||
| 886 | - { | ||
| 887 | - popup_an_error(hSession,_("SOCKS5 Proxy: server timeout")); | ||
| 888 | - return -1; | ||
| 889 | - } | ||
| 890 | - | ||
| 891 | - nr = recv(fd, (char *) &r, 1, 0); | ||
| 892 | - if (nr < 0) | ||
| 893 | - { | ||
| 894 | - popup_a_sockerr(hSession,_("SOCKS5 Proxy: receive error")); | ||
| 895 | -#if defined(X3270_TRACE) | ||
| 896 | - if (nread) | ||
| 897 | - trace_netdata(hSession, '<', (unsigned char *)buf, nread); | ||
| 898 | -#endif | ||
| 899 | - return -1; | ||
| 900 | - } | ||
| 901 | - if (nr == 0) | ||
| 902 | - { | ||
| 903 | - popup_an_error(hSession, _("SOCKS5 Proxy: unexpected EOF")); | ||
| 904 | -#if defined(X3270_TRACE) | ||
| 905 | - if (nread) | ||
| 906 | - trace_netdata(hSession, '<', (unsigned char *)buf, nread); | ||
| 907 | -#endif | ||
| 908 | - return -1; | ||
| 909 | - } | ||
| 910 | - | ||
| 911 | - buf = Realloc(buf, nread + 1); | ||
| 912 | - buf[nread] = r; | ||
| 913 | - | ||
| 914 | - switch (nread++) { | ||
| 915 | - case 0: | ||
| 916 | - if (r != 0x05) | ||
| 917 | - { | ||
| 918 | - popup_an_error(hSession, _("SOCKS5 Proxy: incorrect reply version 0x%02x"), r); | ||
| 919 | -#if defined(X3270_TRACE) | ||
| 920 | - if (nread) | ||
| 921 | - trace_netdata(hSession, '<', (unsigned char *)buf, nread); | ||
| 922 | -#endif | ||
| 923 | - return -1; | ||
| 924 | - } | ||
| 925 | - break; | ||
| 926 | - case 1: | ||
| 927 | -#if defined(X3270_TRACE) | ||
| 928 | - if (r != 0x00) | ||
| 929 | - trace_netdata(hSession, '<', (unsigned char *)buf, nread); | ||
| 930 | -#endif | ||
| 931 | - switch (r) | ||
| 932 | - { | ||
| 933 | - case 0x00: | ||
| 934 | - break; | ||
| 935 | - case 0x01: | ||
| 936 | - popup_an_error(hSession, _("SOCKS5 Proxy: server failure")); | ||
| 937 | - return -1; | ||
| 938 | - case 0x02: | ||
| 939 | - popup_an_error(hSession, _("SOCKS5 Proxy: connection not allowed")); | ||
| 940 | - return -1; | ||
| 941 | - case 0x03: | ||
| 942 | - popup_an_error(hSession, _("SOCKS5 Proxy: network unreachable")); | ||
| 943 | - return -1; | ||
| 944 | - case 0x04: | ||
| 945 | - popup_an_error(hSession, _("SOCKS5 Proxy: host unreachable")); | ||
| 946 | - return -1; | ||
| 947 | - case 0x05: | ||
| 948 | - popup_an_error(hSession, _("SOCKS5 Proxy: connection refused")); | ||
| 949 | - return -1; | ||
| 950 | - case 0x06: | ||
| 951 | - popup_an_error(hSession, _("SOCKS5 Proxy: ttl expired")); | ||
| 952 | - return -1; | ||
| 953 | - case 0x07: | ||
| 954 | - popup_an_error(hSession, _("SOCKS5 Proxy: command not supported")); | ||
| 955 | - return -1; | ||
| 956 | - case 0x08: | ||
| 957 | - popup_an_error(hSession, _("SOCKS5 Proxy: address type not supported")); | ||
| 958 | - return -1; | ||
| 959 | - default: | ||
| 960 | - popup_an_error(hSession, _("SOCKS5 Proxy: unknown server error 0x%02x"), r); | ||
| 961 | - return -1; | ||
| 962 | - } | ||
| 963 | - break; | ||
| 964 | - | ||
| 965 | - case 2: | ||
| 966 | - break; | ||
| 967 | - case 3: | ||
| 968 | - switch (r) | ||
| 969 | - { | ||
| 970 | - case 0x01: | ||
| 971 | - n2read = 6; | ||
| 972 | - break; | ||
| 973 | - case 0x03: | ||
| 974 | - n2read = -1; | ||
| 975 | - break; | ||
| 976 | -#if defined(AF_INET6) | ||
| 977 | - case 0x04: | ||
| 978 | - n2read = sizeof(struct in6_addr) + 2; | ||
| 979 | - break; | ||
| 980 | -#endif | ||
| 981 | - default: | ||
| 982 | - popup_an_error(hSession, _("SOCKS5 Proxy: unknown server address type 0x%02x"), r); | ||
| 983 | -#if defined(X3270_TRACE) | ||
| 984 | - if (nread) | ||
| 985 | - trace_netdata(hSession, '<', (unsigned char *)buf, nread); | ||
| 986 | -#endif | ||
| 987 | - return -1; | ||
| 988 | - } | ||
| 989 | - break; | ||
| 990 | - default: | ||
| 991 | - if (n2read == -1) | ||
| 992 | - n2read = r + 2; | ||
| 993 | - else if (!--n2read) | ||
| 994 | - done = 1; | ||
| 995 | - break; | ||
| 996 | - } | ||
| 997 | - } | ||
| 998 | - | ||
| 999 | -#if defined(X3270_TRACE) | ||
| 1000 | - trace_netdata(hSession, '<', (unsigned char *)buf, nread); | ||
| 1001 | - switch (buf[3]) { | ||
| 1002 | - case 0x01: // IPv4 | ||
| 1003 | - memcpy(&ha.sin.sin_addr, &buf[4], 4); | ||
| 1004 | - strcpy(nbuf, inet_ntoa(ha.sin.sin_addr)); | ||
| 1005 | - portp = (unsigned char *)&buf[4 + 4]; | ||
| 1006 | - break; | ||
| 1007 | - case 0x03: // domainname | ||
| 1008 | - strncpy(nbuf, &buf[5], buf[4]); | ||
| 1009 | - nbuf[(unsigned char)buf[4]] = '\0'; | ||
| 1010 | - portp = (unsigned char *)&buf[5 + (unsigned char)buf[4]]; | ||
| 1011 | - break; | ||
| 1012 | -#if defined(AF_INET6) | ||
| 1013 | - case 0x04: // IPv6 | ||
| 1014 | - memcpy(&ha.sin6.sin6_addr, &buf[4], sizeof(struct in6_addr)); | ||
| 1015 | - (void) inet_ntop(AF_INET6, &ha.sin6.sin6_addr, nbuf, | ||
| 1016 | - sizeof(nbuf)); | ||
| 1017 | - portp = (unsigned char *)&buf[4 + sizeof(struct in6_addr)]; | ||
| 1018 | - break; | ||
| 1019 | -#endif | ||
| 1020 | - default: | ||
| 1021 | - // can't happen | ||
| 1022 | - nbuf[0] = '\0'; | ||
| 1023 | - portp = (unsigned char *)buf; | ||
| 1024 | - break; | ||
| 1025 | - } | ||
| 1026 | - rport = (*portp << 8) + *(portp + 1); | ||
| 1027 | - trace_dsn(hSession,"SOCKS5 Proxy: recv version %d status 0x%02x address %s %s port %u\n", | ||
| 1028 | - buf[0], buf[1], | ||
| 1029 | - atype_name[(unsigned char)buf[3]], | ||
| 1030 | - nbuf, | ||
| 1031 | - rport); | ||
| 1032 | -#endif | ||
| 1033 | - lib3270_free(buf); | ||
| 1034 | - | ||
| 1035 | - return 0; | ||
| 1036 | -} | ||
| 1037 | -*/ |
| @@ -0,0 +1,8 @@ | @@ -0,0 +1,8 @@ | ||
| 1 | +char *build = "@PACKAGE_TARNAME@ v@PACKAGE_VERSION@ @RPQ_BUILD_DATE@ @SCCS_USER@"; | ||
| 2 | +char *app_defaults_version = "@PACKAGE_VERSION@"; | ||
| 3 | +char *sccsid = "@(#)@PACKAGE_TARNAME@ v@PACKAGE_VERSION@ @SCCS_DATE@ @SCCS_USER@"; | ||
| 4 | + | ||
| 5 | +const char *build_rpq_timestamp = "@RPQ_TIMESTAMP@"; | ||
| 6 | +const char *build_rpq_version = "@PACKAGE_VERSION@"; | ||
| 7 | +const char *build_rpq_revision = "@RPQ_REVISION@"; | ||
| 8 | + |