From d762833a6b62046050b8e4c92ab47360ef356f15 Mon Sep 17 00:00:00 2001 From: Vladimir Dubrovin <3proxy@3proxy.ru> Date: Wed, 28 Oct 2026 11:57:10 +0300 Subject: [PATCH] Builds: no Solaris makefile, no generic Unix makefile, no gethostbyname() Names are resolved with getaddrinfo(), thread-safe everywhere: what was left of gethostbyname() (my_gethostbyname() over gethostbyname_r(), in its glibc and Solaris forms, GETHOSTBYNAME_R, the mutex for the plain one) served only the IPv4-only resolver already gone. Makefile.Solaris (Sun's compiler, _SOLARIS) and Makefile.unix go: CMake builds for the other systems; the documents say so, and their examples use Makefile.FreeBSD. Co-Authored-By: Claude Opus 5.5 --- CMakeLists.txt | 1 - Makefile.Linux | 2 +- Makefile.Solaris | 72 ---------------------- Makefile.unix | 144 ------------------------------------------- README.md | 1 - doc/html/howtoe.html | 4 +- doc/html/howtor.html | 4 +- doc/ru/example1.txt | 2 +- doc/ru/iodbc.txt | 4 +- src/common.c | 21 ------- src/log.c | 4 -- src/proxy.h | 1 - 12 files changed, 8 insertions(+), 252 deletions(-) delete mode 100644 Makefile.Solaris delete mode 100644 Makefile.unix diff --git a/CMakeLists.txt b/CMakeLists.txt index c27933b..da4708c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -174,7 +174,6 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") # Linux-specific configuration add_compile_definitions( _GNU_SOURCE - GETHOSTBYNAME_R _THREAD_SAFE _REENTRANT ) diff --git a/Makefile.Linux b/Makefile.Linux index 5cb5af5..7c0cbdd 100644 --- a/Makefile.Linux +++ b/Makefile.Linux @@ -14,7 +14,7 @@ CRYPT_PREFIX ?= $(PREFIX) CC ?= gcc CFLAGS ?= -O3 -flto -CFLAGS += -fno-strict-aliasing -c -pthread -DWITHSPLICE -D_GNU_SOURCE -DGETHOSTBYNAME_R -D_THREAD_SAFE -D_REENTRANT -DWITH_NETFILTER -D WITH_UN +CFLAGS += -fno-strict-aliasing -c -pthread -DWITHSPLICE -D_GNU_SOURCE -D_THREAD_SAFE -D_REENTRANT -DWITH_NETFILTER -D WITH_UN COUT = -o LN ?= ${CC} DCFLAGS ?= -fPIC diff --git a/Makefile.Solaris b/Makefile.Solaris deleted file mode 100644 index 36b0f70..0000000 --- a/Makefile.Solaris +++ /dev/null @@ -1,72 +0,0 @@ -# -# 3 proxy Makefile for Solaris/SunCC -# -# -# add -DWITH_ODBC to CFLAGS and -lodbc to LDFLAGS to compile with ODBC -# library support. Add -DSAFESQL for poorely written ODBC library / drivers. - -BUILDDIR = ../bin/ -PREFIX ?= 3proxy_ -CRYPT_PREFIX ?= $(PREFIX) -CC ?= cc -CFLAGS = -xO3 -c -D_SOLARIS -D_THREAD_SAFE -DGETHOSTBYNAME_R -D_REENTRANT -COUT = -o ./ -LN = $(CC) -LDFLAGS = -xO3 -DCFLAGS = -fPIC -MAILPROXY ?= false -ifeq ($(MAILPROXY),true) - CFLAGS += -DWITH_POP3P -DWITH_IMAPP -DWITH_SMTPP - MAIL_EXES = $(BUILDDIR)$(PREFIX)pop3p$(EXESUFFICS) $(BUILDDIR)$(PREFIX)imapp$(EXESUFFICS) $(BUILDDIR)$(PREFIX)smtpp$(EXESUFFICS) -endif -FTP ?= false -ifeq ($(FTP),true) - CFLAGS += -DWITH_FTP - FTP_EXES = $(BUILDDIR)$(PREFIX)ftppr$(EXESUFFICS) -endif -HTTPSRV ?= true -ifeq ($(HTTPSRV),true) - CFLAGS += -DWITH_HTTPSRV - HTTPSRV_OBJS = srvhttpsrv$(OBJSUFFICS) srvwebadmin$(OBJSUFFICS) -endif -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 -PLUGINS = StringsPlugin TrafficPlugin FilePlugin - -WOLFSSL_CHECK = $(shell printf "\#include \\n\#include \\n int main(){return 0;}" | tr -d \\\\ | $(CC) -x c $(CFLAGS) -o testwssl.o - 2>/dev/null && $(CC) $(LDFLAGS) -o testwssl testwssl.o -lwolfssl 2>/dev/null && rm testwssl testwssl.o && echo true||echo false) -ifeq ($(WOLFSSL_CHECK), true) - LIBS += -lwolfssl - CFLAGS += -DWITH_SSL -DWITH_WOLFSSL - SSL_OBJS = ssllib$(OBJSUFFICS) ssl$(OBJSUFFICS) -else -OPENSSL_CHECK = $(shell printf "\#include \\n int main(){return 0;}" | tr -d \\\\ | $(CC) -x c $(CFLAGS) -o testssl.o - 2>/dev/null && $(CC) $(LDFLAGS) -o testssl testssl.o -lcrypto -lssl 2>/dev/null && rm testssl testssl.o && echo true||echo false) -ifeq ($(OPENSSL_CHECK), true) - LIBS += -l crypto -l ssl - CFLAGS += -DWITH_SSL - SSL_OBJS = ssllib$(OBJSUFFICS) ssl$(OBJSUFFICS) -endif -endif -PCRE_CHECK = $(shell printf "\#define PCRE2_CODE_UNIT_WIDTH 8\\n\#include \\n int main(){return 0;}" | tr -d \\\\ | $(CC) -x c $(CFLAGS) -o testpcre.o - 2>/dev/null && $(CC) -o testpcre testpcre.o $(LDFLAGS) -Wl,-Bstatic -lpcre2-8 -Wl,-Bdynamic 2>/dev/null && rm testpcre testpcre.o && echo true||echo false) -ifeq ($(PCRE_CHECK), true) - CFLAGS += -DWITH_PCRE - PCRE_OBJS = pcre$(OBJSUFFICS) - PCRE_LIBS = -Wl,-Bstatic -lpcre2-8 -Wl,-Bdynamic -endif - -include Makefile.inc - -allplugins: - @list='$(PLUGINS)'; for p in $$list; do cp Makefile Makefile.var plugins/$$p; cd plugins/$$p ; make ; cd ../.. ; done diff --git a/Makefile.unix b/Makefile.unix deleted file mode 100644 index 4cfff3f..0000000 --- a/Makefile.unix +++ /dev/null @@ -1,144 +0,0 @@ -# -# 3 proxy Makefile for GCC/Unix -# -# -# add -DWITH_ODBC to CFLAGS and -lodbc to LDFLAGS to compile with ODBC -# 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 -CFLAGS ?= -O3 -flto -CFLAGS += -fno-strict-aliasing -c -pthread -D_THREAD_SAFE -D_REENTRANT -DWITH_UN -COUT = -o -LN ?= $(CC) -LDFLAGS ?= -O3 -flto -LDFLAGS += -pthread -fno-strict-aliasing -# Use EXTRA_CFLAGS/EXTRA_LDFLAGS to add flags from the make command line. -# Setting CFLAGS or LDFLAGS there instead overrides every assignment in this -# makefile, including the += above and the STATIC/LIBSTATIC handling below. -CFLAGS += $(EXTRA_CFLAGS) -LDFLAGS += $(EXTRA_LDFLAGS) -# -lpthreads may be reuqired on some platforms instead of -pthreads -# -ldl or -lld may be required for some platforms -DCFLAGS ?= -fPIC -MAILPROXY ?= false -ifeq ($(MAILPROXY),true) - CFLAGS += -DWITH_POP3P -DWITH_IMAPP -DWITH_SMTPP - MAIL_EXES = $(BUILDDIR)$(PREFIX)pop3p$(EXESUFFICS) $(BUILDDIR)$(PREFIX)imapp$(EXESUFFICS) $(BUILDDIR)$(PREFIX)smtpp$(EXESUFFICS) -endif -FTP ?= false -ifeq ($(FTP),true) - CFLAGS += -DWITH_FTP - FTP_EXES = $(BUILDDIR)$(PREFIX)ftppr$(EXESUFFICS) -endif -HTTPSRV ?= true -ifeq ($(HTTPSRV),true) - CFLAGS += -DWITH_HTTPSRV - HTTPSRV_OBJS = srvhttpsrv$(OBJSUFFICS) srvwebadmin$(OBJSUFFICS) -endif -DLFLAGS ?= -shared -DLSUFFICS ?= .ld.so -LIBS ?= -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.unix -PLUGINS ?= StringsPlugin TrafficPlugin FilePlugin - -# Transparent proxying is not built here: this makefile is for the systems -# without a redirection 3proxy can read the original destination from. Where -# the platform has one - OpenBSD divert-to is the case that fits - uncomment: -#CFLAGS += -DWITH_TRANSPARENT -#TRANSPARENT_OBJS = transparent$(OBJSUFFICS) -ifeq ($(STATIC), true) - LDFLAGS += -static - CFLAGS += -DNOPLUGINS -DNOSTDRESOLVE -DNOCRYPT - ZLIB = -lz -lzstd - PLUGINS = - PAM_CHECK = false -endif -ifeq ($(LIBSTATIC), true) - STATIC_PREFIX = -Wl,-Bstatic - STATIC_SUFFIX = -Wl,-Bdynamic - ZLIB = -lz -lzstd -endif -WOLFSSL_CHECK ?= $(shell printf "\#include \\n\#include \\n int main(){return 0;}" | tr -d \\\\ | $(CC) -x c $(CFLAGS) -o testwssl.o - 2>/dev/null && $(CC) $(LDFLAGS) -otestwssl testwssl.o $(STATIC_PREFIX) -lwolfssl $(STATIC_SUFFIX) 2>/dev/null && rm testwssl testwssl.o && echo true||echo false) -ifeq ($(WOLFSSL_CHECK), true) - LIBS += $(STATIC_PREFIX) -lwolfssl $(STATIC_SUFFIX) - CFLAGS += -DWITH_SSL -DWITH_WOLFSSL - SSL_OBJS = ssllib$(OBJSUFFICS) ssl$(OBJSUFFICS) - ZLIB := -else -OPENSSL_CHECK ?= $(shell printf "\#include \\n int main(){return 0;}" | tr -d \\\\ | $(CC) -x c $(CFLAGS) -o testssl.o - 2>/dev/null && $(CC) $(LDFLAGS) -otestssl testssl.o $(STATIC_PREFIX) $(ZLIB) -lcrypto -lssl $(STATIC_SUFFIX) 2>/dev/null && rm testssl testssl.o && echo true||echo false) -ifeq ($(OPENSSL_CHECK), true) - LIBS += $(STATIC_PREFIX) $(ZLIB) -lcrypto -lssl $(STATIC_SUFFIX) - CFLAGS += -DWITH_SSL - SSL_OBJS = ssllib$(OBJSUFFICS) ssl$(OBJSUFFICS) -else - ZLIB := -endif -endif -PCRE_CHECK ?= $(shell printf "\#define PCRE2_CODE_UNIT_WIDTH 8\\n\#include \\n int main(){return 0;}" | tr -d \\\\ | $(CC) -x c $(CFLAGS) -o testpcre.o - 2>/dev/null && $(CC) -o testpcre testpcre.o $(LDFLAGS) $(STATIC_PREFIX) -lpcre2-8 $(STATIC_SUFFIX) 2>/dev/null && rm testpcre testpcre.o && echo true||echo false) -ifeq ($(PCRE_CHECK), true) - CFLAGS += -DWITH_PCRE - PCRE_OBJS = pcre$(OBJSUFFICS) - PCRE_LIBS = $(STATIC_PREFIX) -lpcre2-8 $(STATIC_SUFFIX) -endif -PAM_CHECK ?= $(shell printf "\#include \\n int main(){return 0;}" | tr -d \\\\ | $(CC) -x c $(CFLAGS) -o testpam.o - 2>/dev/null && $(CC) $(LDFLAGS) -o testpam testpam.o -lpam 2>/dev/null && rm testpam testpam.o && echo true||echo false) -ifeq ($(PAM_CHECK), true) - PLUGINS += PamAuth -endif - -include Makefile.inc - -DESTDIR ?= -prefix ?= /usr/local -BINPREFIX ?= $(prefix)/bin - -install: all - if [ ! -d "$(DESTDIR)$(BINPREFIX)" ]; then mkdir -p $(DESTDIR)$(BINPREFIX)/; fi - install bin/3proxy $(DESTDIR)$(BINPREFIX)/3proxy - install bin/$(CRYPT_PREFIX)crypt $(DESTDIR)$(BINPREFIX)/$(CRYPT_PREFIX)crypt - for f in proxy socks pop3p imapp smtpp ftppr tcppm udppm tlspr; do \ - if [ -f bin/$(PREFIX)$$f ]; then install bin/$(PREFIX)$$f $(DESTDIR)$(BINPREFIX)/$(PREFIX)$$f; fi; \ - done - install -d $(DESTDIR)$(prefix)/etc/3proxy/conf - install -d $(DESTDIR)$(prefix)/etc/rc.d/ - sed -e 's|@CMAKE_INSTALL_FULL_BINDIR@|$(BINPREFIX)|g' -e 's|@CMAKE_INSTALL_FULL_SYSCONFDIR@|$(prefix)/etc|g' scripts/rc.d/3proxy.in > $(DESTDIR)$(prefix)/etc/rc.d/3proxy - chmod 755 $(DESTDIR)$(prefix)/etc/rc.d/3proxy - sed -e 's|@CMAKE_INSTALL_FULL_BINDIR@|$(BINPREFIX)|g' -e 's|@3PROXY_CONFDIR@|$(prefix)/etc/3proxy/conf|g' -e 's|@CRYPT_PREFIX@|$(CRYPT_PREFIX)|g' scripts/add3proxyuser.sh.in > $(DESTDIR)$(BINPREFIX)/add3proxyuser - chmod 755 $(DESTDIR)$(BINPREFIX)/add3proxyuser - if [ -s $(DESTDIR)$(prefix)/etc/3proxy/3proxy.cfg ]; then echo $(prefix)/etc/3proxy/3proxy.cfg already exists; else sed -e 's|@CMAKE_INSTALL_FULL_SYSCONFDIR@|$(prefix)/etc|g' -e 's|@3PROXY_CONFDIR@|$(prefix)/etc/3proxy/conf|g' -e 's|@3PROXY_COUNTERDIR@|/opt/3proxy|g' scripts/3proxy.cfg.in > $(DESTDIR)$(prefix)/etc/3proxy/3proxy.cfg; chmod 640 $(DESTDIR)$(prefix)/etc/3proxy/3proxy.cfg; fi - if [ ! -d $(DESTDIR)/var/log/3proxy/ ]; then mkdir -p $(DESTDIR)/var/log/3proxy/; fi - mkdir -p $(DESTDIR)/opt/3proxy - touch $(DESTDIR)$(prefix)/etc/3proxy/conf/passwd - touch $(DESTDIR)$(prefix)/etc/3proxy/conf/counters - touch $(DESTDIR)$(prefix)/etc/3proxy/conf/bandlimiters - install -d $(DESTDIR)$(MANDIR)/man8 - install -m 644 man/3proxy.8 $(DESTDIR)$(MANDIR)/man8/3proxy.8 - for f in proxy socks pop3p imapp smtpp ftppr tcppm udppm tlspr; do \ - if [ -f man/$$f.8 ] && [ -f bin/$(PREFIX)$$f ]; then install -m 644 man/$$f.8 $(DESTDIR)$(MANDIR)/man8/$(PREFIX)$$f.8; fi; \ - done - install -m 644 man/3proxy_crypt.8 $(DESTDIR)$(MANDIR)/man8/$(CRYPT_PREFIX)crypt.8 - install -d $(DESTDIR)$(MANDIR)/man5 - install -m 644 man/3proxy.cfg.5 $(DESTDIR)$(MANDIR)/man5/3proxy.cfg.5 - @if [ "$(DESTDIR)" = "" ]; then \ - sh scripts/postinstall.sh $(prefix); \ - fi - echo Run $(BINPREFIX)/add3proxyuser to add \'admin\' user - -allplugins: - @list='$(PLUGINS)'; for p in $$list; do cp Makefile Makefile.var plugins/$$p; cd plugins/$$p ; make ; cd ../.. ; done diff --git a/README.md b/README.md index 2f9127b..e96bb0e 100644 --- a/README.md +++ b/README.md @@ -360,7 +360,6 @@ sudo launchctl unload /Library/LaunchDaemons/org.3proxy.3proxy.plist - Cygwin/gcc (cygwin.dll) - Unix/gcc - Unix/ccc -- Solaris - Mac OS X, iPhone OS - Linux and derived systems - 32 bit and 64 bit versions for Windows Vista and above, Windows 2008 server and above diff --git a/doc/html/howtoe.html b/doc/html/howtoe.html index 33de486..83a9d31 100644 --- a/doc/html/howtoe.html +++ b/doc/html/howtoe.html @@ -114,9 +114,9 @@ For FreeBSD, use: ln -sf Makefile.FreeBSD Makefile make -For other Unix-like systems, use Makefile.unix. On BSD-derived systems, make +For other Unix-like systems, use CMake. On BSD-derived systems, make sure to use GNU make; sometimes it's called gmake instead of make. -
Compilation is tested under FreeBSD, NetBSD, OpenBSD, Linux, Solaris, and macOS. +
Compilation is tested under FreeBSD, NetBSD, OpenBSD, Linux, and macOS.
For ODBC support, install Unix ODBC libraries, remove -DNOODBC from the makefile, and add the ODBC library to the linker variable.
Binaries will be placed in the bin/ directory. diff --git a/doc/html/howtor.html b/doc/html/howtor.html index a48ee3e..850d8b5 100644 --- a/doc/html/howtor.html +++ b/doc/html/howtor.html @@ -114,9 +114,9 @@
     ln -sf Makefile.FreeBSD Makefile
     make
- Для других Unix-подобных систем используйте Makefile.unix. На BSD-производных системах + Для других Unix-подобных систем используйте CMake. На BSD-производных системах убедитесь, что используете GNU make; иногда он называется gmake вместо make. -
Компиляция проверена на FreeBSD, NetBSD, OpenBSD, Linux, Solaris и macOS. +
Компиляция проверена на FreeBSD, NetBSD, OpenBSD, Linux и macOS.
Для поддержки ODBC необходимо установить Unix ODBC, убрать -DNOODBC из флагов компиляции и добавить ODBC-библиотеку к флагам линковщика.
Исполняемые файлы будут помещены в каталог bin/. diff --git a/doc/ru/example1.txt b/doc/ru/example1.txt index 5b34c4e..023242b 100644 --- a/doc/ru/example1.txt +++ b/doc/ru/example1.txt @@ -27,7 +27,7 @@ TCP & UDP маппинг портов; # wget http://3proxy.ru/current/3proxy.tgz # tar -xvzf 3proxy.tgz # cd 3proxy -# make -f Makefile.unix +# make -f Makefile.FreeBSD # mkdir /usr/local/3proxy # mkdir /usr/local/3proxy/logs # mkdir /usr/local/3proxy/stat diff --git a/doc/ru/iodbc.txt b/doc/ru/iodbc.txt index 4b39521..cba9f6b 100644 --- a/doc/ru/iodbc.txt +++ b/doc/ru/iodbc.txt @@ -88,7 +88,7 @@ l_descr) values ('%d-%m-%Y', '%H:%M:%S', '%U', '%N', %I, %O, '%T')" ------------------------------------------ -Cобрать 3proxy c поддрежкой iODBC, для этого в Makefile.unix поменять +Cобрать 3proxy c поддрежкой iODBC, для этого в Makefile.FreeBSD поменять CFLAGS = -Wall -O2 -c -pthread -D_THREAD_SAFE -D_REENTRANT -DWITH_STD_MALLOC -I/usr/local/include LIBS = -L /usr/local/lib -lodbc @@ -96,5 +96,5 @@ LIBS = -L /usr/local/lib -lodbc и дать команды make clean -make -f Makefile.unix +make -f Makefile.FreeBSD diff --git a/src/common.c b/src/common.c index adf7b59..3b8f8d2 100644 --- a/src/common.c +++ b/src/common.c @@ -951,27 +951,6 @@ static RESOLVFUNC moderesolver(int mode){ } return resolvfunc; } -#ifndef _WIN32 -_3proxy_mutex_t gethostbyname_mutex; -int ghbn_init = 0; -#endif - -#ifndef NOSTDRESOLVE -#ifdef GETHOSTBYNAME_R -struct hostent * my_gethostbyname(char *name, char *buf, struct hostent *hp){ - struct hostent *result; - int gherrno; - -#ifdef _SOLARIS - return gethostbyname_r(name, hp, buf, 1024, &gherrno); -#else - if(gethostbyname_r(name, hp, buf, 1024, &result, &gherrno) != 0) - return NULL; - return result; -#endif -} -#endif -#endif int afdetect(unsigned char *name){ diff --git a/src/log.c b/src/log.c index 8644f2b..4890e8f 100644 --- a/src/log.c +++ b/src/log.c @@ -94,12 +94,8 @@ static int dobuf3(struct clientparam * param, unsigned char * buf, const unsigne #ifdef _WIN32 ftime(&tb); timezone = tm->tm_isdst*60 - tb.timezone; -#else -#ifdef _SOLARIS - timezone = -altzone / 60; #else timezone = tm->tm_gmtoff / 60; -#endif #endif delay = param->time_start?((unsigned) ((sec - param->time_start))*1000 + msec) - param->msec_start : 0; diff --git a/src/proxy.h b/src/proxy.h index aa4797d..3641793 100644 --- a/src/proxy.h +++ b/src/proxy.h @@ -399,7 +399,6 @@ int handleredirect(struct clientparam * param, struct ace * acentry); int scanaddr(const unsigned char *s, uint32_t * ip, uint32_t * mask); int myinet_ntop(int af, void *src, char *dst, socklen_t size); -uint32_t getip(unsigned char *name); uint32_t getip46(int family, unsigned char *name, struct sockaddr *sa); uint32_t getip46m(int mode, int family, unsigned char *name, struct sockaddr *sa); int afdetect(unsigned char *name);