Compare commits

...

8 Commits

Author SHA1 Message Date
Vladimir Dubrovin
b1ac46da79 Remove linux futext implementation
Some checks failed
Build Win32 3proxy-lite with Watcom / ${{ matrix.target }} (windows-2022) (push) Has been cancelled
Build Win32 3proxy with MSVC / ${{ matrix.target }} (windows-2022) (push) Has been cancelled
Build Win64 3proxy with MSVC / ${{ matrix.target }} (windows-2022) (push) Has been cancelled
Build Win-arm64 3proxy with MSVC / ${{ matrix.target }} (windows-2022) (push) Has been cancelled
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Has been cancelled
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-latest) (push) Has been cancelled
C/C++ CI MacOS / ${{ matrix.target }} (macos-15) (push) Has been cancelled
C/C++ CI Windows / ${{ matrix.target }} (windows-2022) (push) Has been cancelled
C/C++ CI cmake / ${{ matrix.target }} (macos-15) (push) Has been cancelled
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Has been cancelled
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-latest) (push) Has been cancelled
C/C++ CI cmake / ${{ matrix.target }} (windows-2022) (push) Has been cancelled
2026-04-28 18:06:54 +03:00
Vladimir Dubrovin
d125261e8c fix: hashtables on recsize < 4 2026-04-28 16:32:30 +03:00
Vladimir Dubrovin
a4527783d6 Correctly process half-closed connections; add grace sleep before closing sockets 2026-04-28 16:15:18 +03:00
Vladimir Dubrovin
fb70d06d3e Add linger sleep on connection close 2026-04-28 14:55:37 +03:00
Vladimir Dubrovin
57d687fcb8 add 3proxy_crypt man 2026-04-28 14:41:14 +03:00
Vladimir Dubrovin
ada24a98ec Use semaphore/mutex insted of pipe for threads sync 2026-04-28 14:00:15 +03:00
Vladimir Dubrovin
ba2584cebf change 3proxy.cfg.3 to 3proxy.cfg.5 2026-04-28 12:34:53 +03:00
Vladimir Dubrovin
05096c222a Return standalone udppm; do not build standalone modules by default in cmake
Allow to set prefix in cmake, 3proxy_ by default
2026-04-28 12:21:11 +03:00
43 changed files with 874 additions and 609 deletions

View File

@ -45,7 +45,7 @@ jobs:
mkdir dist\3proxy\doc\ru
mkdir dist\3proxy\doc\html
mkdir dist\3proxy\doc\html\plugins
mkdir dist\3proxy\doc\html\man3
mkdir dist\3proxy\doc\html\man5
mkdir dist\3proxy\doc\html\man8
mkdir dist\3proxy\doc\devel
copy bin\3proxy.exe dist\3proxy\bin\
@ -57,7 +57,7 @@ jobs:
copy doc\html\*.* dist\3proxy\doc\html\
copy doc\html\plugins\*.* dist\3proxy\doc\html\plugins\
copy doc\html\man8\*.* dist\3proxy\doc\html\man8\
copy doc\html\man3\*.* dist\3proxy\doc\html\man3\
copy doc\html\man5\*.* dist\3proxy\doc\html\man5\
copy doc\devel\*.rtf dist\3proxy\doc\devel\
copy copying dist\3proxy\
copy authors dist\3proxy\

View File

@ -51,7 +51,7 @@ jobs:
mkdir dist\3proxy\doc\ru
mkdir dist\3proxy\doc\html
mkdir dist\3proxy\doc\html\plugins
mkdir dist\3proxy\doc\html\man3
mkdir dist\3proxy\doc\html\man5
mkdir dist\3proxy\doc\html\man8
mkdir dist\3proxy\doc\devel
copy bin\3proxy.exe dist\3proxy\bin\
@ -63,7 +63,7 @@ jobs:
copy doc\html\*.* dist\3proxy\doc\html\
copy doc\html\plugins\*.* dist\3proxy\doc\html\plugins\
copy doc\html\man8\*.* dist\3proxy\doc\html\man8\
copy doc\html\man3\*.* dist\3proxy\doc\html\man3\
copy doc\html\man5\*.* dist\3proxy\doc\html\man5\
copy doc\devel\*.rtf dist\3proxy\doc\devel\
copy copying dist\3proxy\
copy authors dist\3proxy\

View File

@ -53,7 +53,7 @@ jobs:
mkdir dist\3proxy\doc\ru
mkdir dist\3proxy\doc\html
mkdir dist\3proxy\doc\html\plugins
mkdir dist\3proxy\doc\html\man3
mkdir dist\3proxy\doc\html\man5
mkdir dist\3proxy\doc\html\man8
mkdir dist\3proxy\doc\devel
copy bin\3proxy.exe dist\3proxy\bin64\
@ -65,7 +65,7 @@ jobs:
copy doc\html\*.* dist\3proxy\doc\html\
copy doc\html\plugins\*.* dist\3proxy\doc\html\plugins\
copy doc\html\man8\*.* dist\3proxy\doc\html\man8\
copy doc\html\man3\*.* dist\3proxy\doc\html\man3\
copy doc\html\man5\*.* dist\3proxy\doc\html\man5\
copy doc\devel\*.rtf dist\3proxy\doc\devel\
copy copying dist\3proxy\
copy authors dist\3proxy\

View File

@ -51,7 +51,7 @@ jobs:
mkdir dist\3proxy\doc\ru
mkdir dist\3proxy\doc\html
mkdir dist\3proxy\doc\html\plugins
mkdir dist\3proxy\doc\html\man3
mkdir dist\3proxy\doc\html\man5
mkdir dist\3proxy\doc\html\man8
mkdir dist\3proxy\doc\devel
copy bin\3proxy.exe dist\3proxy\bin64\
@ -63,7 +63,7 @@ jobs:
copy doc\html\*.* dist\3proxy\doc\html\
copy doc\html\plugins\*.* dist\3proxy\doc\html\plugins\
copy doc\html\man8\*.* dist\3proxy\doc\html\man8\
copy doc\html\man3\*.* dist\3proxy\doc\html\man3\
copy doc\html\man5\*.* dist\3proxy\doc\html\man5\
copy doc\devel\*.rtf dist\3proxy\doc\devel\
copy copying dist\3proxy\
copy authors dist\3proxy\

8
.gitignore vendored
View File

@ -259,3 +259,11 @@ pip-log.txt
.mr.developer.cfg
CLAUDE.md
bin/3proxy_crypt
bin/3proxy_ftppr
bin/3proxy_pop3p
bin/3proxy_proxy
bin/3proxy_smtpp
bin/3proxy_socks
bin/3proxy_tcppm
bin/3proxy_tlspr
bin/3proxy_udppm

View File

