mirror of
https://github.com/proxytunnel/proxytunnel.git
synced 2026-01-23 02:34:59 +00:00
Reformatted sourcecode.
git-svn-id: https://proxytunnel.svn.sourceforge.net/svnroot/proxytunnel/trunk/proxytunnel@203 bc163920-b10d-0410-b2c5-a5491ca2ceef
This commit is contained in:
parent
3b12106e03
commit
4ab2eb5b48
16 changed files with 171 additions and 177 deletions
3
Makefile
3
Makefile
|
|
@ -58,11 +58,12 @@ OBJ = proxytunnel.o \
|
|||
base64.o \
|
||||
strlcpy.o \
|
||||
strlcat.o \
|
||||
strzcat.o \
|
||||
setproctitle.o \
|
||||
io.o \
|
||||
http.o \
|
||||
basicauth.o \
|
||||
readpassphrase.o \
|
||||
readpassphrase.o \
|
||||
messages.o \
|
||||
cmdline.o \
|
||||
ntlm.o \
|
||||
|
|
|
|||
29
base64.c
29
base64.c
|
|
@ -41,9 +41,7 @@ static const char base64val[] = {
|
|||
#define DECODE64(c) (isascii(c) ? base64val[c] : BAD)
|
||||
|
||||
|
||||
/*
|
||||
* Small MAX macro
|
||||
*/
|
||||
/* Small MAX macro */
|
||||
#ifndef MAX
|
||||
#define MAX( x, y ) ( ( (x)>(y) ) ? (x) : (y) )
|
||||
#endif
|
||||
|
|
@ -62,8 +60,7 @@ static const char base64val[] = {
|
|||
*/
|
||||
|
||||
/* raw bytes to null-terminated base 64 string */
|
||||
void base64(unsigned char *out, const unsigned char *in, int len)
|
||||
{
|
||||
void base64(unsigned char *out, const unsigned char *in, int len) {
|
||||
while (len >= 3) {
|
||||
*out++ = base64digits[in[0] >> 2];
|
||||
*out++ = base64digits[((in[0] << 4) & 0x30) | (in[1] >> 4)];
|
||||
|
|
@ -88,17 +85,16 @@ void base64(unsigned char *out, const unsigned char *in, int len)
|
|||
*out = '\0';
|
||||
}
|
||||
|
||||
int unbase64(unsigned char *out, const unsigned char *in, int maxlen)
|
||||
/* base 64 to raw bytes in quasi-big-endian order, returning count of bytes */
|
||||
/* maxlen limits output buffer size, set to zero to ignore */
|
||||
{
|
||||
int unbase64(unsigned char *out, const unsigned char *in, int maxlen) {
|
||||
int len = 0;
|
||||
register unsigned char digit1, digit2, digit3, digit4;
|
||||
|
||||
if (in[0] == '+' && in[1] == ' ')
|
||||
in += 2;
|
||||
in += 2;
|
||||
if (*in == '\r')
|
||||
return(0);
|
||||
return(0);
|
||||
|
||||
do {
|
||||
digit1 = in[0];
|
||||
|
|
@ -118,22 +114,19 @@ int unbase64(unsigned char *out, const unsigned char *in, int maxlen)
|
|||
if (maxlen && len > maxlen)
|
||||
return(-1);
|
||||
*out++ = (DECODE64(digit1) << 2) | (DECODE64(digit2) >> 4);
|
||||
if (digit3 != '=')
|
||||
{
|
||||
if (digit3 != '=') {
|
||||
++len;
|
||||
if (maxlen && len > maxlen)
|
||||
return(-1);
|
||||
*out++ = ((DECODE64(digit2) << 4) & 0xf0) | (DECODE64(digit3) >> 2);
|
||||
if (digit4 != '=')
|
||||
{
|
||||
if (digit4 != '=') {
|
||||
++len;
|
||||
if (maxlen && len > maxlen)
|
||||
return(-1);
|
||||
*out++ = ((DECODE64(digit3) << 6) & 0xc0) | DECODE64(digit4);
|
||||
if (maxlen && len > maxlen)
|
||||
return(-1);
|
||||
*out++ = ((DECODE64(digit3) << 6) & 0xc0) | DECODE64(digit4);
|
||||
}
|
||||
}
|
||||
} while
|
||||
(*in && *in != '\r' && digit4 != '=');
|
||||
} while (*in && *in != '\r' && digit4 != '=');
|
||||
|
||||
return (len);
|
||||
}
|
||||
|
|
|
|||
10
basicauth.c
10
basicauth.c
|
|
@ -31,14 +31,11 @@
|
|||
* Create the HTTP basic authentication cookie for use by the proxy. Result
|
||||
* is stored in basicauth.
|
||||
*/
|
||||
void make_basicauth()
|
||||
{
|
||||
void make_basicauth() {
|
||||
int len = strlen( args_info.user_arg ) + strlen( args_info.pass_arg ) + 2;
|
||||
char *p = (char *) malloc( len );
|
||||
|
||||
/*
|
||||
* Set up the cookie in clear text
|
||||
*/
|
||||
/* Set up the cookie in clear text */
|
||||
sprintf( p, "%s:%s", args_info.user_arg, args_info.pass_arg );
|
||||
|
||||
/*
|
||||
|
|
@ -47,8 +44,7 @@ void make_basicauth()
|
|||
*/
|
||||
base64( (unsigned char *)basicauth, (unsigned char *)p, strlen( p ) );
|
||||
|
||||
// if( args_info.verbose_flag )
|
||||
// {
|
||||
// if( args_info.verbose_flag ) {
|
||||
// message( "Proxy basic auth is %s\n", basicauth );
|
||||
// }
|
||||
|
||||
|
|
|
|||
87
cmdline.c
87
cmdline.c
|
|
@ -29,7 +29,7 @@
|
|||
#include "proxytunnel.h"
|
||||
|
||||
#ifndef HAVE_GETOPT_LONG
|
||||
extern char * optarg;
|
||||
extern char * optarg;
|
||||
#else
|
||||
#include <getopt.h>
|
||||
#endif
|
||||
|
|
@ -37,16 +37,12 @@
|
|||
#include "cmdline.h"
|
||||
static char *getCredentialsFromFile( const char* filename, char **user, char **pwd);
|
||||
|
||||
void
|
||||
cmdline_parser_print_version (void)
|
||||
{
|
||||
void cmdline_parser_print_version (void) {
|
||||
printf ("%s %s (rev %d)\nCopyright 2001-2008 Proxytunnel Project\n%s\n", PACKAGE, VERSION, REV, AUTHORS);
|
||||
}
|
||||
|
||||
void
|
||||
cmdline_parser_print_help (void)
|
||||
{
|
||||
// cmdline_parser_print_version ();
|
||||
void cmdline_parser_print_help (void) {
|
||||
// cmdline_parser_print_version ();
|
||||
printf(
|
||||
"Usage: %s [OPTIONS]...\n"
|
||||
"Build generic tunnels trough HTTPS proxy's, supports HTTP authorization\n"
|
||||
|
|
@ -91,14 +87,11 @@ cmdline_parser_print_help (void)
|
|||
}
|
||||
|
||||
|
||||
static char *
|
||||
gengetopt_strdup (char * s)
|
||||
{
|
||||
static char * gengetopt_strdup (char * s) {
|
||||
char * n, * pn, * ps = s;
|
||||
while (*ps) ps++;
|
||||
n = (char *) malloc (1 + ps - s);
|
||||
if (n != NULL)
|
||||
{
|
||||
if (n != NULL) {
|
||||
for (ps=s,pn=n; *ps; ps++,pn++)
|
||||
*pn = *ps;
|
||||
*pn = 0;
|
||||
|
|
@ -106,11 +99,9 @@ gengetopt_strdup (char * s)
|
|||
return n;
|
||||
}
|
||||
|
||||
int
|
||||
cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *args_info )
|
||||
{
|
||||
int c; /* Character of the parsed option. */
|
||||
int r; /* Tmd retval */
|
||||
int cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *args_info ) {
|
||||
int c; /* Character of the parsed option. */
|
||||
int r; /* Tmd retval */
|
||||
int missing_required_options = 0;
|
||||
char * tmp_env_var;
|
||||
|
||||
|
|
@ -171,24 +162,24 @@ cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *args_i
|
|||
/* Struct option: Name, Has_arg, Flag, Value */
|
||||
static struct option long_options[] = {
|
||||
{ "help", 0, NULL, 'h' },
|
||||
{ "version", 0, NULL, 'V' },
|
||||
{ "version", 0, NULL, 'V' },
|
||||
{ "user", 1, NULL, 'u' },
|
||||
{ "pass", 1, NULL, 's' },
|
||||
{ "domain", 1, NULL, 't' },
|
||||
{ "uservar", 1, NULL, 'U' },
|
||||
{ "passvar", 1, NULL, 'S' },
|
||||
{ "passfile", 1, NULL, 'F' },
|
||||
{ "uservar", 1, NULL, 'U' },
|
||||
{ "passvar", 1, NULL, 'S' },
|
||||
{ "passfile", 1, NULL, 'F' },
|
||||
{ "proxy", 1, NULL, 'p' },
|
||||
{ "dest", 1, NULL, 'd' },
|
||||
{ "remproxy", 1, NULL, 'r' },
|
||||
{ "proctitle", 1, NULL, 'x' },
|
||||
{ "remproxy", 1, NULL, 'r' },
|
||||
{ "proctitle", 1, NULL, 'x' },
|
||||
{ "header", 1, NULL, 'H' },
|
||||
{ "verbose", 0, NULL, 'v' },
|
||||
{ "verbose", 0, NULL, 'v' },
|
||||
{ "ntlm", 0, NULL, 'N' },
|
||||
{ "inetd", 0, NULL, 'i' },
|
||||
{ "standalone", 1, NULL, 'a' },
|
||||
{ "standalone", 1, NULL, 'a' },
|
||||
{ "quiet", 0, NULL, 'q' },
|
||||
{ "encrypt", 0, NULL, 'e' },
|
||||
{ "encrypt", 0, NULL, 'e' },
|
||||
{ "encrypt-proxy", 0, NULL, 'E' },
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
|
|
@ -258,7 +249,7 @@ cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *args_i
|
|||
if (args_info->user_given) {
|
||||
fprintf (stderr, "%s: `--user' (`-u'), `--uservar' (`-U') or `--passfile' (`-F') option given more than once\n", PACKAGE);
|
||||
clear_args ();
|
||||
exit (1);
|
||||
exit(1);
|
||||
}
|
||||
args_info->user_given = 1;
|
||||
args_info->user_arg = gengetopt_strdup (optarg);
|
||||
|
|
@ -268,13 +259,13 @@ cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *args_i
|
|||
if (args_info->user_given) {
|
||||
fprintf (stderr, "%s: `--user' (`-u'), `--uservar' (`-U') or `--passfile' (`-F') option given more than once\n", PACKAGE);
|
||||
clear_args ();
|
||||
exit (1);
|
||||
exit(1);
|
||||
}
|
||||
tmp_env_var = getenv(optarg) ;
|
||||
if (!tmp_env_var) {
|
||||
fprintf (stderr, "%s Invalid environment variable\n", optarg) ;
|
||||
clear_args ();
|
||||
exit (1);
|
||||
exit(1);
|
||||
}
|
||||
args_info->user_given = 1;
|
||||
args_info->user_arg = gengetopt_strdup (tmp_env_var);
|
||||
|
|
@ -284,7 +275,7 @@ cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *args_i
|
|||
if (args_info->pass_given) {
|
||||
fprintf (stderr, "%s: `--pass' (`-s'), `--passvar' (`-S') or `--passfile' (`-F') option given more than once\n", PACKAGE);
|
||||
clear_args ();
|
||||
exit (1);
|
||||
exit(1);
|
||||
}
|
||||
args_info->pass_given = 1;
|
||||
args_info->pass_arg = gengetopt_strdup (optarg);
|
||||
|
|
@ -294,7 +285,7 @@ cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *args_i
|
|||
if (args_info->domain_given) {
|
||||
fprintf (stderr, "%s: `--domain' (`-t') option given more than once\n", PACKAGE);
|
||||
clear_args ();
|
||||
exit (1);
|
||||
exit(1);
|
||||
}
|
||||
args_info->domain_given = 1;
|
||||
args_info->domain_arg = gengetopt_strdup (optarg);
|
||||
|
|
@ -304,29 +295,29 @@ cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *args_i
|
|||
if (args_info->pass_given) {
|
||||
fprintf (stderr, "%s: `--pass' (`-s') or `--passvar' (`-S') option given more than once\n", PACKAGE);
|
||||
clear_args ();
|
||||
exit (1);
|
||||
exit(1);
|
||||
}
|
||||
tmp_env_var = getenv(optarg) ;
|
||||
if (!tmp_env_var) {
|
||||
fprintf (stderr, "%s Invalid environment variable\n", optarg) ;
|
||||
clear_args ();
|
||||
exit (1);
|
||||
exit(1);
|
||||
}
|
||||
args_info->pass_given = 1;
|
||||
args_info->pass_arg = gengetopt_strdup (tmp_env_var);
|
||||
break;
|
||||
|
||||
case 'F': /* File containing Username & Password to send to
|
||||
case 'F': /* File containing Username & Password to send to
|
||||
HTTPS proxy for authentication. */
|
||||
if (args_info->user_given) {
|
||||
fprintf (stderr, "%s: `--user' (`-u'), `--uservar' (`-U') or `--passfile' (`-F') option given more than once\n", PACKAGE);
|
||||
clear_args ();
|
||||
exit (1);
|
||||
exit(1);
|
||||
}
|
||||
if (args_info->pass_given) {
|
||||
fprintf (stderr, "%s: `--pass' (`-s'), `--passvar' (`-S') or `--passfile' (`-F') option given more than once\n", PACKAGE);
|
||||
clear_args ();
|
||||
exit (1);
|
||||
exit(1);
|
||||
}
|
||||
args_info->user_given = 1;
|
||||
args_info->pass_given = 1;
|
||||
|
|
@ -335,7 +326,7 @@ cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *args_i
|
|||
if( result != NULL ) {
|
||||
fprintf( stderr, "%s: Bad password file for `--passfile' (`-F')\n%s\n", PACKAGE, result);
|
||||
clear_args();
|
||||
exit (1);
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -343,7 +334,7 @@ cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *args_i
|
|||
if (args_info->proxy_given) {
|
||||
fprintf (stderr, "%s: `--proxy' (`-p') option given more than once\n", PACKAGE);
|
||||
clear_args ();
|
||||
exit (1);
|
||||
exit(1);
|
||||
}
|
||||
args_info->proxy_given = 1;
|
||||
args_info->proxy_arg = gengetopt_strdup (optarg);
|
||||
|
|
@ -353,7 +344,7 @@ cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *args_i
|
|||
if (args_info->remproxy_given) {
|
||||
fprintf (stderr, "%s: `--remproxy' (`-r') option given more than once\n", PACKAGE);
|
||||
clear_args ();
|
||||
exit (1);
|
||||
exit(1);
|
||||
}
|
||||
args_info->remproxy_given = 1;
|
||||
args_info->remproxy_arg = gengetopt_strdup (optarg);
|
||||
|
|
@ -363,20 +354,19 @@ cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *args_i
|
|||
if (args_info->dest_given) {
|
||||
fprintf (stderr, "%s: `--dest' (`-d') option given more than once\n", PACKAGE);
|
||||
clear_args ();
|
||||
exit (1);
|
||||
exit(1);
|
||||
}
|
||||
args_info->dest_given = 1;
|
||||
args_info->dest_arg = gengetopt_strdup (optarg);
|
||||
break;
|
||||
|
||||
case 'H': /* Extra headers to send to HTTPS proxy. */
|
||||
args_info->header_given++; /* Amount of extra headers */
|
||||
strlcat( args_info->header_arg, optarg, MAX_HEADER_SIZE );
|
||||
strlcat( args_info->header_arg, "\r\n", MAX_HEADER_SIZE );
|
||||
args_info->header_given++;
|
||||
strzcat( args_info->header_arg, "%s\r\n", optarg);
|
||||
break;
|
||||
|
||||
case 'v': /* Turn on verbosity. */
|
||||
if (args_info->quiet_flag) { /* -q also on cmd line */
|
||||
if (args_info->quiet_flag) { /* -q also on cmd line */
|
||||
fprintf (stderr, "-v and -q are mutually exclusive\n");
|
||||
clear_args();
|
||||
exit(1);
|
||||
|
|
@ -397,7 +387,7 @@ cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *args_i
|
|||
case '?': /* Invalid option. */
|
||||
/* `getopt_long' already printed an error message. */
|
||||
clear_args();
|
||||
exit (1);
|
||||
exit(1);
|
||||
|
||||
default: /* bug: option not considered. */
|
||||
fprintf (stderr, "%s: option unknown: %c\n", PACKAGE, c);
|
||||
|
|
@ -438,13 +428,12 @@ cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *args_i
|
|||
}
|
||||
|
||||
if ( missing_required_options )
|
||||
exit (1);
|
||||
exit(1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char *
|
||||
getCredentialsFromFile( const char* filename, char **user, char **pwd ) {
|
||||
static char *getCredentialsFromFile( const char* filename, char **user, char **pwd ) {
|
||||
/* Check file permissions, must have '0' for group and other */
|
||||
struct stat statbuf;
|
||||
if ( stat( filename, &statbuf ) == 0 ) {
|
||||
|
|
|
|||
28
cmdline.h
28
cmdline.h
|
|
@ -26,31 +26,31 @@
|
|||
#define MAX_HEADER_SIZE 1024
|
||||
|
||||
struct gengetopt_args_info {
|
||||
char * user_arg; /* Username to send to HTTPS proxy for auth. */
|
||||
char * pass_arg; /* Password to send to HTTPS proxy for auth. */
|
||||
char * domain_arg; /* NTLM Domain override */
|
||||
char * proxy_arg; /* HTTPS Proxy host to connect to. */
|
||||
char * proxyhost_arg; /* HTTPS Proxy host to connect to. */
|
||||
char *user_arg; /* Username to send to HTTPS proxy for auth. */
|
||||
char *pass_arg; /* Password to send to HTTPS proxy for auth. */
|
||||
char *domain_arg; /* NTLM Domain override */
|
||||
char *proxy_arg; /* HTTPS Proxy host to connect to. */
|
||||
char *proxyhost_arg; /* HTTPS Proxy host to connect to. */
|
||||
int proxyport_arg; /* HTTPS Proxy host portnumber to connect to. */
|
||||
char * dest_arg; /* Destination host to built the tunnel to. */
|
||||
char *dest_arg; /* Destination host to built the tunnel to. */
|
||||
char header_arg[MAX_HEADER_SIZE]; /* Extra headers to send to proxy */
|
||||
char * remproxy_arg; /* Remote proxy to tunnel to. */
|
||||
char *remproxy_arg; /* Remote proxy to tunnel to. */
|
||||
int verbose_flag; /* Turn on verbosity (default=off). */
|
||||
int ntlm_flag; /* Turn on ntlm (default=off). */
|
||||
int inetd_flag; /* Turn on inetd (default=off). */
|
||||
int quiet_flag; /* Turn on quiet mode (default=off). */
|
||||
int standalone_arg; /* Turn on stdalone (-a) on port */
|
||||
int encrypt_flag; /* Turn on SSL encryption (default=off). */
|
||||
int encryptproxy_flag; /* Turn on client to proxy SSL encryption .*/
|
||||
char * proctitle_arg; /* Override process title (default=off). */
|
||||
int encryptproxy_flag; /* Turn on client to proxy SSL encryption (def=off).*/
|
||||
char *proctitle_arg; /* Override process title (default=off). */
|
||||
int help_given; /* Whether help was given. */
|
||||
int version_given; /* Whether version was given. */
|
||||
int user_given; /* Whether user was given. */
|
||||
int pass_given; /* Whether pass was given. */
|
||||
int domain_given; /* Whether domain was given. */
|
||||
int proxy_given; /* Whether proxyhost was given. */
|
||||
int proxyhost_given; /* Whether proxyhost was given. */
|
||||
int proxyport_given; /* Whether proxyport was given. */
|
||||
int proxyhost_given; /* Whether proxyhost was given. */
|
||||
int proxyport_given; /* Whether proxyport was given. */
|
||||
int dest_given; /* Whether dest was given. */
|
||||
int remproxy_given; /* Whether remproxy was given. */
|
||||
int verbose_given; /* Whether verbose was given. */
|
||||
|
|
@ -59,9 +59,9 @@ struct gengetopt_args_info {
|
|||
int quiet_given; /* Whether quiet mode was given. */
|
||||
int header_given; /* Whether extra headers are given */
|
||||
int encrypt_given; /* Whether encrypt was given */
|
||||
int encryptproxy_given; /* Whether encrypt was given */
|
||||
int proctitle_given; /* Whether to override process title */
|
||||
} ;
|
||||
int encryptproxy_given; /* Whether encrypt was given */
|
||||
int proctitle_given; /* Whether to override process title */
|
||||
};
|
||||
|
||||
int cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *args_info );
|
||||
|
||||
|
|
|
|||
9
config.h
9
config.h
|
|
@ -17,16 +17,17 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#define VERSION "1.8.0"
|
||||
#define PACKAGE "proxytunnel"
|
||||
#define VERSION "1.8.0"
|
||||
#define PACKAGE "proxytunnel"
|
||||
#define PURPOSE "Build generic tunnels through HTTPS proxies"
|
||||
#define AUTHORS "Jos Visser (Muppet) <josv@osp.nl>, Mark Janssen (Maniac) <maniac@maniac.nl>"
|
||||
|
||||
#ifndef _PATH_TTY
|
||||
# define _PATH_TTY "/dev/tty"
|
||||
#define _PATH_TTY "/dev/tty"
|
||||
#endif
|
||||
|
||||
#ifndef _PASSWORD_LEN
|
||||
# define _PASSWORD_LEN 80
|
||||
#define _PASSWORD_LEN 80
|
||||
#endif
|
||||
|
||||
// vim:noet
|
||||
|
|
|
|||
12
http.c
12
http.c
|
|
@ -96,18 +96,6 @@ void print_line_prefix(char *buf, char *prefix) {
|
|||
// message( "%s: '%s\n", prefix, buf );
|
||||
}
|
||||
|
||||
/*
|
||||
* Append an variable number of strings together
|
||||
*/
|
||||
size_t strzcat(char *strz, char *fmt, ...) {
|
||||
int offset = strlen(strz);
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
size_t dlen = vsnprintf(&strz[offset], SIZE-offset, fmt, ap);
|
||||
va_end(ap);
|
||||
return dlen+offset;
|
||||
}
|
||||
|
||||
/*
|
||||
* Execute the basic proxy protocol of CONNECT and response, until the
|
||||
* last line of the response has been read. The tunnel is then open.
|
||||
|
|
|
|||
16
io.c
16
io.c
|
|
@ -35,9 +35,9 @@
|
|||
* newline character. Result is stored in buf.
|
||||
*/
|
||||
int readline(PTSTREAM *pts) {
|
||||
char *p = buf;
|
||||
char c = 0;
|
||||
int i = 0;
|
||||
char *p = buf;
|
||||
char c = 0;
|
||||
int i = 0;
|
||||
|
||||
/* Read one character at a time into buf, until a newline is encountered. */
|
||||
while ( c != 10 && ( i < SIZE - 1 ) ) {
|
||||
|
|
@ -54,8 +54,8 @@ int readline(PTSTREAM *pts) {
|
|||
*p = 0;
|
||||
|
||||
if( args_info.verbose_flag ) {
|
||||
/* Copy line of data into dstr without trailing newline */
|
||||
char * dstr = malloc(sizeof(buf) + 1);
|
||||
/* Copy line of data into dstr without trailing newline */
|
||||
char *dstr = malloc(sizeof(buf) + 1);
|
||||
strlcpy( dstr, buf, strlen(buf) - 1);
|
||||
if (strcmp(dstr, ""))
|
||||
message( " <- %s\n", dstr );
|
||||
|
|
@ -74,12 +74,11 @@ void cpio(PTSTREAM *stream1, PTSTREAM *stream2) {
|
|||
int in_max_fd, out_max_fd, max_fd;
|
||||
|
||||
/* Find the biggest file descriptor for select() */
|
||||
|
||||
in_max_fd = MAX(stream_get_incoming_fd(stream1), stream_get_incoming_fd(stream2));
|
||||
out_max_fd = MAX(stream_get_outgoing_fd(stream1), stream_get_outgoing_fd(stream2));
|
||||
max_fd = MAX(in_max_fd, out_max_fd);
|
||||
|
||||
/* We're never interested in sockets being available for write. */
|
||||
/* We are never interested in sockets being available for write */
|
||||
FD_ZERO( &writefds );
|
||||
|
||||
if( args_info.verbose_flag )
|
||||
|
|
@ -117,8 +116,7 @@ void cpio(PTSTREAM *stream1, PTSTREAM *stream2) {
|
|||
if ( FD_ISSET( stream_get_incoming_fd(stream1), &readfds ) ) {
|
||||
if ( stream_copy(stream1, stream2 ) )
|
||||
break;
|
||||
}
|
||||
else if( FD_ISSET( stream_get_incoming_fd(stream2), &readfds ) ) {
|
||||
} else if( FD_ISSET( stream_get_incoming_fd(stream2), &readfds ) ) {
|
||||
if( stream_copy(stream2, stream1 ) )
|
||||
break;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@
|
|||
* Give a message to the user
|
||||
*/
|
||||
void message( char *s, ... ) {
|
||||
va_list ap;
|
||||
char buf[1024];
|
||||
va_list ap;
|
||||
char buf[1024];
|
||||
|
||||
va_start( ap, s );
|
||||
vsnprintf( (char *)buf, sizeof( buf ), s, ap );
|
||||
|
|
|
|||
8
ntlm.c
8
ntlm.c
|
|
@ -118,8 +118,9 @@ int parse_type2(unsigned char *buf) {
|
|||
for (i = 0; i < t2->target_name.length / sp; i++)
|
||||
domain[i] = t2_buf[t2->target_name.offset + i * sp];
|
||||
domain[i] = 0;
|
||||
} else
|
||||
} else {
|
||||
domain[0] = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
challenge[i] = t2->challenge[i];
|
||||
|
|
@ -258,7 +259,6 @@ unsigned char digest[16]; /* caller digest to be filled in */
|
|||
MD5_Init( &tctx );
|
||||
MD5_Update( &tctx, key, key_len );
|
||||
MD5_Final( tk, &tctx );
|
||||
|
||||
key = tk;
|
||||
key_len = 16;
|
||||
}
|
||||
|
|
@ -335,9 +335,7 @@ void build_ntlm2_response() {
|
|||
message("NTLM: MD4 of password is: ");
|
||||
for( i = 0; i < 16; i++)
|
||||
message("%02X", passdigest[i]);
|
||||
message("\n");
|
||||
|
||||
message("DOMAIN: %s\nUSER: %s\n", domain, args_info.user_arg);
|
||||
message("\nDOMAIN: %s\nUSER: %s\n", domain, args_info.user_arg);
|
||||
}
|
||||
|
||||
userdomlen = sizeof(unsigned char) * (strlen(args_info.user_arg) + strlen(domain)) * 2;
|
||||
|
|
|
|||
|
|
@ -70,9 +70,7 @@ int tunnel_connect() {
|
|||
struct hostent *he;
|
||||
int sd;
|
||||
|
||||
/*
|
||||
* Create the socket
|
||||
*/
|
||||
/* Create the socket */
|
||||
if( ( sd = socket( AF_INET, SOCK_STREAM, 0 ) ) < 0 ) {
|
||||
my_perror("Can not create socket");
|
||||
exit(1);
|
||||
|
|
@ -80,14 +78,15 @@ int tunnel_connect() {
|
|||
|
||||
/* Lookup the IP address of the proxy */
|
||||
if( ! ( he = gethostbyname( args_info.proxyhost_arg ) ) ) {
|
||||
// FIXME: my_perror("Local proxy %s could not be resolved", args_info.proxyhost_arg);
|
||||
my_perror("Local proxy could not be resolved." );
|
||||
exit(1);
|
||||
}
|
||||
|
||||
char ip[16];
|
||||
snprintf(ip, 16, "%d.%d.%d.%d", he->h_addr[0] & 255, he->h_addr[1] & 255, he->h_addr[2] & 255, he->h_addr[3] & 255);
|
||||
if( args_info.verbose_flag && strcmp(args_info.proxyhost_arg, ip)) {
|
||||
message( "Local proxy %s resolves to %d.%d.%d.%d\n",
|
||||
if( args_info.verbose_flag && strcmp(args_info.proxyhost_arg, ip)) {
|
||||
message( "Local proxy %s resolves to %d.%d.%d.%d\n",
|
||||
args_info.proxyhost_arg,
|
||||
he->h_addr[0] & 255,
|
||||
he->h_addr[1] & 255,
|
||||
|
|
@ -100,13 +99,20 @@ int tunnel_connect() {
|
|||
sa.sin_family = AF_INET;
|
||||
memcpy( &sa.sin_addr.s_addr, he->h_addr, 4);
|
||||
sa.sin_port = htons( args_info.proxyport_arg );
|
||||
|
||||
|
||||
/* Connect the socket */
|
||||
if( connect( sd, (struct sockaddr*) &sa, sizeof( sa ) ) < 0 ) {
|
||||
my_perror("connect() failed");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Increase interactivity of tunnel, patch by Ingo Molnar */
|
||||
int flag = 1;
|
||||
setsockopt( sd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int));
|
||||
|
||||
/* Make sure we get warned when someone hangs up on us */
|
||||
signal(SIGHUP,signal_handler);
|
||||
|
||||
if( ! args_info.quiet_flag ) {
|
||||
if ( ! args_info.verbose_flag ) {
|
||||
if ( args_info.remproxy_given ) {
|
||||
|
|
@ -124,15 +130,6 @@ int tunnel_connect() {
|
|||
}
|
||||
}
|
||||
|
||||
{ /* Increase interactivity of tunnel, patch by Ingo Molnar */
|
||||
int flag = 1;
|
||||
setsockopt( sd, IPPROTO_TCP, TCP_NODELAY,
|
||||
(char *)&flag, sizeof(int));
|
||||
}
|
||||
|
||||
/* Make sure we get warned when someone hangs up on us */
|
||||
signal(SIGHUP,signal_handler);
|
||||
|
||||
/* Return the socket */
|
||||
return sd;
|
||||
}
|
||||
|
|
@ -141,21 +138,20 @@ int tunnel_connect() {
|
|||
/* Leave a goodbye message */
|
||||
void closeall() {
|
||||
#ifndef CYGWIN
|
||||
closelog();
|
||||
closelog();
|
||||
#endif
|
||||
|
||||
/* Close all streams */
|
||||
if (stunnel)
|
||||
{
|
||||
if (stunnel) {
|
||||
stream_close(stunnel);
|
||||
stunnel = NULL;
|
||||
}
|
||||
if (std)
|
||||
{
|
||||
|
||||
if (std) {
|
||||
stream_close(std);
|
||||
std = NULL;
|
||||
}
|
||||
if( args_info.verbose_flag )
|
||||
{
|
||||
if( args_info.verbose_flag ) {
|
||||
message( "Tunnel closed.\n" );
|
||||
}
|
||||
}
|
||||
|
|
@ -251,12 +247,12 @@ void do_daemon()
|
|||
(struct sockaddr *)&sa_cli, &client_len );
|
||||
|
||||
if ( sd_client < 0 ) {
|
||||
my_perror( "accept() failed. Bailing out..." );
|
||||
exit(1);
|
||||
my_perror( "accept() failed. Bailing out..." );
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ( ( pid = fork() ) < 0 ) {
|
||||
my_perror( "Cannot fork worker" );
|
||||
my_perror( "Cannot fork worker" );
|
||||
} else if ( pid == 0 ) {
|
||||
read_fd = write_fd = sd_client;
|
||||
|
||||
|
|
@ -350,8 +346,9 @@ int main( int argc, char *argv[] ) {
|
|||
build_type1();
|
||||
if ( args_info.verbose_flag )
|
||||
message("Build Type 1 NTLM Message : %s\n", ntlm_type1_buf);
|
||||
} else
|
||||
} else {
|
||||
make_basicauth();
|
||||
}
|
||||
}
|
||||
|
||||
/* Only one of -E (SSL encrypt client to proxy connection) or
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ void initsetproctitle(int argc, char *argv[]);
|
|||
void setproctitle(const char *fmt, ...);
|
||||
size_t strlcat(char *dst, const char *src, size_t siz);
|
||||
size_t strlcpy(char *dst, const char *src, size_t siz);
|
||||
size_t strzcat(char *dst, char *format, ...);
|
||||
int main( int argc, char *argv[] );
|
||||
char * readpassphrase(const char *, char *, size_t, int);
|
||||
char * getpass_x(const char *prompt);
|
||||
|
|
|
|||
20
ptstream.c
20
ptstream.c
|
|
@ -29,10 +29,7 @@
|
|||
#include "proxytunnel.h"
|
||||
|
||||
|
||||
/*
|
||||
* Open a stream for incoming and outgoing data with the specified fds
|
||||
*/
|
||||
|
||||
/* Open a stream for incoming and outgoing data with the specified fds */
|
||||
PTSTREAM *stream_open(int incoming_fd, int outgoing_fd) {
|
||||
PTSTREAM *pts;
|
||||
|
||||
|
|
@ -42,22 +39,19 @@ PTSTREAM *stream_open(int incoming_fd, int outgoing_fd) {
|
|||
pts->outgoing_fd = outgoing_fd;
|
||||
pts->ssl = NULL;
|
||||
pts->ctx = NULL;
|
||||
|
||||
|
||||
/* Return a pointer to the structure */
|
||||
return pts;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Close a stream
|
||||
*/
|
||||
|
||||
/* Close a stream */
|
||||
int stream_close(PTSTREAM *pts) {
|
||||
/* Destroy the SSL context */
|
||||
if (pts->ssl) {
|
||||
#ifdef USE_SSL
|
||||
SSL_shutdown (pts->ssl);
|
||||
SSL_free (pts->ssl);
|
||||
SSL_shutdown (pts->ssl);
|
||||
SSL_free (pts->ssl);
|
||||
SSL_CTX_free (pts->ctx);
|
||||
#endif /* USE_SSL */
|
||||
}
|
||||
|
|
@ -76,7 +70,6 @@ int stream_close(PTSTREAM *pts) {
|
|||
|
||||
|
||||
/* Read from a stream */
|
||||
|
||||
int stream_read(PTSTREAM *pts, void *buf, size_t len) {
|
||||
/* Read up to the specified number of bytes into the buffer */
|
||||
int bytes_read;
|
||||
|
|
@ -98,7 +91,7 @@ int stream_read(PTSTREAM *pts, void *buf, size_t len) {
|
|||
}
|
||||
|
||||
|
||||
/* * Write to a stream */
|
||||
/* Write to a stream */
|
||||
int stream_write(PTSTREAM *pts, void *buf, size_t len) {
|
||||
/* Write the specified number of bytes from the buffer */
|
||||
int bytes_written;
|
||||
|
|
@ -193,7 +186,6 @@ int stream_get_incoming_fd(PTSTREAM *pts) {
|
|||
|
||||
/* Return the outgoing_fd for a given stream */
|
||||
int stream_get_outgoing_fd(PTSTREAM *pts) {
|
||||
|
||||
if (!pts->ssl)
|
||||
return pts->outgoing_fd;
|
||||
else
|
||||
|
|
|
|||
|
|
@ -70,8 +70,7 @@ static volatile sig_atomic_t signo;
|
|||
|
||||
static void handler(int);
|
||||
|
||||
char *
|
||||
readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags) {
|
||||
char * readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags) {
|
||||
ssize_t nr;
|
||||
int input, output, save_errno;
|
||||
char ch, *p, *end;
|
||||
|
|
@ -191,11 +190,9 @@ restart:
|
|||
errno = save_errno;
|
||||
return(nr == -1 ? NULL : buf);
|
||||
}
|
||||
|
||||
char *
|
||||
getpass_x(const char *prompt) {
|
||||
static char buf[_PASSWORD_LEN + 1];
|
||||
|
||||
char * getpass_x(const char *prompt) {
|
||||
static char buf[_PASSWORD_LEN + 1];
|
||||
return(readpassphrase(prompt, buf, sizeof(buf), RPP_ECHO_OFF));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,15 +49,15 @@
|
|||
#include <unistd.h>
|
||||
#ifdef HAVE_SYS_PSTAT_H
|
||||
#include <sys/pstat.h>
|
||||
#define SPT_TYPE SPT_PSTAT
|
||||
#define SPT_TYPE SPT_PSTAT
|
||||
#endif
|
||||
|
||||
#ifndef SPT_TYPE
|
||||
# define SPT_TYPE SPT_NONE
|
||||
# define SPT_TYPE SPT_NONE
|
||||
#endif
|
||||
|
||||
#ifndef SPT_PADCHAR
|
||||
# define SPT_PADCHAR '\0'
|
||||
# define SPT_PADCHAR '\0'
|
||||
#endif
|
||||
|
||||
#if SPT_TYPE == SPT_REUSEARGV
|
||||
|
|
@ -119,8 +119,7 @@ void initsetproctitle(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
#ifndef HAVE_SETPROCTITLE
|
||||
void
|
||||
setproctitle(const char *fmt, ...) {
|
||||
void setproctitle(const char *fmt, ...) {
|
||||
#if SPT_TYPE != SPT_NONE
|
||||
va_list ap;
|
||||
char buf[1024];
|
||||
|
|
@ -135,14 +134,13 @@ setproctitle(const char *fmt, ...) {
|
|||
return;
|
||||
#endif
|
||||
|
||||
if( args_info.proctitle_given )
|
||||
if( args_info.proctitle_given ) {
|
||||
strlcpy(buf, args_info.proctitle_arg, sizeof(buf));
|
||||
else {
|
||||
} else {
|
||||
strlcpy(buf, __progname, sizeof(buf));
|
||||
strlcat(buf, ": ", sizeof(buf));
|
||||
}
|
||||
|
||||
|
||||
va_start(ap, fmt);
|
||||
if (fmt != NULL) {
|
||||
len = strlen(buf);
|
||||
|
|
@ -155,8 +153,7 @@ setproctitle(const char *fmt, ...) {
|
|||
pst.pst_command = buf;
|
||||
pstat(PSTAT_SETCMD, pst, strlen(buf), 0, 0);
|
||||
#elif SPT_TYPE == SPT_REUSEARGV
|
||||
/* message("setproctitle: copy \"%s\" into len %d",
|
||||
buf, argv_env_len); */
|
||||
// message("setproctitle: copy \"%s\" into len %d", buf, argv_env_len);
|
||||
len = strlcpy(argv_start, buf, argv_env_len);
|
||||
for(; len < argv_env_len; len++)
|
||||
argv_start[len] = SPT_PADCHAR;
|
||||
|
|
|
|||
46
strzcat.c
Normal file
46
strzcat.c
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
|
||||
/*
|
||||
* Copyright (c) 2008 Dag Wieers <dag@wieers.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#ifndef HAVE_STRZCAT
|
||||
|
||||
#define STRZCAT_SIZE 65535
|
||||
|
||||
/*
|
||||
* Append an variable number of strings together
|
||||
*/
|
||||
size_t strzcat(char *dst, char *format, ...) {
|
||||
// FIXME: Implement similar boundary checks as strlcat
|
||||
|
||||
int offset = strlen(dst);
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
size_t dlen = vsnprintf(&dst[offset], STRZCAT_SIZE-offset, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
return ( dlen+offset );
|
||||
}
|
||||
|
||||
#endif /* !HAVE_STRZCAT */
|
||||
Loading…
Add table
Add a link
Reference in a new issue