diff -purN vtun-3.0.3/auth.c vtun/auth.c --- vtun-3.0.3/auth.c 2009-05-15 11:23:39.000000000 +0400 +++ vtun/auth.c 2013-07-07 23:54:20.000000000 +0400 @@ -17,7 +17,7 @@ */ /* - * $Id: auth.c,v 1.9.2.4 2009/04/24 09:15:33 mtbishop Exp $ + * $Id: auth.c,v 1.9.2.5 2013/07/07 19:54:20 mtbishop Exp $ */ /* @@ -62,12 +62,12 @@ #include #include -void gen_chal(char *buf) +static void gen_chal(char *buf) { RAND_bytes(buf, VTUN_CHAL_SIZE); } -void encrypt_chal(char *chal, char *pwd) +static void encrypt_chal(char *chal, char *pwd) { register int i; BF_KEY key; @@ -78,7 +78,7 @@ void encrypt_chal(char *chal, char *pwd) BF_ecb_encrypt(chal + i, chal + i, &key, BF_ENCRYPT); } -void decrypt_chal(char *chal, char *pwd) +static void decrypt_chal(char *chal, char *pwd) { register int i; BF_KEY key; @@ -91,7 +91,7 @@ void decrypt_chal(char *chal, char *pwd) #else /* HAVE_SSL */ -void encrypt_chal(char *chal, char *pwd) +static void encrypt_chal(char *chal, char *pwd) { char * xor_msk = pwd; register int i, xor_len = strlen(xor_msk); @@ -100,13 +100,13 @@ void encrypt_chal(char *chal, char *pwd) chal[i] ^= xor_msk[i%xor_len]; } -void inline decrypt_chal(char *chal, char *pwd) +static void inline decrypt_chal(char *chal, char *pwd) { encrypt_chal(chal, pwd); } /* Generate PSEUDO random challenge key. */ -void gen_chal(char *buf) +static void gen_chal(char *buf) { register int i; @@ -123,7 +123,7 @@ void gen_chal(char *buf) * C - compression, S - speed for shaper and so on. */ -char *bf2cf(struct vtun_host *host) +static char *bf2cf(struct vtun_host *host) { static char str[20], *ptr = str; @@ -187,7 +187,7 @@ char *bf2cf(struct vtun_host *host) FLAGS: */ -int cf2bf(char *str, struct vtun_host *host) +static int cf2bf(char *str, struct vtun_host *host) { char *ptr, *p; int s; @@ -277,7 +277,7 @@ int cf2bf(char *str, struct vtun_host *h * string format: */ -char *cl2cs(char *chal) +static char *cl2cs(char *chal) { static char str[VTUN_CHAL_SIZE*2+3], *chr="abcdefghijklmnop"; register char *ptr = str; @@ -295,7 +295,7 @@ char *cl2cs(char *chal) return str; } -int cs2cl(char *str, char *chal) +static int cs2cl(char *str, char *chal) { register char *ptr = str; register int i; diff -purN vtun-3.0.3/cfg_file.y vtun/cfg_file.y --- vtun-3.0.3/cfg_file.y 2012-07-09 05:01:08.000000000 +0400 +++ vtun/cfg_file.y 2013-07-08 00:36:33.000000000 +0400 @@ -18,7 +18,7 @@ */ /* - * $Id: cfg_file.y,v 1.8.2.6 2012/07/09 01:01:08 mtbishop Exp $ + * $Id: cfg_file.y,v 1.8.2.7 2013/07/07 20:36:33 mtbishop Exp $ */ #include "config.h" @@ -107,6 +107,7 @@ statement: '\n' memcpy(parse_host, &default_host, sizeof(struct vtun_host)); parse_host->host = strdup($1); parse_host->passwd = NULL; + parse_host->sopt.host = strdup($1); /* Copy local address */ copy_addr(parse_host, &default_host); diff -purN vtun-3.0.3/ChangeLog vtun/ChangeLog --- vtun-3.0.3/ChangeLog 2012-07-09 05:10:17.000000000 +0400 +++ vtun/ChangeLog 2013-07-08 00:24:07.000000000 +0400 @@ -1,3 +1,10 @@ + +-.-.- + bug53 - Race condition in socket() vs syslog (AH) + patch23 - check for fork and work around lack (AM) + patch22 - static declarations where possible (AM) + patch21 - fix up configure.in for newer autoheader (AM) + 3.0.3: rfe2636157 - Delayed UDP connection (dv) rfe2149137 - makefile ignores LDFLAGS (sbk) diff -purN vtun-3.0.3/configure.in vtun/configure.in --- vtun-3.0.3/configure.in 2009-03-29 14:08:51.000000000 +0400 +++ vtun/configure.in 2013-07-07 23:54:28.000000000 +0400 @@ -2,12 +2,12 @@ dnl dnl VTun - Virtual Tunnel over TCP/IP network. dnl Copyright (C) 1998-2006 Maxim Krasnyansky dnl -dnl $Id: configure.in,v 1.19.2.2 2009/03/29 10:08:51 mtbishop Exp $ +dnl $Id: configure.in,v 1.19.2.3 2013/07/07 19:54:28 mtbishop Exp $ dnl dnl Process this file with autoconf to produce a configure script. dnl -AC_INIT(lib.c) +AC_INIT(vtun, 3) dnl this needs to change via variables as in the tail AC_CONFIG_HEADER(config.h) dnl Shapper support @@ -110,10 +110,13 @@ dnl Check for librt AC_SEARCH_LIBS(nanosleep, rt posix4) dnl Check for setproctitle in libutil -AC_SEARCH_LIBS(setproctitle, util bsd, AC_DEFINE(HAVE_SETPROC_TITLE) ) +AC_SEARCH_LIBS(setproctitle, util bsd, AC_DEFINE(HAVE_SETPROC_TITLE, [1], [Define to 1 if you have setproctitle() function]) ) + +dnl Check for fork() (fallback to vfork() on non-MMU systems) +AC_FUNC_FORK if test "$SHAPER" = "yes"; then - AC_DEFINE(HAVE_SHAPER) + AC_DEFINE(HAVE_SHAPER, [1], [Define to 1 if you want to enable shaper module]) fi if test "$ZLIB" = "yes"; then @@ -121,7 +124,7 @@ if test "$ZLIB" = "yes"; then AC_CHECKING( for ZLIB Library and Header files ... ) AC_CHECK_LIB(z, deflate, LIBS="$LIBS -lz" - AC_DEFINE(HAVE_ZLIB), + AC_DEFINE(HAVE_ZLIB, [1], [Define to 1 if you have zlib]), AC_MSG_ERROR( Zlib library not found.) ) fi @@ -148,7 +151,7 @@ if test "$LZO" = "yes"; then AC_CHECK_LIB($I, lzo1x_decompress, [ LIBS="$LIBS -l"$I - AC_DEFINE(HAVE_LZO) + AC_DEFINE(HAVE_LZO, [1], [Define to 1 if you have lzo]) havelzo=1 ] ) @@ -180,8 +183,8 @@ if test "$SSL" = "yes"; then AC_CHECK_LIB(crypto, BF_set_key, [ LIBS="$LIBS -lcrypto" - AC_DEFINE(HAVE_SSL) - AC_DEFINE(HAVE_SSL_BLOWFISH) + AC_DEFINE(HAVE_SSL, [1], [Define to 1 if you have openssl]) + AC_DEFINE(HAVE_SSL_BLOWFISH, [1], [Define to 1 if you have blowfish in openssl]) ], AC_MSG_ERROR( SSL library not found. ) ), @@ -196,7 +199,7 @@ if test "$SSL" = "yes"; then $SSL_HDR_DIR /usr/include/ssl /usr/include/openssl /usr/include /usr/local/include /usr/local/ssl/include /usr/include/crypto, AC_CHECK_LIB(crypto, AES_set_encrypt_key, [ - AC_DEFINE(HAVE_SSL_AES) + AC_DEFINE(HAVE_SSL_AES, [1], [Define to 1 if you have AES in openssl]) ], AC_MSG_ERROR( AES library not found. ) ), @@ -211,7 +214,7 @@ if test "$SSL" = "yes"; then $SSL_HDR_DIR /usr/include/ssl /usr/include/openssl /usr/include /usr/local/include /usr/local/ssl/include /usr/include/crypto, AC_CHECK_LIB(crypto, EVP_EncryptInit, [ - AC_DEFINE(HAVE_SSL_EVP) + AC_DEFINE(HAVE_SSL_EVP, [1], [Define to 1 if you have EVP in openssl]) ], AC_MSG_ERROR( EVP library not found. ) ), @@ -220,7 +223,7 @@ if test "$SSL" = "yes"; then fi if test "$NATHACK" = "yes"; then - AC_DEFINE(ENABLE_NAT_HACK) + AC_DEFINE(ENABLE_NAT_HACK, [1], [Define to 1 if you want to enable Nat Hack code]) fi if test "$SOCKS" = "yes"; then @@ -274,6 +277,6 @@ changequote(<,>) REL=`echo 'BRANCH-3_X' | tr -d '$: \-' | sed 's/^[A-Za-z]*//' | sed 's/\_/\./'` changequote([,]) -AC_DEFINE_UNQUOTED(VTUN_VER, "$REL `date '+%m/%d/%Y'`") +AC_DEFINE_UNQUOTED(VTUN_VER, "$REL `date '+%m/%d/%Y'`", [Vtun version]) AC_OUTPUT(Makefile) diff -purN vtun-3.0.3/Credits vtun/Credits --- vtun-3.0.3/Credits 2012-07-08 09:32:07.000000000 +0400 +++ vtun/Credits 2013-07-08 00:24:11.000000000 +0400 @@ -159,3 +159,11 @@ Eugene Berdnikov Sean MacLennan Reduce connection chatter + +Andrey Mazo + Clean up Configure.in for autoheader + Static declarations where sensible + Check/handle no fork() for no-MMU client systems (eg blackfin) + +Alfred Heisner + Race condition between syslog socket and vtun (bug53) diff -purN vtun-3.0.3/driver.h vtun/driver.h --- vtun-3.0.3/driver.h 2008-01-08 01:35:30.000000000 +0300 +++ vtun/driver.h 2013-07-08 00:36:37.000000000 +0400 @@ -17,14 +17,14 @@ */ /* - * $Id: driver.h,v 1.4.2.2 2008/01/07 22:35:30 mtbishop Exp $ + * $Id: driver.h,v 1.4.2.3 2013/07/07 20:36:37 mtbishop Exp $ */ #ifndef _DRIVER_H #define _DRIVER_H /* Definitions for device and protocol drivers * Interface will be completely rewritten in - * version 3.0 + * future versions. */ extern int (*dev_write)(int fd, char *buf, int len); diff -purN vtun-3.0.3/lfd_encrypt.c vtun/lfd_encrypt.c --- vtun-3.0.3/lfd_encrypt.c 2008-01-08 01:35:32.000000000 +0300 +++ vtun/lfd_encrypt.c 2013-07-07 23:54:35.000000000 +0400 @@ -64,16 +64,16 @@ #define ENC_BUF_SIZE VTUN_FRAME_SIZE + 128 #define ENC_KEY_SIZE 16 -BF_KEY key; -char * enc_buf; -char * dec_buf; +static BF_KEY key; +static char * enc_buf; +static char * dec_buf; #define CIPHER_INIT 0 #define CIPHER_CODE 1 #define CIPHER_SEQUENCE 2 #define CIPHER_REQ_INIT 3 -struct vtun_host *phost; +static struct vtun_host *phost; extern int send_a_packet; @@ -81,27 +81,32 @@ extern int send_a_packet; #define MAX_GIBBERISH 10 #define MIN_GIBBERISH 1 #define MAX_GIBBERISH_TIME 2 -int gibberish; -time_t gib_time_start; +static int gibberish; +static time_t gib_time_start; -int cipher_enc_state; -int cipher_dec_state; -int cipher; -int blocksize; -int keysize; -int enc_init_first_time; -int dec_init_first_time; -unsigned long sequence_num; -char * pkey; -char * iv_buf; +static int cipher_enc_state; +static int cipher_dec_state; +static int cipher; +static int blocksize; +static int keysize; +static int enc_init_first_time; +static int dec_init_first_time; +static unsigned long sequence_num; +static char * pkey; +static char * iv_buf; + +static EVP_CIPHER_CTX ctx_enc; /* encrypt */ +static EVP_CIPHER_CTX ctx_dec; /* decrypt */ + +static EVP_CIPHER_CTX ctx_enc_ecb; /* sideband ecb encrypt */ +static EVP_CIPHER_CTX ctx_dec_ecb; /* sideband ecb decrypt */ + +static int send_msg(int len, char *in, char **out); +static int recv_msg(int len, char *in, char **out); +static int send_ib_mesg(int *len, char **in); +static int recv_ib_mesg(int *len, char **in); -EVP_CIPHER_CTX ctx_enc; /* encrypt */ -EVP_CIPHER_CTX ctx_dec; /* decrypt */ - -EVP_CIPHER_CTX ctx_enc_ecb; /* sideband ecb encrypt */ -EVP_CIPHER_CTX ctx_dec_ecb; /* sideband ecb decrypt */ - -int prep_key(char **key, int size, struct vtun_host *host) +static int prep_key(char **key, int size, struct vtun_host *host) { int tmplen, halflen; char *hashkey; @@ -136,12 +141,12 @@ int prep_key(char **key, int size, struc return 0; } -void free_key (char *key) +static void free_key (char *key) { free(key); } -int alloc_encrypt(struct vtun_host *host) +static int alloc_encrypt(struct vtun_host *host) { int sb_init = 0; int var_key = 0; @@ -282,7 +287,7 @@ int alloc_encrypt(struct vtun_host *host return 0; } -int free_encrypt() +static int free_encrypt() { free_key(pkey); pkey = NULL; @@ -297,7 +302,7 @@ int free_encrypt() return 0; } -int encrypt_buf(int len, char *in, char **out) +static int encrypt_buf(int len, char *in, char **out) { register int pad, p, msg_len; int outlen; @@ -326,7 +331,7 @@ int encrypt_buf(int len, char *in, char return outlen+msg_len; } -int decrypt_buf(int len, char *in, char **out) +static int decrypt_buf(int len, char *in, char **out) { register int pad; char *tmp_ptr, *in_ptr, *out_ptr = dec_buf; @@ -351,7 +356,7 @@ int decrypt_buf(int len, char *in, char return outlen - pad; } -int cipher_enc_init(char * iv) +static int cipher_enc_init(char * iv) { int var_key = 0; const EVP_CIPHER *cipher_type; @@ -442,7 +447,7 @@ int cipher_enc_init(char * iv) return 0; } -int cipher_dec_init(char * iv) +static int cipher_dec_init(char * iv) { int var_key = 0; const EVP_CIPHER *cipher_type; @@ -532,7 +537,7 @@ int cipher_dec_init(char * iv) return 0; } -int send_msg(int len, char *in, char **out) +static int send_msg(int len, char *in, char **out) { char * iv; char * in_ptr; int outlen; @@ -570,7 +575,7 @@ int send_msg(int len, char *in, char **o return len; } -int recv_msg(int len, char *in, char **out) +static int recv_msg(int len, char *in, char **out) { char * iv; char * in_ptr; int outlen; @@ -645,7 +650,7 @@ int recv_msg(int len, char *in, char **o } /* Send In-Band Message */ -int send_ib_mesg(int *len, char **in) +static int send_ib_mesg(int *len, char **in) { char *in_ptr = *in; @@ -684,7 +689,7 @@ int send_ib_mesg(int *len, char **in) } /* Receive In-Band Message */ -int recv_ib_mesg(int *len, char **in) +static int recv_ib_mesg(int *len, char **in) { char *in_ptr = *in; @@ -747,7 +752,7 @@ struct lfd_mod lfd_encrypt = { #else /* HAVE_SSL */ -int no_encrypt(struct vtun_host *host) +static int no_encrypt(struct vtun_host *host) { vtun_syslog(LOG_INFO, "Encryption is not supported"); return -1; diff -purN vtun-3.0.3/lfd_legacy_encrypt.c vtun/lfd_legacy_encrypt.c --- vtun-3.0.3/lfd_legacy_encrypt.c 2008-01-08 01:35:33.000000000 +0300 +++ vtun/lfd_legacy_encrypt.c 2013-07-07 23:54:41.000000000 +0400 @@ -17,7 +17,7 @@ */ /* - * $Id: lfd_legacy_encrypt.c,v 1.1.4.2 2008/01/07 22:35:33 mtbishop Exp $ + * $Id: lfd_legacy_encrypt.c,v 1.1.4.3 2013/07/07 19:54:41 mtbishop Exp $ * Code added wholesale temporarily from lfd_encrypt 1.2.2.8 */ @@ -61,10 +61,10 @@ #define ENC_BUF_SIZE VTUN_FRAME_SIZE + 16 #define ENC_KEY_SIZE 16 -BF_KEY key; -char * enc_buf; +static BF_KEY key; +static char * enc_buf; -int alloc_legacy_encrypt(struct vtun_host *host) +static int alloc_legacy_encrypt(struct vtun_host *host) { if( !(enc_buf = lfd_alloc(ENC_BUF_SIZE)) ){ vtun_syslog(LOG_ERR,"Can't allocate buffer for legacy encryptor"); @@ -77,13 +77,13 @@ int alloc_legacy_encrypt(struct vtun_hos return 0; } -int free_legacy_encrypt() +static int free_legacy_encrypt() { lfd_free(enc_buf); enc_buf = NULL; return 0; } -int legacy_encrypt_buf(int len, char *in, char **out) +static int legacy_encrypt_buf(int len, char *in, char **out) { register int pad, p; register char *in_ptr = in, *out_ptr = enc_buf; @@ -105,7 +105,7 @@ int legacy_encrypt_buf(int len, char *in return len + 8; } -int legacy_decrypt_buf(int len, char *in, char **out) +static int legacy_decrypt_buf(int len, char *in, char **out) { register int p; @@ -140,7 +140,7 @@ struct lfd_mod lfd_legacy_encrypt = { #else /* HAVE_SSL */ -int no_legacy_encrypt(struct vtun_host *host) +static int no_legacy_encrypt(struct vtun_host *host) { vtun_syslog(LOG_INFO, "Encryption is not supported"); return -1; diff -purN vtun-3.0.3/lfd_lzo.c vtun/lfd_lzo.c --- vtun-3.0.3/lfd_lzo.c 2012-07-09 05:01:08.000000000 +0400 +++ vtun/lfd_lzo.c 2013-07-07 23:54:44.000000000 +0400 @@ -17,7 +17,7 @@ */ /* - * $Id: lfd_lzo.c,v 1.5.2.5 2012/07/09 01:01:08 mtbishop Exp $ + * $Id: lfd_lzo.c,v 1.5.2.6 2013/07/07 19:54:44 mtbishop Exp $ */ /* LZO compression module */ @@ -44,7 +44,7 @@ static lzo_voidp wmem; static int zbuf_size = VTUN_FRAME_SIZE * VTUN_FRAME_SIZE / 64 + 16 + 3; /* Pointer to compress function */ -int (*lzo1x_compress)(const lzo_byte *src, lzo_uint src_len, +static int (*lzo1x_compress)(const lzo_byte *src, lzo_uint src_len, lzo_byte *dst, lzo_uint *dst_len, lzo_voidp wrkmem); /* @@ -52,7 +52,7 @@ int (*lzo1x_compress)(const lzo_byte *sr * Allocate the buffers. */ -int alloc_lzo(struct vtun_host *host) +static int alloc_lzo(struct vtun_host *host) { int zlevel = host->zlevel ? host->zlevel : 1; lzo_uint mem; @@ -91,7 +91,7 @@ int alloc_lzo(struct vtun_host *host) * Free the buffer. */ -int free_lzo() +static int free_lzo() { lfd_free(zbuf); zbuf = NULL; lzo_free(wmem); wmem = NULL; @@ -102,7 +102,7 @@ int free_lzo() * This functions _MUST_ consume all incoming bytes in one pass, * that's why we expand buffer dynamicly. */ -int comp_lzo(int len, char *in, char **out) +static int comp_lzo(int len, char *in, char **out) { lzo_uint zlen = 0; int err; @@ -116,7 +116,7 @@ int comp_lzo(int len, char *in, char **o return zlen; } -int decomp_lzo(int len, char *in, char **out) +static int decomp_lzo(int len, char *in, char **out) { lzo_uint zlen = 0; int err; @@ -144,7 +144,7 @@ struct lfd_mod lfd_lzo = { #else /* HAVE_LZO */ -int no_lzo(struct vtun_host *host) +static int no_lzo(struct vtun_host *host) { vtun_syslog(LOG_INFO, "LZO compression is not supported"); return -1; diff -purN vtun-3.0.3/lfd_shaper.c vtun/lfd_shaper.c --- vtun-3.0.3/lfd_shaper.c 2008-01-08 01:35:36.000000000 +0300 +++ vtun/lfd_shaper.c 2013-07-07 23:54:48.000000000 +0400 @@ -17,7 +17,7 @@ */ /* - * $Id: lfd_shaper.c,v 1.7.2.2 2008/01/07 22:35:36 mtbishop Exp $ + * $Id: lfd_shaper.c,v 1.7.2.3 2013/07/07 19:54:48 mtbishop Exp $ */ #include "config.h" @@ -38,13 +38,13 @@ #ifdef HAVE_SHAPER -unsigned long bytes, max_speed; -struct timeval curr_time, last_time; +static unsigned long bytes, max_speed; +static struct timeval curr_time, last_time; /* * Initialization function. */ -int shaper_init(struct vtun_host *host) +static int shaper_init(struct vtun_host *host) { /* Calculate max speed bytes/sec */ max_speed = host->spd_out / 8 * 1024; @@ -59,7 +59,7 @@ int shaper_init(struct vtun_host *host) } /* Shaper counter */ -int shaper_counter(int len, char *in, char **out) +static int shaper_counter(int len, char *in, char **out) { /* Just count incoming bytes */ bytes += len; @@ -69,7 +69,7 @@ int shaper_counter(int len, char *in, ch } /* Convert tv struct to milisec */ -unsigned long inline tv2ms(struct timeval tv) +static unsigned long inline tv2ms(struct timeval tv) { register unsigned long ms = (tv.tv_sec * 1000)+(tv.tv_usec / 1000); return ms ? ms : 1; @@ -94,7 +94,7 @@ unsigned long inline tv2ms(struct timeva * higher than maximal speed stop accepting input * until the speed become lower or equal to maximal. */ -int shaper_avail(void) +static int shaper_avail(void) { static struct timeval tv; register unsigned long speed; @@ -144,7 +144,7 @@ struct lfd_mod lfd_shaper = { #else /* HAVE_SHAPER */ -int no_shaper(struct vtun_host *host) +static int no_shaper(struct vtun_host *host) { vtun_syslog(LOG_INFO, "Traffic shaping is not supported"); return -1; diff -purN vtun-3.0.3/lfd_zlib.c vtun/lfd_zlib.c --- vtun-3.0.3/lfd_zlib.c 2008-01-08 01:35:38.000000000 +0300 +++ vtun/lfd_zlib.c 2013-07-07 23:54:52.000000000 +0400 @@ -17,7 +17,7 @@ */ /* - * $Id: lfd_zlib.c,v 1.5.2.2 2008/01/07 22:35:38 mtbishop Exp $ + * $Id: lfd_zlib.c,v 1.5.2.3 2013/07/07 19:54:52 mtbishop Exp $ */ /* ZLIB compression module */ @@ -45,7 +45,7 @@ static int zbuf_size = VTUN_FRAME_SIZE + * Initialize compressor/decompressor. * Allocate the buffer. */ -int zlib_alloc(struct vtun_host *host) +static int zlib_alloc(struct vtun_host *host) { int zlevel = host->zlevel ? host->zlevel : 1; @@ -78,7 +78,7 @@ int zlib_alloc(struct vtun_host *host) * Free the buffer. */ -int zlib_free() +static int zlib_free() { deflateEnd(&zd); inflateEnd(&zi); @@ -104,7 +104,7 @@ static int expand_zbuf(z_stream *zs, int * That's why we expand buffer dynamically. * Practice shows that buffer will not grow larger that 16K. */ -int zlib_comp(int len, char *in, char **out) +static int zlib_comp(int len, char *in, char **out) { int oavail, olen = 0; int err; @@ -133,7 +133,7 @@ int zlib_comp(int len, char *in, char ** return olen; } -int zlib_decomp(int len, char *in, char **out) +static int zlib_decomp(int len, char *in, char **out) { int oavail = 0, olen = 0; int err; @@ -175,7 +175,7 @@ struct lfd_mod lfd_zlib = { #else /* HAVE_ZLIB */ -int no_zlib(struct vtun_host *host) +static int no_zlib(struct vtun_host *host) { vtun_syslog(LOG_INFO, "ZLIB compression is not supported"); return -1; diff -purN vtun-3.0.3/lib.c vtun/lib.c --- vtun-3.0.3/lib.c 2008-01-08 01:35:40.000000000 +0300 +++ vtun/lib.c 2013-07-08 00:21:20.000000000 +0400 @@ -17,7 +17,7 @@ */ /* - * $Id: lib.c,v 1.9.2.2 2008/01/07 22:35:40 mtbishop Exp $ + * $Id: lib.c,v 1.9.2.4 2013/07/07 20:21:20 mtbishop Exp $ */ #include "config.h" @@ -45,9 +45,9 @@ volatile sig_atomic_t __io_canceled = 0; /* Functions to manipulate with program title */ extern char **environ; -char *title_start; /* start of the proc title space */ -char *title_end; /* end of the proc title space */ -int title_size; +static char *title_start; /* start of the proc title space */ +static char *title_end; /* end of the proc title space */ +static int title_size; void init_title(int argc,char *argv[], char *envp[], char *name) { @@ -148,7 +148,7 @@ int readn_t(int fd, void *buf, size_t co * Substitutes opt in place off '%X'. * Returns new string. */ -char * subst_opt(char *str, struct vtun_sopt *opt) +static char * subst_opt(char *str, struct vtun_sopt *opt) { register int slen, olen, sp, np; register char *optr, *nstr, *tmp; @@ -185,6 +185,9 @@ char * subst_opt(char *str, struct vtun_ sprintf(buf,"%d",opt->rport); optr=buf; break; + case 'h': + optr=opt->host; + break; default: sp++; continue; @@ -223,7 +226,7 @@ char * subst_opt(char *str, struct vtun_ * ' ' - group arguments * Modifies original string. */ -void split_args(char *str, char **argv) +static void split_args(char *str, char **argv) { register int i = 0; int mode = 0; @@ -276,6 +279,7 @@ void split_args(char *str, char **argv) argv[i]=NULL; } +#ifdef HAVE_WORKING_FORK int run_cmd(void *d, void *opt) { struct vtun_cmd *cmd = d; @@ -324,6 +328,7 @@ int run_cmd(void *d, void *opt) vtun_syslog(LOG_ERR,"Couldn't exec program %s", cmd->prog); exit(1); } +#endif void free_sopt( struct vtun_sopt *opt ) { @@ -355,6 +360,7 @@ void vtun_syslog (int priority, char *fo va_start(ap, format); vsnprintf(buf, sizeof(buf)-1, format, ap); syslog(priority, "%s", buf); + closelog(); va_end(ap); in_syslog = 0; diff -purN vtun-3.0.3/lib.h vtun/lib.h --- vtun-3.0.3/lib.h 2008-01-08 01:35:41.000000000 +0300 +++ vtun/lib.h 2013-07-07 23:55:00.000000000 +0400 @@ -17,7 +17,7 @@ */ /* - * $Id: lib.h,v 1.7.2.2 2008/01/07 22:35:41 mtbishop Exp $ + * $Id: lib.h,v 1.7.2.3 2013/07/07 19:55:00 mtbishop Exp $ */ #ifndef _VTUN_LIB_H #define _VTUN_LIB_H @@ -46,7 +46,9 @@ int readn_t(int fd, void *buf, size_t count, time_t timeout); int print_p(int f, const char *ftm, ...); +#ifdef HAVE_WORKING_FORK int run_cmd(void *d, void *opt); +#endif void free_sopt(struct vtun_sopt *opt); /* IO cancelation */ diff -purN vtun-3.0.3/linkfd.c vtun/linkfd.c --- vtun-3.0.3/linkfd.c 2012-07-08 09:31:44.000000000 +0400 +++ vtun/linkfd.c 2013-07-07 23:55:06.000000000 +0400 @@ -17,7 +17,7 @@ */ /* - * $Id: linkfd.c,v 1.13.2.5 2012/07/07 07:14:17 mtbishop Exp $ + * $Id: linkfd.c,v 1.13.2.6 2013/07/07 19:55:06 mtbishop Exp $ */ #include "config.h" @@ -56,14 +56,14 @@ int send_a_packet = 0; /* Host we are working with. * Used by signal handlers that's why it is global. */ -struct vtun_host *lfd_host; +static struct vtun_host *lfd_host; -struct lfd_mod *lfd_mod_head = NULL, *lfd_mod_tail = NULL; +static struct lfd_mod *lfd_mod_head = NULL, *lfd_mod_tail = NULL; /* Modules functions*/ /* Add module to the end of modules list */ -void lfd_add_mod(struct lfd_mod *mod) +static void lfd_add_mod(struct lfd_mod *mod) { if( !lfd_mod_head ){ lfd_mod_head = lfd_mod_tail = mod; @@ -77,7 +77,7 @@ void lfd_add_mod(struct lfd_mod *mod) } /* Initialize and allocate each module */ -int lfd_alloc_mod(struct vtun_host *host) +static int lfd_alloc_mod(struct vtun_host *host) { struct lfd_mod *mod = lfd_mod_head; @@ -91,7 +91,7 @@ int lfd_alloc_mod(struct vtun_host *host } /* Free all modules */ -int lfd_free_mod(void) +static int lfd_free_mod(void) { struct lfd_mod *mod = lfd_mod_head; @@ -105,7 +105,7 @@ int lfd_free_mod(void) } /* Run modules down (from head to tail) */ -inline int lfd_run_down(int len, char *in, char **out) +static inline int lfd_run_down(int len, char *in, char **out) { register struct lfd_mod *mod; @@ -119,7 +119,7 @@ inline int lfd_run_down(int len, char *i } /* Run modules up (from tail to head) */ -inline int lfd_run_up(int len, char *in, char **out) +static inline int lfd_run_up(int len, char *in, char **out) { register struct lfd_mod *mod; @@ -133,7 +133,7 @@ inline int lfd_run_up(int len, char *in, } /* Check if modules are accepting the data(down) */ -inline int lfd_check_down(void) +static inline int lfd_check_down(void) { register struct lfd_mod *mod; int err = 1; @@ -145,7 +145,7 @@ inline int lfd_check_down(void) } /* Check if modules are accepting the data(up) */ -inline int lfd_check_up(void) +static inline int lfd_check_up(void) { register struct lfd_mod *mod; int err = 1; @@ -179,7 +179,7 @@ static void sig_hup(int sig) static volatile sig_atomic_t ka_need_verify = 0; static time_t stat_timer = 0, ka_timer = 0; -void sig_alarm(int sig) +static void sig_alarm(int sig) { static time_t tm_old, tm = 0; static char stm[20]; @@ -215,7 +215,7 @@ static void sig_usr1(int sig) lfd_host->stat.comp_in = lfd_host->stat.comp_out = 0; } -int lfd_linker(void) +static int lfd_linker(void) { int fd1 = lfd_host->rmt_fd; int fd2 = lfd_host->loc_fd; diff -purN vtun-3.0.3/main.c vtun/main.c --- vtun-3.0.3/main.c 2012-07-08 09:32:57.000000000 +0400 +++ vtun/main.c 2013-07-08 00:31:22.000000000 +0400 @@ -17,7 +17,7 @@ */ /* - * $Id: main.c,v 1.9.2.5 2012/07/08 05:32:57 mtbishop Exp $ + * $Id: main.c,v 1.9.2.7 2013/07/07 20:31:22 mtbishop Exp $ */ #include "config.h" @@ -39,13 +39,20 @@ #include "lib.h" #include "compat.h" +#define OPTSTRING "mif:P:L:t:npq" +#ifdef HAVE_WORKING_FORK +# define SERVOPT_STRING "s" +#else +# define SERVOPT_STRING "" +#endif + /* Global options for the server and client */ struct vtun_opts vtun; struct vtun_host default_host; -void write_pid(void); -void reread_config(int sig); -void usage(void); +static void write_pid(void); +static void reread_config(int sig); +static void usage(void); extern int optind,opterr,optopt; extern char *optarg; @@ -55,13 +62,19 @@ int is_rmt_fd_connected=1; int main(int argc, char *argv[], char *env[]) { - int svr, daemon, sock, dofork, fd, opt; + int svr, daemon, sock, fd, opt; +#if defined(HAVE_WORKING_FORK) || defined(HAVE_WORKING_VFORK) + int dofork; +#endif struct vtun_host *host = NULL; struct sigaction sa; char *hst; /* Configure default settings */ - svr = 0; daemon = 1; sock = 0; dofork = 1; + svr = 0; daemon = 1; sock = 0; +#if defined(HAVE_WORKING_FORK) || defined(HAVE_WORKING_VFORK) + dofork = 1; +#endif vtun.cfg_file = VTUN_CONFIG_FILE; vtun.persist = -1; @@ -92,7 +105,7 @@ int main(int argc, char *argv[], char *e /* Start logging to syslog and stderr */ openlog("vtund", LOG_PID | LOG_NDELAY | LOG_PERROR, LOG_DAEMON); - while( (opt=getopt(argc,argv,"misf:P:L:t:npq")) != EOF ){ + while( (opt=getopt(argc,argv,OPTSTRING SERVOPT_STRING)) != EOF ){ switch(opt){ case 'm': if (mlockall(MCL_CURRENT | MCL_FUTURE) < 0) { @@ -102,7 +115,9 @@ int main(int argc, char *argv[], char *e break; case 'i': vtun.svr_type = VTUN_INETD; +#ifdef HAVE_WORKING_FORK case 's': +#endif svr = 1; break; case 'L': @@ -173,13 +188,20 @@ int main(int argc, char *argv[], char *e break; case VTUN_INETD: sock = dup(0); +#if defined(HAVE_WORKING_FORK) || defined(HAVE_WORKING_VFORK) dofork = 0; +#endif break; } if( daemon ){ +#ifdef HAVE_WORKING_FORK if( dofork && fork() ) exit(0); +#elif defined(HAVE_WORKING_VFORK) + if( dofork && vfork() ) + exit(0); +#endif /* Direct stdin,stdout,stderr to '/dev/null' */ fd = open("/dev/null", O_RDWR); @@ -200,8 +222,14 @@ int main(int argc, char *argv[], char *e init_title(argc,argv,env,"vtund[s]: "); - if( vtun.svr_type == VTUN_STAND_ALONE ) + if( vtun.svr_type == VTUN_STAND_ALONE ){ +#ifdef HAVE_WORKING_FORK write_pid(); +#else + vtun_syslog(LOG_ERR,"Standalone server is not supported. Use -i"); + exit(1); +#endif + } server(sock); } else { @@ -218,7 +246,7 @@ int main(int argc, char *argv[], char *e * Very simple PID file creation function. Used by server. * Overrides existing file. */ -void write_pid(void) +static void write_pid(void) { FILE *f; @@ -231,7 +259,7 @@ void write_pid(void) fclose(f); } -void reread_config(int sig) +static void reread_config(int sig) { if( !read_config(vtun.cfg_file) ){ vtun_syslog(LOG_ERR,"No hosts defined"); @@ -239,14 +267,18 @@ void reread_config(int sig) } } -void usage(void) +static void usage(void) { printf("VTun ver %s\n", VTUN_VER); printf("Usage: \n"); printf(" Server:\n"); - printf("\tvtund <-s> [-f file] [-P port] [-L local address]\n"); +#ifdef HAVE_WORKING_FORK + printf("\tvtund <-s|-i> [-f file] [-P port] [-L local address]\n"); +#else + printf("\tvtund <-i> [-f file] [-P port] [-L local address]\n"); +#endif printf(" Client:\n"); /* I don't think these work. I'm disabling the suggestion - bish 20050601*/ printf("\tvtund [-f file] " /* [-P port] [-L local address] */ - "[-p] [-m] [-t timeout] \n"); + "[-q] [-p] [-m] [-t timeout] \n"); } diff -purN vtun-3.0.3/Makefile.in vtun/Makefile.in --- vtun-3.0.3/Makefile.in 2012-07-09 08:55:38.000000000 +0400 +++ vtun/Makefile.in 2013-07-08 00:36:44.000000000 +0400 @@ -15,7 +15,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # -# $Id: Makefile.in,v 1.11.2.6 2012/07/09 04:55:38 mtbishop Exp $ +# $Id: Makefile.in,v 1.11.2.7 2013/07/07 20:36:44 mtbishop Exp $ # CC = @CC@ CFLAGS = @CFLAGS@ @CPPFLAGS@ @@ -73,7 +73,7 @@ depend: makedepend -- $(CFLAGS) -- *.c clean: - rm -f core cfg_file.tab.* cfg_file.lex.* *.o *~ *.bak vtund + rm -f core cfg_file.tab.* cfg_file.lex.* *.o *~ .#* *.bak vtund distclean: clean rm -f $(CONFIGURE_FILES) diff -purN vtun-3.0.3/packages/vtun.spec vtun/packages/vtun.spec --- vtun-3.0.3/packages/vtun.spec 2012-07-08 14:30:27.000000000 +0400 +++ vtun/packages/vtun.spec 2013-07-07 22:03:49.000000000 +0400 @@ -1,4 +1,4 @@ -# $Id: vtun.spec,v 1.24.2.9 2012/07/08 10:30:27 mtbishop Exp $ +# $Id: vtun.spec,v 1.24.2.10 2013/07/07 18:03:49 mtbishop Exp $ # By default, builds without socks-support. # To build with socks-support, issue: @@ -46,6 +46,8 @@ Summary: Virtual tunnel over TCP/IP net Summary(pl): Wirtualne tunele poprzez sieci TCP/IP Vendor: Maxim Krasnyansky Packager: Bishop Clark (LC957) + + # Remember this is ignored for recent distros (Backward Compatibility is dumb) BuildRoot: %{?_tmppath:%{_tmppath}}%{!?_tmppath:%{tmpdir}}/%{name}-%{version}-root-%(id -u -n) Obsoletes: vppp BuildRequires: autoconf diff -purN vtun-3.0.3/server.c vtun/server.c --- vtun-3.0.3/server.c 2012-07-09 05:01:08.000000000 +0400 +++ vtun/server.c 2013-07-07 23:55:14.000000000 +0400 @@ -17,7 +17,7 @@ */ /* - * $Id: server.c,v 1.9.2.3 2012/07/09 01:01:08 mtbishop Exp $ + * $Id: server.c,v 1.9.2.4 2013/07/07 19:55:14 mtbishop Exp $ */ #include "config.h" @@ -58,7 +58,7 @@ static void sig_term(int sig) server_term = VTUN_SIG_TERM; } -void connection(int sock) +static void connection(int sock) { struct sockaddr_in my_addr, cl_addr; struct vtun_host *host; @@ -111,7 +111,8 @@ void connection(int sock) exit(0); } -void listener(void) +#ifdef HAVE_WORKING_FORK +static void listener(void) { struct sigaction sa; struct sockaddr_in my_addr, cl_addr; @@ -172,6 +173,7 @@ void listener(void) } } } +#endif void server(int sock) { @@ -190,7 +192,11 @@ void server(int sock) switch( vtun.svr_type ){ case VTUN_STAND_ALONE: +#ifdef HAVE_WORKING_FORK listener(); +#else + vtun_syslog(LOG_ERR,"Standalone server is not supported: fork() not available"); +#endif break; case VTUN_INETD: connection(sock); diff -purN vtun-3.0.3/tunnel.c vtun/tunnel.c --- vtun-3.0.3/tunnel.c 2008-01-08 01:36:03.000000000 +0300 +++ vtun/tunnel.c 2013-07-07 23:55:17.000000000 +0400 @@ -17,7 +17,7 @@ */ /* - * $Id: tunnel.c,v 1.14.2.2 2008/01/07 22:36:03 mtbishop Exp $ + * $Id: tunnel.c,v 1.14.2.3 2013/07/07 19:55:17 mtbishop Exp $ */ #include "config.h" @@ -147,6 +147,7 @@ int tunnel(struct vtun_host *host) break; } +#ifdef HAVE_WORKING_FORK switch( (pid=fork()) ){ case -1: vtun_syslog(LOG_ERR,"Couldn't fork()"); @@ -187,6 +188,9 @@ int tunnel(struct vtun_host *host) exit(0); } +#else + vtun_syslog(LOG_ERR,"Couldn't run up commands: fork() not available"); +#endif switch( host->flags & VTUN_TYPE_MASK ){ case VTUN_TTY: @@ -222,8 +226,12 @@ int tunnel(struct vtun_host *host) opt = linkfd(host); +#ifdef HAVE_WORKING_FORK set_title("%s running down commands", host->host); llist_trav(&host->down, run_cmd, &host->sopt); +#else + vtun_syslog(LOG_ERR,"Couldn't run down commands: fork() not available"); +#endif if(! ( host->persist == VTUN_PERSIST_KEEPIF ) ) { set_title("%s closing", host->host); diff -purN vtun-3.0.3/vtund.conf vtun/vtund.conf --- vtun-3.0.3/vtund.conf 2012-07-08 09:31:44.000000000 +0400 +++ vtun/vtund.conf 2013-07-08 00:36:48.000000000 +0400 @@ -6,7 +6,7 @@ # Ted Rolle # # Configuration file example -# $Id: vtund.conf,v 1.4.2.5 2012/07/07 07:14:17 mtbishop Exp $ +# $Id: vtund.conf,v 1.4.2.6 2013/07/07 20:36:48 mtbishop Exp $ # # # Lines which begin with '#' are comments @@ -227,6 +227,7 @@ # %P - Local TCP or UDP port # %a - Remote IP address # %p - Remote TCP or UDP port +# %h - Host Profile Name in config # # wait - Wait for the program termination. # diff -purN vtun-3.0.3/vtund.conf.5 vtun/vtund.conf.5 --- vtun-3.0.3/vtund.conf.5 2012-07-08 09:31:44.000000000 +0400 +++ vtun/vtund.conf.5 2013-07-08 00:36:52.000000000 +0400 @@ -1,5 +1,5 @@ .\" Manual page for vtund.conf -.\" $Id: vtund.conf.5,v 1.4.2.4 2012/07/07 07:14:17 mtbishop Exp $ +.\" $Id: vtund.conf.5,v 1.4.2.5 2013/07/07 20:36:52 mtbishop Exp $ .TH VTUND.CONF 5 .SH NAME @@ -315,6 +315,8 @@ Special characters that can be used insi \fB%a\fR - Remote IP address .br \fB%p\fR - Remote TCP or UDP port +.br +\fB%h\fR - Host profile name .IP \fBppp\ \fIarguments\fR run program specified by \fBppp\fR statement in \fBoptions\fR section. All special character described above are valid in \fIarguments\fR here. diff -purN vtun-3.0.3/vtun.h vtun/vtun.h --- vtun-3.0.3/vtun.h 2012-07-09 05:01:08.000000000 +0400 +++ vtun/vtun.h 2013-07-08 00:36:56.000000000 +0400 @@ -17,7 +17,7 @@ */ /* - * $Id: vtun.h,v 1.12.2.7 2012/07/09 01:01:08 mtbishop Exp $ + * $Id: vtun.h,v 1.12.2.8 2013/07/07 20:36:56 mtbishop Exp $ */ #ifndef _VTUN_H @@ -51,6 +51,7 @@ struct vtun_sopt { int lport; char *raddr; int rport; + char *host; }; struct vtun_stat {