Fix deadcode / warnings / minor bugs

This commit is contained in:
Vladimir Dubrovin 2026-07-31 18:55:59 +03:00
parent 44c47ee7d9
commit 4877b39f2c
24 changed files with 49 additions and 145 deletions

View File

@ -236,6 +236,12 @@ else()
)
endif()
# Unix domain sockets off: NO_UN also undefines WITH_UN if it arrives from
# elsewhere, e.g. CFLAGS
if(NOT 3PROXY_USE_UNIX_SOCKETS)
add_compile_definitions(NO_UN)
endif()
# Common definitions
if(WIN32)
# Windows: use WSAPOLL

View File

@ -8,7 +8,7 @@ BUILDDIR = ../bin/
PREFIX = 3proxy_
CRYPT_PREFIX = 3proxy_
CC = cl
CFLAGS = /nologo /Ox /MT /D "NOIPV6" /D "NODEBUG" /D "NORADIUS" /D"WATCOM" /D "MSVC" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_WIN32" /D "PRId64=\"I64d\"" /D "PRIu64=\"I64u\"" /D "SCNu64=\"I64u\"" /D "SCNx64=\"I64x\"" /D "SCNd64=\"I64d\"" /D "PRIx64=\"I64x\"" /c $(VERSION) $(BUILDDATE)
CFLAGS = /nologo /Ox /MT /D "NOIPV6" /D "NO_UN" /D "NODEBUG" /D "NORADIUS" /D"WATCOM" /D "MSVC" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_WIN32" /D "PRId64=\"I64d\"" /D "PRIu64=\"I64u\"" /D "SCNu64=\"I64u\"" /D "SCNx64=\"I64x\"" /D "SCNd64=\"I64d\"" /D "PRIx64=\"I64x\"" /c $(VERSION) $(BUILDDATE)
COUT = /Fo
LN = link
LDFLAGS = /nologo /subsystem:console /incremental:no

View File