@ -56,6 +56,27 @@ option(3PROXY_USE_WSAPOLL "Use WSAPoll instead of select() (Windows only)" ON)
option(3PROXY_USE_NETFILTER "Enable Linux netfilter support (Linux only)" ON)
option(3PROXY_USE_UNIX_SOCKETS "Enable Unix domain socket support (Unix only)" ON)
# Binary name prefix for standalone modules and crypt (default: 3proxy_)
# For crypt: if prefix is empty, "my" is used instead ( mycrypt)
set(3PROXY_BINARY_PREFIX "3proxy_" CACHE STRING "Prefix for standalone module and crypt binary names")
# Standalone module build options (OFF by default)
option(3PROXY_BUILD_ALL "Build all standalone binaries" OFF)
option(3PROXY_BUILD_PROXY "Build standalone proxy binary" OFF)
option(3PROXY_BUILD_SOCKS "Build standalone socks binary" OFF)
option(3PROXY_BUILD_POP3P "Build standalone pop3p binary" OFF)
option(3PROXY_BUILD_SMTPP "Build standalone smtpp binary" OFF)
option(3PROXY_BUILD_FTPPR "Build standalone ftppr binary" OFF)
option(3PROXY_BUILD_TCPPM "Build standalone tcppm binary" OFF)
option(3PROXY_BUILD_UDPPM "Build standalone udppm binary" OFF)
option(3PROXY_BUILD_TLSPR "Build standalone tlspr binary" OFF)
if(3PROXY_BUILD_ALL)
foreach(_M PROXY SOCKS POP3P SMTPP FTPPR TCPPM UDPPM TLSPR)
set(3PROXY_BUILD_${_M} ON)
endforeach()
endif()
# Output directory
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
@ -290,6 +311,7 @@ set(3PROXY_CORE_SOURCES
src/redirect.c
src/authradius.c
src/hash.c
src/hashtables.c
src/resolve.c
src/sql.c
src/conf.c
@ -327,7 +349,7 @@ target_include_directories(base64_obj PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
# These are used by the main 3proxy executable
# ============================================================================
# Server modules object library (without WITHMAIN)
# Server modules object library (without WITHMAIN, without UDP)
add_library(srv_modules OBJECT
src/proxy.c
src/pop3p.c
@ -338,13 +360,17 @@ add_library(srv_modules OBJECT
src/auto.c
src/socks.c
src/webadmin.c
src/udppm.c
src/dnspr.c
)
target_include_directories(srv_modules PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
)
# UDP port mapper server module (without WITHMAIN)
add_library(srvudppm_obj OBJECT src/udppm.c)
target_include_directories(srvudppm_obj PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
)
# mainfunc object (proxymain.c compiled with MODULEMAINFUNC=mainfunc for 3proxy)
add_library(mainfunc OBJECT src/proxymain.c)
@ -368,6 +394,7 @@ add_executable(3proxy
${3PROXY_CORE_SOURCES}
${MD_SOURCES}
$<TARGET_OBJECTS:srv_modules>
$<TARGET_OBJECTS:srvudppm_obj>
$<TARGET_OBJECTS:mainfunc>
$<TARGET_OBJECTS:common_obj>
$<TARGET_OBJECTS:base64_obj>
@ -417,9 +444,19 @@ target_include_directories(3proxy_crypt PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/libs
)
target_link_libraries(3proxy_crypt PRIVATE Threads::Threads)
if("${3PROXY_BINARY_PREFIX}" STREQUAL "")
set_target_properties(3proxy_crypt PROPERTIES OUTPUT_NAME "mycrypt")
else()
set_target_properties(3proxy_crypt PROPERTIES OUTPUT_NAME "${3PROXY_BINARY_PREFIX}crypt")
endif()
# Build standalone proxy executables
foreach(PROXY_NAME proxy socks pop3p smtpp ftppr tcppm tlspr)
foreach(PROXY_NAME proxy socks pop3p smtpp ftppr tcppm udppm tlspr)
string(TOUPPER "${PROXY_NAME}" _MODULE_OPT)
if(NOT 3PROXY_BUILD_${_MODULE_OPT})
continue()
endif()
if(PROXY_NAME STREQUAL "ftppr" OR PROXY_NAME STREQUAL "proxy")
# ftppr and proxy use ftp_obj
add_executable(${PROXY_NAME}
@ -434,6 +471,10 @@ foreach(PROXY_NAME proxy socks pop3p smtpp ftppr tcppm tlspr)
)
endif()
set_target_properties(${PROXY_NAME} PROPERTIES
OUTPUT_NAME "${3PROXY_BINARY_PREFIX}${PROXY_NAME}"
)
target_include_directories(${PROXY_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
)
@ -443,6 +484,10 @@ foreach(PROXY_NAME proxy socks pop3p smtpp ftppr tcppm tlspr)
NOPORTMAP
)
if(NOT PROXY_NAME STREQUAL "udppm")
target_compile_definitions(${PROXY_NAME} PRIVATE NOUDPMAIN)
endif()
target_link_libraries(${PROXY_NAME} PRIVATE Threads::Threads)
if(PROXY_NAME STREQUAL "proxy")
@ -460,6 +505,10 @@ foreach(PROXY_NAME proxy socks pop3p smtpp ftppr tcppm tlspr)
if(PROXY_NAME STREQUAL "proxy" OR PROXY_NAME STREQUAL "smtpp")
target_sources(${PROXY_NAME} PRIVATE $<TARGET_OBJECTS:base64_obj>)
endif()
if(PROXY_NAME STREQUAL "udppm")
target_sources(${PROXY_NAME} PRIVATE src/hash.c)
endif()
endforeach()
# Plugin output directory
@ -503,10 +552,19 @@ if(PAM_FOUND)
endif()
# Installation rules
install(TARGETS 3proxy 3proxy_crypt proxy socks pop3p smtpp ftppr tcppm tlspr
install(TARGETS 3proxy 3proxy_crypt
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
foreach(PROXY_NAME proxy socks pop3p smtpp ftppr tcppm udppm tlspr)
string(TOUPPER "${PROXY_NAME}" _MODULE_OPT)
if(3PROXY_BUILD_${_MODULE_OPT})
install(TARGETS ${PROXY_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
endif()
endforeach()
# Install plugins
file(GLOB PLUGINFILES "${PLUGIN_OUTPUT_DIR}/*${PLUGIN_SUFFIX}")
if(WIN32)
@ -640,10 +698,32 @@ endif()
# Install man pages
if(NOT WIN32)
file(GLOB MAN3_FILES "${CMAKE_CURRENT_SOURCE_DIR}/man/*.3")
file(GLOB MAN8_FILES "${CMAKE_CURRENT_SOURCE_DIR}/man/*.8")
install(FILES ${MAN3_FILES} DESTINATION ${CMAKE_INSTALL_MANDIR}/man3)
install(FILES ${MAN8_FILES} DESTINATION ${CMAKE_INSTALL_MANDIR}/man8)
# Config man page (section 5) no prefix
file(GLOB MAN5_FILES "${CMAKE_CURRENT_SOURCE_DIR}/man/*.5")
install(FILES ${MAN5_FILES} DESTINATION ${CMAKE_INSTALL_MANDIR}/man5)
# Main 3proxy man page no prefix
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/man/3proxy.8"
DESTINATION ${CMAKE_INSTALL_MANDIR}/man8
)
# 3proxy_crypt man page no prefix (already has 3proxy_)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/man/3proxy_crypt.8")
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/man/3proxy_crypt.8"
DESTINATION ${CMAKE_INSTALL_MANDIR}/man8
)
endif()
# Module man pages installed with binary prefix only if module is built
foreach(_MAN proxy socks pop3p smtpp ftppr tcppm udppm tlspr)
string(TOUPPER "${_MAN}" _MODULE_OPT)
if(3PROXY_BUILD_${_MODULE_OPT})
set(_MAN_SRC "${CMAKE_CURRENT_SOURCE_DIR}/man/${_MAN}.8")
if(EXISTS "${_MAN_SRC}")
install(FILES "${_MAN_SRC}"
DESTINATION ${CMAKE_INSTALL_MANDIR}/man8
RENAME "${3PROXY_BINARY_PREFIX}${_MAN}.8"
)
endif()
endif()
endforeach()
endif()
# Summary
@ -677,3 +757,10 @@ message(STATUS " ODBC: ${ODBC_FOUND}")
message(STATUS "")
message(STATUS " Plugins to build: ${ALL_PLUGINS}")
message(STATUS "")
message(STATUS " Standalone modules:")
message(STATUS " Binary prefix: \"${3PROXY_BINARY_PREFIX}\"")
foreach(_M proxy socks pop3p smtpp ftppr tcppm udppm tlspr)
string(TOUPPER "${_M}" _MO)
message(STATUS " BUILD_${_MO}: ${3PROXY_BUILD_${_MO}}")
endforeach()
message(STATUS "")

View File

@ -5,6 +5,9 @@
# library support. Add -DSAFESQL for poorely written ODBC library / drivers.
BUILDDIR = ../bin/
PREFIX ?= 3proxy_
CRYPT_PREFIX ?= $(PREFIX)
MANDIR ?= /usr/share/man
CC ?= cc
CFLAGS := -c -fno-strict-aliasing -DNOODBC -DFD_SETSIZE=4096 -DWITH_POLL -DWITH_UN $(CFLAGS)
@ -49,14 +52,25 @@ include Makefile.inc
install: all
if [ ! -d "/usr/local/3proxy/bin" ]; then mkdir -p /usr/local/3proxy/bin/; fi
install bin/3proxy /usr/local/3proxy/bin/3proxy
install bin/3proxy_crypt /usr/local/3proxy/bin/3proxy_crypt
install bin/$(CRYPT_PREFIX)crypt /usr/local/3proxy/bin/$(CRYPT_PREFIX)crypt
for f in proxy socks pop3p smtpp ftppr tcppm udppm tlspr; do \
if [ -f bin/$(PREFIX)$$f ]; then install bin/$(PREFIX)$$f /usr/local/3proxy/bin/$(PREFIX)$$f; fi; \
done
install scripts/rc.d/3proxy /usr/local/etc/rc.d/3proxy
install scripts/add3proxyuser.sh /usr/local/3proxy/bin/
if [ -s /usr/local/etc/3proxy/3proxy.cfg ]; then /usr/local/3proxy/3proxy.cfg already exists ; else install scripts/3proxy.cfg /usr/local/etc/3proxy/; fi
if [ -s /usr/local/etc/3proxy/3proxy.cfg ]; then echo /usr/local/3proxy/3proxy.cfg already exists; else install scripts/3proxy.cfg /usr/local/etc/3proxy/; fi
if [ ! -d /var/log/3proxy/ ]; then mkdir /var/log/3proxy/; fi
touch /usr/local/3proxy/passwd
touch /usr/local/3proxy/counters
touch /usr/local/3proxy/bandlimiters
install -d $(MANDIR)/man8
install -m 644 man/3proxy.8 $(MANDIR)/man8/3proxy.8
for f in proxy socks pop3p smtpp ftppr tcppm udppm tlspr; do \
if [ -f man/$$f.8 ]; then install -m 644 man/$$f.8 $(MANDIR)/man8/$(PREFIX)$$f.8; fi; \
done
install -m 644 man/3proxy_crypt.8 $(MANDIR)/man8
install -d $(MANDIR)/man5
install -m 644 man/3proxy.cfg.5 $(MANDIR)/man5/3proxy.cfg.5
echo Run /usr/local/3proxy/bin/add3proxyuser.sh to add \'admin\' user
allplugins:

View File

@ -5,6 +5,8 @@
# library support. Add -DSAFESQL for poorely written ODBC library / drivers.
BUILDDIR = ../bin/
PREFIX ?= 3proxy_
CRYPT_PREFIX ?= $(PREFIX)
CC ?= gcc
CFLAGS := -g -fPIC -O2 -fno-strict-aliasing -c -pthread -DWITHSPLICE -D_GNU_SOURCE -DGETHOSTBYNAME_R -D_THREAD_SAFE -D_REENTRANT -DNOODBC -DFD_SETSIZE=4096 -DWITH_POLL -DWITH_NETFILTER -D WITH_UN $(CFLAGS)
@ -61,13 +63,15 @@ INSTALL = /usr/bin/install
INSTALL_BIN = $(INSTALL) -m 755
INSTALL_DATA = $(INSTALL) -m 644
INSTALL_OBJS = bin/3proxy \
bin/ftppr \
bin/3proxy_crypt \
bin/pop3p \
bin/proxy \
bin/socks \
bin/tcppm \
bin/tlspr
bin/$(CRYPT_PREFIX)crypt \
bin/$(PREFIX)ftppr \
bin/$(PREFIX)pop3p \
bin/$(PREFIX)proxy \
bin/$(PREFIX)smtpp \
bin/$(PREFIX)socks \
bin/$(PREFIX)tcppm \
bin/$(PREFIX)tlspr \
bin/$(PREFIX)udppm
INSTALL_CFG = scripts/3proxy.cfg.chroot
@ -81,7 +85,7 @@ INSTALL_SYSTEMD_SCRIPT = scripts/3proxy.service
CHROOTDIR = $(DESTDIR)$(chroot_prefix)/3proxy
CHROOTREL = ../..$(chroot_prefix)/3proxy
MANDIR3 = $(DESTDIR)$(man_prefix)/man/man3
MANDIR5 = $(DESTDIR)$(man_prefix)/man/man5
MANDIR8 = $(DESTDIR)$(man_prefix)/man/man8
BINDIR = $(DESTDIR)$(exec_prefix)/bin
ETCDIR = $(DESTDIR)/etc/3proxy
@ -124,10 +128,14 @@ install-etc: install-etc-dir install-etc-default-config
done;
install-man:
$(INSTALL_BIN) -d $(MANDIR3)
$(INSTALL_BIN) -d $(MANDIR5)
$(INSTALL_BIN) -d $(MANDIR8)
$(INSTALL_DATA) man/*.3 $(MANDIR3)
$(INSTALL_DATA) man/*.8 $(MANDIR8)
$(INSTALL_DATA) man/3proxy.cfg.5 $(MANDIR5)
$(INSTALL_DATA) man/3proxy.8 $(MANDIR8)
for f in proxy socks pop3p smtpp ftppr tcppm udppm tlspr; do \
if [ -f man/$$f.8 ]; then $(INSTALL_DATA) man/$$f.8 $(MANDIR8)/$(PREFIX)$$f.8; fi; \
done
$(INSTALL_DATA) man/3proxy_crypt.8 $(MANDIR8)
install-init:
$(INSTALL_BIN) -d $(INITDDIR)

View File

@ -6,7 +6,7 @@
# library support. Add -DSAFESQL for poorely written ODBC library / drivers.
BUILDDIR = ../bin/
CC = cc
CC ?= cc
CFLAGS = -xO3 -c -D_SOLARIS -D_THREAD_SAFE -DGETHOSTBYNAME_R -D_REENTRANT -DNOODBC -DFD_SETSIZE=4096 -DWITH_POLL
COUT = -o ./
LN = $(CC)

View File

@ -1,36 +0,0 @@
#
# 3 proxy Makefile for Solaris/gcc
#
#
# remove -DNOODBC from CFLAGS and add -lodbc to LDFLAGS to compile with ODBC
# library support. Add -DSAFESQL for poorely written ODBC library / drivers.
BUILDDIR = ../bin/
CC = gcc
CFLAGS = -O2 -fno-strict-aliasing -c -D_SOLARIS -D_THREAD_SAFE -DGETHOSTBYNAME_R -D_REENTRANT -DNOODBC -DFD_SETSIZE=4096 -DWITH_POLL
COUT = -o ./
LN = $(CC)
LDFLAGS = -O3
DCFLAGS = -fPIC
DLFLAGS = -shared
DLSUFFICS = .ld.so
LIBS = -lpthread -lsocket -lnsl -lresolv -ldl
LIBSPREFIX = -l
LIBSSUFFIX =
LNOUT = -o ./
EXESUFFICS =
OBJSUFFICS = .o
DEFINEOPTION = -D
COMPFILES = *~
REMOVECOMMAND = rm -f
AFTERCLEAN = (find . -type f -name "*.o" -delete && find src/ -type f -name "Makefile.var" -delete && find bin/ -type f -executable -delete) || true
TYPECOMMAND = cat
COMPATLIBS =
MAKEFILE = Makefile.Solaris-gcc
PLUGINS = StringsPlugin TrafficPlugin
include Makefile.inc
allplugins:
@list='$(PLUGINS)'; for p in $$list; do cp Makefile Makefile.var plugins/$$p; cd plugins/$$p ; make ; cd ../.. ; done

View File

@ -1,2 +0,0 @@
SUBDIRS = src man
EXTRA_DIST = doc cfg

View File

@ -1,24 +0,0 @@
#
# 3 proxy Makefile for Microsoft Visual C compiler (for both make and nmake)
#
BUILDDIR = ../bin/
CC = cl
CFLAGS = /FD /MDd /nologo /W3 /ZI /Wp64 /GS /Gs /RTCsu /EHs- /GA /GF /DEBUG /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_WIN32" /c
COUT = /Fo
LN = link
LDFLAGS = /nologo /subsystem:console /machine:I386 /DEBUG
LIBS = ws2_32.lib advapi32.lib odbc32.lib user32.lib
LNOUT = /out:
EXESUFFICS = .exe
OBJSUFFICS = .obj
DEFINEOPTION = /D
COMPFILES = *.pch *.idb
REMOVECOMMAND = del 2>NUL >NUL
TYPECOMMAND = type
COMPATLIBS =
MAKEFILE = Makefile.debug
include Makefile.inc
allplugins:

View File

@ -1,111 +0,0 @@
#
# 3 proxy Makefile for GCC/Linux/Cygwin
#
#
# remove -DNOODBC from CFLAGS and add -lodbc to LIBS to compile with ODBC
# library support. Add -DSAFESQL for poorely written ODBC library / drivers.
BUILDDIR = ../bin/
CC = mips-openwrt-linux-gcc
CFLAGS ?= -g -O2 -fno-strict-aliasing -c -pthread -DGETHOSTBYNAME_R -D_THREAD_SAFE -D_REENTRANT -DNOODBC -DFD_SETSIZE=4096 -DWITH_POLL -DWITH_NETFILTER
COUT = -o
LN = $(CC)
DCFLAGS = -fPIC
LDFLAGS ?= -O2 -fno-strict-aliasing -pthread -s
DLFLAGS = -shared
DLSUFFICS = .ld.so
# -lpthreads may be reuqired on some platforms instead of -pthreads
LIBSPREFIX = -l
LIBSSUFFIX =
LNOUT = -o
EXESUFFICS =
OBJSUFFICS = .o
DEFINEOPTION = -D
COMPFILES = *~
REMOVECOMMAND = rm -f
AFTERCLEAN = (find . -type f -name "*.o" -delete && find src/ -type f -name "Makefile.var" -delete && find bin/ -type f -executable -delete) || true
TYPECOMMAND = cat
COMPATLIBS =
MAKEFILE = Makefile.openwrt-mips
# PamAuth requires libpam, you may require pam-devel package to be installed
# SSLPlugin requires -lcrypto -lssl
#LIBS = -lcrypto -lssl -ldl
LIBS ?= -ldl
#PLUGINS = SSLPlugin StringsPlugin TrafficPlugin PCREPlugin TransparentPlugin PamAuth
PLUGINS ?= StringsPlugin TrafficPlugin TransparentPlugin
OPENSSL_CHECK = $(shell echo "\#include <openssl/ssl.h>\\n int main(){return 0;}" | tr -d \\\\ | cc -x c $(CFLAGS) $(LDFLAGS) -l crypto -l ssl -o testssl - 2>/dev/null && rm testssl && echo true||echo false)
ifeq ($(OPENSSL_CHECK), true)
LIBS += -l crypto -l ssl
PLUGINS += SSLPlugin
endif
PCRE_CHECK = $(shell echo "\#define PCRE2_CODE_UNIT_WIDTH 8\\n\#include <pcre2.h>\\n int main(){return 0;}" | tr -d \\\\ | cc -x c $(CFLAGS) $(LDFLAGS) -l pcre2-8 -o testpcre - 2>/dev/null && rm testpcre && echo true||echo false)
ifeq ($(PCRE_CHECK), true)
PLUGINS += PCREPlugin
endif
PAM_CHECK = $(shell echo "\#include <security/pam_appl.h>\\n int main(){return 0;}" | tr -d \\\\ | cc -x c $(CFLAGS) $(LDFLAGS) -l pam -o testpam - 2>/dev/null && rm testpam && echo true||echo false)
ifeq ($(PAM_CHECK), true)
PLUGINS += PamAuth
endif
include Makefile.inc
allplugins:
@list='$(PLUGINS)'; for p in $$list; do cp Makefile Makefile.var plugins/$$p; cd plugins/$$p ; make ; cd ../.. ; done
DESTDIR =
prefix = /usr/local
exec_prefix = $(prefix)
man_prefix = $(prefix)/share
INSTALL = /usr/bin/install
INSTALL_BIN = $(INSTALL) -m 755
INSTALL_DATA = $(INSTALL) -m 644
INSTALL_OBJS = src/3proxy \
src/ftppr \
src/3proxy_crypt \
src/pop3p \
src/proxy \
src/socks \
src/tcppm
INSTALL_CFG_OBJS = scripts/3proxy.cfg \
scripts/add3proxyuser.sh
INSTALL_CFG_DEST = config
INSTALL_CFG_OBJS2 = passwd counters bandlimiters
MANDIR3 = $(DESTDIR)$(man_prefix)/man/man3
MANDIR8 = $(DESTDIR)$(man_prefix)/man/man8
BINDIR = $(DESTDIR)$(exec_prefix)/bin
ETCDIR = $(DESTDIR)$(prefix)/etc/3proxy
install-bin:
$(INSTALL_BIN) -d $(BINDIR)
$(INSTALL_BIN) -s $(INSTALL_OBJS) $(BINDIR)
install-etc-dir:
$(INSTALL_BIN) -d $(ETCDIR)
install-etc-default-config:
if [ -f $(ETCDIR)/$(INSTALL_CFG_DEST) ]; then \
: ; \
else \
$(INSTALL_DATA) $(INSTALL_CFG_OBJS) $(ETCDIR)/$(INSTALL_CFG_DEST) \
fi
install-etc: install-etc-dir
for file in $(INSTALL_CFG_OBJS2); \
do \
touch $(ETCDIR)/$$file; chmod 0600 $(ETCDIR)/$$file; \
done;
install-man:
$(INSTALL_BIN) -d $(MANDIR3)
$(INSTALL_BIN) -d $(MANDIR8)
$(INSTALL_DATA) man/*.3 $(MANDIR3)
$(INSTALL_DATA) man/*.8 $(MANDIR8)
install: install-bin install-etc install-man

View File

@ -6,6 +6,9 @@
# library support. Add -DSAFESQL for poorely written ODBC library / drivers.
BUILDDIR = ../bin/
PREFIX ?= 3proxy_
CRYPT_PREFIX ?= $(PREFIX)
MANDIR ?= /usr/share/man
CC ?= gcc
# you may need -L/usr/pkg/lib for older NetBSD versions
@ -49,17 +52,28 @@ endif
include Makefile.inc
install: all
if [ ! -d "/usr/local/3proxy/bin" ]; then mkdir -p /usr/local/3proxy/bin/; fi
install bin/3proxy /usr/local/3proxy/bin/3proxy
install bin/3proxy_crypt /usr/local/3proxy/bin/3proxy_crypt
install scripts/rc.d/3proxy /usr/local/etc/rc.d/3proxy
install scripts/add3proxyuser.sh /usr/local/3proxy/bin/
if [ -s /usr/local/etc/3proxy/3proxy.cfg ]; then /usr/local/3proxy/3proxy.cfg already exists ; else install scripts/3proxy.cfg /usr/local/etc/3proxy/; fi
if [ ! -d /var/log/3proxy/ ]; then mkdir /var/log/3proxy/; fi
touch /usr/local/3proxy/passwd
touch /usr/local/3proxy/counters
touch /usr/local/3proxy/bandlimiters
echo Run /usr/local/3proxy/bin/add3proxyuser.sh to add \'admin\' user
if [ ! -d "/usr/local/3proxy/bin" ]; then mkdir -p /usr/local/3proxy/bin/; fi
install bin/3proxy /usr/local/3proxy/bin/3proxy
install bin/$(CRYPT_PREFIX)crypt /usr/local/3proxy/bin/$(CRYPT_PREFIX)crypt
for f in proxy socks pop3p smtpp ftppr tcppm udppm tlspr; do \
if [ -f bin/$(PREFIX)$$f ]; then install bin/$(PREFIX)$$f /usr/local/3proxy/bin/$(PREFIX)$$f; fi; \
done
install scripts/rc.d/3proxy /usr/local/etc/rc.d/3proxy
install scripts/add3proxyuser.sh /usr/local/3proxy/bin/
if [ -s /usr/local/etc/3proxy/3proxy.cfg ]; then echo /usr/local/3proxy/3proxy.cfg already exists; else install scripts/3proxy.cfg /usr/local/etc/3proxy/; fi
if [ ! -d /var/log/3proxy/ ]; then mkdir /var/log/3proxy/; fi
touch /usr/local/3proxy/passwd
touch /usr/local/3proxy/counters
touch /usr/local/3proxy/bandlimiters
install -d $(MANDIR)/man8
install -m 644 man/3proxy.8 $(MANDIR)/man8/3proxy.8
for f in proxy socks pop3p smtpp ftppr tcppm udppm tlspr; do \
if [ -f man/$$f.8 ]; then install -m 644 man/$$f.8 $(MANDIR)/man8/$(PREFIX)$$f.8; fi; \
done
install -m 644 man/3proxy_crypt.8 $(MANDIR)/man8
install -d $(MANDIR)/man5
install -m 644 man/3proxy.cfg.5 $(MANDIR)/man5/3proxy.cfg.5
echo Run /usr/local/3proxy/bin/add3proxyuser.sh to add \'admin\' user
allplugins:
@list='$(PLUGINS)'; for p in $$list; do cp Makefile Makefile.var plugins/$$p; cd plugins/$$p ; make ; cd ../.. ; done

View File

@ -1,10 +1,11 @@
man/3proxy.8
man/3proxy.cfg.3
man/ftppr.8
man/pop3p.8
man/tlspr.8
man/proxy.8
man/smtpp.8
man/socks.8
man/tcppm.8
man/udppm.8
man/3proxy.cfg.5
man/3proxy_ftppr.8
man/3proxy_pop3p.8
man/3proxy_tlspr.8
man/3proxy_proxy.8
man/3proxy_smtpp.8
man/3proxy_socks.8
man/3proxy_tcppm.8
man/3proxy_udppm.8
man/3proxy_crypt.8

View File

@ -4,6 +4,7 @@
<a href="howtoe.html">How To (English, very incomplete)</a><br>
<a href="howtor.html">How To (Russian)</a><br>
<h3>Man pages:</h3>
<br><A HREF="man8/3proxy_crypt.8.html">3proxy_crypt.8</A>
<br><A HREF="man8/3proxy.8.html">3proxy.8</A>
<br><A HREF="man8/ftppr.8.html">ftppr.8</A>
<br><A HREF="man8/pop3p.8.html">pop3p.8</A>
@ -13,5 +14,5 @@
<br><A HREF="man8/tcppm.8.html">tcppm.8</A>
<br><A HREF="man8/tlspr.8.html">tlspr.8</A>
<br><A HREF="man8/udppm.8.html">udppm.8</A>
<br><A HREF="man3/3proxy.cfg.3.html">3proxy.cfg.3</A>
<br><A HREF="man5/3proxy.cfg.5.html">3proxy.cfg.5</A>
</body></html>

View File

@ -930,8 +930,10 @@ users test1:CL:password1
&quot;test2:CR:$1$lFDGlder$pLRb4cU2D7GAT58YQvY49.&quot; <br>
users test3:NT:BD7DFBF29A93F93C63CB84790DA00E63 <br>
Note: double quotes are required because the password
contains a $ sign. <b><br>
flush</b> <br>
contains a $ sign.</p>
<p style="margin-left:6%; margin-top: 1em"><b>flush</b>
<br>
empty the active access list. The access list must be
flushed every time you create a new access list for a new
service. For example: <br>

View File

@ -195,7 +195,7 @@ to <b>3proxy@3proxy.org</b></p>
</h2>
<p style="margin-left:6%; margin-top: 1em">3proxy.cfg(3),
<p style="margin-left:6%; margin-top: 1em">3proxy.cfg(5),
proxy(8), ftppr(8), socks(8), pop3p(8), tcppm(8), udppm(8),
kill(1), syslogd(8), <br>
https://3proxy.org/</p>

View File

@ -0,0 +1,168 @@
<!-- Creator : groff version 1.24.1 -->
<html>
<head>
</head>
<body>
<h1 align="center">3proxy_crypt</h1>
<a href="#NAME">NAME</a><br>
<a href="#SYNOPSIS">SYNOPSIS</a><br>
<a href="#DESCRIPTION">DESCRIPTION</a><br>
<a href="#OPTIONS">OPTIONS</a><br>
<a href="#EXAMPLE">EXAMPLE</a><br>
<a href="#NOTES">NOTES</a><br>
<a href="#BUGS">BUGS</a><br>
<a href="#SEE ALSO">SEE ALSO</a><br>
<a href="#AUTHORS">AUTHORS</a><br>
<hr>
<h2>NAME
<a name="NAME"></a>
</h2>
<p style="margin-left:6%; margin-top: 1em"><b>3proxy_crypt</b>
- utility to generate encrypted passwords for 3proxy</p>
<h2>SYNOPSIS
<a name="SYNOPSIS"></a>
</h2>
<p style="margin-left:6%; margin-top: 1em"><b>3proxy_crypt</b>
<i>password</i> <b><br>
3proxy_crypt</b> <i>salt password</i></p>
<h2>DESCRIPTION
<a name="DESCRIPTION"></a>
</h2>
<p style="margin-left:6%; margin-top: 1em"><i><b>3proxy_crypt</b></i>
is a utility to generate encrypted password hashes for use
with 3proxy configuration. Encrypted passwords allow the
system to avoid storing passwords in cleartext in
configuration files.</p>
<p style="margin-left:6%; margin-top: 1em">When invoked
with a single argument, it produces an NT password hash
(MD4-based, suitable for NTLM authentication). The output is
prefixed with <b>NT:</b>.</p>
<p style="margin-left:6%; margin-top: 1em">When invoked
with two arguments (salt and password), it produces a
BLAKE2b password hash. The salt length is limited to 64
characters. The output is prefixed with <b>CR:</b>.</p>
<p style="margin-left:6%; margin-top: 1em">The resulting
hash can be used in the 3proxy configuration file with the
<b>users</b> directive instead of a cleartext password.</p>
<h2>OPTIONS
<a name="OPTIONS"></a>
</h2>
<p style="margin-left:6%; margin-top: 1em"><i>password</i></p>
<p style="margin-left:15%;">Cleartext password to
encrypt.</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="6%"></td>
<td width="5%">
<p><i>salt</i></p></td>
<td width="4%"></td>
<td width="65%">
<p>Salt string for BLAKE2b hashing (max 64 characters).</p></td>
<td width="20%">
</td></tr>
</table>
<h2>EXAMPLE
<a name="EXAMPLE"></a>
</h2>
<p style="margin-left:6%; margin-top: 1em">Generate NT
password hash:</p>
<p style="margin-left:15%;">3proxy_crypt
MySecretPassword</p>
<p style="margin-left:6%;">Result:</p>
<p style="margin-left:15%;">NT:3F7E6D8D96E8E7A9B0C1D2E3F4A5B6C7</p>
<p style="margin-left:6%;">Generate BLAKE2b password hash
with salt:</p>
<p style="margin-left:15%;">3proxy_crypt MySalt
MySecretPassword</p>
<p style="margin-left:6%;">Result:</p>
<p style="margin-left:15%;">CR:$3$MySalt$...</p>
<p style="margin-left:6%;">Using in 3proxy.cfg:</p>
<p style="margin-left:15%;">users
user1:CR:$3$MySalt$...</p>
<h2>NOTES
<a name="NOTES"></a>
</h2>
<p style="margin-left:6%; margin-top: 1em">The NT hash uses
the RSA MD4 Message-Digest Algorithm. The BLAKE2b hash uses
the BLAKE2 cryptographic hash function.</p>
<p style="margin-left:6%; margin-top: 1em">When a password
hash is prefixed with <b>NT:</b> or <b>CR:</b>, 3proxy uses
the corresponding algorithm to verify passwords instead of
comparing cleartext strings.</p>
<h2>BUGS
<a name="BUGS"></a>
</h2>
<p style="margin-left:6%; margin-top: 1em">Report all bugs
to <b>3proxy@3proxy.org</b></p>
<h2>SEE ALSO
<a name="SEE ALSO"></a>
</h2>
<p style="margin-left:6%; margin-top: 1em">3proxy(8),
3proxy.cfg(5), <br>
https://3proxy.org/</p>
<h2>AUTHORS
<a name="AUTHORS"></a>
</h2>
<p style="margin-left:6%; margin-top: 1em">3proxy is
designed by Vladimir 3APA3A Dubrovin
(<i>3proxy@3proxy.org</i>)</p>
<hr>
</body>
</html>

View File

@ -140,7 +140,7 @@ configuration file
Report all bugs to
.BR 3proxy@3proxy.org
.SH SEE ALSO
3proxy.cfg(3), proxy(8), ftppr(8), socks(8), pop3p(8), tcppm(8), udppm(8),
3proxy.cfg(5), proxy(8), ftppr(8), socks(8), pop3p(8), tcppm(8), udppm(8),
kill(1), syslogd(8),
.br
https://3proxy.org/

81
man/3proxy_crypt.8 Normal file
View File

@ -0,0 +1,81 @@
.TH 3proxy_crypt "8" "April 2026" "3proxy 0.9" "Universal proxy server"
.SH NAME
.B 3proxy_crypt
\- utility to generate encrypted passwords for 3proxy
.SH SYNOPSIS
.B 3proxy_crypt
.I password
.br
.B 3proxy_crypt
.I salt password
.SH DESCRIPTION
.B 3proxy_crypt
is a utility to generate encrypted password hashes for use with 3proxy
configuration. Encrypted passwords allow the system to avoid storing
passwords in cleartext in configuration files.
.PP
When invoked with a single argument, it produces an NT password hash
(MD4-based, suitable for NTLM authentication). The output is prefixed with
.BR NT: .
.PP
When invoked with two arguments (salt and password), it produces a BLAKE2b
password hash. The salt length is limited to 64 characters. The output is
prefixed with
.BR CR: .
.PP
The resulting hash can be used in the 3proxy configuration file with the
.B users
directive instead of a cleartext password.
.SH OPTIONS
.TP
.I password
Cleartext password to encrypt.
.TP
.I salt
Salt string for BLAKE2b hashing (max 64 characters).
.SH EXAMPLE
.TP
Generate NT password hash:
.RS
3proxy_crypt MySecretPassword
.RE
.TP
Result:
.RS
NT:3F7E6D8D96E8E7A9B0C1D2E3F4A5B6C7
.RE
.TP
Generate BLAKE2b password hash with salt:
.RS
3proxy_crypt MySalt MySecretPassword
.RE
.TP
Result:
.RS
CR:$3$MySalt$...
.RE
.TP
Using in 3proxy.cfg:
.RS
users user1:CR:$3$MySalt$...
.RE
.SH NOTES
The NT hash uses the RSA MD4 Message-Digest Algorithm. The BLAKE2b hash
uses the BLAKE2 cryptographic hash function.
.PP
When a password hash is prefixed with
.B NT:
or
.BR CR: ,
3proxy uses the corresponding algorithm to verify passwords instead of
comparing cleartext strings.
.SH BUGS
Report all bugs to
.BR 3proxy@3proxy.org
.SH SEE ALSO
3proxy(8), 3proxy.cfg(5),
.br
https://3proxy.org/
.SH AUTHORS
3proxy is designed by Vladimir 3APA3A Dubrovin
.RI ( 3proxy@3proxy.org )

View File

@ -32,13 +32,15 @@ make clean
%files
/bin/3proxy
/bin/ftppr
/bin/3proxy_crypt
/bin/pop3p
/bin/proxy
/bin/socks
/bin/tcppm
/bin/tlspr
/bin/3proxy_ftppr
/bin/3proxy_pop3p
/bin/3proxy_proxy
/bin/3proxy_smtpp
/bin/3proxy_socks
/bin/3proxy_tcppm
/bin/3proxy_tlspr
/bin/3proxy_udppm
%config(noreplace) /etc/3proxy/3proxy.cfg
/etc/3proxy/conf
/etc/init.d/3proxy
@ -48,7 +50,7 @@ make clean
%config(noreplace) /usr/local/3proxy/conf/bandlimiters
%config(noreplace) /usr/local/3proxy/conf/counters
/usr/local/3proxy/libexec/*.ld.so
/usr/share/man/man3/*
/usr/share/man/man5/3proxy.cfg.5
/usr/share/man/man8/*
/var/log/3proxy

View File

@ -66,9 +66,9 @@ void __stdcall CommandHandler( DWORD dwCommand )
Sleep(2000);
SetStatus( SERVICE_STOPPED, 0, 0 );
#ifndef NOODBC
pthread_mutex_lock(&log_mutex);
_3proxy_mutex_lock(&log_mutex);
close_sql();
pthread_mutex_unlock(&log_mutex);
_3proxy_mutex_unlock(&log_mutex);
#endif
break;
case SERVICE_CONTROL_PAUSE:
@ -118,13 +118,6 @@ void mysigpause (int sig){
void mysigterm (int sig){
conf.paused++;
usleep(999*SLEEPTIME);
usleep(999*SLEEPTIME);
#ifndef NOODBC
pthread_mutex_lock(&log_mutex);
close_sql();
pthread_mutex_unlock(&log_mutex);
#endif
conf.timetoexit = 1;
}
@ -512,22 +505,23 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int
return 1;
}
pthread_mutex_init(&config_mutex, NULL);
pthread_mutex_init(&bandlim_mutex, NULL);
pthread_mutex_init(&connlim_mutex, NULL);
pthread_mutex_init(&tc_mutex, NULL);
pthread_mutex_init(&log_mutex, NULL);
_3proxy_mutex_init(&config_mutex);
_3proxy_mutex_init(&bandlim_mutex);
_3proxy_mutex_init(&connlim_mutex);
_3proxy_mutex_init(&tc_mutex);
_3proxy_mutex_init(&log_mutex);
#ifndef NORADIUS
pthread_mutex_init(&rad_mutex, NULL);
_3proxy_mutex_init(&rad_mutex);
#endif
#ifdef _WIN32
if(!CreatePipe(&conf.threadinit[0], &conf.threadinit[1], NULL, 1)){
#else
if(pipe(conf.threadinit)) {
#endif
fprintf(stderr, "CreatePipe failed\n");
conf.threadinit = CreateSemaphore(NULL, 0, 1, NULL);
if(!conf.threadinit){
fprintf(stderr, "semaphore init failed\n");
return 1;
};
}
#else
_3proxy_mutex_init(&conf.threadinit);
#endif
freeconf(&conf);
res = readconfig(fp);

View File

@ -2,8 +2,7 @@
# 3 proxy common Makefile
#
all: $(BUILDDIR)3proxy$(EXESUFFICS) $(BUILDDIR)3proxy_crypt$(EXESUFFICS) $(BUILDDIR)pop3p$(EXESUFFICS) $(BUILDDIR)smtpp$(EXESUFFICS) $(BUILDDIR)ftppr$(EXESUFFICS) $(BUILDDIR)tcppm$(EXESUFFICS) $(BUILDDIR)tlspr$(EXESUFFICS) $(BUILDDIR)socks$(EXESUFFICS) $(BUILDDIR)proxy$(EXESUFFICS) allplugins
all: $(BUILDDIR)3proxy$(EXESUFFICS) $(BUILDDIR)$(CRYPT_PREFIX)crypt$(EXESUFFICS) $(BUILDDIR)$(PREFIX)pop3p$(EXESUFFICS) $(BUILDDIR)$(PREFIX)smtpp$(EXESUFFICS) $(BUILDDIR)$(PREFIX)ftppr$(EXESUFFICS) $(BUILDDIR)$(PREFIX)tcppm$(EXESUFFICS) $(BUILDDIR)$(PREFIX)udppm$(EXESUFFICS) $(BUILDDIR)$(PREFIX)tlspr$(EXESUFFICS) $(BUILDDIR)$(PREFIX)socks$(EXESUFFICS) $(BUILDDIR)$(PREFIX)proxy$(EXESUFFICS) allplugins
sockmap$(OBJSUFFICS): sockmap.c proxy.h structures.h
$(CC) $(CFLAGS) sockmap.c
@ -27,50 +26,56 @@ sockgetchar$(OBJSUFFICS): sockgetchar.c proxy.h structures.h
$(CC) $(CFLAGS) sockgetchar.c
proxy$(OBJSUFFICS): proxy.c proxy.h structures.h proxymain.c
$(CC) $(CFLAGS) $(DEFINEOPTION)WITHMAIN $(DEFINEOPTION)NOPORTMAP $(DEFINEOPTION)ANONYMOUS proxy.c
$(CC) $(CFLAGS) $(DEFINEOPTION)WITHMAIN $(DEFINEOPTION)NOPORTMAP $(DEFINEOPTION)ANONYMOUS $(DEFINEOPTION)NOUDPMAIN proxy.c
pop3p$(OBJSUFFICS): pop3p.c proxy.h structures.h proxymain.c
$(CC) $(CFLAGS) $(DEFINEOPTION)WITHMAIN $(DEFINEOPTION)NOPORTMAP pop3p.c
$(CC) $(CFLAGS) $(DEFINEOPTION)WITHMAIN $(DEFINEOPTION)NOPORTMAP $(DEFINEOPTION)NOUDPMAIN pop3p.c
smtpp$(OBJSUFFICS): smtpp.c proxy.h structures.h proxymain.c
$(CC) $(CFLAGS) $(DEFINEOPTION)WITHMAIN $(DEFINEOPTION)NOPORTMAP smtpp.c
$(CC) $(CFLAGS) $(DEFINEOPTION)WITHMAIN $(DEFINEOPTION)NOPORTMAP $(DEFINEOPTION)NOUDPMAIN smtpp.c
ftppr$(OBJSUFFICS): ftppr.c proxy.h structures.h proxymain.c
$(CC) $(CFLAGS) $(DEFINEOPTION)WITHMAIN $(DEFINEOPTION)NOPORTMAP ftppr.c
$(CC) $(CFLAGS) $(DEFINEOPTION)WITHMAIN $(DEFINEOPTION)NOPORTMAP $(DEFINEOPTION)NOUDPMAIN ftppr.c
tcppm$(OBJSUFFICS): tcppm.c proxy.h structures.h proxymain.c
$(CC) $(CFLAGS) $(DEFINEOPTION)WITHMAIN $(DEFINEOPTION)PORTMAP tcppm.c
$(CC) $(CFLAGS) $(DEFINEOPTION)WITHMAIN $(DEFINEOPTION)PORTMAP $(DEFINEOPTION)NOUDPMAIN tcppm.c
udppm$(OBJSUFFICS): udppm.c proxy.h structures.h proxymain.c
$(CC) $(CFLAGS) $(DEFINEOPTION)WITHMAIN $(DEFINEOPTION)PORTMAP udppm.c
tlspr$(OBJSUFFICS): tlspr.c proxy.h structures.h proxymain.c
$(CC) $(CFLAGS) $(DEFINEOPTION)WITHMAIN $(DEFINEOPTION)PORTMAP tlspr.c
$(CC) $(CFLAGS) $(DEFINEOPTION)WITHMAIN $(DEFINEOPTION)PORTMAP $(DEFINEOPTION)NOUDPMAIN tlspr.c
socks$(OBJSUFFICS): socks.c proxy.h structures.h proxymain.c
$(CC) $(CFLAGS) $(DEFINEOPTION)WITHMAIN $(DEFINEOPTION)NOPORTMAP socks.c
$(CC) $(CFLAGS) $(DEFINEOPTION)WITHMAIN $(DEFINEOPTION)NOPORTMAP $(DEFINEOPTION)NOUDPMAIN socks.c
3proxy$(OBJSUFFICS): 3proxy.c proxy.h structures.h
$(CC) $(CFLAGS) 3proxy.c
$(BUILDDIR)proxy$(EXESUFFICS): sockmap$(OBJSUFFICS) proxy$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) log$(OBJSUFFICS) base64$(OBJSUFFICS) ftp$(OBJSUFFICS) $(COMPATLIBS)
$(LN) $(LNOUT)$(BUILDDIR)proxy$(EXESUFFICS) $(LDFLAGS) sockmap$(OBJSUFFICS) proxy$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) log$(OBJSUFFICS) common$(OBJSUFFICS) base64$(OBJSUFFICS) ftp$(OBJSUFFICS) $(COMPATLIBS) $(LIBS)
$(BUILDDIR)$(PREFIX)proxy$(EXESUFFICS): sockmap$(OBJSUFFICS) proxy$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) log$(OBJSUFFICS) base64$(OBJSUFFICS) ftp$(OBJSUFFICS) $(COMPATLIBS)
$(LN) $(LNOUT)$(BUILDDIR)$(PREFIX)proxy$(EXESUFFICS) $(LDFLAGS) sockmap$(OBJSUFFICS) proxy$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) log$(OBJSUFFICS) common$(OBJSUFFICS) base64$(OBJSUFFICS) ftp$(OBJSUFFICS) $(COMPATLIBS) $(LIBS)
$(BUILDDIR)pop3p$(EXESUFFICS): sockmap$(OBJSUFFICS) pop3p$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) log$(OBJSUFFICS) $(COMPATLIBS)
$(LN) $(LNOUT)$(BUILDDIR)pop3p$(EXESUFFICS) $(LDFLAGS) sockmap$(OBJSUFFICS) pop3p$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) log$(OBJSUFFICS) common$(OBJSUFFICS) $(COMPATLIBS) $(LIBS)
$(BUILDDIR)$(PREFIX)pop3p$(EXESUFFICS): sockmap$(OBJSUFFICS) pop3p$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) log$(OBJSUFFICS) $(COMPATLIBS)
$(LN) $(LNOUT)$(BUILDDIR)$(PREFIX)pop3p$(EXESUFFICS) $(LDFLAGS) sockmap$(OBJSUFFICS) pop3p$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) log$(OBJSUFFICS) common$(OBJSUFFICS) $(COMPATLIBS) $(LIBS)
$(BUILDDIR)smtpp$(EXESUFFICS): sockmap$(OBJSUFFICS) smtpp$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) log$(OBJSUFFICS) base64$(OBJSUFFICS) $(COMPATLIBS)
$(LN) $(LNOUT)$(BUILDDIR)smtpp$(EXESUFFICS) $(LDFLAGS) sockmap$(OBJSUFFICS) smtpp$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) base64$(OBJSUFFICS) log$(OBJSUFFICS) common$(OBJSUFFICS) $(COMPATLIBS) $(LIBS)
$(BUILDDIR)$(PREFIX)smtpp$(EXESUFFICS): sockmap$(OBJSUFFICS) smtpp$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) log$(OBJSUFFICS) base64$(OBJSUFFICS) $(COMPATLIBS)
$(LN) $(LNOUT)$(BUILDDIR)$(PREFIX)smtpp$(EXESUFFICS) $(LDFLAGS) sockmap$(OBJSUFFICS) smtpp$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) base64$(OBJSUFFICS) log$(OBJSUFFICS) common$(OBJSUFFICS) $(COMPATLIBS) $(LIBS)
$(BUILDDIR)ftppr$(EXESUFFICS): sockmap$(OBJSUFFICS) ftppr$(OBJSUFFICS) ftp$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) log$(OBJSUFFICS) $(COMPATLIBS)
$(LN) $(LNOUT)$(BUILDDIR)ftppr$(EXESUFFICS) $(LDFLAGS) sockmap$(OBJSUFFICS) ftppr$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) log$(OBJSUFFICS) ftp$(OBJSUFFICS) $(COMPATLIBS) $(LIBS)
$(BUILDDIR)$(PREFIX)ftppr$(EXESUFFICS): sockmap$(OBJSUFFICS) ftppr$(OBJSUFFICS) ftp$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) log$(OBJSUFFICS) $(COMPATLIBS)
$(LN) $(LNOUT)$(BUILDDIR)$(PREFIX)ftppr$(EXESUFFICS) $(LDFLAGS) sockmap$(OBJSUFFICS) ftppr$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) log$(OBJSUFFICS) ftp$(OBJSUFFICS) $(COMPATLIBS) $(LIBS)
$(BUILDDIR)socks$(EXESUFFICS): sockmap$(OBJSUFFICS) socks$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) log$(OBJSUFFICS)
$(LN) $(LNOUT)$(BUILDDIR)socks$(EXESUFFICS) $(LDFLAGS) sockmap$(OBJSUFFICS) socks$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) log$(OBJSUFFICS) common$(OBJSUFFICS) $(LIBS)
$(BUILDDIR)$(PREFIX)socks$(EXESUFFICS): sockmap$(OBJSUFFICS) socks$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) log$(OBJSUFFICS)
$(LN) $(LNOUT)$(BUILDDIR)$(PREFIX)socks$(EXESUFFICS) $(LDFLAGS) sockmap$(OBJSUFFICS) socks$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) log$(OBJSUFFICS) common$(OBJSUFFICS) $(LIBS)
$(BUILDDIR)tcppm$(EXESUFFICS): sockmap$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) tcppm$(OBJSUFFICS) common$(OBJSUFFICS) log$(OBJSUFFICS)
$(LN) $(LNOUT)$(BUILDDIR)tcppm$(EXESUFFICS) $(LDFLAGS) sockmap$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) tcppm$(OBJSUFFICS) log$(OBJSUFFICS) common$(OBJSUFFICS) $(LIBS)
$(BUILDDIR)$(PREFIX)tcppm$(EXESUFFICS): sockmap$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) tcppm$(OBJSUFFICS) common$(OBJSUFFICS) log$(OBJSUFFICS)
$(LN) $(LNOUT)$(BUILDDIR)$(PREFIX)tcppm$(EXESUFFICS) $(LDFLAGS) sockmap$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) tcppm$(OBJSUFFICS) log$(OBJSUFFICS) common$(OBJSUFFICS) $(LIBS)
$(BUILDDIR)tlspr$(EXESUFFICS): sockmap$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) tlspr$(OBJSUFFICS) common$(OBJSUFFICS) log$(OBJSUFFICS)
$(LN) $(LNOUT)$(BUILDDIR)tlspr$(EXESUFFICS) $(LDFLAGS) sockmap$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) tlspr$(OBJSUFFICS) log$(OBJSUFFICS) common$(OBJSUFFICS) $(LIBS)
$(BUILDDIR)$(PREFIX)udppm$(EXESUFFICS): sockmap$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) udppm$(OBJSUFFICS) common$(OBJSUFFICS) log$(OBJSUFFICS) hash$(OBJSUFFICS)
$(LN) $(LNOUT)$(BUILDDIR)$(PREFIX)udppm$(EXESUFFICS) $(LDFLAGS) sockmap$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) udppm$(OBJSUFFICS) log$(OBJSUFFICS) common$(OBJSUFFICS) hash$(OBJSUFFICS) $(LIBS)
$(BUILDDIR)$(PREFIX)tlspr$(EXESUFFICS): sockmap$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) tlspr$(OBJSUFFICS) common$(OBJSUFFICS) log$(OBJSUFFICS)
$(LN) $(LNOUT)$(BUILDDIR)$(PREFIX)tlspr$(EXESUFFICS) $(LDFLAGS) sockmap$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) tlspr$(OBJSUFFICS) log$(OBJSUFFICS) common$(OBJSUFFICS) $(LIBS)
mainfunc$(OBJSUFFICS): proxy.h structures.h proxymain.c
$(CC) $(COUT)mainfunc$(OBJSUFFICS) $(CFLAGS) $(DEFINEOPTION)MODULEMAINFUNC=mainfunc proxymain.c
@ -123,6 +128,9 @@ redirect$(OBJSUFFICS): redirect.c proxy.h structures.h
hash$(OBJSUFFICS): hash.c proxy.h structures.h
$(CC) $(COUT)hash$(OBJSUFFICS) $(CFLAGS) hash.c
hashtables$(OBJSUFFICS): hashtables.c proxy.h structures.h
$(CC) $(COUT)hashtables$(OBJSUFFICS) $(CFLAGS) hashtables.c
resolve$(OBJSUFFICS): resolve.c proxy.h structures.h
$(CC) $(COUT)resolve$(OBJSUFFICS) $(CFLAGS) resolve.c
@ -153,12 +161,12 @@ md5$(OBJSUFFICS): libs/md5.h libs/md5.c
blake2$(OBJSUFFICS): libs/blake2.h libs/blake2-impl.h libs/blake2b-ref.c
$(CC) $(COUT)blake2$(OBJSUFFICS) $(CFLAGS) libs/blake2b-ref.c
$(BUILDDIR)3proxy_crypt$(EXESUFFICS): md4$(OBJSUFFICS) blake2$(OBJSUFFICS) 3proxy_cryptmain$(OBJSUFFICS) base64$(OBJSUFFICS)
$(LN) $(LNOUT)$(BUILDDIR)3proxy_crypt$(EXESUFFICS) $(LDFLAGS) md4$(OBJSUFFICS) blake2$(OBJSUFFICS) base64$(OBJSUFFICS) 3proxy_cryptmain$(OBJSUFFICS)
$(BUILDDIR)$(CRYPT_PREFIX)crypt$(EXESUFFICS): md4$(OBJSUFFICS) blake2$(OBJSUFFICS) 3proxy_cryptmain$(OBJSUFFICS) base64$(OBJSUFFICS)
$(LN) $(LNOUT)$(BUILDDIR)$(CRYPT_PREFIX)crypt$(EXESUFFICS) $(LDFLAGS) md4$(OBJSUFFICS) blake2$(OBJSUFFICS) base64$(OBJSUFFICS) 3proxy_cryptmain$(OBJSUFFICS)
stringtable$(OBJSUFFICS): stringtable.c
$(CC) $(COUT)stringtable$(OBJSUFFICS) $(CFLAGS) stringtable.c
$(BUILDDIR)3proxy$(EXESUFFICS): 3proxy$(OBJSUFFICS) mainfunc$(OBJSUFFICS) srvproxy$(OBJSUFFICS) srvpop3p$(OBJSUFFICS) srvsmtpp$(OBJSUFFICS) srvftppr$(OBJSUFFICS) srvsocks$(OBJSUFFICS) srvtcppm$(OBJSUFFICS) srvtlspr$(OBJSUFFICS) srvauto$(OBJSUFFICS) srvudppm$(OBJSUFFICS) sockmap$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) auth$(OBJSUFFICS) acl$(OBJSUFFICS) limiter$(OBJSUFFICS) redirect$(OBJSUFFICS) authradius$(OBJSUFFICS) hash$(OBJSUFFICS) resolve$(OBJSUFFICS) sql$(OBJSUFFICS) conf$(OBJSUFFICS) log$(OBJSUFFICS) datatypes$(OBJSUFFICS) md4$(OBJSUFFICS) md5$(OBJSUFFICS) blake2$(OBJSUFFICS) 3proxy_crypt$(OBJSUFFICS) base64$(OBJSUFFICS) ftp$(OBJSUFFICS) stringtable$(OBJSUFFICS) srvwebadmin$(OBJSUFFICS) srvdnspr$(OBJSUFFICS) plugins$(OBJSUFFICS) $(COMPATLIBS) $(VERSIONDEP)
$(LN) $(LNOUT)$(BUILDDIR)3proxy$(EXESUFFICS) $(LDFLAGS) $(VERFILE) 3proxy$(OBJSUFFICS) mainfunc$(OBJSUFFICS) auth$(OBJSUFFICS) acl$(OBJSUFFICS) limiter$(OBJSUFFICS) redirect$(OBJSUFFICS) authradius$(OBJSUFFICS) hash$(OBJSUFFICS) resolve$(OBJSUFFICS) sql$(OBJSUFFICS) conf$(OBJSUFFICS) datatypes$(OBJSUFFICS) srvauto$(OBJSUFFICS) srvproxy$(OBJSUFFICS) srvpop3p$(OBJSUFFICS) srvsmtpp$(OBJSUFFICS) srvftppr$(OBJSUFFICS) srvsocks$(OBJSUFFICS) srvtcppm$(OBJSUFFICS) srvtlspr$(OBJSUFFICS) srvudppm$(OBJSUFFICS) sockmap$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) log$(OBJSUFFICS) 3proxy_crypt$(OBJSUFFICS) md5$(OBJSUFFICS) blake2$(OBJSUFFICS) md4$(OBJSUFFICS) base64$(OBJSUFFICS) ftp$(OBJSUFFICS) stringtable$(OBJSUFFICS) srvwebadmin$(OBJSUFFICS) srvdnspr$(OBJSUFFICS) plugins$(OBJSUFFICS) $(COMPATLIBS) $(LIBS)
$(BUILDDIR)3proxy$(EXESUFFICS): 3proxy$(OBJSUFFICS) mainfunc$(OBJSUFFICS) srvproxy$(OBJSUFFICS) srvpop3p$(OBJSUFFICS) srvsmtpp$(OBJSUFFICS) srvftppr$(OBJSUFFICS) srvsocks$(OBJSUFFICS) srvtcppm$(OBJSUFFICS) srvtlspr$(OBJSUFFICS) srvauto$(OBJSUFFICS) srvudppm$(OBJSUFFICS) sockmap$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) auth$(OBJSUFFICS) acl$(OBJSUFFICS) limiter$(OBJSUFFICS) redirect$(OBJSUFFICS) authradius$(OBJSUFFICS) hash$(OBJSUFFICS) hashtables$(OBJSUFFICS) resolve$(OBJSUFFICS) sql$(OBJSUFFICS) conf$(OBJSUFFICS) log$(OBJSUFFICS) datatypes$(OBJSUFFICS) md4$(OBJSUFFICS) md5$(OBJSUFFICS) blake2$(OBJSUFFICS) 3proxy_crypt$(OBJSUFFICS) base64$(OBJSUFFICS) ftp$(OBJSUFFICS) stringtable$(OBJSUFFICS) srvwebadmin$(OBJSUFFICS) srvdnspr$(OBJSUFFICS) plugins$(OBJSUFFICS) $(COMPATLIBS) $(VERSIONDEP)
$(LN) $(LNOUT)$(BUILDDIR)3proxy$(EXESUFFICS) $(LDFLAGS) $(VERFILE) 3proxy$(OBJSUFFICS) mainfunc$(OBJSUFFICS) auth$(OBJSUFFICS) acl$(OBJSUFFICS) limiter$(OBJSUFFICS) redirect$(OBJSUFFICS) authradius$(OBJSUFFICS) hash$(OBJSUFFICS) hashtables$(OBJSUFFICS) resolve$(OBJSUFFICS) sql$(OBJSUFFICS) conf$(OBJSUFFICS) datatypes$(OBJSUFFICS) srvauto$(OBJSUFFICS) srvproxy$(OBJSUFFICS) srvpop3p$(OBJSUFFICS) srvsmtpp$(OBJSUFFICS) srvftppr$(OBJSUFFICS) srvsocks$(OBJSUFFICS) srvtcppm$(OBJSUFFICS) srvtlspr$(OBJSUFFICS) srvudppm$(OBJSUFFICS) sockmap$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) log$(OBJSUFFICS) 3proxy_crypt$(OBJSUFFICS) md5$(OBJSUFFICS) blake2$(OBJSUFFICS) md4$(OBJSUFFICS) base64$(OBJSUFFICS) ftp$(OBJSUFFICS) stringtable$(OBJSUFFICS) srvwebadmin$(OBJSUFFICS) srvdnspr$(OBJSUFFICS) plugins$(OBJSUFFICS) $(COMPATLIBS) $(LIBS)

View File

@ -20,13 +20,13 @@ int alwaysauth(struct clientparam * param){
res = doconnect(param);
if(!res){
if(conf.bandlimfunc && (conf.bandlimiter||conf.bandlimiterout)){
pthread_mutex_lock(&bandlim_mutex);
_3proxy_mutex_lock(&bandlim_mutex);
initbandlims(param);
pthread_mutex_unlock(&bandlim_mutex);
_3proxy_mutex_unlock(&bandlim_mutex);
}
if(conf.trafcountfunc && conf.trafcounter) {
pthread_mutex_lock(&tc_mutex);
_3proxy_mutex_lock(&tc_mutex);
for(tc = conf.trafcounter; tc; tc = tc->next) {
if(tc->disabled) continue;
if(ACLmatches(tc->ace, param)){
@ -40,7 +40,7 @@ int alwaysauth(struct clientparam * param){
if(tc->ace->action != COUNTALL) continue;
}
if(tc->traflim64 <= tc->traf64) {
pthread_mutex_unlock(&tc_mutex);
_3proxy_mutex_unlock(&tc_mutex);
return 10;
}
param->trafcountfunc = conf.trafcountfunc;
@ -55,14 +55,14 @@ int alwaysauth(struct clientparam * param){
continue;
}
if(tc->traflim64 <= tc->traf64) {
pthread_mutex_unlock(&tc_mutex);
_3proxy_mutex_unlock(&tc_mutex);
return 10;
}
param->trafcountfunc = conf.trafcountfunc;
param->maxtrafout64 = tc->traflim64 - tc->traf64;
}
}
pthread_mutex_unlock(&tc_mutex);
_3proxy_mutex_unlock(&tc_mutex);
}
}
return res;

View File

@ -166,7 +166,7 @@ static int ntry = 0;
int nradservers = 0;
char radiussecret[64]="";
pthread_mutex_t rad_mutex;
_3proxy_mutex_t rad_mutex;
void md5_calc(unsigned char *output, unsigned char *input,
unsigned int inputlen);
@ -327,11 +327,11 @@ int radsend(struct clientparam * param, int auth, int stop){
memset(&packet, 0, sizeof(packet));
pthread_mutex_lock(&rad_mutex);
_3proxy_mutex_lock(&rad_mutex);
if(auth)random_vector(packet.vector, param);
id = ((ntry++) & 0xff);
pthread_mutex_unlock(&rad_mutex);
_3proxy_mutex_unlock(&rad_mutex);
packet.code = auth?PW_AUTHENTICATION_REQUEST:PW_ACCOUNTING_REQUEST;
packet.id=id;

View File

@ -38,35 +38,6 @@ int randomizer = 1;
unsigned char **stringtable = NULL;
#ifdef WITH_LINUX_FUTEX
int sys_futex(void *addr1, int op, int val1, struct timespec *timeout, void *addr2, int val3)
{
return syscall(SYS_futex, addr1, op, val1, timeout, addr2, val3);
}
int mutex_lock(int *val)
{
int c;
if ((c = __sync_val_compare_and_swap(val, 0, 1)) != 0)
do {
if(c == 2 || __sync_val_compare_and_swap(val, 1, 2) != 0)
sys_futex(val, FUTEX_WAIT_PRIVATE, 2, NULL, NULL, 0);
} while ((c = __sync_val_compare_and_swap(val, 0, 2)) != 0);
return 0;
}
int mutex_unlock(int *val)
{
if(__sync_fetch_and_sub (val, 1) != 1){
*val = 0;
sys_futex(val, FUTEX_WAKE_PRIVATE, 1, NULL, NULL, 0);
}
return 0;
}
#endif
#ifdef WITH_UN
void make_un(const unsigned char *path, struct sockaddr_un * sun){
memset(sun, 0, sizeof(*sun));
@ -144,7 +115,11 @@ int timeouts[12] = {
};
struct extparam conf = {
.threadinit = {0, 0},
#ifdef _WIN32
.threadinit = NULL,
#else
.threadinit = 0,
#endif
.timeouts = timeouts,
.acl = NULL,
.conffile = NULL,
@ -687,7 +662,7 @@ int scanaddr(const unsigned char *s, uint32_t * ip, uint32_t * mask) {
RESOLVFUNC resolvfunc = NULL;
#ifndef _WIN32
pthread_mutex_t gethostbyname_mutex;
_3proxy_mutex_t gethostbyname_mutex;
int ghbn_init = 0;
#endif
@ -743,10 +718,10 @@ uint32_t getip(unsigned char *name){
#ifndef NOSTDRESOLVE
#if !defined(_WIN32) && !defined(GETHOSTBYNAME_R)
if(!ghbn_init){
pthread_mutex_init(&gethostbyname_mutex, NULL);
_3proxy_mutex_init(&gethostbyname_mutex);
ghbn_init++;
}
pthread_mutex_lock(&gethostbyname_mutex);
_3proxy_mutex_lock(&gethostbyname_mutex);
#endif
hp=gethostbyname((char *)name);
if (!hp && conf.demanddialprog) {
@ -755,7 +730,7 @@ uint32_t getip(unsigned char *name){
}
retval = hp?*(uint32_t *)hp->h_addr:0;
#if !defined(_WIN32) && !defined(GETHOSTBYNAME_R)
pthread_mutex_unlock(&gethostbyname_mutex);
_3proxy_mutex_unlock(&gethostbyname_mutex);
#endif
#ifdef GETHOSTBYNAME_R
#undef gethostbyname

View File

@ -20,10 +20,10 @@
#define DEFAULTCONFIG conf.stringtable[25]
#endif
pthread_mutex_t bandlim_mutex;
pthread_mutex_t connlim_mutex;
pthread_mutex_t tc_mutex;
pthread_mutex_t config_mutex;
_3proxy_mutex_t bandlim_mutex;
_3proxy_mutex_t connlim_mutex;
_3proxy_mutex_t tc_mutex;
_3proxy_mutex_t config_mutex;
int haveerror = 0;
int linenum = 0;
@ -151,9 +151,7 @@ int start_proxy_thread(struct child * chp){
pthread_t thread;
#ifdef _WIN32
HANDLE h;
DWORD num;
#endif
char r[1];
#ifdef _WIN32
#ifndef _WINCE
@ -166,16 +164,15 @@ int start_proxy_thread(struct child * chp){
pthread_attr_init(&pa);
pthread_attr_setstacksize(&pa,PTHREAD_STACK_MIN + (32768+conf.stacksize));
pthread_attr_setdetachstate(&pa,PTHREAD_CREATE_DETACHED);
_3proxy_mutex_lock(&conf.threadinit);
pthread_create(&thread, &pa, startsrv, (void *)chp);
pthread_attr_destroy(&pa);
#endif
#ifdef _WIN32
ReadFile(conf.threadinit[0], r, 1, &num, NULL);
WaitForSingleObject(conf.threadinit, INFINITE);
#else
while(read(conf.threadinit[0], r, 1) !=1) if(errno != EINTR) {
fprintf(stderr, "pipe failed\n");
return 40;
}
_3proxy_mutex_lock(&conf.threadinit);
_3proxy_mutex_unlock(&conf.threadinit);
#endif
if(haveerror) {
fprintf(stderr, "Service not started on line: %d%s\n", linenum, haveerror == 2? ": insufficient memory":"");
@ -340,10 +337,10 @@ static int h_log(int argc, unsigned char ** argv){
else if(*argv[1]=='&'){
conf.logfunc = logsql;
if(notchanged) return 0;
pthread_mutex_lock(&log_mutex);
_3proxy_mutex_lock(&log_mutex);
close_sql();
init_sql((char *)argv[1]+1);
pthread_mutex_unlock(&log_mutex);
_3proxy_mutex_unlock(&log_mutex);
}
#endif
#ifndef NORADIUS
@ -1260,7 +1257,7 @@ static int h_ace(int argc, unsigned char **argv){
sscanf((char *)argv[1], "%u", &ncl->rate);
sscanf((char *)argv[2], "%u", &ncl->period);
}
pthread_mutex_lock(&connlim_mutex);
_3proxy_mutex_lock(&connlim_mutex);
if(!conf.connlimiter){
conf.connlimiter = ncl;
}
@ -1270,7 +1267,7 @@ static int h_ace(int argc, unsigned char **argv){
for(cli = conf.connlimiter; cli->next; cli = cli->next);
cli->next = ncl;
}
pthread_mutex_unlock(&connlim_mutex);
_3proxy_mutex_unlock(&connlim_mutex);
break;
case BANDLIM:
@ -1292,7 +1289,7 @@ static int h_ace(int argc, unsigned char **argv){
return(4);
}
}
pthread_mutex_lock(&bandlim_mutex);
_3proxy_mutex_lock(&bandlim_mutex);
if(!strcmp((char *)argv[0], "bandlimin") || !strcmp((char *)argv[0], "nobandlimin")){
if(!conf.bandlimiter){
conf.bandlimiter = nbl;
@ -1316,7 +1313,7 @@ static int h_ace(int argc, unsigned char **argv){
}
}
conf.bandlimver++;
pthread_mutex_unlock(&bandlim_mutex);
_3proxy_mutex_unlock(&bandlim_mutex);
break;
case COUNTIN:
@ -1368,7 +1365,7 @@ static int h_ace(int argc, unsigned char **argv){
}
}
}
pthread_mutex_lock(&tc_mutex);
_3proxy_mutex_lock(&tc_mutex);
if(!conf.trafcounter){
conf.trafcounter = tl;
}
@ -1378,7 +1375,7 @@ static int h_ace(int argc, unsigned char **argv){
for(ntl = conf.trafcounter; ntl->next; ntl = ntl->next);
ntl->next = tl;
}
pthread_mutex_unlock(&tc_mutex);
_3proxy_mutex_unlock(&tc_mutex);
}
return 0;
@ -1859,27 +1856,27 @@ void freeconf(struct extparam *confp){
pthread_mutex_lock(&tc_mutex);
_3proxy_mutex_lock(&tc_mutex);
confp->trafcountfunc = NULL;
tc = confp->trafcounter;
confp->trafcounter = NULL;
counterd = confp->counterd;
confp->counterd = -1;
confp->countertype = NONE;
pthread_mutex_unlock(&tc_mutex);
_3proxy_mutex_unlock(&tc_mutex);
pthread_mutex_lock(&bandlim_mutex);
_3proxy_mutex_lock(&bandlim_mutex);
bl = confp->bandlimiter;
blout = confp->bandlimiterout;
confp->bandlimiter = NULL;
confp->bandlimiterout = NULL;
confp->bandlimfunc = NULL;
confp->bandlimver++;
pthread_mutex_unlock(&bandlim_mutex);
pthread_mutex_lock(&connlim_mutex);
_3proxy_mutex_unlock(&bandlim_mutex);
_3proxy_mutex_lock(&connlim_mutex);
cl = confp->connlimiter;
confp->connlimiter = NULL;
pthread_mutex_unlock(&connlim_mutex);
_3proxy_mutex_unlock(&connlim_mutex);
destroyhashtable(&pw_table);
destroyhashtable(&pwnt_table);
@ -1952,7 +1949,7 @@ int reload (void){
FILE *fp;
int error = -2;
pthread_mutex_lock(&config_mutex);
_3proxy_mutex_lock(&config_mutex);
conf.paused++;
freeconf(&conf);
conf.paused++;
@ -1966,6 +1963,6 @@ int reload (void){
}
if(!writable)fclose(fp);
}
pthread_mutex_unlock(&config_mutex);
_3proxy_mutex_unlock(&config_mutex);
return error;
}

View File

@ -1,5 +1,4 @@
#include "proxy.h"
#include "libs/blake2.h"
struct hashentry {
time_t expires;
@ -13,7 +12,7 @@ static uint32_t hashindex(unsigned tablesize, const uint8_t* hash){
void destroyhashtable(struct hashtable *ht){
pthread_mutex_lock(&ht->hash_mutex);
_3proxy_mutex_lock(&ht->hash_mutex);
if(ht->ihashtable){
myfree(ht->ihashtable);
ht->ihashtable = NULL;
@ -29,8 +28,8 @@ void destroyhashtable(struct hashtable *ht){
ht->poolsize = 0;
ht->tablesize = 0;
ht->ihashempty = 0;
pthread_mutex_unlock(&ht->hash_mutex);
pthread_mutex_destroy(&ht->hash_mutex);
_3proxy_mutex_unlock(&ht->hash_mutex);
_3proxy_mutex_destroy(&ht->hash_mutex);
}
#define hvalue(ht,I) ((struct hashentry *)(ht->hashvalues + (I-1)*(sizeof(struct hashentry) + ht->recsize - 4)))
@ -54,7 +53,7 @@ int inithashtable(struct hashtable *ht, unsigned tablesize, unsigned poolsize, u
if(tablesize < 2 || poolsize < tablesize || growlimit < poolsize) return 1;
if(ht->ihashtable){
pthread_mutex_lock(&ht->hash_mutex);
_3proxy_mutex_lock(&ht->hash_mutex);
if(ht->ihashtable){
myfree(ht->ihashtable);
ht->ihashtable = NULL;
@ -71,18 +70,18 @@ int inithashtable(struct hashtable *ht, unsigned tablesize, unsigned poolsize, u
ht->tablesize = 0;
}
else {
pthread_mutex_init(&ht->hash_mutex, NULL);
pthread_mutex_lock(&ht->hash_mutex);
_3proxy_mutex_init(&ht->hash_mutex);
_3proxy_mutex_lock(&ht->hash_mutex);
}
if(!(ht->ihashtable = myalloc(tablesize * sizeof(uint32_t)))
|| !(ht->hashvalues = myalloc(poolsize * (sizeof(struct hashentry) + (ht->recsize-4))))
|| !(ht->hashvalues = myalloc(poolsize * (sizeof(struct hashentry) + ht->recsize - 4)))
|| !(ht->hashhashvalues = myalloc(poolsize * ht->hash_size))
){
myfree(ht->ihashtable);
ht->ihashtable = NULL;
myfree(ht->hashvalues);
ht->hashvalues = NULL;
pthread_mutex_unlock(&ht->hash_mutex);
_3proxy_mutex_unlock(&ht->hash_mutex);
return 3;
}
ht->poolsize = poolsize;
@ -95,7 +94,7 @@ int inithashtable(struct hashtable *ht, unsigned tablesize, unsigned poolsize, u
hvalue(ht,i)->inext = i+1;
}
ht->ihashempty = 1;
pthread_mutex_unlock(&ht->hash_mutex);
_3proxy_mutex_unlock(&ht->hash_mutex);
return 0;
}
@ -180,7 +179,7 @@ void hashadd(struct hashtable *ht, void* name, void* value, time_t expires){
}
ht->index2hash_add(ht, name, hash);
pthread_mutex_lock(&ht->hash_mutex);
_3proxy_mutex_lock(&ht->hash_mutex);
index = hashindex(ht->tablesize, hash);
for(hep = ht->ihashtable + index; (he = *hep)!=0; ){
@ -215,7 +214,7 @@ void hashadd(struct hashtable *ht, void* name, void* value, time_t expires){
hvalue(ht,hen)->expires = expires;
}
pthread_mutex_unlock(&ht->hash_mutex);
_3proxy_mutex_unlock(&ht->hash_mutex);
}
int hashresolv(struct hashtable *ht, void* name, void* value, uint32_t *ttl){
@ -228,7 +227,7 @@ int hashresolv(struct hashtable *ht, void* name, void* value, uint32_t *ttl){
return 0;
}
ht->index2hash_search(ht,name, hash);
pthread_mutex_lock(&ht->hash_mutex);
_3proxy_mutex_lock(&ht->hash_mutex);
index = hashindex(ht->tablesize, hash);
for(hep = ht->ihashtable + index; (he = *hep)!=0; ){
if(hvalue(ht, he)->expires < conf.time) {
@ -240,12 +239,12 @@ int hashresolv(struct hashtable *ht, void* name, void* value, uint32_t *ttl){
else if(!memcmp(hash, hhash(ht,he), ht->hash_size)){
if(ttl) *ttl = (uint32_t)(hvalue(ht,he)->expires - conf.time);
memcpy(value, hvalue(ht,he)->value, ht->recsize);
pthread_mutex_unlock(&ht->hash_mutex);
_3proxy_mutex_unlock(&ht->hash_mutex);
return 1;
}
else hep=&(hvalue(ht,he)->inext);
}
pthread_mutex_unlock(&ht->hash_mutex);
_3proxy_mutex_unlock(&ht->hash_mutex);
return 0;
}
@ -259,7 +258,7 @@ void hashdelete(struct hashtable *ht, void *name){
return;
}
ht->index2hash_search(ht, name, hash);
pthread_mutex_lock(&ht->hash_mutex);
_3proxy_mutex_lock(&ht->hash_mutex);
index = hashindex(ht->tablesize, hash);
for(hep = ht->ihashtable + index; (he = *hep) != 0; ){
if((hvalue(ht, he)->expires && hvalue(ht, he)->expires < conf.time) || !memcmp(hash, hhash(ht, he), ht->hash_size)) {
@ -270,102 +269,48 @@ void hashdelete(struct hashtable *ht, void *name){
}
else hep = &(hvalue(ht, he)->inext);
}
pthread_mutex_unlock(&ht->hash_mutex);
_3proxy_mutex_unlock(&ht->hash_mutex);
}
static void char_index2hash(const struct hashtable *ht, void *index, uint8_t *hash){
char* name = index;
#define MURMUR_C1 0xcc9e2d51u
#define MURMUR_C2 0x1b873593u
blake2b(hash, ht->hash_size, index, strlen((const char*)index), NULL, 0);
uint32_t murmurhash3(const void *key, int len, uint32_t seed) {
const uint8_t *data = (const uint8_t *)key;
const int nblocks = len / 4;
uint32_t h = seed;
int i;
const uint32_t *blocks = (const uint32_t *)(data);
const uint8_t *tail = data + nblocks * 4;
uint32_t k;
for (i = 0; i < nblocks; i++) {
memcpy(&k, blocks + i, sizeof(k));
k *= MURMUR_C1;
k = (k << 15) | (k >> 17);
k *= MURMUR_C2;
h ^= k;
h = (h << 13) | (h >> 19);
h = h * 5 + 0xe6546b64u;
}
k = 0;
switch (len & 3) {
case 3: k ^= (uint32_t)tail[2] << 16; /* fall through */
case 2: k ^= (uint32_t)tail[1] << 8; /* fall through */
case 1: k ^= (uint32_t)tail[0];
k *= MURMUR_C1;
k = (k << 15) | (k >> 17);
k *= MURMUR_C2;
h ^= k;
}
h ^= (uint32_t)len;
h ^= h >> 16;
h *= 0x85ebca6bu;
h ^= h >> 13;
h *= 0xc2b2ae35u;
h ^= h >> 16;
return h;
}
static void param2hash_add(const struct hashtable *ht, void *index, uint8_t *hash){
blake2b_state S;
struct clientparam *param = (struct clientparam *)index;
unsigned type = param->srv->authcachetype;
blake2b_init(&S, ht->hash_size);
if((type & 2) && param->username)blake2b_update(&S, param->username, strlen((const char *)param->username) + 1);
if((type & 4) && param->password)blake2b_update(&S, param->password, strlen((const char *)param->password) + 1);
if((type & 1) && !(type & 8))blake2b_update(&S, SAADDR(&param->sincr), SAADDRLEN(&param->sincr));
if((type & 16))blake2b_update(&S, &param->srv->acl, sizeof(param->srv->acl));
if((type & 64))blake2b_update(&S, SAADDR(&param->req), SAADDRLEN(&param->req));
if((type & 128))blake2b_update(&S, SAPORT(&param->req), 2);
if((type & 256) && param->hostname)blake2b_update(&S, param->hostname, strlen((const char *)param->hostname) + 1);
if((type & 512))blake2b_update(&S, &param->operation, sizeof(param->operation));
if((type & 1024))blake2b_update(&S, SAADDR(&param->srv->intsa), SAADDRLEN(&param->srv->intsa));
if((type & 2048))blake2b_update(&S, SAPORT(&param->srv->intsa), 2);
blake2b_final(&S, hash, ht->hash_size);
memcpy(param->hash, hash, ht->hash_size);
}
void param2hash_search(const struct hashtable *ht, void *index, uint8_t *hash){
struct clientparam *param = (struct clientparam *)index;
memcpy(hash, param->hash, ht->hash_size);
}
static void user2hash_search(const struct hashtable *ht, void *index, uint8_t *hash){
struct clientparam *param = (struct clientparam *)index;
blake2b(hash, ht->hash_size, param->username, strlen((const char *)param->username), NULL, 0);
}
static void udpparam2hash(const struct hashtable *ht, void *index, uint8_t *hash){
struct clientparam *param = (struct clientparam *)index;
blake2b_state S;
blake2b_init(&S, ht->hash_size);
blake2b_update(&S, SAADDR(&param->srv->intsa), SAADDRLEN(&param->srv->intsa));
blake2b_update(&S, SAPORT(&param->srv->intsa), 2);
blake2b_update(&S, SAADDR(&param->sincr), SAADDRLEN(&param->sincr));
blake2b_update(&S, SAPORT(&param->sincr), 2);
blake2b_final(&S, hash, ht->hash_size);
}
static void pw2hash_add(const struct hashtable *ht, void *index, uint8_t *hash){
char ** pw = (char **)index;
blake2b_state S;
blake2b_init(&S, ht->hash_size);
if(pw[0])blake2b_update(&S, pw[0], strlen(pw[0]) + 1);
if(pw[1])blake2b_update(&S, pw[1], strlen(pw[1]) + 1);
blake2b_final(&S, hash, ht->hash_size);
}
static void pw2hash_search(const struct hashtable *ht, void *index, uint8_t *hash){
struct clientparam *param = (struct clientparam *)index;
char *pw[2] = {(char *)param->username, (char *)param->password};
pw2hash_add(ht, pw, hash);
}
static void pwnt2hash_add(const struct hashtable *ht, void *index, uint8_t *hash){
char ** pw = (char **)index;
blake2b_state S;
blake2b_init(&S, ht->hash_size);
if(pw[0])blake2b_update(&S, pw[0], strlen(pw[0]) + 1);
if(pw[1])blake2b_update(&S, pw[1], strlen(pw[1]) + 1);
blake2b_final(&S, hash, ht->hash_size);
}
static void pwnt2hash_search(const struct hashtable *ht, void *index, uint8_t *hash){
struct clientparam *param = (struct clientparam *)index;
unsigned char pass[40];
char *pw[2] = {(char *)param->username, (char *)pass};
ntpwdhash(pass, param->password, 1);
pwnt2hash_add(ht, pw, hash);
}
struct hashtable dns_table = {char_index2hash, char_index2hash, 4, 12};
struct hashtable dns6_table = {char_index2hash, char_index2hash, 16, 12};
struct hashtable auth_table = {param2hash_add, param2hash_search, sizeof(struct authcache), 12};
struct hashtable pw_table = {pw2hash_add, pw2hash_search, 0, 12};
struct hashtable pwnt_table = {pwnt2hash_add, pwnt2hash_search, 0, 12};
struct hashtable pwcr_table = {char_index2hash, user2hash_search, 64, 12};
struct hashtable udp_table = {udpparam2hash, udpparam2hash, sizeof(struct clientparam *), 12};

99
src/hashtables.c Normal file
View File

@ -0,0 +1,99 @@
#include "proxy.h"
#include "libs/blake2.h"
static void char_index2hash(const struct hashtable *ht, void *index, uint8_t *hash){
char* name = index;
blake2b(hash, ht->hash_size, index, strlen((const char*)index), NULL, 0);
}
static void param2hash_add(const struct hashtable *ht, void *index, uint8_t *hash){
blake2b_state S;
struct clientparam *param = (struct clientparam *)index;
unsigned type = param->srv->authcachetype;
blake2b_init(&S, ht->hash_size);
if((type & 2) && param->username)blake2b_update(&S, param->username, strlen((const char *)param->username) + 1);
if((type & 4) && param->password)blake2b_update(&S, param->password, strlen((const char *)param->password) + 1);
if((type & 1) && !(type & 8))blake2b_update(&S, SAADDR(&param->sincr), SAADDRLEN(&param->sincr));
if((type & 16))blake2b_update(&S, &param->srv->acl, sizeof(param->srv->acl));
if((type & 64))blake2b_update(&S, SAADDR(&param->req), SAADDRLEN(&param->req));
if((type & 128))blake2b_update(&S, SAPORT(&param->req), 2);
if((type & 256) && param->hostname)blake2b_update(&S, param->hostname, strlen((const char *)param->hostname) + 1);
if((type & 512))blake2b_update(&S, &param->operation, sizeof(param->operation));
if((type & 1024))blake2b_update(&S, SAADDR(&param->srv->intsa), SAADDRLEN(&param->srv->intsa));
if((type & 2048))blake2b_update(&S, SAPORT(&param->srv->intsa), 2);
blake2b_final(&S, hash, ht->hash_size);
memcpy(param->hash, hash, ht->hash_size);
}
void param2hash_search(const struct hashtable *ht, void *index, uint8_t *hash){
struct clientparam *param = (struct clientparam *)index;
memcpy(hash, param->hash, ht->hash_size);
}
static void user2hash_search(const struct hashtable *ht, void *index, uint8_t *hash){
struct clientparam *param = (struct clientparam *)index;
blake2b(hash, ht->hash_size, param->username, strlen((const char *)param->username), NULL, 0);
}
static void udpparam2hash(const struct hashtable *ht, void *index, uint8_t *hash){
struct clientparam *param = (struct clientparam *)index;
blake2b_state S;
blake2b_init(&S, ht->hash_size);
blake2b_update(&S, SAADDR(&param->srv->intsa), SAADDRLEN(&param->srv->intsa));
blake2b_update(&S, SAPORT(&param->srv->intsa), 2);
blake2b_update(&S, SAADDR(&param->sincr), SAADDRLEN(&param->sincr));
blake2b_update(&S, SAPORT(&param->sincr), 2);
blake2b_final(&S, hash, ht->hash_size);
}
static void pw2hash_add(const struct hashtable *ht, void *index, uint8_t *hash){
char ** pw = (char **)index;
blake2b_state S;
blake2b_init(&S, ht->hash_size);
if(pw[0])blake2b_update(&S, pw[0], strlen(pw[0]) + 1);
if(pw[1])blake2b_update(&S, pw[1], strlen(pw[1]) + 1);
blake2b_final(&S, hash, ht->hash_size);
}
static void pw2hash_search(const struct hashtable *ht, void *index, uint8_t *hash){
struct clientparam *param = (struct clientparam *)index;
char *pw[2] = {(char *)param->username, (char *)param->password};
pw2hash_add(ht, pw, hash);
}
static void pwnt2hash_add(const struct hashtable *ht, void *index, uint8_t *hash){
char ** pw = (char **)index;
blake2b_state S;
blake2b_init(&S, ht->hash_size);
if(pw[0])blake2b_update(&S, pw[0], strlen(pw[0]) + 1);
if(pw[1])blake2b_update(&S, pw[1], strlen(pw[1]) + 1);
blake2b_final(&S, hash, ht->hash_size);
}
static void pwnt2hash_search(const struct hashtable *ht, void *index, uint8_t *hash){
struct clientparam *param = (struct clientparam *)index;
unsigned char pass[40];
char *pw[2] = {(char *)param->username, (char *)pass};
ntpwdhash(pass, param->password, 1);
pwnt2hash_add(ht, pw, hash);
}
struct hashtable dns_table = {char_index2hash, char_index2hash, 4, 12};
struct hashtable dns6_table = {char_index2hash, char_index2hash, 16, 12};
struct hashtable auth_table = {param2hash_add, param2hash_search, sizeof(struct authcache), 12};
struct hashtable pw_table = {pw2hash_add, pw2hash_search, 0, 12};
struct hashtable pwnt_table = {pwnt2hash_add, pwnt2hash_search, 0, 12};
struct hashtable pwcr_table = {char_index2hash, user2hash_search, 64, 12};

View File

@ -15,7 +15,7 @@ int startconnlims (struct clientparam *param){
int ret = 0;
param->connlim = 1;
pthread_mutex_lock(&connlim_mutex);
_3proxy_mutex_lock(&connlim_mutex);
for(ce = conf.connlimiter; ce; ce = ce->next) {
if(ACLmatches(ce->ace, param)){
if(ce->ace->action == NOCONNLIM)break;
@ -51,14 +51,14 @@ int startconnlims (struct clientparam *param){
}
param->connlim = 0;
}
pthread_mutex_unlock(&connlim_mutex);
_3proxy_mutex_unlock(&connlim_mutex);
return ret;
}
void stopconnlims (struct clientparam *param){
struct connlim * ce;
pthread_mutex_lock(&connlim_mutex);
_3proxy_mutex_lock(&connlim_mutex);
for(ce = conf.connlimiter; ce; ce = ce->next) {
if(ACLmatches(ce->ace, param)){
if(ce->ace->action == NOCONNLIM)break;
@ -68,7 +68,7 @@ void stopconnlims (struct clientparam *param){
}
}
}
pthread_mutex_unlock(&connlim_mutex);
_3proxy_mutex_unlock(&connlim_mutex);
}
void initbandlims (struct clientparam *param){
@ -124,7 +124,7 @@ unsigned bandlimitfunc(struct clientparam *param, unsigned nbytesin, unsigned nb
#endif
if(!nbytesin && !nbytesout) return 0;
pthread_mutex_lock(&bandlim_mutex);
_3proxy_mutex_lock(&bandlim_mutex);
if(param->bandlimver != conf.bandlimver){
initbandlims(param);
param->bandlimver = conf.bandlimver;
@ -163,7 +163,7 @@ unsigned bandlimitfunc(struct clientparam *param, unsigned nbytesin, unsigned nb
param->bandlimsout[i]->basetime = sec;
param->bandlimsout[i]->nexttime = msec + nsleeptime + ((nbytesout > 512)? ((nbytesout+32)/64)*((64*8*1000000)/param->bandlimsout[i]->rate) : ((nbytesout+1)* (8*1000000))/param->bandlimsout[i]->rate);
}
pthread_mutex_unlock(&bandlim_mutex);
_3proxy_mutex_unlock(&bandlim_mutex);
return sleeptime/1000;
}
@ -171,7 +171,7 @@ void trafcountfunc(struct clientparam *param){
struct trafcount * tc;
int countout = 0;
pthread_mutex_lock(&tc_mutex);
_3proxy_mutex_lock(&tc_mutex);
for(tc = conf.trafcounter; tc; tc = tc->next) {
if(ACLmatches(tc->ace, param)){
@ -199,6 +199,6 @@ void trafcountfunc(struct clientparam *param){
}
}
pthread_mutex_unlock(&tc_mutex);
_3proxy_mutex_unlock(&tc_mutex);
}

View File

@ -10,7 +10,7 @@
#include "proxy.h"
pthread_mutex_t log_mutex;
_3proxy_mutex_t log_mutex;
int havelog = 0;

View File

@ -45,7 +45,7 @@ extern "C" {
static struct pluginlink * pl;
static pthread_mutex_t file_mutex;
static _3proxy_mutex_t file_mutex;
unsigned long preview = 0;
@ -207,7 +207,7 @@ static void closefiles(struct fp_stream *fps){
static int searchsocket(SOCKET s, struct fp_stream **pfps){
struct fp_stream *fps = NULL;
int ret = 0;
pthread_mutex_lock(&file_mutex);
_3proxy_mutex_lock(&file_mutex);
for(fps = fp_streams; fps; fps = fps->next){
if(fps->fpd.cp->clisock == s) {
ret = 1;
@ -222,7 +222,7 @@ static int searchsocket(SOCKET s, struct fp_stream **pfps){
break;
}
}
pthread_mutex_unlock(&file_mutex);
_3proxy_mutex_unlock(&file_mutex);
*pfps = fps;
return ret;
}
@ -235,7 +235,7 @@ static void freecallback(struct fp_stream * fps, struct fp_callback * fpc){
static void removefps(struct fp_stream * fps){
if(!fp_streams) return;
pthread_mutex_lock(&file_mutex);
_3proxy_mutex_lock(&file_mutex);
if(fp_streams == fps)fp_streams = fps->next;
else {
struct fp_stream *fps2;
@ -248,7 +248,7 @@ static void removefps(struct fp_stream * fps){
}
}
pthread_mutex_unlock(&file_mutex);
_3proxy_mutex_unlock(&file_mutex);
if(fps->callbacks){
freecallback(fps, fps->callbacks);
fps->callbacks = 0;
@ -754,7 +754,7 @@ static int fp_registercallback (int what, int max_size, int preview_size, struct
fpc->max_size = max_size;
fpc->data = data;
fpc->callback = cb;
pthread_mutex_lock(&file_mutex);
_3proxy_mutex_lock(&file_mutex);
fps = addfps(cp);
if(fps){
fpc->next = fps->callbacks;
@ -763,7 +763,7 @@ static int fp_registercallback (int what, int max_size, int preview_size, struct
if(preview_size > fps->preview_size) fps->preview_size = preview_size;
}
else free(fpc);
pthread_mutex_unlock(&file_mutex);
_3proxy_mutex_unlock(&file_mutex);
return fps?1:0;
}
@ -777,9 +777,9 @@ static void * fp_open(void * idata, struct srvparam * param){
static FILTER_ACTION fp_client(void *fo, struct clientparam * param, void** fc){
pthread_mutex_lock(&file_mutex);
_3proxy_mutex_lock(&file_mutex);
(*fc) = (void *)addfps(param);
pthread_mutex_unlock(&file_mutex);
_3proxy_mutex_unlock(&file_mutex);
return CONTINUE;
}
@ -913,7 +913,7 @@ static int file_loaded=0;
int argc, char** argv){
if(!file_loaded){
pthread_mutex_init(&file_mutex, NULL);
_3proxy_mutex_init(&file_mutex);
file_loaded = 1;
pl = pluginlink;
memcpy(&sso, pl->so, sizeof(struct sockfuncs));

View File

@ -21,7 +21,7 @@ extern "C" {
static struct pluginlink * pl;
static pthread_mutex_t pcre_mutex;
static _3proxy_mutex_t pcre_mutex;
static struct filter pcre_first_filter = {
@ -112,7 +112,7 @@ struct pcre_filter_data {
};
static void pcre_data_free(struct pcre_filter_data *pcrefd){
pthread_mutex_lock(&pcre_mutex);
_3proxy_mutex_lock(&pcre_mutex);
pcrefd->users--;
if(!pcrefd->users){
if(pcrefd->match_data) pcre2_match_data_free(pcrefd->match_data);
@ -121,7 +121,7 @@ static void pcre_data_free(struct pcre_filter_data *pcrefd){
if(pcrefd->replace) pl->freefunc(pcrefd->replace);
pl->freefunc(pcrefd);
}
pthread_mutex_unlock(&pcre_mutex);
_3proxy_mutex_unlock(&pcre_mutex);
}
@ -130,9 +130,9 @@ static void pcre_data_free(struct pcre_filter_data *pcrefd){
static void* pcre_filter_open(void * idata, struct srvparam * param){
#define pcrefd ((struct pcre_filter_data *)idata)
if(idata){
pthread_mutex_lock(&pcre_mutex);
_3proxy_mutex_lock(&pcre_mutex);
pcrefd->users++;
pthread_mutex_unlock(&pcre_mutex);
_3proxy_mutex_unlock(&pcre_mutex);
}
#undef pcrefd
return idata;
@ -517,7 +517,7 @@ PLUGINAPI int PLUGINCALL pcre_plugin (struct pluginlink * pluginlink,
pcre_options = 0;
if(!pcre_loaded){
pcre_loaded = 1;
pthread_mutex_init(&pcre_mutex, NULL);
_3proxy_mutex_init(&pcre_mutex);
regexp_symbols[2].next = pl->symbols.next;
pl->symbols.next = regexp_symbols;
pcre_commandhandlers[3].next = pl->commandhandlers->next;

View File

@ -12,7 +12,7 @@ Kirill Lopuchov <lopuchov@mail.ru>
#include <security/pam_appl.h>
pthread_mutex_t pam_mutex;
_3proxy_mutex_t pam_mutex;
static int already_loaded = 0;
@ -89,7 +89,7 @@ static int pamfunc(struct clientparam *param)
/*start process auth */
conv.appdata_ptr = (char *) param->password;
pthread_mutex_lock(&pam_mutex);
_3proxy_mutex_lock(&pam_mutex);
if (!pamh)
{
retval = pam_start ((char *)service, (char *)param->username, &conv, &pamh);
@ -113,7 +113,7 @@ static int pamfunc(struct clientparam *param)
retval = pam_end (pamh, retval);
if (retval != PAM_SUCCESS)
{ pamh = NULL; }
pthread_mutex_unlock(&pam_mutex);
_3proxy_mutex_unlock(&pam_mutex);
return rc;
@ -140,7 +140,7 @@ PLUGINAPI int PLUGINCALL start(struct pluginlink * pluginlink, int argc, unsigne
already_loaded = 1;
pthread_mutex_init(&pam_mutex, NULL);
_3proxy_mutex_init(&pam_mutex);
pamauth.authenticate = pamfunc;
pamauth.authorize = pluginlink->checkACL;
pamauth.desc = "pam";

View File

@ -32,7 +32,7 @@ typedef struct _ssl_conn {
SSL *ssl;
} ssl_conn;
pthread_mutex_t ssl_file_mutex;
_3proxy_mutex_t ssl_file_mutex;
static char errbuf[256];
@ -229,15 +229,15 @@ void _ssl_cert_free(SSL_CERT cert)
/* This array will store all of the mutexes available to OpenSSL. */
static pthread_mutex_t *mutex_buf= NULL;
static _3proxy_mutex_t *mutex_buf= NULL;
static void locking_function(int mode, int n, const char * file, int line)
{
if (mode & CRYPTO_LOCK)
pthread_mutex_lock(mutex_buf + n);
_3proxy_mutex_lock(mutex_buf + n);
else
pthread_mutex_unlock(mutex_buf + n);
_3proxy_mutex_unlock(mutex_buf + n);
}
static unsigned long id_function(void)
@ -253,11 +253,11 @@ int thread_setup(void)
{
int i;
mutex_buf = malloc(CRYPTO_num_locks( ) * sizeof(pthread_mutex_t));
mutex_buf = malloc(CRYPTO_num_locks( ) * sizeof(_3proxy_mutex_t));
if (!mutex_buf)
return 0;
for (i = 0; i < CRYPTO_num_locks( ); i++)
pthread_mutex_init(mutex_buf +i, NULL);
_3proxy_mutex_init(mutex_buf +i);
CRYPTO_set_id_callback(id_function);
CRYPTO_set_locking_callback(locking_function);
return 1;
@ -272,7 +272,7 @@ int thread_cleanup(void)
CRYPTO_set_id_callback(NULL);
CRYPTO_set_locking_callback(NULL);
for (i = 0; i < CRYPTO_num_locks( ); i++)
pthread_mutex_destroy(mutex_buf +i);
_3proxy_mutex_destroy(mutex_buf +i);
free(mutex_buf);
mutex_buf = NULL;
return 1;
@ -291,7 +291,7 @@ void ssl_init()
thread_setup();
SSLeay_add_ssl_algorithms();
SSL_load_error_strings();
pthread_mutex_init(&ssl_file_mutex, NULL);
_3proxy_mutex_init(&ssl_file_mutex);
bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
}
}

View File

@ -299,6 +299,7 @@ int connectwithpoll(struct clientparam *param, SOCKET sock, struct sockaddr *sa,
int myrand(void * entropy, int len);
uint32_t murmurhash3(const void *key, int len, uint32_t seed);
extern char *copyright;
@ -322,12 +323,12 @@ struct datatype;
struct dictionary;
struct node;
struct property;
extern pthread_mutex_t config_mutex;
extern pthread_mutex_t bandlim_mutex;
extern pthread_mutex_t connlim_mutex;
extern pthread_mutex_t tc_mutex;
extern pthread_mutex_t log_mutex;
extern pthread_mutex_t rad_mutex;
extern _3proxy_mutex_t config_mutex;
extern _3proxy_mutex_t bandlim_mutex;
extern _3proxy_mutex_t connlim_mutex;
extern _3proxy_mutex_t tc_mutex;
extern _3proxy_mutex_t log_mutex;
extern _3proxy_mutex_t rad_mutex;
extern struct datatype datatypes[64];
extern struct commands commandhandlers[];

View File

@ -117,10 +117,10 @@ void * threadfunc (void *p) {
int pushthreadinit(){
#ifdef _WIN32
DWORD n;
return WriteFile(conf.threadinit[1], "1", 1, &n, NULL);
return ReleaseSemaphore(conf.threadinit, 1, NULL) ? 1 : 0;
#else
return write(conf.threadinit[1], "1", 1);
_3proxy_mutex_unlock(&conf.threadinit);
return 1;
#endif
}
@ -261,8 +261,10 @@ int MODULEMAINFUNC (int argc, char** argv){
unsigned char buf[256];
char *hostname=NULL;
int opt = 1, isudp = 0, iscbl = 0, iscbc = 0;
#ifndef NOUDPMAIN
unsigned char udpbuf[UDPBUFSIZE];
int udplen = 0;
#endif
unsigned char *cbc_string = NULL, *cbl_string = NULL;
PROXYSOCKADDRTYPE cbsa;
FILE *fp = NULL;
@ -348,7 +350,7 @@ int MODULEMAINFUNC (int argc, char** argv){
srvinit(&srv, &defparam);
srv.pf = childdef.pf;
isudp = childdef.isudp;
#ifndef STDMAIN
#ifndef NOUDPMAIN
if(isudp) {
if(!udp_table.ihashtable)inithashtable(&udp_table, 64, 256, 65536);
}
@ -381,7 +383,7 @@ int MODULEMAINFUNC (int argc, char** argv){
#endif
#else
srv.needuser = 0;
pthread_mutex_init(&log_mutex, NULL);
_3proxy_mutex_init(&log_mutex);
#endif
for (i=1; i<argc; i++) {
@ -680,9 +682,11 @@ int MODULEMAINFUNC (int argc, char** argv){
IPPROTO_TCP
);
}
#ifndef NOUDPMAIN
else {
sock=srv.so._socket(srv.so.state, SASOCK(&srv.intsa), SOCK_DGRAM, IPPROTO_UDP);
}
#endif
if( sock == INVALID_SOCKET) {
perror("socket()");
return -2;
@ -753,8 +757,10 @@ int MODULEMAINFUNC (int argc, char** argv){
return -4;
}
}
#ifndef NOUDPMAIN
else
defparam.clisock = sock;
#endif
if(!srv.silent && !iscbc){
sprintf((char *)buf, "Accepting connections [%"PRIu64"/%"PRIu64"]", (uint64_t)getpid(), (uint64_t)pthread_self());
@ -926,20 +932,20 @@ int MODULEMAINFUNC (int argc, char** argv){
srv.so._setsockopt(srv.so.state, new_sock, SOL_SOCKET, SO_LINGER, (char *)&lg, sizeof(lg));
srv.so._setsockopt(srv.so.state, new_sock, SOL_SOCKET, SO_OOBINLINE, (char *)&opt, sizeof(int));
}
#ifndef STDMAIN
#ifndef NOUDPMAIN
else {
struct clientparam *toparam;
udplen = sockrecvfrom(NULL, srv.srvsock, (struct sockaddr *)&defparam.sincr, udpbuf, UDPBUFSIZE, 0);
if(udplen <= 0) continue;
pthread_mutex_lock(&srv.counter_mutex);
_3proxy_mutex_lock(&srv.counter_mutex);
if(hashresolv(&udp_table, &defparam, &toparam, NULL)) {
socksendto(toparam, toparam->remsock, (struct sockaddr *)&toparam->sinsr, udpbuf, udplen, 0);
toparam->statscli64 += udplen;
toparam->nwrites++;
pthread_mutex_unlock(&srv.counter_mutex);
_3proxy_mutex_unlock(&srv.counter_mutex);
continue;
}
pthread_mutex_unlock(&srv.counter_mutex);
_3proxy_mutex_unlock(&srv.counter_mutex);
}
#endif
if(! (newparam = myalloc (sizeof(defparam)))){
@ -958,6 +964,8 @@ int MODULEMAINFUNC (int argc, char** argv){
freeparam(newparam);
continue;
}
#endif
#ifndef NOUDPMAIN
if(isudp) {
int authres;
@ -988,7 +996,7 @@ int MODULEMAINFUNC (int argc, char** argv){
#endif
newparam->prev = newparam->next = NULL;
error = 0;
pthread_mutex_lock(&srv.counter_mutex);
_3proxy_mutex_lock(&srv.counter_mutex);
if(!srv.child){
srv.child = newparam;
}
@ -1012,7 +1020,7 @@ int MODULEMAINFUNC (int argc, char** argv){
if(!srv.silent)dolog(&defparam, buf);
error = 1;
}
pthread_mutex_unlock(&srv.counter_mutex);
_3proxy_mutex_unlock(&srv.counter_mutex);
if(error) freeparam(newparam);
#else
@ -1023,14 +1031,14 @@ int MODULEMAINFUNC (int argc, char** argv){
if(newparam->prev) newparam->prev->next = newparam->next;
else srv.child = newparam->next;
if(newparam->next) newparam->next->prev = newparam->prev;
pthread_mutex_unlock(&srv.counter_mutex);
_3proxy_mutex_unlock(&srv.counter_mutex);
newparam->srv = NULL;
freeparam(newparam);
}
else {
srv.childcount++;
newparam->threadid = (uint64_t)thread;
pthread_mutex_unlock(&srv.counter_mutex);
_3proxy_mutex_unlock(&srv.counter_mutex);
}
#endif
@ -1040,11 +1048,11 @@ int MODULEMAINFUNC (int argc, char** argv){
#ifndef STDMAIN
pthread_mutex_lock(&config_mutex);
_3proxy_mutex_lock(&config_mutex);
if(srv.next)srv.next->prev = srv.prev;
if(srv.prev)srv.prev->next = srv.next;
else conf.services = srv.next;
pthread_mutex_unlock(&config_mutex);
_3proxy_mutex_unlock(&config_mutex);
#endif
if(!srv.silent) srv.logfunc(&defparam, (unsigned char *)"Exiting thread");
@ -1093,7 +1101,7 @@ void srvinit(struct srvparam * srv, struct clientparam *param){
param->paused = srv->paused;
param->remsock = param->clisock = param->ctrlsock = param->ctrlsocksrv = INVALID_SOCKET;
*SAFAMILY(&param->req) = *SAFAMILY(&param->sinsl) = *SAFAMILY(&param->sinsr) = *SAFAMILY(&param->sincr) = *SAFAMILY(&param->sincl) = AF_INET;
pthread_mutex_init(&srv->counter_mutex, NULL);
_3proxy_mutex_init(&srv->counter_mutex);
srv->intsa = conf.intsa;
srv->extsa = conf.extsa;
#ifndef NOIPV6
@ -1158,7 +1166,7 @@ void srvfree(struct srvparam * srv){
if(srv->acl)freeacl(srv->acl);
if(srv->authfuncs)freeauth(srv->authfuncs);
#endif
pthread_mutex_destroy(&srv->counter_mutex);
_3proxy_mutex_destroy(&srv->counter_mutex);
if(srv->target) myfree(srv->target);
if(srv->logtarget) myfree(srv->logtarget);
if(srv->logformat) myfree(srv->logformat);
@ -1175,7 +1183,7 @@ void freeparam(struct clientparam * param) {
if(param->res == 2) return;
if(param->srv){
if(param->srv->so.freefunc) param->srv->so.freefunc(param->sostate);
pthread_mutex_lock(&param->srv->counter_mutex);
_3proxy_mutex_lock(&param->srv->counter_mutex);
#ifndef STDMAIN
if(param->srv->service == S_UDPPM) hashdelete(&udp_table, param);
#endif
@ -1188,7 +1196,7 @@ void freeparam(struct clientparam * param) {
param->next->prev = param->prev;
}
(param->srv->childcount)--;
pthread_mutex_unlock(&param->srv->counter_mutex);
_3proxy_mutex_unlock(&param->srv->counter_mutex);
}
if(param->clibuf) myfree(param->clibuf);
if(param->srvbuf) myfree(param->srvbuf);

View File

@ -50,7 +50,7 @@ int sockmap(struct clientparam * param, int timeo, int usesplice){
int FROMCLIENT = 1, TOCLIENTBUF = 1, FROMCLIENTBUF = 1, TOSERVER = 1,
FROMSERVER = 1, TOSERVERBUF = 1, FROMSERVERBUF = 1, TOCLIENT = 1;
int HASERROR=0;
int CLIENTTERM = 0, SERVERTERM = 0;
int CLIENTTERMREAD = 0, CLIENTTERMWRITE = 0, SERVERTERMREAD = 0, SERVERTERMWRITE = 0;
int after = 0;
struct pollfd fds[6];
struct pollfd *fdsp = fds;
@ -62,6 +62,8 @@ int sockmap(struct clientparam * param, int timeo, int usesplice){
int needaction = 0;
int graceclinum=0, gracesrvnum=0, graceclitraf=0, gracesrvtraf=0;
time_t gracetime = 0;
int cli_events = 0;
int srv_events = 0;
#ifdef WITHSPLICE
uint64_t inclientpipe = 0, inserverpipe = 0;
@ -121,24 +123,24 @@ int sockmap(struct clientparam * param, int timeo, int usesplice){
if(action != PASS) RETURN(19);
while(
((!CLIENTTERM) && fromserver && (inserverbuf
((!CLIENTTERMWRITE) && fromserver && (inserverbuf
#ifdef WITHSPLICE
|| inserverpipe
#endif
|| (!SERVERTERM )))
|| (!SERVERTERMREAD )))
||
((!SERVERTERM) && fromclient && (inclientbuf
((!SERVERTERMWRITE) && fromclient && (inclientbuf
#ifdef WITHSPLICE
|| inclientpipe
#endif
|| (!CLIENTTERM )))
|| (!CLIENTTERMREAD )))
){
#if WITHLOG > 1
sprintf(logbuf, "int FROMCLIENT = %d, TOCLIENTBUF = %d, FROMCLIENTBUF = %d, TOSERVER = %d, "
"FROMSERVER = %d, TOSERVERBUF = %d, FROMSERVERBUF = %d, TOCLIENT = %d; inclientbuf=%d; "
"inserverbuf=%d, CLIENTTERM = %d, SERVERTERM =%d, fromserver=%u, fromclient=%u"
"inserverbuf=%d, CLIENTTERMREAD=%d CLIENTTERMWRITE=%d SERVERTERMREAD=%d SERVERTERMWRITE=%d fromserver=%u, fromclient=%u"
#ifdef WITHSPLICE
", inserverpipe=%d, inclentpipe=%d "
"TOCLIENTPIPE=%d FROMCLIENTPIPE==%d TOSERVERPIPE==%d FROMSERVERPIPE=%d"
@ -146,7 +148,7 @@ sprintf(logbuf, "int FROMCLIENT = %d, TOCLIENTBUF = %d, FROMCLIENTBUF = %d, TOSE
,
FROMCLIENT, TOCLIENTBUF, FROMCLIENTBUF, TOSERVER,
FROMSERVER, TOSERVERBUF, FROMSERVERBUF, TOCLIENT,
(int)inclientbuf, (int)inserverbuf, CLIENTTERM, SERVERTERM,
(int)inclientbuf, (int)inserverbuf, CLIENTTERMREAD, CLIENTTERMWRITE, SERVERTERMREAD, SERVERTERMWRITE,
(unsigned)fromserver, (unsigned)fromclient
#ifdef WITHSPLICE
,(int)inserverpipe, (int)inclientpipe,
@ -215,7 +217,8 @@ log("send to server from buf");
if(res <= 0) {
TOSERVER = 0;
if(errno && errno != EAGAIN && errno != EINTR){
SERVERTERM = 1;
SERVERTERMREAD = 1;
SERVERTERMWRITE = 1;
HASERROR |= 2;
}
}
@ -260,7 +263,8 @@ log("send to client from buf");
if(res <= 0) {
TOCLIENT = 0;
if(errno && errno != EAGAIN && errno != EINTR){
CLIENTTERM = 1;
CLIENTTERMREAD = 1;
CLIENTTERMWRITE = 1;
HASERROR |= 1;
}
@ -357,7 +361,7 @@ log(logbuf);
if(res <= 0) {
FROMCLIENT = TOCLIENTPIPE = 0;
if(res == 0 && !errno) {
CLIENTTERM = 1;
CLIENTTERMREAD = 1;
continue;
}
}
@ -394,7 +398,7 @@ log(logbuf);
if(res <= 0) {
FROMSERVER = TOSERVERPIPE = 0;
if(res == 0 && !errno) {
SERVERTERM = 1;
SERVERTERMREAD = 1;
continue;
}
}
@ -430,8 +434,13 @@ log("read from client to buf");
res = param->srv->so._recvfrom(param->sostate, param->clisock, (char *)param->clibuf + param->cliinbuf, (int)MIN((uint64_t)param->clibufsize - param->cliinbuf, fromclient-inclientbuf), 0, (struct sockaddr *)&param->sincr, &sasize);
if(res <= 0) {
FROMCLIENT = 0;
if(res == 0 || (errno && errno != EINTR && errno !=EAGAIN)){
CLIENTTERM = 1;
if(res == 0) {
CLIENTTERMREAD = 1;
continue;
}
if(errno && errno != EINTR && errno !=EAGAIN){
CLIENTTERMREAD = 1;
CLIENTTERMWRITE = 1;
continue;
}
}
@ -458,8 +467,13 @@ log("read from server to buf");
res = param->srv->so._recvfrom(param->sostate, param->remsock, (char *)param->srvbuf + param->srvinbuf, (int)MIN((uint64_t)param->srvbufsize - param->srvinbuf, fromserver-inserverbuf), 0, (struct sockaddr *)&param->sinsr, &sasize);
if(res <= 0) {
FROMSERVER = 0;
if(res == 0 || (errno && errno != EINTR && errno !=EAGAIN)) {
SERVERTERM = 1;
if(res == 0) {
SERVERTERMREAD = 1;
continue;
}
if(errno && errno != EINTR && errno !=EAGAIN) {
SERVERTERMREAD = 1;
SERVERTERMWRITE = 1;
continue;
}
}
@ -485,15 +499,15 @@ log("done read from server to buf");
}
}
}
for(after = 0; after < 2; after ++){
for(after = 0, cli_events=0, srv_events=0; after < 2; after ++){
fdsc = 0;
if(!after){
memset(fds, 0, sizeof(fds));
}
if(!CLIENTTERM){
// if(!CLIENTTERMREAD || !CLIENTTERMWRITE){
if(!after){
fds[fdsc].fd = param->clisock;
if(fromclient && !FROMCLIENT && ((
if(fromclient && !CLIENTTERMREAD && !FROMCLIENT && ((
#ifdef WITHSPLICE
!usesplice &&
#endif
@ -501,26 +515,29 @@ log("done read from server to buf");
#ifdef WITHSPLICE
|| (usesplice)
#endif
)){
#ifdef WITHLOG
log("wait reading from client");
#endif
fds[fdsc].events |= (POLLIN);
}
if(!TOCLIENT && (inserverbuf
))
cli_events |= POLLIN;
if(!TOCLIENT && !CLIENTTERMWRITE && (inserverbuf
#ifdef WITHSPLICE
|| inserverpipe
#endif
)){
))
cli_events |= POLLOUT;
if(cli_events){
fds[fdsc].fd = param->clisock;
fds[fdsc].events = cli_events;
#ifdef WITHLOG
if(cli_events & POLLIN)
log("wait reading from client");
if(cli_events & POLLOUT)
log("wait writing to client");
#endif
fds[fdsc].events |= POLLOUT;
}
}
}
else{
else if(cli_events){
if(fds[fdsc].revents & (POLLERR|POLLNVAL)) {
CLIENTTERM = 1;
CLIENTTERMREAD = 1;
CLIENTTERMWRITE = 1;
HASERROR |= 1;
}
else {
@ -538,16 +555,15 @@ log("ready to write to client");
}
if(fds[fdsc].revents & (POLLHUP)) {
if(fds[fdsc].events & POLLIN) FROMCLIENT = 1;
if(fds[fdsc].events & POLLOUT) CLIENTTERM = 1;
if(fds[fdsc].events & POLLOUT) CLIENTTERMWRITE = 1;
}
}
}
fdsc++;
}
if(!SERVERTERM){
// if(!SERVERTERMREAD || !SERVERTERMWRITE){
if(!after){
fds[fdsc].fd = param->remsock;
if(fromserver && !FROMSERVER && ((
if(fromserver && !SERVERTERMREAD && !FROMSERVER && ((
#ifdef WITHSPLICE
!usesplice &&
#endif
@ -555,30 +571,33 @@ log("ready to write to client");
#ifdef WITHSPLICE
|| (usesplice)
#endif
)){
#ifdef WITHLOG
log("wait reading from server");
#endif
fds[fdsc].events |= (POLLIN);
}
if(!TOSERVER && (inclientbuf
))
srv_events |= POLLIN;
if(!TOSERVER && !SERVERTERMWRITE && (inclientbuf
#ifdef WITHSPLICE
|| inclientpipe
#endif
)){
))
srv_events |= POLLOUT;
if(srv_events){
fds[fdsc].fd = param->remsock;
fds[fdsc].events = srv_events;
#ifdef WITHLOG
if(srv_events & POLLIN)
log("wait reading from server");
if(srv_events & POLLOUT)
log("wait writing from server");
#endif
fds[fdsc].events |= POLLOUT;
}
}
}
else{
else if(srv_events){
if(fds[fdsc].revents & (POLLERR|POLLNVAL)) {
#ifdef WITHLOG
log("poll from server failed");
#endif
SERVERTERM = 1;
SERVERTERMREAD = 1;
SERVERTERMWRITE = 1;
HASERROR |=2;
}
else {
@ -599,12 +618,12 @@ log("ready to write to server");
log("server terminated connection");
#endif
if(fds[fdsc].events & POLLIN) FROMSERVER = 1;
if(fds[fdsc].events & POLLOUT) SERVERTERM = 1;
if(fds[fdsc].events & POLLOUT) SERVERTERMWRITE = 1;
}
}
}
fdsc++;
}
// }
#ifdef WITHSPLICE
if(usesplice){
if(fromclient>inclientpipe && !TOCLIENTPIPE && inclientpipe < MAXSPLICE){
@ -727,6 +746,9 @@ log("timeout");
else if(inclientpipe || inserverpipe) res = 94;
#endif
if((param->nwrites > 0 && !SERVERTERMWRITE) || (param->nreads > 0 && !CLIENTTERMWRITE))
usleep(SLEEPTIME * 10);
CLEANRET:
#ifdef WITHSPLICE

View File

@ -98,7 +98,7 @@ void sqlerr (char *buf){
fprintf(conf.stdlog, "%s\n", buf);
fflush(conf.stdlog);
}
pthread_mutex_unlock(&log_mutex);
_3proxy_mutex_unlock(&log_mutex);
}
unsigned char statbuf[8192];
@ -109,7 +109,7 @@ void logsql(struct clientparam * param, const unsigned char *s) {
if(param->nolog) return;
pthread_mutex_lock(&log_mutex);
_3proxy_mutex_lock(&log_mutex);
len = dobuf(param, statbuf, s, (unsigned char *)"\'");
if(attempt > 5){
@ -146,7 +146,7 @@ void logsql(struct clientparam * param, const unsigned char *s) {
}
attempt = 0;
}
pthread_mutex_unlock(&log_mutex);
_3proxy_mutex_unlock(&log_mutex);
}
#endif

View File

@ -37,29 +37,19 @@ extern "C" {
#define SASIZETYPE socklen_t
#define SOCKET int
#define INVALID_SOCKET (-1)
#ifdef WITH_LINUX_FUTEX
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
#include <linux/kernel.h>
#include <linux/futex.h>
#define pthread_mutex_t int
#define pthread_mutex_init(x, y) (*(x)=0)
#define pthread_mutex_destroy(x) (*(x)=0)
#define pthread_mutex_lock(x) mutex_lock(x)
#define pthread_mutex_unlock(x) mutex_unlock(x)
int mutex_lock(int *val);
int mutex_unlock(int *val);
#else
#endif
#define _3proxy_mutex_t pthread_mutex_t
#define _3proxy_mutex_init(x) pthread_mutex_init(x,NULL)
#define _3proxy_mutex_destroy pthread_mutex_destroy
#define _3proxy_mutex_lock pthread_mutex_lock
#define _3proxy_mutex_unlock pthread_mutex_unlock
#else
#include <winsock2.h>
#include <ws2tcpip.h>
#define pthread_mutex_t CRITICAL_SECTION
#define pthread_mutex_init(x, y) InitializeCriticalSection(x)
#define pthread_mutex_lock(x) EnterCriticalSection(x)
#define pthread_mutex_unlock(x) LeaveCriticalSection(x)
#define pthread_mutex_destroy(x) DeleteCriticalSection(x)
#define _3proxy_mutex_t CRITICAL_SECTION
#define _3proxy_mutex_init(x) InitializeCriticalSection(x)
#define _3proxy_mutex_lock(x) EnterCriticalSection(x)
#define _3proxy_mutex_unlock(x) LeaveCriticalSection(x)
#define _3proxy_mutex_destroy(x) DeleteCriticalSection(x)
#ifdef MSVC
#pragma warning (disable : 4996)
#endif
@ -511,7 +501,7 @@ struct hashtable {
uint32_t * ihashtable;
uint8_t * hashvalues;
uint8_t * hashhashvalues;
pthread_mutex_t hash_mutex;
_3proxy_mutex_t hash_mutex;
time_t compacted;
uint32_t ihashhashempty;
uint32_t ihashempty;
@ -556,7 +546,7 @@ struct srvparam {
PROXYSOCKADDRTYPE extsa6;
#endif
PROXYSOCKADDRTYPE extsa;
pthread_mutex_t counter_mutex;
_3proxy_mutex_t counter_mutex;
struct pollfd fds;
FILE *stdlog;
unsigned char * target;
@ -673,9 +663,9 @@ struct filemon {
struct extparam {
#ifdef _WIN32
HANDLE threadinit[2];
HANDLE threadinit;
#else
int threadinit[2];
_3proxy_mutex_t threadinit;
#endif
int *timeouts;
struct ace * acl;

View File

@ -17,6 +17,19 @@
#define RETURN(xxx) { param->res = xxx; goto CLEANRET; }
static void udpparam2hash(const struct hashtable *ht, void *index, uint8_t *hash){
struct clientparam *param = (struct clientparam *)index;
uint32_t m1, m2;
m1 = murmurhash3(SAADDR(&param->srv->intsa), SAADDRLEN(&param->srv->intsa), 0x3a3a3a3a);
m1 = murmurhash3(SAPORT(&param->sincr), 2, m1);
m2 = murmurhash3(SAADDR(&param->sincr), SAADDRLEN(&param->sincr), m1);
m2 = murmurhash3(SAPORT(&param->srv->intsa), 2, m2);
memcpy(hash, &m1, 4);
memcpy(hash+4, &m2, 4);
}
struct hashtable udp_table = {udpparam2hash, udpparam2hash, sizeof(struct clientparam *), 8};
void * udppmchild(struct clientparam* param) {
param->clisock = param->srv->srvsock;