ssh-http-proxy-connect.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
* Copyright 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* An http client that let's users 'ssh' to the
* outside of the firewall by opening up a connection
* through the http proxy.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <netdb.h>
#include <strings.h>
#include <unistd.h>
#include <inttypes.h>
#include <errno.h>
#include <poll.h>
#include <signal.h>
#include <locale.h>
#include <libintl.h>
#include "proxy-io.h"
#define DEFAULT_HTTPPROXYPORT "80"
#define CONNECT_STRLEN 256
static int debug_flag = 0;
static void
usage(void)
{
"[-h http_proxy_host] [-p http_proxy_port]\n"
"remote_host remote_port\n"));
exit(1);
}
/* PRINTFLIKE1 */
static void
{
char fmtbuf[BUFFER_SIZ];
if (debug_flag == 0) {
return;
}
"ssh-http-proxy: %s\n", format);
}
static void
signal_handler(int sig)
{
exit(0);
}
int
{
extern char *optarg;
extern int optind;
char *ssh_host;
char *ret_string;
/* Initialization for variables, set locale and textdomain */
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#endif
(void) textdomain(TEXT_DOMAIN);
/* Set up the signal handler */
switch (retval) {
case 'h':
break;
case 'p':
break;
case 'd':
debug_flag = 1;
break;
default:
break;
}
}
usage();
}
/*
* If the name of the http proxy were not
* passed on the command line, try the
* user's environment. First try HTTPPROXY.
* If it's not set, try http_proxy.
* Check the url specified for http_proxy
* for errors.
*/
/* Try the other environment variable http_proxy */
/* Malformed url */
"Incorrect url specified for http_proxy "
"environment variable\n"));
exit(1);
}
} else {
gettext("ssh-http-proxy: http proxy not specified\n"));
exit(1);
}
}
}
/*
* Extract the proxy port number from the user's environment.
* Ignored if HTTPPROXY is not set.
*/
}
}
!= 0) {
"perform name lookup\n");
exit(1);
}
perror("socket");
exit(1);
}
/* Connect to the http proxy */
exit(1);
} else {
/* Successful connection. */
perror("write");
exit(1);
}
perror("read");
exit(1);
}
gettext("ssh-http-proxy: HTTP reply not understood\n"));
exit(1);
}
/* If the return error code is not 200, print an error and quit. */
if (ret_code != 200) {
exit(1);
} else {
}
}
for (;;) {
perror("poll");
exit(1);
}
/* Data arrived on stdin, write it to the socket */
exit(1);
}
exit(1);
}
/* Data arrived on the socket, write it to stdout */
exit(1);
}
exit(1);
}
}
/* NOTREACHED */
return (0);
}