mirror of
https://github.com/3proxy/3proxy.git
synced 2026-11-26 23:59:41 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
122ca26249 | ||
|
|
6369fe966e | ||
|
|
cb27ca5223 | ||
|
|
932c4e3fd9 | ||
|
|
6818872f63 | ||
|
|
81a4e5bae3 | ||
|
|
0ae2754c1e | ||
|
|
05f83896bf | ||
|
|
f668a34910 | ||
|
|
763e21e053 | ||
|
|
7b85f6a684 | ||
|
|
92d3b08dd2 | ||
|
|
4877b39f2c | ||
|
|
44c47ee7d9 | ||
|
|
5f1ed7363b | ||
|
|
c370635fc4 | ||
|
|
3bfabb29f8 | ||
|
|
e4a5a7252c | ||
|
|
5f542a505a | ||
|
|
5b7446ba8f | ||
|
|
4af02c9268 | ||
|
|
ed5103d176 | ||
|
|
75dedeff28 | ||
|
|
c60af54c98 | ||
|
|
01f85cf755 | ||
|
|
305f9932ac | ||
|
|
c94766dff7 | ||
|
|
87fc8ae4ee | ||
|
|
9ab2e820b5 | ||
|
|
7798f78137 | ||
|
|
d60ac723a5 | ||
|
|
afb2ec0696 | ||
|
|
f18a751f89 | ||
|
|
8de071aa87 | ||
|
|
f173f8860d | ||
|
|
3a66c0a4c0 | ||
|
|
66ee250e5c | ||
|
|
c893e866bd | ||
|
|
fbc0953d5c | ||
|
|
37b1ab8169 | ||
|
|
b7769d05af | ||
|
|
fdda69c1f4 | ||
|
|
a757fae617 | ||
|
|
1c9577b9a9 | ||
|
|
b59c044663 | ||
|
|
de5acb2abd | ||
|
|
d6dea13a6f | ||
|
|
a04cd67eaa |
No files matched your search
@@ -0,0 +1,73 @@
|
||||
# Exclude top-level dirs not needed for build
|
||||
/bin/
|
||||
/bin64/
|
||||
/build/
|
||||
/cfg/
|
||||
/cmake/
|
||||
/CMakeFiles/
|
||||
/debian/
|
||||
/doc/
|
||||
/man/
|
||||
|
||||
# Build artifacts
|
||||
**/*.o
|
||||
**/*.obj
|
||||
**/*.so
|
||||
**/*.dll
|
||||
**/*.exe
|
||||
**/*.exp
|
||||
**/*.lib
|
||||
**/*.pdb
|
||||
**/*.ilk
|
||||
**/*.idb
|
||||
**/*.err
|
||||
**/*.ld.so
|
||||
**/*.dSYM
|
||||
**/*.var
|
||||
build*/
|
||||
buildlinux.sh
|
||||
tmp/
|
||||
|
||||
# macOS
|
||||
.DS_Store
|
||||
|
||||
# Editor / IDE
|
||||
**/*.swp
|
||||
**/*.swo
|
||||
**/*~
|
||||
**/*.bak
|
||||
**/*.tmp
|
||||
**/*.log
|
||||
.project
|
||||
.cproject
|
||||
.classpath
|
||||
.settings/
|
||||
.vscode/
|
||||
.idea/
|
||||
|
||||
# Git
|
||||
.git
|
||||
.gitignore
|
||||
|
||||
# Claude / docs
|
||||
CLAUDE.md
|
||||
.claude/
|
||||
|
||||
# Generated version files
|
||||
version
|
||||
version.c
|
||||
version.sh
|
||||
verfile.sh
|
||||
|
||||
# Local config / keys
|
||||
**/*.key
|
||||
**/*.pem
|
||||
**/*.pfx
|
||||
3proxy.cfg
|
||||
3proxy-ssl.cfg
|
||||
3proxy-pcre.cfg
|
||||
|
||||
# Misc
|
||||
res
|
||||
3proxy.res
|
||||
copytgz.sh
|
||||
@@ -88,6 +88,7 @@ jobs:
|
||||
run: Compress-Archive -Path dist/* -DestinationPath 3proxy-${{ env.RELEASE }}-lite.zip
|
||||
- name: Upload to release
|
||||
if: github.event_name == 'release'
|
||||
shell: bash
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
TAG: ${{ github.event.release.tag_name }}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
name: Build 3proxy with MSYS2 UCRT64
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
name: "msys2-ucrt64"
|
||||
runs-on: windows-2022
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
- name: Setup MSYS2 (UCRT64)
|
||||
uses: msys2/setup-msys2@v2
|
||||
with:
|
||||
msystem: UCRT64
|
||||
update: true
|
||||
install: >-
|
||||
make
|
||||
mingw-w64-ucrt-x86_64-gcc
|
||||
mingw-w64-ucrt-x86_64-pcre2
|
||||
mingw-w64-ucrt-x86_64-openssl
|
||||
mingw-w64-ucrt-x86_64-zlib
|
||||
- name: set date
|
||||
shell: pwsh
|
||||
run: |
|
||||
$NOW = Get-Date -Format "yyMMddHHmmss"
|
||||
$RELEASE = Get-Content -Path "RELEASE" -Raw
|
||||
echo "NOW=$NOW" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
|
||||
echo "RELEASE=$RELEASE" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
|
||||
- name: make Windows (Makefile.win)
|
||||
shell: msys2 {0}
|
||||
env:
|
||||
LIBSTATIC: 'true'
|
||||
run: make -f Makefile.win
|
||||
- name: make dist dir
|
||||
shell: cmd
|
||||
run: |
|
||||
mkdir dist
|
||||
mkdir dist\3proxy
|
||||
mkdir dist\3proxy\bin
|
||||
mkdir dist\3proxy\cfg
|
||||
mkdir dist\3proxy\cfg\sql
|
||||
mkdir dist\3proxy\doc
|
||||
mkdir dist\3proxy\doc\ru
|
||||
mkdir dist\3proxy\doc\html
|
||||
mkdir dist\3proxy\doc\html\plugins
|
||||
mkdir dist\3proxy\doc\html\man5
|
||||
mkdir dist\3proxy\doc\html\man8
|
||||
mkdir dist\3proxy\doc\html\devel
|
||||
copy bin\3proxy.exe dist\3proxy\bin\
|
||||
copy bin\*.dll dist\3proxy\bin\
|
||||
copy bin\3proxy_crypt.exe dist\3proxy\bin\
|
||||
copy cfg\*.* dist\3proxy\cfg\
|
||||
copy cfg\sql\*.* dist\3proxy\cfg\sql\
|
||||
copy doc\ru\*.* dist\3proxy\doc\ru\
|
||||
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\man5\*.* dist\3proxy\doc\html\man5\
|
||||
copy doc\html\devel\*.* dist\3proxy\doc\html\devel\
|
||||
copy copying dist\3proxy\
|
||||
copy authors dist\3proxy\
|
||||
copy README.md dist\3proxy\
|
||||
copy rus.3ps dist\3proxy\
|
||||
- name: Get artifact
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: "3proxy-${{ env.RELEASE }}-msys2-ucrt64"
|
||||
path: dist/
|
||||
@@ -28,7 +28,7 @@ jobs:
|
||||
echo "VERSION=/D `"VERSION=\`"3proxy-$RELEASE\`"`"" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
|
||||
echo "BUILDDATE=/D `"BUILDDATE=\`"$NOW\`"`"" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
|
||||
- name: install packages
|
||||
run: vcpkg install pcre2:x86-windows-static openssl:x86-windows-static
|
||||
run: vcpkg install pcre2:x86-windows-static wolfssl:x86-windows-static
|
||||
- name: Add msbuild to PATH
|
||||
uses: microsoft/setup-msbuild@v3
|
||||
- name: make Windows MSVC
|
||||
@@ -41,7 +41,7 @@ jobs:
|
||||
set "LIB=%LIB%;c:/vcpkg/installed/x86-windows-static/lib"
|
||||
set "INCLUDE=%INCLUDE%;c:/vcpkg/installed/x86-windows-static/include"
|
||||
echo "volatile char VerSion[]=^"3APA3A-3proxy-Internal-Build: 3proxy-%RELEASE%-%NOW%\r\nCode certificate: https://3proxy.org/3proxy.cer\r\n^";" >>src/3proxy.c
|
||||
nmake /F Makefile.msvc
|
||||
nmake /F Makefile.msvc WOLFSSL=1
|
||||
- name: Decode Certificate
|
||||
shell: pwsh
|
||||
run: |
|
||||
@@ -95,7 +95,7 @@ jobs:
|
||||
- name: Get artifact
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: "3proxy-${{ env.RELEASE }}"
|
||||
name: "3proxy-${{ env.RELEASE }}-x86"
|
||||
path: dist/
|
||||
- name: Create zip
|
||||
if: github.event_name == 'release'
|
||||
@@ -103,6 +103,7 @@ jobs:
|
||||
run: Compress-Archive -Path dist/* -DestinationPath 3proxy-${{ env.RELEASE }}-x86.zip
|
||||
- name: Upload to release
|
||||
if: github.event_name == 'release'
|
||||
shell: bash
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
TAG: ${{ github.event.release.tag_name }}
|
||||
|
||||
@@ -29,7 +29,7 @@ jobs:
|
||||
echo "VERSION=/D `"VERSION=\`"3proxy-$RELEASE\`"`"" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
|
||||
echo "BUILDDATE=/D `"BUILDDATE=\`"$NOW\`"`"" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
|
||||
- name: install packages
|
||||
run: vcpkg install pcre2:x64-windows-static openssl:x64-windows-static
|
||||
run: vcpkg install pcre2:x64-windows-static wolfssl:x64-windows-static
|
||||
- name: Add msbuild to PATH
|
||||
uses: microsoft/setup-msbuild@v3
|
||||
- name: make Windows MSVC
|
||||
@@ -42,7 +42,7 @@ jobs:
|
||||
set "INCLUDE=%INCLUDE%;c:/vcpkg/installed/x64-windows-static/include"
|
||||
echo "volatile char VerSion[]=^"3APA3A-3proxy-Internal-Build: 3proxy-%RELEASE%-%NOW%\r\nCode certificate: https://3proxy.org/3proxy.cer\r\n^";" >>src/3proxy.c
|
||||
echo %NOW% / %RELEASE% / %BUILDDATE% / %VERSION%
|
||||
nmake /F Makefile.msvc
|
||||
nmake /F Makefile.msvc WOLFSSL=1
|
||||
- name: Decode Certificate
|
||||
shell: pwsh
|
||||
run: |
|
||||
@@ -104,6 +104,7 @@ jobs:
|
||||
run: Compress-Archive -Path dist/* -DestinationPath 3proxy-${{ env.RELEASE }}-x64.zip
|
||||
- name: Upload to release
|
||||
if: github.event_name == 'release'
|
||||
shell: bash
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
TAG: ${{ github.event.release.tag_name }}
|
||||
|
||||
@@ -28,7 +28,7 @@ jobs:
|
||||
echo "VERSION=/D `"VERSION=\`"3proxy-$RELEASE\`"`"" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
|
||||
echo "BUILDDATE=/D `"BUILDDATE=\`"$NOW\`"`"" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
|
||||
- name: install packages
|
||||
run: vcpkg install pcre2:arm64-windows-static openssl:arm64-windows-static
|
||||
run: vcpkg install pcre2:arm64-windows-static wolfssl:arm64-windows-static
|
||||
- name: Add msbuild to PATH
|
||||
uses: microsoft/setup-msbuild@v3
|
||||
- name: make Windows MSVC
|
||||
@@ -41,7 +41,7 @@ jobs:
|
||||
set "LIB=%LIB%;c:/vcpkg/installed/arm64-windows-static/lib"
|
||||
set "INCLUDE=%INCLUDE%;c:/vcpkg/installed/arm64-windows-static/include"
|
||||
echo "volatile char VerSion[]=^"3APA3A-3proxy-Internal-Build: 3proxy-%RELEASE%-%NOW%\r\nCode certificate: https://3proxy.org/3proxy.cer\r\n^";" >>src/3proxy.c
|
||||
nmake /F Makefile.msvc
|
||||
nmake /F Makefile.msvc WOLFSSL=1
|
||||
- name: Decode Certificate
|
||||
shell: pwsh
|
||||
run: |
|
||||
@@ -103,6 +103,7 @@ jobs:
|
||||
run: Compress-Archive -Path dist/* -DestinationPath 3proxy-${{ env.RELEASE }}-arm64.zip
|
||||
- name: Upload to release
|
||||
if: github.event_name == 'release'
|
||||
shell: bash
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
TAG: ${{ github.event.release.tag_name }}
|
||||
|
||||
@@ -25,7 +25,7 @@ jobs:
|
||||
# run: ./configure
|
||||
- name: Linux libraries
|
||||
if: ${{ startsWith(matrix.target, 'ubuntu') }}
|
||||
run: sudo apt install libssl-dev libpam-dev libpcre2-dev
|
||||
run: sudo apt-get update && sudo apt-get install -y libssl-dev libpam-dev libpcre2-dev
|
||||
- name: make
|
||||
run: make -f Makefile.Linux
|
||||
- name: mkdir
|
||||
|
||||
@@ -21,7 +21,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
- name: install Windows libraries
|
||||
run: vcpkg install pcre2:x64-windows && c:\msys64\usr\bin\pacman.exe -S --noconfirm mingw-w64-x86_64-pcre2 mingw-w64-x86_64-openssl
|
||||
run: vcpkg install pcre2:x64-windows wolfssl:x64-windows-static && c:\msys64\usr\bin\pacman.exe -S --noconfirm mingw-w64-x86_64-pcre2 mingw-w64-x86_64-wolfssl
|
||||
- name: make Windows
|
||||
run: make -f Makefile.win
|
||||
env:
|
||||
@@ -37,7 +37,7 @@ jobs:
|
||||
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
|
||||
D:
|
||||
cd "D:/a/3proxy/3proxy"
|
||||
set "LIB=%LIB%;c:/program files/openssl/lib/VC/x64/MT;c:/vcpkg/installed/x64-windows/lib"
|
||||
set "INCLUDE=%INCLUDE%;c:/program files/openssl/include;c:/vcpkg/installed/x64-windows/include"
|
||||
nmake /F Makefile.msvc
|
||||
set "LIB=%LIB%;c:/vcpkg/installed/x64-windows-static/lib;c:/vcpkg/installed/x64-windows/lib"
|
||||
set "INCLUDE=%INCLUDE%;c:/vcpkg/installed/x64-windows-static/include;c:/vcpkg/installed/x64-windows/include"
|
||||
nmake /F Makefile.msvc WOLFSSL=1 || exit /b 1
|
||||
nmake /F Makefile.msvc clean
|
||||
@@ -27,7 +27,7 @@ jobs:
|
||||
# run: ./configure
|
||||
- name: Linux libraries
|
||||
if: ${{ startsWith(matrix.target, 'ubuntu') }}
|
||||
run: sudo apt install libssl-dev libpam-dev libpcre2-dev
|
||||
run: sudo apt-get update && sudo apt-get install -y libssl-dev libpam-dev libpcre2-dev
|
||||
- name: Mac libraries
|
||||
if: ${{ startsWith(matrix.target, 'macos') }}
|
||||
run: brew install pcre2
|
||||
@@ -57,3 +57,18 @@ jobs:
|
||||
cmake --build .
|
||||
cd ..
|
||||
rmdir /s /q build
|
||||
|
||||
wolfssl:
|
||||
name: "ubuntu-latest (wolfSSL)"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
- name: Install wolfSSL
|
||||
run: sudo apt-get update && sudo apt-get install -y libwolfssl-dev
|
||||
- name: make with CMake (wolfSSL preferred)
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
cmake --build .
|
||||
cd .. && rm -rf build/
|
||||
@@ -0,0 +1,35 @@
|
||||
name: Build Docker images (test, no publish)
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build ${{ matrix.file }} (${{ matrix.platform }})
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
file: [Dockerfile.minimal, Dockerfile.busybox, Dockerfile.full]
|
||||
platform: [linux/amd64, linux/arm64]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v7
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v4
|
||||
|
||||
- name: Build image
|
||||
uses: docker/build-push-action@v7
|
||||
with:
|
||||
context: .
|
||||
file: ${{ matrix.file }}
|
||||
platforms: ${{ matrix.platform }}
|
||||
push: false
|
||||
load: ${{ matrix.platform == 'linux/amd64' }}
|
||||
+6
-1
@@ -18,6 +18,7 @@ bin/socks
|
||||
bin/tcppm
|
||||
bin/udppm
|
||||
bin/pop3p
|
||||
bin/imapp
|
||||
bin/smtpp
|
||||
bin/ftppr
|
||||
bin/mycrypt
|
||||
@@ -45,6 +46,7 @@ src/socks
|
||||
src/tcppm
|
||||
src/udppm
|
||||
src/pop3p
|
||||
src/imapp
|
||||
src/smtpp
|
||||
src/ftppr
|
||||
src/icqpr
|
||||
@@ -261,10 +263,13 @@ CLAUDE.md
|
||||
bin/3proxy_crypt
|
||||
bin/3proxy_ftppr
|
||||
bin/3proxy_pop3p
|
||||
bin/3proxy_imapp
|
||||
bin/3proxy_proxy
|
||||
bin/3proxy_smtpp
|
||||
bin/3proxy_socks
|
||||
bin/3proxy_tcppm
|
||||
bin/3proxy_tlspr
|
||||
bin/3proxy_udppm
|
||||
build*/*
|
||||
build*/*
|
||||
testcerts/
|
||||
/.claude
|
||||
@@ -1,25 +1,28 @@
|
||||
3proxy-0.9.7 Released July, 4 2026
|
||||
3proxy-0.9.8 Released August, 7 2026
|
||||
|
||||
+ PCRE2 and SSL/TLS code moved from plugins into main 3proxy binary; dynamic linking with ssl/pcre by default, STATIC/LIBSTATIC options for static linking
|
||||
+ Unix sockets support for parent proxies, tcppm, internal listeners and -i option; abstract (fileless) unix sockets on Linux
|
||||
+ ssl_client_mode = 3 to use 'secure' parent types: https, tcps, socks5s, connect+s, etc.
|
||||
+ New authcache types: cacheacl, dstaddr, dstport, dsthost, dstoper, srvaddr, srvport; authcache is now configurable per service
|
||||
+ Hashtables for password lists and authcache, faster password lookups
|
||||
+ 3proxy_crypt: new internal password hashing replacing mycrypt
|
||||
+ udppm switched to hashtables and supports multiple connections
|
||||
+ SOCKSv5 UDP parent support; -Ne/-Ni NAT options
|
||||
+ Docker images for more platforms, signed; DLLs signed; public cert added to build
|
||||
+ Grace sleep and linger on connection close; correctly process half-closed connections
|
||||
+ Allow setting internal/external network namespaces on Linux
|
||||
- icqpr/OSCAR code removed
|
||||
! Fix: invalid error in SSL server handshake could break service state
|
||||
! Fix: invalid offset in datafilters
|
||||
! Fix: invalid socket in poll() could break sockmap() on Windows
|
||||
! Fix: deadlock in ftppr
|
||||
! Fix: crash on standalone services
|
||||
! Fix: non-initialized mutex crash under Windows
|
||||
! Fix: socks v5 parent with no auth
|
||||
! Fix: hanging connections in sockmap; unneeded poll in sockmap
|
||||
! Fix: symbols collision with OpenSSL could lead to crash
|
||||
! Fix: compatibility with older SSL versions and older Windows (7 and below)
|
||||
!! Fix: use-after-free on the ftp:// request path in HTTP proxy, a request buffer reallocation left a stale pointer; heap corruption, requires authenticated access
|
||||
!! Fix: buffer overflow in radsend() with an oversized request hostname; RADIUS is experimental, log radius or auth radius with fakeresolve is required to reach it
|
||||
!! Fix: buffer overflow in smtpp when relaying AUTH LOGIN credentials to a server which offers AUTH PLAIN only; requires authorised access to smtpp
|
||||
!! Fix: out-of-bounds read in tlspr on a malformed TLS ClientHello
|
||||
!! Fix: LDAP injection and unsafe counter file names in LdapPlugin; the plugin is unsupported and is not built with 3proxy
|
||||
!! Fix: password and hash comparison in strong authentication is constant-time now
|
||||
!! Fix: bounds validation and match/depth limits in pcre filters
|
||||
+ imapp: IMAPv4 proxy added, supports LOGIN command, AUTH PLAIN and AUTH LOGIN
|
||||
+ STARTTLS support for smtpp, pop3p, imapp and tlspr, on both client and server side; -x option to disable
|
||||
+ wolfSSL is supported as an alternative TLS backend, WOLFSSL_CHECK=true selects it (wolfSSL must be built with --enable-opensslextra)
|
||||
+ Chunked Transfer-Encoding from client is supported by HTTP proxy
|
||||
+ dnspr: -F option added, fake resolve to redirect traffic
|
||||
+ ucrt64 build support; static libraries support in Makefile.win
|
||||
+ minimal and busybox Docker images switched to musl + wolfSSL
|
||||
- splice() support is not built by default anymore, it is slower than the read/write path for most traffic; add -DWITHSPLICE to build it
|
||||
! Fix: hashtable item was added with wrong index on table grow; with large username/password tables it could cause a single record to be missing
|
||||
! Fix: race conditions; stack overflow on FreeBSD
|
||||
! Fix: generated certificates are X.509 v3 with basicConstraints CA:FALSE and extendedKeyUsage serverAuth, required by Apple TLS stack and by Chrome on macOS/iOS
|
||||
! Fix: dnspr was broken since udppm rewrite
|
||||
! Fix: short cleartext passwords failed authentication
|
||||
! Fix: parent negotiation after sending PROXY protocol header
|
||||
! Fix: maxchild dropped to 100 on config reload if not set explicitly
|
||||
! Fix: getrandom() is not used with glibc below 2.25
|
||||
! Fix: IPV6_BOUND_IF definition for legacy MacOS
|
||||
! Fix: cmake build, arm64 Docker build, Makefile.win with UCRT
|
||||
! Multiple minor bugfixes and code cleanup
|
||||
+26
-23
@@ -1,25 +1,28 @@
|
||||
3proxy-0.9.7 Вышел 4 Июля 2026
|
||||
3proxy-0.9.8 Вышел 7 Августа 2026
|
||||
|
||||
+ Код PCRE2 и SSL/TLS перенесён из плагинов в основной бинарный файл 3proxy; по умолчанию динамическое связывание с ssl/pcre, опции STATIC/LIBSTATIC для статического связывания
|
||||
+ Поддержка unix-сокетов для родительских прокси, tcppm, внутренних слушателей и опции -i; абстрактные (безфайловые) unix-сокеты в Linux
|
||||
+ ssl_client_mode = 3 для использования «безопасных» типов родителя: https, tcps, socks5s, connect+s и т.д.
|
||||
+ Новые типы authcache: cacheacl, dstaddr, dstport, dsthost, dstoper, srvaddr, srvport; authcache настраивается для каждого сервиса
|
||||
+ Хеш-таблицы для списков паролей и authcache, более быстрый поиск паролей
|
||||
+ 3proxy_crypt: новое внутреннее хеширование паролей, заменяющее mycrypt
|
||||
+ udppm переведён на хеш-таблицы и поддерживает множество соединений
|
||||
+ Поддержка UDP-родителя для SOCKSv5; опции NAT -Ne/-Ni
|
||||
+ Docker-образы для большего числа платформ, подписанные; подписанные DLL; публичный сертификат добавлен в сборку
|
||||
+ Grace sleep и linger при закрытии соединения; корректная обработка полузакрытых соединений
|
||||
+ Разрешено задавать внутренние/внешние сетевые пространства имён (network namespaces) в Linux
|
||||
- Код icqpr/OSCAR удалён
|
||||
! Исправление: некорректная ошибка в SSL server handshake могла ломать состояние сервиса
|
||||
! Исправление: некорректное смещение в datafilters
|
||||
! Исправление: некорректный сокет в poll() мог ломать sockmap() в Windows
|
||||
! Исправление: взаимоблокировка (deadlock) в ftppr
|
||||
! Исправление: падение на standalone-сервисах
|
||||
! Исправление: падение из-за неинициализированного mutex в Windows
|
||||
! Исправление: родитель socks v5 без аутентификации
|
||||
! Исправление: зависающие соединения в sockmap; лишний poll в sockmap
|
||||
! Исправление: конфликт символов с OpenSSL мог приводить к падению
|
||||
! Исправление: совместимость со старыми версиями SSL и старыми версиями Windows (7 и ниже)
|
||||
!! Исправление: use-after-free на пути обработки запроса ftp:// в HTTP-прокси, перевыделение буфера запроса оставляло устаревший указатель; повреждение кучи, требуется аутентифицированный доступ
|
||||
!! Исправление: переполнение буфера в radsend() при слишком длинном имени хоста в запросе; RADIUS является экспериментальным, для достижения кода необходимы log radius или auth radius в сочетании с fakeresolve
|
||||
!! Исправление: переполнение буфера в smtpp при передаче учётных данных AUTH LOGIN серверу, поддерживающему только AUTH PLAIN; требуется авторизованный доступ к smtpp
|
||||
!! Исправление: чтение за границами буфера в tlspr при некорректном TLS ClientHello
|
||||
!! Исправление: LDAP-инъекция и небезопасные имена файлов счётчиков в LdapPlugin; плагин не поддерживается и не собирается вместе с 3proxy
|
||||
!! Исправление: сравнение паролей и хешей в strong-аутентификации теперь выполняется за постоянное время
|
||||
!! Исправление: проверка границ и ограничения match/depth в pcre-фильтрах
|
||||
+ imapp: добавлен IMAPv4-прокси, поддерживаются команда LOGIN, AUTH PLAIN и AUTH LOGIN
|
||||
+ Поддержка STARTTLS для smtpp, pop3p, imapp и tlspr, как со стороны клиента, так и со стороны сервера; опция -x для отключения
|
||||
+ wolfSSL поддерживается как альтернативный TLS-бэкенд, выбирается через WOLFSSL_CHECK=true (wolfSSL должен быть собран с --enable-opensslextra)
|
||||
+ HTTP-прокси поддерживает Transfer-Encoding: chunked от клиента
|
||||
+ dnspr: добавлена опция -F, фиктивное разрешение имён для перенаправления трафика
|
||||
+ Поддержка сборки ucrt64; поддержка статических библиотек в Makefile.win
|
||||
+ Docker-образы minimal и busybox переведены на musl + wolfSSL
|
||||
- Поддержка splice() больше не собирается по умолчанию, она медленнее пути read/write для большинства видов трафика; для сборки добавьте -DWITHSPLICE
|
||||
! Исправление: элемент хеш-таблицы добавлялся с неверным индексом при росте таблицы; на больших таблицах пользователей/паролей это могло приводить к отсутствию одной записи
|
||||
! Исправление: состояния гонки; переполнение стека во FreeBSD
|
||||
! Исправление: генерируемые сертификаты имеют формат X.509 v3 с basicConstraints CA:FALSE и extendedKeyUsage serverAuth, что требуется TLS-стеком Apple и Chrome в macOS/iOS
|
||||
! Исправление: dnspr был сломан со времён переписывания udppm
|
||||
! Исправление: короткие пароли в открытом виде не проходили аутентификацию
|
||||
! Исправление: согласование с родителем после отправки заголовка PROXY protocol
|
||||
! Исправление: maxchild сбрасывался в 100 при перезагрузке конфигурации, если не задан явно
|
||||
! Исправление: getrandom() не используется с glibc ниже 2.25
|
||||
! Исправление: определение IPV6_BOUND_IF для устаревших версий MacOS
|
||||
! Исправление: сборка cmake, сборка Docker для arm64, Makefile.win с UCRT
|
||||
! Множество мелких исправлений и очистка кода
|
||||
+139
-55
@@ -46,11 +46,12 @@ endif()
|
||||
|
||||
# Options
|
||||
option(3PROXY_BUILD_SHARED "Build shared libraries for plugins" ON)
|
||||
option(3PROXY_USE_OPENSSL "Enable TLS/SSL support (requires OpenSSL)" ON)
|
||||
option(3PROXY_USE_WOLFSSL "Enable TLS/SSL support via wolfSSL (preferred when detected)" ON)
|
||||
option(3PROXY_USE_OPENSSL "Enable TLS/SSL support via OpenSSL (fallback when wolfSSL unavailable)" ON)
|
||||
option(3PROXY_USE_PCRE2 "Enable PCRE2 regex filtering" ON)
|
||||
option(3PROXY_USE_PAM "Enable PAM/PamAuth" ON)
|
||||
option(3PROXY_USE_ODBC "Enable ODBC support (Unix only, always ON on Windows)" OFF)
|
||||
option(3PROXY_USE_SPLICE "Use Linux splice() for zero-copy (Linux only)" ON)
|
||||
option(3PROXY_USE_SPLICE "Build Linux splice() support, slower than read/write for most traffic (Linux only)" OFF)
|
||||
option(3PROXY_USE_POLL "Use poll() instead of select() (Unix only)" ON)
|
||||
option(3PROXY_USE_WSAPOLL "Use WSAPoll instead of select() (Windows only)" ON)
|
||||
option(3PROXY_USE_NETFILTER "Enable Linux netfilter support (Linux only)" ON)
|
||||
@@ -69,6 +70,7 @@ option(3PROXY_BUILD_NONE "Do not build standalone binaries" OFF)
|
||||
option(3PROXY_BUILD_PROXY "Build standalone proxy binary" ON)
|
||||
option(3PROXY_BUILD_SOCKS "Build standalone socks binary" ON)
|
||||
option(3PROXY_BUILD_POP3P "Build standalone pop3p binary" ON)
|
||||
option(3PROXY_BUILD_IMAPP "Build standalone imapp binary" ON)
|
||||
option(3PROXY_BUILD_SMTPP "Build standalone smtpp binary" ON)
|
||||
option(3PROXY_BUILD_FTPPR "Build standalone ftppr binary" ON)
|
||||
option(3PROXY_BUILD_TCPPM "Build standalone tcppm binary" ON)
|
||||
@@ -76,7 +78,7 @@ option(3PROXY_BUILD_UDPPM "Build standalone udppm binary" ON)
|
||||
option(3PROXY_BUILD_TLSPR "Build standalone tlspr binary" ON)
|
||||
|
||||
if(3PROXY_BUILD_NONE)
|
||||
foreach(_M PROXY SOCKS POP3P SMTPP FTPPR TCPPM UDPPM TLSPR)
|
||||
foreach(_M PROXY SOCKS POP3P IMAPP SMTPP FTPPR TCPPM UDPPM TLSPR)
|
||||
set(3PROXY_BUILD_${_M} OFF)
|
||||
endforeach()
|
||||
endif()
|
||||
@@ -234,6 +236,12 @@ else()
|
||||
)
|
||||
endif()
|
||||
|
||||
# Unix domain sockets off: NO_UN also undefines WITH_UN if it arrives from
|
||||
# elsewhere, e.g. CFLAGS
|
||||
if(NOT 3PROXY_USE_UNIX_SOCKETS)
|
||||
add_compile_definitions(NO_UN)
|
||||
endif()
|
||||
|
||||
# Common definitions
|
||||
if(WIN32)
|
||||
# Windows: use WSAPOLL
|
||||
@@ -253,17 +261,38 @@ endif()
|
||||
|
||||
# Find dependencies
|
||||
|
||||
# OpenSSL
|
||||
# TLS/SSL backend: prefer wolfSSL when detected, fall back to OpenSSL.
|
||||
set(3PROXY_SSL_ENABLED FALSE)
|
||||
set(3PROXY_SSL_WOLFSSL FALSE)
|
||||
set(OPENSSL_FOUND FALSE)
|
||||
if(3PROXY_USE_OPENSSL)
|
||||
set(WOLFSSL_FOUND FALSE)
|
||||
|
||||
if(3PROXY_USE_WOLFSSL)
|
||||
find_path(WOLFSSL_INCLUDE_DIR NAMES wolfssl/options.h wolfssl/ssl.h)
|
||||
find_library(WOLFSSL_LIBRARIES NAMES wolfssl)
|
||||
if(WOLFSSL_INCLUDE_DIR AND WOLFSSL_LIBRARIES)
|
||||
set(WOLFSSL_FOUND TRUE)
|
||||
set(3PROXY_SSL_ENABLED TRUE)
|
||||
set(3PROXY_SSL_WOLFSSL TRUE)
|
||||
add_compile_definitions(WITH_SSL WITH_WOLFSSL)
|
||||
message(STATUS "wolfSSL found: ${WOLFSSL_LIBRARIES} (preferred backend)")
|
||||
else()
|
||||
message(STATUS "wolfSSL not found, falling back to OpenSSL if enabled")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT 3PROXY_SSL_ENABLED AND 3PROXY_USE_OPENSSL)
|
||||
find_package(OpenSSL REQUIRED)
|
||||
if(OpenSSL_FOUND)
|
||||
set(OPENSSL_FOUND TRUE)
|
||||
set(3PROXY_SSL_ENABLED TRUE)
|
||||
add_compile_definitions(WITH_SSL)
|
||||
message(STATUS "OpenSSL found: ${OPENSSL_VERSION}")
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "OpenSSL disabled by user request")
|
||||
elseif(NOT 3PROXY_SSL_ENABLED)
|
||||
message(STATUS "SSL disabled (neither wolfSSL nor OpenSSL enabled/found)")
|
||||
elseif(3PROXY_SSL_WOLFSSL)
|
||||
message(STATUS "OpenSSL skipped (wolfSSL in use)")
|
||||
endif()
|
||||
|
||||
# PCRE2
|
||||
@@ -305,8 +334,9 @@ if(ODBC_FOUND)
|
||||
add_compile_definitions(WITH_ODBC)
|
||||
endif()
|
||||
|
||||
# Set NORADIUS if OpenSSL is not available (RADIUS requires MD5 from OpenSSL)
|
||||
if(NOT OPENSSL_FOUND)
|
||||
# Set NORADIUS if no SSL backend is available (RADIUS MD5 uses bundled md5, but
|
||||
# keep the historical gate tied to SSL availability).
|
||||
if(NOT 3PROXY_SSL_ENABLED)
|
||||
add_compile_definitions(NORADIUS)
|
||||
endif()
|
||||
|
||||
@@ -328,10 +358,8 @@ set(3PROXY_CORE_SOURCES
|
||||
src/stringtable.c
|
||||
)
|
||||
|
||||
# BLAKE2 source for 3proxy_crypt
|
||||
set(MD_SOURCES
|
||||
src/libs/blake2b-ref.c
|
||||
)
|
||||
# Bundled hash implementations (md4.c, md5.c, blake2b-ref.c) self-disable
|
||||
# via preprocessor guards when wolfSSL provides them natively.
|
||||
|
||||
# ============================================================================
|
||||
# Object libraries for common sources (shared between executables)
|
||||
@@ -350,6 +378,14 @@ target_include_directories(common_obj PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
add_library(base64_obj OBJECT src/base64.c)
|
||||
target_include_directories(base64_obj PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
|
||||
# mdhash object library. md4.c/md5.c self-disable via NO_MD4/NO_MD5 guards
|
||||
# when wolfSSL provides them; always compiled for fallback.
|
||||
add_library(mdhash_obj OBJECT src/mdhash.c src/libs/md4.c src/libs/md5.c src/libs/blake2b-ref.c)
|
||||
target_include_directories(mdhash_obj PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
if(3PROXY_SSL_WOLFSSL)
|
||||
target_include_directories(mdhash_obj PRIVATE ${WOLFSSL_INCLUDE_DIR})
|
||||
endif()
|
||||
|
||||
# ============================================================================
|
||||
# Object libraries for 3proxy (compiled WITHOUT WITHMAIN)
|
||||
# These are used by the main 3proxy executable
|
||||
@@ -359,6 +395,7 @@ target_include_directories(base64_obj PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
add_library(srv_modules OBJECT
|
||||
src/proxy.c
|
||||
src/pop3p.c
|
||||
src/imapp.c
|
||||
src/smtpp.c
|
||||
src/ftppr.c
|
||||
src/tcppm.c
|
||||
@@ -394,8 +431,12 @@ target_include_directories(ftp_obj PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
# 3proxy_crypt object for 3proxy (without WITHMAIN)
|
||||
add_library(3proxy_crypt_obj OBJECT src/3proxy_crypt.c)
|
||||
target_include_directories(3proxy_crypt_obj PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
if(OpenSSL_FOUND)
|
||||
target_include_directories(3proxy_crypt_obj PRIVATE ${OPENSSL_INCLUDE_DIR})
|
||||
if(3PROXY_SSL_ENABLED)
|
||||
if(3PROXY_SSL_WOLFSSL)
|
||||
target_include_directories(3proxy_crypt_obj PRIVATE ${WOLFSSL_INCLUDE_DIR})
|
||||
else()
|
||||
target_include_directories(3proxy_crypt_obj PRIVATE ${OPENSSL_INCLUDE_DIR})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# ============================================================================
|
||||
@@ -411,12 +452,12 @@ add_executable(3proxy
|
||||
$<TARGET_OBJECTS:common_obj>
|
||||
$<TARGET_OBJECTS:udpsockmap_obj>
|
||||
$<TARGET_OBJECTS:base64_obj>
|
||||
$<TARGET_OBJECTS:mdhash_obj>
|
||||
$<TARGET_OBJECTS:ftp_obj>
|
||||
$<TARGET_OBJECTS:3proxy_crypt_obj>
|
||||
)
|
||||
target_sources(3proxy PRIVATE ${MD_SOURCES})
|
||||
|
||||
if(OpenSSL_FOUND)
|
||||
if(3PROXY_SSL_ENABLED)
|
||||
target_sources(3proxy PRIVATE src/ssllib.c src/ssl.c)
|
||||
endif()
|
||||
|
||||
@@ -428,8 +469,12 @@ target_include_directories(3proxy PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/libs
|
||||
)
|
||||
if(OpenSSL_FOUND)
|
||||
target_include_directories(3proxy PRIVATE ${OPENSSL_INCLUDE_DIR})
|
||||
if(3PROXY_SSL_ENABLED)
|
||||
if(3PROXY_SSL_WOLFSSL)
|
||||
target_include_directories(3proxy PRIVATE ${WOLFSSL_INCLUDE_DIR})
|
||||
else()
|
||||
target_include_directories(3proxy PRIVATE ${OPENSSL_INCLUDE_DIR})
|
||||
endif()
|
||||
endif()
|
||||
if(PCRE2_FOUND)
|
||||
target_include_directories(3proxy PRIVATE ${PCRE2_INCLUDE_DIRS})
|
||||
@@ -445,10 +490,16 @@ if(ODBC_FOUND)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# OpenSSL linking
|
||||
if(OpenSSL_FOUND)
|
||||
if(3PROXY_STATIC_LINK)
|
||||
# Will be linked statically below (if static libraries are found)
|
||||
# SSL linking
|
||||
if(3PROXY_SSL_ENABLED)
|
||||
if(3PROXY_SSL_WOLFSSL)
|
||||
if(3PROXY_STATIC_LINK)
|
||||
# Will be linked statically below (if static library is found)
|
||||
else()
|
||||
target_link_libraries(3proxy PRIVATE ${WOLFSSL_LIBRARIES})
|
||||
endif()
|
||||
elseif(3PROXY_STATIC_LINK)
|
||||
# OpenSSL static linking handled below
|
||||
else()
|
||||
target_link_libraries(3proxy PRIVATE OpenSSL::SSL OpenSSL::Crypto)
|
||||
endif()
|
||||
@@ -465,14 +516,19 @@ if(PCRE2_FOUND)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Static linking of OpenSSL and PCRE2 (when option is enabled)
|
||||
if(3PROXY_STATIC_LINK AND (OpenSSL_FOUND OR PCRE2_FOUND))
|
||||
# Static linking of SSL backend and PCRE2 (when option is enabled)
|
||||
if(3PROXY_STATIC_LINK AND ((3PROXY_SSL_ENABLED AND NOT 3PROXY_SSL_WOLFSSL) OR (3PROXY_SSL_WOLFSSL) OR PCRE2_FOUND))
|
||||
set(_saved_cmake_find_library_suffixes ${CMAKE_FIND_LIBRARY_SUFFIXES})
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
|
||||
|
||||
set(_static_libs "")
|
||||
|
||||
if(OpenSSL_FOUND)
|
||||
if(3PROXY_SSL_WOLFSSL)
|
||||
find_library(_wolfssl_static_lib NAMES wolfssl)
|
||||
if(_wolfssl_static_lib)
|
||||
list(APPEND _static_libs ${_wolfssl_static_lib})
|
||||
endif()
|
||||
elseif(OpenSSL_FOUND)
|
||||
find_library(_ssl_static_lib ssl)
|
||||
find_library(_crypto_static_lib crypto)
|
||||
if(_ssl_static_lib AND _crypto_static_lib)
|
||||
@@ -491,10 +547,12 @@ if(3PROXY_STATIC_LINK AND (OpenSSL_FOUND OR PCRE2_FOUND))
|
||||
|
||||
if(_static_libs)
|
||||
target_link_libraries(3proxy PRIVATE -Wl,-Bstatic ${_static_libs} -Wl,-Bdynamic)
|
||||
message(STATUS "Static linking enabled for OpenSSL/PCRE2")
|
||||
message(STATUS "Static linking enabled for SSL backend/PCRE2")
|
||||
else()
|
||||
message(WARNING "3PROXY_STATIC_LINK is ON but static libraries not found, falling back to dynamic")
|
||||
if(OpenSSL_FOUND)
|
||||
if(3PROXY_SSL_WOLFSSL)
|
||||
target_link_libraries(3proxy PRIVATE ${WOLFSSL_LIBRARIES})
|
||||
elseif(OpenSSL_FOUND)
|
||||
target_link_libraries(3proxy PRIVATE OpenSSL::SSL OpenSSL::Crypto)
|
||||
endif()
|
||||
if(PCRE2_FOUND)
|
||||
@@ -520,33 +578,55 @@ endif()
|
||||
add_executable(3proxy_crypt
|
||||
src/3proxy_crypt.c
|
||||
$<TARGET_OBJECTS:base64_obj>
|
||||
$<TARGET_OBJECTS:mdhash_obj>
|
||||
)
|
||||
target_sources(3proxy_crypt PRIVATE ${MD_SOURCES})
|
||||
target_compile_definitions(3proxy_crypt PRIVATE WITHMAIN)
|
||||
target_include_directories(3proxy_crypt PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/libs
|
||||
)
|
||||
if(OpenSSL_FOUND)
|
||||
target_include_directories(3proxy_crypt PRIVATE ${OPENSSL_INCLUDE_DIR})
|
||||
if(3PROXY_SSL_ENABLED)
|
||||
if(3PROXY_SSL_WOLFSSL)
|
||||
target_include_directories(3proxy_crypt PRIVATE ${WOLFSSL_INCLUDE_DIR})
|
||||
else()
|
||||
target_include_directories(3proxy_crypt PRIVATE ${OPENSSL_INCLUDE_DIR})
|
||||
endif()
|
||||
endif()
|
||||
target_link_libraries(3proxy_crypt PRIVATE Threads::Threads)
|
||||
if(OpenSSL_FOUND)
|
||||
if(3PROXY_STATIC_LINK)
|
||||
set(_saved_cmake_find_library_suffixes ${CMAKE_FIND_LIBRARY_SUFFIXES})
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
|
||||
find_library(_ssl_static_lib ssl)
|
||||
find_library(_crypto_static_lib crypto)
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_saved_cmake_find_library_suffixes})
|
||||
if(_ssl_static_lib AND _crypto_static_lib)
|
||||
target_link_libraries(3proxy_crypt PRIVATE -Wl,-Bstatic ${_ssl_static_lib} ${_crypto_static_lib} -Wl,-Bdynamic)
|
||||
message(STATUS "3proxy_crypt: static OpenSSL")
|
||||
if(3PROXY_SSL_ENABLED)
|
||||
if(3PROXY_SSL_WOLFSSL)
|
||||
if(3PROXY_STATIC_LINK)
|
||||
set(_saved_cmake_find_library_suffixes ${CMAKE_FIND_LIBRARY_SUFFIXES})
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
|
||||
find_library(_wolfssl_static_lib_c NAMES wolfssl)
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_saved_cmake_find_library_suffixes})
|
||||
if(_wolfssl_static_lib_c)
|
||||
target_link_libraries(3proxy_crypt PRIVATE -Wl,-Bstatic ${_wolfssl_static_lib_c} -Wl,-Bdynamic)
|
||||
message(STATUS "3proxy_crypt: static wolfSSL")
|
||||
else()
|
||||
message(WARNING "3PROXY_STATIC_LINK is ON but static wolfSSL not found, using dynamic")
|
||||
target_link_libraries(3proxy_crypt PRIVATE ${WOLFSSL_LIBRARIES})
|
||||
endif()
|
||||
else()
|
||||
message(WARNING "3PROXY_STATIC_LINK is ON but static OpenSSL not found, using dynamic")
|
||||
target_link_libraries(3proxy_crypt PRIVATE OpenSSL::SSL OpenSSL::Crypto)
|
||||
target_link_libraries(3proxy_crypt PRIVATE ${WOLFSSL_LIBRARIES})
|
||||
endif()
|
||||
else()
|
||||
target_link_libraries(3proxy_crypt PRIVATE OpenSSL::SSL OpenSSL::Crypto)
|
||||
if(3PROXY_STATIC_LINK)
|
||||
set(_saved_cmake_find_library_suffixes ${CMAKE_FIND_LIBRARY_SUFFIXES})
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
|
||||
find_library(_ssl_static_lib ssl)
|
||||
find_library(_crypto_static_lib crypto)
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_saved_cmake_find_library_suffixes})
|
||||
if(_ssl_static_lib AND _crypto_static_lib)
|
||||
target_link_libraries(3proxy_crypt PRIVATE -Wl,-Bstatic ${_ssl_static_lib} ${_crypto_static_lib} -Wl,-Bdynamic)
|
||||
message(STATUS "3proxy_crypt: static OpenSSL")
|
||||
else()
|
||||
message(WARNING "3PROXY_STATIC_LINK is ON but static OpenSSL not found, using dynamic")
|
||||
target_link_libraries(3proxy_crypt PRIVATE OpenSSL::SSL OpenSSL::Crypto)
|
||||
endif()
|
||||
else()
|
||||
target_link_libraries(3proxy_crypt PRIVATE OpenSSL::SSL OpenSSL::Crypto)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
if("${3PROXY_BINARY_PREFIX}" STREQUAL "")
|
||||
@@ -556,7 +636,7 @@ else()
|
||||
endif()
|
||||
|
||||
# Build standalone proxy executables
|
||||
foreach(PROXY_NAME proxy socks pop3p smtpp ftppr tcppm udppm tlspr)
|
||||
foreach(PROXY_NAME proxy socks pop3p imapp smtpp ftppr tcppm udppm tlspr)
|
||||
string(TOUPPER "${PROXY_NAME}" _MODULE_OPT)
|
||||
if(NOT 3PROXY_BUILD_${_MODULE_OPT})
|
||||
continue()
|
||||
@@ -607,7 +687,7 @@ foreach(PROXY_NAME proxy socks pop3p smtpp ftppr tcppm udppm tlspr)
|
||||
target_link_libraries(${PROXY_NAME} PRIVATE ${WINDOWS_LIBS})
|
||||
endif()
|
||||
|
||||
if(PROXY_NAME STREQUAL "proxy" OR PROXY_NAME STREQUAL "smtpp")
|
||||
if(PROXY_NAME STREQUAL "proxy" OR PROXY_NAME STREQUAL "smtpp" OR PROXY_NAME STREQUAL "imapp")
|
||||
target_sources(${PROXY_NAME} PRIVATE $<TARGET_OBJECTS:base64_obj>)
|
||||
endif()
|
||||
|
||||
@@ -651,7 +731,7 @@ install(TARGETS 3proxy 3proxy_crypt
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
|
||||
foreach(PROXY_NAME proxy socks pop3p smtpp ftppr tcppm udppm tlspr)
|
||||
foreach(PROXY_NAME proxy socks pop3p imapp smtpp ftppr tcppm udppm tlspr)
|
||||
string(TOUPPER "${PROXY_NAME}" _MODULE_OPT)
|
||||
if(3PROXY_BUILD_${_MODULE_OPT})
|
||||
install(TARGETS ${PROXY_NAME}
|
||||
@@ -661,16 +741,18 @@ foreach(PROXY_NAME proxy socks pop3p smtpp ftppr tcppm udppm tlspr)
|
||||
endforeach()
|
||||
|
||||
# Install plugins
|
||||
file(GLOB PLUGINFILES "${PLUGIN_OUTPUT_DIR}/*${PLUGIN_SUFFIX}")
|
||||
# Use install(DIRECTORY ... FILES_MATCHING) so the glob resolves at install
|
||||
# time, after plugin targets have been built. A configure-time file(GLOB)
|
||||
# would run before any plugin exists and install nothing.
|
||||
if(WIN32)
|
||||
install(FILES
|
||||
${PLUGINFILES}
|
||||
install(DIRECTORY ${PLUGIN_OUTPUT_DIR}/
|
||||
DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
FILES_MATCHING PATTERN "*${PLUGIN_SUFFIX}"
|
||||
)
|
||||
else()
|
||||
install(FILES
|
||||
${PLUGINFILES}
|
||||
install(DIRECTORY ${PLUGIN_OUTPUT_DIR}/
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/3proxy
|
||||
FILES_MATCHING PATTERN "*${PLUGIN_SUFFIX}"
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -812,7 +894,7 @@ if(NOT WIN32)
|
||||
)
|
||||
endif()
|
||||
# Module man pages — installed with binary prefix only if module is built
|
||||
foreach(_MAN proxy socks pop3p smtpp ftppr tcppm udppm tlspr)
|
||||
foreach(_MAN proxy socks pop3p imapp 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")
|
||||
@@ -836,7 +918,8 @@ message(STATUS " Build type: ${CMAKE_BUILD_TYPE}")
|
||||
message(STATUS "")
|
||||
message(STATUS " Options:")
|
||||
message(STATUS " BUILD_SHARED: ${3PROXY_BUILD_SHARED}")
|
||||
message(STATUS " USE_OPENSSL: ${3PROXY_USE_OPENSSL}")
|
||||
message(STATUS " USE_WOLFSSL: ${3PROXY_USE_WOLFSSL}")
|
||||
message(STATUS " USE_OPENSSL: ${3PROXY_USE_OPENSSL}")
|
||||
message(STATUS " USE_PCRE2: ${3PROXY_USE_PCRE2}")
|
||||
message(STATUS " USE_PAM: ${3PROXY_USE_PAM}")
|
||||
message(STATUS " USE_ODBC: ${3PROXY_USE_ODBC}")
|
||||
@@ -853,6 +936,7 @@ if(WIN32)
|
||||
endif()
|
||||
message(STATUS "")
|
||||
message(STATUS " Libraries found:")
|
||||
message(STATUS " wolfSSL: ${WOLFSSL_FOUND}")
|
||||
message(STATUS " OpenSSL: ${OPENSSL_FOUND}")
|
||||
message(STATUS " PCRE2: ${PCRE2_FOUND}")
|
||||
message(STATUS " PAM: ${PAM_FOUND}")
|
||||
@@ -862,7 +946,7 @@ 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)
|
||||
foreach(_M proxy socks pop3p imapp smtpp ftppr tcppm udppm tlspr)
|
||||
string(TOUPPER "${_M}" _MO)
|
||||
message(STATUS " BUILD_${_MO}: ${3PROXY_BUILD_${_MO}}")
|
||||
endforeach()
|
||||
|
||||
+25
-10
@@ -1,4 +1,5 @@
|
||||
# 3proxy.full is fully functional 3proxy build based on busybox:glibc
|
||||
# 3proxy.busybox is fully functional 3proxy build based on busybox:musl
|
||||
# built against wolfSSL and PCRE2.
|
||||
#
|
||||
# Examples are for podman, for docker change 'podman' to 'docker'
|
||||
#
|
||||
@@ -19,11 +20,27 @@
|
||||
# configuration is supported for compatibility only.
|
||||
|
||||
|
||||
FROM docker.io/gcc AS buildenv
|
||||
FROM docker.io/alpine:latest AS wolfssl
|
||||
RUN apk add --no-cache build-base curl autoconf automake libtool linux-headers
|
||||
RUN TAG=$(curl -s https://api.github.com/repos/wolfSSL/wolfssl/releases/latest \
|
||||
| sed -n 's/.*"tag_name": *"\([^"]*\)".*/\1/p') && \
|
||||
echo "wolfssl tag: $TAG" && \
|
||||
curl -sL https://api.github.com/repos/wolfSSL/wolfssl/tarball/$TAG -o /tmp/w.tar.gz && \
|
||||
mkdir /src && tar -xzf /tmp/w.tar.gz -C /src --strip-components=1 && \
|
||||
cd /src && \
|
||||
autoreconf -i && \
|
||||
./configure --enable-opensslextra --enable-certgen \
|
||||
--enable-tls13 --enable-sni --enable-session-ticket \
|
||||
--enable-static --disable-shared --prefix=/usr/local && \
|
||||
make -j$(nproc) && make install
|
||||
|
||||
FROM docker.io/alpine:latest AS buildenv
|
||||
RUN apk add --no-cache gcc make musl-dev pcre2-dev
|
||||
COPY --from=wolfssl /usr/local /usr/local
|
||||
COPY . 3proxy
|
||||
RUN cd 3proxy &&\
|
||||
apt --assume-yes update && apt --assume-yes install libssl-dev libpcre2-dev &&\
|
||||
make -f Makefile.Linux LIBSTATIC=true PAM_CHECK=false &&\
|
||||
RUN cd 3proxy && mkdir -p bin &&\
|
||||
make -f Makefile.Linux LIBSTATIC=true PAM_CHECK=false WOLFSSL_CHECK=true \
|
||||
EXTRA_LDFLAGS="-L/usr/local/lib" &&\
|
||||
strip bin/3proxy &&\
|
||||
strip bin/*so &&\
|
||||
mkdir /dist &&\
|
||||
@@ -42,11 +59,9 @@ RUN cd /dist &&\
|
||||
ln -s /lib lib64 &&\
|
||||
ln -s /lib usr/lib &&\
|
||||
ln -s /lib usr/lib64
|
||||
RUN cp /lib/ld-*.so.* /dist/usr/local/3proxy/libexec || true
|
||||
RUN cp /lib64/ld-*.so.* /dist/usr/local/3proxy/libexec || true
|
||||
RUN cp "/lib/`gcc -dumpmachine`"/libdl.so.* /dist/usr/local/3proxy/libexec
|
||||
RUN cp /lib/ld-musl-*.so.* /dist/usr/local/3proxy/libexec || true
|
||||
|
||||
FROM docker.io/busybox:glibc
|
||||
FROM docker.io/busybox:musl
|
||||
COPY --from=buildenv /dist /
|
||||
RUN ln -sf /usr/local/3proxy/libexec/* /lib/ && cd /usr/local/3proxy/ && ln -s libexec lib && ln -s libexec lib64 && mkdir usr && ln -s libexec usr/lib && ln -s libexec usr//lib64
|
||||
RUN mkdir -p /lib /lib64 && ln -sf /usr/local/3proxy/libexec/* /lib/ && cd /usr/local/3proxy/ && ln -s libexec lib && ln -s libexec lib64 && mkdir usr && ln -s libexec usr/lib && ln -s libexec usr/lib64
|
||||
CMD ["/bin/3proxy", "/etc/3proxy/3proxy.cfg"]
|
||||
@@ -23,6 +23,7 @@ FROM docker.io/gcc AS buildenv
|
||||
COPY . 3proxy
|
||||
RUN cd 3proxy &&\
|
||||
apt --assume-yes update && apt --assume-yes install libssl-dev libpcre2-dev &&\
|
||||
mkdir -p bin &&\
|
||||
make -f Makefile.Linux LIBSTATIC=true PAM_CHECK=false &&\
|
||||
strip bin/3proxy &&\
|
||||
mkdir /dist &&\
|
||||
|
||||
+24
-6
@@ -3,7 +3,8 @@
|
||||
#
|
||||
# Examples are for podman. For docker change 'podman' to 'docker'.
|
||||
#
|
||||
# This is busybox based docker with only 3proxy static executable.
|
||||
# This is a scratch-based docker with statically linked 3proxy executable
|
||||
# built against musl and wolfSSL.
|
||||
#
|
||||
# Limitations for minimal version:
|
||||
# no support for plugins and system resolver.
|
||||
@@ -15,7 +16,7 @@
|
||||
#
|
||||
# Run example:
|
||||
#
|
||||
# podman run --read-only -i -p 3129:3129 --name 3proxy 3proxy.minimal
|
||||
# podman run --read-only -i -p 3129:3129 --name 3proxy 3proxy.minimal
|
||||
#or
|
||||
# podman start -ai 3proxy
|
||||
#<nserver 8.8.8.8
|
||||
@@ -25,12 +26,29 @@
|
||||
#<end
|
||||
#
|
||||
|
||||
FROM docker.io/gcc AS buildenv
|
||||
FROM docker.io/alpine:latest AS wolfssl
|
||||
RUN apk add --no-cache build-base curl autoconf automake libtool linux-headers
|
||||
RUN TAG=$(curl -s https://api.github.com/repos/wolfSSL/wolfssl/releases/latest \
|
||||
| sed -n 's/.*"tag_name": *"\([^"]*\)".*/\1/p') && \
|
||||
echo "wolfssl tag: $TAG" && \
|
||||
curl -sL https://api.github.com/repos/wolfSSL/wolfssl/tarball/$TAG -o /tmp/w.tar.gz && \
|
||||
mkdir /src && tar -xzf /tmp/w.tar.gz -C /src --strip-components=1 && \
|
||||
cd /src && \
|
||||
autoreconf -i && \
|
||||
./configure --enable-opensslextra --enable-certgen \
|
||||
--enable-tls13 --enable-sni --enable-session-ticket \
|
||||
--enable-static --disable-shared --prefix=/usr/local && \
|
||||
make -j$(nproc) && make install
|
||||
|
||||
FROM docker.io/alpine:latest AS buildenv
|
||||
RUN apk add --no-cache gcc make musl-dev
|
||||
COPY --from=wolfssl /usr/local /usr/local
|
||||
COPY . 3proxy
|
||||
RUN cd 3proxy &&\
|
||||
make -f Makefile.Linux STATIC=true &&\
|
||||
RUN cd 3proxy && mkdir -p bin &&\
|
||||
make -f Makefile.Linux STATIC=true WOLFSSL_CHECK=true \
|
||||
EXTRA_LDFLAGS="-L/usr/local/lib" &&\
|
||||
strip bin/3proxy
|
||||
|
||||
|
||||
FROM scratch
|
||||
COPY --from=buildenv 3proxy/bin/3proxy /bin/3proxy
|
||||
CMD ["/bin/3proxy"]
|
||||
+16
-3
@@ -15,7 +15,12 @@ CFLAGS += -c -fno-strict-aliasing -DFD_SETSIZE=4096 -DWITH_POLL -DWITH_UN
|
||||
COUT = -o
|
||||
LN ?= ${CC}
|
||||
LDFLAGS ?= -O3 -flto
|
||||
LDFLAGS += -pthread -fno-strict-aliasing
|
||||
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 reuiured on some platforms instead of -pthreads
|
||||
# -ldl or -lld may be required for some platforms
|
||||
DCFLAGS ?= -fPIC
|
||||
@@ -47,6 +52,13 @@ ifeq ($(LIBSTATIC), true)
|
||||
STATIC_SUFFIX = -Wl,-Bdynamic
|
||||
ZLIB = -lz -lzstd
|
||||
endif
|
||||
WOLFSSL_CHECK ?= $(shell echo "\#include <wolfssl/options.h>\\n\#include <wolfssl/openssl/ssl.h>\\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 echo "\#include <openssl/ssl.h>\\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) -l crypto -l ssl $(STATIC_SUFFIX)
|
||||
@@ -55,6 +67,7 @@ ifeq ($(OPENSSL_CHECK), true)
|
||||
else
|
||||
ZLIB :=
|
||||
endif
|
||||
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) -o testpcre.o - 2>/dev/null && $(CC) -o testpcre testpcre.o $(LDFLAGS) -lpcre2-8 2>/dev/null && rm testpcre testpcre.o && echo true||echo false)
|
||||
ifeq ($(PCRE_CHECK), true)
|
||||
CFLAGS += -DWITH_PCRE
|
||||
@@ -76,7 +89,7 @@ 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 smtpp ftppr tcppm udppm tlspr; do \
|
||||
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
|
||||
@@ -93,7 +106,7 @@ install: all
|
||||
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 smtpp ftppr tcppm udppm tlspr; do \
|
||||
for f in proxy socks pop3p imapp smtpp ftppr tcppm udppm tlspr; do \
|
||||
if [ -f man/$$f.8 ]; 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
|
||||
|
||||
+23
-5
@@ -3,19 +3,28 @@
|
||||
#
|
||||
# add -DWITH_ODBC to CFLAGS and -lodbc to LIBS to compile with ODBC
|
||||
# library support. Add -DSAFESQL for poorely written ODBC library / drivers.
|
||||
#
|
||||
# Linux splice() support is not built by default, it is slower than the
|
||||
# read/write path for most traffic. Add -DWITHSPLICE to CFLAGS to build it,
|
||||
# it must additionally be enabled per service with the -s option.
|
||||
|
||||
BUILDDIR = ../bin/
|
||||
PREFIX ?= 3proxy_
|
||||
CRYPT_PREFIX ?= $(PREFIX)
|
||||
CC ?= gcc
|
||||
|
||||
CFLAGS ?= -O3 -flto -fPIC
|
||||
CFLAGS += -fno-strict-aliasing -c -pthread -DWITHSPLICE -D_GNU_SOURCE -DGETHOSTBYNAME_R -D_THREAD_SAFE -D_REENTRANT -DFD_SETSIZE=4096 -DWITH_POLL -DWITH_NETFILTER -D WITH_UN
|
||||
CFLAGS ?= -O3 -flto
|
||||
CFLAGS += -fno-strict-aliasing -c -pthread -D_GNU_SOURCE -DGETHOSTBYNAME_R -D_THREAD_SAFE -D_REENTRANT -DFD_SETSIZE=4096 -DWITH_POLL -DWITH_NETFILTER -D WITH_UN
|
||||
COUT = -o
|
||||
LN ?= ${CC}
|
||||
DCFLAGS ?=
|
||||
LDFLAGS ?= -O3 -flto -fPIC
|
||||
DCFLAGS ?= -fPIC
|
||||
LDFLAGS ?= -O3 -flto
|
||||
LDFLAGS += -fno-strict-aliasing -pthread
|
||||
# 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)
|
||||
DLFLAGS ?= -shared
|
||||
DLSUFFICS = .ld.so
|
||||
# -lpthreads may be reuqired on some platforms instead of -pthreads
|
||||
@@ -51,6 +60,13 @@ ifeq ($(LIBSTATIC), true)
|
||||
ZLIB = -lz -lzstd
|
||||
endif
|
||||
|
||||
WOLFSSL_CHECK ?= $(shell echo "\#include <wolfssl/options.h>\\n\#include <wolfssl/openssl/ssl.h>\\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 echo "\#include <openssl/ssl.h>\\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)
|
||||
@@ -59,6 +75,7 @@ ifeq ($(OPENSSL_CHECK), true)
|
||||
else
|
||||
ZLIB :=
|
||||
endif
|
||||
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) -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
|
||||
@@ -86,6 +103,7 @@ INSTALL_DATA = $(INSTALL) -m 644
|
||||
INSTALL_OBJS = bin/3proxy \
|
||||
bin/$(CRYPT_PREFIX)crypt \
|
||||
bin/$(PREFIX)ftppr \
|
||||
bin/$(PREFIX)imapp \
|
||||
bin/$(PREFIX)pop3p \
|
||||
bin/$(PREFIX)proxy \
|
||||
bin/$(PREFIX)smtpp \
|
||||
@@ -149,7 +167,7 @@ install-man:
|
||||
$(INSTALL_BIN) -d $(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 \
|
||||
for f in proxy socks pop3p imapp 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)/$(CRYPT_PREFIX)crypt.8
|
||||
|
||||
@@ -31,12 +31,19 @@ COMPATLIBS =
|
||||
MAKEFILE = Makefile.Solaris
|
||||
PLUGINS = StringsPlugin TrafficPlugin TransparentPlugin FilePlugin
|
||||
|
||||
WOLFSSL_CHECK = $(shell echo "\#include <wolfssl/options.h>\\n\#include <wolfssl/openssl/ssl.h>\\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 echo "\#include <openssl/ssl.h>\\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 echo "\#define PCRE2_CODE_UNIT_WIDTH 8\\n\#include <pcre2.h>\\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
|
||||
|
||||
+9
-2
@@ -11,13 +11,20 @@ CRYPT_PREFIX = 3proxy_
|
||||
CC = cl
|
||||
VERSION = $(VERSION)
|
||||
BUILDDATE = $(BUILDDATE)
|
||||
CFLAGS = /nologo /MT /W3 /Ox /GS /EHs- /GA /GF /D "MSVC" /D "WITH_WSAPOLL" /D "NDEBUG" /D "WIN32" /D "WITH_SSL" /D "WITH_PCRE" /D "WITH_ODBC" /D "_CONSOLE" /D "_MBCS" /D "_WIN32" /Fp"proxy.pch" /FD /c $(BUILDDATE) $(VERSION)
|
||||
!IFDEF WOLFSSL
|
||||
SSL_DEFS = /D "WITH_SSL" /D "WITH_WOLFSSL"
|
||||
SSL_LIBS = wolfssl.lib
|
||||
!ELSE
|
||||
SSL_DEFS = /D "WITH_SSL"
|
||||
SSL_LIBS = libcrypto.lib libssl.lib
|
||||
!ENDIF
|
||||
CFLAGS = /nologo /MT /W3 /Ox /GS /EHs- /GA /GF /D "MSVC" /D "WITH_WSAPOLL" /D "NDEBUG" /D "WIN32" $(SSL_DEFS) /D "WITH_PCRE" /D "WITH_ODBC" /D "_CONSOLE" /D "_MBCS" /D "_WIN32" /Fp"proxy.pch" /FD /c $(BUILDDATE) $(VERSION)
|
||||
COUT = /Fo
|
||||
LN = link
|
||||
LDFLAGS = /nologo /subsystem:console /incremental:no
|
||||
DLFLAGS = /DLL
|
||||
DLSUFFICS = .dll
|
||||
LIBS = ws2_32.lib advapi32.lib odbc32.lib user32.lib kernel32.lib Gdi32.lib Crypt32.lib libcrypto.lib libssl.lib pcre2-8.lib
|
||||
LIBS = ws2_32.lib advapi32.lib odbc32.lib user32.lib kernel32.lib Gdi32.lib Crypt32.lib $(SSL_LIBS) pcre2-8.lib
|
||||
LIBSPREFIX =
|
||||
LIBSSUFFIX = .lib
|
||||
LIBEXT = .lib
|
||||
|
||||
+15
-2
@@ -18,6 +18,11 @@ 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
|
||||
@@ -49,6 +54,13 @@ ifeq ($(LIBSTATIC), true)
|
||||
STATIC_SUFFIX = -Wl,-Bdynamic
|
||||
ZLIB = -lz -lzstd
|
||||
endif
|
||||
WOLFSSL_CHECK ?= $(shell echo "\#include <wolfssl/options.h>\\n\#include <wolfssl/openssl/ssl.h>\\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 echo "\#include <openssl/ssl.h>\\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)
|
||||
@@ -57,6 +69,7 @@ ifeq ($(OPENSSL_CHECK), true)
|
||||
else
|
||||
ZLIB :=
|
||||
endif
|
||||
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) -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
|
||||
@@ -78,7 +91,7 @@ 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 smtpp ftppr tcppm udppm tlspr; do \
|
||||
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
|
||||
@@ -95,7 +108,7 @@ install: all
|
||||
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 smtpp ftppr tcppm udppm tlspr; do \
|
||||
for f in proxy socks pop3p imapp smtpp ftppr tcppm udppm tlspr; do \
|
||||
if [ -f man/$$f.8 ]; 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
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ BUILDDIR = ../bin/
|
||||
PREFIX = 3proxy_
|
||||
CRYPT_PREFIX = 3proxy_
|
||||
CC = cl
|
||||
CFLAGS = /nologo /Ox /MT /D "NOIPV6" /D "NODEBUG" /D "NORADIUS" /D"WATCOM" /D "MSVC" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_WIN32" /D "PRId64=\"I64d\"" /D "PRIu64=\"I64u\"" /D "SCNu64=\"I64u\"" /D "SCNx64=\"I64x\"" /D "SCNd64=\"I64d\"" /D "PRIx64=\"I64x\"" /c $(VERSION) $(BUILDDATE)
|
||||
CFLAGS = /nologo /Ox /MT /D "NOIPV6" /D "NO_UN" /D "NODEBUG" /D "NORADIUS" /D"WATCOM" /D "MSVC" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_WIN32" /D "PRId64=\"I64d\"" /D "PRIu64=\"I64u\"" /D "SCNu64=\"I64u\"" /D "SCNx64=\"I64x\"" /D "SCNd64=\"I64d\"" /D "PRIx64=\"I64x\"" /c $(VERSION) $(BUILDDATE)
|
||||
COUT = /Fo
|
||||
LN = link
|
||||
LDFLAGS = /nologo /subsystem:console /incremental:no
|
||||
|
||||
+25
-5
@@ -15,6 +15,11 @@ COUT = -o
|
||||
LN ?= $(CC)
|
||||
LDFLAGS ?= -O3 -flto
|
||||
LDFLAGS += -fno-strict-aliasing -mthreads
|
||||
# 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)
|
||||
DLFLAGS ?= -shared
|
||||
DLSUFFICS = .dll
|
||||
LIBS += -lws2_32 -lodbc32 -ladvapi32 -luser32 -lbcrypt
|
||||
@@ -37,21 +42,36 @@ BUILDDATE := $(BUILDDATE)
|
||||
AFTERCLEAN = (find . -type f -name "*.o" -delete && find . -type f -name "*.res" -delete && find src/ -type f -name "Makefile.var" -delete && find bin/ -type f -executable -delete) || true
|
||||
|
||||
ifndef OPENSSL_CHECK
|
||||
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 ($(LIBSTATIC), true)
|
||||
STATIC_PREFIX = -Wl,-Bstatic
|
||||
STATIC_SUFFIX = -Wl,-Bdynamic
|
||||
ZLIB = -lz
|
||||
endif
|
||||
WOLFSSL_CHECK = $(shell echo "\#include <wolfssl/options.h>\\n\#include <wolfssl/openssl/ssl.h>\\n int main(){return 0;}" | tr -d '\\\\' | $(CC) -x c $(CFLAGS) $(LDFLAGS) $(STATIC_PREFIX) -lwolfssl $(STATIC_SUFFIX) -o testwssl - 2>/dev/null && rm testwssl && echo true||echo false)
|
||||
ifeq ($(WOLFSSL_CHECK), true)
|
||||
LIBS += $(STATIC_PREFIX) -lwolfssl $(STATIC_SUFFIX) -lws2_32
|
||||
CFLAGS += -DWITH_SSL -DWITH_WOLFSSL
|
||||
SSL_OBJS = ssllib$(OBJSUFFICS) ssl$(OBJSUFFICS)
|
||||
ZLIB :=
|
||||
else
|
||||
OPENSSL_CHECK = $(shell echo "\#include <openssl/ssl.h>\\n int main(){return 0;}" | tr -d '\\\\' | $(CC) -x c $(CFLAGS) $(LDFLAGS) $(STATIC_PREFIX) $(ZLIB) -l crypto -l ssl $(STATIC_SUFFIX) -o testssl - 2>/dev/null && rm testssl && echo true||echo false)
|
||||
ifeq ($(OPENSSL_CHECK), true)
|
||||
LIBS += -l crypto -l ssl
|
||||
LIBS += $(STATIC_PREFIX) $(ZLIB) -l crypto -l ssl $(STATIC_SUFFIX) -lcrypt32
|
||||
CFLAGS += -DWITH_SSL
|
||||
SSL_OBJS = ssllib$(OBJSUFFICS) ssl$(OBJSUFFICS)
|
||||
else
|
||||
ZLIB :=
|
||||
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)
|
||||
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
|
||||
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) -lpcre2-8 -o testpcre - 2>/dev/null && rm testpcre && echo true||echo false)
|
||||
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) $(STATIC_PREFIX) -lpcre2-8 $(STATIC_SUFFIX) -o testpcre - 2>/dev/null && rm testpcre && echo true||echo false)
|
||||
ifeq ($(PCRE_CHECK), true)
|
||||
CFLAGS += -DWITH_PCRE
|
||||
PCRE_OBJS = pcre$(OBJSUFFICS)
|
||||
PCRE_LIBS = -lpcre2-8
|
||||
PCRE_LIBS = $(STATIC_PREFIX) -lpcre2-8 $(STATIC_SUFFIX)
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
Vendored
+6
@@ -1,3 +1,9 @@
|
||||
3proxy (0.9.8-1) buster; urgency=medium
|
||||
|
||||
*3proxy 0.9.8 initial build
|
||||
|
||||
-- z3APA3A <3apa3a@3proxy.org> Fri, 07 Aug 2026 17:44:30 +0300
|
||||
|
||||
3proxy (0.9.7-1) buster; urgency=medium
|
||||
|
||||
*3proxy 0.9.7 initial build
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
!! Fix: use-after-free on the ftp:// request path in HTTP proxy, a request buffer reallocation left a stale pointer; heap corruption, requires authenticated access
|
||||
!! Fix: buffer overflow in radsend() with an oversized request hostname; RADIUS is experimental, log radius or auth radius with fakeresolve is required to reach it
|
||||
!! Fix: buffer overflow in smtpp when relaying AUTH LOGIN credentials to a server which offers AUTH PLAIN only; requires authorised access to smtpp
|
||||
!! Fix: out-of-bounds read in tlspr on a malformed TLS ClientHello
|
||||
!! Fix: LDAP injection and unsafe counter file names in LdapPlugin; the plugin is unsupported and is not built with 3proxy
|
||||
!! Fix: password and hash comparison in strong authentication is constant-time now
|
||||
!! Fix: bounds validation and match/depth limits in pcre filters
|
||||
+ imapp: IMAPv4 proxy added, supports LOGIN command, AUTH PLAIN and AUTH LOGIN
|
||||
+ STARTTLS support for smtpp, pop3p, imapp and tlspr, on both client and server side; -x option to disable
|
||||
+ wolfSSL is supported as an alternative TLS backend, WOLFSSL_CHECK=true selects it (wolfSSL must be built with --enable-opensslextra)
|
||||
+ Chunked Transfer-Encoding from client is supported by HTTP proxy
|
||||
+ dnspr: -F option added, fake resolve to redirect traffic
|
||||
+ ucrt64 build support; static libraries support in Makefile.win
|
||||
+ minimal and busybox Docker images switched to musl + wolfSSL
|
||||
- splice() support is not built by default anymore, it is slower than the read/write path for most traffic; add -DWITHSPLICE to build it
|
||||
! Fix: hashtable item was added with wrong index on table grow; with large username/password tables it could cause a single record to be missing
|
||||
! Fix: race conditions; stack overflow on FreeBSD
|
||||
! Fix: generated certificates are X.509 v3 with basicConstraints CA:FALSE and extendedKeyUsage serverAuth, required by Apple TLS stack and by Chrome on macOS/iOS
|
||||
! Fix: dnspr was broken since udppm rewrite
|
||||
! Fix: short cleartext passwords failed authentication
|
||||
! Fix: parent negotiation after sending PROXY protocol header
|
||||
! Fix: maxchild dropped to 100 on config reload if not set explicitly
|
||||
! Fix: getrandom() is not used with glibc below 2.25
|
||||
! Fix: IPV6_BOUND_IF definition for legacy MacOS
|
||||
! Fix: cmake build, arm64 Docker build, Makefile.win with UCRT
|
||||
! Multiple minor bugfixes and code cleanup
|
||||
+197
-197
@@ -1,134 +1,134 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<meta http-equiv="Content-Style-Type" content="text/css">
|
||||
<title>3proxy developer reference</title>
|
||||
<style type="text/css">
|
||||
span.s1 {text-decoration: underline}
|
||||
ol {list-style-type: none}
|
||||
ol.level1 {counter-reset: h1}
|
||||
ol.level1 > li::before {content: counter(h1) ". "; counter-increment: h1; font-weight: bold}
|
||||
ol.level2 {counter-reset: h2}
|
||||
ol.level2 > li::before {content: counter(h1) "." counter(h2) " "; counter-increment: h2}
|
||||
ol.level3 {counter-reset: h3}
|
||||
ol.level3 > li::before {content: counter(h1) "." counter(h2) "." counter(h3) " "; counter-increment: h3}
|
||||
pre {margin: 0.5em 0; padding: 0.5em; background: #f5f5f5; border: 1px solid #ddd}
|
||||
code {font-family: monospace}
|
||||
</style>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<meta http-equiv="Content-Style-Type" content="text/css">
|
||||
<title>3proxy developer reference</title>
|
||||
<style type="text/css">
|
||||
span.s1 {text-decoration: underline}
|
||||
ol {list-style-type: none}
|
||||
ol.level1 {counter-reset: h1}
|
||||
ol.level1 > li::before {content: counter(h1) ". "; counter-increment: h1; font-weight: bold}
|
||||
ol.level2 {counter-reset: h2}
|
||||
ol.level2 > li::before {content: counter(h1) "." counter(h2) " "; counter-increment: h2}
|
||||
ol.level3 {counter-reset: h3}
|
||||
ol.level3 > li::before {content: counter(h1) "." counter(h2) "." counter(h3) " "; counter-increment: h3}
|
||||
pre {margin: 0.5em 0; padding: 0.5em; background: #f5f5f5; border: 1px solid #ddd}
|
||||
code {font-family: monospace}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h2>3proxy developer reference</h2>
|
||||
|
||||
<ol class="level1">
|
||||
<li><b>Understanding Internal 3proxy structure</b>
|
||||
<p>3proxy is implemented as multithread application. Server model is implemented as "one connection – one thread". It means, for every client connection new thread is created. This model is effective enough under Windows, because it allows it avoid thread creation on asynchronous operations, yet under most POSIX systems this model can not be considered as most efficient. It's planned for (very far in future) release to implement more efficient model, where single thread can serve few clients.</p>
|
||||
<ol class="level2">
|
||||
<li>main thread
|
||||
<p>3proxy begins with main thread. This thread parses configuration file and starts main loop. During configuration file parsing <code>struct extaparam conf;</code> structure is filled and service threads are started.</p>
|
||||
<p>Main loop cycle takes approximately 1 second and does these tasks:</p>
|
||||
<ul>
|
||||
<li>re-reads configuration file, if necessary</li>
|
||||
<li>performs scheduled tasks</li>
|
||||
<li>monitors files ('monitor' command), approx. once in a minute</li>
|
||||
<li>rotates main logfile</li>
|
||||
<li>dumps counters to file, approx. once in a minute</li>
|
||||
<li>performs termination, if required</li>
|
||||
</ul>
|
||||
<p>It's guaranteed every configuration and schedule command is executed from the same thread.</p>
|
||||
<p>Main thread is implemented in <b>3proxy.c</b></p>
|
||||
</li>
|
||||
<li>service thread
|
||||
<p>Service threads are started immediately, than service command (e.g. 'proxy' or 'socks') are found during configuration file parsing. Each command creates new thread. Thread does these tasks:</p>
|
||||
<ul>
|
||||
<li>parses service command arguments and fills <code>struct srvparam srv</code> structure with service configuration and <code>struct clientparam defparam</code> structure with default client configuration</li>
|
||||
<li>initializes filters (filter_open)</li>
|
||||
<li>creates and initializes listening service socket</li>
|
||||
<li>enters into service loop</li>
|
||||
<li>terminates filters (filter_close)</li>
|
||||
</ul>
|
||||
<p>service loop:</p>
|
||||
<ul>
|
||||
<li>checks for configuration reload (approximately every second), thread exits if configuration reloaded or 3proxy is in terminating state.</li>
|
||||
<li>accepts client connection and creates <code>struct clientparam newparam</code> structure with client configuration</li>
|
||||
<li>creates/checks client filters (filter_client)</li>
|
||||
<li>creates client thread with newly created <code>struct clientparam newparam</code></li>
|
||||
</ul>
|
||||
<p>service threads are implemented in <b>proxymain.c</b></p>
|
||||
<p>Please note: struct clientparam is freed and filter_clear is executed from different (client) thread.</p>
|
||||
</li>
|
||||
<li>client thread
|
||||
<p>Client threads are started from service thread. Client thread:</p>
|
||||
<ul>
|
||||
<li>reads client request (except portmappers) with authentication information and request headers (if any).</li>
|
||||
<li>filters request (if any) with filter_request</li>
|
||||
<li>filters headers (if any) with filter_header_cli</li>
|
||||
<li>performs authentication and authorization</li>
|
||||
<li>established connection with server</li>
|
||||
<li>sends request to server</li>
|
||||
<li>filters server headers (if any)</li>
|
||||
<li>maps client end server sockets to transmit data between client and server</li>
|
||||
<li>logs request. Global counters are also updated on this operation</li>
|
||||
<li>clears client filters (filter_clear)</li>
|
||||
<li>frees <code>struct clientparam</code> data</li>
|
||||
</ul>
|
||||
<p>in some point client thread may loop to process few client requests from the same connection (e.g. HTTP 'established' connection in 'proxy').</p>
|
||||
<p>Socket mapping does:</p>
|
||||
<ul>
|
||||
<li>caches data in internal client and server buffers</li>
|
||||
<li>delays data transmit to limit bandwidth</li>
|
||||
<li>performs data filtering (filter_data_cli / filter_data_srv)</li>
|
||||
</ul>
|
||||
<p>client threads are implemented in <b>proxy.c</b>, <b>socks.c</b>, <b>pop3p.c</b> etc.</p>
|
||||
</li>
|
||||
</ol>
|
||||
</li>
|
||||
<li><b>Hacking into 3proxy code with plugins</b>
|
||||
<ol class="level2">
|
||||
<li>What is 3proxy plugin
|
||||
<p>3proxy plugin is any dynamic/shared library. There is no specific requirement for plugin, actually you can load any dynamic library with 'plugin' command. No linking with any libraries are required. However, to interoperate with 3proxy dynamic library must have an export function 3proxy may call to pass the structure with required information.</p>
|
||||
<li><b>Understanding Internal 3proxy structure</b>
|
||||
<p>3proxy is implemented as multithread application. Server model is implemented as "one connection – one thread". It means, for every client connection new thread is created. This model is effective enough under Windows, because it allows it avoid thread creation on asynchronous operations, yet under most POSIX systems this model can not be considered as most efficient. It's planned for (very far in future) release to implement more efficient model, where single thread can serve few clients.</p>
|
||||
<ol class="level2">
|
||||
<li>main thread
|
||||
<p>3proxy begins with main thread. This thread parses configuration file and starts main loop. During configuration file parsing <code>struct extaparam conf;</code> structure is filled and service threads are started.</p>
|
||||
<p>Main loop cycle takes approximately 1 second and does these tasks:</p>
|
||||
<ul>
|
||||
<li>re-reads configuration file, if necessary</li>
|
||||
<li>performs scheduled tasks</li>
|
||||
<li>monitors files ('monitor' command), approx. once in a minute</li>
|
||||
<li>rotates main logfile</li>
|
||||
<li>dumps counters to file, approx. once in a minute</li>
|
||||
<li>performs termination, if required</li>
|
||||
</ul>
|
||||
<p>It's guaranteed every configuration and schedule command is executed from the same thread.</p>
|
||||
<p>Main thread is implemented in <b>3proxy.c</b></p>
|
||||
</li>
|
||||
<li>service thread
|
||||
<p>Service threads are started immediately, than service command (e.g. 'proxy' or 'socks') are found during configuration file parsing. Each command creates new thread. Thread does these tasks:</p>
|
||||
<ul>
|
||||
<li>parses service command arguments and fills <code>struct srvparam srv</code> structure with service configuration and <code>struct clientparam defparam</code> structure with default client configuration</li>
|
||||
<li>initializes filters (filter_open)</li>
|
||||
<li>creates and initializes listening service socket</li>
|
||||
<li>enters into service loop</li>
|
||||
<li>terminates filters (filter_close)</li>
|
||||
</ul>
|
||||
<p>service loop:</p>
|
||||
<ul>
|
||||
<li>checks for configuration reload (approximately every second), thread exits if configuration reloaded or 3proxy is in terminating state.</li>
|
||||
<li>accepts client connection and creates <code>struct clientparam newparam</code> structure with client configuration</li>
|
||||
<li>creates/checks client filters (filter_client)</li>
|
||||
<li>creates client thread with newly created <code>struct clientparam newparam</code></li>
|
||||
</ul>
|
||||
<p>service threads are implemented in <b>proxymain.c</b></p>
|
||||
<p>Please note: struct clientparam is freed and filter_clear is executed from different (client) thread.</p>
|
||||
</li>
|
||||
<li>client thread
|
||||
<p>Client threads are started from service thread. Client thread:</p>
|
||||
<ul>
|
||||
<li>reads client request (except portmappers) with authentication information and request headers (if any).</li>
|
||||
<li>filters request (if any) with filter_request</li>
|
||||
<li>filters headers (if any) with filter_header_cli</li>
|
||||
<li>performs authentication and authorization</li>
|
||||
<li>established connection with server</li>
|
||||
<li>sends request to server</li>
|
||||
<li>filters server headers (if any)</li>
|
||||
<li>maps client end server sockets to transmit data between client and server</li>
|
||||
<li>logs request. Global counters are also updated on this operation</li>
|
||||
<li>clears client filters (filter_clear)</li>
|
||||
<li>frees <code>struct clientparam</code> data</li>
|
||||
</ul>
|
||||
<p>in some point client thread may loop to process few client requests from the same connection (e.g. HTTP 'established' connection in 'proxy').</p>
|
||||
<p>Socket mapping does:</p>
|
||||
<ul>
|
||||
<li>caches data in internal client and server buffers</li>
|
||||
<li>delays data transmit to limit bandwidth</li>
|
||||
<li>performs data filtering (filter_data_cli / filter_data_srv)</li>
|
||||
</ul>
|
||||
<p>client threads are implemented in <b>proxy.c</b>, <b>socks.c</b>, <b>pop3p.c</b> etc.</p>
|
||||
</li>
|
||||
</ol>
|
||||
</li>
|
||||
<li><b>Hacking into 3proxy code with plugins</b>
|
||||
<ol class="level2">
|
||||
<li>What is 3proxy plugin
|
||||
<p>3proxy plugin is any dynamic/shared library. There is no specific requirement for plugin, actually you can load any dynamic library with 'plugin' command. No linking with any libraries are required. However, to interoperate with 3proxy dynamic library must have an export function 3proxy may call to pass the structure with required information.</p>
|
||||
<pre><code>typedef int (*PLUGINFUNC) (struct pluginlink *pluginlink, int argc, char** argv);</code></pre>
|
||||
<p><code>struct pluginlink</code> is a structure with export information, explained later, argc and argv are argument counter and array of arguments of "plugin" command. Plugin should report it's status with integer return value. 0 is success, positive value indicates non-recoverable error, 3proxy do not parse rest of configuration and enters into termination state, negative value indicates recoverable value, 3proxy logs warning (if possible). In case of C++, all 3proxy functions/structures must be extern "C".</p>
|
||||
<p>All 3proxy structures/functions descriptions are located in <b>structures.h</b></p>
|
||||
</li>
|
||||
<li>Understanding pluginlink structure
|
||||
<p>Because there is no linking between 3proxy and plugin, all 3proxy functions and structures are passed with pluginlink structure. Pluginlink is actually a collection of pointers to 3proxy internal structures and functions. Because pluginlink is constantly extending, you should see it's definitions in <b>structures.h</b>.</p>
|
||||
<p>most important are:</p>
|
||||
<p><code>struct pluginlink</code> is a structure with export information, explained later, argc and argv are argument counter and array of arguments of "plugin" command. Plugin should report it's status with integer return value. 0 is success, positive value indicates non-recoverable error, 3proxy do not parse rest of configuration and enters into termination state, negative value indicates recoverable value, 3proxy logs warning (if possible). In case of C++, all 3proxy functions/structures must be extern "C".</p>
|
||||
<p>All 3proxy structures/functions descriptions are located in <b>structures.h</b></p>
|
||||
</li>
|
||||
<li>Understanding pluginlink structure
|
||||
<p>Because there is no linking between 3proxy and plugin, all 3proxy functions and structures are passed with pluginlink structure. Pluginlink is actually a collection of pointers to 3proxy internal structures and functions. Because pluginlink is constantly extending, you should see it's definitions in <b>structures.h</b>.</p>
|
||||
<p>most important are:</p>
|
||||
<pre><code>struct symbol symbols;</code></pre>
|
||||
<p>"symbols" is a kind of name/value export table, made as a list. It can be used by plugins to exchange information and functions between plugins, e.g. to export functions from one plugin to another, where pluginlink is useless, because it's static. It's quite simple:</p>
|
||||
<p>"symbols" is a kind of name/value export table, made as a list. It can be used by plugins to exchange information and functions between plugins, e.g. to export functions from one plugin to another, where pluginlink is useless, because it's static. It's quite simple:</p>
|
||||
<pre><code>struct symbol {
|
||||
struct symbol *next;
|
||||
char * name;
|
||||
void * value;
|
||||
struct symbol *next;
|
||||
char * name;
|
||||
void * value;
|
||||
};</code></pre>
|
||||
<p><code>name</code> – is a name of function or structure</p>
|
||||
<p><code>value</code> – is it's value.</p>
|
||||
<p>use <code>pluginlink->findbyname</code> function to lookup, e.g.</p>
|
||||
<p><code>name</code> – is a name of function or structure</p>
|
||||
<p><code>value</code> – is it's value.</p>
|
||||
<p>use <code>pluginlink->findbyname</code> function to lookup, e.g.</p>
|
||||
<pre><code>anotherplugindata = pluginlink->findbyname("anotherplugindata");</code></pre>
|
||||
<p>To export something from your plugin, add your structure to this list.</p>
|
||||
<p>To export something from your plugin, add your structure to this list.</p>
|
||||
<pre><code>struct extparam *conf;</code></pre>
|
||||
<p>pointer to conf structure, it holds all current 3proxy configuration</p>
|
||||
</li>
|
||||
<li>How to get control within plugin
|
||||
<p>There are few points you can get control for your plugin, after it's loaded with 'plugin' command.</p>
|
||||
<ol class="level3">
|
||||
<li>Adding configuration command processor with struct command structure
|
||||
<p>A list of configuration file command, available from 3proxy.cfg is extendable. Each command is defined by <code>struct commands</code>:</p>
|
||||
<p>pointer to conf structure, it holds all current 3proxy configuration</p>
|
||||
</li>
|
||||
<li>How to get control within plugin
|
||||
<p>There are few points you can get control for your plugin, after it's loaded with 'plugin' command.</p>
|
||||
<ol class="level3">
|
||||
<li>Adding configuration command processor with struct command structure
|
||||
<p>A list of configuration file command, available from 3proxy.cfg is extendable. Each command is defined by <code>struct commands</code>:</p>
|
||||
<pre><code>struct commands {
|
||||
struct commands *next;
|
||||
char * command;
|
||||
int (* handler)(int argc, unsigned char ** argv);
|
||||
int minargs;
|
||||
int maxargs;
|
||||
struct commands *next;
|
||||
char * command;
|
||||
int (* handler)(int argc, unsigned char ** argv);
|
||||
int minargs;
|
||||
int maxargs;
|
||||
};</code></pre>
|
||||
<p><code>struct commands *next</code> - next element in list</p>
|
||||
<p><code>char * command</code> – command name</p>
|
||||
<p><code>int (* handler)(int argc, unsigned char ** argv)</code> – command handler. It's called than 'command' is found in configuration files, argc is a number of arguments, counting command itself, argv is array of arguments.</p>
|
||||
<p><code>minargs</code> – minimum number of arguments command support (>= 1)</p>
|
||||
<p><code>maxargs</code> – maximum number of arguments command support, 0 means infinity.</p>
|
||||
<p>Handler return value of 0 indicates command is successfully processed. Positive return value indicates non-recoverable error, 3proxy enters termination state. Negative value indicates 3proxy to continue to process command list, it makes it possible to set few handlers for the same command.</p>
|
||||
<p>A list of the command is pointed by <code>pluginlink->commandhandlers</code>; you must insert you command after first one (do not replace <code>pluginlink->commandhandlers</code>). It's guaranteed at least 1 dummy command is always present.</p>
|
||||
<p>Example:</p>
|
||||
<p><code>struct commands *next</code> - next element in list</p>
|
||||
<p><code>char * command</code> – command name</p>
|
||||
<p><code>int (* handler)(int argc, unsigned char ** argv)</code> – command handler. It's called than 'command' is found in configuration files, argc is a number of arguments, counting command itself, argv is array of arguments.</p>
|
||||
<p><code>minargs</code> – minimum number of arguments command support (>= 1)</p>
|
||||
<p><code>maxargs</code> – maximum number of arguments command support, 0 means infinity.</p>
|
||||
<p>Handler return value of 0 indicates command is successfully processed. Positive return value indicates non-recoverable error, 3proxy enters termination state. Negative value indicates 3proxy to continue to process command list, it makes it possible to set few handlers for the same command.</p>
|
||||
<p>A list of the command is pointed by <code>pluginlink->commandhandlers</code>; you must insert you command after first one (do not replace <code>pluginlink->commandhandlers</code>). It's guaranteed at least 1 dummy command is always present.</p>
|
||||
<p>Example:</p>
|
||||
<pre><code>int mycommandhandler(int argc, unsigned char **argv);
|
||||
struct commands mycommand;
|
||||
|
||||
@@ -138,27 +138,27 @@ mycommand.intargs = 1;
|
||||
mycommand.intargs = 2;
|
||||
mycommand.next = pluginslinks->commandhandlers->next;
|
||||
pluginslink->commandhandlers->next = &mycommand;</code></pre>
|
||||
<p>Adds processor for "mycommand" command with zero on one arguments.</p>
|
||||
<p>Adding configuration command is useful, if your plugin expects configuration data.</p>
|
||||
</li>
|
||||
<li>Adding authentication method with struct auth
|
||||
<p>3proxy supports authentication and authorization. Authentication process determines user account (for example by username and password), authorization checks, if user account has a right to access given resource and optionally establishes a connection, if required.</p>
|
||||
<p>'auth' command combines both authentication and authorization method. It's extandable with struct auth list:</p>
|
||||
<p>Adds processor for "mycommand" command with zero on one arguments.</p>
|
||||
<p>Adding configuration command is useful, if your plugin expects configuration data.</p>
|
||||
</li>
|
||||
<li>Adding authentication method with struct auth
|
||||
<p>3proxy supports authentication and authorization. Authentication process determines user account (for example by username and password), authorization checks, if user account has a right to access given resource and optionally establishes a connection, if required.</p>
|
||||
<p>'auth' command combines both authentication and authorization method. It's extandable with struct auth list:</p>
|
||||
<pre><code>struct auth {
|
||||
struct auth *next;
|
||||
AUTHFUNC authenticate;
|
||||
AUTHFUNC authorize;
|
||||
char * desc;
|
||||
struct auth *next;
|
||||
AUTHFUNC authenticate;
|
||||
AUTHFUNC authorize;
|
||||
char * desc;
|
||||
};</code></pre>
|
||||
<p><code>char * desc</code> – name of authentication/authorization method</p>
|
||||
<p><code>authenticate</code> – name of authentication function</p>
|
||||
<p><code>authorize</code> – name of authorization function</p>
|
||||
<p><code>pluginlink->authfuncs</code> points to list of authenticataction structures. Like above, new structure must be inserted after fiest one (or to the end of the list).</p>
|
||||
<p>First, authentication is called, if authentication indicates OK status (return value 0), authorization is called. Normally, 'checkACL' (<code>pluginlink->checkACL</code>) is called as authorization function to check user's request matches to standard allow/deny rules. If for some reason you need to avoid this check, you should call <code>pluginlink->alwaysauth</code> to do some dirty job, like establishing outgoing connection.</p>
|
||||
<p><code>char * desc</code> – name of authentication/authorization method</p>
|
||||
<p><code>authenticate</code> – name of authentication function</p>
|
||||
<p><code>authorize</code> – name of authorization function</p>
|
||||
<p><code>pluginlink->authfuncs</code> points to list of authenticataction structures. Like above, new structure must be inserted after fiest one (or to the end of the list).</p>
|
||||
<p>First, authentication is called, if authentication indicates OK status (return value 0), authorization is called. Normally, 'checkACL' (<code>pluginlink->checkACL</code>) is called as authorization function to check user's request matches to standard allow/deny rules. If for some reason you need to avoid this check, you should call <code>pluginlink->alwaysauth</code> to do some dirty job, like establishing outgoing connection.</p>
|
||||
<pre><code>typedef int (*AUTHFUNC)(struct clientparam * param);</code></pre>
|
||||
<p>is both authentication and authorization function. <code>struct clientparam</code> holds all information about client connection, including username (<code>param->username</code>) and password (<code>param->password</code>).</p>
|
||||
<p>Return value of 0 indicates successful authentication/authorization, 1 and 3 – authorization failed (access denied), use 3 in case you want to indicate access is explicitly denied and 3 in case there is no matching rule. 4,5,6,7,8 – authentication failed (e.g. username/password do not match). 4 indicates username does not present in request and must be requested, if possible. 5 indicates username found in request can not be found in user's database/list, 6,7,8 – username does not match password for different authentication types. 10 – user exceeded some limits, e.g. traffic. You may use some different code to indicate internal problems.</p>
|
||||
<p>Example:</p>
|
||||
<p>is both authentication and authorization function. <code>struct clientparam</code> holds all information about client connection, including username (<code>param->username</code>) and password (<code>param->password</code>).</p>
|
||||
<p>Return value of 0 indicates successful authentication/authorization, 1 and 3 – authorization failed (access denied), use 3 in case you want to indicate access is explicitly denied and 3 in case there is no matching rule. 4,5,6,7,8 – authentication failed (e.g. username/password do not match). 4 indicates username does not present in request and must be requested, if possible. 5 indicates username found in request can not be found in user's database/list, 6,7,8 – username does not match password for different authentication types. 10 – user exceeded some limits, e.g. traffic. You may use some different code to indicate internal problems.</p>
|
||||
<p>Example:</p>
|
||||
<pre><code>int myauthfunc(struct clientparam *param);
|
||||
struct auth myauth;
|
||||
|
||||
@@ -167,27 +167,27 @@ myauth.authenticate = myauthfunc;
|
||||
myauth.authorize = pluginlink->checkACL;
|
||||
myauth->next = pluginlink->authfuncs->next;
|
||||
pluginlink->authfuncs->next = &myauth;</code></pre>
|
||||
<p>Installs "myauthfunc" as authentication function. There is no need to add 'auth' command processor for new authentication type, it's processed by standard 'auth' command processor.</p>
|
||||
</li>
|
||||
<li>Adding scheduled functions
|
||||
<p>Scheduled functions are described by this structure:</p>
|
||||
<p>Installs "myauthfunc" as authentication function. There is no need to add 'auth' command processor for new authentication type, it's processed by standard 'auth' command processor.</p>
|
||||
</li>
|
||||
<li>Adding scheduled functions
|
||||
<p>Scheduled functions are described by this structure:</p>
|
||||
<pre><code>typedef enum {NONE, MINUTELY, HOURLY, DAILY, WEEKLY, MONTHLY, ANNUALLY, NEVER} ROTATION;
|
||||
|
||||
struct schedule {
|
||||
struct schedule *next;
|
||||
ROTATION type;
|
||||
void *data;
|
||||
int (*function)(void *);
|
||||
time_t start_time;
|
||||
struct schedule *next;
|
||||
ROTATION type;
|
||||
void *data;
|
||||
int (*function)(void *);
|
||||
time_t start_time;
|
||||
};</code></pre>
|
||||
<p><code>int (*function)(void *)</code> – scheduled function</p>
|
||||
<p><code>void *data</code> – this pointer will be passed as an argument to scheduled functions</p>
|
||||
<p><code>ROTATION type</code> – defines how often function is called (once in a minute, hour, etc).</p>
|
||||
<p><code>start_time</code> – time to begin using of scheduled function</p>
|
||||
<p>Scheduled functions are called every 'type' interval after start_time and also on reloading configuration and going to termination state.</p>
|
||||
<p>Schedule function return value of 1 means function must be removed from the schedule. 3proxy doesn't free struct schedule.</p>
|
||||
<p>Schedule list can be empty. Pointer to schedule is pointed by <code>struct schedule ** schedule;</code> in pluginlink.</p>
|
||||
<p>Example:</p>
|
||||
<p><code>int (*function)(void *)</code> – scheduled function</p>
|
||||
<p><code>void *data</code> – this pointer will be passed as an argument to scheduled functions</p>
|
||||
<p><code>ROTATION type</code> – defines how often function is called (once in a minute, hour, etc).</p>
|
||||
<p><code>start_time</code> – time to begin using of scheduled function</p>
|
||||
<p>Scheduled functions are called every 'type' interval after start_time and also on reloading configuration and going to termination state.</p>
|
||||
<p>Schedule function return value of 1 means function must be removed from the schedule. 3proxy doesn't free struct schedule.</p>
|
||||
<p>Schedule list can be empty. Pointer to schedule is pointed by <code>struct schedule ** schedule;</code> in pluginlink.</p>
|
||||
<p>Example:</p>
|
||||
<pre><code>int myschedfunc(void * data);
|
||||
struct schedule myschedule;
|
||||
|
||||
@@ -197,62 +197,62 @@ myschedule.type = MINUTELY;
|
||||
myschedule.starttime = 0;
|
||||
myschedule.next = *pluginlink->schedule;
|
||||
*pluginlink->schedule = myschedule;</code></pre>
|
||||
<p><span class="s1">NOTE:</span> time_t is different for different compilers. Make sure to compile plugin and 3proxy with same compiler.</p>
|
||||
</li>
|
||||
<li>Filters API
|
||||
<p>3proxy has filters API, you can use, to process client request and data flowing through proxy. It should be noted, that currently 3proxy doesn't provide filters with any useful data conversion, so, it's filter's task to find data in data flow. In case filter modifies some data, it's filter's task again to assure that everything's fine. If you know some filtering API like MILTER, you will find 3proxy filters very same.</p>
|
||||
<p><span class="s1">NOTE:</span> time_t is different for different compilers. Make sure to compile plugin and 3proxy with same compiler.</p>
|
||||
</li>
|
||||
<li>Filters API
|
||||
<p>3proxy has filters API, you can use, to process client request and data flowing through proxy. It should be noted, that currently 3proxy doesn't provide filters with any useful data conversion, so, it's filter's task to find data in data flow. In case filter modifies some data, it's filter's task again to assure that everything's fine. If you know some filtering API like MILTER, you will find 3proxy filters very same.</p>
|
||||
<pre><code>typedef enum {
|
||||
PASS,
|
||||
CONTINUE,
|
||||
HANDLED,
|
||||
REJECT,
|
||||
REMOVE
|
||||
PASS,
|
||||
CONTINUE,
|
||||
HANDLED,
|
||||
REJECT,
|
||||
REMOVE
|
||||
} FILTER_ACTION;
|
||||
|
||||
typedef void* FILTER_OPEN(void * idata, struct srvparam * param);
|
||||
typedef FILTER_ACTION FILTER_CLIENT(void *fo, struct clientparam * param, void** fc);
|
||||
typedef FILTER_ACTION FILTER_BUFFER(void *fc, struct clientparam * param, unsigned char ** buf_p, int * bufsize_p, int offset, int * length_p);
|
||||
typedef void FILTER_CLOSE(void *fo);
|
||||
typedef void* FILTER_OPEN(void * idata, struct srvparam * param);
|
||||
typedef FILTER_ACTION FILTER_CLIENT(void *fo, struct clientparam * param, void** fc);
|
||||
typedef FILTER_ACTION FILTER_BUFFER(void *fc, struct clientparam * param, unsigned char ** buf_p, int * bufsize_p, int offset, int * length_p);
|
||||
typedef void FILTER_CLOSE(void *fo);
|
||||
|
||||
struct filter {
|
||||
struct filter * next;
|
||||
char * instance;
|
||||
void * data;
|
||||
FILTER_OPEN *filter_open;
|
||||
FILTER_CLIENT *filter_client;
|
||||
FILTER_BUFFER *filter_request;
|
||||
FILTER_BUFFER *filter_header_cli;
|
||||
FILTER_BUFFER *filter_header_srv;
|
||||
FILTER_BUFFER *filter_data_cli;
|
||||
FILTER_BUFFER *filter_data_srv;
|
||||
FILTER_CLOSE *filter_clear;
|
||||
FILTER_CLOSE *filter_close;
|
||||
struct filter * next;
|
||||
char * instance;
|
||||
void * data;
|
||||
FILTER_OPEN *filter_open;
|
||||
FILTER_CLIENT *filter_client;
|
||||
FILTER_BUFFER *filter_request;
|
||||
FILTER_BUFFER *filter_header_cli;
|
||||
FILTER_BUFFER *filter_header_srv;
|
||||
FILTER_BUFFER *filter_data_cli;
|
||||
FILTER_BUFFER *filter_data_srv;
|
||||
FILTER_CLOSE *filter_clear;
|
||||
FILTER_CLOSE *filter_close;
|
||||
};</code></pre>
|
||||
<p><code>char * instance</code> – is some instance identifier. You can use it to find required filter in the list. 3proxy itself doesn't use this field.</p>
|
||||
<p><code>void * data</code> – this parameter is passed to filter_open function. The rest are filtering functions. Section 1 explains where and then each filter is called. data should not be NULL.</p>
|
||||
<p><code>filter_open</code> must always be defined, if you want filter to be ever used. It's called then new service is created and is given "data" from struct filter and struct srvparam (parsed service configuration). If filter_open for some filter returns NULL, filter will not be used for this service. Non-NULL return value will be used as "fo" parameter for every call to filter_client.</p>
|
||||
<p><code>filter_client</code> is called upon client connect (before any data is sent/received). It's good place to filter client by IP (and is not good place to filter it by hostname, because this operation takes a long time, 3proxy will not be able to accept new connection). fo is a data pointer received from filter_open, param – newly created clientparam structure, fc is return parameter filter_open must initialize, it will be used as an argument to FILTER_BUFFER functions. PASS return value means this filter will be used for this client request. CONTINUE says to install filters. On different values client connection is closed and no client thread is created.</p>
|
||||
<p><code>filter_request, filter_header_cli, filter_header_srv, filter_data_cli, filter_data_srv</code> are used to process request and data received from client and server.</p>
|
||||
<p><code>char ** buf_p</code> is a pointer to current buffer, <code>int * bufsize_p</code> is a pointer to it's size. In case you change some data and it doesn't fit to current buffer, you may allocate new buffer (with <code>pluginlink->myalloc</code>), copy data from old buffer, free old buffer (with <code>pluginlink->myfree</code>) and set new values for <code>*buf_p</code> and <code>*bufsize_p</code>.</p>
|
||||
<p><code>int offset</code> offset of the new data in the buffer, <code>int * length_p</code> length of all data in the buffer. You should filter only <code>(*length_p - *offset_p)</code> characters starting from <code>(*buf_p + *offset_p)</code>.</p>
|
||||
<p><code>filter_clear</code> is called for each successfule filter_client and should be used to free allocated resources</p>
|
||||
<p><code>filter_close</code> is called for each successful filter_open for the same reason</p>
|
||||
<p>An example of filter API usage you can find in PCREPlugin (see plugins/PCREPlugin/pcre_plugin.c).</p>
|
||||
<p><span class="s1">Note</span>: if <code>param->nooverwritefilter</code> is set for FILTER_BUFFER functions, filter may change data in the buffer, but must not change data length. This flag may be set, if data size if already known and is sent to the client.</p>
|
||||
</li>
|
||||
<li>Replacing log functions, traffic counting functions, bandwidth limitation functions
|
||||
<p>Log, traffic and bandwidth function can be directly replaced in any over place. All functions may be replaced in conf (<code>pluginlink->conf->logfunc</code>, <code>pluginlink->conf->bandlimfunc</code>, <code>pluginlink->conf->trafcountfunc</code>). In this case, these functions will be used for services started after the changes are made. logfunc may also be changed for struct srvparam (e.g. within filter_open), bandlimfunc and trafcountfunc may be changed in struct clientparam for every client individually (e.g. within filter_client).</p>
|
||||
<p><code>char * instance</code> – is some instance identifier. You can use it to find required filter in the list. 3proxy itself doesn't use this field.</p>
|
||||
<p><code>void * data</code> – this parameter is passed to filter_open function. The rest are filtering functions. Section 1 explains where and then each filter is called. data should not be NULL.</p>
|
||||
<p><code>filter_open</code> must always be defined, if you want filter to be ever used. It's called then new service is created and is given "data" from struct filter and struct srvparam (parsed service configuration). If filter_open for some filter returns NULL, filter will not be used for this service. Non-NULL return value will be used as "fo" parameter for every call to filter_client.</p>
|
||||
<p><code>filter_client</code> is called upon client connect (before any data is sent/received). It's good place to filter client by IP (and is not good place to filter it by hostname, because this operation takes a long time, 3proxy will not be able to accept new connection). fo is a data pointer received from filter_open, param – newly created clientparam structure, fc is return parameter filter_open must initialize, it will be used as an argument to FILTER_BUFFER functions. PASS return value means this filter will be used for this client request. CONTINUE says to install filters. On different values client connection is closed and no client thread is created.</p>
|
||||
<p><code>filter_request, filter_header_cli, filter_header_srv, filter_data_cli, filter_data_srv</code> are used to process request and data received from client and server.</p>
|
||||
<p><code>char ** buf_p</code> is a pointer to current buffer, <code>int * bufsize_p</code> is a pointer to it's size. In case you change some data and it doesn't fit to current buffer, you may allocate new buffer (with <code>pluginlink->myalloc</code>), copy data from old buffer, free old buffer (with <code>pluginlink->myfree</code>) and set new values for <code>*buf_p</code> and <code>*bufsize_p</code>.</p>
|
||||
<p><code>int offset</code> offset of the new data in the buffer, <code>int * length_p</code> length of all data in the buffer. You should filter only <code>(*length_p - *offset_p)</code> characters starting from <code>(*buf_p + *offset_p)</code>.</p>
|
||||
<p><code>filter_clear</code> is called for each successfule filter_client and should be used to free allocated resources</p>
|
||||
<p><code>filter_close</code> is called for each successful filter_open for the same reason</p>
|
||||
<p>An example of filter API usage you can find in PCREPlugin (see plugins/PCREPlugin/pcre_plugin.c).</p>
|
||||
<p><span class="s1">Note</span>: if <code>param->nooverwritefilter</code> is set for FILTER_BUFFER functions, filter may change data in the buffer, but must not change data length. This flag may be set, if data size if already known and is sent to the client.</p>
|
||||
</li>
|
||||
<li>Replacing log functions, traffic counting functions, bandwidth limitation functions
|
||||
<p>Log, traffic and bandwidth function can be directly replaced in any over place. All functions may be replaced in conf (<code>pluginlink->conf->logfunc</code>, <code>pluginlink->conf->bandlimfunc</code>, <code>pluginlink->conf->trafcountfunc</code>). In this case, these functions will be used for services started after the changes are made. logfunc may also be changed for struct srvparam (e.g. within filter_open), bandlimfunc and trafcountfunc may be changed in struct clientparam for every client individually (e.g. within filter_client).</p>
|
||||
<pre><code>typedef void (*LOGFUNC)(struct clientparam * param, const unsigned char * test);
|
||||
typedef void (*TRAFCOUNTFUNC)(struct clientparam * param);
|
||||
typedef unsigned (*BANDLIMFUNC)(struct clientparam * param, unsigned nbytesin, unsigned nbytesout);</code></pre>
|
||||
<p><code>struct clientparam * param</code> – information about client request</p>
|
||||
<p><code>char * text</code> - text string (e.g. request)</p>
|
||||
<p><code>nbytesin, nbytesout</code> – number of bytes received from / send to server. bandlimfunc returns delay in milliseconds.</p>
|
||||
</li>
|
||||
</ol>
|
||||
</li>
|
||||
</ol>
|
||||
</li>
|
||||
<p><code>struct clientparam * param</code> – information about client request</p>
|
||||
<p><code>char * text</code> - text string (e.g. request)</p>
|
||||
<p><code>nbytesin, nbytesout</code> – number of bytes received from / send to server. bandlimfunc returns delay in milliseconds.</p>
|
||||
</li>
|
||||
</ol>
|
||||
</li>
|
||||
</ol>
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
</body>
|
||||
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
|
||||
<H2><A href="howtoe.html">See HowTo:</a></H2>
|
||||
<H2><A href="howtoe.html">See HowTo:</a></h2>
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
|
||||
<H2><A href="howtoe.html">См. HowTo</a></H2>
|
||||
<H2><A href="howtoe.html">См. HowTo</a></h2>
|
||||
+250
-51
@@ -5,8 +5,8 @@
|
||||
<h4>Configuring 'maxconn'</h4>
|
||||
|
||||
The number of simultaneous connections per service is limited by the 'maxconn' option.
|
||||
The default maxconn value since 3proxy 0.8 is 500. You may want to set 'maxconn'
|
||||
to a higher value. Under this configuration:
|
||||
The default maxconn value is 500. You may want to set 'maxconn'
|
||||
to a higher value; it must be set before the services it should apply to. Under this configuration:
|
||||
<pre>
|
||||
maxconn 1000
|
||||
proxy -p3129
|
||||
@@ -19,6 +19,10 @@ simultaneous connections to 3proxy.
|
||||
<p>Avoid setting 'maxconn' to an arbitrarily high value; it should be carefully
|
||||
chosen to protect the system and proxy from resource exhaustion. Setting maxconn
|
||||
above available resources can lead to denial of service conditions.
|
||||
<p>'maxconn' is not reduced automatically to fit the open file limit. If the limit is
|
||||
too low 3proxy only prints a warning at startup
|
||||
("current open file ulimits are too low") and then fails to accept connections once
|
||||
the limit is reached, so check for this warning after changing 'maxconn'.
|
||||
<h4>Understanding Resource Requirements</h4>
|
||||
Each running service requires:
|
||||
<ul>
|
||||
@@ -30,10 +34,7 @@ Each connected client requires:
|
||||
<ul>
|
||||
<li>1 thread (process)
|
||||
<li>2 sockets (file descriptors). For FTP, 4 sockets are required.
|
||||
<br>Under Linux since 0.9, splice() is used. It's much more efficient but requires
|
||||
<br>2 sockets (file descriptors) + 2 pipes (file descriptors) = 4 file descriptors.
|
||||
<br>For FTP with splice(), 4 sockets and 2 pipes are required.
|
||||
<br>Up to 128K (up to 256K in the case of splice()) of kernel buffer memory. This is the theoretical maximum; actual numbers depend on connection quality and traffic amount.
|
||||
<br>Up to 128K of kernel buffer memory. This is the theoretical maximum; actual numbers depend on connection quality and traffic amount.
|
||||
<br>1 additional socket (file descriptor) during name resolution for non-cached names
|
||||
<br>1 additional socket during authentication or logging for RADIUS authentication or logging.
|
||||
<li>1 ephemeral port (3 ephemeral ports for FTP connections).
|
||||
@@ -59,19 +60,45 @@ system "ulimit -Sa >>/tmp/3proxy.ulim.soft"
|
||||
at the beginning (before the first service is started) and at the end of the config file.
|
||||
Perform both a hard restart (i.e., kill and start the 3proxy process) and a soft restart
|
||||
by sending SIGUSR1 to the 3proxy process; check that the ulimits recorded to files match your
|
||||
expectations. In systemd-based distros (e.g., latest Debian/Ubuntu), changing limits.conf
|
||||
is not enough; limits must be adjusted in the systemd configuration, e.g., by setting:
|
||||
expectations. In systemd-based distros (e.g., latest Debian/Ubuntu) changing limits.conf is not
|
||||
enough for a service: limits must be set in the unit file. Set them in the 3proxy
|
||||
unit itself rather than globally, so the rest of the system is unaffected. The
|
||||
shipped 3proxy.service already contains:
|
||||
<pre>
|
||||
DefaultLimitDATA=infinity
|
||||
DefaultLimitSTACK=infinity
|
||||
DefaultLimitCORE=infinity
|
||||
DefaultLimitRSS=infinity
|
||||
DefaultLimitNOFILE=102400
|
||||
DefaultLimitAS=infinity
|
||||
DefaultLimitNPROC=10240
|
||||
DefaultLimitMEMLOCK=infinity
|
||||
LimitNOFILE=1048576
|
||||
LimitNPROC=infinity
|
||||
TasksMax=infinity
|
||||
</pre>
|
||||
To change them on an installed system use an override instead of editing the unit:
|
||||
<pre>
|
||||
systemctl edit 3proxy
|
||||
systemctl daemon-reload && systemctl restart 3proxy
|
||||
systemctl show 3proxy -p LimitNOFILE -p LimitNPROC -p TasksMax
|
||||
</pre>
|
||||
<b>TasksMax is the one that is easy to miss.</b> It is the cgroup limit on the number
|
||||
of threads, and if it is not set the unit inherits DefaultTasksMax, which is 15% of
|
||||
kernel.threads-max (about 9000 on a typical host). Since 3proxy uses one thread per
|
||||
connection, that caps concurrent connections at that number regardless of LimitNPROC
|
||||
and maxconn, and the only symptom is "pthread_create()" errors in the log.
|
||||
<p>On systemd older than 227, which has no TasksMax, and for limits that must apply to
|
||||
several services, the same values can be set globally as DefaultLimitNOFILE /
|
||||
DefaultLimitNPROC in /etc/systemd/system.conf, but prefer the per-unit settings.
|
||||
|
||||
<p>With SysV init the limits are not applied by limits.conf either, because
|
||||
start-stop-daemon does not open a PAM session, so the daemon simply inherits the limits
|
||||
of init. The shipped init script raises them itself before starting 3proxy:
|
||||
<pre>
|
||||
ulimit -n 65536
|
||||
ulimit -u 32768
|
||||
</pre>
|
||||
adjust these values in the script to match 'maxconn'.
|
||||
|
||||
<p>On FreeBSD rc.subr applies limits(1) with the login class of the service (the
|
||||
"daemon" class by default), so the limits can be set either in /etc/login.conf for that
|
||||
class, or per service in rc.conf:
|
||||
<pre>
|
||||
3proxy_limits="-n 65536"
|
||||
</pre>
|
||||
in user.conf / system.conf
|
||||
|
||||
<h4>Extending System Limitations</h4>
|
||||
|
||||
@@ -86,19 +113,172 @@ proxy -olSO_REUSEADDR,SO_REUSEPORT -ocTCP_TIMESTAMPS,TCP_NODELAY -osTCP_NODELAY
|
||||
</pre>
|
||||
Available options are system-dependent.
|
||||
|
||||
<h4>Linux Tuning Hints</h4>
|
||||
|
||||
Values below are examples, not recommendations: check the current value first
|
||||
(<tt>sysctl NAME</tt>), change only what your workload actually hits, and make changes
|
||||
persistent in <tt>/etc/sysctl.d/</tt>. Defaults given in parentheses are from a recent
|
||||
(6.x) kernel and vary between distributions and versions.
|
||||
|
||||
<p><b>File descriptors.</b> 3proxy needs 2 descriptors per connection (4 for FTP), plus
|
||||
one per service, plus temporary ones for name resolution and RADIUS.
|
||||
<pre>
|
||||
fs.nr_open = 1048576 # (1048576) upper bound for any process' RLIMIT_NOFILE
|
||||
</pre>
|
||||
<tt>ulimit -n</tt> (RLIMIT_NOFILE) is the limit that actually applies and is commonly
|
||||
left at 1024; it must be raised for the 3proxy process itself, see "Setting ulimits"
|
||||
above. <tt>fs.file-max</tt> is effectively unlimited on 64-bit kernels and rarely needs
|
||||
changing.
|
||||
|
||||
<p><b>Threads.</b> Because of the "one connection - one thread" model these limits are
|
||||
reached earlier with 3proxy than with event-driven servers. Each thread also consumes
|
||||
one or two mappings, so <tt>vm.max_map_count</tt> matters too.
|
||||
<pre>
|
||||
kernel.threads-max = 200000 # (~60000 on a 16G host, scales with RAM)
|
||||
kernel.pid_max = 4194304 # (4194304)
|
||||
vm.max_map_count = 1048576 # (1048576)
|
||||
</pre>
|
||||
RLIMIT_NPROC (<tt>ulimit -u</tt>) limits threads per user and must be raised as well.
|
||||
Check the actual thread count with <tt>grep Threads /proc/PID/status</tt>.
|
||||
|
||||
<p><b>Listen queue.</b> 3proxy uses a listen backlog of 1+(maxconn/8) unless the
|
||||
'backlog' command is given, so a large 'maxconn' does not automatically give a large
|
||||
queue, and the kernel caps it at somaxconn:
|
||||
<pre>
|
||||
net.core.somaxconn = 4096 # (4096)
|
||||
net.ipv4.tcp_max_syn_backlog = 4096 # (512) raise for bursty connection rates
|
||||
net.ipv4.tcp_syncookies = 1 # (1) keep enabled
|
||||
</pre>
|
||||
|
||||
<p><b>Ephemeral ports and TIME_WAIT.</b> See "Extending the Ephemeral Port Range" above
|
||||
for the multi-IP case. The range gives about 28000 outgoing connections per
|
||||
destination address by default:
|
||||
<pre>
|
||||
net.ipv4.ip_local_port_range = 10240 65535 # (32768 60999)
|
||||
net.ipv4.tcp_tw_reuse = 2 # (2) reuse TIME_WAIT for outgoing connections
|
||||
net.ipv4.tcp_fin_timeout = 30 # (60)
|
||||
</pre>
|
||||
Do not enable tcp_tw_recycle; it was removed in kernel 4.12 and breaks NAT clients.
|
||||
|
||||
<p><b>Socket buffers.</b> Autotuning is usually right. Buffer memory is per connection,
|
||||
so raising the maximums with tens of thousands of connections costs a lot of RAM:
|
||||
<pre>
|
||||
net.core.rmem_max = 4194304 # (212992)
|
||||
net.core.wmem_max = 4194304 # (212992)
|
||||
net.ipv4.tcp_rmem = 4096 131072 6291456 # (same) min default max
|
||||
net.ipv4.tcp_wmem = 4096 16384 4194304 # (same)
|
||||
</pre>
|
||||
Raise these only for high bandwidth-delay product links, and prefer raising the third
|
||||
(max) value and leaving the default alone.
|
||||
|
||||
<p><b>Conntrack.</b> Only relevant if netfilter/nftables tracks the proxy's traffic. If
|
||||
it does, the table is exhausted long before 3proxy's own limits, with
|
||||
"nf_conntrack: table full, dropping packet" in dmesg:
|
||||
<pre>
|
||||
net.netfilter.nf_conntrack_max = 1048576
|
||||
net.netfilter.nf_conntrack_buckets = 262144
|
||||
net.netfilter.nf_conntrack_tcp_timeout_established = 3600 # (432000, i.e. 5 days)
|
||||
net.netfilter.nf_conntrack_tcp_timeout_time_wait = 30 # (120)
|
||||
</pre>
|
||||
nf_conntrack_max defaults to nf_conntrack_buckets, which itself is derived from the
|
||||
amount of RAM, so it is often much lower than expected on small machines. Each
|
||||
connection takes two entries (one per direction). The default established timeout of
|
||||
5 days matters more than the table size with high connection churn: entries for
|
||||
connections that are long gone keep occupying the table.
|
||||
<p>If no rules need conntrack, not loading it at all is faster: the modules are loaded
|
||||
on demand by the first rule that needs them ("-m state", "-m conntrack", any NAT
|
||||
rule), so a ruleset without such rules keeps the proxy traffic untracked. If conntrack
|
||||
is needed for other traffic but not for the proxy's, exempt the proxy's traffic
|
||||
explicitly in the raw table:
|
||||
<pre>
|
||||
iptables -t raw -A PREROUTING -p tcp --dport 3128 -j CT --notrack
|
||||
iptables -t raw -A OUTPUT -p tcp -m owner --uid-owner proxy -j CT --notrack
|
||||
</pre>
|
||||
|
||||
<p><b>Conntrack helpers (ALGs).</b> The helper modules - nf_conntrack_ftp,
|
||||
nf_conntrack_sip, nf_conntrack_h323, nf_conntrack_pptp, nf_conntrack_irc,
|
||||
nf_conntrack_tftp - inspect the payload of every matching packet and create additional
|
||||
"expectation" entries, so they cost both CPU and table space, and they have a long
|
||||
history of security issues. Unload and blacklist the ones you do not actually need:
|
||||
<pre>
|
||||
lsmod | grep nf_conntrack
|
||||
modprobe -r nf_conntrack_sip nf_conntrack_h323 nf_conntrack_ftp nf_conntrack_pptp
|
||||
echo "blacklist nf_conntrack_sip" >> /etc/modprobe.d/no-alg.conf
|
||||
</pre>
|
||||
On current kernels a helper only acts when it is attached explicitly
|
||||
("-j CT --helper ftp"), so simply not attaching it is enough; automatic helper
|
||||
assignment was deprecated and later removed. Older kernels, and most router firmware,
|
||||
still enable them by default.
|
||||
|
||||
<p><b>Checking the result.</b> <tt>ss -s</tt> for socket state totals,
|
||||
<tt>ss -lnt</tt> for listen queue overflow, <tt>nstat -az TcpExtListenOverflows
|
||||
TcpExtListenDrops</tt> for accept queue drops, and
|
||||
<tt>cat /proc/PID/limits</tt> for the limits actually applied to the running process.
|
||||
|
||||
<h4>Windows Tuning Hints</h4>
|
||||
|
||||
<p><b>Dynamic (ephemeral) port range.</b> Since Windows Vista / Server 2008 the default
|
||||
range is 49152-65535, i.e. only 16384 outgoing connections per local address, which is
|
||||
reached quickly by a busy proxy. Show and change it with:
|
||||
<pre>
|
||||
netsh int ipv4 show dynamicport tcp
|
||||
netsh int ipv4 set dynamicport tcp start=10000 num=55535
|
||||
</pre>
|
||||
The minimum start port is 1025, the minimum size of the range is 255, and the end of
|
||||
the range cannot exceed 65535. The range is set separately for TCP and UDP, and for
|
||||
IPv4 and IPv6. On pre-Vista systems the equivalent is the MaxUserPort registry value
|
||||
in HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters.
|
||||
|
||||
<p><b>Listening socket.</b> 3proxy sets SO_REUSEADDR on the listening socket by
|
||||
default on Unix, but not on Windows: there it is not needed to rebind the port, and it
|
||||
only allows another local process to bind the same address and port, with undefined
|
||||
behaviour as to which of them receives the connections. If the machine is shared or
|
||||
untrusted, harden the listening socket instead:
|
||||
<pre>
|
||||
proxy -olSO_EXCLUSIVEADDRUSE
|
||||
</pre>
|
||||
Note that a socket with SO_EXCLUSIVEADDRUSE may not be immediately rebindable after a
|
||||
restart if accepted connections are still active, so test restarts before using it.
|
||||
|
||||
<p><b>Port reuse.</b> 3proxy always binds the outgoing socket before connecting, so
|
||||
Windows does not apply its automatic ephemeral port reuse (which it does only for
|
||||
connections with an implicit bind). Setting the option explicitly on the
|
||||
proxy-to-server socket therefore helps against port exhaustion:
|
||||
<pre>
|
||||
proxy -osSO_REUSE_UNICASTPORT
|
||||
</pre>
|
||||
SO_REUSE_UNICASTPORT requires Windows 10 / Server 2019 or later. On older systems
|
||||
(Windows 7 / Server 2008 and later) use SO_PORT_SCALABILITY instead; where both are
|
||||
available Microsoft recommends SO_REUSE_UNICASTPORT. Note that SO_REUSEADDR has
|
||||
different, weaker semantics on Windows than on Unix and allows another socket to bind
|
||||
the same address and port, so do not use it on the listening socket as a substitute.
|
||||
|
||||
<p><b>TIME_WAIT.</b> Closed connections hold their port for the TcpTimedWaitDelay
|
||||
period, set in
|
||||
HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters (DWORD, seconds). The
|
||||
effective default differs between Windows versions (2 to 4 minutes); check the current
|
||||
behaviour before changing it, and lower it only together with an extended port range.
|
||||
Count the connections in that state with:
|
||||
<pre>
|
||||
netstat -ano -p tcp | find /c "TIME_WAIT"
|
||||
</pre>
|
||||
|
||||
<p><b>Threads and address space.</b> Windows has no ulimit equivalent, and the handle
|
||||
count is not normally the limit. On 32-bit builds the 2 GB of user address space is:
|
||||
each connection thread reserves its stack there, so a few thousand connections can
|
||||
exhaust the address space while physical memory is still free. Use a 64-bit build for high load, and
|
||||
see "Setting Stack Size" above.
|
||||
|
||||
<p><b>Filter drivers.</b> Antivirus, endpoint protection and other LSP/WFP filter
|
||||
drivers inspect every connection and are frequently the actual bottleneck on Windows,
|
||||
costing far more than any tuning above can recover. Exclude the 3proxy process and its
|
||||
ports, or test with the protection temporarily disabled to see the difference before
|
||||
tuning anything else.
|
||||
|
||||
<h4>Using 3proxy in a Virtual Environment</h4>
|
||||
|
||||
If 3proxy is used in a VPS environment, there can be additional limitations.
|
||||
For example, kernel resources, system CPU usage, and IOCTLs can be limited differently, and this can become a bottleneck.
|
||||
Since 0.9-devel, 3proxy uses splice() by default on Linux. splice() prevents network traffic from being copied from
|
||||
kernel space to the 3proxy process and generally increases throughput, especially in the case of high-volume traffic. This is especially
|
||||
true for virtual environments (it can improve throughput up to 10 times) unless there are additional kernel limitations.
|
||||
Since some work is moved to the kernel, it requires up to 2 times more kernel resources in terms of CPU, memory, and IOCTLs.
|
||||
If your hosting additionally limits kernel resources (you can see this as nearly 100% CPU usage without any real CPU activity for
|
||||
any application performing IOCTLs), use the -s0 option to disable splice() usage for a given service, e.g.:
|
||||
<pre>
|
||||
socks -s0
|
||||
</pre>
|
||||
|
||||
<h4>Extending the Ephemeral Port Range</h4>
|
||||
|
||||
@@ -160,10 +340,10 @@ Under the latest Linux versions, you can also start multiple services with diffe
|
||||
external addresses on a single port with SO_REUSEPORT on the listening socket to
|
||||
evenly distribute incoming connections between outgoing interfaces:
|
||||
<pre>
|
||||
socks -olSO_REUSEPORT -p3128 -e 1.1.1.1
|
||||
socks -olSO_REUSEPORT -p3128 -e 2.2.2.2
|
||||
socks -olSO_REUSEPORT -p3128 -e 3.3.3.3
|
||||
socks -olSO_REUSEPORT -p3128 -e 4.4.4.4
|
||||
socks -olSO_REUSEPORT -p3128 -e1.1.1.1
|
||||
socks -olSO_REUSEPORT -p3128 -e2.2.2.2
|
||||
socks -olSO_REUSEPORT -p3128 -e3.3.3.3
|
||||
socks -olSO_REUSEPORT -p3128 -e4.4.4.4
|
||||
</pre>
|
||||
For web browsing, the last two examples are not recommended because the same client can get
|
||||
a different external address for different requests; you should choose the external
|
||||
@@ -184,6 +364,39 @@ randomly fail due to IP+port pair collisions if the remote or local system
|
||||
doesn't support this trick.
|
||||
</ol>
|
||||
|
||||
<h4>NAT on the Path Must Be Tuned Too</h4>
|
||||
|
||||
Everything above tunes the machine 3proxy runs on. If the outgoing traffic passes
|
||||
through NAT - a router, a firewall, a CGNAT of the provider, or a cloud NAT gateway -
|
||||
that device keeps its own translation table and its own pool of source ports, and it
|
||||
limits the number of connections independently of the proxy. Extending
|
||||
ip_local_port_range on the 3proxy host changes nothing if the NAT device rewrites the
|
||||
source port from its own, smaller pool.
|
||||
|
||||
<p>On a Linux based router the same knobs apply and have to be raised there as well:
|
||||
nf_conntrack_max / nf_conntrack_buckets and the conntrack timeouts (see "Linux Tuning
|
||||
Hints" above), plus the port range used for translation, which is ip_local_port_range
|
||||
for MASQUERADE, or the explicit range if SNAT is configured with --to-ports. Note that
|
||||
the range is per translated address: with a single public IP, all clients share it.
|
||||
|
||||
<p>Entry level and SOHO routers are the usual bottleneck here. They typically have a
|
||||
small fixed NAT/conntrack table (a few thousand entries), aggressive or non-adjustable
|
||||
timeouts, and no way to change either. Symptoms are seen on the proxy but caused by the
|
||||
router: connections that fail or hang at random under load while the proxy is far from
|
||||
its own limits, no error in the 3proxy log except a failed outgoing connect, and
|
||||
recovery after a pause or a router reboot. Before tuning 3proxy further, check the
|
||||
router's session/NAT table counters. For high load either give the proxy a public
|
||||
address without NAT in the path, or use a router where the table size and timeouts are
|
||||
configurable.
|
||||
|
||||
<p>On the router, also turn off the application layer gateways that are not actually
|
||||
used - they usually appear in the web interface as "SIP ALG", "FTP ALG", "H.323 ALG",
|
||||
"PPTP passthrough", "IPsec/VPN passthrough". They are commonly enabled by default, they
|
||||
parse the payload of matching connections, and they consume additional session table
|
||||
entries for the connections they expect. If nothing behind the proxy uses FTP, VoIP or
|
||||
those VPN protocols, disabling them frees table space and CPU on exactly the device
|
||||
that is the bottleneck.
|
||||
|
||||
<h4>Setting Stack Size</h4>
|
||||
|
||||
'stacksize' is a size added to all stack allocations and can be both positive and
|
||||
@@ -199,7 +412,11 @@ the need to add additional physical memory,
|
||||
but it's system/libc dependent and requires additional testing under your
|
||||
installation. Don't forget about memory-related ulimits.
|
||||
<p>For 32-bit systems, address space can be a bottleneck you should consider. If
|
||||
you're short on address space, you can try using a negative stack size.
|
||||
you're short on address space, you can try using a negative stack size. The result is
|
||||
never lowered below the system minimum (PTHREAD_STACK_MIN), so a large negative value
|
||||
can not disable the thread stack. The base value the 'stacksize' is added to is 48K
|
||||
(64K on FreeBSD/NetBSD/OpenBSD/DragonFly, where libc uses more stack, e.g. in
|
||||
vfprintf() called by syslog()).
|
||||
|
||||
<h4>Known System Issues</h4>
|
||||
|
||||
@@ -268,24 +485,6 @@ sets TCP_NODELAY for client (oc) and server (os) connections.
|
||||
<p>Do not use TCP_NODELAY on slow connections with high delays when
|
||||
connection bandwidth is a bottleneck.
|
||||
|
||||
<h4>Use Splice to Speed Up Large Data Amount Transfers</h4>
|
||||
|
||||
splice() allows copying data between connections without copying to the process
|
||||
address space. It can speed up the proxy on high-bandwidth connections if most
|
||||
connections require large data transfers. Splice is enabled by default on Linux
|
||||
since 0.9; "-s0" disables splice usage. Example:
|
||||
<pre>
|
||||
proxy -s0
|
||||
</pre>
|
||||
Splice is only available on Linux. Splice requires more system buffers and file descriptors
|
||||
and produces more IOCTLs but reduces process memory and overall CPU usage.
|
||||
Disable splice if there are a lot of short-lived connections with no bandwidth
|
||||
requirements.
|
||||
<p>Use splice only on high-speed connections (e.g., 10GbE) when the processor, memory speed, or
|
||||
system bus are bottlenecks.
|
||||
<p>TCP_NODELAY and splice are not contrary to each other and should be combined on
|
||||
high-speed connections.
|
||||
|
||||
<h4>Add Grace Delay to Reduce System Calls</h4>
|
||||
|
||||
<pre>proxy -g8000,3,10</pre>
|
||||
@@ -294,7 +493,7 @@ the minimal number of packets in the same direction to apply the algorithm,
|
||||
and the last value is the delay added after polling and prior to reading data.
|
||||
The example above adds a 10-millisecond delay before reading data if the average
|
||||
polling size is below 8000 bytes and 3 read operations have been made in the same
|
||||
direction. It's especially useful with splice. <pre>logdump 1 1</pre> is useful
|
||||
direction. <pre>logdump 1 1</pre> is useful
|
||||
to see how grace delays work; choose a delay value to avoid filling the read
|
||||
pipe/buffer (typically 64K) but keep the request sizes close to the chosen average
|
||||
buffer (typically 64K) but keep the request sizes close to the chosen average
|
||||
on large file uploads/downloads.
|
||||
+522
-432
File diff suppressed because it is too large.
Load diff
+1184
-1092
File diff suppressed because it is too large.
Load diff
@@ -8,6 +8,7 @@
|
||||
<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/imapp.8.html">imapp.8</A>
|
||||
<br><A HREF="man8/pop3p.8.html">pop3p.8</A>
|
||||
<br><A HREF="man8/proxy.8.html">proxy.8</A>
|
||||
<br><A HREF="man8/smtpp.8.html">smtpp.8</A>
|
||||
|
||||
@@ -87,6 +87,7 @@ start gateway services:</p>
|
||||
[options] <b><br>
|
||||
socks</b> [options] <b><br>
|
||||
pop3p</b> [options] <b><br>
|
||||
imapp</b> [options] <b><br>
|
||||
smtpp</b> [options] <b><br>
|
||||
ftppr</b> [options] <b><br>
|
||||
admin</b> [options] <b><br>
|
||||
@@ -104,6 +105,7 @@ handshake), may be used to redirect any TLS-based traffic
|
||||
auto</b> Proxy with protocol autoselection between proxy /
|
||||
socks / tlspr <b><br>
|
||||
pop3p</b> POP3 proxy (default port 110) <b><br>
|
||||
imapp</b> IMAPv4 proxy (default port 143) <b><br>
|
||||
smtpp</b> SMTP proxy (default port 25) <b><br>
|
||||
ftppr</b> FTP proxy (default port 21) <b><br>
|
||||
admin</b> Web interface (default port 80) <b><br>
|
||||
@@ -190,9 +192,16 @@ or hostname, useful in case of dynamic DNS. <b><br>
|
||||
(<b>-ol</b>), connect back client (<b>-or</b>), connect back
|
||||
listening (<b>-oR</b>) sockets. Options like TCP_CORK,
|
||||
TCP_NODELAY, TCP_DEFER_ACCEPT, TCP_QUICKACK, TCP_TIMESTAMPS,
|
||||
USE_TCP_FASTOPEN, SO_REUSEADDR, SO_REUSEPORT,
|
||||
SO_PORT_SCALABILITY, SO_REUSE_UNICASTPORT, SO_KEEPALIVE,
|
||||
SO_DONTROUTE may be supported depending on OS. <b><br>
|
||||
TCP_FASTOPEN, SO_REUSEADDR, SO_REUSEPORT,
|
||||
SO_EXCLUSIVEADDRUSE, SO_PORT_SCALABILITY,
|
||||
SO_REUSE_UNICASTPORT, SO_KEEPALIVE, SO_DONTROUTE may be
|
||||
supported depending on OS. SO_REUSEADDR and SO_REUSEPORT are
|
||||
set on the listening socket by default on Unix. On Windows
|
||||
SO_REUSEADDR is not set: it is not required to rebind a
|
||||
listening port and it only lets another local process bind
|
||||
the same address and port. Use SO_EXCLUSIVEADDRUSE (Windows)
|
||||
on the listening socket (<b>-ol</b>) to prevent that.
|
||||
<b><br>
|
||||
-H</b> (for all services) Expect HAProxy PROXY protocol v1
|
||||
header on incoming connection. This allows the proxy to
|
||||
receive real client IP address from HAProxy or other load
|
||||
@@ -203,9 +212,16 @@ be sent before any protocol-specific data. <b><br>
|
||||
delay GRACE_DELAY milliseconds before polling if average
|
||||
polling size is below GRACE_TRAFF bytes and GRACE_NUM read
|
||||
operations in a single direction are detected within 1
|
||||
second. Useful to minimize polling <b>-s</b> <br>
|
||||
second. Useful to minimize polling <b><br>
|
||||
-s</b> <br>
|
||||
(for admin) secure, allow only secure operations, currently
|
||||
only traffic counters view without ability to reset. <br>
|
||||
(for TCP services, Linux) enable splice(). splice() is not
|
||||
built by default and is disabled even when built, because
|
||||
current Linux does not implement SPLICE_F_MOVE, so no real
|
||||
zero-copy takes place and the read/write path is faster for
|
||||
most traffic. Rebuild with -DWITHSPLICE to make -s
|
||||
available, -s0 disables it explicitly. <br>
|
||||
(for dnspr) simple, do not use resolver and 3proxy cache,
|
||||
always use external DNS server. <br>
|
||||
(for udppm) singlepacket, expect only one packet from both
|
||||
@@ -220,8 +236,8 @@ information reported) <b><br>
|
||||
-a2</b> (for proxy) generate Via: and X-Forwarded-For:
|
||||
instead of Forwarded: <br>
|
||||
Also, all options mentioned for <b>proxy</b>(8)
|
||||
<b>socks</b>(8) <b>pop3p</b>(8) <b>tcppm</b>(8)
|
||||
<b>udppm</b>(8) <b>ftppr</b>(8) <br>
|
||||
<b>socks</b>(8) <b>pop3p</b>(8) <b>imapp</b>(8)
|
||||
<b>tcppm</b>(8) <b>udppm</b>(8) <b>ftppr</b>(8) <br>
|
||||
are also supported. <br>
|
||||
Portmapping services listen at SRCPORT and connect to
|
||||
DSTADDR:DSTPORT HTTP and SOCKS proxies are standard. <br>
|
||||
@@ -757,10 +773,15 @@ useful). Never use this option unless you know exactly you
|
||||
need it. <b><br>
|
||||
admin</b> redirect request to local ´admin´
|
||||
service (with -s parameter). <b><br>
|
||||
ha</b> send HAProxy PROXY protocol v1 header to parent
|
||||
proxy. Must be the last in the proxy chain. Useful for
|
||||
passing client IP information to the parent proxy. Example:
|
||||
parent 1000 ha <br>
|
||||
ha</b> send HAProxy PROXY protocol v1 header to the next
|
||||
parent proxy (or to the destination if <b>ha</b> is used
|
||||
alone). Place <b>ha</b> before the parent that should
|
||||
receive the header; after the header is sent, negotiation of
|
||||
that parent protocol continues (SOCKS, CONNECT, etc.).
|
||||
Useful for passing client IP information to the parent
|
||||
proxy. Example: <br>
|
||||
parent 1000 ha 0.0.0.0 0 <br>
|
||||
parent 1000 socks5 parent.example.com 1080 <br>
|
||||
Use "+" proxy only with <b>fakeresolve</b> option
|
||||
<br>
|
||||
Any parent type above can be suffixed with <b>s</b> (e.g.
|
||||
@@ -779,8 +800,9 @@ special case of local redirection, it works only with
|
||||
<b>socks</b> proxy. In case of local redirection request is
|
||||
redirected to different service, <b>ftp</b> locally
|
||||
redirects to <b>ftppr pop3</b> locally redirects to <b>pop3p
|
||||
http</b> locally redirects to <b>proxy admin</b> locally
|
||||
redirects to the admin -s service. <br>
|
||||
imap</b> locally redirects to <b>imapp http</b> locally
|
||||
redirects to <b>proxy admin</b> locally redirects to the
|
||||
admin -s service. <br>
|
||||
Unix domain sockets can be used instead of IP address with
|
||||
the syntax <i>unix:/path/to/socket</i> (e.g., parent 1000
|
||||
socks5 unix:/var/run/parent.sock 1080). On Linux, abstract
|
||||
@@ -1040,7 +1062,17 @@ experience 3proxy crash on request processing, try to set
|
||||
some positive value. You may start with stacksize 65536 and
|
||||
then find the minimal value for the service to work. If you
|
||||
experience memory shortage, you can try to experiment with
|
||||
negative values.</p>
|
||||
negative values. <br>
|
||||
With SQL logging (log &ODBC_string) the value is
|
||||
automatically raised to 32768 if it is smaller, because ODBC
|
||||
drivers require more stack. A <b>stacksize</b> command
|
||||
placed after the <b>log</b> command overrides this. <br>
|
||||
The base stack size the value is added to is 49152. On
|
||||
FreeBSD, NetBSD, OpenBSD and DragonFly it is 65536, because
|
||||
libc functions such as vfprintf() called by syslog() use
|
||||
significantly more stack there. The result is never lowered
|
||||
below PTHREAD_STACK_MIN, so a large negative value can not
|
||||
disable the thread stack.</p>
|
||||
|
||||
<h2>PLUGINS
|
||||
<a name="PLUGINS"></a>
|
||||
@@ -1294,7 +1326,8 @@ to <b>3proxy@3proxy.org</b></p>
|
||||
|
||||
<p style="margin-left:6%; margin-top: 1em">3proxy(8),
|
||||
3proxy_crypt(8), proxy(8), ftppr(8), socks(8), pop3p(8),
|
||||
smtpp(8), tlspr(8), tcppm(8), udppm(8), syslogd(8), <br>
|
||||
imapp(8), smtpp(8), tlspr(8), tcppm(8), udppm(8),
|
||||
syslogd(8), <br>
|
||||
https://3proxy.org/</p>
|
||||
|
||||
<h2>AUTHORS
|
||||
|
||||
@@ -58,11 +58,11 @@ multiple gateways with HTTP and HTTPS proxy with FTP over
|
||||
HTTP support, SOCKS v4, v4.5 and v5, POP3 proxy, UDP and TCP
|
||||
portmappers. Each gateway is started from the configuration
|
||||
file like an independent service <b>proxy</b>(8)
|
||||
<b>socks</b>(8) <b>pop3p</b>(8) <b>tcppm</b>(8)
|
||||
<b>udppm</b>(8) <b>ftppr</b>(8) <b>dnspr</b> but
|
||||
<b>3proxy</b> is not a kind of wrapper or superserver for
|
||||
these daemons. It just has the same code compiled in, but
|
||||
provides much more functionality. SOCKSv5 implementation
|
||||
<b>socks</b>(8) <b>pop3p</b>(8) <b>imapp</b>(8)
|
||||
<b>tcppm</b>(8) <b>udppm</b>(8) <b>ftppr</b>(8) <b>dnspr</b>
|
||||
but <b>3proxy</b> is not a kind of wrapper or superserver
|
||||
for these daemons. It just has the same code compiled in,
|
||||
but provides much more functionality. SOCKSv5 implementation
|
||||
allows you to use 3proxy with any UDP or TCP based client
|
||||
applications designed without proxy support (with
|
||||
<i>SocksCAP</i>, <i>FreeCAP</i> or another client-side
|
||||
@@ -195,8 +195,8 @@ to <b>3proxy@3proxy.org</b></p>
|
||||
|
||||
|
||||
<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>
|
||||
proxy(8), ftppr(8), socks(8), pop3p(8), imapp(8), tcppm(8),
|
||||
udppm(8), kill(1), syslogd(8), <br>
|
||||
https://3proxy.org/</p>
|
||||
|
||||
<h2>AUTHORS
|
||||
|
||||
@@ -0,0 +1,287 @@
|
||||
<!-- Creator : groff version 1.24.1 -->
|
||||
<html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1 align="center">imapp</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="#CLIENTS">CLIENTS</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>imapp</b> -
|
||||
IMAPv4 proxy gateway service</p>
|
||||
|
||||
<h2>SYNOPSIS
|
||||
<a name="SYNOPSIS"></a>
|
||||
</h2>
|
||||
|
||||
|
||||
<p style="margin-left:6%; margin-top: 1em"><b>imapp</b>
|
||||
[<b>-d</b>] [<b>-l</b>[[<i>@</i>]<i>logfile</i>]]
|
||||
[<b>-p</b><i>port</i>] [<b>-i</b><i>internal_ip</i>]
|
||||
[<b>-e</b><i>external_ip</i>]
|
||||
[<b>-h</b><i>default_ip[:port]</i>] [<b>-x</b><i>]</i></p>
|
||||
|
||||
<h2>DESCRIPTION
|
||||
<a name="DESCRIPTION"></a>
|
||||
</h2>
|
||||
|
||||
|
||||
|
||||
<p style="margin-left:6%; margin-top: 1em"><i><b>imapp</b></i>
|
||||
is IMAPv4 (IMAP4rev1) gateway service to allow internal
|
||||
users to access external IMAP servers.</p>
|
||||
|
||||
<h2>OPTIONS
|
||||
<a name="OPTIONS"></a>
|
||||
</h2>
|
||||
|
||||
|
||||
<table width="100%" border="0" rules="none" frame="void"
|
||||
cellspacing="0" cellpadding="0">
|
||||
<tr valign="top" align="left">
|
||||
<td width="6%"></td>
|
||||
<td width="3%">
|
||||
|
||||
|
||||
<p style="margin-top: 1em"><b>-I</b></p></td>
|
||||
<td width="6%"></td>
|
||||
<td width="85%">
|
||||
|
||||
|
||||
<p style="margin-top: 1em">Inetd mode. Standalone service
|
||||
only.</p> </td></tr>
|
||||
<tr valign="top" align="left">
|
||||
<td width="6%"></td>
|
||||
<td width="3%">
|
||||
|
||||
|
||||
<p style="margin-top: 1em"><b>-d</b></p></td>
|
||||
<td width="6%"></td>
|
||||
<td width="85%">
|
||||
|
||||
|
||||
<p style="margin-top: 1em">Daemonize. Detach service from
|
||||
console and run in the background.</p></td></tr>
|
||||
<tr valign="top" align="left">
|
||||
<td width="6%"></td>
|
||||
<td width="3%">
|
||||
|
||||
|
||||
<p style="margin-top: 1em"><b>-t</b></p></td>
|
||||
<td width="6%"></td>
|
||||
<td width="85%">
|
||||
|
||||
|
||||
<p style="margin-top: 1em">Be silenT. Do not log
|
||||
start/stop/accept error records.</p></td></tr>
|
||||
<tr valign="top" align="left">
|
||||
<td width="6%"></td>
|
||||
<td width="3%">
|
||||
|
||||
|
||||
<p style="margin-top: 1em"><b>-u</b></p></td>
|
||||
<td width="6%"></td>
|
||||
<td width="85%">
|
||||
|
||||
|
||||
<p style="margin-top: 1em">Never look for username
|
||||
authentication.</p> </td></tr>
|
||||
<tr valign="top" align="left">
|
||||
<td width="6%"></td>
|
||||
<td width="3%">
|
||||
|
||||
|
||||
<p style="margin-top: 1em"><b>-e</b></p></td>
|
||||
<td width="6%"></td>
|
||||
<td width="85%">
|
||||
|
||||
|
||||
<p style="margin-top: 1em">External address. IP address of
|
||||
the interface the proxy should initiate connections from. By
|
||||
default, the system will decide which address to use in
|
||||
accordance with the routing table.</p></td></tr>
|
||||
</table>
|
||||
|
||||
<p style="margin-left:6%;"><b>-ni</b><i>PATH</i></p>
|
||||
|
||||
<p style="margin-left:15%;">(Linux only) Switch to the
|
||||
network namespace identified by <i>PATH</i> before opening
|
||||
the listening socket. The current namespace is saved and
|
||||
restored immediately after binding, so outgoing connections
|
||||
run in the original namespace unless <b>-ne</b> is also
|
||||
given.</p>
|
||||
|
||||
<p style="margin-left:6%;"><b>-ne</b><i>PATH</i></p>
|
||||
|
||||
<p style="margin-left:15%;">(Linux only) Switch to the
|
||||
network namespace identified by <i>PATH</i> after the
|
||||
listening socket has been bound (and after restoring from
|
||||
<b>-ni</b> if applicable). Both options accept any namespace
|
||||
file path (e.g. <i>/var/run/netns/myns</i> or
|
||||
<i>/proc/PID/ns/net</i>) and require
|
||||
<b>CAP_SYS_ADMIN</b>.</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="3%">
|
||||
|
||||
|
||||
<p><b>-i</b></p></td>
|
||||
<td width="6%"></td>
|
||||
<td width="85%">
|
||||
|
||||
|
||||
<p>Internal address. IP address the proxy accepts
|
||||
connections to. By default, connections to any interface are
|
||||
accepted. It´s usually unsafe. Unix domain sockets can
|
||||
be specified with <i>-iunix:/path/to/socket</i> syntax
|
||||
(e.g., -iunix:/var/run/imapp.sock). On Linux, abstract
|
||||
sockets use <i>-iunix:@socketname</i> syntax.</p></td></tr>
|
||||
<tr valign="top" align="left">
|
||||
<td width="6%"></td>
|
||||
<td width="3%">
|
||||
|
||||
|
||||
<p style="margin-top: 1em"><b>-p</b></p></td>
|
||||
<td width="6%"></td>
|
||||
<td width="85%">
|
||||
|
||||
|
||||
<p style="margin-top: 1em">Port. Port proxy listens for
|
||||
incoming connections. Default is 143.</p></td></tr>
|
||||
<tr valign="top" align="left">
|
||||
<td width="6%"></td>
|
||||
<td width="3%">
|
||||
|
||||
|
||||
<p style="margin-top: 1em"><b>-h</b></p></td>
|
||||
<td width="6%"></td>
|
||||
<td width="85%">
|
||||
|
||||
|
||||
<p style="margin-top: 1em">Default destination. It’s
|
||||
used if the target address is not specified by the user.</p></td></tr>
|
||||
<tr valign="top" align="left">
|
||||
<td width="6%"></td>
|
||||
<td width="3%">
|
||||
|
||||
|
||||
<p style="margin-top: 1em"><b>-x</b></p></td>
|
||||
<td width="6%"></td>
|
||||
<td width="85%">
|
||||
|
||||
|
||||
<p style="margin-top: 1em">Disable STARTTLS support.
|
||||
STARTTLS is not announced in the CAPABILITY response and the
|
||||
STARTTLS command is not accepted.</p></td></tr>
|
||||
<tr valign="top" align="left">
|
||||
<td width="6%"></td>
|
||||
<td width="3%">
|
||||
|
||||
|
||||
<p style="margin-top: 1em"><b>-l</b></p></td>
|
||||
<td width="6%"></td>
|
||||
<td width="85%">
|
||||
|
||||
|
||||
<p style="margin-top: 1em">Log. By default logging is to
|
||||
stdout. If <i>logfile</i> is specified logging is to file.
|
||||
Under Unix, if ´<i>@</i>´ precedes
|
||||
<i>logfile</i>, syslog is used for logging.</p></td></tr>
|
||||
<tr valign="top" align="left">
|
||||
<td width="6%"></td>
|
||||
<td width="3%">
|
||||
|
||||
|
||||
<p style="margin-top: 1em"><b>-S</b></p></td>
|
||||
<td width="6%"></td>
|
||||
<td width="85%">
|
||||
|
||||
|
||||
<p style="margin-top: 1em">Increase or decrease stack size.
|
||||
You may want to try something like -S8192 if you experience
|
||||
3proxy crashes.</p></td></tr>
|
||||
</table>
|
||||
|
||||
<h2>CLIENTS
|
||||
<a name="CLIENTS"></a>
|
||||
</h2>
|
||||
|
||||
|
||||
<p style="margin-left:6%; margin-top: 1em">You can use any
|
||||
MUA (Mail User Agent) with IMAPv4 support. Set the client to
|
||||
use <i>internal_ip</i> and <i>port</i> as an IMAP server.
|
||||
The address of the real IMAP server must be configured as a
|
||||
part of the IMAP username. The format for the username is
|
||||
<i>username</i>@<i>server</i>, where <i>server</i> is the
|
||||
address of the IMAP server and <i>username</i> is the
|
||||
user´s login on this IMAP server. The login itself may
|
||||
contain an ´@´ sign. Supported client
|
||||
authentication methods are the LOGIN command, AUTHENTICATE
|
||||
PLAIN and AUTHENTICATE LOGIN. With the server, the proxy
|
||||
authenticates using the method chosen by the client if the
|
||||
server supports it (as advertised in the CAPABILITY
|
||||
response); otherwise it falls back to AUTHENTICATE LOGIN,
|
||||
AUTHENTICATE PLAIN or the LOGIN command, in this order of
|
||||
preference. Challenge-response authentication (CRAM-MD5,
|
||||
etc.) is not supported, because it requires a challenge from
|
||||
the server before we know which server to connect to. When
|
||||
running as a 3proxy service (not as a standalone binary),
|
||||
STARTTLS is supported and announced in the CAPABILITY
|
||||
response unless disabled with <b>-x</b>. After the client
|
||||
issues STARTTLS, the connection is handled by
|
||||
<b>tlspr</b>(8): the destination host is taken from the SNI
|
||||
of the client TLS handshake (or from the -h option), the
|
||||
proxy performs STARTTLS negotiation with the destination
|
||||
server, and then transparently passes TLS traffic between
|
||||
the client and the server. If the destination server does
|
||||
not support STARTTLS, the TLS handshake with the client
|
||||
fails.</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),
|
||||
ftppr(8), pop3p(8), proxy(8), smtpp(8), socks(8), tcppm(8),
|
||||
tlspr(8), udppm(8), syslogd(8), <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 Dubrovin <vlad@3proxy.org></p>
|
||||
<hr>
|
||||
</body>
|
||||
</html>
|
||||
@@ -36,15 +36,16 @@ POP3 proxy gateway service</p>
|
||||
[<b>-d</b>] [<b>-l</b>[[<i>@</i>]<i>logfile</i>]]
|
||||
[<b>-p</b><i>port</i>] [<b>-i</b><i>internal_ip</i>]
|
||||
[<b>-e</b><i>external_ip</i>]
|
||||
[<b>-h</b><i>default_ip[:port]</i>]</p>
|
||||
[<b>-h</b><i>default_ip[:port]</i>] [<b>-x</b><i>]</i></p>
|
||||
|
||||
<h2>DESCRIPTION
|
||||
<a name="DESCRIPTION"></a>
|
||||
</h2>
|
||||
|
||||
|
||||
<p style="margin-left:6%; margin-top: 1em"><b>pop3p</b> is
|
||||
POP3 gateway service to allow internal users to access
|
||||
|
||||
<p style="margin-left:6%; margin-top: 1em"><i><b>pop3p</b></i>
|
||||
is POP3 gateway service to allow internal users to access
|
||||
external POP3 servers.</p>
|
||||
|
||||
<h2>OPTIONS
|
||||
@@ -184,6 +185,19 @@ used if the target address is not specified by the user.</p></td></tr>
|
||||
<td width="3%">
|
||||
|
||||
|
||||
<p style="margin-top: 1em"><b>-x</b></p></td>
|
||||
<td width="6%"></td>
|
||||
<td width="85%">
|
||||
|
||||
|
||||
<p style="margin-top: 1em">Disable STARTTLS (STLS) support.
|
||||
STLS is not announced in the CAPA response and the STLS
|
||||
command is not accepted.</p></td></tr>
|
||||
<tr valign="top" align="left">
|
||||
<td width="6%"></td>
|
||||
<td width="3%">
|
||||
|
||||
|
||||
<p style="margin-top: 1em"><b>-l</b></p></td>
|
||||
<td width="6%"></td>
|
||||
<td width="85%">
|
||||
@@ -224,8 +238,17 @@ user´s login on this POP3 server. The login itself may
|
||||
contain an ´@´ sign. Only cleartext
|
||||
authentication is supported, because challenge-response
|
||||
authentication (APOP, CRAM-MD5, etc.) requires a challenge
|
||||
from the server before we know which server to connect
|
||||
to.</p>
|
||||
from the server before we know which server to connect to.
|
||||
When running as a 3proxy service (not as a standalone
|
||||
binary), STLS is supported and announced in the CAPA
|
||||
response unless disabled with <b>-x</b>. After the client
|
||||
issues STLS, the connection is handled by <b>tlspr</b>(8):
|
||||
the destination host is taken from the SNI of the client TLS
|
||||
handshake (or from the -h option), the proxy performs STLS
|
||||
negotiation with the destination server, and then
|
||||
transparently passes TLS traffic between the client and the
|
||||
server. If the destination server does not support STLS, the
|
||||
TLS handshake with the client fails.</p>
|
||||
|
||||
<h2>BUGS
|
||||
<a name="BUGS"></a>
|
||||
|
||||
@@ -36,15 +36,16 @@ SMTP proxy gateway service</p>
|
||||
[<b>-d</b>] [<b>-l</b>[[<i>@</i>]<i>logfile</i>]]
|
||||
[<b>-p</b><i>port</i>] [<b>-i</b><i>internal_ip</i>]
|
||||
[<b>-e</b><i>external_ip</i>]
|
||||
[<b>-h</b><i>default_ip[:port]</i>]</p>
|
||||
[<b>-h</b><i>default_ip[:port]</i>] [<b>-x</b><i>]</i></p>
|
||||
|
||||
<h2>DESCRIPTION
|
||||
<a name="DESCRIPTION"></a>
|
||||
</h2>
|
||||
|
||||
|
||||
<p style="margin-left:6%; margin-top: 1em"><b>smtpp</b> is
|
||||
SMTP gateway service to allow internal users to access
|
||||
|
||||
<p style="margin-left:6%; margin-top: 1em"><i><b>smtpp</b></i>
|
||||
is SMTP gateway service to allow internal users to access
|
||||
external SMTP servers.</p>
|
||||
|
||||
<h2>OPTIONS
|
||||
@@ -166,7 +167,7 @@ sockets use <i>-iunix:@socketname</i> syntax.</p></td></tr>
|
||||
|
||||
|
||||
<p style="margin-top: 1em">Port. Port proxy listens for
|
||||
incoming connections. Default is 25.</p></td></tr>
|
||||
incoming connections. Default is 587.</p></td></tr>
|
||||
<tr valign="top" align="left">
|
||||
<td width="6%"></td>
|
||||
<td width="3%">
|
||||
@@ -184,6 +185,19 @@ used if the target address is not specified by the user.</p></td></tr>
|
||||
<td width="3%">
|
||||
|
||||
|
||||
<p style="margin-top: 1em"><b>-x</b></p></td>
|
||||
<td width="6%"></td>
|
||||
<td width="85%">
|
||||
|
||||
|
||||
<p style="margin-top: 1em">Disable STARTTLS support.
|
||||
STARTTLS is not announced in the EHLO response and the
|
||||
STARTTLS command is not accepted.</p></td></tr>
|
||||
<tr valign="top" align="left">
|
||||
<td width="6%"></td>
|
||||
<td width="3%">
|
||||
|
||||
|
||||
<p style="margin-top: 1em"><b>-l</b></p></td>
|
||||
<td width="6%"></td>
|
||||
<td width="85%">
|
||||
@@ -225,7 +239,17 @@ server. The login itself may contain an ´@´
|
||||
sign. Only cleartext authentication is supported, because
|
||||
challenge-response authentication (CRAM-MD5, SPA, etc.)
|
||||
requires a challenge from the server before we know which
|
||||
server to connect to.</p>
|
||||
server to connect to. When running as a 3proxy service (not
|
||||
as a standalone binary), STARTTLS is supported and announced
|
||||
in the EHLO response unless disabled with <b>-x</b>. After
|
||||
the client issues STARTTLS, the connection is handled by
|
||||
<b>tlspr</b>(8): the destination host is taken from the SNI
|
||||
of the client TLS handshake (or from the -h option), the
|
||||
proxy performs STARTTLS negotiation with the destination
|
||||
server, and then transparently passes TLS traffic between
|
||||
the client and the server. If the destination server does
|
||||
not support STARTTLS, the TLS handshake with the client
|
||||
fails.</p>
|
||||
|
||||
<h2>BUGS
|
||||
<a name="BUGS"></a>
|
||||
|
||||
+30
-10
@@ -49,7 +49,9 @@ SNI proxy gateway service</p>
|
||||
an SNI gateway service (destination host is taken from TLS
|
||||
handshake). The destination port must be specified via the
|
||||
-P option (or it may be detected with the Transparent
|
||||
plugin).</p>
|
||||
plugin). tlspr does not support user authentication; use
|
||||
ACLs by client IP or a parent proxy with authentication if
|
||||
access control is required.</p>
|
||||
|
||||
<h2>OPTIONS
|
||||
<a name="OPTIONS"></a>
|
||||
@@ -241,27 +243,45 @@ with TLS 1.3)</p></td></tr>
|
||||
packet across multiple TCP segments to make SNI-based DPI
|
||||
detection harder. An optional numeric value can follow (e.g.
|
||||
<b>-s1</b>) to control the splitting behaviour.</p></td></tr>
|
||||
</table>
|
||||
|
||||
<p style="margin-left:6%;"><b>-Ximap | -Xpop3 |
|
||||
-Xsmtp</b></p>
|
||||
|
||||
<p style="margin-left:15%;">STARTTLS mode for the given
|
||||
protocol. The proxy speaks the plaintext protocol with the
|
||||
client (greeting, capability advertisement with STARTTLS
|
||||
only, STARTTLS command), then, after the client issues
|
||||
STARTTLS and sends a TLS Client HELLO, connects to the
|
||||
destination taken from SNI (default port 143/110/587),
|
||||
performs STARTTLS negotiation with the destination server
|
||||
and transparently passes TLS traffic. If the destination
|
||||
server does not support STARTTLS, the TLS handshake with the
|
||||
client fails.</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="4%">
|
||||
<td width="3%">
|
||||
|
||||
|
||||
<p style="margin-top: 1em"><b>-l</b></p></td>
|
||||
<td width="5%"></td>
|
||||
<p><b>-l</b></p></td>
|
||||
<td width="6%"></td>
|
||||
<td width="85%">
|
||||
|
||||
|
||||
<p style="margin-top: 1em">Log. By default logging is to
|
||||
stdout. If <i>logfile</i> is specified logging is to file.
|
||||
Under Unix, if ´<i>@</i>´ precedes
|
||||
<i>logfile</i>, syslog is used for logging.</p></td></tr>
|
||||
<p>Log. By default logging is to stdout. If <i>logfile</i>
|
||||
is specified logging is to file. Under Unix, if
|
||||
´<i>@</i>´ precedes <i>logfile</i>, syslog is
|
||||
used for logging.</p></td></tr>
|
||||
<tr valign="top" align="left">
|
||||
<td width="6%"></td>
|
||||
<td width="4%">
|
||||
<td width="3%">
|
||||
|
||||
|
||||
<p style="margin-top: 1em"><b>-S</b></p></td>
|
||||
<td width="5%"></td>
|
||||
<td width="6%"></td>
|
||||
<td width="85%">
|
||||
|
||||
|
||||
|
||||
@@ -49,4 +49,4 @@ The second rule will never be applied.
|
||||
</li></ul>
|
||||
|
||||
© Maslov Michael aka Flexx(rus)
|
||||
|
||||
|
||||
@@ -27,18 +27,18 @@ plugin TrafficPlugin.dll start
|
||||
trafcorrect m <сервис> <исходящий порт> <коэффициент>
|
||||
</pre>
|
||||
где: <сервис> может быть proxy, socks4, socks45, socks5, tcppm, udppm, pop3p
|
||||
если сервис указан неверно то считается, что это может быть любой сервис.
|
||||
можно использовать *, тогда правило будет считаться для любого сервиса.
|
||||
если сервис указан неверно то считается, что это может быть любой сервис.
|
||||
можно использовать *, тогда правило будет считаться для любого сервиса.
|
||||
<br> <исходящий порт> - порт, к которому подключается прокси сервер. * - любой
|
||||
<коэффициент> - число на каоторое домнажается траффик. Обязательный параметр.
|
||||
Должен быть от больше 0 и меньше 100
|
||||
<коэффициент> - число на каоторое домнажается траффик. Обязательный параметр.
|
||||
Должен быть от больше 0 и меньше 100
|
||||
<br>
|
||||
ДЛЯ РЕЖИМА С УЧЁТОМ РАЗМЕРА ЗАГОЛОВКОВ ПАКЕТОВ:
|
||||
<pre>
|
||||
trafcorrect p <сервис> <tcp/udp> <исходящий порт> [размер пустого пакета]
|
||||
</pre>
|
||||
<tcp/udp> - протокол, по которому осуществляется соединение.
|
||||
[размер пакета] - средний размер пустого пакета. Можно определить захватив
|
||||
<tcp/udp> - протокол, по которому осуществляется соединение.
|
||||
[размер пакета] - средний размер пустого пакета. Можно определить захватив
|
||||
данные при помощи такой утилиты как Ethereal. Параметр необязателен. Если отсутствует,
|
||||
то размер пакета будет считаться равным 66 байт.
|
||||
<br>Режимы можно смешивать.
|
||||
|
||||
+2
-1
@@ -29,6 +29,7 @@ from the configuration file like an independent service
|
||||
.BR proxy (8)
|
||||
.BR socks (8)
|
||||
.BR pop3p (8)
|
||||
.BR imapp (8)
|
||||
.BR tcppm (8)
|
||||
.BR udppm (8)
|
||||
.BR ftppr (8)
|
||||
@@ -140,7 +141,7 @@ configuration file
|
||||
Report all bugs to
|
||||
.BR 3proxy@3proxy.org
|
||||
.SH SEE ALSO
|
||||
3proxy.cfg(5), proxy(8), ftppr(8), socks(8), pop3p(8), tcppm(8), udppm(8),
|
||||
3proxy.cfg(5), proxy(8), ftppr(8), socks(8), pop3p(8), imapp(8), tcppm(8), udppm(8),
|
||||
kill(1), syslogd(8),
|
||||
.br
|
||||
https://3proxy.org/
|
||||
|
||||
+43
-5
@@ -55,6 +55,9 @@ Recursion is not allowed.
|
||||
.B pop3p
|
||||
[options]
|
||||
.br
|
||||
.B imapp
|
||||
[options]
|
||||
.br
|
||||
.B smtpp
|
||||
[options]
|
||||
.br
|
||||
@@ -92,6 +95,9 @@ Proxy with protocol autoselection between proxy / socks / tlspr
|
||||
.B pop3p
|
||||
POP3 proxy (default port 110)
|
||||
.br
|
||||
.B imapp
|
||||
IMAPv4 proxy (default port 143)
|
||||
.br
|
||||
.B smtpp
|
||||
SMTP proxy (default port 25)
|
||||
.br
|
||||
@@ -172,7 +178,8 @@ connect to given remote HOST:port instead of listening local connection on -p or
|
||||
.br
|
||||
.B -oc\fIOPTIONS\fB, -os\fIOPTIONS\fB, -ol\fIOPTIONS\fB, -or\fIOPTIONS\fB, -oR\fIOPTIONS\fR
|
||||
options for proxy-to-client (\fB-oc\fR), proxy-to-server (\fB-os\fR), proxy listening (\fB-ol\fR), connect back client (\fB-or\fR), connect back listening (\fB-oR\fR) sockets.
|
||||
Options like TCP_CORK, TCP_NODELAY, TCP_DEFER_ACCEPT, TCP_QUICKACK, TCP_TIMESTAMPS, USE_TCP_FASTOPEN, SO_REUSEADDR, SO_REUSEPORT, SO_PORT_SCALABILITY, SO_REUSE_UNICASTPORT, SO_KEEPALIVE, SO_DONTROUTE may be supported depending on OS.
|
||||
Options like TCP_CORK, TCP_NODELAY, TCP_DEFER_ACCEPT, TCP_QUICKACK, TCP_TIMESTAMPS, TCP_FASTOPEN, SO_REUSEADDR, SO_REUSEPORT, SO_EXCLUSIVEADDRUSE, SO_PORT_SCALABILITY, SO_REUSE_UNICASTPORT, SO_KEEPALIVE, SO_DONTROUTE may be supported depending on OS.
|
||||
SO_REUSEADDR and SO_REUSEPORT are set on the listening socket by default on Unix. On Windows SO_REUSEADDR is not set: it is not required to rebind a listening port and it only lets another local process bind the same address and port. Use SO_EXCLUSIVEADDRUSE (Windows) on the listening socket (\fB-ol\fR) to prevent that.
|
||||
.br
|
||||
.B -H
|
||||
(for all services) Expect HAProxy PROXY protocol v1 header on incoming connection.
|
||||
@@ -182,9 +189,16 @@ any protocol-specific data.
|
||||
.br
|
||||
.B -g(\fIGRACE_TRAFF\fB,\fIGRACE_NUM\fB,\fIGRACE_DELAY\fR)
|
||||
delay GRACE_DELAY milliseconds before polling if average polling size is below GRACE_TRAFF bytes and GRACE_NUM read operations in a single direction are detected within 1 second. Useful to minimize polling
|
||||
.br
|
||||
.B -s
|
||||
(for admin) secure, allow only secure operations, currently only traffic counters
|
||||
view without ability to reset.
|
||||
.br
|
||||
(for TCP services, Linux) enable splice(). splice() is not built by default and
|
||||
is disabled even when built, because current Linux does not implement
|
||||
SPLICE_F_MOVE, so no real zero-copy takes place and the read/write path is faster
|
||||
for most traffic. Rebuild with -DWITHSPLICE to make -s available, -s0 disables it
|
||||
explicitly.
|
||||
.br
|
||||
(for dnspr) simple, do not use resolver and 3proxy cache, always use external DNS server.
|
||||
.br
|
||||
@@ -209,6 +223,7 @@ Never ask for username/password
|
||||
.BR proxy (8)
|
||||
.BR socks (8)
|
||||
.BR pop3p (8)
|
||||
.BR imapp (8)
|
||||
.BR tcppm (8)
|
||||
.BR udppm (8)
|
||||
.BR ftppr (8)
|
||||
@@ -821,9 +836,16 @@ unless you know exactly you need it.
|
||||
.br
|
||||
\fBadmin\fR redirect request to local \'admin\' service (with -s parameter).
|
||||
.br
|
||||
\fBha\fR send HAProxy PROXY protocol v1 header to parent proxy. Must be the last
|
||||
in the proxy chain. Useful for passing client IP information to the parent proxy.
|
||||
Example: parent 1000 ha
|
||||
\fBha\fR send HAProxy PROXY protocol v1 header to the next parent proxy (or to
|
||||
the destination if \fBha\fR is used alone). Place \fBha\fR before the parent
|
||||
that should receive the header; after the header is sent, negotiation of that
|
||||
parent protocol continues (SOCKS, CONNECT, etc.). Useful for passing client IP
|
||||
information to the parent proxy.
|
||||
Example:
|
||||
.br
|
||||
parent 1000 ha 0.0.0.0 0
|
||||
.br
|
||||
parent 1000 socks5 parent.example.com 1080
|
||||
.br
|
||||
Use "+" proxy only with \fBfakeresolve\fR option
|
||||
.br
|
||||
@@ -847,6 +869,9 @@ locally redirects to
|
||||
.B pop3
|
||||
locally redirects to
|
||||
.B pop3p
|
||||
.B imap
|
||||
locally redirects to
|
||||
.B imapp
|
||||
.B http
|
||||
locally redirects to
|
||||
.B proxy
|
||||
@@ -1161,6 +1186,19 @@ crash on request processing, try to set some positive value. You may start with
|
||||
stacksize 65536
|
||||
and then find the minimal value for the service to work. If you experience
|
||||
memory shortage, you can try to experiment with negative values.
|
||||
.br
|
||||
With SQL logging (log &ODBC_string) the value is automatically raised to
|
||||
32768 if it is smaller, because ODBC drivers require more stack. A
|
||||
.BR stacksize
|
||||
command placed after the
|
||||
.BR log
|
||||
command overrides this.
|
||||
.br
|
||||
The base stack size the value is added to is 49152. On FreeBSD, NetBSD,
|
||||
OpenBSD and DragonFly it is 65536, because libc functions such as vfprintf()
|
||||
called by syslog() use significantly more stack there. The result is never
|
||||
lowered below PTHREAD_STACK_MIN, so a large negative value can not disable
|
||||
the thread stack.
|
||||
|
||||
.SH PLUGINS
|
||||
|
||||
@@ -1384,7 +1422,7 @@ authentication and/or allow/deny ACLs.
|
||||
Report all bugs to
|
||||
.BR 3proxy@3proxy.org
|
||||
.SH SEE ALSO
|
||||
3proxy(8), 3proxy_crypt(8), proxy(8), ftppr(8), socks(8), pop3p(8), smtpp(8), tlspr(8), tcppm(8), udppm(8), syslogd(8),
|
||||
3proxy(8), 3proxy_crypt(8), proxy(8), ftppr(8), socks(8), pop3p(8), imapp(8), smtpp(8), tlspr(8), tcppm(8), udppm(8), syslogd(8),
|
||||
.br
|
||||
https://3proxy.org/
|
||||
.SH AUTHORS
|
||||
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
.TH imapp "8" "July 2026" "3proxy 0.9" "Universal proxy server"
|
||||
.SH NAME
|
||||
.B imapp
|
||||
\- IMAPv4 proxy gateway service
|
||||
.SH SYNOPSIS
|
||||
.BR "imapp " [ -d ]
|
||||
.IB \fR[ -l \fR[ \fR[ @ \fR] logfile \fR]]
|
||||
.IB \fR[ -p port\fR]
|
||||
.IB \fR[ -i internal_ip\fR]
|
||||
.IB \fR[ -e external_ip\fR]
|
||||
.IB \fR[ -h default_ip[:port]\fR]
|
||||
.IB \fR[ -x ]
|
||||
.SH DESCRIPTION
|
||||
.B imapp
|
||||
is IMAPv4 (IMAP4rev1) gateway service to allow internal users to access external
|
||||
IMAP servers.
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B -I
|
||||
Inetd mode. Standalone service only.
|
||||
.TP
|
||||
.B -d
|
||||
Daemonize. Detach service from console and run in the background.
|
||||
.TP
|
||||
.B -t
|
||||
Be silenT. Do not log start/stop/accept error records.
|
||||
.TP
|
||||
.B -u
|
||||
Never look for username authentication.
|
||||
.TP
|
||||
.B -e
|
||||
External address. IP address of the interface the proxy should initiate connections
|
||||
from.
|
||||
By default, the system will decide which address to use in accordance
|
||||
with the routing table.
|
||||
.TP
|
||||
.B \-ni\fIPATH\fR
|
||||
(Linux only) Switch to the network namespace identified by
|
||||
.I PATH
|
||||
before opening the listening socket. The current namespace is saved and restored
|
||||
immediately after binding, so outgoing connections run in the original namespace
|
||||
unless
|
||||
.B \-ne
|
||||
is also given.
|
||||
.TP
|
||||
.B \-ne\fIPATH\fR
|
||||
(Linux only) Switch to the network namespace identified by
|
||||
.I PATH
|
||||
after the listening socket has been bound (and after restoring from
|
||||
.B \-ni
|
||||
if applicable). Both options accept any namespace file path
|
||||
(e.g.\& \fI/var/run/netns/myns\fR or \fI/proc/PID/ns/net\fR)
|
||||
and require \fBCAP_SYS_ADMIN\fR.
|
||||
.TP
|
||||
.B -i
|
||||
Internal address. IP address the proxy accepts connections to.
|
||||
By default, connections to any interface are accepted. It\'s usually unsafe.
|
||||
Unix domain sockets can be specified with
|
||||
.I -iunix:/path/to/socket
|
||||
syntax (e.g., -iunix:/var/run/imapp.sock). On Linux, abstract sockets use
|
||||
.I -iunix:@socketname
|
||||
syntax.
|
||||
.TP
|
||||
.B -p
|
||||
Port. Port proxy listens for incoming connections. Default is 143.
|
||||
.TP
|
||||
.B -h
|
||||
Default destination. It's used if the target address is not specified by the user.
|
||||
.TP
|
||||
.B -x
|
||||
Disable STARTTLS support. STARTTLS is not announced in the CAPABILITY
|
||||
response and the STARTTLS command is not accepted.
|
||||
.TP
|
||||
.B -l
|
||||
Log. By default logging is to stdout. If
|
||||
.I logfile
|
||||
is specified logging is to file. Under Unix, if
|
||||
.RI \' @ \'
|
||||
precedes
|
||||
.IR logfile ,
|
||||
syslog is used for logging.
|
||||
.TP
|
||||
.B -S
|
||||
Increase or decrease stack size. You may want to try something like -S8192 if you experience 3proxy
|
||||
crashes.
|
||||
.SH CLIENTS
|
||||
You can use any MUA (Mail User Agent) with IMAPv4 support. Set the client to use
|
||||
.I internal_ip
|
||||
and
|
||||
.IR port
|
||||
as an IMAP server. The address of the real IMAP server must be configured as a part of
|
||||
the IMAP username. The format for the username is
|
||||
.IR username @ server ,
|
||||
where
|
||||
.I server
|
||||
is the address of the IMAP server and
|
||||
.I username
|
||||
is the user\'s login on this IMAP server. The login itself may contain an \'@\' sign.
|
||||
Supported client authentication methods are the LOGIN command, AUTHENTICATE PLAIN
|
||||
and AUTHENTICATE LOGIN. With the server, the proxy authenticates using the method
|
||||
chosen by the client if the server supports it (as advertised in the CAPABILITY
|
||||
response); otherwise it falls back to AUTHENTICATE LOGIN, AUTHENTICATE PLAIN or
|
||||
the LOGIN command, in this order of preference. Challenge-response authentication
|
||||
(CRAM-MD5, etc.) is not supported, because it requires a challenge from the server
|
||||
before we know which server to connect to.
|
||||
When running as a 3proxy service (not as a standalone binary), STARTTLS is
|
||||
supported and announced in the CAPABILITY response unless disabled with
|
||||
.BR -x .
|
||||
After the client issues STARTTLS, the connection is handled by
|
||||
.BR tlspr (8):
|
||||
the destination host is taken from the SNI of the client TLS handshake (or from
|
||||
the -h option), the proxy performs STARTTLS negotiation with the destination
|
||||
server, and then transparently passes TLS traffic between the client and the
|
||||
server. If the destination server does not support STARTTLS, the TLS handshake
|
||||
with the client fails.
|
||||
.SH BUGS
|
||||
Report all bugs to
|
||||
.BR 3proxy@3proxy.org
|
||||
.SH SEE ALSO
|
||||
3proxy(8), ftppr(8), pop3p(8), proxy(8), smtpp(8), socks(8), tcppm(8), tlspr(8), udppm(8), syslogd(8),
|
||||
.br
|
||||
https://3proxy.org/
|
||||
.SH AUTHORS
|
||||
3proxy is designed by Vladimir Dubrovin <vlad@3proxy.org>
|
||||
+15
@@ -9,6 +9,7 @@
|
||||
.IB \fR[ -i internal_ip\fR]
|
||||
.IB \fR[ -e external_ip\fR]
|
||||
.IB \fR[ -h default_ip[:port]\fR]
|
||||
.IB \fR[ -x ]
|
||||
.SH DESCRIPTION
|
||||
.B pop3p
|
||||
is POP3 gateway service to allow internal users to access external POP3
|
||||
@@ -66,6 +67,10 @@ Port. Port proxy listens for incoming connections. Default is 110.
|
||||
.B -h
|
||||
Default destination. It's used if the target address is not specified by the user.
|
||||
.TP
|
||||
.B -x
|
||||
Disable STARTTLS (STLS) support. STLS is not announced in the CAPA response
|
||||
and the STLS command is not accepted.
|
||||
.TP
|
||||
.B -l
|
||||
Log. By default logging is to stdout. If
|
||||
.I logfile
|
||||
@@ -94,6 +99,16 @@ is the user\'s login on this POP3 server. The login itself may contain an \'@\'
|
||||
Only cleartext authentication is supported, because challenge-response
|
||||
authentication (APOP, CRAM-MD5, etc.) requires a challenge from the server before
|
||||
we know which server to connect to.
|
||||
When running as a 3proxy service (not as a standalone binary), STLS is
|
||||
supported and announced in the CAPA response unless disabled with
|
||||
.BR -x .
|
||||
After the client issues STLS, the connection is handled by
|
||||
.BR tlspr (8):
|
||||
the destination host is taken from the SNI of the client TLS handshake (or from
|
||||
the -h option), the proxy performs STLS negotiation with the destination
|
||||
server, and then transparently passes TLS traffic between the client and the
|
||||
server. If the destination server does not support STLS, the TLS handshake
|
||||
with the client fails.
|
||||
.SH BUGS
|
||||
Report all bugs to
|
||||
.BR 3proxy@3proxy.org
|
||||
|
||||
+16
-1
@@ -9,6 +9,7 @@
|
||||
.IB \fR[ -i internal_ip\fR]
|
||||
.IB \fR[ -e external_ip\fR]
|
||||
.IB \fR[ -h default_ip[:port]\fR]
|
||||
.IB \fR[ -x ]
|
||||
.SH DESCRIPTION
|
||||
.B smtpp
|
||||
is SMTP gateway service to allow internal users to access external SMTP
|
||||
@@ -61,11 +62,15 @@ syntax (e.g., -iunix:/var/run/smtpp.sock). On Linux, abstract sockets use
|
||||
syntax.
|
||||
.TP
|
||||
.B -p
|
||||
Port. Port proxy listens for incoming connections. Default is 25.
|
||||
Port. Port proxy listens for incoming connections. Default is 587.
|
||||
.TP
|
||||
.B -h
|
||||
Default destination. It's used if the target address is not specified by the user.
|
||||
.TP
|
||||
.B -x
|
||||
Disable STARTTLS support. STARTTLS is not announced in the EHLO response
|
||||
and the STARTTLS command is not accepted.
|
||||
.TP
|
||||
.B -l
|
||||
Log. By default logging is to stdout. If
|
||||
.I logfile
|
||||
@@ -95,6 +100,16 @@ is the user\'s login on this SMTP server. The login itself may contain an \'@\'
|
||||
Only cleartext authentication is supported, because challenge-response
|
||||
authentication (CRAM-MD5, SPA, etc.) requires a challenge from the server before
|
||||
we know which server to connect to.
|
||||
When running as a 3proxy service (not as a standalone binary), STARTTLS is
|
||||
supported and announced in the EHLO response unless disabled with
|
||||
.BR -x .
|
||||
After the client issues STARTTLS, the connection is handled by
|
||||
.BR tlspr (8):
|
||||
the destination host is taken from the SNI of the client TLS handshake (or from
|
||||
the -h option), the proxy performs STARTTLS negotiation with the destination
|
||||
server, and then transparently passes TLS traffic between the client and the
|
||||
server. If the destination server does not support STARTTLS, the TLS handshake
|
||||
with the client fails.
|
||||
.SH BUGS
|
||||
Report all bugs to
|
||||
.BR 3proxy@3proxy.org
|
||||
|
||||
+10
@@ -13,6 +13,7 @@
|
||||
.SH DESCRIPTION
|
||||
.B tlspr
|
||||
is an SNI gateway service (destination host is taken from TLS handshake). The destination port must be specified via the -P option (or it may be detected with the Transparent plugin).
|
||||
tlspr does not support user authentication; use ACLs by client IP or a parent proxy with authentication if access control is required.
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B -I
|
||||
@@ -78,6 +79,15 @@ TLS_CHECK_LEVEL. 0 (default) - allow non-TLS traffic to pass, 1 - require TLS, o
|
||||
.B -s
|
||||
Split the TLS Client HELLO packet across multiple TCP segments to make SNI-based DPI detection harder. An optional numeric value can follow (e.g. \fB-s1\fR) to control the splitting behaviour.
|
||||
.TP
|
||||
.B -Ximap | -Xpop3 | -Xsmtp
|
||||
STARTTLS mode for the given protocol. The proxy speaks the plaintext protocol
|
||||
with the client (greeting, capability advertisement with STARTTLS only, STARTTLS
|
||||
command), then, after the client issues STARTTLS and sends a TLS Client HELLO,
|
||||
connects to the destination taken from SNI (default port 143/110/587), performs
|
||||
STARTTLS negotiation with the destination server and transparently passes TLS
|
||||
traffic. If the destination server does not support STARTTLS, the TLS handshake
|
||||
with the client fails.
|
||||
.TP
|
||||
.B -l
|
||||
Log. By default logging is to stdout. If
|
||||
.I logfile
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[Unit]
|
||||
Description=3proxy tiny proxy server
|
||||
Documentation=man:3proxy(1)
|
||||
Documentation=man:3proxy(8) man:3proxy.cfg(5)
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
@@ -13,8 +13,15 @@ ExecReload=/bin/kill -SIGUSR1 $MAINPID
|
||||
KillMode=process
|
||||
Restart=on-failure
|
||||
RestartSec=60s
|
||||
LimitNOFILE=65536
|
||||
LimitNPROC=32768
|
||||
# 3proxy uses one thread and two descriptors per connection (four for ftppr),
|
||||
# so it reaches these limits much earlier than event driven servers. They are
|
||||
# ceilings only: the actual number of connections is governed by 'maxconn' in
|
||||
# the configuration file. TasksMax must be set explicitly, systemd's
|
||||
# DefaultTasksMax (15% of kernel.threads-max, e.g. ~9000) otherwise caps the
|
||||
# number of threads, and thus connections, regardless of LimitNPROC.
|
||||
LimitNOFILE=1048576
|
||||
LimitNPROC=infinity
|
||||
TasksMax=infinity
|
||||
RuntimeDirectory=3proxy
|
||||
RuntimeDirectoryMode=0755
|
||||
|
||||
|
||||
@@ -24,9 +24,19 @@ if [ -f /etc/init.d/functions ]; then
|
||||
. /etc/init.d/functions
|
||||
fi
|
||||
|
||||
# SysV init does not apply limits.conf consistently: start-stop-daemon does not
|
||||
# open a PAM session, so pam_limits is not involved and the daemon inherits the
|
||||
# limits of init. 3proxy needs two descriptors per connection (four for ftppr),
|
||||
# so raise them here. Adjust to match 'maxconn' in the configuration file.
|
||||
set_limits() {
|
||||
ulimit -n 65536 2>/dev/null || ulimit -n 4096 2>/dev/null || true
|
||||
ulimit -u 32768 2>/dev/null || true
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
echo -n "Starting 3Proxy: "
|
||||
set_limits
|
||||
|
||||
if [ ! -d /var/run/3proxy ]; then
|
||||
mkdir -p /var/run/3proxy
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Name: 3proxy
|
||||
Version: 0.9.7
|
||||
Version: 0.9.8
|
||||
Release: 1%{?dist}
|
||||
Summary: 3proxy tiny proxy server
|
||||
License: GPL/LGPL/Apache/BSD
|
||||
@@ -34,6 +34,7 @@ make clean
|
||||
/bin/3proxy
|
||||
/bin/3proxy_crypt
|
||||
/bin/3proxy_ftppr
|
||||
/bin/3proxy_imapp
|
||||
/bin/3proxy_pop3p
|
||||
/bin/3proxy_proxy
|
||||
/bin/3proxy_smtpp
|
||||
|
||||
+2
-6
@@ -519,15 +519,10 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int
|
||||
#ifndef NORADIUS
|
||||
_3proxy_mutex_init(&rad_mutex);
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
conf.threadinit = CreateSemaphore(NULL, 1, 1, NULL);
|
||||
if(!conf.threadinit){
|
||||
if(_3proxy_sem_init(conf.threadinit, 1, 1)){
|
||||
fprintf(stderr, "semaphore init failed\n");
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
_3proxy_mutex_init(&conf.threadinit);
|
||||
#endif
|
||||
|
||||
#ifdef WITH_SSL
|
||||
ssl_install();
|
||||
@@ -537,6 +532,7 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int
|
||||
#endif
|
||||
|
||||
freeconf(&conf);
|
||||
initcommands();
|
||||
res = readconfig(fp);
|
||||
conf.version++;
|
||||
|
||||
|
||||
+45
-100
@@ -5,14 +5,7 @@
|
||||
please read License Agreement
|
||||
|
||||
*/
|
||||
#include "libs/blake2.h"
|
||||
#ifdef WITH_SSL
|
||||
#include <openssl/evp.h>
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
#include <openssl/params.h>
|
||||
#include <openssl/core_names.h>
|
||||
#endif
|
||||
#endif
|
||||
#include "mdhash.h"
|
||||
#include <string.h>
|
||||
|
||||
#define MD5_SIZE 16
|
||||
@@ -28,11 +21,6 @@ static unsigned char itoa64[] =
|
||||
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
|
||||
#if defined(WITH_SSL) && OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
EVP_MD *md4_hash = NULL;
|
||||
EVP_MD *md5_hash = NULL;
|
||||
#endif
|
||||
|
||||
void
|
||||
_crypt_to64(unsigned char *s, unsigned long v, int n)
|
||||
{
|
||||
@@ -43,21 +31,13 @@ _crypt_to64(unsigned char *s, unsigned long v, int n)
|
||||
}
|
||||
|
||||
|
||||
#ifdef WITH_SSL
|
||||
unsigned char * ntpwdhash (unsigned char *szHash, const unsigned char *szPassword, int ctohex)
|
||||
{
|
||||
unsigned char szUnicodePass[513];
|
||||
unsigned int nPasswordLen;
|
||||
EVP_MD_CTX *ctx;
|
||||
unsigned int len=sizeof(szUnicodePass);
|
||||
unsigned int len = 16;
|
||||
unsigned int i;
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
const EVP_MD *md4 = md4_hash;
|
||||
#else
|
||||
const EVP_MD *md4 = EVP_md4();
|
||||
#endif
|
||||
if(md4 == NULL) return NULL;
|
||||
mdh_ctx *ctx;
|
||||
|
||||
/*
|
||||
* NT passwords are unicode. Convert plain text password
|
||||
@@ -71,15 +51,14 @@ unsigned char * ntpwdhash (unsigned char *szHash, const unsigned char *szPasswor
|
||||
}
|
||||
|
||||
/* Encrypt Unicode password to a 16-byte MD4 hash */
|
||||
ctx = EVP_MD_CTX_new();
|
||||
ctx = mdh_init(MDH_MD4, 16);
|
||||
if(!ctx) return NULL;
|
||||
if(!EVP_DigestInit_ex(ctx, md4, NULL)){
|
||||
EVP_MD_CTX_free(ctx);
|
||||
return NULL;
|
||||
mdh_update(ctx, szUnicodePass, (nPasswordLen<<1));
|
||||
if(!mdh_final(ctx, szUnicodePass, &len)) {
|
||||
mdh_free(ctx);
|
||||
return NULL;
|
||||
}
|
||||
EVP_DigestUpdate(ctx, szUnicodePass, (nPasswordLen<<1));
|
||||
EVP_DigestFinal_ex(ctx, szUnicodePass, &len);
|
||||
EVP_MD_CTX_free(ctx);
|
||||
mdh_free(ctx);
|
||||
if (ctohex){
|
||||
tohex(szUnicodePass, szHash, 16);
|
||||
}
|
||||
@@ -87,7 +66,6 @@ unsigned char * ntpwdhash (unsigned char *szHash, const unsigned char *szPasswor
|
||||
memset(szUnicodePass, 0, sizeof szUnicodePass);
|
||||
return szHash;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
unsigned char * mycrypt(const unsigned char *pw, const unsigned char *salt, unsigned char *passwd){
|
||||
@@ -100,57 +78,44 @@ unsigned char * mycrypt(const unsigned char *pw, const unsigned char *salt, unsi
|
||||
int sl;
|
||||
unsigned long l;
|
||||
|
||||
#if defined(WITH_SSL)
|
||||
#ifndef WITHMAIN
|
||||
if(salt[0] == '$' && salt[1] == '1' && salt[2] == '$' && (ep = (unsigned char *)strchr((char *)salt+3, '$'))) {
|
||||
EVP_MD_CTX *ctx, *ctx1;
|
||||
unsigned int len;
|
||||
mdh_ctx *ctx, *ctx1;
|
||||
unsigned int len = MD5_SIZE;
|
||||
int pl, i;
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
const EVP_MD *md5 = md5_hash;
|
||||
#else
|
||||
const EVP_MD *md5 = EVP_md5();
|
||||
#endif
|
||||
if(md5 == NULL) {
|
||||
*passwd = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sp = salt +3;
|
||||
sl = (int)(ep - sp);
|
||||
magic = (unsigned char *)"$1$";
|
||||
|
||||
ctx = EVP_MD_CTX_new();
|
||||
ctx = mdh_init(MDH_MD5, 16);
|
||||
if(!ctx) {
|
||||
*passwd = 0;
|
||||
return NULL;
|
||||
}
|
||||
EVP_DigestInit_ex(ctx, md5, NULL);
|
||||
|
||||
/* The password first, since that is what is most unknown */
|
||||
EVP_DigestUpdate(ctx,pw,strlen((char *)pw));
|
||||
mdh_update(ctx, pw, (unsigned int)strlen((char *)pw));
|
||||
|
||||
/* Then our magic string */
|
||||
EVP_DigestUpdate(ctx,magic,strlen((char *)magic));
|
||||
mdh_update(ctx, magic, (unsigned int)strlen((char *)magic));
|
||||
|
||||
/* Then the raw salt */
|
||||
EVP_DigestUpdate(ctx,sp,sl);
|
||||
mdh_update(ctx, sp, (unsigned int)sl);
|
||||
|
||||
/* Then just as many unsigned characters of the MD5(pw,salt,pw) */
|
||||
ctx1 = EVP_MD_CTX_new();
|
||||
ctx1 = mdh_init(MDH_MD5, 16);
|
||||
if(!ctx1) {
|
||||
EVP_MD_CTX_free(ctx);
|
||||
mdh_free(ctx);
|
||||
*passwd = 0;
|
||||
return NULL;
|
||||
}
|
||||
EVP_DigestInit_ex(ctx1, md5, NULL);
|
||||
EVP_DigestUpdate(ctx1,pw,strlen((char *)pw));
|
||||
EVP_DigestUpdate(ctx1,sp,sl);
|
||||
EVP_DigestUpdate(ctx1,pw,strlen((char *)pw));
|
||||
EVP_DigestFinal_ex(ctx1,final,&len);
|
||||
mdh_update(ctx1, pw, (unsigned int)strlen((char *)pw));
|
||||
mdh_update(ctx1, sp, (unsigned int)sl);
|
||||
mdh_update(ctx1, pw, (unsigned int)strlen((char *)pw));
|
||||
mdh_final(ctx1, final, &len);
|
||||
for(pl = (int)strlen((char *)pw); pl > 0; pl -= MD5_SIZE)
|
||||
EVP_DigestUpdate(ctx,final,pl>MD5_SIZE ? MD5_SIZE : pl);
|
||||
mdh_update(ctx, final, (unsigned int)(pl>MD5_SIZE ? MD5_SIZE : pl));
|
||||
|
||||
/* Don't leave anything around in vm they could use. */
|
||||
memset(final,0,sizeof final);
|
||||
@@ -158,13 +123,13 @@ unsigned char * mycrypt(const unsigned char *pw, const unsigned char *salt, unsi
|
||||
/* Then something really weird... */
|
||||
for (i = (int)strlen((char *)pw); i ; i >>= 1)
|
||||
if(i&1)
|
||||
EVP_DigestUpdate(ctx, final, 1);
|
||||
mdh_update(ctx, final, 1);
|
||||
else
|
||||
EVP_DigestUpdate(ctx, pw, 1);
|
||||
mdh_update(ctx, pw, 1);
|
||||
|
||||
|
||||
EVP_DigestFinal_ex(ctx,final,&len);
|
||||
EVP_MD_CTX_free(ctx);
|
||||
mdh_final(ctx, final, &len);
|
||||
mdh_free(ctx);
|
||||
|
||||
/*
|
||||
* and now, just to make sure things don't run too fast
|
||||
@@ -172,43 +137,46 @@ unsigned char * mycrypt(const unsigned char *pw, const unsigned char *salt, unsi
|
||||
* need 30 seconds to build a 1000 entry dictionary...
|
||||
*/
|
||||
for(i=0;i<1000;i++) {
|
||||
EVP_MD_CTX_reset(ctx1);
|
||||
EVP_DigestInit_ex(ctx1, md5, NULL);
|
||||
mdh_free(ctx1);
|
||||
ctx1 = mdh_init(MDH_MD5, 16);
|
||||
if(!ctx1) { *passwd = 0; return NULL; }
|
||||
if(i & 1)
|
||||
EVP_DigestUpdate(ctx1,pw,strlen((char *)pw));
|
||||
mdh_update(ctx1, pw, (unsigned int)strlen((char *)pw));
|
||||
else
|
||||
EVP_DigestUpdate(ctx1,final,MD5_SIZE);
|
||||
mdh_update(ctx1, final, MD5_SIZE);
|
||||
|
||||
if(i % 3)
|
||||
EVP_DigestUpdate(ctx1,sp,sl);
|
||||
mdh_update(ctx1, sp, (unsigned int)sl);
|
||||
|
||||
if(i % 7)
|
||||
EVP_DigestUpdate(ctx1,pw,strlen((char *)pw));
|
||||
mdh_update(ctx1, pw, (unsigned int)strlen((char *)pw));
|
||||
|
||||
if(i & 1)
|
||||
EVP_DigestUpdate(ctx1,final,MD5_SIZE);
|
||||
mdh_update(ctx1, final, MD5_SIZE);
|
||||
else
|
||||
EVP_DigestUpdate(ctx1,pw,strlen((char *)pw));
|
||||
EVP_DigestFinal_ex(ctx1,final,&len);
|
||||
mdh_update(ctx1, pw, (unsigned int)strlen((char *)pw));
|
||||
mdh_final(ctx1, final, &len);
|
||||
}
|
||||
EVP_MD_CTX_free(ctx1);
|
||||
mdh_free(ctx1);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#endif
|
||||
if(salt[0] == '$' && salt[1] == '3' && salt[2] == '$' && (ep = (unsigned char *)strchr((char *)salt+3, '$'))) {
|
||||
sp = salt +3;
|
||||
sl = (int)(ep - sp);
|
||||
magic = (unsigned char *)"$3$";
|
||||
{
|
||||
blake2b_state S;
|
||||
if(blake2b_init(&S, MD5_SIZE) != 0 ||
|
||||
blake2b_update(&S, pw, strlen((char *)pw) + 1) != 0 ||
|
||||
blake2b_update(&S, sp, sl) != 0 ||
|
||||
blake2b_final(&S, final, MD5_SIZE) != 0) {
|
||||
mdh_ctx *bctx = mdh_init(MDH_BLAKE2, MD5_SIZE);
|
||||
unsigned int blen = MD5_SIZE;
|
||||
if(!bctx ||
|
||||
!mdh_update(bctx, pw, (unsigned int)(strlen((char *)pw) + 1)) ||
|
||||
!mdh_update(bctx, sp, (unsigned int)sl) ||
|
||||
!mdh_final(bctx, final, &blen)) {
|
||||
mdh_free(bctx);
|
||||
*passwd = 0;
|
||||
return NULL;
|
||||
}
|
||||
mdh_free(bctx);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -238,9 +206,6 @@ unsigned char * mycrypt(const unsigned char *pw, const unsigned char *salt, unsi
|
||||
}
|
||||
|
||||
#ifdef WITHMAIN
|
||||
#if defined(WITH_SSL) && OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
#include <openssl/provider.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
int main(int argc, char* argv[]){
|
||||
unsigned char buf1[128];
|
||||
@@ -248,37 +213,17 @@ int main(int argc, char* argv[]){
|
||||
unsigned i;
|
||||
if(argc < 2 || argc > 3) {
|
||||
fprintf(stderr, "usage: \n"
|
||||
#ifdef WITH_SSL
|
||||
"\t%s <password>\n"
|
||||
#endif
|
||||
"\t%s <salt> <password>\n"
|
||||
#ifdef WITH_SSL
|
||||
"Performs NT crypt if no salt specified, BLAKE2 crypt with salt\n"
|
||||
#else
|
||||
"Performs BLAKE2 crypt with salt\n"
|
||||
#endif
|
||||
,
|
||||
#ifdef WITH_SSL
|
||||
argv[0],
|
||||
#endif
|
||||
argv[0]);
|
||||
return 1;
|
||||
}
|
||||
#if defined(WITH_SSL) && OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
OSSL_PROVIDER_load(NULL, "legacy");
|
||||
OSSL_PROVIDER_load(NULL, "default");
|
||||
md4_hash = EVP_MD_fetch(NULL, "MD4", NULL);
|
||||
if (md4_hash == NULL) {
|
||||
fprintf(stderr, "Error fetching MD4\n");
|
||||
}
|
||||
#endif
|
||||
if(argc == 2) {
|
||||
#ifdef WITH_SSL
|
||||
{ unsigned char *nt = ntpwdhash(buf1, (unsigned char *)argv[1], 1);
|
||||
if(nt) printf("NT:%s\n", nt); }
|
||||
#else
|
||||
fprintf(stderr, "NT crypt not available (compiled without OpenSSL)\n");
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
unsigned char *cr;
|
||||
|
||||
+26
-8
@@ -2,7 +2,7 @@
|
||||
# 3 proxy common Makefile
|
||||
#
|
||||
|
||||
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
|
||||
all: $(BUILDDIR)3proxy$(EXESUFFICS) $(BUILDDIR)$(CRYPT_PREFIX)crypt$(EXESUFFICS) $(BUILDDIR)$(PREFIX)pop3p$(EXESUFFICS) $(BUILDDIR)$(PREFIX)imapp$(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
|
||||
@@ -31,6 +31,9 @@ proxy$(OBJSUFFICS): proxy.c proxy.h structures.h proxymain.c
|
||||
pop3p$(OBJSUFFICS): pop3p.c proxy.h structures.h proxymain.c
|
||||
$(CC) $(CFLAGS) $(DEFINEOPTION)WITHMAIN $(DEFINEOPTION)NOPORTMAP $(DEFINEOPTION)NOUDPMAIN pop3p.c
|
||||
|
||||
imapp$(OBJSUFFICS): imapp.c proxy.h structures.h proxymain.c
|
||||
$(CC) $(CFLAGS) $(DEFINEOPTION)WITHMAIN $(DEFINEOPTION)NOPORTMAP $(DEFINEOPTION)NOUDPMAIN imapp.c
|
||||
|
||||
smtpp$(OBJSUFFICS): smtpp.c proxy.h structures.h proxymain.c
|
||||
$(CC) $(CFLAGS) $(DEFINEOPTION)WITHMAIN $(DEFINEOPTION)NOPORTMAP $(DEFINEOPTION)NOUDPMAIN smtpp.c
|
||||
|
||||
@@ -59,6 +62,9 @@ $(BUILDDIR)$(PREFIX)proxy$(EXESUFFICS): sockmap$(OBJSUFFICS) proxy$(OBJSUFFICS)
|
||||
$(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)$(PREFIX)imapp$(EXESUFFICS): sockmap$(OBJSUFFICS) imapp$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) log$(OBJSUFFICS) base64$(OBJSUFFICS) $(COMPATLIBS)
|
||||
$(LN) $(LNOUT)$(BUILDDIR)$(PREFIX)imapp$(EXESUFFICS) $(LDFLAGS) sockmap$(OBJSUFFICS) imapp$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) log$(OBJSUFFICS) common$(OBJSUFFICS) base64$(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)
|
||||
|
||||
@@ -86,6 +92,9 @@ srvproxy$(OBJSUFFICS): proxy.c proxy.h structures.h
|
||||
srvpop3p$(OBJSUFFICS): pop3p.c proxy.h structures.h
|
||||
$(CC) $(COUT)srvpop3p$(OBJSUFFICS) $(CFLAGS) pop3p.c
|
||||
|
||||
srvimapp$(OBJSUFFICS): imapp.c proxy.h structures.h
|
||||
$(CC) $(COUT)srvimapp$(OBJSUFFICS) $(CFLAGS) imapp.c
|
||||
|
||||
srvsmtpp$(OBJSUFFICS): smtpp.c proxy.h structures.h
|
||||
$(CC) $(COUT)srvsmtpp$(OBJSUFFICS) $(CFLAGS) smtpp.c
|
||||
|
||||
@@ -134,7 +143,7 @@ hashtables$(OBJSUFFICS): hashtables.c proxy.h structures.h libs/blake2.h
|
||||
resolve$(OBJSUFFICS): resolve.c proxy.h structures.h
|
||||
$(CC) $(COUT)resolve$(OBJSUFFICS) $(CFLAGS) resolve.c
|
||||
|
||||
authradius$(OBJSUFFICS): authradius.c proxy.h structures.h
|
||||
authradius$(OBJSUFFICS): authradius.c proxy.h structures.h mdhash.h
|
||||
$(CC) $(COUT)authradius$(OBJSUFFICS) $(CFLAGS) authradius.c
|
||||
|
||||
conf$(OBJSUFFICS): conf.c proxy.h structures.h
|
||||
@@ -146,17 +155,26 @@ log$(OBJSUFFICS): log.c proxy.h structures.h
|
||||
datatypes$(OBJSUFFICS): datatypes.c proxy.h structures.h
|
||||
$(CC) $(COUT)datatypes$(OBJSUFFICS) $(CFLAGS) datatypes.c
|
||||
|
||||
3proxy_crypt$(OBJSUFFICS): 3proxy_crypt.c libs/blake2.h
|
||||
3proxy_crypt$(OBJSUFFICS): 3proxy_crypt.c libs/blake2.h mdhash.h
|
||||
$(CC) $(COUT)3proxy_crypt$(OBJSUFFICS) $(CFLAGS) 3proxy_crypt.c
|
||||
|
||||
3proxy_cryptmain$(OBJSUFFICS): 3proxy_crypt.c libs/blake2.h
|
||||
3proxy_cryptmain$(OBJSUFFICS): 3proxy_crypt.c libs/blake2.h mdhash.h
|
||||
$(CC) $(COUT)3proxy_cryptmain$(OBJSUFFICS) $(CFLAGS) $(DEFINEOPTION)WITHMAIN 3proxy_crypt.c
|
||||
|
||||
blake2$(OBJSUFFICS): libs/blake2b-ref.c
|
||||
$(CC) $(COUT)blake2$(OBJSUFFICS) $(CFLAGS) libs/blake2b-ref.c
|
||||
|
||||
$(BUILDDIR)$(CRYPT_PREFIX)crypt$(EXESUFFICS): blake2$(OBJSUFFICS) 3proxy_cryptmain$(OBJSUFFICS) base64$(OBJSUFFICS)
|
||||
$(LN) $(LNOUT)$(BUILDDIR)$(CRYPT_PREFIX)crypt$(EXESUFFICS) $(LDFLAGS) blake2$(OBJSUFFICS) base64$(OBJSUFFICS) 3proxy_cryptmain$(OBJSUFFICS) $(LIBS)
|
||||
mdhash$(OBJSUFFICS): mdhash.c mdhash.h proxy.h structures.h
|
||||
$(CC) $(COUT)mdhash$(OBJSUFFICS) $(CFLAGS) mdhash.c
|
||||
|
||||
md4$(OBJSUFFICS): libs/md4.c libs/md4.h
|
||||
$(CC) $(COUT)md4$(OBJSUFFICS) $(CFLAGS) libs/md4.c
|
||||
|
||||
md5$(OBJSUFFICS): libs/md5.c libs/md5.h
|
||||
$(CC) $(COUT)md5$(OBJSUFFICS) $(CFLAGS) libs/md5.c
|
||||
|
||||
$(BUILDDIR)$(CRYPT_PREFIX)crypt$(EXESUFFICS): md4$(OBJSUFFICS) md5$(OBJSUFFICS) blake2$(OBJSUFFICS) 3proxy_cryptmain$(OBJSUFFICS) base64$(OBJSUFFICS) mdhash$(OBJSUFFICS)
|
||||
$(LN) $(LNOUT)$(BUILDDIR)$(CRYPT_PREFIX)crypt$(EXESUFFICS) $(LDFLAGS) md4$(OBJSUFFICS) md5$(OBJSUFFICS) blake2$(OBJSUFFICS) base64$(OBJSUFFICS) mdhash$(OBJSUFFICS) 3proxy_cryptmain$(OBJSUFFICS) $(LIBS)
|
||||
|
||||
stringtable$(OBJSUFFICS): stringtable.c
|
||||
$(CC) $(COUT)stringtable$(OBJSUFFICS) $(CFLAGS) stringtable.c
|
||||
@@ -170,6 +188,6 @@ ssl$(OBJSUFFICS): ssl.c structures.h proxy.h ssl.h
|
||||
pcre$(OBJSUFFICS): pcre.c structures.h
|
||||
$(CC) $(COUT)pcre$(OBJSUFFICS) $(CFLAGS) $(DEFINEOPTION)WITH_PCRE pcre.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) udpsockmap$(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) blake2$(OBJSUFFICS) 3proxy_crypt$(OBJSUFFICS) base64$(OBJSUFFICS) ftp$(OBJSUFFICS) stringtable$(OBJSUFFICS) srvwebadmin$(OBJSUFFICS) srvdnspr$(OBJSUFFICS) plugins$(OBJSUFFICS) $(SSL_OBJS) $(PCRE_OBJS) $(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) udpsockmap$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) log$(OBJSUFFICS) 3proxy_crypt$(OBJSUFFICS) blake2$(OBJSUFFICS) base64$(OBJSUFFICS) ftp$(OBJSUFFICS) stringtable$(OBJSUFFICS) srvwebadmin$(OBJSUFFICS) srvdnspr$(OBJSUFFICS) plugins$(OBJSUFFICS) $(SSL_OBJS) $(PCRE_OBJS) $(COMPATLIBS) $(LIBS) $(PCRE_LIBS)
|
||||
$(BUILDDIR)3proxy$(EXESUFFICS): 3proxy$(OBJSUFFICS) mainfunc$(OBJSUFFICS) srvproxy$(OBJSUFFICS) srvpop3p$(OBJSUFFICS) srvimapp$(OBJSUFFICS) srvsmtpp$(OBJSUFFICS) srvftppr$(OBJSUFFICS) srvsocks$(OBJSUFFICS) srvtcppm$(OBJSUFFICS) srvtlspr$(OBJSUFFICS) srvauto$(OBJSUFFICS) srvudppm$(OBJSUFFICS) sockmap$(OBJSUFFICS) udpsockmap$(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) mdhash$(OBJSUFFICS) $(SSL_OBJS) $(PCRE_OBJS) $(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) srvimapp$(OBJSUFFICS) srvsmtpp$(OBJSUFFICS) srvftppr$(OBJSUFFICS) srvsocks$(OBJSUFFICS) srvtcppm$(OBJSUFFICS) srvtlspr$(OBJSUFFICS) srvudppm$(OBJSUFFICS) sockmap$(OBJSUFFICS) udpsockmap$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) log$(OBJSUFFICS) 3proxy_crypt$(OBJSUFFICS) md4$(OBJSUFFICS) md5$(OBJSUFFICS) blake2$(OBJSUFFICS) base64$(OBJSUFFICS) ftp$(OBJSUFFICS) stringtable$(OBJSUFFICS) srvwebadmin$(OBJSUFFICS) srvdnspr$(OBJSUFFICS) plugins$(OBJSUFFICS) mdhash$(OBJSUFFICS) $(SSL_OBJS) $(PCRE_OBJS) $(COMPATLIBS) $(LIBS) $(PCRE_LIBS)
|
||||
|
||||
@@ -99,7 +99,7 @@ int ACLmatches(struct ace* acentry, struct clientparam * param){
|
||||
ntohs(*SAPORT(¶m->req)) <= portentry->endport) {
|
||||
break;
|
||||
}
|
||||
if(!portentry) return 0;
|
||||
if(!portentry) return 0;
|
||||
}
|
||||
if(acentry->wdays){
|
||||
if(!(acentry -> wdays & wday)) return 0;
|
||||
@@ -110,7 +110,7 @@ int ACLmatches(struct ace* acentry, struct clientparam * param){
|
||||
if(start_time >= periodentry->fromtime && start_time < periodentry->totime){
|
||||
break;
|
||||
}
|
||||
if(!periodentry) return 0;
|
||||
if(!periodentry) return 0;
|
||||
}
|
||||
if(acentry->users){
|
||||
for(userentry = acentry->users; userentry; userentry = userentry->next)
|
||||
|
||||
+36
-14
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
#include "proxy.h"
|
||||
#include "libs/blake2.h"
|
||||
#include "mdhash.h"
|
||||
|
||||
void initbandlims(struct clientparam *param);
|
||||
|
||||
@@ -80,7 +80,7 @@ int cacheauth(struct clientparam * param){
|
||||
((type & 4) && !param->password) ||
|
||||
(
|
||||
(type & 1) && *SAFAMILY(¶m->sincr) != AF_INET
|
||||
#ifndef NOIPv6
|
||||
#ifndef NOIPV6
|
||||
&& *SAFAMILY(¶m->sincr) != AF_INET6
|
||||
#endif
|
||||
) || (!hashresolv(&auth_table, param, &ac, &ttl))) {
|
||||
@@ -108,7 +108,6 @@ int cacheauth(struct clientparam * param){
|
||||
int doauth(struct clientparam * param){
|
||||
int res = 0;
|
||||
struct auth *authfuncs;
|
||||
char * tmp;
|
||||
int ret = 0;
|
||||
|
||||
for(authfuncs=param->srv->authfuncs; authfuncs; authfuncs=authfuncs->next){
|
||||
@@ -125,7 +124,7 @@ int doauth(struct clientparam * param){
|
||||
ac.username[63] = 0;
|
||||
}
|
||||
if(*SAFAMILY(¶m->sincr) == AF_INET
|
||||
#ifndef NOIPv6
|
||||
#ifndef NOIPV6
|
||||
|| *SAFAMILY(¶m->sincr) == AF_INET6
|
||||
#endif
|
||||
) {
|
||||
@@ -134,7 +133,7 @@ int doauth(struct clientparam * param){
|
||||
}
|
||||
|
||||
if(*SAFAMILY(¶m->sinsl) == AF_INET
|
||||
#ifndef NOIPv6
|
||||
#ifndef NOIPV6
|
||||
|| *SAFAMILY(¶m->sinsl) == AF_INET6
|
||||
#endif
|
||||
) {
|
||||
@@ -216,8 +215,25 @@ int dnsauth(struct clientparam * param){
|
||||
return param->username? 0:3;
|
||||
}
|
||||
|
||||
static int ctmemcmp(const void *a, const void *b, size_t len){
|
||||
const unsigned char *pa = (const unsigned char *)a, *pb = (const unsigned char *)b;
|
||||
unsigned char diff = 0;
|
||||
size_t i;
|
||||
for(i = 0; i < len; i++) diff |= (unsigned char)(pa[i] ^ pb[i]);
|
||||
return diff;
|
||||
}
|
||||
|
||||
static int ctstrcmp(const char *a, const char *b, size_t maxlen){
|
||||
unsigned char diff = 0;
|
||||
size_t i;
|
||||
for(i = 0; i < maxlen; i++){
|
||||
diff |= (unsigned char)((unsigned char)a[i] ^ (unsigned char)b[i]);
|
||||
if(!a[i] && !b[i]) break;
|
||||
}
|
||||
return diff;
|
||||
}
|
||||
|
||||
int strongauth(struct clientparam * param){
|
||||
static char dummy;
|
||||
unsigned char buf[256];
|
||||
char pass[256] = {0};
|
||||
|
||||
@@ -229,27 +245,33 @@ int strongauth(struct clientparam * param){
|
||||
int pwlen = strlen((char *)param->password);
|
||||
if(pwlen > 255) pwlen = 255;
|
||||
if((unsigned)pwlen < pwl_table.recsize) {
|
||||
if(!strncmp(pass + 1, (char *)param->password, pwl_table.recsize - 1)) return 0;
|
||||
memset(buf, 0, pwl_table.recsize - 1);
|
||||
memcpy(buf, param->password, pwlen);
|
||||
if(!ctmemcmp(pass + 1, buf, pwl_table.recsize - 1)) return 0;
|
||||
} else {
|
||||
blake2b_state S;
|
||||
mdh_ctx *bctx;
|
||||
unsigned hashsz;
|
||||
unsigned int blen;
|
||||
hashsz = pwl_table.recsize - 1 < 64 ? pwl_table.recsize - 1 : 64;
|
||||
memset(buf, 0, pwl_table.recsize - 1);
|
||||
blake2b_init(&S, hashsz);
|
||||
blake2b_update(&S, param->password, pwlen + 1);
|
||||
blake2b_final(&S, buf, hashsz);
|
||||
if(!memcmp(pass + 1, buf, pwl_table.recsize - 1)) return 0;
|
||||
bctx = mdh_init(MDH_BLAKE2, hashsz);
|
||||
if(!bctx) return 6;
|
||||
mdh_update(bctx, param->password, pwlen + 1);
|
||||
blen = hashsz;
|
||||
mdh_final(bctx, buf, &blen);
|
||||
mdh_free(bctx);
|
||||
if(!ctmemcmp(pass + 1, buf, pwl_table.recsize - 1)) return 0;
|
||||
}
|
||||
return 6;
|
||||
}
|
||||
case CR:
|
||||
if (mycrypt(param->password, (unsigned char *)pass + 1, buf) &&
|
||||
!strcmp(pass + 1, (char *)buf))
|
||||
!ctstrcmp(pass + 1, (char *)buf, sizeof(pass) - 1))
|
||||
return 0;
|
||||
else return 7;
|
||||
#ifdef WITH_SSL
|
||||
case NT:
|
||||
if(ntpwdhash(buf, param->password, 1) && !strcmp(pass + 1, (char *)buf)) return 0;
|
||||
if(ntpwdhash(buf, param->password, 1) && !ctstrcmp(pass + 1, (char *)buf, sizeof(pass) - 1)) return 0;
|
||||
else return 8;
|
||||
#endif
|
||||
default:
|
||||
|
||||
+9
-31
@@ -8,7 +8,7 @@
|
||||
|
||||
#ifndef NORADIUS
|
||||
#include "proxy.h"
|
||||
#include <openssl/evp.h>
|
||||
#include "mdhash.h"
|
||||
|
||||
#define AUTH_VECTOR_LEN 16
|
||||
#define MAX_STRING_LEN 254
|
||||
@@ -174,36 +174,15 @@ void md5_calc(unsigned char *output, unsigned char *input,
|
||||
unsigned int inputlen);
|
||||
|
||||
|
||||
char *strNcpy(char *dest, const char *src, int n)
|
||||
{
|
||||
if (n > 0)
|
||||
strncpy(dest, src, n);
|
||||
else
|
||||
n = 1;
|
||||
dest[n - 1] = 0;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
extern EVP_MD *md4_hash;
|
||||
extern EVP_MD *md5_hash;
|
||||
#endif
|
||||
|
||||
|
||||
void md5_calc(unsigned char *output, unsigned char *input,
|
||||
unsigned int inlen)
|
||||
{
|
||||
EVP_MD_CTX *ctx = EVP_MD_CTX_new();
|
||||
unsigned int len = 0;
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
EVP_DigestInit_ex(ctx, md5_hash, NULL);
|
||||
#else
|
||||
EVP_DigestInit_ex(ctx, EVP_md5(), NULL);
|
||||
#endif
|
||||
EVP_DigestUpdate(ctx, input, inlen);
|
||||
EVP_DigestFinal_ex(ctx, output, &len);
|
||||
EVP_MD_CTX_free(ctx);
|
||||
mdh_ctx *ctx = mdh_init(MDH_MD5, 16);
|
||||
unsigned int len = 16;
|
||||
if(!ctx) return;
|
||||
mdh_update(ctx, input, inlen);
|
||||
mdh_final(ctx, output, &len);
|
||||
mdh_free(ctx);
|
||||
}
|
||||
|
||||
|
||||
@@ -318,14 +297,12 @@ int radsend(struct clientparam * param, int auth, int stop){
|
||||
unsigned char *ptr;
|
||||
int total_length;
|
||||
int len;
|
||||
int op;
|
||||
PROXYSOCKADDRTYPE saremote;
|
||||
struct pollfd fds[1];
|
||||
char vector[AUTH_VECTOR_LEN];
|
||||
radius_packet_t packet, rpacket;
|
||||
SASIZETYPE salen;
|
||||
int data_len;
|
||||
uint8_t *vendor_len;
|
||||
int count=0;
|
||||
uint8_t *attr;
|
||||
long vendor=0;
|
||||
@@ -401,6 +378,7 @@ int radsend(struct clientparam * param, int auth, int stop){
|
||||
if(conf.stringtable){
|
||||
*ptr++ = PW_NAS_IDENTIFIER;
|
||||
len = strlen((char *)conf.stringtable[SERVICES+param->service]);
|
||||
if(len > 253) len = 253;
|
||||
*ptr++ = (2 + len);
|
||||
memcpy(ptr, conf.stringtable[SERVICES+param->service], len);
|
||||
ptr += len;
|
||||
@@ -426,6 +404,7 @@ int radsend(struct clientparam * param, int auth, int stop){
|
||||
if(param->hostname){
|
||||
*ptr++ = PW_CALLED_STATION_ID;
|
||||
len = strlen((char *)param->hostname);
|
||||
if(len > 253) len = 253;
|
||||
*ptr++ = (2 + len);
|
||||
memcpy(ptr, param->hostname, len);
|
||||
ptr += len;
|
||||
@@ -621,7 +600,6 @@ int radsend(struct clientparam * param, int auth, int stop){
|
||||
|
||||
attr = rpacket.data;
|
||||
count = total_length - 20;
|
||||
vendor_len = 0;
|
||||
|
||||
while (count >= 2) {
|
||||
if (!vendor && attr[0] == 0) {
|
||||
|
||||
+4
-3
@@ -21,16 +21,17 @@ void * autochild(struct clientparam* param) {
|
||||
if (len != 1){
|
||||
param->res = 801;
|
||||
dolog(param, (unsigned char *)"");
|
||||
return 0;
|
||||
}
|
||||
if(*param->clibuf == 4 || *param->clibuf == 5) {
|
||||
param->service = S_SOCKS;
|
||||
return sockschild(param);
|
||||
return (void *)sockschild;
|
||||
}
|
||||
if(*param->clibuf == 22) {
|
||||
param->service = S_TLSPR;
|
||||
return tlsprchild(param);
|
||||
return (void *)tlsprchild;
|
||||
}
|
||||
param->service = S_PROXY;
|
||||
return proxychild(param);
|
||||
return (void *)proxychild;
|
||||
}
|
||||
|
||||
+79
-22
@@ -17,6 +17,8 @@ char * copyright = COPYRIGHT;
|
||||
# define MYRAND_ARC4RANDOM 1
|
||||
#elif defined(__GLIBC__) && ((__GLIBC__ > 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 36)))
|
||||
# define MYRAND_ARC4RANDOM 1
|
||||
#elif defined(__GLIBC__) && ((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 25)))
|
||||
# define MYRAND_FALLBACK 1
|
||||
#elif defined(__linux__)
|
||||
# define MYRAND_GETRANDOM 1
|
||||
# include <sys/random.h>
|
||||
@@ -132,12 +134,47 @@ int timeouts[12] = {
|
||||
0
|
||||
};
|
||||
|
||||
struct extparam conf = {
|
||||
#ifdef _WIN32
|
||||
.threadinit = NULL,
|
||||
#else
|
||||
.threadinit = 0,
|
||||
#ifndef _WIN32
|
||||
/* PTHREAD_STACK_MIN is 128K on glibc/aarch64 and glibc/powerpc and may be
|
||||
a sysconf() call with _GNU_SOURCE. pthread_attr_setstacksize() fails with
|
||||
EINVAL below it and the thread silently gets the 8M system default stack.
|
||||
*/
|
||||
size_t threadstacksize(int extra){
|
||||
long size = BASESTACKSIZE + extra;
|
||||
|
||||
if(size < (long)PTHREAD_STACK_MIN) size = (long)PTHREAD_STACK_MIN;
|
||||
return (size_t)size;
|
||||
}
|
||||
|
||||
int _3proxy_sem_init_f(_3proxy_sem_t *sem, unsigned count, unsigned maxcount){
|
||||
sem->count = count;
|
||||
sem->maxcount = maxcount;
|
||||
if(pthread_mutex_init(&sem->mutex, NULL)) return 1;
|
||||
if(pthread_cond_init(&sem->cond, NULL)){
|
||||
pthread_mutex_destroy(&sem->mutex);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void _3proxy_sem_lock_f(_3proxy_sem_t *sem){
|
||||
pthread_mutex_lock(&sem->mutex);
|
||||
while(!sem->count) pthread_cond_wait(&sem->cond, &sem->mutex);
|
||||
sem->count--;
|
||||
pthread_mutex_unlock(&sem->mutex);
|
||||
}
|
||||
|
||||
void _3proxy_sem_unlock_f(_3proxy_sem_t *sem){
|
||||
pthread_mutex_lock(&sem->mutex);
|
||||
if(sem->count < sem->maxcount){
|
||||
sem->count++;
|
||||
pthread_cond_signal(&sem->cond);
|
||||
}
|
||||
pthread_mutex_unlock(&sem->mutex);
|
||||
}
|
||||
#endif
|
||||
|
||||
struct extparam conf = {
|
||||
.timeouts = timeouts,
|
||||
.acl = NULL,
|
||||
.conffile = NULL,
|
||||
@@ -153,7 +190,7 @@ struct extparam conf = {
|
||||
.paused = 0,
|
||||
.archiverc = 0,
|
||||
.demon = 0,
|
||||
.maxchild = 500,
|
||||
.maxchild = DEFAULT_MAXCHILD,
|
||||
.backlog = 0,
|
||||
.needreload = 0,
|
||||
.timetoexit = 0,
|
||||
@@ -497,6 +534,19 @@ int parsehostname(char *hostname, struct clientparam *param, uint16_t port){
|
||||
if(se){
|
||||
*se = 0;
|
||||
}
|
||||
if(!*hostname){
|
||||
if(sp){
|
||||
port = atoi(sp+1);
|
||||
*sp = ':';
|
||||
}
|
||||
*SAPORT(¶m->req) = htons(port);
|
||||
return 0;
|
||||
}
|
||||
if(strlen(hostname + (se!=0)) > 253){
|
||||
if(se) *se = ']';
|
||||
if(sp) *sp = ':';
|
||||
return 1;
|
||||
}
|
||||
if(hostname != (char *)param->hostname){
|
||||
if(param->hostname) free(param->hostname);
|
||||
param->hostname = (unsigned char *)strdup(hostname + (se!=0));
|
||||
@@ -551,14 +601,14 @@ int parseconnusername(char *username, struct clientparam *param, int extpasswd,
|
||||
if(!username || !*username) return 1;
|
||||
if ((sb=strchr(username, conf.delimchar)) == NULL){
|
||||
if(!param->hostname && param->remsock == INVALID_SOCKET) return 2;
|
||||
if(param->hostname)parsehostname((char *)param->hostname, param, port);
|
||||
if(param->hostname)parsehostname((char *)param->hostname, param, *SAPORT(¶m->req)? ntohs(*SAPORT(¶m->req)) : port);
|
||||
return parseusername(username, param, extpasswd);
|
||||
}
|
||||
while ((se=strchr(sb+1, conf.delimchar)))sb=se;
|
||||
*(sb) = 0;
|
||||
if(parseusername(username, param, extpasswd)) return 3;
|
||||
*(sb) = conf.delimchar;
|
||||
if(parsehostname(sb+1, param, port)) return 4;
|
||||
if(parsehostname(sb+1, param, *SAPORT(¶m->req)? ntohs(*SAPORT(¶m->req)) : port)) return 4;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -631,20 +681,6 @@ int doconnect(struct clientparam * param){
|
||||
setopts(param->remsock, param->srv->srvsockopts);
|
||||
|
||||
param->srv->so._setsockopt(param->sostate, param->remsock, SOL_SOCKET, SO_LINGER, (char *)&lg, sizeof(lg));
|
||||
#ifdef REUSE
|
||||
{
|
||||
int opt;
|
||||
|
||||
#ifdef SO_REUSEADDR
|
||||
opt = 1;
|
||||
param->srv->so._setsockopt(param->sostate, param->remsock, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(int));
|
||||
#endif
|
||||
#ifdef SO_REUSEPORT
|
||||
opt = 1;
|
||||
param->srv->so._setsockopt(param->sostate, param->remsock, SOL_SOCKET, SO_REUSEPORT, (unsigned char *)&opt, sizeof(int));
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#if defined SO_BINDTODEVICE
|
||||
if(param->srv->obindtodevice) {
|
||||
if(param->srv->so._setsockopt(param->sostate, param->remsock, SOL_SOCKET, SO_BINDTODEVICE, param->srv->obindtodevice, strlen(param->srv->obindtodevice) + 1))
|
||||
@@ -657,6 +693,9 @@ int doconnect(struct clientparam * param){
|
||||
if(!idx || (*SAFAMILY(¶m->sinsl) == AF_INET && param->srv->so._setsockopt(param->sostate, param->remsock, IPPROTO_IP, IP_BOUND_IF, &idx, sizeof(idx))))
|
||||
return 12;
|
||||
#ifndef NOIPV6
|
||||
#ifndef IPV6_BOUND_IF
|
||||
#define IPV6_BOUND_IF 125
|
||||
#endif
|
||||
if(*SAFAMILY(¶m->sinsl) == AF_INET6 && param->srv->so._setsockopt(param->sostate, param->remsock, IPPROTO_IPV6, IPV6_BOUND_IF, &idx, sizeof(idx))) return 12;
|
||||
#endif
|
||||
}
|
||||
@@ -867,3 +906,21 @@ uint32_t getip46(int family, unsigned char *name, struct sockaddr *sa){
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int hascap(const unsigned char *line, const char *cap){
|
||||
int len = (int)strlen(cap);
|
||||
for(; *line; line++) if(!strncasecmp((char *)line, cap, len)) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getmultiline(struct clientparam *param, DIRECTION which, unsigned char *buf, int bufsize, const char *cap, int *found){
|
||||
int i;
|
||||
do {
|
||||
i = sockgetlinebuf(param, which, buf, bufsize, '\n', conf.timeouts[STRING_L]);
|
||||
if(i > 0 && cap && found && !*found){
|
||||
buf[i] = 0;
|
||||
if(hascap(buf, cap)) *found = 1;
|
||||
}
|
||||
} while (i > 3 && buf[3] == '-');
|
||||
return i;
|
||||
}
|
||||
+201
-89
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
#include "proxy.h"
|
||||
#include "libs/blake2.h"
|
||||
#include "mdhash.h"
|
||||
#ifdef WITH_SSL
|
||||
void ssl_install(void);
|
||||
#endif
|
||||
@@ -156,7 +156,7 @@ int start_proxy_thread(struct child * chp){
|
||||
if(h)CloseHandle(h);
|
||||
#else
|
||||
pthread_attr_init(&pa);
|
||||
pthread_attr_setstacksize(&pa,PTHREAD_STACK_MIN + (32768+conf.stacksize));
|
||||
pthread_attr_setstacksize(&pa,threadstacksize(conf.stacksize));
|
||||
pthread_attr_setdetachstate(&pa,PTHREAD_CREATE_DETACHED);
|
||||
pthread_create(&thread, &pa, startsrv, (void *)chp);
|
||||
pthread_attr_destroy(&pa);
|
||||
@@ -191,14 +191,21 @@ static int h_proxy(int argc, unsigned char ** argv){
|
||||
childdef.port = 110;
|
||||
childdef.isudp = 0;
|
||||
childdef.service = S_POP3P;
|
||||
childdef.helpmessage = " -hdefault_host[:port] - use this host and port as default if no host specified\n";
|
||||
childdef.helpmessage = " -hdefault_host[:port] - use this host and port as default if no host specified\n -x - disable STARTTLS\n";
|
||||
}
|
||||
else if(!strcmp((char *)argv[0], "imapp")) {
|
||||
childdef.pf = imappchild;
|
||||
childdef.port = 143;
|
||||
childdef.isudp = 0;
|
||||
childdef.service = S_IMAPP;
|
||||
childdef.helpmessage = " -hdefault_host[:port] - use this host and port as default if no host specified\n -x - disable STARTTLS\n";
|
||||
}
|
||||
else if(!strcmp((char *)argv[0], "smtpp")) {
|
||||
childdef.pf = smtppchild;
|
||||
childdef.port = 25;
|
||||
childdef.port = 587;
|
||||
childdef.isudp = 0;
|
||||
childdef.service = S_SMTPP;
|
||||
childdef.helpmessage = " -hdefault_host[:port] - use this host and port as default if no host specified\n";
|
||||
childdef.helpmessage = " -hdefault_host[:port] - use this host and port as default if no host specified\n -x - disable STARTTLS\n";
|
||||
}
|
||||
else if(!strcmp((char *)argv[0], "ftppr")) {
|
||||
childdef.pf = ftpprchild;
|
||||
@@ -257,7 +264,7 @@ static int h_proxy(int argc, unsigned char ** argv){
|
||||
childdef.port = 53;
|
||||
childdef.isudp = 1;
|
||||
childdef.service = S_DNSPR;
|
||||
childdef.helpmessage = " -s - simple DNS forwarding - do not use 3proxy resolver / name cache\n";
|
||||
childdef.helpmessage = " -s - simple DNS forwarding - do not use 3proxy resolver / name cache\n -Fip - fake: answer all A queries with this IP\n";
|
||||
#ifndef NOIPV6
|
||||
if(!resolvfunc || (resolvfunc == myresolver && !dns_table.poolsize) || resolvfunc == fakeresolver){
|
||||
fprintf(stderr, "[line %d] Warning: no nserver/nscache configured, dnspr will not work as expected\n", linenum);
|
||||
@@ -289,12 +296,19 @@ static int h_external(int argc, unsigned char ** argv){
|
||||
else conf.extsa6 = sa6;
|
||||
#else
|
||||
res = getip46(46, argv[1], (struct sockaddr *)&conf.extsa);
|
||||
if(!res) return 1;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int h_log(int argc, unsigned char ** argv){
|
||||
/* ODBC drivers require noticeably more stack than the file logger, raise
|
||||
the client thread stack size unless a larger one is configured
|
||||
explicitly. An explicit stacksize placed after the log command still wins.
|
||||
*/
|
||||
#define LOGSTACKSIZE 32768
|
||||
|
||||
static int h_log(int argc, unsigned char ** argv){
|
||||
unsigned char tmpbuf[8192];
|
||||
int notchanged = 0;
|
||||
|
||||
@@ -323,6 +337,7 @@ static int h_log(int argc, unsigned char ** argv){
|
||||
#ifdef WITH_ODBC
|
||||
else if(*argv[1]=='&'){
|
||||
conf.logfunc = logsql;
|
||||
if(conf.stacksize < LOGSTACKSIZE) conf.stacksize = LOGSTACKSIZE;
|
||||
if(notchanged) return 0;
|
||||
_3proxy_mutex_lock(&log_mutex);
|
||||
close_sql();
|
||||
@@ -503,7 +518,6 @@ static int h_auth(int argc, unsigned char **argv){
|
||||
}
|
||||
|
||||
static int h_users(int argc, unsigned char **argv){
|
||||
static char dummy;
|
||||
int j;
|
||||
unsigned char *arg;
|
||||
char *pw[2];
|
||||
@@ -543,13 +557,17 @@ static int h_users(int argc, unsigned char **argv){
|
||||
l = strlen(pw[1]);
|
||||
if(l > 255) l = 255;
|
||||
if((unsigned)l >= pwl_table.recsize) {
|
||||
blake2b_state S;
|
||||
mdh_ctx *bctx;
|
||||
unsigned hashsz;
|
||||
unsigned int blen;
|
||||
if(*pass != CL) continue;
|
||||
hashsz = pwl_table.recsize - 1 < 64 ? pwl_table.recsize - 1 : 64;
|
||||
blake2b_init(&S, hashsz);
|
||||
blake2b_update(&S, pw[1], l + 1);
|
||||
blake2b_final(&S, pass+1, hashsz);
|
||||
bctx = mdh_init(MDH_BLAKE2, hashsz);
|
||||
if(!bctx) continue;
|
||||
mdh_update(bctx, pw[1], l + 1);
|
||||
blen = hashsz;
|
||||
mdh_final(bctx, (unsigned char *)pass+1, &blen);
|
||||
mdh_free(bctx);
|
||||
} else {
|
||||
memcpy(pass + 1, pw[1], l);
|
||||
}
|
||||
@@ -739,6 +757,7 @@ struct redirdesc redirs[] = {
|
||||
{R_SOCKS5, "socks5", sockschild},
|
||||
{R_HTTP, "http", proxychild},
|
||||
{R_POP3, "pop3", pop3pchild},
|
||||
{R_IMAP, "imap", imappchild},
|
||||
{R_SMTP, "smtp", smtppchild},
|
||||
{R_FTP, "ftp", ftpprchild},
|
||||
{R_CONNECTP, "connect+", proxychild},
|
||||
@@ -1599,89 +1618,182 @@ static int h_chroot(int argc, unsigned char **argv){
|
||||
#endif
|
||||
|
||||
|
||||
struct commands specificcommands[]={
|
||||
#ifndef _WIN32
|
||||
{specificcommands+1, "setuid", h_setuid, 2, 2},
|
||||
{specificcommands+2, "setgid", h_setgid, 2, 2},
|
||||
{specificcommands+3, "chroot", h_chroot, 2, 4},
|
||||
#ifdef WITH_SSL
|
||||
int h_mitm(int argc, unsigned char **argv);
|
||||
int h_nomitm(int argc, unsigned char **argv);
|
||||
int h_serv(int argc, unsigned char **argv);
|
||||
int h_noserv(int argc, unsigned char **argv);
|
||||
int h_cli(int argc, unsigned char **argv);
|
||||
int h_nocli(int argc, unsigned char **argv);
|
||||
int h_certcache(int argc, unsigned char **argv);
|
||||
int h_srvcert(int argc, unsigned char **argv);
|
||||
int h_srvkey(int argc, unsigned char **argv);
|
||||
int h_clicert(int argc, unsigned char **argv);
|
||||
int h_clikey(int argc, unsigned char **argv);
|
||||
int h_client_cipher_list(int argc, unsigned char **argv);
|
||||
int h_server_cipher_list(int argc, unsigned char **argv);
|
||||
int h_client_ciphersuites(int argc, unsigned char **argv);
|
||||
int h_server_ciphersuites(int argc, unsigned char **argv);
|
||||
int h_server_ca_file(int argc, unsigned char **argv);
|
||||
int h_server_ca_key(int argc, unsigned char **argv);
|
||||
int h_client_ca_file(int argc, unsigned char **argv);
|
||||
int h_client_ca_dir(int argc, unsigned char **argv);
|
||||
int h_client_ca_store(int argc, unsigned char **argv);
|
||||
int h_client_sni(int argc, unsigned char **argv);
|
||||
int h_client_alpn(int argc, unsigned char **argv);
|
||||
int h_server_ca_dir(int argc, unsigned char **argv);
|
||||
int h_server_ca_store(int argc, unsigned char **argv);
|
||||
int h_client_min_proto_version(int argc, unsigned char **argv);
|
||||
int h_client_max_proto_version(int argc, unsigned char **argv);
|
||||
int h_server_min_proto_version(int argc, unsigned char **argv);
|
||||
int h_server_max_proto_version(int argc, unsigned char **argv);
|
||||
int h_client_verify(int argc, unsigned char **argv);
|
||||
int h_no_client_verify(int argc, unsigned char **argv);
|
||||
int h_server_verify(int argc, unsigned char **argv);
|
||||
int h_no_server_verify(int argc, unsigned char **argv);
|
||||
int h_client_mode(int argc, unsigned char **argv);
|
||||
#endif
|
||||
#ifdef WITH_PCRE
|
||||
int h_pcre(int argc, unsigned char **argv);
|
||||
int h_pcre_rewrite(int argc, unsigned char **argv);
|
||||
int h_pcre_extend(int argc, unsigned char **argv);
|
||||
int h_pcre_options(int argc, unsigned char **argv);
|
||||
#endif
|
||||
{NULL, "", h_noop, 1, 0}
|
||||
};
|
||||
|
||||
struct commands commandhandlers[]={
|
||||
{commandhandlers+1, "", h_noop, 1, 0},
|
||||
{commandhandlers+2, "proxy", h_proxy, 1, 0},
|
||||
{commandhandlers+3, "pop3p", h_proxy, 1, 0},
|
||||
{commandhandlers+4, "ftppr", h_proxy, 1, 0},
|
||||
{commandhandlers+5, "socks", h_proxy, 1, 0},
|
||||
{commandhandlers+6, "tcppm", h_proxy, 4, 0},
|
||||
{commandhandlers+7, "udppm", h_proxy, 4, 0},
|
||||
{commandhandlers+8, "admin", h_proxy, 1, 0},
|
||||
{commandhandlers+9, "dnspr", h_proxy, 1, 0},
|
||||
{commandhandlers+10, "internal", h_internal, 2, 2},
|
||||
{commandhandlers+11, "external", h_external, 2, 2},
|
||||
{commandhandlers+12, "log", h_log, 1, 0},
|
||||
{commandhandlers+13, "service", h_service, 1, 1},
|
||||
{commandhandlers+14, "daemon", h_daemon, 1, 1},
|
||||
{commandhandlers+15, "config", h_config, 2, 2},
|
||||
{commandhandlers+16, "include", h_include, 2, 2},
|
||||
{commandhandlers+17, "archiver", h_archiver, 3, 0},
|
||||
{commandhandlers+18, "counter", h_counter, 2, 4},
|
||||
{commandhandlers+19, "rotate", h_rotate, 2, 2},
|
||||
{commandhandlers+20, "logformat", h_logformat, 2, 2},
|
||||
{commandhandlers+21, "timeouts", h_timeouts, 2, 0},
|
||||
{commandhandlers+22, "auth", h_auth, 2, 0},
|
||||
{commandhandlers+23, "users", h_users, 1, 0},
|
||||
{commandhandlers+24, "maxconn", h_maxconn, 2, 2},
|
||||
{commandhandlers+25, "flush", h_flush, 1, 1},
|
||||
{commandhandlers+26, "nserver", h_nserver, 2, 2},
|
||||
{commandhandlers+27, "fakeresolve", h_fakeresolve, 1, 1},
|
||||
{commandhandlers+28, "nscache", h_nscache, 2, 2},
|
||||
{commandhandlers+29, "nscache6", h_nscache6, 2, 2},
|
||||
{commandhandlers+30, "nsrecord", h_nsrecord, 3, 3},
|
||||
{commandhandlers+31, "dialer", h_dialer, 2, 2},
|
||||
{commandhandlers+32, "system", h_system, 2, 2},
|
||||
{commandhandlers+33, "pidfile", h_pidfile, 2, 2},
|
||||
{commandhandlers+34, "monitor", h_monitor, 2, 2},
|
||||
{commandhandlers+35, "parent", h_parent, 5, 0},
|
||||
{commandhandlers+36, "allow", h_ace, 1, 0},
|
||||
{commandhandlers+37, "deny", h_ace, 1, 0},
|
||||
{commandhandlers+38, "redirect", h_ace, 3, 0},
|
||||
{commandhandlers+39, "bandlimin", h_ace, 2, 0},
|
||||
{commandhandlers+40, "bandlimout", h_ace, 2, 0},
|
||||
{commandhandlers+41, "nobandlimin", h_ace, 1, 0},
|
||||
{commandhandlers+42, "nobandlimout", h_ace, 1, 0},
|
||||
{commandhandlers+43, "countin", h_ace, 4, 0},
|
||||
{commandhandlers+44, "nocountin", h_ace, 1, 0},
|
||||
{commandhandlers+45, "countout", h_ace, 4, 0},
|
||||
{commandhandlers+46, "nocountout", h_ace, 1, 0},
|
||||
{commandhandlers+47, "countall", h_ace, 4, 0},
|
||||
{commandhandlers+48, "nocountall", h_ace, 1, 0},
|
||||
{commandhandlers+49, "connlim", h_ace, 4, 0},
|
||||
{commandhandlers+50, "noconnlim", h_ace, 1, 0},
|
||||
{commandhandlers+51, "plugin", h_plugin, 3, 0},
|
||||
{commandhandlers+52, "logdump", h_logdump, 2, 3},
|
||||
{commandhandlers+53, "filtermaxsize", h_filtermaxsize, 2, 2},
|
||||
{commandhandlers+54, "nolog", h_nolog, 1, 1},
|
||||
{commandhandlers+55, "weight", h_nolog, 2, 2},
|
||||
{commandhandlers+56, "authcache", h_authcache, 2, 4},
|
||||
{commandhandlers+57, "smtpp", h_proxy, 1, 0},
|
||||
{commandhandlers+58, "delimchar",h_delimchar, 2, 2},
|
||||
{commandhandlers+59, "authnserver", h_authnserver, 2, 2},
|
||||
{commandhandlers+60, "stacksize", h_stacksize, 2, 2},
|
||||
{commandhandlers+61, "force", h_force, 1, 1},
|
||||
{commandhandlers+62, "noforce", h_noforce, 1, 1},
|
||||
{commandhandlers+63, "parentretries", h_parentretries, 2, 2},
|
||||
{commandhandlers+64, "auto", h_proxy, 1, 0},
|
||||
{commandhandlers+65, "backlog", h_backlog, 2, 2},
|
||||
{commandhandlers+66, "tlspr", h_proxy, 1, 0},
|
||||
{commandhandlers+67, "maxseg", h_maxseg, 2, 2},
|
||||
{NULL, "", h_noop, 1, 0},
|
||||
{NULL, "proxy", h_proxy, 1, 0},
|
||||
{NULL, "pop3p", h_proxy, 1, 0},
|
||||
{NULL, "imapp", h_proxy, 1, 0},
|
||||
{NULL, "ftppr", h_proxy, 1, 0},
|
||||
{NULL, "socks", h_proxy, 1, 0},
|
||||
{NULL, "tcppm", h_proxy, 4, 0},
|
||||
{NULL, "udppm", h_proxy, 4, 0},
|
||||
{NULL, "admin", h_proxy, 1, 0},
|
||||
{NULL, "dnspr", h_proxy, 1, 0},
|
||||
{NULL, "internal", h_internal, 2, 2},
|
||||
{NULL, "external", h_external, 2, 2},
|
||||
{NULL, "log", h_log, 1, 0},
|
||||
{NULL, "service", h_service, 1, 1},
|
||||
{NULL, "daemon", h_daemon, 1, 1},
|
||||
{NULL, "config", h_config, 2, 2},
|
||||
{NULL, "include", h_include, 2, 2},
|
||||
{NULL, "archiver", h_archiver, 3, 0},
|
||||
{NULL, "counter", h_counter, 2, 4},
|
||||
{NULL, "rotate", h_rotate, 2, 2},
|
||||
{NULL, "logformat", h_logformat, 2, 2},
|
||||
{NULL, "timeouts", h_timeouts, 2, 0},
|
||||
{NULL, "auth", h_auth, 2, 0},
|
||||
{NULL, "users", h_users, 1, 0},
|
||||
{NULL, "maxconn", h_maxconn, 2, 2},
|
||||
{NULL, "flush", h_flush, 1, 1},
|
||||
{NULL, "nserver", h_nserver, 2, 2},
|
||||
{NULL, "fakeresolve", h_fakeresolve, 1, 1},
|
||||
{NULL, "nscache", h_nscache, 2, 2},
|
||||
{NULL, "nscache6", h_nscache6, 2, 2},
|
||||
{NULL, "nsrecord", h_nsrecord, 3, 3},
|
||||
{NULL, "dialer", h_dialer, 2, 2},
|
||||
{NULL, "system", h_system, 2, 2},
|
||||
{NULL, "pidfile", h_pidfile, 2, 2},
|
||||
{NULL, "monitor", h_monitor, 2, 2},
|
||||
{NULL, "parent", h_parent, 5, 0},
|
||||
{NULL, "allow", h_ace, 1, 0},
|
||||
{NULL, "deny", h_ace, 1, 0},
|
||||
{NULL, "redirect", h_ace, 3, 0},
|
||||
{NULL, "bandlimin", h_ace, 2, 0},
|
||||
{NULL, "bandlimout", h_ace, 2, 0},
|
||||
{NULL, "nobandlimin", h_ace, 1, 0},
|
||||
{NULL, "nobandlimout", h_ace, 1, 0},
|
||||
{NULL, "countin", h_ace, 4, 0},
|
||||
{NULL, "nocountin", h_ace, 1, 0},
|
||||
{NULL, "countout", h_ace, 4, 0},
|
||||
{NULL, "nocountout", h_ace, 1, 0},
|
||||
{NULL, "countall", h_ace, 4, 0},
|
||||
{NULL, "nocountall", h_ace, 1, 0},
|
||||
{NULL, "connlim", h_ace, 4, 0},
|
||||
{NULL, "noconnlim", h_ace, 1, 0},
|
||||
{NULL, "plugin", h_plugin, 3, 0},
|
||||
{NULL, "logdump", h_logdump, 2, 3},
|
||||
{NULL, "filtermaxsize", h_filtermaxsize, 2, 2},
|
||||
{NULL, "nolog", h_nolog, 1, 1},
|
||||
{NULL, "weight", h_nolog, 2, 2},
|
||||
{NULL, "authcache", h_authcache, 2, 4},
|
||||
{NULL, "smtpp", h_proxy, 1, 0},
|
||||
{NULL, "delimchar",h_delimchar, 2, 2},
|
||||
{NULL, "authnserver", h_authnserver, 2, 2},
|
||||
{NULL, "stacksize", h_stacksize, 2, 2},
|
||||
{NULL, "force", h_force, 1, 1},
|
||||
{NULL, "noforce", h_noforce, 1, 1},
|
||||
{NULL, "parentretries", h_parentretries, 2, 2},
|
||||
{NULL, "auto", h_proxy, 1, 0},
|
||||
{NULL, "backlog", h_backlog, 2, 2},
|
||||
{NULL, "tlspr", h_proxy, 1, 0},
|
||||
{NULL, "maxseg", h_maxseg, 2, 2},
|
||||
#ifndef NORADIUS
|
||||
{commandhandlers+68, "radius", h_radius, 3, 0},
|
||||
{NULL, "radius", h_radius, 3, 0},
|
||||
#endif
|
||||
{specificcommands, "", h_noop, 1, 0}
|
||||
#ifndef _WIN32
|
||||
{NULL, "setuid", h_setuid, 2, 2},
|
||||
{NULL, "setgid", h_setgid, 2, 2},
|
||||
{NULL, "chroot", h_chroot, 2, 4},
|
||||
#endif
|
||||
#ifdef WITH_SSL
|
||||
{NULL, "ssl_mitm", h_mitm, 1, 1},
|
||||
{NULL, "ssl_nomitm", h_nomitm, 1, 1},
|
||||
{NULL, "ssl_serv", h_serv, 1, 1},
|
||||
{NULL, "ssl_noserv", h_noserv, 1, 1},
|
||||
{NULL, "ssl_server_cert", h_srvcert, 1, 2},
|
||||
{NULL, "ssl_server_key", h_srvkey, 1, 2},
|
||||
{NULL, "ssl_server_ca_file", h_server_ca_file, 1, 2},
|
||||
{NULL, "ssl_server_ca_key", h_server_ca_key, 1, 2},
|
||||
{NULL, "ssl_client_ca_file", h_client_ca_file, 1, 2},
|
||||
{NULL, "ssl_client_ca_dir", h_client_ca_dir, 1, 2},
|
||||
{NULL, "ssl_client_ca_store", h_client_ca_store, 1, 2},
|
||||
{NULL, "ssl_client_ciphersuites", h_client_ciphersuites, 1, 2},
|
||||
{NULL, "ssl_server_ciphersuites", h_server_ciphersuites, 1, 2},
|
||||
{NULL, "ssl_client_cipher_list", h_client_cipher_list, 1, 2},
|
||||
{NULL, "ssl_server_cipher_list", h_server_cipher_list, 1, 2},
|
||||
{NULL, "ssl_client_min_proto_version", h_client_min_proto_version, 1, 2},
|
||||
{NULL, "ssl_server_min_proto_version", h_server_min_proto_version, 1, 2},
|
||||
{NULL, "ssl_client_max_proto_version", h_client_max_proto_version, 1, 2},
|
||||
{NULL, "ssl_server_max_proto_version", h_server_max_proto_version, 1, 2},
|
||||
{NULL, "ssl_client_verify", h_client_verify, 1, 1},
|
||||
{NULL, "ssl_client_no_verify", h_no_client_verify, 1, 1},
|
||||
{NULL, "ssl_cli", h_cli, 1, 1},
|
||||
{NULL, "ssl_nocli", h_nocli, 1, 1},
|
||||
{NULL, "ssl_client_cert", h_clicert, 1, 2},
|
||||
{NULL, "ssl_client_key", h_clikey, 1, 2},
|
||||
{NULL, "ssl_server", h_serv, 1, 1},
|
||||
{NULL, "ssl_noserver", h_noserv, 1, 1},
|
||||
{NULL, "ssl_client", h_cli, 1, 1},
|
||||
{NULL, "ssl_noclient", h_nocli, 1, 1},
|
||||
{NULL, "ssl_server_verify", h_server_verify, 1, 1},
|
||||
{NULL, "ssl_server_no_verify", h_no_server_verify, 1, 1},
|
||||
{NULL, "ssl_server_ca_dir", h_server_ca_dir, 1, 2},
|
||||
{NULL, "ssl_server_ca_store", h_server_ca_store, 1, 2},
|
||||
{NULL, "ssl_client_sni", h_client_sni, 1, 2},
|
||||
{NULL, "ssl_client_alpn", h_client_alpn, 1, 0},
|
||||
{NULL, "ssl_client_mode", h_client_mode, 1, 2},
|
||||
{NULL, "ssl_certcache", h_certcache, 2, 2},
|
||||
#endif
|
||||
#ifdef WITH_PCRE
|
||||
{NULL, "pcre", h_pcre, 4, 0},
|
||||
{NULL, "pcre_rewrite", h_pcre_rewrite, 5, 0},
|
||||
{NULL, "pcre_extend", h_pcre_extend, 2, 0},
|
||||
{NULL, "pcre_options", h_pcre_options, 2, 0},
|
||||
#endif
|
||||
{NULL, "", h_noop, 1, 0}
|
||||
};
|
||||
|
||||
void initcommands(void){
|
||||
static int initialized = 0;
|
||||
unsigned i;
|
||||
if(initialized) return;
|
||||
initialized = 1;
|
||||
for(i = 0; i + 1 < sizeof(commandhandlers)/sizeof(commandhandlers[0]); i++)
|
||||
commandhandlers[i].next = commandhandlers + i + 1;
|
||||
}
|
||||
|
||||
int parsestr (unsigned char *str, unsigned char **argm, int nitems, unsigned char ** buff, int *inbuf, int *bufsize){
|
||||
#define buf (*buff)
|
||||
int argc = 0;
|
||||
@@ -1913,7 +2025,7 @@ void freeconf(struct extparam *confp){
|
||||
#endif
|
||||
*SAFAMILY(&confp->intsa) = AF_INET;
|
||||
*SAFAMILY(&confp->extsa) = AF_INET;
|
||||
confp->maxchild = 100;
|
||||
confp->maxchild = DEFAULT_MAXCHILD;
|
||||
confp->backlog = 0;
|
||||
resolvfunc = NULL;
|
||||
numservers = 0;
|
||||
|
||||
+2
-9
@@ -61,13 +61,6 @@ static void pr_ip(struct node *node, CBFUNC cbf, void*cb){
|
||||
if(node->value)(*cbf)(cb, buf, myinet_ntop(AF_INET, node -> value, buf, 4));
|
||||
}
|
||||
|
||||
#ifndef NOIPV6
|
||||
static void pr_ip6(struct node *node, CBFUNC cbf, void*cb){
|
||||
char buf[64];
|
||||
if(node->value)(*cbf)(cb, buf, myinet_ntop(AF_INET6, node -> value, buf, 16));
|
||||
}
|
||||
#endif
|
||||
|
||||
static void pr_sa(struct node *node, CBFUNC cbf, void*cb){
|
||||
#ifdef NOIPV6
|
||||
if(node->value)pr_ip(node, cbf, cb);
|
||||
@@ -523,7 +516,7 @@ static void * ef_server_next(struct node * node){
|
||||
|
||||
static void * ef_server_type(struct node * node){
|
||||
int service = ((struct srvparam *)node->value) -> service;
|
||||
return (service>=0 && service < 15)? (void *)conf.stringtable[SERVICES + service] : (void *)"unknown";
|
||||
return (service>=0 && service < MAX_SERVICE)? (void *)conf.stringtable[SERVICES + service] : (void *)"unknown";
|
||||
}
|
||||
|
||||
static void * ef_server_child(struct node * node){
|
||||
@@ -682,7 +675,7 @@ static void * ef_client_next(struct node * node){
|
||||
|
||||
static void * ef_client_type(struct node * node){
|
||||
int service = ((struct clientparam *)node->value) -> service;
|
||||
return (service>=0 && service < 15)? (void *)conf.stringtable[SERVICES + service] : (void *)"unknown";
|
||||
return (service>=0 && service < MAX_SERVICE)? (void *)conf.stringtable[SERVICES + service] : (void *)"unknown";
|
||||
}
|
||||
|
||||
static void * ef_client_operation(struct node * node){
|
||||
|
||||
+22
-8
@@ -25,6 +25,7 @@ void * dnsprchild(struct clientparam* param) {
|
||||
SASIZETYPE size;
|
||||
int res, i;
|
||||
int len;
|
||||
int semlocked = 1;
|
||||
unsigned type=0;
|
||||
uint32_t ttl;
|
||||
unsigned char addr[16];
|
||||
@@ -34,14 +35,16 @@ void * dnsprchild(struct clientparam* param) {
|
||||
|
||||
|
||||
if(!(bbuf = malloc(BUFSIZE+2))){
|
||||
param->srv->fds.events = POLLIN;
|
||||
RETURN (21);
|
||||
}
|
||||
buf = bbuf+2;
|
||||
size = sizeof(param->sincr);
|
||||
i = param->srv->so._recvfrom(param->sostate, param->srv->srvsock, (char *)buf, BUFSIZE, 0, (struct sockaddr *)¶m->sincr, &size);
|
||||
size = sizeof(param->sinsl);
|
||||
getsockname(param->srv->srvsock, (struct sockaddr *)¶m->sincl, &size);
|
||||
i = param->srv->udplen;
|
||||
if(i > BUFSIZE) i = BUFSIZE;
|
||||
memcpy(buf, param->srv->udpbuf, i);
|
||||
_3proxy_sem_unlock(udpinit);
|
||||
semlocked = 0;
|
||||
#ifdef _WIN32
|
||||
if((param->clisock=param->srv->so._socket(param->sostate, AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == INVALID_SOCKET) {
|
||||
RETURN(818);
|
||||
@@ -55,7 +58,6 @@ void * dnsprchild(struct clientparam* param) {
|
||||
#else
|
||||
param->clisock = param->srv->srvsock;
|
||||
#endif
|
||||
param->srv->fds.events = POLLIN;
|
||||
|
||||
if(i < 0) {
|
||||
RETURN(813);
|
||||
@@ -82,7 +84,19 @@ void * dnsprchild(struct clientparam* param) {
|
||||
*s2 = (len - (int)(s2 - buf)) - 1;
|
||||
|
||||
type = ((unsigned)buf[len+1])*256 + (unsigned)buf[len+2];
|
||||
if((type==0x01 || type==0x1c) && !param->srv->s_option){
|
||||
if(type==0x01 && param->srv->fakeip){
|
||||
ip = 1;
|
||||
ttl = 3600;
|
||||
*(uint32_t *)addr = param->srv->fakeip;
|
||||
}
|
||||
#ifndef NOIPV6
|
||||
else if(type==0x1c && *(uint32_t *)param->srv->fakeip6){
|
||||
ip = 1;
|
||||
ttl = 3600;
|
||||
memcpy(addr, param->srv->fakeip6, 16);
|
||||
}
|
||||
#endif
|
||||
else if((type==0x01 || type==0x1c) && !param->srv->s_option){
|
||||
ip = udpresolve((type==0x1c)?AF_INET6:AF_INET, (unsigned char *)host, addr, &ttl, param, 0);
|
||||
}
|
||||
|
||||
@@ -106,8 +120,8 @@ void * dnsprchild(struct clientparam* param) {
|
||||
len+=(type==1?16:28);
|
||||
}
|
||||
else if(type == 0x0c) {
|
||||
unsigned a, b, c, d;
|
||||
sscanf(host, "%u.%u.%u.%u", &a, &b, &c, &d);
|
||||
unsigned a = 0, b = 0, c = 0, d = 0;
|
||||
if(sscanf(host, "%u.%u.%u.%u", &a, &b, &c, &d) != 4) a = b = c = d = 0;
|
||||
ip = htonl((d<<24) ^ (c<<16) ^ (b<<8) ^ a);
|
||||
if(*SAFAMILY(¶m->sincl) == AF_INET && ip == *(uint32_t *)SAADDR(¶m->sincl)){
|
||||
buf[2] = 0x85;
|
||||
@@ -191,6 +205,7 @@ void * dnsprchild(struct clientparam* param) {
|
||||
|
||||
CLEANRET:
|
||||
|
||||
if(semlocked) _3proxy_sem_unlock(udpinit);
|
||||
if(param->res!=813){
|
||||
sprintf((char *)buf, "%04x/%s/",
|
||||
(unsigned)type,
|
||||
@@ -205,7 +220,6 @@ CLEANRET:
|
||||
#ifndef _WIN32
|
||||
param->clisock = INVALID_SOCKET;
|
||||
#endif
|
||||
freeparam(param);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
@@ -325,7 +325,6 @@ CLEANRET:
|
||||
}
|
||||
if(req) free(req);
|
||||
if(buf) free(buf);
|
||||
freeparam(param);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
||||
+1
-3
@@ -36,7 +36,6 @@ void destroyhashtable(struct hashtable *ht){
|
||||
|
||||
int inithashtable(struct hashtable *ht, unsigned tablesize, unsigned poolsize, unsigned growlimit){
|
||||
unsigned i;
|
||||
clock_t c;
|
||||
|
||||
#ifdef _WIN32
|
||||
struct timeb tb;
|
||||
@@ -48,7 +47,6 @@ int inithashtable(struct hashtable *ht, unsigned tablesize, unsigned poolsize, u
|
||||
struct timezone tz;
|
||||
gettimeofday(&tb, &tz);
|
||||
#endif
|
||||
c = clock();
|
||||
|
||||
if(tablesize < 2 || poolsize < tablesize || growlimit < poolsize) return 1;
|
||||
if(ht->ihashtable){
|
||||
@@ -169,7 +167,6 @@ static void hashgrow(struct hashtable *ht){
|
||||
void hashadd(struct hashtable *ht, void* name, void* value, time_t expires){
|
||||
uint32_t hen, he;
|
||||
uint32_t *hep;
|
||||
int overwrite = 0;
|
||||
uint8_t hash[MAX_HASH_SIZE];
|
||||
uint32_t index;
|
||||
uint32_t last = 0;
|
||||
@@ -197,6 +194,7 @@ void hashadd(struct hashtable *ht, void* name, void* value, time_t expires){
|
||||
|
||||
if(!ht->ihashempty){
|
||||
hashgrow(ht);
|
||||
index = hashindex(ht, ht->tablesize, hash);
|
||||
}
|
||||
|
||||
if(ht->ihashempty){
|
||||
|
||||
+24
-30
@@ -1,18 +1,21 @@
|
||||
#include "proxy.h"
|
||||
#include "libs/blake2.h"
|
||||
#include "mdhash.h"
|
||||
|
||||
|
||||
static void char_index2hash(const struct hashtable *ht, void *index, uint8_t *hash){
|
||||
blake2b_state S;
|
||||
int len;
|
||||
unsigned int blen;
|
||||
|
||||
len = strlen((const char*)index);
|
||||
memset(hash, 0, ht->hash_size);
|
||||
if(len <= ht->hash_size) memcpy(hash, index, len);
|
||||
else {
|
||||
blake2b_init(&S, ht->hash_size);
|
||||
blake2b_update(&S, index, strlen((const char*)index) + 1);
|
||||
blake2b_final(&S, hash, ht->hash_size);
|
||||
mdh_ctx *bctx = mdh_init(MDH_BLAKE2, ht->hash_size);
|
||||
if(!bctx) return;
|
||||
mdh_update(bctx, index, (unsigned int)(strlen((const char*)index) + 1));
|
||||
blen = ht->hash_size;
|
||||
mdh_final(bctx, hash, &blen);
|
||||
mdh_free(bctx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,10 +26,9 @@ static void param2hash_add(const struct hashtable *ht, void *index, uint8_t *has
|
||||
}
|
||||
|
||||
void param2hash_search(const struct hashtable *ht, void *index, uint8_t *hash){
|
||||
blake2b_state S;
|
||||
struct clientparam *param = (struct clientparam *)index;
|
||||
unsigned type = param->srv->authcachetype;
|
||||
int len = 0, oplen = 0, acllen = 0, ulen = 0, plen = 0, hlen = 0, a1len = 0, a2len = 0, a3len = 0, p1len=0, p2len = 0;
|
||||
int oplen = 0, acllen = 0, ulen = 0, plen = 0, hlen = 0, a1len = 0, a2len = 0, a3len = 0, p1len=0, p2len = 0;
|
||||
|
||||
|
||||
if((type & 2) && param->username) ulen = strlen((const char *)param->username) + 1;
|
||||
@@ -55,33 +57,25 @@ void param2hash_search(const struct hashtable *ht, void *index, uint8_t *hash){
|
||||
if((type & 2048)){ memcpy(hash + offset, SAPORT(¶m->srv->intsa), p2len); offset += 2; }
|
||||
}
|
||||
else {
|
||||
blake2b_init(&S, ht->hash_size);
|
||||
if((type & 2) && param->username)blake2b_update(&S, param->username, ulen);
|
||||
if((type & 4) && param->password)blake2b_update(&S, param->password, plen);
|
||||
if((type & 1) && !(type & 8))blake2b_update(&S, SAADDR(¶m->sincr), a1len);
|
||||
if((type & 16))blake2b_update(&S, ¶m->srv->acl, acllen);
|
||||
if((type & 64))blake2b_update(&S, SAADDR(¶m->req), a2len);
|
||||
if((type & 128))blake2b_update(&S, SAPORT(¶m->req), 2);
|
||||
if((type & 256) && param->hostname)blake2b_update(&S, param->hostname, hlen);
|
||||
if((type & 512))blake2b_update(&S, ¶m->operation, sizeof(param->operation));
|
||||
if((type & 1024))blake2b_update(&S, SAADDR(¶m->srv->intsa), a3len);
|
||||
if((type & 2048))blake2b_update(&S, SAPORT(¶m->srv->intsa), 2);
|
||||
blake2b_final(&S, hash, ht->hash_size);
|
||||
mdh_ctx *bctx = mdh_init(MDH_BLAKE2, ht->hash_size);
|
||||
unsigned int blen = ht->hash_size;
|
||||
if(!bctx) { memcpy(param->hash, hash, ht->hash_size); return; }
|
||||
if((type & 2) && param->username)mdh_update(bctx, param->username, ulen);
|
||||
if((type & 4) && param->password)mdh_update(bctx, param->password, plen);
|
||||
if((type & 1) && !(type & 8))mdh_update(bctx, SAADDR(¶m->sincr), a1len);
|
||||
if((type & 16))mdh_update(bctx, ¶m->srv->acl, acllen);
|
||||
if((type & 64))mdh_update(bctx, SAADDR(¶m->req), a2len);
|
||||
if((type & 128))mdh_update(bctx, SAPORT(¶m->req), 2);
|
||||
if((type & 256) && param->hostname)mdh_update(bctx, param->hostname, hlen);
|
||||
if((type & 512))mdh_update(bctx, ¶m->operation, sizeof(param->operation));
|
||||
if((type & 1024))mdh_update(bctx, SAADDR(¶m->srv->intsa), a3len);
|
||||
if((type & 2048))mdh_update(bctx, SAPORT(¶m->srv->intsa), 2);
|
||||
mdh_final(bctx, hash, &blen);
|
||||
mdh_free(bctx);
|
||||
}
|
||||
memcpy(param->hash, hash, ht->hash_size);
|
||||
}
|
||||
|
||||
static void udpparam2hash(const struct hashtable *ht, void *index, uint8_t *hash){
|
||||
struct clientparam *param = (struct clientparam *)index;
|
||||
blake2b_state S;
|
||||
blake2b_init(&S, ht->hash_size);
|
||||
blake2b_update(&S, SAADDR(¶m->srv->intsa), SAADDRLEN(¶m->srv->intsa));
|
||||
blake2b_update(&S, SAPORT(¶m->srv->intsa), 2);
|
||||
blake2b_update(&S, SAADDR(¶m->sincr), SAADDRLEN(¶m->sincr));
|
||||
blake2b_update(&S, SAPORT(¶m->sincr), 2);
|
||||
blake2b_final(&S, hash, ht->hash_size);
|
||||
}
|
||||
|
||||
struct hashtable dns_table = {char_index2hash, char_index2hash, 4, 32};
|
||||
struct hashtable dns6_table = {char_index2hash, char_index2hash, 16, 32};
|
||||
struct hashtable auth_table = {param2hash_add, param2hash_search, sizeof(struct authcache), 64};
|
||||
|
||||
+254
@@ -0,0 +1,254 @@
|
||||
/*
|
||||
3APA3A simplest proxy server
|
||||
(c) 2002-2026 by Vladimir Dubrovin <vlad@3proxy.org>
|
||||
|
||||
please read License Agreement
|
||||
|
||||
*/
|
||||
|
||||
#include "proxy.h"
|
||||
|
||||
#define RETURN(xxx) { param->res = xxx; goto CLEANRET; }
|
||||
|
||||
#define CL_LOGINCMD 0
|
||||
#define CL_PLAIN 1
|
||||
#define CL_LOGIN 2
|
||||
|
||||
#define CAP_PLAIN 1
|
||||
#define CAP_LOGIN 2
|
||||
|
||||
#ifdef WITHMAIN
|
||||
#define NOSTARTTLS 1
|
||||
#else
|
||||
#define NOSTARTTLS param->srv->nostarttls
|
||||
#endif
|
||||
|
||||
void * imappchild(struct clientparam* param) {
|
||||
int i=0, res, method=CL_LOGINCMD, caps=0;
|
||||
unsigned char buf[2048];
|
||||
unsigned char srvbuf[1024];
|
||||
unsigned char ibuf[2048];
|
||||
unsigned char tag[64];
|
||||
unsigned char ub[320];
|
||||
unsigned char pb[320];
|
||||
unsigned char *se, *cmd, *user, *pass, *p1, *p2;
|
||||
|
||||
*tag = 0;
|
||||
i = sprintf((char *)buf, "* OK [CAPABILITY IMAP4rev1%s AUTH=PLAIN AUTH=LOGIN] IMAP4rev1 Proxy Ready\r\n", NOSTARTTLS?"":" STARTTLS");
|
||||
if(socksend(param, param->clisock, buf, i, conf.timeouts[STRING_S])!=i) {RETURN (691);}
|
||||
for(;;){
|
||||
i = sockgetlinebuf(param, CLIENT, buf, sizeof(buf) - 10, '\n', conf.timeouts[STRING_S]);
|
||||
if(i < 4) {RETURN(692);}
|
||||
buf[i] = 0;
|
||||
if ((se=(unsigned char *)strchr((char *)buf, '\r'))) *se = 0;
|
||||
if (!(se=(unsigned char *)strchr((char *)buf, ' ')) || (se - buf) >= (int)(sizeof(tag) - 1)) {RETURN(692);}
|
||||
memcpy(tag, buf, se - buf);
|
||||
tag[se - buf] = 0;
|
||||
cmd = se + 1;
|
||||
if(!strncasecmp((char *)cmd, "LOGOUT", 6)){
|
||||
socksend(param, param->clisock, (unsigned char *)"* BYE\r\n", 7, conf.timeouts[STRING_S]);
|
||||
sprintf((char *)buf, "%.60s OK LOGOUT completed\r\n", (char *)tag);
|
||||
socksend(param, param->clisock, buf, (int)strlen((char *)buf), conf.timeouts[STRING_S]);
|
||||
RETURN(0);
|
||||
}
|
||||
if(!strncasecmp((char *)cmd, "CAPABILITY", 10)){
|
||||
i = sprintf((char *)buf, "* CAPABILITY IMAP4rev1%s AUTH=PLAIN AUTH=LOGIN\r\n", NOSTARTTLS?"":" STARTTLS");
|
||||
socksend(param, param->clisock, buf, i, conf.timeouts[STRING_S]);
|
||||
sprintf((char *)buf, "%.60s OK CAPABILITY completed\r\n", (char *)tag);
|
||||
socksend(param, param->clisock, buf, (int)strlen((char *)buf), conf.timeouts[STRING_S]);
|
||||
continue;
|
||||
}
|
||||
#ifndef WITHMAIN
|
||||
if(!strncasecmp((char *)cmd, "STARTTLS", 8) && !param->srv->nostarttls){
|
||||
sprintf((char *)buf, "%.60s OK Begin TLS negotiation\r\n", (char *)tag);
|
||||
if(socksend(param, param->clisock, buf, (int)strlen((char *)buf), conf.timeouts[STRING_S]) <= 0) {RETURN(698);}
|
||||
param->clientstarttls = S_IMAPP;
|
||||
if(!param->srv->targetport) param->srv->targetport = htons(143);
|
||||
return (void *)tlsprchild;
|
||||
}
|
||||
#endif
|
||||
if(!strncasecmp((char *)cmd, "LOGIN ", 6)){
|
||||
user = cmd + 6;
|
||||
if(*user == '"') {
|
||||
user++;
|
||||
if (!(se=(unsigned char *)strchr((char *)user, '"'))) {RETURN(693);}
|
||||
*se = 0;
|
||||
pass = se + 1;
|
||||
if(*pass == ' ') pass++;
|
||||
}
|
||||
else {
|
||||
if (!(se=(unsigned char *)strchr((char *)user, ' '))) {RETURN(693);}
|
||||
*se = 0;
|
||||
pass = se + 1;
|
||||
}
|
||||
if(strlen((char *)user) >= sizeof(ub) || strlen((char *)pass) >= sizeof(pb)) {RETURN(693);}
|
||||
strcpy((char *)ub, (char *)user);
|
||||
strcpy((char *)pb, (char *)pass);
|
||||
break;
|
||||
}
|
||||
if(!strncasecmp((char *)cmd, "AUTHENTICATE PLAIN", 18)){
|
||||
method = CL_PLAIN;
|
||||
se = cmd + 18;
|
||||
if(*se == ' ') se++; else se = NULL;
|
||||
if(!se || !*se){
|
||||
if(socksend(param, param->clisock, (unsigned char *)"+ \r\n", 4, conf.timeouts[STRING_S])!=4) {RETURN(698);}
|
||||
i = sockgetlinebuf(param, CLIENT, buf, sizeof(buf) - 10, '\n', conf.timeouts[STRING_S]);
|
||||
if(i < 1) {RETURN(698);}
|
||||
buf[i] = 0;
|
||||
if ((se=(unsigned char *)strchr((char *)buf, '\r'))) *se = 0;
|
||||
se = buf;
|
||||
}
|
||||
i = de64(se, ibuf, (int)sizeof(ibuf) - 1);
|
||||
if(i < 3) {RETURN(693);}
|
||||
ibuf[i] = 0;
|
||||
p1 = (unsigned char *)memchr(ibuf, 0, i);
|
||||
if(!p1 || p1 == ibuf + i - 1) {RETURN(693);}
|
||||
p2 = (unsigned char *)memchr(p1 + 1, 0, i - (int)(p1 + 1 - ibuf));
|
||||
if(p2){
|
||||
user = p1 + 1;
|
||||
pass = p2 + 1;
|
||||
}
|
||||
else {
|
||||
user = ibuf;
|
||||
pass = p1 + 1;
|
||||
}
|
||||
if(strlen((char *)user) >= sizeof(ub) || strlen((char *)pass) >= sizeof(pb)) {RETURN(693);}
|
||||
strcpy((char *)ub, (char *)user);
|
||||
strcpy((char *)pb, (char *)pass);
|
||||
break;
|
||||
}
|
||||
if(!strncasecmp((char *)cmd, "AUTHENTICATE LOGIN", 18)){
|
||||
method = CL_LOGIN;
|
||||
se = cmd + 18;
|
||||
if(*se == ' ') se++; else se = NULL;
|
||||
if(se && *se){
|
||||
i = de64(se, ub, (int)sizeof(ub) - 1);
|
||||
if(i < 0) {RETURN(693);}
|
||||
ub[i] = 0;
|
||||
}
|
||||
else {
|
||||
if(socksend(param, param->clisock, (unsigned char *)"+ VXNlcm5hbWU6\r\n", 16, conf.timeouts[STRING_S])!=16) {RETURN(698);}
|
||||
i = sockgetlinebuf(param, CLIENT, buf, sizeof(buf) - 10, '\n', conf.timeouts[STRING_S]);
|
||||
if(i < 1) {RETURN(698);}
|
||||
buf[i] = 0;
|
||||
if ((se=(unsigned char *)strchr((char *)buf, '\r'))) *se = 0;
|
||||
i = de64(buf, ub, (int)sizeof(ub) - 1);
|
||||
if(i < 0) {RETURN(693);}
|
||||
ub[i] = 0;
|
||||
}
|
||||
if(socksend(param, param->clisock, (unsigned char *)"+ UGFzc3dvcmQ6\r\n", 16, conf.timeouts[STRING_S])!=16) {RETURN(698);}
|
||||
i = sockgetlinebuf(param, CLIENT, buf, sizeof(buf) - 10, '\n', conf.timeouts[STRING_S]);
|
||||
if(i < 1) {RETURN(698);}
|
||||
buf[i] = 0;
|
||||
if ((se=(unsigned char *)strchr((char *)buf, '\r'))) *se = 0;
|
||||
i = de64(buf, pb, (int)sizeof(pb) - 1);
|
||||
if(i < 0) {RETURN(693);}
|
||||
pb[i] = 0;
|
||||
break;
|
||||
}
|
||||
sprintf((char *)buf, "%.60s BAD need LOGIN first\r\n", (char *)tag);
|
||||
socksend(param, param->clisock, buf, (int)strlen((char *)buf), conf.timeouts[STRING_S]);
|
||||
}
|
||||
if(parseconnusername((char *)ub, param, 0, 143)){RETURN(694);}
|
||||
if(*pb && !param->password) param->password = (unsigned char *)strdup((char *)pb);
|
||||
param->operation = CONNECT;
|
||||
res = (*param->srv->authfunc)(param);
|
||||
if(res) {RETURN(res);}
|
||||
i = sockgetlinebuf(param, SERVER, srvbuf, sizeof(srvbuf) - 1, '\n', conf.timeouts[STRING_L]);
|
||||
if( i < 4 ) {RETURN(695);}
|
||||
srvbuf[i] = 0;
|
||||
if(strncasecmp((char *)srvbuf, "* OK", 4)){RETURN(696);}
|
||||
if((se = (unsigned char *)strstr((char *)srvbuf, "[CAPABILITY "))){
|
||||
if(hascap(se, "AUTH=PLAIN")) caps |= CAP_PLAIN;
|
||||
if(hascap(se, "AUTH=LOGIN")) caps |= CAP_LOGIN;
|
||||
}
|
||||
else {
|
||||
if(socksend(param, param->remsock, (unsigned char *)"zz CAPABILITY\r\n", 15, conf.timeouts[STRING_S])!=15) {RETURN(697);}
|
||||
for(;;){
|
||||
i = sockgetlinebuf(param, SERVER, srvbuf, sizeof(srvbuf) - 1, '\n', conf.timeouts[STRING_L]);
|
||||
if(i < 3) {RETURN(697);}
|
||||
srvbuf[i] = 0;
|
||||
if(!strncasecmp((char *)srvbuf, "* CAPABILITY", 12)){
|
||||
if(hascap(srvbuf, "AUTH=PLAIN")) caps |= CAP_PLAIN;
|
||||
if(hascap(srvbuf, "AUTH=LOGIN")) caps |= CAP_LOGIN;
|
||||
continue;
|
||||
}
|
||||
if(!strncasecmp((char *)srvbuf, "zz ", 3)) break;
|
||||
}
|
||||
}
|
||||
if(method == CL_PLAIN && !(caps & CAP_PLAIN)) method = (caps & CAP_LOGIN)? CL_LOGIN : CL_LOGINCMD;
|
||||
else if(method == CL_LOGIN && !(caps & CAP_LOGIN)) method = (caps & CAP_PLAIN)? CL_PLAIN : CL_LOGINCMD;
|
||||
else if(method == CL_LOGINCMD && caps) method = (caps & CAP_PLAIN)? CL_PLAIN : CL_LOGIN;
|
||||
if(method == CL_PLAIN){
|
||||
i = (int)strlen((char *)param->extusername);
|
||||
res = (int)strlen((char *)pb);
|
||||
if(((i + res + 4) / 3) * 4 + 1 > (int)sizeof(srvbuf)) {RETURN(693);}
|
||||
ibuf[0] = 0;
|
||||
memcpy(ibuf + 1, param->extusername, i);
|
||||
ibuf[i + 1] = 0;
|
||||
memcpy(ibuf + i + 2, pb, res);
|
||||
en64(ibuf, srvbuf, i + res + 2);
|
||||
if( socksend(param, param->remsock, tag, (int)strlen((char *)tag), conf.timeouts[STRING_S]) <= 0 ||
|
||||
socksend(param, param->remsock, (unsigned char *)" AUTHENTICATE PLAIN ", 20, conf.timeouts[STRING_S])!= 20 ||
|
||||
socksend(param, param->remsock, srvbuf, (int)strlen((char *)srvbuf), conf.timeouts[STRING_S]) <= 0 ||
|
||||
socksend(param, param->remsock, (unsigned char *)"\r\n", 2, conf.timeouts[STRING_S])!=2)
|
||||
{RETURN(699);}
|
||||
}
|
||||
else if(method == CL_LOGIN){
|
||||
if( socksend(param, param->remsock, tag, (int)strlen((char *)tag), conf.timeouts[STRING_S]) <= 0 ||
|
||||
socksend(param, param->remsock, (unsigned char *)" AUTHENTICATE LOGIN\r\n", 21, conf.timeouts[STRING_S])!= 21)
|
||||
{RETURN(699);}
|
||||
i = sockgetlinebuf(param, SERVER, srvbuf, sizeof(srvbuf) - 1, '\n', conf.timeouts[STRING_L]);
|
||||
if(i < 1 || *srvbuf != '+') {RETURN(699);}
|
||||
if(((int)strlen((char *)param->extusername) + 2) / 3 * 4 + 1 > (int)sizeof(ibuf) - 3) {RETURN(693);}
|
||||
en64(param->extusername, ibuf, (int)strlen((char *)param->extusername));
|
||||
if( socksend(param, param->remsock, ibuf, (int)strlen((char *)ibuf), conf.timeouts[STRING_S]) <= 0 ||
|
||||
socksend(param, param->remsock, (unsigned char *)"\r\n", 2, conf.timeouts[STRING_S])!=2)
|
||||
{RETURN(699);}
|
||||
i = sockgetlinebuf(param, SERVER, srvbuf, sizeof(srvbuf) - 1, '\n', conf.timeouts[STRING_L]);
|
||||
if(i < 1 || *srvbuf != '+') {RETURN(699);}
|
||||
if(((int)strlen((char *)pb) + 2) / 3 * 4 + 1 > (int)sizeof(ibuf) - 3) {RETURN(693);}
|
||||
en64(pb, ibuf, (int)strlen((char *)pb));
|
||||
if( socksend(param, param->remsock, ibuf, (int)strlen((char *)ibuf), conf.timeouts[STRING_S]) <= 0 ||
|
||||
socksend(param, param->remsock, (unsigned char *)"\r\n", 2, conf.timeouts[STRING_S])!=2)
|
||||
{RETURN(699);}
|
||||
}
|
||||
else {
|
||||
if( socksend(param, param->remsock, tag, (int)strlen((char *)tag), conf.timeouts[STRING_S]) <= 0 ||
|
||||
socksend(param, param->remsock, (unsigned char *)" LOGIN ", 7, conf.timeouts[STRING_S])!= 7 ||
|
||||
socksend(param, param->remsock, param->extusername, (int)strlen((char *)param->extusername), conf.timeouts[STRING_S]) <= 0 ||
|
||||
socksend(param, param->remsock, (unsigned char *)" ", 1, conf.timeouts[STRING_S])!= 1 ||
|
||||
socksend(param, param->remsock, pb, (int)strlen((char *)pb), conf.timeouts[STRING_S]) <= 0 ||
|
||||
socksend(param, param->remsock, (unsigned char *)"\r\n", 2, conf.timeouts[STRING_S])!=2)
|
||||
{RETURN(699);}
|
||||
}
|
||||
param->statscli64 += (uint64_t)(strlen((char *)tag) + strlen((char *)param->extusername) + strlen((char *)pb) + 11);
|
||||
param->nwrites++;
|
||||
RETURN (mapsocket(param, 180));
|
||||
CLEANRET:
|
||||
|
||||
if(param->hostname&¶m->extusername) {
|
||||
sprintf((char *)buf, "%.128s@%.128s%c%hu", param->extusername, param->hostname, (*SAPORT(¶m->sinsr)==143)?0:':', ntohs(*SAPORT(¶m->sinsr)));
|
||||
dolog(param, buf);
|
||||
}
|
||||
else dolog(param, NULL);
|
||||
if(param->clisock != INVALID_SOCKET) {
|
||||
if ((param->res > 0 && param->res < 100) || (param->res > 691 && param->res <700)) {
|
||||
sprintf((char *)buf, "%.60s NO proxy error\r\n", *tag? (char *)tag : "*");
|
||||
socksend(param, param->clisock, buf, (int)strlen((char *)buf),conf.timeouts[STRING_S]);
|
||||
}
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
#ifdef WITHMAIN
|
||||
struct proxydef childdef = {
|
||||
imappchild,
|
||||
143,
|
||||
0,
|
||||
S_IMAPP,
|
||||
" -hdefault_host[:port] - use this host and port as default if no host specified\n -x - disable STARTTLS\n"
|
||||
|
||||
};
|
||||
#include "proxymain.c"
|
||||
#endif
|
||||
@@ -13,6 +13,12 @@
|
||||
https://blake2.net.
|
||||
*/
|
||||
|
||||
#if defined(WITH_WOLFSSL)
|
||||
#include <wolfssl/options.h>
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_BLAKE2B
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
@@ -377,3 +383,5 @@ fail:
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !HAVE_BLAKE2B */
|
||||
+276
@@ -0,0 +1,276 @@
|
||||
/*
|
||||
* This is an OpenSSL API compatible (but not ABI compatible) implementation
|
||||
* of the RSA Data Security, Inc. MD4 Message-Digest Algorithm (RFC 1320).
|
||||
*
|
||||
* Homepage:
|
||||
* https://openwall.info/wiki/people/solar/software/public-domain-source-code/md4
|
||||
*
|
||||
* Author:
|
||||
* Alexander Peslyak, better known as Solar Designer <solar at openwall.com>
|
||||
*
|
||||
* This software was written by Alexander Peslyak in 2001. No copyright is
|
||||
* claimed, and the software is hereby placed in the public domain.
|
||||
* In case this attempt to disclaim copyright and place the software in the
|
||||
* public domain is deemed null and void, then the software is
|
||||
* Copyright (c) 2001 Alexander Peslyak and it is hereby released to the
|
||||
* general public under the following terms:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted.
|
||||
*
|
||||
* There's ABSOLUTELY NO WARRANTY, express or implied.
|
||||
*
|
||||
* (This is a heavily cut-down "BSD license".)
|
||||
*
|
||||
* This differs from Colin Plumb's older public domain implementation in that
|
||||
* no exactly 32-bit integer data type is required (any 32-bit or wider
|
||||
* unsigned integer data type will do), there's no compile-time endianness
|
||||
* configuration, and the function prototypes match OpenSSL's. No code from
|
||||
* Colin Plumb's implementation has been reused; this comment merely compares
|
||||
* the properties of the two independent implementations.
|
||||
*
|
||||
* The primary goals of this implementation are portability and ease of use.
|
||||
* It is meant to be fast, but not as fast as possible. Some known
|
||||
* optimizations are not included to reduce source code size and avoid
|
||||
* compile-time configuration.
|
||||
*/
|
||||
|
||||
#if defined(WITH_WOLFSSL)
|
||||
#include <wolfssl/options.h>
|
||||
#endif
|
||||
|
||||
#if !defined(WITH_WOLFSSL) || defined(NO_MD4)
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "md4.h"
|
||||
|
||||
/*
|
||||
* The basic MD4 functions.
|
||||
*
|
||||
* F and G are optimized compared to their RFC 1320 definitions, with the
|
||||
* optimization for F borrowed from Colin Plumb's MD5 implementation.
|
||||
*/
|
||||
#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
|
||||
#define G(x, y, z) (((x) & ((y) | (z))) | ((y) & (z)))
|
||||
#define H(x, y, z) ((x) ^ (y) ^ (z))
|
||||
|
||||
/*
|
||||
* The MD4 transformation for all three rounds.
|
||||
*/
|
||||
#define STEP(f, a, b, c, d, x, s) \
|
||||
(a) += f((b), (c), (d)) + (x); \
|
||||
(a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s))));
|
||||
|
||||
/*
|
||||
* SET reads 4 input bytes in little-endian byte order and stores them in a
|
||||
* properly aligned word in host byte order.
|
||||
*
|
||||
* The check for little-endian architectures that tolerate unaligned memory
|
||||
* accesses is just an optimization. Nothing will break if it fails to detect
|
||||
* a suitable architecture.
|
||||
*
|
||||
* Unfortunately, this optimization may be a C strict aliasing rules violation
|
||||
* if the caller's data buffer has effective type that cannot be aliased by
|
||||
* MD4_u32plus. In practice, this problem may occur if these MD4 routines are
|
||||
* inlined into a calling function, or with future and dangerously advanced
|
||||
* link-time optimizations. For the time being, keeping these MD4 routines in
|
||||
* their own translation unit avoids the problem.
|
||||
*/
|
||||
#if defined(__i386__) || defined(__x86_64__) || defined(__vax__)
|
||||
#define SET(n) \
|
||||
(*(MD4_u32plus *)&ptr[(n) * 4])
|
||||
#define GET(n) \
|
||||
SET(n)
|
||||
#else
|
||||
#define SET(n) \
|
||||
(ctx->block[(n)] = \
|
||||
(MD4_u32plus)ptr[(n) * 4] | \
|
||||
((MD4_u32plus)ptr[(n) * 4 + 1] << 8) | \
|
||||
((MD4_u32plus)ptr[(n) * 4 + 2] << 16) | \
|
||||
((MD4_u32plus)ptr[(n) * 4 + 3] << 24))
|
||||
#define GET(n) \
|
||||
(ctx->block[(n)])
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This processes one or more 64-byte data blocks, but does NOT update the bit
|
||||
* counters. There are no alignment requirements.
|
||||
*/
|
||||
static const void *body(MD4_CTX *ctx, const void *data, size_t size)
|
||||
{
|
||||
const unsigned char *ptr;
|
||||
MD4_u32plus a, b, c, d;
|
||||
MD4_u32plus saved_a, saved_b, saved_c, saved_d;
|
||||
const MD4_u32plus ac1 = 0x5a827999, ac2 = 0x6ed9eba1;
|
||||
|
||||
ptr = (const unsigned char *)data;
|
||||
|
||||
a = ctx->a;
|
||||
b = ctx->b;
|
||||
c = ctx->c;
|
||||
d = ctx->d;
|
||||
|
||||
do {
|
||||
saved_a = a;
|
||||
saved_b = b;
|
||||
saved_c = c;
|
||||
saved_d = d;
|
||||
|
||||
/* Round 1 */
|
||||
STEP(F, a, b, c, d, SET(0), 3)
|
||||
STEP(F, d, a, b, c, SET(1), 7)
|
||||
STEP(F, c, d, a, b, SET(2), 11)
|
||||
STEP(F, b, c, d, a, SET(3), 19)
|
||||
STEP(F, a, b, c, d, SET(4), 3)
|
||||
STEP(F, d, a, b, c, SET(5), 7)
|
||||
STEP(F, c, d, a, b, SET(6), 11)
|
||||
STEP(F, b, c, d, a, SET(7), 19)
|
||||
STEP(F, a, b, c, d, SET(8), 3)
|
||||
STEP(F, d, a, b, c, SET(9), 7)
|
||||
STEP(F, c, d, a, b, SET(10), 11)
|
||||
STEP(F, b, c, d, a, SET(11), 19)
|
||||
STEP(F, a, b, c, d, SET(12), 3)
|
||||
STEP(F, d, a, b, c, SET(13), 7)
|
||||
STEP(F, c, d, a, b, SET(14), 11)
|
||||
STEP(F, b, c, d, a, SET(15), 19)
|
||||
|
||||
/* Round 2 */
|
||||
STEP(G, a, b, c, d, GET(0) + ac1, 3)
|
||||
STEP(G, d, a, b, c, GET(4) + ac1, 5)
|
||||
STEP(G, c, d, a, b, GET(8) + ac1, 9)
|
||||
STEP(G, b, c, d, a, GET(12) + ac1, 13)
|
||||
STEP(G, a, b, c, d, GET(1) + ac1, 3)
|
||||
STEP(G, d, a, b, c, GET(5) + ac1, 5)
|
||||
STEP(G, c, d, a, b, GET(9) + ac1, 9)
|
||||
STEP(G, b, c, d, a, GET(13) + ac1, 13)
|
||||
STEP(G, a, b, c, d, GET(2) + ac1, 3)
|
||||
STEP(G, d, a, b, c, GET(6) + ac1, 5)
|
||||
STEP(G, c, d, a, b, GET(10) + ac1, 9)
|
||||
STEP(G, b, c, d, a, GET(14) + ac1, 13)
|
||||
STEP(G, a, b, c, d, GET(3) + ac1, 3)
|
||||
STEP(G, d, a, b, c, GET(7) + ac1, 5)
|
||||
STEP(G, c, d, a, b, GET(11) + ac1, 9)
|
||||
STEP(G, b, c, d, a, GET(15) + ac1, 13)
|
||||
|
||||
/* Round 3 */
|
||||
STEP(H, a, b, c, d, GET(0) + ac2, 3)
|
||||
STEP(H, d, a, b, c, GET(8) + ac2, 9)
|
||||
STEP(H, c, d, a, b, GET(4) + ac2, 11)
|
||||
STEP(H, b, c, d, a, GET(12) + ac2, 15)
|
||||
STEP(H, a, b, c, d, GET(2) + ac2, 3)
|
||||
STEP(H, d, a, b, c, GET(10) + ac2, 9)
|
||||
STEP(H, c, d, a, b, GET(6) + ac2, 11)
|
||||
STEP(H, b, c, d, a, GET(14) + ac2, 15)
|
||||
STEP(H, a, b, c, d, GET(1) + ac2, 3)
|
||||
STEP(H, d, a, b, c, GET(9) + ac2, 9)
|
||||
STEP(H, c, d, a, b, GET(5) + ac2, 11)
|
||||
STEP(H, b, c, d, a, GET(13) + ac2, 15)
|
||||
STEP(H, a, b, c, d, GET(3) + ac2, 3)
|
||||
STEP(H, d, a, b, c, GET(11) + ac2, 9)
|
||||
STEP(H, c, d, a, b, GET(7) + ac2, 11)
|
||||
STEP(H, b, c, d, a, GET(15) + ac2, 15)
|
||||
|
||||
a += saved_a;
|
||||
b += saved_b;
|
||||
c += saved_c;
|
||||
d += saved_d;
|
||||
|
||||
ptr += 64;
|
||||
} while (size -= 64);
|
||||
|
||||
ctx->a = a;
|
||||
ctx->b = b;
|
||||
ctx->c = c;
|
||||
ctx->d = d;
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void MD4_Init(MD4_CTX *ctx)
|
||||
{
|
||||
ctx->a = 0x67452301;
|
||||
ctx->b = 0xefcdab89;
|
||||
ctx->c = 0x98badcfe;
|
||||
ctx->d = 0x10325476;
|
||||
|
||||
ctx->lo = 0;
|
||||
ctx->hi = 0;
|
||||
}
|
||||
|
||||
void MD4_Update(MD4_CTX *ctx, const void *data, size_t size)
|
||||
{
|
||||
MD4_u32plus saved_lo;
|
||||
size_t used, available;
|
||||
|
||||
saved_lo = ctx->lo;
|
||||
if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo)
|
||||
ctx->hi++;
|
||||
ctx->hi += (MD4_u32plus)(size >> 29);
|
||||
|
||||
used = saved_lo & 0x3f;
|
||||
|
||||
if (used) {
|
||||
available = 64 - used;
|
||||
|
||||
if (size < available) {
|
||||
memcpy(&ctx->buffer[used], data, size);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(&ctx->buffer[used], data, available);
|
||||
data = (const unsigned char *)data + available;
|
||||
size -= available;
|
||||
body(ctx, ctx->buffer, 64);
|
||||
}
|
||||
|
||||
if (size >= 64) {
|
||||
data = body(ctx, data, size & ~(size_t)0x3f);
|
||||
size &= 0x3f;
|
||||
}
|
||||
|
||||
memcpy(ctx->buffer, data, size);
|
||||
}
|
||||
|
||||
#define OUT(dst, src) \
|
||||
(dst)[0] = (unsigned char)(src); \
|
||||
(dst)[1] = (unsigned char)((src) >> 8); \
|
||||
(dst)[2] = (unsigned char)((src) >> 16); \
|
||||
(dst)[3] = (unsigned char)((src) >> 24);
|
||||
|
||||
void MD4_Final(unsigned char *result, MD4_CTX *ctx)
|
||||
{
|
||||
size_t used, available;
|
||||
|
||||
used = ctx->lo & 0x3f;
|
||||
|
||||
ctx->buffer[used++] = 0x80;
|
||||
|
||||
available = 64 - used;
|
||||
|
||||
if (available < 8) {
|
||||
memset(&ctx->buffer[used], 0, available);
|
||||
body(ctx, ctx->buffer, 64);
|
||||
used = 0;
|
||||
available = 64;
|
||||
}
|
||||
|
||||
memset(&ctx->buffer[used], 0, available - 8);
|
||||
|
||||
ctx->lo <<= 3;
|
||||
OUT(&ctx->buffer[56], ctx->lo)
|
||||
OUT(&ctx->buffer[60], ctx->hi)
|
||||
|
||||
body(ctx, ctx->buffer, 64);
|
||||
|
||||
OUT(&result[0], ctx->a)
|
||||
OUT(&result[4], ctx->b)
|
||||
OUT(&result[8], ctx->c)
|
||||
OUT(&result[12], ctx->d)
|
||||
|
||||
#if 0
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* !WITH_WOLFSSL || NO_MD4 */
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* This is an OpenSSL API compatible (but not ABI compatible) implementation
|
||||
* of the RSA Data Security, Inc. MD4 Message-Digest Algorithm (RFC 1320).
|
||||
*
|
||||
* Homepage:
|
||||
* https://openwall.info/wiki/people/solar/software/public-domain-source-code/md4
|
||||
*
|
||||
* Author:
|
||||
* Alexander Peslyak, better known as Solar Designer <solar at openwall.com>
|
||||
*
|
||||
* This software was written by Alexander Peslyak in 2001. No copyright is
|
||||
* claimed, and the software is hereby placed in the public domain.
|
||||
* In case this attempt to disclaim copyright and place the software in the
|
||||
* public domain is deemed null and void, then the software is
|
||||
* Copyright (c) 2001 Alexander Peslyak and it is hereby released to the
|
||||
* general public under the following terms:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted.
|
||||
*
|
||||
* There's ABSOLUTELY NO WARRANTY, express or implied.
|
||||
*
|
||||
* See md4.c for more information.
|
||||
*/
|
||||
|
||||
#ifndef _MD4_H
|
||||
#define _MD4_H
|
||||
|
||||
#ifdef WITH_WOLFSSL
|
||||
#include <wolfssl/options.h>
|
||||
#endif
|
||||
|
||||
#if defined(WITH_WOLFSSL) && !defined(NO_MD4)
|
||||
#include <wolfssl/openssl/md4.h>
|
||||
#else
|
||||
|
||||
#include <stddef.h> /* for size_t */
|
||||
|
||||
/* Any 32-bit or wider unsigned integer data type will do */
|
||||
typedef unsigned int MD4_u32plus;
|
||||
|
||||
typedef struct {
|
||||
MD4_u32plus lo, hi;
|
||||
MD4_u32plus a, b, c, d;
|
||||
unsigned char buffer[64];
|
||||
#if !(defined(__i386__) || defined(__x86_64__) || defined(__vax__))
|
||||
MD4_u32plus block[16];
|
||||
#endif
|
||||
} MD4_CTX;
|
||||
|
||||
/* Remap public symbols to a 3proxy-private namespace so the bundled
|
||||
implementation does not collide with OpenSSL/libcrypto's MD4 symbols
|
||||
when statically linked. Callers keep using the MD4_* names. */
|
||||
#define MD4_Init _3proxy_MD4_Init
|
||||
#define MD4_Update _3proxy_MD4_Update
|
||||
#define MD4_Final _3proxy_MD4_Final
|
||||
|
||||
extern void MD4_Init(MD4_CTX *ctx);
|
||||
extern void MD4_Update(MD4_CTX *ctx, const void *data, size_t size);
|
||||
extern void MD4_Final(unsigned char *result, MD4_CTX *ctx);
|
||||
|
||||
#endif /* !WITH_WOLFSSL */
|
||||
|
||||
#endif
|
||||
+295
@@ -0,0 +1,295 @@
|
||||
/*
|
||||
* This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
|
||||
* MD5 Message-Digest Algorithm (RFC 1321).
|
||||
*
|
||||
* Homepage:
|
||||
* http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5
|
||||
*
|
||||
* Author:
|
||||
* Alexander Peslyak, better known as Solar Designer <solar at openwall.com>
|
||||
*
|
||||
* This software was written by Alexander Peslyak in 2001. No copyright is
|
||||
* claimed, and the software is hereby placed in the public domain.
|
||||
* In case this attempt to disclaim copyright and place the software in the
|
||||
* public domain is deemed null and void, then the software is
|
||||
* Copyright (c) 2001 Alexander Peslyak and it is hereby released to the
|
||||
* general public under the following terms:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted.
|
||||
*
|
||||
* There's ABSOLUTELY NO WARRANTY, express or implied.
|
||||
*
|
||||
* (This is a heavily cut-down "BSD license".)
|
||||
*
|
||||
* This differs from Colin Plumb's older public domain implementation in that
|
||||
* no exactly 32-bit integer data type is required (any 32-bit or wider
|
||||
* unsigned integer data type will do), there's no compile-time endianness
|
||||
* configuration, and the function prototypes match OpenSSL's. No code from
|
||||
* Colin Plumb's implementation has been reused; this comment merely compares
|
||||
* the properties of the two independent implementations.
|
||||
*
|
||||
* The primary goals of this implementation are portability and ease of use.
|
||||
* It is meant to be fast, but not as fast as possible. Some known
|
||||
* optimizations are not included to reduce source code size and avoid
|
||||
* compile-time configuration.
|
||||
*/
|
||||
|
||||
#if defined(WITH_WOLFSSL)
|
||||
#include <wolfssl/options.h>
|
||||
#endif
|
||||
|
||||
#if !defined(WITH_WOLFSSL) || defined(NO_MD5)
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "md5.h"
|
||||
|
||||
/*
|
||||
* The basic MD5 functions.
|
||||
*
|
||||
* F and G are optimized compared to their RFC 1321 definitions for
|
||||
* architectures that lack an AND-NOT instruction, just like in Colin Plumb's
|
||||
* implementation.
|
||||
*/
|
||||
#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
|
||||
#define G(x, y, z) ((y) ^ ((z) & ((x) ^ (y))))
|
||||
#define H(x, y, z) (((x) ^ (y)) ^ (z))
|
||||
#define H2(x, y, z) ((x) ^ ((y) ^ (z)))
|
||||
#define I(x, y, z) ((y) ^ ((x) | ~(z)))
|
||||
|
||||
/*
|
||||
* The MD5 transformation for all four rounds.
|
||||
*/
|
||||
#define STEP(f, a, b, c, d, x, t, s) \
|
||||
(a) += f((b), (c), (d)) + (x) + (t); \
|
||||
(a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \
|
||||
(a) += (b);
|
||||
|
||||
/*
|
||||
* SET reads 4 input bytes in little-endian byte order and stores them in a
|
||||
* properly aligned word in host byte order.
|
||||
*
|
||||
* The check for little-endian architectures that tolerate unaligned memory
|
||||
* accesses is just an optimization. Nothing will break if it fails to detect
|
||||
* a suitable architecture.
|
||||
*
|
||||
* Unfortunately, this optimization may be a C strict aliasing rules violation
|
||||
* if the caller's data buffer has effective type that cannot be aliased by
|
||||
* MD5_u32plus. In practice, this problem may occur if these MD5 routines are
|
||||
* inlined into a calling function, or with future and dangerously advanced
|
||||
* link-time optimizations. For the time being, keeping these MD5 routines in
|
||||
* their own translation unit avoids the problem.
|
||||
*/
|
||||
#if defined(__i386__) || defined(__x86_64__) || defined(__vax__)
|
||||
#define SET(n) \
|
||||
(*(MD5_u32plus *)&ptr[(n) * 4])
|
||||
#define GET(n) \
|
||||
SET(n)
|
||||
#else
|
||||
#define SET(n) \
|
||||
(ctx->block[(n)] = \
|
||||
(MD5_u32plus)ptr[(n) * 4] | \
|
||||
((MD5_u32plus)ptr[(n) * 4 + 1] << 8) | \
|
||||
((MD5_u32plus)ptr[(n) * 4 + 2] << 16) | \
|
||||
((MD5_u32plus)ptr[(n) * 4 + 3] << 24))
|
||||
#define GET(n) \
|
||||
(ctx->block[(n)])
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This processes one or more 64-byte data blocks, but does NOT update the bit
|
||||
* counters. There are no alignment requirements.
|
||||
*/
|
||||
static const void *body(MD5_CTX *ctx, const void *data, unsigned long size)
|
||||
{
|
||||
const unsigned char *ptr;
|
||||
MD5_u32plus a, b, c, d;
|
||||
MD5_u32plus saved_a, saved_b, saved_c, saved_d;
|
||||
|
||||
ptr = (const unsigned char *)data;
|
||||
|
||||
a = ctx->a;
|
||||
b = ctx->b;
|
||||
c = ctx->c;
|
||||
d = ctx->d;
|
||||
|
||||
do {
|
||||
saved_a = a;
|
||||
saved_b = b;
|
||||
saved_c = c;
|
||||
saved_d = d;
|
||||
|
||||
/* Round 1 */
|
||||
STEP(F, a, b, c, d, SET(0), 0xd76aa478, 7)
|
||||
STEP(F, d, a, b, c, SET(1), 0xe8c7b756, 12)
|
||||
STEP(F, c, d, a, b, SET(2), 0x242070db, 17)
|
||||
STEP(F, b, c, d, a, SET(3), 0xc1bdceee, 22)
|
||||
STEP(F, a, b, c, d, SET(4), 0xf57c0faf, 7)
|
||||
STEP(F, d, a, b, c, SET(5), 0x4787c62a, 12)
|
||||
STEP(F, c, d, a, b, SET(6), 0xa8304613, 17)
|
||||
STEP(F, b, c, d, a, SET(7), 0xfd469501, 22)
|
||||
STEP(F, a, b, c, d, SET(8), 0x698098d8, 7)
|
||||
STEP(F, d, a, b, c, SET(9), 0x8b44f7af, 12)
|
||||
STEP(F, c, d, a, b, SET(10), 0xffff5bb1, 17)
|
||||
STEP(F, b, c, d, a, SET(11), 0x895cd7be, 22)
|
||||
STEP(F, a, b, c, d, SET(12), 0x6b901122, 7)
|
||||
STEP(F, d, a, b, c, SET(13), 0xfd987193, 12)
|
||||
STEP(F, c, d, a, b, SET(14), 0xa679438e, 17)
|
||||
STEP(F, b, c, d, a, SET(15), 0x49b40821, 22)
|
||||
|
||||
/* Round 2 */
|
||||
STEP(G, a, b, c, d, GET(1), 0xf61e2562, 5)
|
||||
STEP(G, d, a, b, c, GET(6), 0xc040b340, 9)
|
||||
STEP(G, c, d, a, b, GET(11), 0x265e5a51, 14)
|
||||
STEP(G, b, c, d, a, GET(0), 0xe9b6c7aa, 20)
|
||||
STEP(G, a, b, c, d, GET(5), 0xd62f105d, 5)
|
||||
STEP(G, d, a, b, c, GET(10), 0x02441453, 9)
|
||||
STEP(G, c, d, a, b, GET(15), 0xd8a1e681, 14)
|
||||
STEP(G, b, c, d, a, GET(4), 0xe7d3fbc8, 20)
|
||||
STEP(G, a, b, c, d, GET(9), 0x21e1cde6, 5)
|
||||
STEP(G, d, a, b, c, GET(14), 0xc33707d6, 9)
|
||||
STEP(G, c, d, a, b, GET(3), 0xf4d50d87, 14)
|
||||
STEP(G, b, c, d, a, GET(8), 0x455a14ed, 20)
|
||||
STEP(G, a, b, c, d, GET(13), 0xa9e3e905, 5)
|
||||
STEP(G, d, a, b, c, GET(2), 0xfcefa3f8, 9)
|
||||
STEP(G, c, d, a, b, GET(7), 0x676f02d9, 14)
|
||||
STEP(G, b, c, d, a, GET(12), 0x8d2a4c8a, 20)
|
||||
|
||||
/* Round 3 */
|
||||
STEP(H, a, b, c, d, GET(5), 0xfffa3942, 4)
|
||||
STEP(H2, d, a, b, c, GET(8), 0x8771f681, 11)
|
||||
STEP(H, c, d, a, b, GET(11), 0x6d9d6122, 16)
|
||||
STEP(H2, b, c, d, a, GET(14), 0xfde5380c, 23)
|
||||
STEP(H, a, b, c, d, GET(1), 0xa4beea44, 4)
|
||||
STEP(H2, d, a, b, c, GET(4), 0x4bdecfa9, 11)
|
||||
STEP(H, c, d, a, b, GET(7), 0xf6bb4b60, 16)
|
||||
STEP(H2, b, c, d, a, GET(10), 0xbebfbc70, 23)
|
||||
STEP(H, a, b, c, d, GET(13), 0x289b7ec6, 4)
|
||||
STEP(H2, d, a, b, c, GET(0), 0xeaa127fa, 11)
|
||||
STEP(H, c, d, a, b, GET(3), 0xd4ef3085, 16)
|
||||
STEP(H2, b, c, d, a, GET(6), 0x04881d05, 23)
|
||||
STEP(H, a, b, c, d, GET(9), 0xd9d4d039, 4)
|
||||
STEP(H2, d, a, b, c, GET(12), 0xe6db99e5, 11)
|
||||
STEP(H, c, d, a, b, GET(15), 0x1fa27cf8, 16)
|
||||
STEP(H2, b, c, d, a, GET(2), 0xc4ac5665, 23)
|
||||
|
||||
/* Round 4 */
|
||||
STEP(I, a, b, c, d, GET(0), 0xf4292244, 6)
|
||||
STEP(I, d, a, b, c, GET(7), 0x432aff97, 10)
|
||||
STEP(I, c, d, a, b, GET(14), 0xab9423a7, 15)
|
||||
STEP(I, b, c, d, a, GET(5), 0xfc93a039, 21)
|
||||
STEP(I, a, b, c, d, GET(12), 0x655b59c3, 6)
|
||||
STEP(I, d, a, b, c, GET(3), 0x8f0ccc92, 10)
|
||||
STEP(I, c, d, a, b, GET(10), 0xffeff47d, 15)
|
||||
STEP(I, b, c, d, a, GET(1), 0x85845dd1, 21)
|
||||
STEP(I, a, b, c, d, GET(8), 0x6fa87e4f, 6)
|
||||
STEP(I, d, a, b, c, GET(15), 0xfe2ce6e0, 10)
|
||||
STEP(I, c, d, a, b, GET(6), 0xa3014314, 15)
|
||||
STEP(I, b, c, d, a, GET(13), 0x4e0811a1, 21)
|
||||
STEP(I, a, b, c, d, GET(4), 0xf7537e82, 6)
|
||||
STEP(I, d, a, b, c, GET(11), 0xbd3af235, 10)
|
||||
STEP(I, c, d, a, b, GET(2), 0x2ad7d2bb, 15)
|
||||
STEP(I, b, c, d, a, GET(9), 0xeb86d391, 21)
|
||||
|
||||
a += saved_a;
|
||||
b += saved_b;
|
||||
c += saved_c;
|
||||
d += saved_d;
|
||||
|
||||
ptr += 64;
|
||||
} while (size -= 64);
|
||||
|
||||
ctx->a = a;
|
||||
ctx->b = b;
|
||||
ctx->c = c;
|
||||
ctx->d = d;
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void MD5_Init(MD5_CTX *ctx)
|
||||
{
|
||||
ctx->a = 0x67452301;
|
||||
ctx->b = 0xefcdab89;
|
||||
ctx->c = 0x98badcfe;
|
||||
ctx->d = 0x10325476;
|
||||
|
||||
ctx->lo = 0;
|
||||
ctx->hi = 0;
|
||||
}
|
||||
|
||||
void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size)
|
||||
{
|
||||
MD5_u32plus saved_lo;
|
||||
unsigned long used, available;
|
||||
|
||||
saved_lo = ctx->lo;
|
||||
if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo)
|
||||
ctx->hi++;
|
||||
ctx->hi += size >> 29;
|
||||
|
||||
used = saved_lo & 0x3f;
|
||||
|
||||
if (used) {
|
||||
available = 64 - used;
|
||||
|
||||
if (size < available) {
|
||||
memcpy(&ctx->buffer[used], data, size);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(&ctx->buffer[used], data, available);
|
||||
data = (const unsigned char *)data + available;
|
||||
size -= available;
|
||||
body(ctx, ctx->buffer, 64);
|
||||
}
|
||||
|
||||
if (size >= 64) {
|
||||
data = body(ctx, data, size & ~(unsigned long)0x3f);
|
||||
size &= 0x3f;
|
||||
}
|
||||
|
||||
memcpy(ctx->buffer, data, size);
|
||||
}
|
||||
|
||||
#define OUT(dst, src) \
|
||||
(dst)[0] = (unsigned char)(src); \
|
||||
(dst)[1] = (unsigned char)((src) >> 8); \
|
||||
(dst)[2] = (unsigned char)((src) >> 16); \
|
||||
(dst)[3] = (unsigned char)((src) >> 24);
|
||||
|
||||
void MD5_Final(unsigned char *result, MD5_CTX *ctx)
|
||||
{
|
||||
unsigned long used, available;
|
||||
|
||||
used = ctx->lo & 0x3f;
|
||||
|
||||
ctx->buffer[used++] = 0x80;
|
||||
|
||||
available = 64 - used;
|
||||
|
||||
if (available < 8) {
|
||||
memset(&ctx->buffer[used], 0, available);
|
||||
body(ctx, ctx->buffer, 64);
|
||||
used = 0;
|
||||
available = 64;
|
||||
}
|
||||
|
||||
memset(&ctx->buffer[used], 0, available - 8);
|
||||
|
||||
ctx->lo <<= 3;
|
||||
OUT(&ctx->buffer[56], ctx->lo)
|
||||
OUT(&ctx->buffer[60], ctx->hi)
|
||||
|
||||
body(ctx, ctx->buffer, 64);
|
||||
|
||||
OUT(&result[0], ctx->a)
|
||||
OUT(&result[4], ctx->b)
|
||||
OUT(&result[8], ctx->c)
|
||||
OUT(&result[12], ctx->d)
|
||||
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
}
|
||||
|
||||
#endif /* !WITH_WOLFSSL || NO_MD5 */
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
|
||||
* MD5 Message-Digest Algorithm (RFC 1321).
|
||||
*
|
||||
* Homepage:
|
||||
* http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5
|
||||
*
|
||||
* Author:
|
||||
* Alexander Peslyak, better known as Solar Designer <solar at openwall.com>
|
||||
*
|
||||
* This software was written by Alexander Peslyak in 2001. No copyright is
|
||||
* claimed, and the software is hereby placed in the public domain.
|
||||
* In case this attempt to disclaim copyright and place the software in the
|
||||
* public domain is deemed null and void, then the software is
|
||||
* Copyright (c) 2001 Alexander Peslyak and it is hereby released to the
|
||||
* general public under the following terms:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted.
|
||||
*
|
||||
* There's ABSOLUTELY NO WARRANTY, express or implied.
|
||||
*
|
||||
* See md5.c for more information.
|
||||
*/
|
||||
|
||||
#ifndef _MD5_H
|
||||
#define _MD5_H
|
||||
|
||||
#ifdef WITH_WOLFSSL
|
||||
#include <wolfssl/options.h>
|
||||
#endif
|
||||
|
||||
#if defined(WITH_WOLFSSL) && !defined(NO_MD5)
|
||||
#include <wolfssl/openssl/md5.h>
|
||||
#else
|
||||
|
||||
/* Any 32-bit or wider unsigned integer data type will do */
|
||||
typedef unsigned int MD5_u32plus;
|
||||
|
||||
typedef struct {
|
||||
MD5_u32plus lo, hi;
|
||||
MD5_u32plus a, b, c, d;
|
||||
unsigned char buffer[64];
|
||||
MD5_u32plus block[16];
|
||||
} MD5_CTX;
|
||||
|
||||
/* Remap public symbols to a 3proxy-private namespace so the bundled
|
||||
implementation does not collide with OpenSSL/libcrypto's MD5 symbols
|
||||
when statically linked. Callers keep using the MD5_* names. */
|
||||
#define MD5_Init _3proxy_MD5_Init
|
||||
#define MD5_Update _3proxy_MD5_Update
|
||||
#define MD5_Final _3proxy_MD5_Final
|
||||
|
||||
extern void MD5_Init(MD5_CTX *ctx);
|
||||
extern void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size);
|
||||
extern void MD5_Final(unsigned char *result, MD5_CTX *ctx);
|
||||
|
||||
#endif /* !WITH_WOLFSSL */
|
||||
|
||||
#endif
|
||||
@@ -338,7 +338,7 @@ void lognone(struct clientparam * param, const unsigned char *s) {
|
||||
clearstat(param);
|
||||
}
|
||||
|
||||
void logstdout(struct clientparam * param, const unsigned char *s) {
|
||||
NOINLINE void logstdout(struct clientparam * param, const unsigned char *s) {
|
||||
FILE *log;
|
||||
unsigned char tmpbuf[8192];
|
||||
|
||||
|
||||
+211
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
3APA3A simplest proxy server
|
||||
(c) 2002-2026 by Vladimir Dubrovin <vlad@3proxy.org>
|
||||
|
||||
please read License Agreement
|
||||
|
||||
MD4/MD5/BLAKE2 hash implementation.
|
||||
- Windows (no wolfSSL): CryptoAPI (CAPI) for MD4/MD5; bundled BLAKE2.
|
||||
- wolfSSL: wolfCrypt for MD4/MD5 (OpenSSL compat) and BLAKE2 (native wc_*).
|
||||
- Other: bundled public-domain MD4/MD5 + bundled BLAKE2 reference.
|
||||
*/
|
||||
#include "mdhash.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/* ----- BLAKE2 backend selection ----- */
|
||||
/* wolfSSL may provide BLAKE2 natively (HAVE_BLAKE2B). If not enabled
|
||||
(e.g. vcpkg port), fall back to the bundled reference implementation. */
|
||||
#ifdef WITH_WOLFSSL
|
||||
#include <wolfssl/options.h>
|
||||
#ifdef HAVE_BLAKE2B
|
||||
#include <wolfssl/wolfcrypt/blake2.h>
|
||||
#define MDH_BLAKE2_BACKEND_WOLFSSL
|
||||
#else
|
||||
#include "libs/blake2.h"
|
||||
#endif
|
||||
#else
|
||||
#include "libs/blake2.h"
|
||||
#endif
|
||||
|
||||
/* ----- MD4/MD5 backend selection ----- */
|
||||
#if defined(_WIN32) && !defined(WITH_WOLFSSL)
|
||||
#define MDH_MD_BACKEND_CAPI
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <wincrypt.h>
|
||||
#else
|
||||
#include "libs/md4.h"
|
||||
#include "libs/md5.h"
|
||||
#endif
|
||||
|
||||
struct mdh_ctx {
|
||||
mdh_alg alg;
|
||||
unsigned int outlen;
|
||||
#ifdef MDH_MD_BACKEND_CAPI
|
||||
HCRYPTPROV hProv;
|
||||
HCRYPTHASH hHash;
|
||||
#else
|
||||
union {
|
||||
MD4_CTX md4;
|
||||
MD5_CTX md5;
|
||||
} u;
|
||||
#endif
|
||||
#ifdef MDH_BLAKE2_BACKEND_WOLFSSL
|
||||
Blake2b blake2;
|
||||
#else
|
||||
blake2b_state blake2;
|
||||
#endif
|
||||
};
|
||||
|
||||
mdh_ctx *mdh_init(mdh_alg alg, unsigned int outlen)
|
||||
{
|
||||
mdh_ctx *c = (mdh_ctx *)malloc(sizeof(mdh_ctx));
|
||||
if(!c) return NULL;
|
||||
memset(c, 0, sizeof(*c));
|
||||
c->alg = alg;
|
||||
c->outlen = outlen;
|
||||
|
||||
switch(alg) {
|
||||
case MDH_MD4:
|
||||
#ifdef MDH_MD_BACKEND_CAPI
|
||||
if(!CryptAcquireContext(&c->hProv, NULL, NULL, PROV_RSA_FULL,
|
||||
CRYPT_VERIFYCONTEXT)) {
|
||||
free(c);
|
||||
return NULL;
|
||||
}
|
||||
if(!CryptCreateHash(c->hProv, CALG_MD4, 0, 0, &c->hHash)) {
|
||||
CryptReleaseContext(c->hProv, 0);
|
||||
free(c);
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
MD4_Init(&c->u.md4);
|
||||
#endif
|
||||
break;
|
||||
case MDH_MD5:
|
||||
#ifdef MDH_MD_BACKEND_CAPI
|
||||
if(!CryptAcquireContext(&c->hProv, NULL, NULL, PROV_RSA_FULL,
|
||||
CRYPT_VERIFYCONTEXT)) {
|
||||
free(c);
|
||||
return NULL;
|
||||
}
|
||||
if(!CryptCreateHash(c->hProv, CALG_MD5, 0, 0, &c->hHash)) {
|
||||
CryptReleaseContext(c->hProv, 0);
|
||||
free(c);
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
MD5_Init(&c->u.md5);
|
||||
#endif
|
||||
break;
|
||||
case MDH_BLAKE2:
|
||||
if(!outlen || outlen > 64) {
|
||||
free(c);
|
||||
return NULL;
|
||||
}
|
||||
#ifdef MDH_BLAKE2_BACKEND_WOLFSSL
|
||||
if(wc_InitBlake2b(&c->blake2, outlen) != 0) {
|
||||
free(c);
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
if(blake2b_init(&c->blake2, outlen) != 0) {
|
||||
free(c);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
free(c);
|
||||
return NULL;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
int mdh_update(mdh_ctx *c, const void *data, unsigned int len)
|
||||
{
|
||||
if(!c) return 0;
|
||||
if(len == 0) return 1;
|
||||
switch(c->alg) {
|
||||
case MDH_MD4:
|
||||
#ifdef MDH_MD_BACKEND_CAPI
|
||||
return CryptHashData(c->hHash, (BYTE *)data, len, 0) ? 1 : 0;
|
||||
#else
|
||||
MD4_Update(&c->u.md4, data, (size_t)len);
|
||||
return 1;
|
||||
#endif
|
||||
case MDH_MD5:
|
||||
#ifdef MDH_MD_BACKEND_CAPI
|
||||
return CryptHashData(c->hHash, (BYTE *)data, len, 0) ? 1 : 0;
|
||||
#else
|
||||
MD5_Update(&c->u.md5, data, (unsigned long)len);
|
||||
return 1;
|
||||
#endif
|
||||
case MDH_BLAKE2:
|
||||
#ifdef MDH_BLAKE2_BACKEND_WOLFSSL
|
||||
return wc_Blake2bUpdate(&c->blake2, (const byte *)data, len) == 0;
|
||||
#else
|
||||
return blake2b_update(&c->blake2, data, len) == 0;
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mdh_final(mdh_ctx *c, unsigned char *out, unsigned int *outlen)
|
||||
{
|
||||
if(!c || !outlen) return 0;
|
||||
switch(c->alg) {
|
||||
case MDH_MD4:
|
||||
#ifdef MDH_MD_BACKEND_CAPI
|
||||
{
|
||||
DWORD l = (DWORD)*outlen;
|
||||
if(!CryptGetHashParam(c->hHash, HP_HASHVAL, out, &l, 0))
|
||||
return 0;
|
||||
*outlen = (unsigned int)l;
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
MD4_Final(out, &c->u.md4);
|
||||
*outlen = 16;
|
||||
return 1;
|
||||
#endif
|
||||
case MDH_MD5:
|
||||
#ifdef MDH_MD_BACKEND_CAPI
|
||||
{
|
||||
DWORD l = (DWORD)*outlen;
|
||||
if(!CryptGetHashParam(c->hHash, HP_HASHVAL, out, &l, 0))
|
||||
return 0;
|
||||
*outlen = (unsigned int)l;
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
MD5_Final(out, &c->u.md5);
|
||||
*outlen = 16;
|
||||
return 1;
|
||||
#endif
|
||||
case MDH_BLAKE2:
|
||||
if(*outlen < c->outlen) return 0;
|
||||
#ifdef MDH_BLAKE2_BACKEND_WOLFSSL
|
||||
if(wc_Blake2bFinal(&c->blake2, out, c->outlen) != 0)
|
||||
return 0;
|
||||
#else
|
||||
if(blake2b_final(&c->blake2, out, c->outlen) != 0)
|
||||
return 0;
|
||||
#endif
|
||||
*outlen = c->outlen;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mdh_free(mdh_ctx *c)
|
||||
{
|
||||
if(!c) return;
|
||||
#ifdef MDH_MD_BACKEND_CAPI
|
||||
if(c->hHash) CryptDestroyHash(c->hHash);
|
||||
if(c->hProv) CryptReleaseContext(c->hProv, 0);
|
||||
#endif
|
||||
memset(c, 0, sizeof(*c));
|
||||
free(c);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
3APA3A simplest proxy server
|
||||
(c) 2002-2026 by Vladimir Dubrovin <vlad@3proxy.org>
|
||||
|
||||
please read License Agreement
|
||||
|
||||
Internal MD4/MD5/BLAKE2 hash abstraction.
|
||||
- Windows (no wolfSSL): CryptoAPI (CAPI) for MD4/MD5; bundled BLAKE2.
|
||||
- wolfSSL: wolfCrypt for MD4/MD5 (OpenSSL compat) and BLAKE2 (native).
|
||||
- Other: bundled public-domain MD4/MD5 + bundled BLAKE2 reference.
|
||||
*/
|
||||
#ifndef _MDHASH_H
|
||||
#define _MDHASH_H
|
||||
|
||||
typedef enum { MDH_MD4, MDH_MD5, MDH_BLAKE2 } mdh_alg;
|
||||
|
||||
typedef struct mdh_ctx mdh_ctx;
|
||||
|
||||
/* alg selects the hash. outlen selects digest size:
|
||||
- MD4/MD5: outlen ignored (fixed 16 bytes).
|
||||
- BLAKE2: outlen is the requested digest length (1..64).
|
||||
Returns NULL on failure. */
|
||||
mdh_ctx *mdh_init(mdh_alg alg, unsigned int outlen);
|
||||
|
||||
/* Returns 1 on success, 0 on failure. */
|
||||
int mdh_update(mdh_ctx *c, const void *data, unsigned int len);
|
||||
|
||||
/* outlen is in/out: caller passes buffer size, receives hash length.
|
||||
Returns 1 on success, 0 on failure. */
|
||||
int mdh_final(mdh_ctx *c, unsigned char *out, unsigned int *outlen);
|
||||
|
||||
/* Safe to call with NULL. */
|
||||
void mdh_free(mdh_ctx *c);
|
||||
|
||||
#endif /* _MDHASH_H */
|
||||
+32
-17
@@ -214,6 +214,7 @@ struct pcre_filter_data {
|
||||
int users;
|
||||
pcre2_code * re;
|
||||
pcre2_match_data * match_data;
|
||||
pcre2_match_context * match_context;
|
||||
int action;
|
||||
char * replace;
|
||||
struct ace *acl;
|
||||
@@ -223,6 +224,7 @@ static void pcre_data_free(struct pcre_filter_data *pcrefd){
|
||||
_3proxy_mutex_lock(&pcre_mutex);
|
||||
pcrefd->users--;
|
||||
if(!pcrefd->users){
|
||||
if(pcrefd->match_context) pcre2_match_context_free(pcrefd->match_context);
|
||||
if(pcrefd->match_data) pcre2_match_data_free(pcrefd->match_data);
|
||||
if(pcrefd->re) pcre2_code_free(pcrefd->re);
|
||||
if(pcrefd->acl) pl->freeacl(pcrefd->acl);
|
||||
@@ -283,10 +285,12 @@ static FILTER_ACTION pcre_filter_buffer(void *fc, struct clientparam *param, uns
|
||||
if(!match) return CONTINUE;
|
||||
if(!pcrefd->re) return pcrefd->action;
|
||||
for(; offset < *length_p; nreplaces++){
|
||||
int repsz;
|
||||
|
||||
count = pcre2_match(pcrefd->re, (PCRE2_SPTR)*buf_p, *length_p, offset, 0, pcrefd->match_data, NULL);
|
||||
count = pcre2_match(pcrefd->re, (PCRE2_SPTR)*buf_p, *length_p, offset, 0, pcrefd->match_data, pcrefd->match_context);
|
||||
if(count <= 0) break;
|
||||
ovector = pcre2_get_ovector_pointer(pcrefd->match_data);
|
||||
if(ovector[0] > (PCRE2_SIZE)*length_p || ovector[1] > (PCRE2_SIZE)*length_p || ovector[1] < ovector[0]) break;
|
||||
if(!(replace = pcrefd->replace) || param->nooverwritefilter) return pcrefd->action;
|
||||
|
||||
replen = *length_p - ovector[1];
|
||||
@@ -300,6 +304,8 @@ static FILTER_ACTION pcre_filter_buffer(void *fc, struct clientparam *param, uns
|
||||
num = atoi(replace);
|
||||
while(isnumber(*replace)) replace++;
|
||||
if(num > (count - 1)) continue;
|
||||
if(ovector[(num<<1)] == PCRE2_UNSET) continue;
|
||||
if(ovector[(num<<1) + 1] > (PCRE2_SIZE)*length_p || ovector[(num<<1)] > ovector[(num<<1) + 1]) continue;
|
||||
replen += (ovector[(num<<1) + 1] - ovector[(num<<1)]);
|
||||
}
|
||||
else {
|
||||
@@ -319,6 +325,8 @@ static FILTER_ACTION pcre_filter_buffer(void *fc, struct clientparam *param, uns
|
||||
replace ++;
|
||||
num = atoi(replace);
|
||||
if(num > (count - 1)) continue;
|
||||
if(ovector[(num<<1)] == PCRE2_UNSET) continue;
|
||||
if(ovector[(num<<1) + 1] > (PCRE2_SIZE)*length_p || ovector[(num<<1)] > ovector[(num<<1) + 1]) continue;
|
||||
memcpy(target, *buf_p + ovector[(num<<1)], ovector[(num<<1) + 1] - ovector[(num<<1)]);
|
||||
target += (ovector[(num<<1) + 1] - ovector[(num<<1)]);
|
||||
while(isnumber(*replace)) replace++;
|
||||
@@ -327,6 +335,7 @@ static FILTER_ACTION pcre_filter_buffer(void *fc, struct clientparam *param, uns
|
||||
*target++ = *replace++;
|
||||
}
|
||||
}
|
||||
repsz = (int)(target - tmpbuf);
|
||||
memcpy(target, *buf_p + ovector[1], *length_p - ovector[1]);
|
||||
if((ovector[0] + replen + 1) > *bufsize_p){
|
||||
newbuf = pl->mallocfunc(ovector[0] + replen + 1);
|
||||
@@ -343,10 +352,11 @@ static FILTER_ACTION pcre_filter_buffer(void *fc, struct clientparam *param, uns
|
||||
pl->freefunc(tmpbuf);
|
||||
(*buf_p)[ovector[0] + replen] = 0;
|
||||
*length_p = ovector[0] + replen;
|
||||
if(ovector[0] + replen <= offset){
|
||||
break;
|
||||
offset = ovector[0] + repsz;
|
||||
if(ovector[1] == ovector[0] && offset <= (int)ovector[0]){
|
||||
/* zero-width match with empty replacement: force progress */
|
||||
offset = ovector[1] + 1;
|
||||
}
|
||||
offset = ovector[0] + (int)strlen(pcrefd->replace);
|
||||
}
|
||||
return nreplaces? pcrefd->action : CONTINUE;
|
||||
#undef pcrefd
|
||||
@@ -360,7 +370,7 @@ static void pcre_filter_close(void *fo){
|
||||
pcre_data_free((struct pcre_filter_data *)fo);
|
||||
}
|
||||
|
||||
static int h_pcre(int argc, unsigned char **argv){
|
||||
int h_pcre(int argc, unsigned char **argv){
|
||||
int action = 0;
|
||||
pcre2_code *re = NULL;
|
||||
pcre2_match_data *match_data = NULL;
|
||||
@@ -442,6 +452,13 @@ static int h_pcre(int argc, unsigned char **argv){
|
||||
flt->acl = acl;
|
||||
flt->replace = replace;
|
||||
flt->users = 1;
|
||||
if(re){
|
||||
flt->match_context = pcre2_match_context_create(NULL);
|
||||
if(flt->match_context){
|
||||
pcre2_set_match_limit(flt->match_context, 1000000);
|
||||
pcre2_set_depth_limit(flt->match_context, 10000);
|
||||
}
|
||||
}
|
||||
newf->instance = "pcre";
|
||||
newf->data = flt;
|
||||
newf->filter_open = pcre_filter_open;
|
||||
@@ -467,7 +484,7 @@ static int h_pcre(int argc, unsigned char **argv){
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_pcre_rewrite(int argc, unsigned char **argv){
|
||||
int h_pcre_rewrite(int argc, unsigned char **argv){
|
||||
int action = 0;
|
||||
pcre2_code *re = NULL;
|
||||
pcre2_match_data *match_data = NULL;
|
||||
@@ -549,6 +566,13 @@ static int h_pcre_rewrite(int argc, unsigned char **argv){
|
||||
flt->acl = acl;
|
||||
flt->replace = replace;
|
||||
flt->users = 1;
|
||||
if(re){
|
||||
flt->match_context = pcre2_match_context_create(NULL);
|
||||
if(flt->match_context){
|
||||
pcre2_set_match_limit(flt->match_context, 1000000);
|
||||
pcre2_set_depth_limit(flt->match_context, 10000);
|
||||
}
|
||||
}
|
||||
newf->instance = "pcre";
|
||||
newf->data = flt;
|
||||
newf->filter_open = pcre_filter_open;
|
||||
@@ -574,7 +598,7 @@ static int h_pcre_rewrite(int argc, unsigned char **argv){
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_pcre_extend(int argc, unsigned char **argv){
|
||||
int h_pcre_extend(int argc, unsigned char **argv){
|
||||
struct ace *acl;
|
||||
if(!pcre_last_filter || !pcre_last_filter->data) return 1;
|
||||
acl = ((struct pcre_filter_data *)pcre_last_filter->data)->acl;
|
||||
@@ -585,7 +609,7 @@ static int h_pcre_extend(int argc, unsigned char **argv){
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_pcre_options(int argc, unsigned char **argv){
|
||||
int h_pcre_options(int argc, unsigned char **argv){
|
||||
int i,j;
|
||||
|
||||
pcre_options = 0;
|
||||
@@ -598,13 +622,6 @@ static int h_pcre_options(int argc, unsigned char **argv){
|
||||
}
|
||||
|
||||
|
||||
static struct commands pcre_commandhandlers[] = {
|
||||
{pcre_commandhandlers+1, "pcre", h_pcre, 4, 0},
|
||||
{pcre_commandhandlers+2, "pcre_rewrite", h_pcre_rewrite, 5, 0},
|
||||
{pcre_commandhandlers+3, "pcre_extend", h_pcre_extend, 2, 0},
|
||||
{NULL, "pcre_options", h_pcre_options, 2, 0}
|
||||
};
|
||||
|
||||
static struct symbol regexp_symbols[] = {
|
||||
{regexp_symbols+1, "pcre2_compile", (void*) pcre2_compile},
|
||||
{regexp_symbols+2, "pcre2_match", (void*) pcre2_match},
|
||||
@@ -622,8 +639,6 @@ void pcre_install(void){
|
||||
_3proxy_mutex_init(&pcre_mutex);
|
||||
regexp_symbols[2].next = pl->symbols.next;
|
||||
pl->symbols.next = regexp_symbols;
|
||||
pcre_commandhandlers[3].next = pl->commandhandlers->next;
|
||||
pl->commandhandlers->next = pcre_commandhandlers;
|
||||
pcre_first_filter.next = pl->conf->filters;
|
||||
pl->conf->filters = &pcre_first_filter;
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ struct symbol symbols[] = {
|
||||
{symbols+46, "make_ace", (void *) make_ace},
|
||||
{symbols+47, "freeacl", (void *) freeacl},
|
||||
{symbols+48, "handleredirect", (void *) handleredirect},
|
||||
{symbols+49, "imapp", (void *) imappchild},
|
||||
{NULL, "", NULL}
|
||||
};
|
||||
|
||||
|
||||
@@ -52,7 +52,6 @@ unsigned long preview = 0;
|
||||
char path[300];
|
||||
|
||||
static int counter = 0;
|
||||
static int timeo = 0;
|
||||
|
||||
static char * fp_stringtable[] = {
|
||||
/* 0 */ "HTTP/1.0 503 Service Unavailable\r\n"
|
||||
@@ -261,10 +260,6 @@ static void removefps(struct fp_stream * fps){
|
||||
fps->state = 0;
|
||||
}
|
||||
|
||||
static int WINAPI fp_connect(SOCKET s, const struct sockaddr *name, fp_size_t namelen){
|
||||
return sso._connect(sso.state, s, name, namelen);
|
||||
}
|
||||
|
||||
void processcallbacks(struct fp_stream *fps, int what, char *msg, int size){
|
||||
struct fp_callback *cb;
|
||||
int state;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
all: $(BUILDDIR)FilePlugin$(DLSUFFICS)
|
||||
|
||||
FilePlugin$(OBJSUFFICS): FilePlugin.c
|
||||
$(CC) $(DCFLAGS) $(CFLAGS) FilePlugin.c
|
||||
$(CC) $(CFLAGS) $(DCFLAGS) FilePlugin.c
|
||||
|
||||
$(BUILDDIR)FilePlugin$(DLSUFFICS): FilePlugin$(OBJSUFFICS)
|
||||
$(LN) $(LNOUT)../../$(BUILDDIR)FilePlugin$(DLSUFFICS) $(LDFLAGS) $(DLFLAGS) FilePlugin$(OBJSUFFICS)
|
||||
@@ -1,7 +1,7 @@
|
||||
all: $(BUILDDIR)ldapauth$(DLSUFFICS)
|
||||
|
||||
ldapauth$(OBJSUFFICS): ldapauth.c
|
||||
$(CC) $(DCFLAGS) $(CFLAGS) ldapauth.c
|
||||
$(CC) $(CFLAGS) $(DCFLAGS) ldapauth.c
|
||||
|
||||
$(BUILDDIR)ldapauth$(DLSUFFICS): ldapauth$(OBJSUFFICS)
|
||||
$(LN) $(LNOUT)../../$(BUILDDIR)ldapauth$(DLSUFFICS) $(LDFLAGS) $(DLFLAGS) $(LIBSPREFIX)ldap$(LIBSSUFFIX) ldapauth$(OBJSUFFICS)
|
||||
@@ -42,7 +42,7 @@ struct schedule myschedule;
|
||||
void lower (char *string)
|
||||
{
|
||||
int length, i;
|
||||
|
||||
|
||||
length = strlen(string);
|
||||
for (i=0; i<length; i++)
|
||||
{
|
||||
@@ -51,8 +51,56 @@ void lower (char *string)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* RFC 4514 escaping for DN attribute values. Returns dst, NULL on overflow. */
|
||||
static char * ldap_escape_dn(const char *src, char *dst, int dstlen)
|
||||
{
|
||||
int j = 0;
|
||||
unsigned char c;
|
||||
for (; *src; src++){
|
||||
c = (unsigned char)*src;
|
||||
if(c == ',' || c == '+' || c == '"' || c == '\\' || c == '<' || c == '>' || c == ';' || c == '=' || c < 0x20 || c == 0x7f){
|
||||
if(j + 3 >= dstlen) return NULL;
|
||||
sprintf(dst + j, "\\%02X", c);
|
||||
j += 3;
|
||||
}
|
||||
else {
|
||||
if(j + 1 >= dstlen) return NULL;
|
||||
dst[j++] = (char)c;
|
||||
}
|
||||
}
|
||||
dst[j] = 0;
|
||||
return dst;
|
||||
}
|
||||
|
||||
/* RFC 4515 escaping for search filter values. Returns dst, NULL on overflow. */
|
||||
static char * ldap_escape_filter(const char *src, char *dst, int dstlen)
|
||||
{
|
||||
int j = 0;
|
||||
unsigned char c;
|
||||
for (; *src; src++){
|
||||
c = (unsigned char)*src;
|
||||
if(c == '*' || c == '(' || c == ')' || c == '\\' || c == 0 || c < 0x20 || c >= 0x7f){
|
||||
if(j + 3 >= dstlen) return NULL;
|
||||
sprintf(dst + j, "\\%02X", c);
|
||||
j += 3;
|
||||
}
|
||||
else {
|
||||
if(j + 1 >= dstlen) return NULL;
|
||||
dst[j++] = (char)c;
|
||||
}
|
||||
}
|
||||
dst[j] = 0;
|
||||
return dst;
|
||||
}
|
||||
|
||||
/* reject names unsafe for use in filesystem paths */
|
||||
static int unsafe_filename(const char *name)
|
||||
{
|
||||
return (strchr(name, '/') || strchr(name, '\\') || strstr(name, "..") || !*name);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
int savecounters(void)
|
||||
int savecounters(void *v)
|
||||
{
|
||||
struct trafcount *tc=mypluginlink->conf->trafcounter;
|
||||
struct trafcount *tcd;
|
||||
@@ -67,8 +115,8 @@ int savecounters(void)
|
||||
tcd = tc;
|
||||
tc = tc->next;
|
||||
f=NULL;
|
||||
if(strcmp(tcd->comment,"ldapcounters")==0) {
|
||||
tmpbuf=malloc(strlen(pat_file)+strlen(ldap_dircount)+strlen(tcd->ace->users->user));
|
||||
if(strcmp(tcd->comment,"ldapcounters")==0 && !unsafe_filename(tcd->ace->users->user)) {
|
||||
tmpbuf=malloc(strlen(ldap_dircount)+strlen(tcd->ace->users->user)+sizeof(".lc"));
|
||||
sprintf(tmpbuf,pat_file,ldap_dircount,tcd->ace->users->user);
|
||||
f=fopen(tmpbuf,"w+b");
|
||||
fseek(f,0,SEEK_SET);
|
||||
@@ -97,9 +145,10 @@ static int ldapfunc(struct clientparam *param)
|
||||
{
|
||||
|
||||
LDAP *ld = NULL;
|
||||
LDAPMessage *res = NULL;
|
||||
LDAPMessage *res = NULL;
|
||||
int rc = -1;
|
||||
char tmpbuf[1024];
|
||||
char escuser[512];
|
||||
|
||||
/* test proxy user auth ------------------------*/
|
||||
if(!param->username || !param->password) return 4;
|
||||
@@ -126,7 +175,12 @@ static int ldapfunc(struct clientparam *param)
|
||||
|
||||
|
||||
/* create user for test auth */
|
||||
sprintf(tmpbuf,"%.200s=%.200s,%.200s",attrs[0],param->username,ldap_userenv);
|
||||
if(!ldap_escape_dn(param->username, escuser, sizeof(escuser)))
|
||||
{
|
||||
ldap_unbind_s(ld);
|
||||
return 5;
|
||||
}
|
||||
snprintf(tmpbuf, sizeof(tmpbuf), "%.200s=%.510s,%.200s",attrs[0],escuser,ldap_userenv);
|
||||
|
||||
rc = ldap_bind_s( ld, tmpbuf, param->password, LDAP_AUTH_SIMPLE );
|
||||
|
||||
@@ -162,7 +216,12 @@ static int ldapfunc(struct clientparam *param)
|
||||
/* test enter user in filter ------------------------------
|
||||
create filter for search*/
|
||||
|
||||
sprintf(tmpbuf,"(&(%.200s=%.200s)(%.200s=%.200s))",attrs[0],param->username,
|
||||
if(!ldap_escape_filter(param->username, escuser, sizeof(escuser)))
|
||||
{
|
||||
ldap_unbind_s(ld);
|
||||
return 5;
|
||||
}
|
||||
snprintf(tmpbuf, sizeof(tmpbuf), "(&(%.200s=%.510s)(%.200s=%.200s))",attrs[0],escuser,
|
||||
ldap_group_attr,ldap_access);
|
||||
|
||||
|
||||
@@ -326,7 +385,7 @@ int h_trafgroup(int argc, unsigned char ** argv)
|
||||
while (rc > 0)
|
||||
{
|
||||
vals=ldap_get_values(ld, msg, getattr);
|
||||
if (vals != NULL && vals[0] != NULL )
|
||||
if (vals != NULL && vals[0] != NULL && !unsafe_filename(vals[0]) )
|
||||
{
|
||||
|
||||
/* -------------bandlim----------
|
||||
@@ -378,7 +437,7 @@ int h_trafgroup(int argc, unsigned char ** argv)
|
||||
newtrafcount->traflim64 = traflimit;
|
||||
newtrafcount->comment=(*mypluginlink->strdupfunc)("ldapcounters");
|
||||
newtrafcount->number=0;
|
||||
tmpbuf=malloc(strlen(pat_file)+strlen(ldap_dircount)+strlen(vals[0]));
|
||||
tmpbuf=malloc(strlen(ldap_dircount)+strlen(vals[0])+sizeof(".lc"));
|
||||
sprintf(tmpbuf,pat_file,ldap_dircount,vals[0]);
|
||||
f=NULL;
|
||||
f=fopen(tmpbuf,"rb");
|
||||
|
||||
@@ -3,7 +3,7 @@ PAMLIB ?= pam
|
||||
all: $(BUILDDIR)pamauth$(DLSUFFICS)
|
||||
|
||||
pamauth$(OBJSUFFICS): pamauth.c
|
||||
$(CC) $(DCFLAGS) $(CFLAGS) pamauth.c
|
||||
$(CC) $(CFLAGS) $(DCFLAGS) pamauth.c
|
||||
|
||||
$(BUILDDIR)pamauth$(DLSUFFICS): pamauth$(OBJSUFFICS)
|
||||
$(LN) $(LNOUT)../../$(BUILDDIR)pamauth$(DLSUFFICS) $(LDFLAGS) $(DLFLAGS) $(LIBSPREFIX)$(PAMLIB)$(LIBSSUFFIX) pamauth$(OBJSUFFICS)
|
||||
|
||||
@@ -90,10 +90,7 @@ static int pamfunc(struct clientparam *param)
|
||||
conv.appdata_ptr = (char *) param->password;
|
||||
|
||||
_3proxy_mutex_lock(&pam_mutex);
|
||||
if (!pamh)
|
||||
{
|
||||
retval = pam_start ((char *)service, (char *)param->username, &conv, &pamh);
|
||||
}
|
||||
retval = pam_start ((char *)service, (char *)param->username, &conv, &pamh);
|
||||
if (retval == PAM_SUCCESS)
|
||||
retval = pam_set_item (pamh, PAM_USER, param->username);
|
||||
/*fprintf(stderr,"pam_set_item1 rc=%d\n",retval);*/
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
all: $(BUILDDIR)StringsPlugin$(DLSUFFICS)
|
||||
|
||||
StringsPlugin$(OBJSUFFICS): StringsPlugin.c
|
||||
$(CC) $(DCFLAGS) $(CFLAGS) StringsPlugin.c
|
||||
$(CC) $(CFLAGS) $(DCFLAGS) StringsPlugin.c
|
||||
|
||||
$(BUILDDIR)StringsPlugin$(DLSUFFICS): StringsPlugin$(OBJSUFFICS)
|
||||
$(LN) $(LNOUT)../../$(BUILDDIR)StringsPlugin$(DLSUFFICS) $(LDFLAGS) $(DLFLAGS) StringsPlugin$(OBJSUFFICS)
|
||||
@@ -49,9 +49,13 @@ char **load_string(FILE *f,int max_count_str, int *countloadstr,
|
||||
|
||||
/*load from file new strings */
|
||||
i=0;
|
||||
while ( !feof(f) || i< max_count_str)
|
||||
while ( !feof(f) && i < max_count_str)
|
||||
{
|
||||
if(!fgets(tmpbuf1, 1023,f)) return NULL;
|
||||
if(!fgets(tmpbuf1, 1023,f)){
|
||||
if(pt) free(pt);
|
||||
free(old_table);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((strstr(tmpbuf1,stop))!=NULL) { break; }
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
all: $(BUILDDIR)TrafficPlugin$(DLSUFFICS)
|
||||
|
||||
TrafficPlugin$(OBJSUFFICS): TrafficPlugin.c
|
||||
$(CC) $(DCFLAGS) $(CFLAGS) TrafficPlugin.c
|
||||
$(CC) $(CFLAGS) $(DCFLAGS) TrafficPlugin.c
|
||||
|
||||
$(BUILDDIR)TrafficPlugin$(DLSUFFICS): TrafficPlugin$(OBJSUFFICS)
|
||||
$(LN) $(LNOUT)../../$(BUILDDIR)TrafficPlugin$(DLSUFFICS) $(LDFLAGS) $(DLFLAGS) TrafficPlugin$(OBJSUFFICS)
|
||||
@@ -3,7 +3,7 @@ all: $(BUILDDIR)TransparentPlugin$(DLSUFFICS)
|
||||
|
||||
|
||||
transparent_plugin$(OBJSUFFICS): transparent_plugin.c
|
||||
$(CC) $(DCFLAGS) $(CFLAGS) transparent_plugin.c
|
||||
$(CC) $(CFLAGS) $(DCFLAGS) transparent_plugin.c
|
||||
|
||||
|
||||
$(BUILDDIR)TransparentPlugin$(DLSUFFICS): transparent_plugin$(OBJSUFFICS)
|
||||
|
||||
@@ -34,13 +34,12 @@ static void* transparent_filter_open(void * idata, struct srvparam * param){
|
||||
|
||||
static FILTER_ACTION transparent_filter_client(void *fo, struct clientparam * param, void** fc){
|
||||
|
||||
socklen_t len;
|
||||
char addrbuf[64];
|
||||
int i=0;
|
||||
|
||||
len = sizeof(param->req);
|
||||
|
||||
#ifdef WITH_NETFILTER
|
||||
socklen_t len;
|
||||
|
||||
len = sizeof(param->req);
|
||||
#ifdef SO_ORIGINAL_DST
|
||||
|
||||
if(getsockopt(param->clisock,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
all: $(BUILDDIR)WindowsAuthentication$(DLSUFFICS)
|
||||
|
||||
WindowsAuthentication$(OBJSUFFICS): WindowsAuthentication.c
|
||||
$(CC) $(DCFLAGS) $(CFLAGS) WindowsAuthentication.c
|
||||
$(CC) $(CFLAGS) $(DCFLAGS) WindowsAuthentication.c
|
||||
|
||||
$(BUILDDIR)WindowsAuthentication$(DLSUFFICS): WindowsAuthentication$(OBJSUFFICS)
|
||||
$(LN) $(LNOUT)../../$(BUILDDIR)WindowsAuthentication$(DLSUFFICS) $(LDFLAGS) $(DLFLAGS) WindowsAuthentication$(OBJSUFFICS) $(LIBS)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
all: $(BUILDDIR)utf8tocp1251$(DLSUFFICS)
|
||||
|
||||
utf8tocp1251$(OBJSUFFICS): utf8tocp1251.c
|
||||
$(CC) $(DCFLAGS) $(CFLAGS) utf8tocp1251.c
|
||||
$(CC) $(CFLAGS) $(DCFLAGS) utf8tocp1251.c
|
||||
|
||||
$(BUILDDIR)utf8tocp1251$(DLSUFFICS): utf8tocp1251$(OBJSUFFICS)
|
||||
$(LN) $(LNOUT)../../$(BUILDDIR)utf8tocp1251$(DLSUFFICS) $(LDFLAGS) $(DLFLAGS) utf8tocp1251$(OBJSUFFICS) $(LIBS)
|
||||
|
||||
+22
-4
@@ -10,6 +10,12 @@
|
||||
|
||||
#define RETURN(xxx) { param->res = xxx; goto CLEANRET; }
|
||||
|
||||
#ifdef WITHMAIN
|
||||
#define NOSTARTTLS 1
|
||||
#else
|
||||
#define NOSTARTTLS param->srv->nostarttls
|
||||
#endif
|
||||
|
||||
void * pop3pchild(struct clientparam* param) {
|
||||
int i=0, res;
|
||||
unsigned char buf[320];
|
||||
@@ -19,10 +25,23 @@ void * pop3pchild(struct clientparam* param) {
|
||||
i = sockgetlinebuf(param, CLIENT, buf, sizeof(buf) - 10, '\n', conf.timeouts[STRING_S]);
|
||||
while(i > 4 && strncasecmp((char *)buf, "USER", 4)){
|
||||
if(!strncasecmp((char *)buf, "QUIT", 4)){
|
||||
socksend(param, param->clisock, (unsigned char *)"+OK\r\n", 5,conf.timeouts[STRING_S]);
|
||||
socksend(param, param->clisock, (unsigned char *)"+OK\r\n", 5,conf.timeouts[STRING_S]);
|
||||
RETURN(0);
|
||||
}
|
||||
socksend(param, param->clisock, (unsigned char *)"-ERR need USER first\r\n", 22, conf.timeouts[STRING_S]);
|
||||
if(!strncasecmp((char *)buf, "CAPA", 4) && !NOSTARTTLS){
|
||||
socksend(param, param->clisock, (unsigned char *)"+OK Capability list follows\r\nSTLS\r\n.\r\n", 38, conf.timeouts[STRING_S]);
|
||||
i = sockgetlinebuf(param, CLIENT, buf, sizeof(buf) - 10, '\n', conf.timeouts[STRING_S]);
|
||||
continue;
|
||||
}
|
||||
#ifndef WITHMAIN
|
||||
if(!strncasecmp((char *)buf, "STLS", 4) && !param->srv->nostarttls){
|
||||
if(socksend(param, param->clisock, (unsigned char *)"+OK Begin TLS negotiation\r\n", 27, conf.timeouts[STRING_S])!=27) {RETURN(623);}
|
||||
param->clientstarttls = S_POP3P;
|
||||
if(!param->srv->targetport) param->srv->targetport = htons(110);
|
||||
return (void *)tlsprchild;
|
||||
}
|
||||
#endif
|
||||
socksend(param, param->clisock, (unsigned char *)"-ERR need USER first\r\n", 22, conf.timeouts[STRING_S]);
|
||||
i = sockgetlinebuf(param, CLIENT, buf, sizeof(buf) - 10, '\n', conf.timeouts[STRING_S]);
|
||||
}
|
||||
if(i<6) {RETURN(612);}
|
||||
@@ -55,7 +74,6 @@ CLEANRET:
|
||||
if(param->clisock != INVALID_SOCKET) {
|
||||
if ((param->res > 0 && param->res < 100) || (param->res > 611 && param->res <700)) socksend(param, param->clisock, (unsigned char *)"-ERR\r\n", 6,conf.timeouts[STRING_S]);
|
||||
}
|
||||
freeparam(param);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
@@ -65,7 +83,7 @@ struct proxydef childdef = {
|
||||
110,
|
||||
0,
|
||||
S_POP3P,
|
||||
" -hdefault_host[:port] - use this host and port as default if no host specified\n"
|
||||
" -hdefault_host[:port] - use this host and port as default if no host specified\n -x - disable STARTTLS\n"
|
||||
|
||||
};
|
||||
#include "proxymain.c"
|
||||
|
||||
+104
-10
@@ -240,13 +240,21 @@ void * proxychild(struct clientparam* param) {
|
||||
int keepalive = 0;
|
||||
uint64_t contentlength64 = 0;
|
||||
int hascontent =0;
|
||||
int clhdrofs = -1;
|
||||
int chunkedcli = 0;
|
||||
int clhdrofs_req = -1;
|
||||
int isconnect = 0;
|
||||
int redirect = 0;
|
||||
int prefix = 0, ckeepalive=0;
|
||||
int ftp = 0;
|
||||
int ssoff = 0;
|
||||
#ifndef ANONYMOUS
|
||||
int anonymous;
|
||||
#endif
|
||||
int sleeptime = 0;
|
||||
#ifndef WITHMAIN
|
||||
int reqsize, reqbufsize;
|
||||
#endif
|
||||
int authenticate;
|
||||
struct pollfd fds[2];
|
||||
SOCKET ftps;
|
||||
@@ -262,10 +270,15 @@ void * proxychild(struct clientparam* param) {
|
||||
if(param->remsock != INVALID_SOCKET) haveconnection = 1;
|
||||
if(!(buf = malloc(BUFSIZE))) {RETURN(21);}
|
||||
bufsize = BUFSIZE;
|
||||
#ifndef ANONYMOUS
|
||||
anonymous = param->srv->anonymous;
|
||||
#endif
|
||||
for(;;){
|
||||
memset(buf, 0, bufsize);
|
||||
inbuf = 0;
|
||||
chunkedcli = 0;
|
||||
clhdrofs_req = -1;
|
||||
param->nolongdatfilter = 0;
|
||||
|
||||
|
||||
if(keepalive && (param->cliinbuf == param->clioffset) && (param->remsock != INVALID_SOCKET)){
|
||||
@@ -326,6 +339,7 @@ for(;;){
|
||||
|
||||
if ((sb=(unsigned char *)(unsigned char *)strchr((char *)buf, ' ')) == NULL) {RETURN(512);}
|
||||
ss = ++sb;
|
||||
ssoff = (int)(ss - buf);
|
||||
if(!isconnect) {
|
||||
if (!strncasecmp((char *)sb, "http://", 7)) {
|
||||
sb += 7;
|
||||
@@ -413,6 +427,10 @@ for(;;){
|
||||
param->password = (unsigned char *)strdup((char *)sb+1);
|
||||
param->pwtype = 0;
|
||||
}
|
||||
else if(param->password){
|
||||
free(param->password);
|
||||
param->password = NULL;
|
||||
}
|
||||
if(param->username)free(param->username);
|
||||
param->username = (unsigned char *)strdup((char *)username);
|
||||
continue;
|
||||
@@ -458,13 +476,14 @@ for(;;){
|
||||
if(parsehostname((char *)sb, param, 80)) RETURN(100);
|
||||
}
|
||||
newbuf = malloc(strlen((char *)req) + strlen((char *)(buf+inbuf)) + 8);
|
||||
if(newbuf){
|
||||
sp = (unsigned char *)strchr((char *)req+1, '/');
|
||||
sp = (unsigned char *)strchr((char *)req+1, '/');
|
||||
if(newbuf && sp){
|
||||
memcpy(newbuf, req, (sp - req));
|
||||
sprintf((char*)newbuf + (sp - req), "http://%s%s",sb,sp);
|
||||
free(req);
|
||||
req = newbuf;
|
||||
}
|
||||
else if(newbuf) free(newbuf);
|
||||
if(se)*se = c;
|
||||
}
|
||||
if(ftp && i > 13 && (!strncasecmp((char *)(buf+inbuf), "authorization", 13))){
|
||||
@@ -485,12 +504,17 @@ for(;;){
|
||||
if(param->extpassword)free(param->extpassword);
|
||||
param->extpassword = (unsigned char *)strdup((char *)sb+1);
|
||||
}
|
||||
else if(param->extpassword){
|
||||
free(param->extpassword);
|
||||
param->extpassword = NULL;
|
||||
}
|
||||
if(param->extusername)free(param->extusername);
|
||||
param->extusername = (unsigned char *)strdup((char *)username);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if(i> 15 && (!strncasecmp((char *)(buf+inbuf), "content-length", 14))){
|
||||
if(chunkedcli) continue;
|
||||
sb = (unsigned char *)strchr((char *)(buf+inbuf), ':');
|
||||
if(!sb)continue;
|
||||
++sb;
|
||||
@@ -500,6 +524,23 @@ for(;;){
|
||||
RETURN(10);
|
||||
}
|
||||
if(param->ndatfilterscli > 0 && contentlength64 > 0) continue;
|
||||
clhdrofs_req = inbuf;
|
||||
}
|
||||
else if(i>25 && (!strncasecmp((char *)(buf+inbuf), "transfer-encoding", 17))){
|
||||
sb = (unsigned char *)strchr((char *)(buf+inbuf), ':');
|
||||
if(sb){
|
||||
++sb;
|
||||
while(isspace(*sb))sb++;
|
||||
if(!strncasecmp((char *)sb, "chunked", 7)){
|
||||
chunkedcli = 1;
|
||||
if(clhdrofs_req >= 0){
|
||||
buf[clhdrofs_req] = 'X';
|
||||
clhdrofs_req = -1;
|
||||
}
|
||||
contentlength64 = 0;
|
||||
param->nolongdatfilter = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
inbuf += i;
|
||||
if((bufsize - inbuf) < LINESIZE){
|
||||
@@ -515,8 +556,10 @@ for(;;){
|
||||
|
||||
buf[inbuf] = 0;
|
||||
|
||||
#ifndef WITHMAIN
|
||||
reqsize = (int)strlen((char *)req);
|
||||
reqbufsize = reqsize + 1;
|
||||
#endif
|
||||
|
||||
|
||||
if(param->srv->needuser > 1 && !param->username) {RETURN(4);}
|
||||
@@ -565,7 +608,7 @@ for(;;){
|
||||
if (conf.filtermaxsize && contentlength64 > (uint64_t)conf.filtermaxsize) {
|
||||
param->nolongdatfilter = 1;
|
||||
}
|
||||
else if(param->ndatfilterscli > 0 && contentlength64 > 0){
|
||||
else if(param->ndatfilterscli > 0 && contentlength64 > 0 && contentlength64 == (uint64_t)(unsigned long)contentlength64){
|
||||
uint64_t newlen64;
|
||||
newlen64 = (uint64_t) sockfillbuffcli(param, (unsigned long)contentlength64, CONNECTION_S);
|
||||
if(newlen64 == contentlength64) {
|
||||
@@ -599,6 +642,7 @@ for(;;){
|
||||
ckeepalive = 1;
|
||||
if(ftpbase) free(ftpbase);
|
||||
ftpbase = NULL;
|
||||
ss = buf + ssoff;
|
||||
if(!(sp = (unsigned char *)strchr((char *)ss, ' '))){RETURN(799);}
|
||||
*sp = 0;
|
||||
|
||||
@@ -668,7 +712,6 @@ for(;;){
|
||||
int sizetoken =-1;
|
||||
int modetoken =-1;
|
||||
int datetoken =-1;
|
||||
int spaces = 1;
|
||||
unsigned char * tokens[10];
|
||||
unsigned wordlen [10];
|
||||
unsigned char j=0;
|
||||
@@ -701,7 +744,6 @@ for(;;){
|
||||
wordlen[datetoken] = ((unsigned)(tokens[1] - tokens[0])) + wordlen[1];
|
||||
sizetoken = 2;
|
||||
filetoken = 3;
|
||||
spaces = 10;
|
||||
}
|
||||
else {
|
||||
if(j < 8 || wordlen[0]!=10) continue;
|
||||
@@ -831,7 +873,7 @@ for(;;){
|
||||
if(isconnect && param->redirtype != R_HTTP) {
|
||||
if(param->redirectfunc) {
|
||||
freeptr(&req); freeptr(&buf); freeptr(&ftpbase);
|
||||
return (*param->redirectfunc)(param);
|
||||
return (void *)param->redirectfunc;
|
||||
}
|
||||
param->res = mapsocket(param, conf.timeouts[CONNECTION_L]);
|
||||
RETURN(param->res);
|
||||
@@ -906,13 +948,48 @@ for(;;){
|
||||
if(param->bandlimfunc) {
|
||||
sleeptime = param->bandlimfunc(param, 0, (int)strlen((char *)buf));
|
||||
}
|
||||
if(contentlength64 > 0){
|
||||
if(chunkedcli || contentlength64 > 0){
|
||||
if(chunkedcli){
|
||||
do {
|
||||
unsigned char smallbuf[32];
|
||||
while ((i = sockgetlinebuf(param, CLIENT, smallbuf, 30, '\n', conf.timeouts[STRING_S])) == 2) {
|
||||
if (socksend(param, param->remsock, smallbuf, i, conf.timeouts[STRING_S]) != i) RETURN(536);
|
||||
if(chunkedcli == 2) break;
|
||||
}
|
||||
if(i<3) break;
|
||||
if (socksend(param, param->remsock, smallbuf, i, conf.timeouts[STRING_S]) != i) RETURN(536);
|
||||
if(chunkedcli == 2) {
|
||||
if((i = sockgetlinebuf(param, CLIENT, smallbuf, 30, '\n', conf.timeouts[STRING_S])) != 2) RETURN(537);
|
||||
if (socksend(param, param->remsock, smallbuf, i, conf.timeouts[STRING_S]) != i) RETURN(536);
|
||||
break;
|
||||
}
|
||||
smallbuf[i] = 0;
|
||||
contentlength64 = 0;
|
||||
if(sscanf((char *)smallbuf, "%"SCNx64"", &contentlength64) != 1) RETURN(537);
|
||||
/* chunk-size line may be longer than smallbuf: drain and relay the
|
||||
remainder up to LF so client/backend framing stays in sync */
|
||||
while(i > 0 && smallbuf[i-1] != '\n'){
|
||||
if((i = sockgetlinebuf(param, CLIENT, smallbuf, 30, '\n', conf.timeouts[STRING_S])) <= 0) RETURN(537);
|
||||
if (socksend(param, param->remsock, smallbuf, i, conf.timeouts[STRING_S]) != i) RETURN(536);
|
||||
}
|
||||
if(contentlength64 == 0) chunkedcli = 2;
|
||||
else {
|
||||
param->waitclient64 = contentlength64;
|
||||
res = mapsocket(param, conf.timeouts[CONNECTION_S]);
|
||||
param->waitclient64 = 0;
|
||||
if(res != 99) RETURN(res);
|
||||
}
|
||||
} while(chunkedcli);
|
||||
res = 99;
|
||||
}
|
||||
else {
|
||||
param->waitclient64 = contentlength64;
|
||||
res = mapsocket(param, conf.timeouts[CONNECTION_S]);
|
||||
param->waitclient64 = 0;
|
||||
if(res != 99) {
|
||||
RETURN(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
contentlength64 = 0;
|
||||
inbuf = 0;
|
||||
@@ -921,6 +998,7 @@ for(;;){
|
||||
authenticate = 0;
|
||||
param->chunked = 0;
|
||||
hascontent = 0;
|
||||
clhdrofs = -1;
|
||||
|
||||
while( (i = sockgetlinebuf(param, SERVER, buf + inbuf, LINESIZE - 1, '\n', conf.timeouts[(res)?STRING_S:STRING_L])) > 2) {
|
||||
if(!res && i>9)param->status = res = atoi((char *)buf + inbuf + 9);
|
||||
@@ -942,6 +1020,7 @@ for(;;){
|
||||
authenticate = 1;
|
||||
}
|
||||
else if(i > 15 && (!strncasecmp((char *)(buf+inbuf), "content-length", 14))){
|
||||
if(param->chunked) continue;
|
||||
buf[inbuf+i]=0;
|
||||
sb = (unsigned char *)strchr((char *)(buf+inbuf), ':');
|
||||
if(!sb)continue;
|
||||
@@ -949,6 +1028,7 @@ for(;;){
|
||||
while(isspace(*sb))sb++;
|
||||
sscanf((char *)sb, "%"SCNu64"", &contentlength64);
|
||||
hascontent = 1;
|
||||
clhdrofs = inbuf;
|
||||
if(param->unsafefilter && param->ndatfilterssrv > 0) {
|
||||
hascontent = 2;
|
||||
continue;
|
||||
@@ -965,6 +1045,12 @@ for(;;){
|
||||
while(isspace(*sb))sb++;
|
||||
if(!strncasecmp((char *)sb, "chunked", 7)){
|
||||
param->chunked = 1;
|
||||
if(clhdrofs >= 0){
|
||||
buf[clhdrofs] = 'X';
|
||||
clhdrofs = -1;
|
||||
contentlength64 = 0;
|
||||
hascontent = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
inbuf += i;
|
||||
@@ -1009,7 +1095,7 @@ for(;;){
|
||||
if (conf.filtermaxsize && contentlength64 > (uint64_t)conf.filtermaxsize) {
|
||||
param->nolongdatfilter = 1;
|
||||
}
|
||||
else if(param->ndatfilterssrv > 0 && contentlength64 > 0 && param->operation != HTTP_HEAD && res != 204 && res != 304){
|
||||
else if(param->ndatfilterssrv > 0 && contentlength64 > 0 && contentlength64 == (uint64_t)(unsigned long)contentlength64 && param->operation != HTTP_HEAD && res != 204 && res != 304){
|
||||
uint64_t newlen;
|
||||
newlen = (uint64_t)sockfillbuffsrv(param, (unsigned long) contentlength64, CONNECTION_S);
|
||||
if(newlen == contentlength64) {
|
||||
@@ -1073,7 +1159,16 @@ for(;;){
|
||||
}
|
||||
smallbuf[i] = 0;
|
||||
contentlength64 = 0;
|
||||
sscanf((char *)smallbuf, "%"SCNx64"", &contentlength64);
|
||||
if(sscanf((char *)smallbuf, "%"SCNx64"", &contentlength64) != 1) {
|
||||
keepalive = 0;
|
||||
break;
|
||||
}
|
||||
/* chunk-size line may be longer than smallbuf: drain and relay the
|
||||
remainder up to LF so client/backend framing stays in sync */
|
||||
while(i > 0 && smallbuf[i-1] != '\n'){
|
||||
if((i = sockgetlinebuf(param, SERVER, smallbuf, 30, '\n', conf.timeouts[STRING_S])) <= 0) RETURN(534);
|
||||
if (socksend(param, param->clisock, smallbuf, i, conf.timeouts[STRING_S]) != i) RETURN(535);
|
||||
}
|
||||
if(contentlength64 == 0) {
|
||||
param->chunked = 2;
|
||||
}
|
||||
@@ -1140,7 +1235,6 @@ CLEANRET:
|
||||
}
|
||||
logurl(param, (char *)buf, (char *)req, ftp);
|
||||
freeptr(&req); freeptr(&buf); freeptr(&ftpbase);
|
||||
freeparam(param);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
||||
+48
-8
@@ -34,6 +34,7 @@
|
||||
#define MAXUSERNAME 128
|
||||
#define _PASSWORD_LEN 256
|
||||
#define MAXNSERVERS 5
|
||||
#define DEFAULT_MAXCHILD 500
|
||||
|
||||
#define TCPBUFSIZE 65536
|
||||
#define SRVBUFSIZE (param->srv->bufsize?param->srv->bufsize:((param->service == S_UDPPM)?UDPBUFSIZE:TCPBUFSIZE))
|
||||
@@ -103,7 +104,6 @@
|
||||
#include <pthread.h>
|
||||
#ifndef PTHREAD_STACK_MIN
|
||||
#define PTHREAD_STACK_MIN 32768
|
||||
#define sockerror strerror
|
||||
#endif
|
||||
void daemonize(void);
|
||||
#define SLEEPTIME 1000
|
||||
@@ -112,6 +112,33 @@ void daemonize(void);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Keeps a callee with a large frame out of the caller's frame, e.g. the
|
||||
8K log buffer of logstdout() out of dolog(), which calls it in a branch
|
||||
taken only when there is no service.
|
||||
*/
|
||||
#if defined(__GNUC__)
|
||||
#define NOINLINE __attribute__((noinline))
|
||||
#elif defined(_MSC_VER)
|
||||
#define NOINLINE __declspec(noinline)
|
||||
#else
|
||||
#define NOINLINE
|
||||
#endif
|
||||
|
||||
/* Thread stack size, stacksize command value is added to it. BSD libc uses
|
||||
significantly more stack, e.g. in vfprintf() called by syslog().
|
||||
*/
|
||||
#ifndef BASESTACKSIZE
|
||||
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
|
||||
#define BASESTACKSIZE 65536
|
||||
#else
|
||||
#define BASESTACKSIZE 49152
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
size_t threadstacksize(int extra);
|
||||
#endif
|
||||
|
||||
#ifdef WITH_ODBC
|
||||
#ifndef _WIN32
|
||||
#include <sqltypes.h>
|
||||
@@ -188,6 +215,8 @@ unsigned long sockfillbuffcli(struct clientparam * param, unsigned long size, in
|
||||
unsigned long sockfillbuffsrv(struct clientparam * param, unsigned long size, int timeosec);
|
||||
|
||||
int sockgetlinebuf(struct clientparam * param, DIRECTION which, unsigned char * buf, int bufsize, int delim, int to);
|
||||
int getmultiline(struct clientparam * param, DIRECTION which, unsigned char * buf, int bufsize, const char *cap, int *found);
|
||||
int hascap(const unsigned char *line, const char *cap);
|
||||
|
||||
|
||||
|
||||
@@ -196,7 +225,7 @@ void dolog(struct clientparam * param, const unsigned char *s);
|
||||
int dobuf(struct clientparam * param, unsigned char * buf, const unsigned char *s, const unsigned char * doublec);
|
||||
int dobuf2(struct clientparam * param, unsigned char * buf, const unsigned char *s, const unsigned char * doublec, struct tm* tm, char * format);
|
||||
extern FILE * stdlog;
|
||||
void logstdout(struct clientparam * param, const unsigned char *s);
|
||||
NOINLINE void logstdout(struct clientparam * param, const unsigned char *s);
|
||||
void logsyslog(struct clientparam * param, const unsigned char *s);
|
||||
void lognone(struct clientparam * param, const unsigned char *s);
|
||||
void logradius(struct clientparam * param, const unsigned char *s);
|
||||
@@ -240,22 +269,24 @@ extern int paused;
|
||||
extern int demon;
|
||||
|
||||
unsigned char * mycrypt(const unsigned char *key, const unsigned char *salt, unsigned char *buf);
|
||||
#ifdef WITH_SSL
|
||||
unsigned char * ntpwdhash (unsigned char *szHash, const unsigned char *szPassword, int tohex);
|
||||
#endif
|
||||
int de64 (const unsigned char *in, unsigned char *out, int maxlen);
|
||||
unsigned char* en64 (const unsigned char *in, unsigned char *out, int inlen);
|
||||
void tohex(unsigned char *in, unsigned char *out, int len);
|
||||
void fromhex(unsigned char *in, unsigned char *out, int len);
|
||||
|
||||
extern _3proxy_sem_t udpinit;
|
||||
#ifdef _WIN32
|
||||
extern HANDLE udpinit;
|
||||
#define _3proxy_sem_init(x, count, maxcount) (((x) = CreateSemaphore(NULL, (count), (maxcount), NULL))? 0 : 1)
|
||||
#define _3proxy_sem_lock(x) WaitForSingleObject(x, INFINITE)
|
||||
#define _3proxy_sem_unlock(x) ReleaseSemaphore(x, 1, NULL)
|
||||
#else
|
||||
extern _3proxy_mutex_t udpinit;
|
||||
#define _3proxy_sem_lock(x) pthread_mutex_lock(&x)
|
||||
#define _3proxy_sem_unlock(x) pthread_mutex_unlock(&x)
|
||||
int _3proxy_sem_init_f(_3proxy_sem_t *sem, unsigned count, unsigned maxcount);
|
||||
void _3proxy_sem_lock_f(_3proxy_sem_t *sem);
|
||||
void _3proxy_sem_unlock_f(_3proxy_sem_t *sem);
|
||||
#define _3proxy_sem_init(x, count, maxcount) _3proxy_sem_init_f(&x, (count), (maxcount))
|
||||
#define _3proxy_sem_lock(x) _3proxy_sem_lock_f(&x)
|
||||
#define _3proxy_sem_unlock(x) _3proxy_sem_unlock_f(&x)
|
||||
#endif
|
||||
|
||||
|
||||
@@ -314,6 +345,7 @@ void srvinit2(struct srvparam * srv, struct clientparam *param);
|
||||
void srvfree(struct srvparam * srv);
|
||||
unsigned char * dologname (unsigned char *buf, unsigned char *name, const unsigned char *ext, ROTATION lt, time_t t);
|
||||
int readconfig(FILE * fp);
|
||||
void initcommands(void);
|
||||
int connectwithpoll(struct clientparam *param, SOCKET sock, struct sockaddr *sa, SASIZETYPE size, int to);
|
||||
|
||||
|
||||
@@ -327,6 +359,7 @@ extern char *copyright;
|
||||
|
||||
void * dnsprchild(struct clientparam * param);
|
||||
void * pop3pchild(struct clientparam * param);
|
||||
void * imappchild(struct clientparam * param);
|
||||
void * smtppchild(struct clientparam * param);
|
||||
void * proxychild(struct clientparam * param);
|
||||
void * sockschild(struct clientparam * param);
|
||||
@@ -336,6 +369,13 @@ void * udppmchild(struct clientparam * param);
|
||||
void * adminchild(struct clientparam * param);
|
||||
void * ftpprchild(struct clientparam * param);
|
||||
void * tlsprchild(struct clientparam * param);
|
||||
/* Child functions return the child to redirect the request to, or NULL if
|
||||
the request is complete. childfunc() calls them and releases param.
|
||||
Recursive redirection, e.g. a socks service redirected to socks5, used to
|
||||
be limited by the stack size only, MAXCHILDREDIRECTS limits it now.
|
||||
*/
|
||||
#define MAXCHILDREDIRECTS 16
|
||||
void * childfunc(struct clientparam * param);
|
||||
|
||||
|
||||
struct datatype;
|
||||
|
||||
+92
-32
@@ -11,6 +11,24 @@
|
||||
#include <sched.h>
|
||||
#endif
|
||||
|
||||
/* Child functions do not call each other, a child requesting redirection to
|
||||
another child returns it instead of calling it, to keep the stack flat.
|
||||
The child which completed the request returns NULL. param is logged by
|
||||
the child and released here.
|
||||
*/
|
||||
void * childfunc(struct clientparam * param){
|
||||
PROXYFUNC pf = param->srv->pf;
|
||||
int i;
|
||||
|
||||
for(i = 0; pf && i < MAXCHILDREDIRECTS; i++) pf = (PROXYFUNC)(*pf)(param);
|
||||
if(pf){
|
||||
param->res = 101;
|
||||
dolog(param, (unsigned char *)"Redirection loop");
|
||||
}
|
||||
freeparam(param);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define param ((struct clientparam *) p)
|
||||
#ifdef _WIN32
|
||||
DWORD WINAPI threadfunc(LPVOID p) {
|
||||
@@ -121,7 +139,7 @@ void * threadfunc (void *p) {
|
||||
}
|
||||
}
|
||||
}
|
||||
((struct clientparam *) p)->srv->pf((struct clientparam *)p);
|
||||
childfunc((struct clientparam *)p);
|
||||
}
|
||||
#ifdef _WIN32
|
||||
return 0;
|
||||
@@ -131,6 +149,20 @@ void * threadfunc (void *p) {
|
||||
}
|
||||
#undef param
|
||||
|
||||
#ifdef _WIN32
|
||||
/* Present since Windows 7 (SO_PORT_SCALABILITY) and Windows 10 / Server 2019
|
||||
(SO_REUSE_UNICASTPORT), define them if the SDK is older so the options can
|
||||
still be requested. setsockopt() just fails on a system which does not
|
||||
support them and the failure is ignored.
|
||||
*/
|
||||
#ifndef SO_PORT_SCALABILITY
|
||||
#define SO_PORT_SCALABILITY 0x3006
|
||||
#endif
|
||||
#ifndef SO_REUSE_UNICASTPORT
|
||||
#define SO_REUSE_UNICASTPORT 0x3007
|
||||
#endif
|
||||
#endif
|
||||
|
||||
struct socketoptions sockopts[] = {
|
||||
#ifdef TCP_NODELAY
|
||||
{TCP_NODELAY, "TCP_NODELAY"},
|
||||
@@ -147,15 +179,15 @@ struct socketoptions sockopts[] = {
|
||||
#ifdef TCP_TIMESTAMPS
|
||||
{TCP_TIMESTAMPS, "TCP_TIMESTAMPS"},
|
||||
#endif
|
||||
#ifdef USE_TCP_FASTOPEN
|
||||
{USE_TCP_FASTOPEN, "USE_TCP_FASTOPEN"},
|
||||
#endif
|
||||
#ifdef SO_REUSEADDR
|
||||
{SO_REUSEADDR, "SO_REUSEADDR"},
|
||||
#endif
|
||||
#ifdef SO_REUSEPORT
|
||||
{SO_REUSEPORT, "SO_REUSEPORT"},
|
||||
#endif
|
||||
#ifdef SO_EXCLUSIVEADDRUSE
|
||||
{SO_EXCLUSIVEADDRUSE, "SO_EXCLUSIVEADDRUSE"},
|
||||
#endif
|
||||
#ifdef SO_PORT_SCALABILITY
|
||||
{SO_PORT_SCALABILITY, "SO_PORT_SCALABILITY"},
|
||||
#endif
|
||||
@@ -279,6 +311,7 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
#ifdef __linux__
|
||||
int saved_nsfd = -1;
|
||||
#endif
|
||||
#if !defined(PORTMAP) || !defined(NOPORTMAP)
|
||||
char loghelp[] =
|
||||
#ifdef STDMAIN
|
||||
#ifndef _WIN32
|
||||
@@ -294,8 +327,8 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
" -Di(DEVICENAME) bind internal interface to device, e.g. eth1\n"
|
||||
" -De(DEVICENAME) bind external interface to device, e.g. eth1\n"
|
||||
#endif
|
||||
#ifdef WITHSLICE
|
||||
" -s Use slice() - faster proxing, but no filtering for data\n"
|
||||
#ifdef WITHSPLICE
|
||||
" -s Use splice() - no filtering for data, off by default\n"
|
||||
#endif
|
||||
"-g(GRACE_TRAFF,GRACE_NUM,GRACE_DELAY) - delay GRACE_DELAY milliseconds before polling if average polling size below GRACE_TRAFF bytes and GRACE_NUM read operations in single directions are detected within 1 second to minimize polling\n"
|
||||
" -fFORMAT logging format (see documentation)\n"
|
||||
@@ -317,6 +350,7 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
" to-client (oc), to-server (os), listening (ol) socket, connect back client\n"
|
||||
" (or) socket, connect back server (oR) listening socket\n"
|
||||
" where possible options are: ";
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
unsigned long ul = 1;
|
||||
@@ -367,6 +401,7 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
if(!srv.udpbuf || !srv.udpbuf2) {
|
||||
#ifndef STDMAIN
|
||||
haveerror = 2;
|
||||
_3proxy_sem_unlock(conf.threadinit);
|
||||
#endif
|
||||
return 11;
|
||||
}
|
||||
@@ -528,6 +563,27 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
srv.needuser = 0;
|
||||
if(*(argv[i] + 2)) srv.needuser = atoi(argv[i] + 2);
|
||||
break;
|
||||
case 'x':
|
||||
srv.nostarttls = 1;
|
||||
break;
|
||||
case 'X':
|
||||
if(!strncasecmp(argv[i]+2, "imap", 4)) srv.srvstarttls = S_IMAPP;
|
||||
else if(!strncasecmp(argv[i]+2, "pop3", 4)) srv.srvstarttls = S_POP3P;
|
||||
else if(!strncasecmp(argv[i]+2, "smtp", 4)) srv.srvstarttls = S_SMTPP;
|
||||
else error = 1;
|
||||
break;
|
||||
case 'F':
|
||||
{
|
||||
PROXYSOCKADDRTYPE fsa;
|
||||
memset(&fsa, 0, sizeof(fsa));
|
||||
if(!getip46(46, (unsigned char *)argv[i]+2, (struct sockaddr *)&fsa)) error = 1;
|
||||
else if(*SAFAMILY(&fsa) == AF_INET) srv.fakeip = *(uint32_t *)SAADDR(&fsa);
|
||||
#ifndef NOIPV6
|
||||
else if(*SAFAMILY(&fsa) == AF_INET6) memcpy(srv.fakeip6, SAADDR(&fsa), 16);
|
||||
#endif
|
||||
else error = 1;
|
||||
}
|
||||
break;
|
||||
case 'T':
|
||||
srv.transparent = 1;
|
||||
break;
|
||||
@@ -547,7 +603,7 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
srv.s_option = 1 + atoi(argv[i]+2);
|
||||
#ifdef WITHSPLICE
|
||||
else
|
||||
if(*(argv[i]+2)) srv.usesplice = atoi(argv[i]+2);
|
||||
srv.usesplice = *(argv[i]+2)? atoi(argv[i]+2) : 1;
|
||||
#endif
|
||||
break;
|
||||
case 'o':
|
||||
@@ -587,7 +643,6 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
if (error || i!=argc) {
|
||||
#ifndef STDMAIN
|
||||
haveerror = 1;
|
||||
_3proxy_sem_unlock(conf.threadinit);
|
||||
#endif
|
||||
fprintf(stderr, "%s of %s\n"
|
||||
"Usage: %s options\n"
|
||||
@@ -607,6 +662,9 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
""
|
||||
#endif
|
||||
);
|
||||
#ifndef STDMAIN
|
||||
_3proxy_sem_unlock(conf.threadinit);
|
||||
#endif
|
||||
|
||||
return (1);
|
||||
}
|
||||
@@ -619,7 +677,6 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
if (error || argc != i+3 || *argv[i]=='-'|| (*SAPORT(&srv.intsa) = htons((uint16_t)atoi(argv[i])))==0 || (srv.targetport = htons((uint16_t)atoi(argv[i+2])))==0) {
|
||||
#ifndef STDMAIN
|
||||
haveerror = 1;
|
||||
_3proxy_sem_unlock(conf.threadinit);
|
||||
#endif
|
||||
fprintf(stderr, "%s of %s\n"
|
||||
"Usage: %s options"
|
||||
@@ -640,6 +697,9 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
""
|
||||
#endif
|
||||
);
|
||||
#ifndef STDMAIN
|
||||
_3proxy_sem_unlock(conf.threadinit);
|
||||
#endif
|
||||
return (1);
|
||||
}
|
||||
srv.target = (unsigned char *)strdup(argv[i+1]);
|
||||
@@ -663,7 +723,7 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
return 2;
|
||||
};
|
||||
*newparam = defparam;
|
||||
return((*srv.pf)((void *)newparam)? 1:0);
|
||||
return(childfunc(newparam)? 1:0);
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -751,8 +811,15 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
if(*SAFAMILY(&srv.intsa) != AF_UNIX)
|
||||
#endif
|
||||
{
|
||||
/* SO_REUSEADDR is not set on Windows: it is not needed to rebind a listening
|
||||
port there, and it only allows another local process to bind the same
|
||||
address and port, with undefined behaviour as to which socket receives the
|
||||
connections. Use -olSO_EXCLUSIVEADDRUSE to prevent that instead.
|
||||
*/
|
||||
#ifndef _WIN32
|
||||
opt = 1;
|
||||
if(srv.so._setsockopt(srv.so.state, sock, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(int)))perror("setsockopt()");
|
||||
#endif
|
||||
#ifdef SO_REUSEPORT
|
||||
opt = 1;
|
||||
srv.so._setsockopt(srv.so.state, sock, SOL_SOCKET, SO_REUSEPORT, (char *)&opt, sizeof(int));
|
||||
@@ -772,6 +839,9 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
return -12;
|
||||
}
|
||||
#ifndef NOIPV6
|
||||
#ifndef IPV6_BOUND_IF
|
||||
#define IPV6_BOUND_IF 125
|
||||
#endif
|
||||
if((*SAFAMILY(&srv.intsa) == AF_INET6 && srv.so._setsockopt(srv.so.state, sock, IPPROTO_IPV6, IPV6_BOUND_IF, &idx, sizeof(idx)))) {
|
||||
dolog(&defparam, (unsigned char *)"failed to bind device");
|
||||
return -12;
|
||||
@@ -865,8 +935,10 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
freesrvstrings(&srv, cbc_string, cbl_string);
|
||||
return -6;
|
||||
}
|
||||
#ifndef _WIN32
|
||||
opt = 1;
|
||||
srv.so._setsockopt(srv.so.state, srv.cbsock, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(int));
|
||||
#endif
|
||||
#ifdef SO_REUSEPORT
|
||||
opt = 1;
|
||||
srv.so._setsockopt(srv.so.state, srv.cbsock, SOL_SOCKET, SO_REUSEPORT, (char *)&opt, sizeof(int));
|
||||
@@ -893,7 +965,7 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
|
||||
#ifndef _WIN32
|
||||
pthread_attr_init(&pa);
|
||||
pthread_attr_setstacksize(&pa,PTHREAD_STACK_MIN + (32768 + srv.stacksize));
|
||||
pthread_attr_setstacksize(&pa,threadstacksize(srv.stacksize));
|
||||
pthread_attr_setdetachstate(&pa,PTHREAD_CREATE_DETACHED);
|
||||
#endif
|
||||
|
||||
@@ -910,13 +982,7 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
}
|
||||
if (iscbc) break;
|
||||
if (conf.paused != srv.paused) break;
|
||||
if (srv.fds.events & POLLIN) {
|
||||
error = srv.so._poll(srv.so.state, &srv.fds, 1, 1000);
|
||||
}
|
||||
else {
|
||||
usleep(SLEEPTIME);
|
||||
continue;
|
||||
}
|
||||
error = srv.so._poll(srv.so.state, &srv.fds, 1, 1000);
|
||||
if (error >= 1) break;
|
||||
if (error == 0) continue;
|
||||
if (errno != EAGAIN && errno != EINTR) {
|
||||
@@ -1027,9 +1093,12 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
else {
|
||||
struct clientparam *toparam;
|
||||
|
||||
srv.udplen = sockrecvfrom(NULL, srv.srvsock, (struct sockaddr *)&defparam.sincr, srv.udpbuf, UDPBUFSIZE, 0);
|
||||
if(srv.udplen <= 0) continue;
|
||||
_3proxy_sem_lock(udpinit);
|
||||
srv.udplen = sockrecvfrom(NULL, srv.srvsock, (struct sockaddr *)&defparam.sincr, srv.udpbuf, UDPBUFSIZE, 0);
|
||||
if(srv.udplen <= 0) {
|
||||
_3proxy_sem_unlock(udpinit);
|
||||
continue;
|
||||
}
|
||||
if(hashresolv(&udp_table, &defparam, &toparam, NULL)) {
|
||||
int i, len=0;
|
||||
|
||||
@@ -1148,12 +1217,7 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
|
||||
#ifndef NOUDPMAIN
|
||||
int udpinited = 0;
|
||||
#ifdef _WIN32
|
||||
HANDLE udpinit;
|
||||
#else
|
||||
_3proxy_mutex_t udpinit;
|
||||
#endif
|
||||
|
||||
_3proxy_sem_t udpinit;
|
||||
#endif
|
||||
|
||||
void srvinit(struct srvparam * srv, struct clientparam *param){
|
||||
@@ -1181,7 +1245,7 @@ void srvinit(struct srvparam * srv, struct clientparam *param){
|
||||
srv->saved_nsfd = srv->i_nsfd = srv->o_nsfd = -1;
|
||||
#endif
|
||||
#ifdef WITHSPLICE
|
||||
srv->usesplice = 1;
|
||||
srv->usesplice = 0;
|
||||
#endif
|
||||
memset(param, 0, sizeof(struct clientparam));
|
||||
param->srv = srv;
|
||||
@@ -1192,11 +1256,7 @@ void srvinit(struct srvparam * srv, struct clientparam *param){
|
||||
_3proxy_mutex_init(&srv->counter_mutex);
|
||||
#ifndef NOUDPMAIN
|
||||
if(!udpinited){
|
||||
#ifdef _WIN32
|
||||
udpinit = CreateSemaphore(NULL, 1, 1, NULL);
|
||||
#else
|
||||
_3proxy_mutex_init(&udpinit);
|
||||
#endif
|
||||
(void)_3proxy_sem_init(udpinit, 1, 1);
|
||||
}
|
||||
udpinited = 1;
|
||||
#endif
|
||||
|
||||
+2
-1
@@ -47,6 +47,7 @@ int clientnegotiate(struct chain * redir, struct clientparam * param, struct soc
|
||||
switch(redir->type){
|
||||
case R_TCP:
|
||||
case R_HTTP:
|
||||
case R_IMAP:
|
||||
return 0;
|
||||
case R_CONNECT:
|
||||
case R_CONNECTP:
|
||||
@@ -374,7 +375,7 @@ int handleredirect(struct clientparam * param, struct ace * acentry){
|
||||
ntohs(*SAPORT(¶m->sincl))
|
||||
);
|
||||
if(socksend(param, param->remsock, (unsigned char *)buf, len, conf.timeouts[CHAIN_TO])!=len) return 39;
|
||||
return 0;
|
||||
if(cur->type == R_HA) return 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
+39
-14
@@ -10,11 +10,23 @@
|
||||
|
||||
#define RETURN(xxx) { param->res = xxx; goto CLEANRET; }
|
||||
|
||||
#ifdef WITHMAIN
|
||||
#define NOSTARTTLS 1
|
||||
#else
|
||||
#define NOSTARTTLS param->srv->nostarttls
|
||||
#endif
|
||||
|
||||
char ehlo[] = "250-Proxy\r\n"
|
||||
"250-AUTH PLAIN LOGIN\r\n"
|
||||
"250-8BITMIME\r\n"
|
||||
"250 DSN\r\n";
|
||||
|
||||
char ehlotls[] = "250-Proxy\r\n"
|
||||
"250-AUTH PLAIN LOGIN\r\n"
|
||||
"250-8BITMIME\r\n"
|
||||
"250-STARTTLS\r\n"
|
||||
"250 DSN\r\n";
|
||||
|
||||
int readreply (struct clientparam* param) {
|
||||
unsigned char * buf;
|
||||
int res, i, bufsize = 640;
|
||||
@@ -44,7 +56,10 @@ int readreply (struct clientparam* param) {
|
||||
|
||||
int readcommand (struct clientparam* param) {
|
||||
unsigned char * buf;
|
||||
int res, i, bufsize = 320;
|
||||
int i, bufsize = 320;
|
||||
#ifndef WITHMAIN
|
||||
int res;
|
||||
#endif
|
||||
int ret = 1;
|
||||
|
||||
if(!(buf = malloc(bufsize))) return 0;
|
||||
@@ -70,7 +85,10 @@ int readcommand (struct clientparam* param) {
|
||||
|
||||
int readdata (struct clientparam* param) {
|
||||
unsigned char * buf;
|
||||
int res, i, bufsize = 4096;
|
||||
int i, bufsize = 4096;
|
||||
#ifndef WITHMAIN
|
||||
int res;
|
||||
#endif
|
||||
|
||||
if(!(buf = malloc(bufsize))) return 0;
|
||||
while ((i = sockgetlinebuf(param, CLIENT, buf, bufsize-1, '\n', conf.timeouts[STRING_L])) > 0 && !(i==3 && buf[0] == '.')){
|
||||
@@ -112,9 +130,18 @@ void * smtppchild(struct clientparam* param) {
|
||||
socksend(param, param->clisock, (unsigned char *)"250 Proxy\r\n", 11,conf.timeouts[STRING_S]);
|
||||
}
|
||||
else if(!strncasecmp((char *)buf, "EHLO ", 5)){
|
||||
socksend(param, param->clisock, (unsigned char *)ehlo, sizeof(ehlo) - 1,conf.timeouts[STRING_S]);
|
||||
if(!NOSTARTTLS) socksend(param, param->clisock, (unsigned char *)ehlotls, sizeof(ehlotls) - 1,conf.timeouts[STRING_S]);
|
||||
else socksend(param, param->clisock, (unsigned char *)ehlo, sizeof(ehlo) - 1,conf.timeouts[STRING_S]);
|
||||
}
|
||||
else if(!param->hostname) socksend(param, param->clisock, (unsigned char *)"571 need AUTH first\r\n", 22, conf.timeouts[STRING_S]);
|
||||
#ifndef WITHMAIN
|
||||
else if(!strncasecmp((char *)buf, "STARTTLS", 8) && !param->srv->nostarttls){
|
||||
if(socksend(param, param->clisock, (unsigned char *)"220 2.0.0 Ready to start TLS\r\n", 30, conf.timeouts[STRING_S])!=30) {RETURN(673);}
|
||||
param->clientstarttls = S_SMTPP;
|
||||
if(!param->srv->targetport) param->srv->targetport = htons(587);
|
||||
return (void *)tlsprchild;
|
||||
}
|
||||
#endif
|
||||
else if(!param->hostname) socksend(param, param->clisock, (unsigned char *)"571 need AUTH first\r\n", 22, conf.timeouts[STRING_S]);
|
||||
else {
|
||||
login = -1;
|
||||
buf[i] = 0;
|
||||
@@ -132,7 +159,7 @@ void * smtppchild(struct clientparam* param) {
|
||||
i = de64(buf,username,255);
|
||||
if(i < 1) {RETURN(664);}
|
||||
username[i] = 0;
|
||||
parseconnusername((char *)username, param, 0, 25);
|
||||
parseconnusername((char *)username, param, 0, 587);
|
||||
socksend(param, param->clisock, (unsigned char *)"334 UGFzc3dvcmQ6\r\n", 18,conf.timeouts[STRING_S]);
|
||||
i = sockgetlinebuf(param, CLIENT, buf, sizeof(buf) - 10, '\n', conf.timeouts[STRING_S]);
|
||||
if(i < 2) {RETURN(665);}
|
||||
@@ -157,7 +184,7 @@ void * smtppchild(struct clientparam* param) {
|
||||
}
|
||||
if(i < 3 || *username) {RETURN(668);}
|
||||
username[i] = 0;
|
||||
parseconnusername((char *)username+1, param, 0, 25);
|
||||
parseconnusername((char *)username+1, param, 0, 587);
|
||||
res = (int)strlen((char *)username+1) + 2;
|
||||
if(res < i){
|
||||
if(param->extpassword) free(param->extpassword);
|
||||
@@ -180,9 +207,7 @@ void * smtppchild(struct clientparam* param) {
|
||||
param->operation = CONNECT;
|
||||
res = (*param->srv->authfunc)(param);
|
||||
if(res) {RETURN(res);}
|
||||
do {
|
||||
i = sockgetlinebuf(param, SERVER, buf, sizeof(buf) - 1, '\n', conf.timeouts[STRING_L]);
|
||||
} while (i > 3 && buf[3] == '-');
|
||||
i = getmultiline(param, SERVER, buf, sizeof(buf) - 1, NULL, NULL);
|
||||
if( i < 3 ) {RETURN(671);}
|
||||
buf[i] = 0;
|
||||
if(strncasecmp((char *)buf, "220", 3)||!strncasecmp((char *)buf+4, "PROXY", 5)){RETURN(672);}
|
||||
@@ -233,9 +258,10 @@ void * smtppchild(struct clientparam* param) {
|
||||
if(i<4 || strncasecmp((char *)buf, "334", 3)) {RETURN(682);}
|
||||
*username = 0;
|
||||
i = (int)strlen((char *)param->extusername) + 1;
|
||||
res = (int)strlen((char *)param->extpassword);
|
||||
if(i + 1 + res >= (int)sizeof(username) || ((i + 1 + res + 2) / 3) * 4 + 1 > (int)sizeof(buf)) {RETURN(683);}
|
||||
memcpy(username+1, param->extusername, i);
|
||||
i++;
|
||||
res = (int)strlen((char *)param->extpassword);
|
||||
memcpy(username + i, param->extpassword, res);
|
||||
i+=res;
|
||||
en64(username, buf, i);
|
||||
@@ -291,7 +317,7 @@ void * smtppchild(struct clientparam* param) {
|
||||
CLEANRET:
|
||||
|
||||
if(param->hostname&¶m->extusername) {
|
||||
sprintf((char *)buf, "%.128s@%.128s%c%hu", param->extusername, param->hostname, *SAPORT(¶m->sinsr)==25?0:':',ntohs(*SAPORT(¶m->sinsr)));
|
||||
sprintf((char *)buf, "%.128s@%.128s%c%hu", param->extusername, param->hostname, *SAPORT(¶m->sinsr)==587?0:':',ntohs(*SAPORT(¶m->sinsr)));
|
||||
dolog(param, buf);
|
||||
}
|
||||
else dolog(param, NULL);
|
||||
@@ -299,17 +325,16 @@ CLEANRET:
|
||||
if ((param->res > 0 && param->res < 100) || (param->res > 661 && param->res <700)) socksend(param, param->clisock, (unsigned char *)"571 \r\n", 6,conf.timeouts[STRING_S]);
|
||||
}
|
||||
if(command) free(command);
|
||||
freeparam(param);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
#ifdef WITHMAIN
|
||||
struct proxydef childdef = {
|
||||
smtppchild,
|
||||
25,
|
||||
587,
|
||||
0,
|
||||
S_SMTPP,
|
||||
" -hdefault_host[:port] - use this host and port as default if no host specified\n"
|
||||
" -hdefault_host[:port] - use this host and port as default if no host specified\n -x - disable STARTTLS\n"
|
||||
|
||||
};
|
||||
#include "proxymain.c"
|
||||
|
||||
+33
-9
@@ -16,15 +16,16 @@ int socksend(struct clientparam *param, SOCKET sock, unsigned char * buf, int bu
|
||||
fds.events = POLLOUT;
|
||||
do {
|
||||
if(conf.timetoexit) return 0;
|
||||
/* try to send first; poll only when the socket would block */
|
||||
res = param?param->srv->so._send(param->sostate, sock, (char *)buf + sent, bufsize - sent, 0) : so._send(so.state, sock, (char *)buf + sent, bufsize - sent, 0);
|
||||
if(res > 0) {
|
||||
sent += res;
|
||||
continue;
|
||||
}
|
||||
if(res < 0 && errno != EAGAIN && errno != EINTR) break;
|
||||
res = param?param->srv->so._poll(param->sostate, &fds, 1, to*1000):so._poll(so.state, &fds, 1, to*1000);
|
||||
if(res < 0 && (errno == EAGAIN || errno == EINTR)) continue;
|
||||
if(res < 1) break;
|
||||
res = param?param->srv->so._send(param->sostate, sock, (char *)buf + sent, bufsize - sent, 0) : so._send(so.state, sock, (char *)buf + sent, bufsize - sent, 0);
|
||||
if(res < 0) {
|
||||
if(errno == EAGAIN || errno == EINTR) continue;
|
||||
break;
|
||||
}
|
||||
sent += res;
|
||||
} while (sent < bufsize);
|
||||
return sent;
|
||||
}
|
||||
@@ -158,10 +159,33 @@ int sockgetlinebuf(struct clientparam * param, DIRECTION which, unsigned char *
|
||||
int c;
|
||||
int i=0;
|
||||
|
||||
while(i < bufsize && (c = (which)?sockgetcharsrv(param, to, 0):sockgetcharcli(param, to, 0)) != EOF){
|
||||
for(;;){
|
||||
unsigned char *base = which? param->srvbuf : param->clibuf;
|
||||
unsigned *offp = which? ¶m->srvoffset : ¶m->clioffset;
|
||||
unsigned *inp = which? ¶m->srvinbuf : ¶m->cliinbuf;
|
||||
|
||||
/* drain already-buffered bytes in bulk instead of one call per byte */
|
||||
if(base && *offp < *inp && i < bufsize){
|
||||
int avail = (int)(*inp - *offp);
|
||||
int n = (bufsize - i < avail)? bufsize - i : avail;
|
||||
if(delim != EOF){
|
||||
unsigned char *d = (unsigned char *)memchr(base + *offp, delim, n);
|
||||
if(d) n = (int)(d - (base + *offp)) + 1;
|
||||
memcpy(buf + i, base + *offp, n);
|
||||
i += n; *offp += n;
|
||||
if(d || i >= bufsize) return i;
|
||||
}
|
||||
else {
|
||||
memcpy(buf + i, base + *offp, n);
|
||||
i += n; *offp += n;
|
||||
if(i >= bufsize) return i;
|
||||
}
|
||||
}
|
||||
if(i >= bufsize) return i;
|
||||
/* buffer empty: one call forces a refill (with poll + accounting), then bulk-drain the rest */
|
||||
if((c = which? sockgetcharsrv(param, to, 0) : sockgetcharcli(param, to, 0)) == EOF) return i;
|
||||
buf[i++] = c;
|
||||
if(delim != EOF && c == delim) break;
|
||||
if((delim != EOF && c == delim) || i >= bufsize) return i;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
+6
-4
@@ -14,7 +14,7 @@
|
||||
#if WITHLOG > 1
|
||||
char logbuf[1024];
|
||||
#endif
|
||||
#define log(X) dolog(param,X)
|
||||
#define log(X) dolog(param,(const unsigned char *)(X))
|
||||
#else
|
||||
#define log(X)
|
||||
#endif
|
||||
@@ -47,13 +47,15 @@ ssize_t splice(int fd_in, loff_t *off_in, int fd_out, loff_t *off_out, size_t le
|
||||
int sockmap(struct clientparam * param, int timeo, int usesplice){
|
||||
uint64_t fromclient=0x7fffffffffffffff, fromserver =0x7fffffffffffffff;
|
||||
uint64_t inclientbuf = 0, inserverbuf = 0;
|
||||
int FROMCLIENT = 1, TOCLIENTBUF = 1, FROMCLIENTBUF = 1, TOSERVER = 1,
|
||||
FROMSERVER = 1, TOSERVERBUF = 1, FROMSERVERBUF = 1, TOCLIENT = 1;
|
||||
int FROMCLIENT = 1, TOCLIENTBUF = 1, TOSERVER = 1,
|
||||
FROMSERVER = 1, TOSERVERBUF = 1, TOCLIENT = 1;
|
||||
#if WITHLOG > 1
|
||||
int FROMCLIENTBUF = 1, FROMSERVERBUF = 1;
|
||||
#endif
|
||||
int HASERROR=0;
|
||||
int CLIENTTERMREAD = 0, CLIENTTERMWRITE = 0, SERVERTERMREAD = 0, SERVERTERMWRITE = 0;
|
||||
int after = 0;
|
||||
struct pollfd fds[8];
|
||||
struct pollfd *fdsp = fds;
|
||||
int fdsc = 0;
|
||||
int sleeptime = 0;
|
||||
FILTER_ACTION action;
|
||||
|
||||
+2
-17
@@ -53,7 +53,6 @@ void * sockschild(struct clientparam* param) {
|
||||
int ver=0;
|
||||
int havepass = 0;
|
||||
PROXYSOCKADDRTYPE sin;
|
||||
int len;
|
||||
|
||||
|
||||
param->service = S_SOCKS;
|
||||
@@ -212,19 +211,7 @@ void * sockschild(struct clientparam* param) {
|
||||
param->operation = command == 2?BIND:UDPASSOC;
|
||||
if(command == 2){
|
||||
if ((param->remsock=param->srv->so._socket(param->sostate, SASOCK(¶m->req), SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) {RETURN (11);}
|
||||
#ifdef REUSE
|
||||
{
|
||||
int opt;
|
||||
#ifdef SO_REUSEADDR
|
||||
opt = 1;
|
||||
param->srv->so._setsockopt(param->sostate, param->remsock, SOL_SOCKET, SO_REUSEADDR, (unsigned char *)&opt, sizeof(int));
|
||||
#endif
|
||||
#ifdef SO_REUSEPORT
|
||||
opt = 1;
|
||||
param->srv->so._setsockopt(param->sostate, param->remsock, SOL_SOCKET, SO_REUSEPORT, (unsigned char *)&opt, sizeof(int));
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
setopts(param->remsock, param->srv->lissockopts);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -385,9 +372,8 @@ fflush(stderr);
|
||||
switch(command) {
|
||||
case 1:
|
||||
if(param->redirectfunc){
|
||||
void *ret = (*param->redirectfunc)(param);
|
||||
if(buf)free(buf);
|
||||
return ret;
|
||||
return (void *)param->redirectfunc;
|
||||
}
|
||||
param->res = mapsocket(param, conf.timeouts[CONNECTION_L]);
|
||||
break;
|
||||
@@ -467,7 +453,6 @@ fflush(stderr);
|
||||
dolog(param, buf);
|
||||
free(buf);
|
||||
}
|
||||
freeparam(param);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,11 +6,20 @@
|
||||
*/
|
||||
|
||||
#include "structures.h"
|
||||
#ifdef WITH_WOLFSSL
|
||||
#include <wolfssl/options.h>
|
||||
#include <wolfssl/openssl/crypto.h>
|
||||
#include <wolfssl/openssl/x509.h>
|
||||
#include <wolfssl/openssl/pem.h>
|
||||
#include <wolfssl/openssl/ssl.h>
|
||||
#include <wolfssl/openssl/err.h>
|
||||
#else
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/err.h>
|
||||
#endif
|
||||
#include "proxy.h"
|
||||
#include "ssl.h"
|
||||
|
||||
@@ -18,6 +27,10 @@
|
||||
#define WINAPI
|
||||
#endif
|
||||
|
||||
#if defined(WITH_WOLFSSL) && !defined(SSL_set_mode)
|
||||
#define SSL_set_mode(ssl,op) ((void)0)
|
||||
#endif
|
||||
|
||||
#ifndef isnumber
|
||||
#define isnumber(i_n_arg) ((i_n_arg>='0')&&(i_n_arg<='9'))
|
||||
#endif
|
||||
@@ -44,7 +57,6 @@ static char *client_ca_store = NULL;
|
||||
static int mitm = 0;
|
||||
static int serv = 0;
|
||||
static int cli = 0;
|
||||
static int ssl_inited = 0;
|
||||
static int client_min_proto_version = 0;
|
||||
static int client_max_proto_version = 0;
|
||||
static int server_min_proto_version = 0;
|
||||
@@ -477,9 +489,23 @@ EVP_PKEY * getKey(const char *fname){
|
||||
return key;
|
||||
}
|
||||
|
||||
static int verify_callback(int preverify_ok, X509_STORE_CTX *ctx){
|
||||
return preverify_ok;
|
||||
#ifdef WITH_WOLFSSL
|
||||
/* wolfSSL's SSL_CTX_use_PrivateKey(EVP_PKEY*) compat is unreliable: it
|
||||
* silently fails (returns 0, no error queued) for keys loaded via
|
||||
* PEM_read_bio_PrivateKey. Export the key to DER and load via the
|
||||
* native buffer API instead. */
|
||||
static int ssl_ctx_use_pkey(SSL_CTX *ctx, EVP_PKEY *key){
|
||||
unsigned char *der = NULL;
|
||||
int len, rc;
|
||||
len = i2d_PrivateKey(key, &der);
|
||||
if(len <= 0 || !der) return 0;
|
||||
rc = wolfSSL_CTX_use_PrivateKey_buffer(ctx, der, (long)len, SSL_FILETYPE_ASN1);
|
||||
OPENSSL_free(der);
|
||||
return rc;
|
||||
}
|
||||
#else
|
||||
#define ssl_ctx_use_pkey(ctx, key) SSL_CTX_use_PrivateKey((ctx), (key))
|
||||
#endif
|
||||
|
||||
|
||||
SSL_CTX * ssl_cli_ctx(SSL_CONFIG *config, X509 *server_cert, EVP_PKEY *server_key, char** errSSL){
|
||||
@@ -487,7 +513,7 @@ SSL_CTX * ssl_cli_ctx(SSL_CONFIG *config, X509 *server_cert, EVP_PKEY *server_ke
|
||||
int err = 0;
|
||||
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
#if !defined(WITH_WOLFSSL) && OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
ctx = SSL_CTX_new(SSLv23_server_method());
|
||||
#else
|
||||
ctx = SSL_CTX_new(TLS_server_method());
|
||||
@@ -507,24 +533,34 @@ SSL_CTX * ssl_cli_ctx(SSL_CONFIG *config, X509 *server_cert, EVP_PKEY *server_ke
|
||||
}
|
||||
}
|
||||
|
||||
err = SSL_CTX_use_PrivateKey(ctx, server_key);
|
||||
if ( err <= 0 ) {
|
||||
*errSSL = getSSLErr();
|
||||
SSL_CTX_free(ctx);
|
||||
return NULL;
|
||||
/* Load the private key only when a cert is already loaded into ctx.
|
||||
* wolfSSL validates the key against the cert and requires the cert
|
||||
* to be present first; OpenSSL tolerates either order but is happy
|
||||
* with cert-first too. When server_cert is NULL (serv path), the
|
||||
* caller loads the cert chain and the key itself after this call. */
|
||||
if(server_cert) {
|
||||
err = ssl_ctx_use_pkey(ctx, server_key);
|
||||
if ( err <= 0 ) {
|
||||
*errSSL = getSSLErr();
|
||||
SSL_CTX_free(ctx);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
SSL_CTX_set_session_id_context(ctx, (const unsigned char *)"3proxy", 6);
|
||||
if(config->server_min_proto_version)SSL_CTX_set_min_proto_version(ctx, config->server_min_proto_version);
|
||||
if(config->server_max_proto_version)SSL_CTX_set_max_proto_version(ctx, config->server_max_proto_version);
|
||||
if(config->server_cipher_list)SSL_CTX_set_cipher_list(ctx, config->server_cipher_list);
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10101000L
|
||||
#if !defined(WITH_WOLFSSL) && OPENSSL_VERSION_NUMBER >= 0x10101000L
|
||||
if(config->server_ciphersuites)SSL_CTX_set_ciphersuites(ctx, config->server_ciphersuites);
|
||||
#elif defined(WITH_WOLFSSL)
|
||||
/* wolfSSL has no separate TLS1.3 ciphersuites API; route to cipher list. */
|
||||
if(config->server_ciphersuites)wolfSSL_CTX_set_cipher_list(ctx, config->server_ciphersuites);
|
||||
#endif
|
||||
if(config->server_verify){
|
||||
if(config->server_ca_file || config->server_ca_dir){
|
||||
SSL_CTX_load_verify_locations(ctx, config->server_ca_file, config->server_ca_dir);
|
||||
}
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
#if !defined(WITH_WOLFSSL) && OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
else if(config->server_ca_store){
|
||||
SSL_CTX_load_verify_store(ctx, config->server_ca_store);
|
||||
}
|
||||
@@ -643,6 +679,10 @@ static void* ssl_filter_open(void * idata, struct srvparam * srv){
|
||||
fprintf(stderr, "failed to read server cert: %s\n", srvcert);
|
||||
return sc;
|
||||
}
|
||||
if(ssl_ctx_use_pkey(sc->cli_ctx, sc->server_key) <= 0){
|
||||
fprintf(stderr, "failed to use server key\n");
|
||||
return sc;
|
||||
}
|
||||
sc->serv = 1;
|
||||
}
|
||||
if(mitm || cli || serv){
|
||||
@@ -655,7 +695,7 @@ static void* ssl_filter_open(void * idata, struct srvparam * srv){
|
||||
srv->so._poll = ssl_poll;
|
||||
}
|
||||
if(sc && (sc->mitm || sc->cli)){
|
||||
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
#if !defined(WITH_WOLFSSL) && OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
sc->srv_ctx = SSL_CTX_new(SSLv23_client_method());
|
||||
#else
|
||||
sc->srv_ctx = SSL_CTX_new(TLS_client_method());
|
||||
@@ -666,30 +706,42 @@ static void* ssl_filter_open(void * idata, struct srvparam * srv){
|
||||
}
|
||||
if(sc->client_cert){
|
||||
SSL_CTX_use_certificate(sc->srv_ctx, (X509 *) sc->client_cert);
|
||||
SSL_CTX_use_PrivateKey(sc->srv_ctx, sc->client_key);
|
||||
ssl_ctx_use_pkey(sc->srv_ctx, sc->client_key);
|
||||
}
|
||||
if(sc->client_min_proto_version)SSL_CTX_set_min_proto_version(sc->srv_ctx, sc->client_min_proto_version);
|
||||
if(sc->client_max_proto_version)SSL_CTX_set_max_proto_version(sc->srv_ctx, sc->client_max_proto_version);
|
||||
if(sc->client_cipher_list)SSL_CTX_set_cipher_list(sc->srv_ctx, sc->client_cipher_list);
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10101000L
|
||||
#if !defined(WITH_WOLFSSL) && OPENSSL_VERSION_NUMBER >= 0x10101000L
|
||||
if(sc->client_ciphersuites)SSL_CTX_set_ciphersuites(sc->srv_ctx, sc->client_ciphersuites);
|
||||
#elif defined(WITH_WOLFSSL)
|
||||
/* wolfSSL has no separate TLS1.3 ciphersuites API; route to cipher list. */
|
||||
if(sc->client_ciphersuites)wolfSSL_CTX_set_cipher_list(sc->srv_ctx, sc->client_ciphersuites);
|
||||
#endif
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10200000L
|
||||
#if (defined(WITH_WOLFSSL) && defined(HAVE_ALPN) && LIBWOLFSSL_VERSION_HEX >= 0x03007000) || (!defined(WITH_WOLFSSL) && OPENSSL_VERSION_NUMBER >= 0x10200000L)
|
||||
if(sc->client_alpn_protos.protos_len)SSL_CTX_set_alpn_protos(sc->srv_ctx, sc->client_alpn_protos.protos, sc->client_alpn_protos.protos_len);
|
||||
#endif
|
||||
if(sc->client_verify){
|
||||
if(sc->client_ca_file || sc->client_ca_dir){
|
||||
SSL_CTX_load_verify_locations(sc->srv_ctx, sc->client_ca_file, sc->client_ca_dir);
|
||||
}
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
#if !defined(WITH_WOLFSSL) && OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
else if(sc->client_ca_store){
|
||||
SSL_CTX_load_verify_store(sc->srv_ctx, sc->client_ca_store);
|
||||
}
|
||||
#endif
|
||||
else
|
||||
SSL_CTX_set_default_verify_paths(sc->srv_ctx);
|
||||
SSL_CTX_set_verify(sc->srv_ctx, SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL);
|
||||
SSL_CTX_set_verify(sc->srv_ctx, SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL);
|
||||
}
|
||||
#ifdef WITH_WOLFSSL
|
||||
else {
|
||||
/* wolfSSL defaults to peer verification; OpenSSL defaults to
|
||||
* SSL_VERIFY_NONE. Make the no-verify intent explicit so the
|
||||
* upstream handshake (ssl_cli / ssl_mitm) succeeds without a
|
||||
* trusted CA store. */
|
||||
SSL_CTX_set_verify(sc->srv_ctx, SSL_VERIFY_NONE, NULL);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifdef WITHSPLICE
|
||||
srv->usesplice = 0;
|
||||
@@ -865,7 +917,7 @@ static void unsetfilters(){
|
||||
}
|
||||
}
|
||||
|
||||
static int h_mitm(int argc, unsigned char **argv){
|
||||
int h_mitm(int argc, unsigned char **argv){
|
||||
if(mitm) return 0;
|
||||
if(serv) return 2;
|
||||
mitm = 1;
|
||||
@@ -873,14 +925,14 @@ static int h_mitm(int argc, unsigned char **argv){
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_nomitm(int argc, unsigned char **argv){
|
||||
int h_nomitm(int argc, unsigned char **argv){
|
||||
if(!mitm) return 0;
|
||||
mitm = 0;
|
||||
unsetfilters();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_serv(int argc, unsigned char **argv){
|
||||
int h_serv(int argc, unsigned char **argv){
|
||||
if(serv) return 0;
|
||||
if(mitm) return 2;
|
||||
serv = 1;
|
||||
@@ -888,14 +940,14 @@ static int h_serv(int argc, unsigned char **argv){
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_noserv(int argc, unsigned char **argv){
|
||||
int h_noserv(int argc, unsigned char **argv){
|
||||
if(!serv) return 0;
|
||||
serv = 0;
|
||||
unsetfilters();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_cli(int argc, unsigned char **argv){
|
||||
int h_cli(int argc, unsigned char **argv){
|
||||
if(cli) return 0;
|
||||
if(mitm) return 2;
|
||||
cli = 1;
|
||||
@@ -903,7 +955,7 @@ static int h_cli(int argc, unsigned char **argv){
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_nocli(int argc, unsigned char **argv){
|
||||
int h_nocli(int argc, unsigned char **argv){
|
||||
if(!cli) return 0;
|
||||
cli = 0;
|
||||
unsetfilters();
|
||||
@@ -911,7 +963,7 @@ static int h_nocli(int argc, unsigned char **argv){
|
||||
}
|
||||
|
||||
|
||||
static int h_certcache(int argc, unsigned char **argv){
|
||||
int h_certcache(int argc, unsigned char **argv){
|
||||
size_t len;
|
||||
len = strlen((char *)argv[1]);
|
||||
if(!len || (argv[1][len - 1] != '/' && argv[1][len - 1] != '\\')) return 1;
|
||||
@@ -920,92 +972,92 @@ static int h_certcache(int argc, unsigned char **argv){
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_srvcert(int argc, unsigned char **argv){
|
||||
int h_srvcert(int argc, unsigned char **argv){
|
||||
free(srvcert);
|
||||
srvcert = argc > 1? strdup((char *)argv[1]) : NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_srvkey(int argc, unsigned char **argv){
|
||||
int h_srvkey(int argc, unsigned char **argv){
|
||||
free(srvkey);
|
||||
srvkey = argc > 1? strdup((char *)argv[1]) : NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_clicert(int argc, unsigned char **argv){
|
||||
int h_clicert(int argc, unsigned char **argv){
|
||||
free(clicert);
|
||||
clicert = argc > 1? strdup((char *)argv[1]) : NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_clikey(int argc, unsigned char **argv){
|
||||
int h_clikey(int argc, unsigned char **argv){
|
||||
free(clikey);
|
||||
clikey = argc > 1? strdup((char *)argv[1]) : NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int h_client_cipher_list(int argc, unsigned char **argv){
|
||||
int h_client_cipher_list(int argc, unsigned char **argv){
|
||||
free(client_cipher_list);
|
||||
client_cipher_list = argc > 1? strdup((char *)argv[1]) : NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_server_cipher_list(int argc, unsigned char **argv){
|
||||
int h_server_cipher_list(int argc, unsigned char **argv){
|
||||
free(server_cipher_list);
|
||||
server_cipher_list = argc > 1? strdup((char *)argv[1]) : NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_client_ciphersuites(int argc, unsigned char **argv){
|
||||
int h_client_ciphersuites(int argc, unsigned char **argv){
|
||||
free(client_ciphersuites);
|
||||
client_ciphersuites = argc > 1? strdup((char *)argv[1]) : NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_server_ciphersuites(int argc, unsigned char **argv){
|
||||
int h_server_ciphersuites(int argc, unsigned char **argv){
|
||||
free(server_ciphersuites);
|
||||
server_ciphersuites = argc > 1? strdup((char *)argv[1]) : NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_server_ca_file(int argc, unsigned char **argv){
|
||||
int h_server_ca_file(int argc, unsigned char **argv){
|
||||
free(server_ca_file);
|
||||
server_ca_file = argc > 1? strdup((char *)argv[1]) : NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_server_ca_key(int argc, unsigned char **argv){
|
||||
int h_server_ca_key(int argc, unsigned char **argv){
|
||||
free(server_ca_key);
|
||||
server_ca_key = argc > 1? strdup((char *)argv[1]) : NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_client_ca_file(int argc, unsigned char **argv){
|
||||
int h_client_ca_file(int argc, unsigned char **argv){
|
||||
free(client_ca_file);
|
||||
client_ca_file = argc > 1? strdup((char *)argv[1]) : NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_client_ca_dir(int argc, unsigned char **argv){
|
||||
int h_client_ca_dir(int argc, unsigned char **argv){
|
||||
free(client_ca_dir);
|
||||
client_ca_dir = argc > 1? strdup((char *)argv[1]) : NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_client_ca_store(int argc, unsigned char **argv){
|
||||
int h_client_ca_store(int argc, unsigned char **argv){
|
||||
free(client_ca_store);
|
||||
client_ca_store = argc > 1? strdup((char *)argv[1]) : NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_client_sni(int argc, unsigned char **argv){
|
||||
int h_client_sni(int argc, unsigned char **argv){
|
||||
free(client_sni);
|
||||
client_sni = argc > 1? strdup((char *)argv[1]) : NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_client_alpn(int argc, unsigned char **argv){
|
||||
int h_client_alpn(int argc, unsigned char **argv){
|
||||
int len, i;
|
||||
|
||||
if(client_alpn_protos.protos_len){
|
||||
@@ -1035,13 +1087,13 @@ static int h_client_alpn(int argc, unsigned char **argv){
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_server_ca_dir(int argc, unsigned char **argv){
|
||||
int h_server_ca_dir(int argc, unsigned char **argv){
|
||||
free(server_ca_dir);
|
||||
server_ca_dir = argc > 1? strdup((char *)argv[1]) : NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_server_ca_store(int argc, unsigned char **argv){
|
||||
int h_server_ca_store(int argc, unsigned char **argv){
|
||||
free(server_ca_store);
|
||||
server_ca_store = argc > 1? strdup((char *)argv[1]) : NULL;
|
||||
return 0;
|
||||
@@ -1082,41 +1134,41 @@ int string_to_version(unsigned char *ver){
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_client_min_proto_version(int argc, unsigned char **argv){
|
||||
int h_client_min_proto_version(int argc, unsigned char **argv){
|
||||
client_min_proto_version = argc>1? string_to_version(argv[1]) : 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_client_max_proto_version(int argc, unsigned char **argv){
|
||||
int h_client_max_proto_version(int argc, unsigned char **argv){
|
||||
client_max_proto_version = argc>1? string_to_version(argv[1]) : 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_server_min_proto_version(int argc, unsigned char **argv){
|
||||
int h_server_min_proto_version(int argc, unsigned char **argv){
|
||||
server_min_proto_version = argc>1? string_to_version(argv[1]) : 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_server_max_proto_version(int argc, unsigned char **argv){
|
||||
int h_server_max_proto_version(int argc, unsigned char **argv){
|
||||
server_max_proto_version = argc>1? string_to_version(argv[1]) : 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_client_verify(int argc, unsigned char **argv){
|
||||
int h_client_verify(int argc, unsigned char **argv){
|
||||
client_verify = 1;
|
||||
return 0;
|
||||
}
|
||||
static int h_no_client_verify(int argc, unsigned char **argv){
|
||||
int h_no_client_verify(int argc, unsigned char **argv){
|
||||
client_verify = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_server_verify(int argc, unsigned char **argv){
|
||||
int h_server_verify(int argc, unsigned char **argv){
|
||||
server_verify = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_client_mode(int argc, unsigned char **argv){
|
||||
int h_client_mode(int argc, unsigned char **argv){
|
||||
client_mode = 0;
|
||||
if(argc <= 1) return 0;
|
||||
client_mode = atoi((char *)argv[1]);
|
||||
@@ -1124,51 +1176,11 @@ static int h_client_mode(int argc, unsigned char **argv){
|
||||
}
|
||||
|
||||
|
||||
static int h_no_server_verify(int argc, unsigned char **argv){
|
||||
int h_no_server_verify(int argc, unsigned char **argv){
|
||||
server_verify = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct commands ssl_commandhandlers[] = {
|
||||
{ssl_commandhandlers+1, "ssl_mitm", h_mitm, 1, 1},
|
||||
{ssl_commandhandlers+2, "ssl_nomitm", h_nomitm, 1, 1},
|
||||
{ssl_commandhandlers+3, "ssl_serv", h_serv, 1, 1},
|
||||
{ssl_commandhandlers+4, "ssl_noserv", h_noserv, 1, 1},
|
||||
{ssl_commandhandlers+5, "ssl_server_cert", h_srvcert, 1, 2},
|
||||
{ssl_commandhandlers+6, "ssl_server_key", h_srvkey, 1, 2},
|
||||
{ssl_commandhandlers+7, "ssl_server_ca_file", h_server_ca_file, 1, 2},
|
||||
{ssl_commandhandlers+8, "ssl_server_ca_key", h_server_ca_key, 1, 2},
|
||||
{ssl_commandhandlers+9, "ssl_client_ca_file", h_client_ca_file, 1, 2},
|
||||
{ssl_commandhandlers+10, "ssl_client_ca_dir", h_client_ca_dir, 1, 2},
|
||||
{ssl_commandhandlers+11, "ssl_client_ca_store", h_client_ca_store, 1, 2},
|
||||
{ssl_commandhandlers+12, "ssl_client_ciphersuites", h_client_ciphersuites, 1, 2},
|
||||
{ssl_commandhandlers+13, "ssl_server_ciphersuites", h_server_ciphersuites, 1, 2},
|
||||
{ssl_commandhandlers+14, "ssl_client_cipher_list", h_client_cipher_list, 1, 2},
|
||||
{ssl_commandhandlers+15, "ssl_server_cipher_list", h_server_cipher_list, 1, 2},
|
||||
{ssl_commandhandlers+16, "ssl_client_min_proto_version", h_client_min_proto_version, 1, 2},
|
||||
{ssl_commandhandlers+17, "ssl_server_min_proto_version", h_server_min_proto_version, 1, 2},
|
||||
{ssl_commandhandlers+18, "ssl_client_max_proto_version", h_client_max_proto_version, 1, 2},
|
||||
{ssl_commandhandlers+19, "ssl_server_max_proto_version", h_server_max_proto_version, 1, 2},
|
||||
{ssl_commandhandlers+20, "ssl_client_verify", h_client_verify, 1, 1},
|
||||
{ssl_commandhandlers+21, "ssl_client_no_verify", h_no_client_verify, 1, 1},
|
||||
{ssl_commandhandlers+22, "ssl_cli", h_cli, 1, 1},
|
||||
{ssl_commandhandlers+23, "ssl_nocli", h_nocli, 1, 1},
|
||||
{ssl_commandhandlers+24, "ssl_client_cert", h_clicert, 1, 2},
|
||||
{ssl_commandhandlers+25, "ssl_client_key", h_clikey, 1, 2},
|
||||
{ssl_commandhandlers+26, "ssl_server", h_serv, 1, 1},
|
||||
{ssl_commandhandlers+27, "ssl_noserver", h_noserv, 1, 1},
|
||||
{ssl_commandhandlers+28, "ssl_client", h_cli, 1, 1},
|
||||
{ssl_commandhandlers+29, "ssl_noclient", h_nocli, 1, 1},
|
||||
{ssl_commandhandlers+30, "ssl_server_verify", h_server_verify, 1, 1},
|
||||
{ssl_commandhandlers+31, "ssl_server_no_verify", h_no_server_verify, 1, 1},
|
||||
{ssl_commandhandlers+32, "ssl_server_ca_dir", h_server_ca_dir, 1, 2},
|
||||
{ssl_commandhandlers+33, "ssl_server_ca_store", h_server_ca_store, 1, 2},
|
||||
{ssl_commandhandlers+34, "ssl_client_sni", h_client_sni, 1, 2},
|
||||
{ssl_commandhandlers+35, "ssl_client_alpn", h_client_alpn, 1, 0},
|
||||
{ssl_commandhandlers+36, "ssl_client_mode", h_client_mode, 1, 2},
|
||||
{NULL, "ssl_certcache", h_certcache, 2, 2},
|
||||
};
|
||||
|
||||
static struct symbol ssl_symbols[] = {
|
||||
{NULL, "ssl_parent", (void *)&ssl_parent},
|
||||
};
|
||||
@@ -1226,8 +1238,6 @@ void ssl_install(void){
|
||||
if(!ssl_loaded){
|
||||
ssl_loaded = 1;
|
||||
ssl_init();
|
||||
ssl_commandhandlers[(sizeof(ssl_commandhandlers)/sizeof(struct commands))-1].next = pl->commandhandlers->next;
|
||||
pl->commandhandlers->next = ssl_commandhandlers;
|
||||
ssl_symbols[0].next = pl->symbols.next;
|
||||
pl->symbols.next = ssl_symbols;
|
||||
}
|
||||
|
||||
+102
-75
@@ -14,14 +14,21 @@
|
||||
#include <sys/file.h>
|
||||
#endif
|
||||
|
||||
#ifdef WITH_WOLFSSL
|
||||
#include <wolfssl/options.h>
|
||||
#include <wolfssl/openssl/crypto.h>
|
||||
#include <wolfssl/openssl/x509.h>
|
||||
#include <wolfssl/openssl/x509v3.h>
|
||||
#include <wolfssl/openssl/pem.h>
|
||||
#include <wolfssl/openssl/ssl.h>
|
||||
#include <wolfssl/openssl/err.h>
|
||||
#else
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/x509v3.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/err.h>
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
#include <openssl/provider.h>
|
||||
#endif
|
||||
|
||||
#include "proxy.h"
|
||||
@@ -38,8 +45,6 @@ static char hexMap[] = {
|
||||
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
|
||||
};
|
||||
|
||||
static BIO *bio_err=NULL;
|
||||
|
||||
|
||||
|
||||
char * getSSLErr(){
|
||||
@@ -67,10 +72,23 @@ static size_t bin2hex (const unsigned char* bin, size_t bin_length, char* str, s
|
||||
return p - str;
|
||||
}
|
||||
|
||||
static int add_ext(X509 *cert, int nid, char *value)
|
||||
static int copy_ext(X509 *dst_cert, X509 *src_cert, int nid)
|
||||
{
|
||||
X509_EXTENSION *ext;
|
||||
int idx;
|
||||
|
||||
idx = X509_get_ext_by_NID(src_cert, nid, -1);
|
||||
if(idx < 0) return 0;
|
||||
if(!(ext = X509_get_ext(src_cert, idx))) return 0;
|
||||
return X509_add_ext(dst_cert, ext, -1) > 0;
|
||||
}
|
||||
|
||||
#ifndef WITH_WOLFSSL
|
||||
static int add_ext(X509 *cert, int nid, const char *value)
|
||||
{
|
||||
X509_EXTENSION *ex;
|
||||
X509V3_CTX ctx;
|
||||
int err;
|
||||
/* This sets the 'context' of the extensions. */
|
||||
/* No configuration database */
|
||||
X509V3_set_ctx_nodb(&ctx);
|
||||
@@ -78,25 +96,16 @@ static int add_ext(X509 *cert, int nid, char *value)
|
||||
* no request and no CRL
|
||||
*/
|
||||
X509V3_set_ctx(&ctx, cert, cert, NULL, NULL, 0);
|
||||
ex = X509V3_EXT_conf_nid(NULL, &ctx, nid, value);
|
||||
/* value is char * prior to OpenSSL 1.1.0 */
|
||||
ex = X509V3_EXT_conf_nid(NULL, &ctx, nid, (char *)value);
|
||||
if (!ex)
|
||||
return 0;
|
||||
|
||||
X509_add_ext(cert,ex,-1);
|
||||
err = X509_add_ext(cert,ex,-1);
|
||||
X509_EXTENSION_free(ex);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void del_ext(X509 *dst_cert, int nid, int where){
|
||||
int ex;
|
||||
|
||||
ex = X509_get_ext_by_NID(dst_cert, nid, where);
|
||||
if(ex>=0){
|
||||
X509_EXTENSION *ext;
|
||||
if((ext = X509_delete_ext(dst_cert, ex))) X509_EXTENSION_free(ext);
|
||||
}
|
||||
|
||||
return err > 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
SSL_CERT ssl_copy_cert(SSL_CERT cert, SSL_CONFIG *config)
|
||||
{
|
||||
@@ -105,22 +114,18 @@ SSL_CERT ssl_copy_cert(SSL_CERT cert, SSL_CONFIG *config)
|
||||
X509 *src_cert = (X509 *) cert;
|
||||
X509 *dst_cert = NULL;
|
||||
|
||||
EVP_PKEY *pk = NULL;
|
||||
RSA *rsa = NULL;
|
||||
|
||||
int hash_size = 20;
|
||||
unsigned char hash_sha1[20];
|
||||
char hash_name_sha1[(20*2) + 1];
|
||||
unsigned char hash_sha256[32];
|
||||
char hash_name_sha256[(16*2) + 1];
|
||||
char cache_name[256];
|
||||
|
||||
err = X509_digest(src_cert, EVP_sha1(), hash_sha1, NULL);
|
||||
err = X509_digest(src_cert, EVP_sha256(), hash_sha256, NULL);
|
||||
if(!err){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(config->certcache){
|
||||
bin2hex(hash_sha1, 20, hash_name_sha1, sizeof(hash_name_sha1));
|
||||
sprintf(cache_name, "%s%s.pem", config->certcache, hash_name_sha1);
|
||||
bin2hex(hash_sha256, 16, hash_name_sha256, sizeof(hash_name_sha256));
|
||||
sprintf(cache_name, "%s%s.pem", config->certcache, hash_name_sha256);
|
||||
/* check if certificate is already cached */
|
||||
fcache = BIO_new_file(cache_name, "rb");
|
||||
if ( fcache != NULL ) {
|
||||
@@ -137,28 +142,67 @@ SSL_CERT ssl_copy_cert(SSL_CERT cert, SSL_CONFIG *config)
|
||||
}
|
||||
}
|
||||
}
|
||||
/* proceed if certificate is not cached */
|
||||
dst_cert = X509_dup(src_cert);
|
||||
/* Build a fresh certificate instead of duplicating the source: only
|
||||
* the fields required for a usable server cert are copied (version,
|
||||
* serial, subject, validity, SAN). This avoids inheriting upstream
|
||||
* extensions (AKI, CRL dist points, certificate policies, ...) that
|
||||
* break chain validation, and works around wolfSSL's no-op
|
||||
* X509_delete_ext compat shim. */
|
||||
dst_cert = X509_new();
|
||||
if ( dst_cert == NULL ) {
|
||||
return NULL;
|
||||
}
|
||||
del_ext(dst_cert, NID_crl_distribution_points, -1);
|
||||
del_ext(dst_cert, NID_info_access, -1);
|
||||
del_ext(dst_cert, NID_authority_key_identifier, -1);
|
||||
del_ext(dst_cert, NID_certificate_policies, 0);
|
||||
|
||||
/* v3 is required, extensions are added below */
|
||||
X509_set_version(dst_cert, 2);
|
||||
if(!X509_set_serialNumber(dst_cert, X509_get_serialNumber(src_cert))
|
||||
|| !X509_set_subject_name(dst_cert, X509_get_subject_name(src_cert))
|
||||
|| !X509_set_issuer_name(dst_cert, X509_get_subject_name(config->CA_cert))){
|
||||
X509_free(dst_cert);
|
||||
return NULL;
|
||||
}
|
||||
err = X509_set_pubkey(dst_cert, config->server_key?config->server_key:config->CA_key);
|
||||
if ( err == 0 ) {
|
||||
X509_free(dst_cert);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
err = X509_set_issuer_name(dst_cert, X509_get_subject_name(config->CA_cert));
|
||||
if(!err){
|
||||
/* wolfSSL has no X509_set1_notBefore/X509_set1_notAfter before 5.7.2,
|
||||
X509_set_notBefore/X509_set_notAfter are available in every version and
|
||||
copy the time the same way.
|
||||
*/
|
||||
#if defined(WITH_WOLFSSL) || OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
if(!X509_set_notBefore(dst_cert, X509_get_notBefore(src_cert))
|
||||
|| !X509_set_notAfter(dst_cert, X509_get_notAfter(src_cert))){
|
||||
#else
|
||||
if(!X509_set1_notBefore(dst_cert, X509_get0_notBefore(src_cert))
|
||||
|| !X509_set1_notAfter(dst_cert, X509_get0_notAfter(src_cert))){
|
||||
#endif
|
||||
X509_free(dst_cert);
|
||||
return NULL;
|
||||
}
|
||||
/* Copy the extensions an end entity certificate is expected to have.
|
||||
* The extensions which break chain validation (AKI, CRL distribution
|
||||
* points, certificate policies, ...) are intentionally not copied.
|
||||
* A copy may fail: wolfSSL keeps extKeyUsage in its own form and can
|
||||
* not add back the one it returns, it is not fatal.
|
||||
*/
|
||||
copy_ext(dst_cert, src_cert, NID_subject_alt_name);
|
||||
#ifndef WITH_WOLFSSL
|
||||
/* Without EKU serverAuth Apple's TLS stack (and Chrome on macOS/iOS,
|
||||
* which uses it) rejects the certificate, generate the extensions the
|
||||
* server certificate has no usable ones to copy. keyUsage is not set:
|
||||
* it depends on the type of the key reused for every generated
|
||||
* certificate, and an absent keyUsage places no restriction.
|
||||
* wolfSSL_X509V3_EXT_conf_nid() is a stub returning NULL in every
|
||||
* wolfSSL version, the extensions can not be generated there.
|
||||
*/
|
||||
if(!copy_ext(dst_cert, src_cert, NID_basic_constraints))
|
||||
add_ext(dst_cert, NID_basic_constraints, "critical,CA:FALSE");
|
||||
if(!copy_ext(dst_cert, src_cert, NID_ext_key_usage))
|
||||
add_ext(dst_cert, NID_ext_key_usage, "serverAuth");
|
||||
#else
|
||||
copy_ext(dst_cert, src_cert, NID_basic_constraints);
|
||||
copy_ext(dst_cert, src_cert, NID_ext_key_usage);
|
||||
#endif
|
||||
err = X509_sign(dst_cert, config->CA_key, EVP_sha256());
|
||||
if(!err){
|
||||
X509_free(dst_cert);
|
||||
@@ -224,10 +268,18 @@ void _ssl_cert_free(SSL_CERT cert)
|
||||
|
||||
|
||||
|
||||
/* OpenSSL before 1.1.0 requires the application to install threading
|
||||
callbacks; OpenSSL >= 1.1.0 and wolfSSL handle locking internally. */
|
||||
#if !defined(WITH_WOLFSSL) && defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
#define LEGACY_SSL_THREADING 1
|
||||
#else
|
||||
#define LEGACY_SSL_THREADING 0
|
||||
#endif
|
||||
|
||||
#if LEGACY_SSL_THREADING
|
||||
/* This array will store all of the mutexes available to OpenSSL. */
|
||||
static _3proxy_mutex_t *mutex_buf= NULL;
|
||||
|
||||
|
||||
static void locking_function(int mode, int n, const char * file, int line)
|
||||
{
|
||||
if (mode & CRYPTO_LOCK)
|
||||
@@ -244,9 +296,11 @@ static unsigned long id_function(void)
|
||||
return ((unsigned long)pthread_self());
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
int thread_setup(void)
|
||||
{
|
||||
#if LEGACY_SSL_THREADING
|
||||
int i;
|
||||
|
||||
mutex_buf = malloc(CRYPTO_num_locks( ) * sizeof(_3proxy_mutex_t));
|
||||
@@ -256,21 +310,7 @@ int thread_setup(void)
|
||||
_3proxy_mutex_init(mutex_buf +i);
|
||||
CRYPTO_set_id_callback(id_function);
|
||||
CRYPTO_set_locking_callback(locking_function);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int thread_cleanup(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!mutex_buf)
|
||||
return 0;
|
||||
CRYPTO_set_id_callback(NULL);
|
||||
CRYPTO_set_locking_callback(NULL);
|
||||
for (i = 0; i < CRYPTO_num_locks( ); i++)
|
||||
_3proxy_mutex_destroy(mutex_buf +i);
|
||||
free(mutex_buf);
|
||||
mutex_buf = NULL;
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -280,33 +320,20 @@ int ssl_file_init = 0;
|
||||
|
||||
int ssl_init_done = 0;
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
extern EVP_MD *md4_hash;
|
||||
extern EVP_MD *md5_hash;
|
||||
#endif
|
||||
|
||||
|
||||
void ssl_init()
|
||||
{
|
||||
if(!ssl_init_done){
|
||||
|
||||
|
||||
ssl_init_done = 1;
|
||||
thread_setup();
|
||||
#ifdef WITH_WOLFSSL
|
||||
wolfSSL_Init();
|
||||
#elif defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||
OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS, NULL);
|
||||
#else
|
||||
SSLeay_add_ssl_algorithms();
|
||||
SSL_load_error_strings();
|
||||
_3proxy_mutex_init(&ssl_file_mutex);
|
||||
bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
OSSL_PROVIDER_load(NULL, "legacy");
|
||||
OSSL_PROVIDER_load(NULL, "default");
|
||||
md4_hash = EVP_MD_fetch(NULL, "MD4", NULL);
|
||||
if (md4_hash == NULL) {
|
||||
fprintf(stderr, "Error fetching MD4\n");
|
||||
}
|
||||
md5_hash = EVP_MD_fetch(NULL, "MD5", NULL);
|
||||
if (md5_hash == NULL) {
|
||||
fprintf(stderr, "Error fetching MD5\n");
|
||||
}
|
||||
#endif
|
||||
_3proxy_mutex_init(&ssl_file_mutex);
|
||||
}
|
||||
}
|
||||
Loaded 100 of 107 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user