@ -80,7 +80,7 @@ int cacheauth(struct clientparam * param){
((type & 4) && !param->password) ||
(
(type & 1) && *SAFAMILY(&param->sincr) != AF_INET
#ifndef NOIPv6
#ifndef NOIPV6
&& *SAFAMILY(&param->sincr) != AF_INET6
#endif
) || (!hashresolv(&auth_table, param, &ac, &ttl))) {
@ -108,7 +108,6 @@ int cacheauth(struct clientparam * param){
int doauth(struct clientparam * param){
int res = 0;
struct auth *authfuncs;
char * tmp;
int ret = 0;
for(authfuncs=param->srv->authfuncs; authfuncs; authfuncs=authfuncs->next){
@ -125,7 +124,7 @@ int doauth(struct clientparam * param){
ac.username[63] = 0;
}
if(*SAFAMILY(&param->sincr) == AF_INET
#ifndef NOIPv6
#ifndef NOIPV6
|| *SAFAMILY(&param->sincr) == AF_INET6
#endif
) {
@ -134,7 +133,7 @@ int doauth(struct clientparam * param){
}
if(*SAFAMILY(&param->sinsl) == AF_INET
#ifndef NOIPv6
#ifndef NOIPV6
|| *SAFAMILY(&param->sinsl) == AF_INET6
#endif
) {
@ -235,7 +234,6 @@ static int ctstrcmp(const char *a, const char *b, size_t maxlen){
}
int strongauth(struct clientparam * param){
static char dummy;
unsigned char buf[256];
char pass[256] = {0};

View File

@ -174,17 +174,6 @@ void md5_calc(unsigned char *output, unsigned char *input,
unsigned int inputlen);
char *strNcpy(char *dest, const char *src, int n)
{
if (n > 0)
strncpy(dest, src, n);
else
n = 1;
dest[n - 1] = 0;
return dest;
}
void md5_calc(unsigned char *output, unsigned char *input,
unsigned int inlen)
{
@ -308,14 +297,12 @@ int radsend(struct clientparam * param, int auth, int stop){
unsigned char *ptr;
int total_length;
int len;
int op;
PROXYSOCKADDRTYPE saremote;
struct pollfd fds[1];
char vector[AUTH_VECTOR_LEN];
radius_packet_t packet, rpacket;
SASIZETYPE salen;
int data_len;
uint8_t *vendor_len;
int count=0;
uint8_t *attr;
long vendor=0;
@ -613,7 +600,6 @@ int radsend(struct clientparam * param, int auth, int stop){
attr = rpacket.data;
count = total_length - 20;
vendor_len = 0;
while (count >= 2) {
if (!vendor && attr[0] == 0) {

View File

@ -21,6 +21,7 @@ void * autochild(struct clientparam* param) {
if (len != 1){
param->res = 801;
dolog(param, (unsigned char *)"");
return 0;
}
if(*param->clibuf == 4 || *param->clibuf == 5) {
param->service = S_SOCKS;

View File

@ -681,20 +681,6 @@ int doconnect(struct clientparam * param){
setopts(param->remsock, param->srv->srvsockopts);
param->srv->so._setsockopt(param->sostate, param->remsock, SOL_SOCKET, SO_LINGER, (char *)&lg, sizeof(lg));
#ifdef REUSE
{
int opt;
#ifdef SO_REUSEADDR
opt = 1;
param->srv->so._setsockopt(param->sostate, param->remsock, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(int));
#endif
#ifdef SO_REUSEPORT
opt = 1;
param->srv->so._setsockopt(param->sostate, param->remsock, SOL_SOCKET, SO_REUSEPORT, (unsigned char *)&opt, sizeof(int));
#endif
}
#endif
#if defined SO_BINDTODEVICE
if(param->srv->obindtodevice) {
if(param->srv->so._setsockopt(param->sostate, param->remsock, SOL_SOCKET, SO_BINDTODEVICE, param->srv->obindtodevice, strlen(param->srv->obindtodevice) + 1))

View File

@ -296,6 +296,7 @@ static int h_external(int argc, unsigned char ** argv){
else conf.extsa6 = sa6;
#else
res = getip46(46, argv[1], (struct sockaddr *)&conf.extsa);
if(!res) return 1;
#endif
return 0;
}
@ -517,7 +518,6 @@ static int h_auth(int argc, unsigned char **argv){
}
static int h_users(int argc, unsigned char **argv){
static char dummy;
int j;
unsigned char *arg;
char *pw[2];

View File

@ -61,13 +61,6 @@ static void pr_ip(struct node *node, CBFUNC cbf, void*cb){
if(node->value)(*cbf)(cb, buf, myinet_ntop(AF_INET, node -> value, buf, 4));
}
#ifndef NOIPV6
static void pr_ip6(struct node *node, CBFUNC cbf, void*cb){
char buf[64];
if(node->value)(*cbf)(cb, buf, myinet_ntop(AF_INET6, node -> value, buf, 16));
}
#endif
static void pr_sa(struct node *node, CBFUNC cbf, void*cb){
#ifdef NOIPV6
if(node->value)pr_ip(node, cbf, cb);

View File

@ -36,7 +36,6 @@ void destroyhashtable(struct hashtable *ht){
int inithashtable(struct hashtable *ht, unsigned tablesize, unsigned poolsize, unsigned growlimit){
unsigned i;
clock_t c;
#ifdef _WIN32
struct timeb tb;
@ -48,7 +47,6 @@ int inithashtable(struct hashtable *ht, unsigned tablesize, unsigned poolsize, u
struct timezone tz;
gettimeofday(&tb, &tz);
#endif
c = clock();
if(tablesize < 2 || poolsize < tablesize || growlimit < poolsize) return 1;
if(ht->ihashtable){
@ -169,7 +167,6 @@ static void hashgrow(struct hashtable *ht){
void hashadd(struct hashtable *ht, void* name, void* value, time_t expires){
uint32_t hen, he;
uint32_t *hep;
int overwrite = 0;
uint8_t hash[MAX_HASH_SIZE];
uint32_t index;
uint32_t last = 0;

View File

@ -28,7 +28,7 @@ static void param2hash_add(const struct hashtable *ht, void *index, uint8_t *has
void param2hash_search(const struct hashtable *ht, void *index, uint8_t *hash){
struct clientparam *param = (struct clientparam *)index;
unsigned type = param->srv->authcachetype;
int len = 0, oplen = 0, acllen = 0, ulen = 0, plen = 0, hlen = 0, a1len = 0, a2len = 0, a3len = 0, p1len=0, p2len = 0;
int oplen = 0, acllen = 0, ulen = 0, plen = 0, hlen = 0, a1len = 0, a2len = 0, a3len = 0, p1len=0, p2len = 0;
if((type & 2) && param->username) ulen = strlen((const char *)param->username) + 1;
@ -76,19 +76,6 @@ void param2hash_search(const struct hashtable *ht, void *index, uint8_t *hash){
memcpy(param->hash, hash, ht->hash_size);
}
static void udpparam2hash(const struct hashtable *ht, void *index, uint8_t *hash){
struct clientparam *param = (struct clientparam *)index;
mdh_ctx *bctx = mdh_init(MDH_BLAKE2, ht->hash_size);
unsigned int blen = ht->hash_size;
if(!bctx) return;
mdh_update(bctx, SAADDR(&param->srv->intsa), SAADDRLEN(&param->srv->intsa));
mdh_update(bctx, SAPORT(&param->srv->intsa), 2);
mdh_update(bctx, SAADDR(&param->sincr), SAADDRLEN(&param->sincr));
mdh_update(bctx, SAPORT(&param->sincr), 2);
mdh_final(bctx, hash, &blen);
mdh_free(bctx);
}
struct hashtable dns_table = {char_index2hash, char_index2hash, 4, 32};
struct hashtable dns6_table = {char_index2hash, char_index2hash, 16, 32};
struct hashtable auth_table = {param2hash_add, param2hash_search, sizeof(struct authcache), 64};

View File

@ -52,7 +52,6 @@ unsigned long preview = 0;
char path[300];
static int counter = 0;
static int timeo = 0;
static char * fp_stringtable[] = {
/* 0 */ "HTTP/1.0 503 Service Unavailable\r\n"
@ -261,10 +260,6 @@ static void removefps(struct fp_stream * fps){
fps->state = 0;
}
static int WINAPI fp_connect(SOCKET s, const struct sockaddr *name, fp_size_t namelen){
return sso._connect(sso.state, s, name, namelen);
}
void processcallbacks(struct fp_stream *fps, int what, char *msg, int size){
struct fp_callback *cb;
int state;

View File

@ -90,10 +90,7 @@ static int pamfunc(struct clientparam *param)
conv.appdata_ptr = (char *) param->password;
_3proxy_mutex_lock(&pam_mutex);
if (!pamh)
{
retval = pam_start ((char *)service, (char *)param->username, &conv, &pamh);
}
if (retval == PAM_SUCCESS)
retval = pam_set_item (pamh, PAM_USER, param->username);
/*fprintf(stderr,"pam_set_item1 rc=%d\n",retval);*/

View File

@ -34,13 +34,12 @@ static void* transparent_filter_open(void * idata, struct srvparam * param){
static FILTER_ACTION transparent_filter_client(void *fo, struct clientparam * param, void** fc){
socklen_t len;
char addrbuf[64];
int i=0;
len = sizeof(param->req);
#ifdef WITH_NETFILTER
socklen_t len;
len = sizeof(param->req);
#ifdef SO_ORIGINAL_DST
if(getsockopt(param->clisock,

View File

@ -247,9 +247,13 @@ void * proxychild(struct clientparam* param) {
int redirect = 0;
int prefix = 0, ckeepalive=0;
int ftp = 0;
#ifndef ANONYMOUS
int anonymous;
#endif
int sleeptime = 0;
#ifndef WITHMAIN
int reqsize, reqbufsize;
#endif
int authenticate;
struct pollfd fds[2];
SOCKET ftps;
@ -265,7 +269,9 @@ void * proxychild(struct clientparam* param) {
if(param->remsock != INVALID_SOCKET) haveconnection = 1;
if(!(buf = malloc(BUFSIZE))) {RETURN(21);}
bufsize = BUFSIZE;
#ifndef ANONYMOUS
anonymous = param->srv->anonymous;
#endif
for(;;){
memset(buf, 0, bufsize);
inbuf = 0;
@ -548,8 +554,10 @@ for(;;){
buf[inbuf] = 0;
#ifndef WITHMAIN
reqsize = (int)strlen((char *)req);
reqbufsize = reqsize + 1;
#endif
if(param->srv->needuser > 1 && !param->username) {RETURN(4);}
@ -701,7 +709,6 @@ for(;;){
int sizetoken =-1;
int modetoken =-1;
int datetoken =-1;
int spaces = 1;
unsigned char * tokens[10];
unsigned wordlen [10];
unsigned char j=0;
@ -734,7 +741,6 @@ for(;;){
wordlen[datetoken] = ((unsigned)(tokens[1] - tokens[0])) + wordlen[1];
sizetoken = 2;
filetoken = 3;
spaces = 10;
}
else {
if(j < 8 || wordlen[0]!=10) continue;

View File

@ -103,7 +103,6 @@
#include <pthread.h>
#ifndef PTHREAD_STACK_MIN
#define PTHREAD_STACK_MIN 32768
#define sockerror strerror
#endif
void daemonize(void);
#define SLEEPTIME 1000

View File

@ -165,9 +165,6 @@ struct socketoptions sockopts[] = {
#ifdef TCP_TIMESTAMPS
{TCP_TIMESTAMPS, "TCP_TIMESTAMPS"},
#endif
#ifdef USE_TCP_FASTOPEN
{USE_TCP_FASTOPEN, "USE_TCP_FASTOPEN"},
#endif
#ifdef SO_REUSEADDR
{SO_REUSEADDR, "SO_REUSEADDR"},
#endif
@ -297,6 +294,7 @@ int MODULEMAINFUNC (int argc, char** argv){
#ifdef __linux__
int saved_nsfd = -1;
#endif
#if !defined(PORTMAP) || !defined(NOPORTMAP)
char loghelp[] =
#ifdef STDMAIN
#ifndef _WIN32
@ -312,8 +310,8 @@ int MODULEMAINFUNC (int argc, char** argv){
" -Di(DEVICENAME) bind internal interface to device, e.g. eth1\n"
" -De(DEVICENAME) bind external interface to device, e.g. eth1\n"
#endif
#ifdef WITHSLICE
" -s Use slice() - faster proxing, but no filtering for data\n"
#ifdef WITHSPLICE
" -s Use splice() - faster proxing, but no filtering for data\n"
#endif
"-g(GRACE_TRAFF,GRACE_NUM,GRACE_DELAY) - delay GRACE_DELAY milliseconds before polling if average polling size below GRACE_TRAFF bytes and GRACE_NUM read operations in single directions are detected within 1 second to minimize polling\n"
" -fFORMAT logging format (see documentation)\n"
@ -335,6 +333,7 @@ int MODULEMAINFUNC (int argc, char** argv){
" to-client (oc), to-server (os), listening (ol) socket, connect back client\n"
" (or) socket, connect back server (oR) listening socket\n"
" where possible options are: ";
#endif
#ifdef _WIN32
unsigned long ul = 1;

View File

@ -56,7 +56,10 @@ int readreply (struct clientparam* param) {
int readcommand (struct clientparam* param) {
unsigned char * buf;
int res, i, bufsize = 320;
int i, bufsize = 320;
#ifndef WITHMAIN
int res;
#endif
int ret = 1;
if(!(buf = malloc(bufsize))) return 0;
@ -82,7 +85,10 @@ int readcommand (struct clientparam* param) {
int readdata (struct clientparam* param) {
unsigned char * buf;
int res, i, bufsize = 4096;
int i, bufsize = 4096;
#ifndef WITHMAIN
int res;
#endif
if(!(buf = malloc(bufsize))) return 0;
while ((i = sockgetlinebuf(param, CLIENT, buf, bufsize-1, '\n', conf.timeouts[STRING_L])) > 0 && !(i==3 && buf[0] == '.')){

View File

@ -14,7 +14,7 @@
#if WITHLOG > 1
char logbuf[1024];
#endif
#define log(X) dolog(param,X)
#define log(X) dolog(param,(const unsigned char *)(X))
#else
#define log(X)
#endif
@ -47,13 +47,15 @@ ssize_t splice(int fd_in, loff_t *off_in, int fd_out, loff_t *off_out, size_t le
int sockmap(struct clientparam * param, int timeo, int usesplice){
uint64_t fromclient=0x7fffffffffffffff, fromserver =0x7fffffffffffffff;
uint64_t inclientbuf = 0, inserverbuf = 0;
int FROMCLIENT = 1, TOCLIENTBUF = 1, FROMCLIENTBUF = 1, TOSERVER = 1,
FROMSERVER = 1, TOSERVERBUF = 1, FROMSERVERBUF = 1, TOCLIENT = 1;
int FROMCLIENT = 1, TOCLIENTBUF = 1, TOSERVER = 1,
FROMSERVER = 1, TOSERVERBUF = 1, TOCLIENT = 1;
#if WITHLOG > 1
int FROMCLIENTBUF = 1, FROMSERVERBUF = 1;
#endif
int HASERROR=0;
int CLIENTTERMREAD = 0, CLIENTTERMWRITE = 0, SERVERTERMREAD = 0, SERVERTERMWRITE = 0;
int after = 0;
struct pollfd fds[8];
struct pollfd *fdsp = fds;
int fdsc = 0;
int sleeptime = 0;
FILTER_ACTION action;

View File

@ -53,7 +53,6 @@ void * sockschild(struct clientparam* param) {
int ver=0;
int havepass = 0;
PROXYSOCKADDRTYPE sin;
int len;
param->service = S_SOCKS;
@ -212,19 +211,7 @@ void * sockschild(struct clientparam* param) {
param->operation = command == 2?BIND:UDPASSOC;
if(command == 2){
if ((param->remsock=param->srv->so._socket(param->sostate, SASOCK(&param->req), SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) {RETURN (11);}
#ifdef REUSE
{
int opt;
#ifdef SO_REUSEADDR
opt = 1;
param->srv->so._setsockopt(param->sostate, param->remsock, SOL_SOCKET, SO_REUSEADDR, (unsigned char *)&opt, sizeof(int));
#endif
#ifdef SO_REUSEPORT
opt = 1;
param->srv->so._setsockopt(param->sostate, param->remsock, SOL_SOCKET, SO_REUSEPORT, (unsigned char *)&opt, sizeof(int));
#endif
}
#endif
setopts(param->remsock, param->srv->lissockopts);
}
break;

View File

@ -53,7 +53,6 @@ static char *client_ca_store = NULL;
static int mitm = 0;
static int serv = 0;
static int cli = 0;
static int ssl_inited = 0;
static int client_min_proto_version = 0;
static int client_max_proto_version = 0;
static int server_min_proto_version = 0;
@ -486,10 +485,6 @@ EVP_PKEY * getKey(const char *fname){
return key;
}
static int verify_callback(int preverify_ok, X509_STORE_CTX *ctx){
return preverify_ok;
}
#ifdef WITH_WOLFSSL
/* wolfSSL's SSL_CTX_use_PrivateKey(EVP_PKEY*) compat is unreliable: it
* silently fails (returns 0, no error queued) for keys loaded via

View File

@ -310,29 +310,8 @@ int thread_setup(void)
_3proxy_mutex_init(mutex_buf +i);
CRYPTO_set_id_callback(id_function);
CRYPTO_set_locking_callback(locking_function);
return 1;
#else
return 1;
#endif
}
int thread_cleanup(void)
{
#if LEGACY_SSL_THREADING
int i;
if (!mutex_buf)
return 0;
CRYPTO_set_id_callback(NULL);
CRYPTO_set_locking_callback(NULL);
for (i = 0; i < CRYPTO_num_locks( ); i++)
_3proxy_mutex_destroy(mutex_buf +i);
free(mutex_buf);
mutex_buf = NULL;
return 1;
#else
return 1;
#endif
}

View File

@ -182,7 +182,7 @@ int
#ifdef WITH_UN
#define PROXYSOCKADDRTYPE struct sockaddr_storage
#else
#ifndef NOIPv6
#ifndef NOIPV6
#define PROXYSOCKADDRTYPE struct sockaddr_in6
#else
#define PROXYSOCKADDRTYPE struct sockaddr_in
@ -798,7 +798,7 @@ extern struct hashtable udp_table;
struct authcache {
unsigned char username[64];
#ifndef NOIPv6
#ifndef NOIPV6
uint8_t sincr_addr[16];
uint8_t sinsl_addr[16];
#else

View File

@ -19,20 +19,6 @@ unsigned size16(unsigned char *buf){
return res;
}
int readtls(struct clientparam *param, int direction, unsigned char *buf, int bufsize){
int res = 0;
int len;
if(bufsize < 3) return -1;
res = sockgetlinebuf(param, direction, buf, 3, EOF, conf.timeouts[STRING_S]);
if(res !=3 || buf[0] != 22 || buf[1] != 3) return -2;
len = size16(buf+3);
if((len+3) > bufsize) return -3;
res = sockgetlinebuf(param, direction, buf+3, len, EOF, conf.timeouts[STRING_S]);
if(res != len) return -4;
return len+3;
}
#define BSIZE (4096)
#define SNILEN (256)
#define PROTOLEN (32)