mirror of
https://github.com/3proxy/3proxy.git
synced 2026-11-26 23:59:41 +08:00
Compare commits
No files matched your search
@@ -0,0 +1,140 @@
|
||||
name: OpenWrt ipk build
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
env:
|
||||
OPENWRT_RELEASE: 24.10.0
|
||||
|
||||
jobs:
|
||||
ipk:
|
||||
permissions:
|
||||
contents: write
|
||||
id-token: write
|
||||
attestations: write
|
||||
name: "${{ matrix.arch }}"
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- target: ramips/mt7621
|
||||
arch: mipsel_24kc
|
||||
- target: ath79/generic
|
||||
arch: mips_24kc
|
||||
- target: ipq40xx/generic
|
||||
arch: arm_cortex-a7_neon-vfpv4
|
||||
- target: mediatek/filogic
|
||||
arch: aarch64_cortex-a53
|
||||
# 26.04: the OpenWrt SDK refuses its non-GNU install
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
|
||||
- name: env
|
||||
run: echo "RELEASE=$(tr -d ' \t\r\n' < RELEASE)" >> $GITHUB_ENV
|
||||
|
||||
- name: Install build dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y build-essential libncurses-dev zlib1g-dev gawk git \
|
||||
gettext libssl-dev xsltproc wget unzip python3 rsync file zstd
|
||||
|
||||
- name: Fetch SDK
|
||||
run: |
|
||||
BASE="https://downloads.openwrt.org/releases/$OPENWRT_RELEASE/targets/${{ matrix.target }}"
|
||||
# The SDK file name carries the toolchain flavour, which differs between
|
||||
# targets (musl vs musl_eabi), so take it from the directory listing.
|
||||
NAME=$(curl -fsSL "$BASE/" | grep -oE 'openwrt-sdk-[^"]*\.tar\.zst' | head -1)
|
||||
if [ -z "$NAME" ]; then echo "no SDK for ${{ matrix.target }}"; exit 1; fi
|
||||
echo "fetching $NAME"
|
||||
curl -fsSL "$BASE/$NAME" -o sdk.tar.zst
|
||||
tar --zstd -xf sdk.tar.zst
|
||||
mv "${NAME%.tar.zst}" sdk
|
||||
rm sdk.tar.zst
|
||||
|
||||
- name: Stage the package
|
||||
run: |
|
||||
mkdir -p sdk/package/3proxy sdk/dl
|
||||
cp -a scripts/openwrt/. sdk/package/3proxy/
|
||||
# Build the checkout rather than a published tarball, so the workflow
|
||||
# does not depend on the release archive existing yet.
|
||||
git archive --format=tar.gz --prefix="3proxy-$RELEASE/" -o "sdk/dl/3proxy-$RELEASE.tar.gz" HEAD
|
||||
HASH=$(sha256sum "sdk/dl/3proxy-$RELEASE.tar.gz" | cut -d' ' -f1)
|
||||
sed -i "s|^PKG_VERSION:=.*|PKG_VERSION:=$RELEASE|" sdk/package/3proxy/Makefile
|
||||
sed -i "s|^PKG_HASH:=.*|PKG_HASH:=$HASH|" sdk/package/3proxy/Makefile
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
cd sdk
|
||||
./scripts/feeds update base packages
|
||||
./scripts/feeds install libopenssl libpcre2
|
||||
echo CONFIG_PACKAGE_3proxy=m >> .config
|
||||
make defconfig
|
||||
make package/3proxy/compile -j$(nproc)
|
||||
|
||||
- name: Collect
|
||||
run: |
|
||||
find sdk/bin -name '3proxy_*.ipk' -exec cp {} . \;
|
||||
ls -l *.ipk
|
||||
for f in *.ipk; do echo "$f"; done
|
||||
|
||||
- name: Get artifact ipk
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: "3proxy-${{ env.RELEASE }}-${{ matrix.arch }}.ipk"
|
||||
path: "*.ipk"
|
||||
|
||||
- name: Import signing key
|
||||
if: github.event_name == 'release'
|
||||
env:
|
||||
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
|
||||
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
|
||||
run: |
|
||||
if [ -z "$GPG_PRIVATE_KEY" ]; then echo "GPG_PRIVATE_KEY is not set"; exit 1; fi
|
||||
mkdir -p ~/.gnupg && chmod 700 ~/.gnupg
|
||||
printf 'allow-loopback-pinentry\ndefault-cache-ttl 7200\nmax-cache-ttl 7200\n' > ~/.gnupg/gpg-agent.conf
|
||||
gpgconf --kill gpg-agent || true
|
||||
printf '%s' "$GPG_PRIVATE_KEY" | gpg --batch --import
|
||||
KEYID=$(gpg --list-secret-keys --with-colons | awk -F: '/^sec:/{print $5; exit}')
|
||||
echo "GPG_KEYID=$KEYID" >> $GITHUB_ENV
|
||||
echo prime > /tmp/prime.txt
|
||||
gpg --batch --yes --pinentry-mode loopback --passphrase "$GPG_PASSPHRASE" \
|
||||
-u "$KEYID" --detach-sign -o /dev/null /tmp/prime.txt
|
||||
rm -f /tmp/prime.txt
|
||||
|
||||
- name: Checksums and detached signatures
|
||||
if: github.event_name == 'release'
|
||||
env:
|
||||
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
|
||||
run: |
|
||||
# opkg verifies the signature of a feed index, never of a package file,
|
||||
# so the checksums and their signature are what a manual install can be
|
||||
# checked against.
|
||||
sha256sum *.ipk > SHA256SUMS-openwrt-${{ matrix.arch }}
|
||||
for f in *.ipk SHA256SUMS-openwrt-${{ matrix.arch }}; do
|
||||
gpg --batch --yes --pinentry-mode loopback --passphrase "$GPG_PASSPHRASE" \
|
||||
-u "$GPG_KEYID" --armor --detach-sign "$f"
|
||||
done
|
||||
sha256sum -c SHA256SUMS-openwrt-${{ matrix.arch }}
|
||||
gpg --verify SHA256SUMS-openwrt-${{ matrix.arch }}.asc SHA256SUMS-openwrt-${{ matrix.arch }}
|
||||
|
||||
- name: Attest build provenance
|
||||
if: github.event_name == 'release'
|
||||
uses: actions/attest-build-provenance@v2
|
||||
with:
|
||||
subject-path: |
|
||||
*.ipk
|
||||
|
||||
- name: Upload to release
|
||||
if: github.event_name == 'release'
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
TAG: ${{ github.event.release.tag_name }}
|
||||
run: |
|
||||
gh release upload "$TAG" *.ipk *.ipk.asc \
|
||||
SHA256SUMS-openwrt-${{ matrix.arch }} SHA256SUMS-openwrt-${{ matrix.arch }}.asc
|
||||
@@ -6,10 +6,14 @@ on:
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
permissions:
|
||||
contents: write
|
||||
id-token: write
|
||||
attestations: write
|
||||
name: "${{ matrix.target }}"
|
||||
strategy:
|
||||
matrix:
|
||||
@@ -22,12 +26,13 @@ jobs:
|
||||
run: |
|
||||
pwd
|
||||
echo "RELEASE=$(cat RELEASE)" >> $GITHUB_ENV
|
||||
echo "VERSION=$(date +%y%m%d%H%M%S)" >> $GITHUB_ENV
|
||||
echo "MAJOR=$(cat RELEASE | cut -d "-" -f 1)" >> $GITHUB_ENV
|
||||
echo "SUBMAJOR=$(cat RELEASE | cut -d "-" -f 2)" >> $GITHUB_ENV
|
||||
echo "MINOR=$(cat RELEASE | cut -d "-" -f 3)" >> $GITHUB_ENV
|
||||
BUILDDATE=$(sed -n 's/^#define BUILDDATE "\(.*\)"$/\1/p' src/version.h)
|
||||
[ -n "$BUILDDATE" ] || BUILDDATE=$(date -u +%y%m%d%H%M%S)
|
||||
echo "VERSION=$BUILDDATE" >> $GITHUB_ENV
|
||||
SOURCE_DATE_EPOCH=$(date -u -d "20${BUILDDATE:0:2}-${BUILDDATE:2:2}-${BUILDDATE:4:2} ${BUILDDATE:6:2}:${BUILDDATE:8:2}:${BUILDDATE:10:2}" +%s)
|
||||
echo "SOURCE_DATE_EPOCH=$SOURCE_DATE_EPOCH" >> $GITHUB_ENV
|
||||
- name: echo env
|
||||
run: echo "release $RELEASE version $VERSION major $MAJOR submajor $SUBMAJOR minor $MINOR"
|
||||
run: echo "release $RELEASE version $VERSION"
|
||||
- name: Linux libraries
|
||||
run: |
|
||||
sudo apt update
|
||||
@@ -42,45 +47,142 @@ jobs:
|
||||
cp ~/rpmbuild/SOURCES/3proxy-$RELEASE.tar.gz ~/debian/3proxy_$RELEASE.orig.tar.gz
|
||||
- name: rpmbuild
|
||||
run: |
|
||||
ret=`pwd`
|
||||
cd ~/rpmbuild/SPECS
|
||||
rpmbuild -ba 3proxy-$RELEASE.spec
|
||||
cd $ret
|
||||
mv ~/rpmbuild/RPMS/aarch64/3proxy-$RELEASE-1.aarch64.rpm 3proxy-$RELEASE.arm64.rpm
|
||||
mkdir -p rpmout
|
||||
for EL in 8 9 10; do
|
||||
docker run --rm \
|
||||
-v "$HOME/rpmbuild/SOURCES/3proxy-$RELEASE.tar.gz:/src.tar.gz:ro" \
|
||||
-v "$PWD/scripts/rh/3proxy.spec:/3proxy.spec:ro" \
|
||||
-v "$PWD/rpmout:/out" \
|
||||
-e RELEASE="$RELEASE" -e HOSTUID="$(id -u)" -e HOSTGID="$(id -g)" \
|
||||
-e SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
|
||||
"almalinux:$EL" bash -c '
|
||||
set -e
|
||||
dnf -y install rpm-build gcc make openssl-devel pcre2-devel pam-devel tar gzip
|
||||
mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
|
||||
cp /src.tar.gz ~/rpmbuild/SOURCES/3proxy-$RELEASE.tar.gz
|
||||
ln -sf ~/rpmbuild/SOURCES/3proxy-$RELEASE.tar.gz ~/rpmbuild/SOURCES/$RELEASE.tar.gz
|
||||
cp /3proxy.spec ~/rpmbuild/SPECS/3proxy-$RELEASE.spec
|
||||
cd ~/rpmbuild/SPECS
|
||||
rpmbuild -ba \
|
||||
--define "use_source_date_epoch_as_buildtime 1" \
|
||||
--define "clamp_mtime_to_source_date_epoch 1" \
|
||||
--define "_buildhost 3proxy.org" \
|
||||
3proxy-$RELEASE.spec
|
||||
cp ~/rpmbuild/RPMS/*/*.rpm /out/
|
||||
chown "$HOSTUID:$HOSTGID" /out/*.rpm || chmod 0666 /out/*.rpm'
|
||||
done
|
||||
for f in rpmout/*.rpm; do
|
||||
dist=$(rpm -qp --qf '%{RELEASE}' "$f" | sed 's/^1\.//')
|
||||
arch=$(rpm -qp --qf '%{ARCH}' "$f")
|
||||
mv "$f" "3proxy-$RELEASE.$dist.$arch.rpm"
|
||||
done
|
||||
rmdir rpmout
|
||||
ls -l *.rpm
|
||||
- name: Get artifact rpm
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: "3proxy-${{ env.RELEASE }}-arm64.rpm"
|
||||
path: "*.rpm"
|
||||
- name: Upload rpm to release
|
||||
if: github.event_name == 'release'
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
TAG: ${{ github.event.release.tag_name }}
|
||||
run: gh release upload "$TAG" 3proxy-${{ env.RELEASE }}.arm64.rpm
|
||||
- name: debbuild
|
||||
run: |
|
||||
ret=`pwd`
|
||||
cd ~/debian/
|
||||
tar xzf 3proxy_$RELEASE.orig.tar.gz
|
||||
cd 3proxy-$RELEASE
|
||||
echo "3proxy ($RELEASE-$VERSION) buster; urgency=medium" >debian/changelog
|
||||
echo " " >>debian/changelog
|
||||
echo " *3proxy $RELEASE build" >>debian/changelog
|
||||
echo " " >>debian/changelog
|
||||
echo " -- z3APA3A <3apa3a@3proxy.org> "`date "+%a, %d %b %Y %H:%M:%S %z"` >>debian/changelog
|
||||
echo "">>debian/changelog
|
||||
dpkg-buildpackage
|
||||
cd $ret
|
||||
docker run --rm \
|
||||
-v "$HOME/debian:/debian" \
|
||||
-e RELEASE="$RELEASE" -e VERSION="$VERSION" \
|
||||
-e SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
|
||||
ubuntu:22.04 bash -c '
|
||||
set -e
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
apt-get update
|
||||
apt-get install -y build-essential debhelper fakeroot libssl-dev libpcre2-dev libpam0g-dev
|
||||
cd /debian
|
||||
tar xzf 3proxy_$RELEASE.orig.tar.gz
|
||||
cd 3proxy-$RELEASE
|
||||
{ echo "3proxy ($RELEASE-$VERSION) buster; urgency=medium"
|
||||
echo " "
|
||||
echo " *3proxy $RELEASE build"
|
||||
echo " "
|
||||
echo " -- z3APA3A <3apa3a@3proxy.org> $(date -R -u -d @$SOURCE_DATE_EPOCH)"
|
||||
echo ""
|
||||
} > debian/changelog
|
||||
dpkg-buildpackage'
|
||||
cp ~/debian/3proxy_$RELEASE-"$VERSION"_arm64.deb ./3proxy-$RELEASE.arm64.deb
|
||||
- name: Get artifact deb
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: "3proxy-${{ env.RELEASE }}-arm64.deb"
|
||||
path: "*.deb"
|
||||
- name: Upload deb to release
|
||||
- name: Import signing key
|
||||
if: github.event_name == 'release'
|
||||
env:
|
||||
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
|
||||
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
|
||||
run: |
|
||||
if [ -z "$GPG_PRIVATE_KEY" ]; then echo "GPG_PRIVATE_KEY is not set"; exit 1; fi
|
||||
mkdir -p ~/.gnupg && chmod 700 ~/.gnupg
|
||||
printf 'allow-loopback-pinentry\ndefault-cache-ttl 7200\nmax-cache-ttl 7200\n' > ~/.gnupg/gpg-agent.conf
|
||||
gpgconf --kill gpg-agent || true
|
||||
printf '%s' "$GPG_PRIVATE_KEY" | gpg --batch --import
|
||||
KEYID=$(gpg --list-secret-keys --with-colons | awk -F: '/^sec:/{print $5; exit}')
|
||||
echo "GPG_KEYID=$KEYID" >> $GITHUB_ENV
|
||||
echo prime > /tmp/prime.txt
|
||||
gpg --batch --yes --pinentry-mode loopback --passphrase "$GPG_PASSPHRASE" \
|
||||
-u "$KEYID" --detach-sign -o /dev/null /tmp/prime.txt
|
||||
rm -f /tmp/prime.txt
|
||||
- name: Sign rpm
|
||||
if: github.event_name == 'release'
|
||||
env:
|
||||
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
|
||||
run: |
|
||||
GPGBIN=$(command -v gpg)
|
||||
if [ -z "$GPGBIN" ]; then echo "gpg not found"; exit 1; fi
|
||||
umask 077
|
||||
printf '%s' "$GPG_PASSPHRASE" > /tmp/gpgpass
|
||||
echo test > /tmp/signtest
|
||||
gpg --batch --yes --pinentry-mode loopback --passphrase-file /tmp/gpgpass \
|
||||
-u "$GPG_KEYID" --detach-sign -o /tmp/signtest.sig /tmp/signtest
|
||||
echo "key can sign"
|
||||
{ echo "%_gpg_name $GPG_KEYID"
|
||||
echo "%__gpg $GPGBIN"
|
||||
echo '%__gpg_sign_cmd %{__gpg} gpg --batch --no-armor --pinentry-mode loopback --passphrase-file /tmp/gpgpass --no-secmem-warning --digest-algo sha256 -u "%{_gpg_name}" -sbo %{__signature_filename} %{__plaintext_filename}'
|
||||
} > ~/.rpmmacros
|
||||
rpm --addsign *.rpm
|
||||
rm -f /tmp/gpgpass /tmp/signtest /tmp/signtest.sig
|
||||
for f in *.rpm; do
|
||||
sig=$(rpm -qp --qf '%{RSAHEADER:pgpsig}' "$f" 2>/dev/null)
|
||||
case "$sig" in ""|"(none)")
|
||||
sig=$(rpm -qp --qf '%{DSAHEADER:pgpsig}' "$f" 2>/dev/null) ;;
|
||||
esac
|
||||
case "$sig" in ""|"(none)")
|
||||
echo "$f is not signed"
|
||||
echo "--- rpm version ---"; rpm --version
|
||||
echo "--- sign cmd ---"; rpm --eval '%{__gpg_sign_cmd}'
|
||||
echo "--- secret keys ---"; gpg --list-secret-keys --with-colons | grep -E '^(sec|ssb):' || true
|
||||
exit 1 ;;
|
||||
esac
|
||||
echo "$f: $sig"
|
||||
done
|
||||
- name: Checksums and detached signatures
|
||||
if: github.event_name == 'release'
|
||||
env:
|
||||
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
|
||||
run: |
|
||||
sha256sum *.rpm *.deb > SHA256SUMS-arm64
|
||||
for f in *.deb SHA256SUMS-arm64; do
|
||||
gpg --batch --yes --pinentry-mode loopback --passphrase "$GPG_PASSPHRASE" \
|
||||
-u "$GPG_KEYID" --armor --detach-sign "$f"
|
||||
done
|
||||
sha256sum -c SHA256SUMS-arm64
|
||||
gpg --verify SHA256SUMS-arm64.asc SHA256SUMS-arm64
|
||||
- name: Attest build provenance
|
||||
if: github.event_name == 'release'
|
||||
uses: actions/attest-build-provenance@v2
|
||||
with:
|
||||
subject-path: |
|
||||
*.rpm
|
||||
*.deb
|
||||
- name: Upload to release
|
||||
if: github.event_name == 'release'
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
TAG: ${{ github.event.release.tag_name }}
|
||||
run: gh release upload "$TAG" 3proxy-${{ env.RELEASE }}.arm64.deb
|
||||
run: gh release upload "$TAG" *.rpm *.deb *.deb.asc SHA256SUMS-arm64 SHA256SUMS-arm64.asc
|
||||
@@ -1,4 +1,4 @@
|
||||
name: RPM/DEB build armhf
|
||||
name: DEB build armhf
|
||||
|
||||
on:
|
||||
release:
|
||||
@@ -6,10 +6,14 @@ on:
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
permissions:
|
||||
contents: write
|
||||
id-token: write
|
||||
attestations: write
|
||||
name: "${{ matrix.target }}"
|
||||
strategy:
|
||||
matrix:
|
||||
@@ -22,38 +26,12 @@ jobs:
|
||||
run: |
|
||||
pwd
|
||||
echo "RELEASE=$(cat RELEASE)" >> $GITHUB_ENV
|
||||
echo "VERSION=$(date +%y%m%d%H%M%S)" >> $GITHUB_ENV
|
||||
echo "MAJOR=$(cat RELEASE | cut -d "-" -f 1)" >> $GITHUB_ENV
|
||||
echo "SUBMAJOR=$(cat RELEASE | cut -d "-" -f 2)" >> $GITHUB_ENV
|
||||
echo "MINOR=$(cat RELEASE | cut -d "-" -f 3)" >> $GITHUB_ENV
|
||||
- name: Linux libraries
|
||||
run: |
|
||||
sudo apt update
|
||||
sudo dpkg --add-architecture armhf
|
||||
echo "Types: deb" > ~/ubuntu.sources
|
||||
echo "URIs: http://archive.ubuntu.com/ubuntu/" >> ~/ubuntu.sources
|
||||
echo "Suites: noble noble-updates noble-backports" >> ~/ubuntu.sources
|
||||
echo "Components: main restricted universe multiverse" >> ~/ubuntu.sources
|
||||
echo "Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg" >> ~/ubuntu.sources
|
||||
echo "Architectures: amd64" >> ~/ubuntu.sources
|
||||
echo "" >> ~/ubuntu.sources
|
||||
echo "Types: deb" >> ~/ubuntu.sources
|
||||
echo "URIs: http://security.ubuntu.com/ubuntu/" >> ~/ubuntu.sources
|
||||
echo "Suites: noble-security" >> ~/ubuntu.sources
|
||||
echo "Components: main restricted universe multiverse" >> ~/ubuntu.sources
|
||||
echo "Architectures: amd64" >> ~/ubuntu.sources
|
||||
echo "Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg" >> ~/ubuntu.sources
|
||||
echo "" >> ~/ubuntu.sources
|
||||
echo "Types: deb" >>~/ubuntu.sources
|
||||
echo "URIs: http://ports.ubuntu.com/ubuntu-ports/" >>~/ubuntu.sources
|
||||
echo "Suites: noble noble-updates" >>~/ubuntu.sources
|
||||
echo "Components: main restricted universe multiverse" >>~/ubuntu.sources
|
||||
echo "Architectures: armhf" >>~/ubuntu.sources
|
||||
echo "Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg" >>~/ubuntu.sources
|
||||
sudo cp ~/ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources
|
||||
sudo apt update
|
||||
sudo apt install libssl3t64:armhf openssl:armhf libssl-dev:armhf libpam0g:armhf libpam0g-dev:armhf libpcre2-dev:armhf rpm crossbuild-essential-armhf build-essential debhelper
|
||||
- name: configure rpm env
|
||||
BUILDDATE=$(sed -n 's/^#define BUILDDATE "\(.*\)"$/\1/p' src/version.h)
|
||||
[ -n "$BUILDDATE" ] || BUILDDATE=$(date -u +%y%m%d%H%M%S)
|
||||
echo "VERSION=$BUILDDATE" >> $GITHUB_ENV
|
||||
SOURCE_DATE_EPOCH=$(date -u -d "20${BUILDDATE:0:2}-${BUILDDATE:2:2}-${BUILDDATE:4:2} ${BUILDDATE:6:2}:${BUILDDATE:8:2}:${BUILDDATE:10:2}" +%s)
|
||||
echo "SOURCE_DATE_EPOCH=$SOURCE_DATE_EPOCH" >> $GITHUB_ENV
|
||||
- name: configure deb env
|
||||
run: |
|
||||
mkdir ~/debian
|
||||
mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
|
||||
@@ -61,59 +39,81 @@ jobs:
|
||||
ln -s ~/rpmbuild/SOURCES/3proxy-$RELEASE.tar.gz ~/rpmbuild/SOURCES/$RELEASE.tar.gz
|
||||
cp scripts/rh/3proxy.spec ~/rpmbuild/SPECS/3proxy-$RELEASE.spec
|
||||
cp ~/rpmbuild/SOURCES/3proxy-$RELEASE.tar.gz ~/debian/3proxy_$RELEASE.orig.tar.gz
|
||||
- name: rpmbuild
|
||||
run: |
|
||||
ret=`pwd`
|
||||
cd ~/rpmbuild/SPECS
|
||||
PATH=/usr/arm-linux-gnueabihf/bin:$PATH
|
||||
export PATH=$PATH
|
||||
CC=arm-linux-gnueabihf-gcc
|
||||
export CC=$CC
|
||||
export RPATH=/usr/arm-linux-gnueabihf/lib:$RPATH
|
||||
export LD_LIBRARY_PATH=/usr/arm-linux-gnueabihf/lib:$LD_LIBRARY_PATH
|
||||
rpmbuild -ba --define "PAMLIB pam0g" --define "_arch arm" --define "cross yes" --target=arm-linux-gnueabihf 3proxy-$RELEASE.spec
|
||||
cd $ret
|
||||
mv ~/rpmbuild/RPMS/arm/3proxy-$RELEASE-1.arm.rpm 3proxy-$RELEASE.arm.rpm
|
||||
- name: Get artifact rpm
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: "3proxy-${{ env.RELEASE }}-arm.rpm"
|
||||
path: "*.rpm"
|
||||
- name: Upload rpm to release
|
||||
if: github.event_name == 'release'
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
TAG: ${{ github.event.release.tag_name }}
|
||||
run: gh release upload "$TAG" 3proxy-${{ env.RELEASE }}.arm.rpm
|
||||
- name: debbuild
|
||||
run: |
|
||||
ret=`pwd`
|
||||
cd ~/debian/
|
||||
tar xzf 3proxy_$RELEASE.orig.tar.gz
|
||||
cd 3proxy-$RELEASE
|
||||
echo "3proxy ($RELEASE-$VERSION) buster; urgency=medium" >debian/changelog
|
||||
echo " " >>debian/changelog
|
||||
echo " *3proxy $RELEASE build" >>debian/changelog
|
||||
echo " " >>debian/changelog
|
||||
echo " -- z3APA3A <3apa3a@3proxy.org> "`date "+%a, %d %b %Y %H:%M:%S %z"` >>debian/changelog
|
||||
echo "">>debian/changelog
|
||||
PATH=/usr/arm-linux-gnueabihf/bin:$PATH
|
||||
export PATH=$PATH
|
||||
CC=arm-linux-gnueabihf-gcc
|
||||
export CC=$CC
|
||||
export RPATH=/usr/arm-linux-gnueabihf/lib:$RPATH
|
||||
export LD_LIBRARY_PATH=/usr/arm-linux-gnueabihf/lib:$LD_LIBRARY_PATH
|
||||
dpkg-buildpackage
|
||||
cd $ret
|
||||
docker run --rm \
|
||||
-v "$HOME/debian:/debian" \
|
||||
-e RELEASE="$RELEASE" -e VERSION="$VERSION" \
|
||||
-e SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
|
||||
ubuntu:22.04 bash -c '
|
||||
set -e
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
dpkg --add-architecture armhf
|
||||
sed -i "s|^deb |deb [arch=amd64] |" /etc/apt/sources.list
|
||||
{ echo "deb [arch=armhf] http://ports.ubuntu.com/ubuntu-ports jammy main restricted universe multiverse"
|
||||
echo "deb [arch=armhf] http://ports.ubuntu.com/ubuntu-ports jammy-updates main restricted universe multiverse"
|
||||
} >> /etc/apt/sources.list
|
||||
apt-get update
|
||||
apt-get install -y crossbuild-essential-armhf build-essential debhelper fakeroot \
|
||||
libssl-dev:armhf libpcre2-dev:armhf libpam0g-dev:armhf
|
||||
cd /debian
|
||||
tar xzf 3proxy_$RELEASE.orig.tar.gz
|
||||
cd 3proxy-$RELEASE
|
||||
{ echo "3proxy ($RELEASE-$VERSION) buster; urgency=medium"
|
||||
echo " "
|
||||
echo " *3proxy $RELEASE build"
|
||||
echo " "
|
||||
echo " -- z3APA3A <3apa3a@3proxy.org> $(date -R -u -d @$SOURCE_DATE_EPOCH)"
|
||||
echo ""
|
||||
} > debian/changelog
|
||||
export PATH=/usr/arm-linux-gnueabihf/bin:$PATH
|
||||
export CC=arm-linux-gnueabihf-gcc
|
||||
export LD_LIBRARY_PATH=/usr/arm-linux-gnueabihf/lib:$LD_LIBRARY_PATH
|
||||
dpkg-buildpackage'
|
||||
cp ~/debian/3proxy_$RELEASE-"$VERSION"_armhf.deb ./3proxy-$RELEASE.arm.deb
|
||||
- name: Get artifact deb
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: "3proxy-${{ env.RELEASE }}-arm.deb"
|
||||
path: "*.deb"
|
||||
- name: Upload deb to release
|
||||
- name: Import signing key
|
||||
if: github.event_name == 'release'
|
||||
env:
|
||||
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
|
||||
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
|
||||
run: |
|
||||
if [ -z "$GPG_PRIVATE_KEY" ]; then echo "GPG_PRIVATE_KEY is not set"; exit 1; fi
|
||||
mkdir -p ~/.gnupg && chmod 700 ~/.gnupg
|
||||
printf 'allow-loopback-pinentry\ndefault-cache-ttl 7200\nmax-cache-ttl 7200\n' > ~/.gnupg/gpg-agent.conf
|
||||
gpgconf --kill gpg-agent || true
|
||||
printf '%s' "$GPG_PRIVATE_KEY" | gpg --batch --import
|
||||
KEYID=$(gpg --list-secret-keys --with-colons | awk -F: '/^sec:/{print $5; exit}')
|
||||
echo "GPG_KEYID=$KEYID" >> $GITHUB_ENV
|
||||
echo prime > /tmp/prime.txt
|
||||
gpg --batch --yes --pinentry-mode loopback --passphrase "$GPG_PASSPHRASE" \
|
||||
-u "$KEYID" --detach-sign -o /dev/null /tmp/prime.txt
|
||||
rm -f /tmp/prime.txt
|
||||
- name: Checksums and detached signatures
|
||||
if: github.event_name == 'release'
|
||||
env:
|
||||
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
|
||||
run: |
|
||||
sha256sum *.deb > SHA256SUMS-arm
|
||||
for f in *.deb SHA256SUMS-arm; do
|
||||
gpg --batch --yes --pinentry-mode loopback --passphrase "$GPG_PASSPHRASE" \
|
||||
-u "$GPG_KEYID" --armor --detach-sign "$f"
|
||||
done
|
||||
sha256sum -c SHA256SUMS-arm
|
||||
gpg --verify SHA256SUMS-arm.asc SHA256SUMS-arm
|
||||
- name: Attest build provenance
|
||||
if: github.event_name == 'release'
|
||||
uses: actions/attest-build-provenance@v2
|
||||
with:
|
||||
subject-path: |
|
||||
*.deb
|
||||
- name: Upload to release
|
||||
if: github.event_name == 'release'
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
TAG: ${{ github.event.release.tag_name }}
|
||||
run: gh release upload "$TAG" 3proxy-${{ env.RELEASE }}.arm.deb
|
||||
run: gh release upload "$TAG" *.deb *.deb.asc SHA256SUMS-arm SHA256SUMS-arm.asc
|
||||
@@ -6,15 +6,20 @@ on:
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
permissions:
|
||||
contents: write
|
||||
id-token: write
|
||||
attestations: write
|
||||
name: "${{ matrix.target }}"
|
||||
strategy:
|
||||
matrix:
|
||||
target:
|
||||
- ubuntu-latest
|
||||
# 26.04: rpm 6 runs %__gpg_sign_cmd differently, signing fails
|
||||
- ubuntu-24.04
|
||||
runs-on: ${{ matrix.target }}
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
@@ -22,12 +27,13 @@ jobs:
|
||||
run: |
|
||||
pwd
|
||||
echo "RELEASE=$(cat RELEASE)" >> $GITHUB_ENV
|
||||
echo "VERSION=$(date +%y%m%d%H%M%S)" >> $GITHUB_ENV
|
||||
echo "MAJOR=$(cat RELEASE | cut -d "-" -f 1)" >> $GITHUB_ENV
|
||||
echo "SUBMAJOR=$(cat RELEASE | cut -d "-" -f 2)" >> $GITHUB_ENV
|
||||
echo "MINOR=$(cat RELEASE | cut -d "-" -f 3)" >> $GITHUB_ENV
|
||||
BUILDDATE=$(sed -n 's/^#define BUILDDATE "\(.*\)"$/\1/p' src/version.h)
|
||||
[ -n "$BUILDDATE" ] || BUILDDATE=$(date -u +%y%m%d%H%M%S)
|
||||
echo "VERSION=$BUILDDATE" >> $GITHUB_ENV
|
||||
SOURCE_DATE_EPOCH=$(date -u -d "20${BUILDDATE:0:2}-${BUILDDATE:2:2}-${BUILDDATE:4:2} ${BUILDDATE:6:2}:${BUILDDATE:8:2}:${BUILDDATE:10:2}" +%s)
|
||||
echo "SOURCE_DATE_EPOCH=$SOURCE_DATE_EPOCH" >> $GITHUB_ENV
|
||||
- name: echo env
|
||||
run: echo "release $RELEASE version $VERSION major $MAJOR submajor $SUBMAJOR minor $MINOR"
|
||||
run: echo "release $RELEASE version $VERSION"
|
||||
- name: Linux libraries
|
||||
run: |
|
||||
sudo apt update
|
||||
@@ -42,46 +48,143 @@ jobs:
|
||||
cp ~/rpmbuild/SOURCES/3proxy-$RELEASE.tar.gz ~/debian/3proxy_$RELEASE.orig.tar.gz
|
||||
- name: rpmbuild
|
||||
run: |
|
||||
ret=`pwd`
|
||||
cd ~/rpmbuild/SPECS
|
||||
rpmbuild -ba 3proxy-$RELEASE.spec
|
||||
cd $ret
|
||||
mv ~/rpmbuild/RPMS/x86_64/3proxy-$RELEASE-1.x86_64.rpm 3proxy-$RELEASE.x86_64.rpm
|
||||
mkdir -p rpmout
|
||||
for EL in 8 9 10; do
|
||||
docker run --rm \
|
||||
-v "$HOME/rpmbuild/SOURCES/3proxy-$RELEASE.tar.gz:/src.tar.gz:ro" \
|
||||
-v "$PWD/scripts/rh/3proxy.spec:/3proxy.spec:ro" \
|
||||
-v "$PWD/rpmout:/out" \
|
||||
-e RELEASE="$RELEASE" -e HOSTUID="$(id -u)" -e HOSTGID="$(id -g)" \
|
||||
-e SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
|
||||
"almalinux:$EL" bash -c '
|
||||
set -e
|
||||
dnf -y install rpm-build gcc make openssl-devel pcre2-devel pam-devel tar gzip
|
||||
mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
|
||||
cp /src.tar.gz ~/rpmbuild/SOURCES/3proxy-$RELEASE.tar.gz
|
||||
ln -sf ~/rpmbuild/SOURCES/3proxy-$RELEASE.tar.gz ~/rpmbuild/SOURCES/$RELEASE.tar.gz
|
||||
cp /3proxy.spec ~/rpmbuild/SPECS/3proxy-$RELEASE.spec
|
||||
cd ~/rpmbuild/SPECS
|
||||
rpmbuild -ba \
|
||||
--define "use_source_date_epoch_as_buildtime 1" \
|
||||
--define "clamp_mtime_to_source_date_epoch 1" \
|
||||
--define "_buildhost 3proxy.org" \
|
||||
3proxy-$RELEASE.spec
|
||||
cp ~/rpmbuild/RPMS/*/*.rpm /out/
|
||||
chown "$HOSTUID:$HOSTGID" /out/*.rpm || chmod 0666 /out/*.rpm'
|
||||
done
|
||||
for f in rpmout/*.rpm; do
|
||||
dist=$(rpm -qp --qf '%{RELEASE}' "$f" | sed 's/^1\.//')
|
||||
arch=$(rpm -qp --qf '%{ARCH}' "$f")
|
||||
mv "$f" "3proxy-$RELEASE.$dist.$arch.rpm"
|
||||
done
|
||||
rmdir rpmout
|
||||
ls -l *.rpm
|
||||
- name: Get artifact rpm
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: "3proxy-${{ env.RELEASE }}-x86_64.rpm"
|
||||
path: "*.rpm"
|
||||
- name: Upload rpm to release
|
||||
if: github.event_name == 'release'
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
TAG: ${{ github.event.release.tag_name }}
|
||||
run: gh release upload "$TAG" 3proxy-${{ env.RELEASE }}.x86_64.rpm
|
||||
- name: debbuild
|
||||
run: |
|
||||
ret=`pwd`
|
||||
cd ~/debian/
|
||||
tar xzf 3proxy_$RELEASE.orig.tar.gz
|
||||
cd 3proxy-$RELEASE
|
||||
echo "3proxy ($RELEASE-$VERSION) buster; urgency=medium" >debian/changelog
|
||||
echo " " >>debian/changelog
|
||||
echo " *3proxy $RELEASE build" >>debian/changelog
|
||||
echo " " >>debian/changelog
|
||||
echo " -- z3APA3A <3apa3a@3proxy.org> "`date "+%a, %d %b %Y %H:%M:%S %z"` >>debian/changelog
|
||||
echo "">>debian/changelog
|
||||
dpkg-buildpackage
|
||||
cd $ret
|
||||
docker run --rm \
|
||||
-v "$HOME/debian:/debian" \
|
||||
-e RELEASE="$RELEASE" -e VERSION="$VERSION" \
|
||||
-e SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
|
||||
ubuntu:22.04 bash -c '
|
||||
set -e
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
apt-get update
|
||||
apt-get install -y build-essential debhelper fakeroot libssl-dev libpcre2-dev libpam0g-dev
|
||||
cd /debian
|
||||
tar xzf 3proxy_$RELEASE.orig.tar.gz
|
||||
cd 3proxy-$RELEASE
|
||||
{ echo "3proxy ($RELEASE-$VERSION) buster; urgency=medium"
|
||||
echo " "
|
||||
echo " *3proxy $RELEASE build"
|
||||
echo " "
|
||||
echo " -- z3APA3A <3apa3a@3proxy.org> $(date -R -u -d @$SOURCE_DATE_EPOCH)"
|
||||
echo ""
|
||||
} > debian/changelog
|
||||
dpkg-buildpackage'
|
||||
cp ~/debian/3proxy_$RELEASE-"$VERSION"_amd64.deb ./3proxy-$RELEASE.x86_64.deb
|
||||
- name: Get artifact deb
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: "3proxy-${{ env.RELEASE }}-x86_64.deb"
|
||||
path: "*.deb"
|
||||
- name: Upload deb to release
|
||||
|
||||
- name: Import signing key
|
||||
if: github.event_name == 'release'
|
||||
env:
|
||||
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
|
||||
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
|
||||
run: |
|
||||
if [ -z "$GPG_PRIVATE_KEY" ]; then echo "GPG_PRIVATE_KEY is not set"; exit 1; fi
|
||||
mkdir -p ~/.gnupg && chmod 700 ~/.gnupg
|
||||
printf 'allow-loopback-pinentry\ndefault-cache-ttl 7200\nmax-cache-ttl 7200\n' > ~/.gnupg/gpg-agent.conf
|
||||
gpgconf --kill gpg-agent || true
|
||||
printf '%s' "$GPG_PRIVATE_KEY" | gpg --batch --import
|
||||
KEYID=$(gpg --list-secret-keys --with-colons | awk -F: '/^sec:/{print $5; exit}')
|
||||
echo "GPG_KEYID=$KEYID" >> $GITHUB_ENV
|
||||
echo prime > /tmp/prime.txt
|
||||
gpg --batch --yes --pinentry-mode loopback --passphrase "$GPG_PASSPHRASE" \
|
||||
-u "$KEYID" --detach-sign -o /dev/null /tmp/prime.txt
|
||||
rm -f /tmp/prime.txt
|
||||
- name: Sign rpm
|
||||
if: github.event_name == 'release'
|
||||
env:
|
||||
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
|
||||
run: |
|
||||
GPGBIN=$(command -v gpg)
|
||||
if [ -z "$GPGBIN" ]; then echo "gpg not found"; exit 1; fi
|
||||
umask 077
|
||||
printf '%s' "$GPG_PASSPHRASE" > /tmp/gpgpass
|
||||
echo test > /tmp/signtest
|
||||
gpg --batch --yes --pinentry-mode loopback --passphrase-file /tmp/gpgpass \
|
||||
-u "$GPG_KEYID" --detach-sign -o /tmp/signtest.sig /tmp/signtest
|
||||
echo "key can sign"
|
||||
{ echo "%_gpg_name $GPG_KEYID"
|
||||
echo "%__gpg $GPGBIN"
|
||||
echo '%__gpg_sign_cmd %{__gpg} gpg --batch --no-armor --pinentry-mode loopback --passphrase-file /tmp/gpgpass --no-secmem-warning --digest-algo sha256 -u "%{_gpg_name}" -sbo %{__signature_filename} %{__plaintext_filename}'
|
||||
} > ~/.rpmmacros
|
||||
rpm --addsign *.rpm
|
||||
rm -f /tmp/gpgpass /tmp/signtest /tmp/signtest.sig
|
||||
for f in *.rpm; do
|
||||
sig=$(rpm -qp --qf '%{RSAHEADER:pgpsig}' "$f" 2>/dev/null)
|
||||
case "$sig" in ""|"(none)")
|
||||
sig=$(rpm -qp --qf '%{DSAHEADER:pgpsig}' "$f" 2>/dev/null) ;;
|
||||
esac
|
||||
case "$sig" in ""|"(none)")
|
||||
echo "$f is not signed"
|
||||
echo "--- rpm version ---"; rpm --version
|
||||
echo "--- sign cmd ---"; rpm --eval '%{__gpg_sign_cmd}'
|
||||
echo "--- secret keys ---"; gpg --list-secret-keys --with-colons | grep -E '^(sec|ssb):' || true
|
||||
exit 1 ;;
|
||||
esac
|
||||
echo "$f: $sig"
|
||||
done
|
||||
- name: Checksums and detached signatures
|
||||
if: github.event_name == 'release'
|
||||
env:
|
||||
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
|
||||
run: |
|
||||
sha256sum *.rpm *.deb > SHA256SUMS-x86_64
|
||||
for f in *.deb SHA256SUMS-x86_64; do
|
||||
gpg --batch --yes --pinentry-mode loopback --passphrase "$GPG_PASSPHRASE" \
|
||||
-u "$GPG_KEYID" --armor --detach-sign "$f"
|
||||
done
|
||||
sha256sum -c SHA256SUMS-x86_64
|
||||
gpg --verify SHA256SUMS-x86_64.asc SHA256SUMS-x86_64
|
||||
- name: Attest build provenance
|
||||
if: github.event_name == 'release'
|
||||
uses: actions/attest-build-provenance@v2
|
||||
with:
|
||||
subject-path: |
|
||||
*.rpm
|
||||
*.deb
|
||||
- name: Upload to release
|
||||
if: github.event_name == 'release'
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
TAG: ${{ github.event.release.tag_name }}
|
||||
run: gh release upload "$TAG" 3proxy-${{ env.RELEASE }}.x86_64.deb
|
||||
|
||||
run: gh release upload "$TAG" *.rpm *.deb *.deb.asc SHA256SUMS-x86_64 SHA256SUMS-x86_64.asc
|
||||
@@ -6,10 +6,14 @@ on:
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
permissions:
|
||||
contents: write
|
||||
id-token: write
|
||||
attestations: write
|
||||
name: "${{ matrix.target }}"
|
||||
strategy:
|
||||
matrix:
|
||||
@@ -34,19 +38,8 @@ jobs:
|
||||
- name: make Watcom
|
||||
shell: cmd
|
||||
run: |
|
||||
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 "volatile char VerSion[]=^"3APA3A-3proxy-Internal-Build: 3proxy-%RELEASE%-%NOW%\r\n^";" >>src/3proxy.c
|
||||
nmake /F Makefile.watcom
|
||||
- name: Decode Certificate
|
||||
shell: pwsh
|
||||
run: |
|
||||
$pfx_cert_byte = [System.Convert]::FromBase64String("${{ secrets.WINDOWS_CERTIFICATE }}")
|
||||
[System.IO.File]::WriteAllBytes("${{ github.workspace }}\cert.pfx", $pfx_cert_byte)
|
||||
- name: Sign
|
||||
shell: pwsh
|
||||
run: |
|
||||
$signtool = (Get-ChildItem "C:\Program Files (x86)\Windows Kits\10\bin\*\x64\signtool.exe" | Sort-Object { [version]$_.Directory.Parent.Name } -Descending | Select-Object -First 1).FullName
|
||||
& $signtool sign /f "${{ github.workspace }}\cert.pfx" /p "${{ secrets.WINDOWS_CERTIFICATE_PASSWORD }}" /tr http://timestamp.digicert.com /td sha256 /fd sha256 "bin\3proxy.exe"
|
||||
& $signtool sign /f "${{ github.workspace }}\cert.pfx" /p "${{ secrets.WINDOWS_CERTIFICATE_PASSWORD }}" /tr http://timestamp.digicert.com /td sha256 /fd sha256 "bin\3proxy_crypt.exe"
|
||||
- name: make dist dir
|
||||
shell: cmd
|
||||
run: |
|
||||
@@ -86,10 +79,30 @@ jobs:
|
||||
if: github.event_name == 'release'
|
||||
shell: pwsh
|
||||
run: Compress-Archive -Path dist/* -DestinationPath 3proxy-${{ env.RELEASE }}-lite.zip
|
||||
- name: Checksums and detached signature
|
||||
if: github.event_name == 'release'
|
||||
shell: bash
|
||||
env:
|
||||
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
|
||||
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
|
||||
run: |
|
||||
if [ -z "$GPG_PRIVATE_KEY" ]; then echo "GPG_PRIVATE_KEY is not set"; exit 1; fi
|
||||
printf '%s' "$GPG_PRIVATE_KEY" | gpg --batch --import
|
||||
KEYID=$(gpg --list-secret-keys --with-colons | awk -F: '/^sec:/{print $5; exit}')
|
||||
sha256sum *.zip > SHA256SUMS-win-lite
|
||||
gpg --batch --yes --pinentry-mode loopback --passphrase "$GPG_PASSPHRASE" \
|
||||
-u "$KEYID" --armor --detach-sign SHA256SUMS-win-lite
|
||||
sha256sum -c SHA256SUMS-win-lite
|
||||
- name: Attest build provenance
|
||||
if: github.event_name == 'release'
|
||||
uses: actions/attest-build-provenance@v2
|
||||
with:
|
||||
subject-path: |
|
||||
*.zip
|
||||
- name: Upload to release
|
||||
if: github.event_name == 'release'
|
||||
shell: bash
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
TAG: ${{ github.event.release.tag_name }}
|
||||
run: gh release upload "$TAG" 3proxy-${{ env.RELEASE }}-lite.zip
|
||||
run: gh release upload "$TAG" *.zip SHA256SUMS-win-lite SHA256SUMS-win-lite.asc
|
||||
@@ -6,10 +6,14 @@ on:
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
permissions:
|
||||
contents: write
|
||||
id-token: write
|
||||
attestations: write
|
||||
name: "${{ matrix.target }}"
|
||||
strategy:
|
||||
matrix:
|
||||
@@ -40,27 +44,8 @@ jobs:
|
||||
cd "D:/a/3proxy/3proxy"
|
||||
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
|
||||
echo "volatile char VerSion[]=^"3APA3A-3proxy-Internal-Build: 3proxy-%RELEASE%-%NOW%\r\n^";" >>src/3proxy.c
|
||||
nmake /F Makefile.msvc WOLFSSL=1
|
||||
- name: Decode Certificate
|
||||
shell: pwsh
|
||||
run: |
|
||||
$pfx_cert_byte = [System.Convert]::FromBase64String("${{ secrets.WINDOWS_CERTIFICATE }}")
|
||||
[System.IO.File]::WriteAllBytes("${{ github.workspace }}\cert.pfx", $pfx_cert_byte)
|
||||
- name: Extract public certificate
|
||||
shell: pwsh
|
||||
env:
|
||||
CERT_PASSWORD: ${{ secrets.WINDOWS_CERTIFICATE_PASSWORD }}
|
||||
run: |
|
||||
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("${{ github.workspace }}\cert.pfx", "$env:CERT_PASSWORD")
|
||||
[System.IO.File]::WriteAllBytes("${{ github.workspace }}\3proxy.crt", $cert.Export("Cert"))
|
||||
- name: Sign
|
||||
shell: pwsh
|
||||
env:
|
||||
CERT_PASSWORD: ${{ secrets.WINDOWS_CERTIFICATE_PASSWORD }}
|
||||
run: |
|
||||
$signtool = (Get-ChildItem "C:\Program Files (x86)\Windows Kits\10\bin\*\x64\signtool.exe" | Sort-Object { [version]$_.Directory.Parent.Name } -Descending | Select-Object -First 1).FullName
|
||||
Get-ChildItem bin\*.exe, bin\*.dll | ForEach-Object { & $signtool sign /f "${{ github.workspace }}\cert.pfx" /p "$env:CERT_PASSWORD" /tr http://timestamp.digicert.com /td sha256 /fd sha256 $_.FullName }
|
||||
- name: make dist dir
|
||||
shell: cmd
|
||||
run: |
|
||||
@@ -91,7 +76,6 @@ jobs:
|
||||
copy authors dist\3proxy\
|
||||
copy README.md dist\3proxy\
|
||||
copy rus.3ps dist\3proxy\
|
||||
copy 3proxy.crt dist\3proxy\
|
||||
- name: Get artifact
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
@@ -101,10 +85,30 @@ jobs:
|
||||
if: github.event_name == 'release'
|
||||
shell: pwsh
|
||||
run: Compress-Archive -Path dist/* -DestinationPath 3proxy-${{ env.RELEASE }}-x86.zip
|
||||
- name: Checksums and detached signature
|
||||
if: github.event_name == 'release'
|
||||
shell: bash
|
||||
env:
|
||||
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
|
||||
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
|
||||
run: |
|
||||
if [ -z "$GPG_PRIVATE_KEY" ]; then echo "GPG_PRIVATE_KEY is not set"; exit 1; fi
|
||||
printf '%s' "$GPG_PRIVATE_KEY" | gpg --batch --import
|
||||
KEYID=$(gpg --list-secret-keys --with-colons | awk -F: '/^sec:/{print $5; exit}')
|
||||
sha256sum *.zip > SHA256SUMS-win-x86
|
||||
gpg --batch --yes --pinentry-mode loopback --passphrase "$GPG_PASSPHRASE" \
|
||||
-u "$KEYID" --armor --detach-sign SHA256SUMS-win-x86
|
||||
sha256sum -c SHA256SUMS-win-x86
|
||||
- name: Attest build provenance
|
||||
if: github.event_name == 'release'
|
||||
uses: actions/attest-build-provenance@v2
|
||||
with:
|
||||
subject-path: |
|
||||
*.zip
|
||||
- name: Upload to release
|
||||
if: github.event_name == 'release'
|
||||
shell: bash
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
TAG: ${{ github.event.release.tag_name }}
|
||||
run: gh release upload "$TAG" 3proxy-${{ env.RELEASE }}-x86.zip
|
||||
run: gh release upload "$TAG" *.zip SHA256SUMS-win-x86 SHA256SUMS-win-x86.asc
|
||||
@@ -6,10 +6,14 @@ on:
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
permissions:
|
||||
contents: write
|
||||
id-token: write
|
||||
attestations: write
|
||||
name: "${{ matrix.target }}"
|
||||
strategy:
|
||||
matrix:
|
||||
@@ -40,28 +44,9 @@ jobs:
|
||||
cd "D:/a/3proxy/3proxy"
|
||||
set "LIB=%LIB%;c:/vcpkg/installed/x64-windows-static/lib"
|
||||
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 "volatile char VerSion[]=^"3APA3A-3proxy-Internal-Build: 3proxy-%RELEASE%-%NOW%\r\n^";" >>src/3proxy.c
|
||||
echo %NOW% / %RELEASE% / %BUILDDATE% / %VERSION%
|
||||
nmake /F Makefile.msvc WOLFSSL=1
|
||||
- name: Decode Certificate
|
||||
shell: pwsh
|
||||
run: |
|
||||
$pfx_cert_byte = [System.Convert]::FromBase64String("${{ secrets.WINDOWS_CERTIFICATE }}")
|
||||
[System.IO.File]::WriteAllBytes("${{ github.workspace }}\cert.pfx", $pfx_cert_byte)
|
||||
- name: Extract public certificate
|
||||
shell: pwsh
|
||||
env:
|
||||
CERT_PASSWORD: ${{ secrets.WINDOWS_CERTIFICATE_PASSWORD }}
|
||||
run: |
|
||||
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("${{ github.workspace }}\cert.pfx", "$env:CERT_PASSWORD")
|
||||
[System.IO.File]::WriteAllBytes("${{ github.workspace }}\3proxy.crt", $cert.Export("Cert"))
|
||||
- name: Sign
|
||||
shell: pwsh
|
||||
env:
|
||||
CERT_PASSWORD: ${{ secrets.WINDOWS_CERTIFICATE_PASSWORD }}
|
||||
run: |
|
||||
$signtool = (Get-ChildItem "C:\Program Files (x86)\Windows Kits\10\bin\*\x64\signtool.exe" | Sort-Object { [version]$_.Directory.Parent.Name } -Descending | Select-Object -First 1).FullName
|
||||
Get-ChildItem bin\*.exe, bin\*.dll | ForEach-Object { & $signtool sign /f "${{ github.workspace }}\cert.pfx" /p "$env:CERT_PASSWORD" /tr http://timestamp.digicert.com /td sha256 /fd sha256 $_.FullName }
|
||||
- name: make dist dir
|
||||
shell: cmd
|
||||
run: |
|
||||
@@ -92,7 +77,6 @@ jobs:
|
||||
copy authors dist\3proxy\
|
||||
copy README.md dist\3proxy\
|
||||
copy rus.3ps dist\3proxy\
|
||||
copy 3proxy.crt dist\3proxy\
|
||||
- name: Get artifact
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
@@ -102,10 +86,30 @@ jobs:
|
||||
if: github.event_name == 'release'
|
||||
shell: pwsh
|
||||
run: Compress-Archive -Path dist/* -DestinationPath 3proxy-${{ env.RELEASE }}-x64.zip
|
||||
- name: Checksums and detached signature
|
||||
if: github.event_name == 'release'
|
||||
shell: bash
|
||||
env:
|
||||
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
|
||||
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
|
||||
run: |
|
||||
if [ -z "$GPG_PRIVATE_KEY" ]; then echo "GPG_PRIVATE_KEY is not set"; exit 1; fi
|
||||
printf '%s' "$GPG_PRIVATE_KEY" | gpg --batch --import
|
||||
KEYID=$(gpg --list-secret-keys --with-colons | awk -F: '/^sec:/{print $5; exit}')
|
||||
sha256sum *.zip > SHA256SUMS-win-x64
|
||||
gpg --batch --yes --pinentry-mode loopback --passphrase "$GPG_PASSPHRASE" \
|
||||
-u "$KEYID" --armor --detach-sign SHA256SUMS-win-x64
|
||||
sha256sum -c SHA256SUMS-win-x64
|
||||
- name: Attest build provenance
|
||||
if: github.event_name == 'release'
|
||||
uses: actions/attest-build-provenance@v2
|
||||
with:
|
||||
subject-path: |
|
||||
*.zip
|
||||
- name: Upload to release
|
||||
if: github.event_name == 'release'
|
||||
shell: bash
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
TAG: ${{ github.event.release.tag_name }}
|
||||
run: gh release upload "$TAG" 3proxy-${{ env.RELEASE }}-x64.zip
|
||||
run: gh release upload "$TAG" *.zip SHA256SUMS-win-x64 SHA256SUMS-win-x64.asc
|
||||
@@ -6,10 +6,14 @@ on:
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
permissions:
|
||||
contents: write
|
||||
id-token: write
|
||||
attestations: write
|
||||
name: "${{ matrix.target }}"
|
||||
strategy:
|
||||
matrix:
|
||||
@@ -40,27 +44,8 @@ jobs:
|
||||
cd "D:/a/3proxy/3proxy"
|
||||
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
|
||||
echo "volatile char VerSion[]=^"3APA3A-3proxy-Internal-Build: 3proxy-%RELEASE%-%NOW%\r\n^";" >>src/3proxy.c
|
||||
nmake /F Makefile.msvc WOLFSSL=1
|
||||
- name: Decode Certificate
|
||||
shell: pwsh
|
||||
run: |
|
||||
$pfx_cert_byte = [System.Convert]::FromBase64String("${{ secrets.WINDOWS_CERTIFICATE }}")
|
||||
[System.IO.File]::WriteAllBytes("${{ github.workspace }}\cert.pfx", $pfx_cert_byte)
|
||||
- name: Extract public certificate
|
||||
shell: pwsh
|
||||
env:
|
||||
CERT_PASSWORD: ${{ secrets.WINDOWS_CERTIFICATE_PASSWORD }}
|
||||
run: |
|
||||
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("${{ github.workspace }}\cert.pfx", "$env:CERT_PASSWORD")
|
||||
[System.IO.File]::WriteAllBytes("${{ github.workspace }}\3proxy.crt", $cert.Export("Cert"))
|
||||
- name: Sign
|
||||
shell: pwsh
|
||||
env:
|
||||
CERT_PASSWORD: ${{ secrets.WINDOWS_CERTIFICATE_PASSWORD }}
|
||||
run: |
|
||||
$signtool = (Get-ChildItem "C:\Program Files (x86)\Windows Kits\10\bin\*\x64\signtool.exe" | Sort-Object { [version]$_.Directory.Parent.Name } -Descending | Select-Object -First 1).FullName
|
||||
Get-ChildItem bin\*.exe, bin\*.dll | ForEach-Object { & $signtool sign /f "${{ github.workspace }}\cert.pfx" /p "$env:CERT_PASSWORD" /tr http://timestamp.digicert.com /td sha256 /fd sha256 $_.FullName }
|
||||
- name: make dist dir
|
||||
shell: cmd
|
||||
run: |
|
||||
@@ -91,7 +76,6 @@ jobs:
|
||||
copy authors dist\3proxy\
|
||||
copy README.md dist\3proxy\
|
||||
copy rus.3ps dist\3proxy\
|
||||
copy 3proxy.crt dist\3proxy\
|
||||
- name: Get artifact
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
@@ -101,10 +85,30 @@ jobs:
|
||||
if: github.event_name == 'release'
|
||||
shell: pwsh
|
||||
run: Compress-Archive -Path dist/* -DestinationPath 3proxy-${{ env.RELEASE }}-arm64.zip
|
||||
- name: Checksums and detached signature
|
||||
if: github.event_name == 'release'
|
||||
shell: bash
|
||||
env:
|
||||
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
|
||||
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
|
||||
run: |
|
||||
if [ -z "$GPG_PRIVATE_KEY" ]; then echo "GPG_PRIVATE_KEY is not set"; exit 1; fi
|
||||
printf '%s' "$GPG_PRIVATE_KEY" | gpg --batch --import
|
||||
KEYID=$(gpg --list-secret-keys --with-colons | awk -F: '/^sec:/{print $5; exit}')
|
||||
sha256sum *.zip > SHA256SUMS-win-arm64
|
||||
gpg --batch --yes --pinentry-mode loopback --passphrase "$GPG_PASSPHRASE" \
|
||||
-u "$KEYID" --armor --detach-sign SHA256SUMS-win-arm64
|
||||
sha256sum -c SHA256SUMS-win-arm64
|
||||
- name: Attest build provenance
|
||||
if: github.event_name == 'release'
|
||||
uses: actions/attest-build-provenance@v2
|
||||
with:
|
||||
subject-path: |
|
||||
*.zip
|
||||
- name: Upload to release
|
||||
if: github.event_name == 'release'
|
||||
shell: bash
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
TAG: ${{ github.event.release.tag_name }}
|
||||
run: gh release upload "$TAG" 3proxy-${{ env.RELEASE }}-arm64.zip
|
||||
run: gh release upload "$TAG" *.zip SHA256SUMS-win-arm64 SHA256SUMS-win-arm64.asc
|
||||
@@ -1,99 +0,0 @@
|
||||
name: Build Docker images (GHCR)
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
id-token: write
|
||||
|
||||
env:
|
||||
REGISTRY: ghcr.io
|
||||
IMAGE_NAME: ${{ github.repository }}
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build and push Docker images
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v7
|
||||
|
||||
- name: Determine tags
|
||||
id: tags
|
||||
env:
|
||||
RELEASE_TAG: ${{ github.event.release.tag_name }}
|
||||
IMAGE: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||
run: |
|
||||
if [[ "$RELEASE_TAG" != "" ]]; then
|
||||
RELEASE="${RELEASE_TAG#v}"
|
||||
echo "minimal=${IMAGE}:${RELEASE}.minimal,${IMAGE}:minimal" >> "$GITHUB_OUTPUT"
|
||||
echo "busybox=${IMAGE}:${RELEASE}.busybox,${IMAGE}:busybox" >> "$GITHUB_OUTPUT"
|
||||
echo "full=${IMAGE}:${RELEASE},${IMAGE}:latest" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
DATETIME=$(date +%d%m%y%H%M%S)
|
||||
BRANCH=$(echo "${GITHUB_REF#refs/heads/}" | tr "/" "-")
|
||||
echo "minimal=${IMAGE}:${DATETIME}-${BRANCH}.minimal,${IMAGE}:${BRANCH}.minimal" >> "$GITHUB_OUTPUT"
|
||||
echo "busybox=${IMAGE}:${DATETIME}-${BRANCH}.busybox,${IMAGE}:${BRANCH}.busybox" >> "$GITHUB_OUTPUT"
|
||||
echo "full=${IMAGE}:${DATETIME}-${BRANCH},${IMAGE}:${BRANCH}" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v4
|
||||
|
||||
- name: Install cosign
|
||||
uses: sigstore/cosign-installer@v3
|
||||
|
||||
- name: Login to GHCR
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/login-action@v4
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build and push minimal
|
||||
uses: docker/build-push-action@v7
|
||||
with:
|
||||
context: .
|
||||
file: Dockerfile.minimal
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7,ppc64le
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.tags.outputs.minimal }}
|
||||
|
||||
- name: Build and push busybox
|
||||
uses: docker/build-push-action@v7
|
||||
with:
|
||||
context: .
|
||||
file: Dockerfile.busybox
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7,ppc64le
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.tags.outputs.busybox }}
|
||||
|
||||
- name: Build and push full
|
||||
uses: docker/build-push-action@v7
|
||||
with:
|
||||
context: .
|
||||
file: Dockerfile.full
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7,ppc64le
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.tags.outputs.full }}
|
||||
|
||||
- name: Sign images
|
||||
if: github.event_name != 'pull_request'
|
||||
env:
|
||||
TAGS_MINIMAL: ${{ steps.tags.outputs.minimal }}
|
||||
TAGS_BUSYBOX: ${{ steps.tags.outputs.busybox }}
|
||||
TAGS_FULL: ${{ steps.tags.outputs.full }}
|
||||
run: |
|
||||
IFS=',' read -ra TAGS <<< "$TAGS_MINIMAL,$TAGS_BUSYBOX,$TAGS_FULL"
|
||||
for tag in "${TAGS[@]}"; do
|
||||
cosign sign --yes "$tag"
|
||||
done
|
||||
|
||||
+152
-54
@@ -1,4 +1,4 @@
|
||||
name: Build Docker images (Docker Hub)
|
||||
name: Build Docker images
|
||||
|
||||
on:
|
||||
release:
|
||||
@@ -7,89 +7,187 @@ on:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
id-token: write
|
||||
|
||||
env:
|
||||
REGISTRY: docker.io
|
||||
IMAGE_NAME: 3proxy/3proxy
|
||||
DOCKERHUB_IMAGE: docker.io/3proxy/3proxy
|
||||
GHCR_IMAGE: ghcr.io/3proxy/3proxy
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build and push Docker images
|
||||
runs-on: ubuntu-latest
|
||||
name: ${{ matrix.image }} ${{ matrix.platform }}
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
runs-on: ${{ matrix.runner }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
image: [full, busybox, minimal]
|
||||
platform: [linux/amd64, linux/arm64, linux/arm/v7]
|
||||
include:
|
||||
- platform: linux/amd64
|
||||
runner: ubuntu-latest
|
||||
- platform: linux/arm64
|
||||
runner: ubuntu-24.04-arm
|
||||
- platform: linux/arm/v7
|
||||
runner: ubuntu-24.04-arm
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v7
|
||||
|
||||
- name: Determine tags
|
||||
id: tags
|
||||
env:
|
||||
RELEASE_TAG: ${{ github.event.release.tag_name }}
|
||||
run: |
|
||||
if [[ "$RELEASE_TAG" != "" ]]; then
|
||||
RELEASE="${RELEASE_TAG#v}"
|
||||
echo "minimal=${REGISTRY}/${IMAGE_NAME}:${RELEASE}.minimal,${REGISTRY}/${IMAGE_NAME}:minimal" >> "$GITHUB_OUTPUT"
|
||||
echo "busybox=${REGISTRY}/${IMAGE_NAME}:${RELEASE}.busybox,${REGISTRY}/${IMAGE_NAME}:busybox" >> "$GITHUB_OUTPUT"
|
||||
echo "full=${REGISTRY}/${IMAGE_NAME}:${RELEASE},${REGISTRY}/${IMAGE_NAME}:latest" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
DATETIME=$(date +%d%m%y%H%M%S)
|
||||
BRANCH=$(echo "${GITHUB_REF#refs/heads/}" | tr "/" "-")
|
||||
echo "minimal=${REGISTRY}/${IMAGE_NAME}:${DATETIME}-${BRANCH}.minimal,${REGISTRY}/${IMAGE_NAME}:${BRANCH}.minimal" >> "$GITHUB_OUTPUT"
|
||||
echo "busybox=${REGISTRY}/${IMAGE_NAME}:${DATETIME}-${BRANCH}.busybox,${REGISTRY}/${IMAGE_NAME}:${BRANCH}.busybox" >> "$GITHUB_OUTPUT"
|
||||
echo "full=${REGISTRY}/${IMAGE_NAME}:${DATETIME}-${BRANCH},${REGISTRY}/${IMAGE_NAME}:${BRANCH}" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
- name: Platform name
|
||||
id: platform
|
||||
run: echo "pair=$(echo '${{ matrix.platform }}' | tr / -)" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Set up QEMU
|
||||
if: matrix.platform == 'linux/arm/v7'
|
||||
uses: docker/setup-qemu-action@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v4
|
||||
|
||||
- name: Login to GHCR
|
||||
uses: docker/login-action@v4
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build and push by digest
|
||||
id: build
|
||||
uses: docker/build-push-action@v7
|
||||
with:
|
||||
context: .
|
||||
file: Dockerfile.${{ matrix.image }}
|
||||
platforms: ${{ matrix.platform }}
|
||||
provenance: false
|
||||
sbom: false
|
||||
outputs: type=image,name=${{ env.GHCR_IMAGE }},push-by-digest=true,name-canonical=true,push=true
|
||||
|
||||
- name: Export digest
|
||||
env:
|
||||
DIGEST: ${{ steps.build.outputs.digest }}
|
||||
run: |
|
||||
mkdir -p /tmp/digests
|
||||
touch "/tmp/digests/${DIGEST#sha256:}"
|
||||
|
||||
- name: Upload digest
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: digests-${{ matrix.image }}-${{ steps.platform.outputs.pair }}
|
||||
path: /tmp/digests/*
|
||||
if-no-files-found: error
|
||||
retention-days: 1
|
||||
|
||||
publish:
|
||||
name: Publish ${{ matrix.image }}
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
id-token: write
|
||||
attestations: write
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- image: full
|
||||
suffix: ''
|
||||
floating: lts
|
||||
- image: busybox
|
||||
suffix: .busybox
|
||||
floating: lts-busybox
|
||||
- image: minimal
|
||||
suffix: .minimal
|
||||
floating: lts-minimal
|
||||
steps:
|
||||
- name: Download digests
|
||||
uses: actions/download-artifact@v7
|
||||
with:
|
||||
path: /tmp/digests
|
||||
pattern: digests-${{ matrix.image }}-*
|
||||
merge-multiple: true
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v4
|
||||
|
||||
- name: Install cosign
|
||||
uses: sigstore/cosign-installer@v3
|
||||
with:
|
||||
cosign-release: v2.4.3
|
||||
|
||||
- name: Login to Docker Hub
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/login-action@v4
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Build and push minimal
|
||||
uses: docker/build-push-action@v7
|
||||
- name: Login to GHCR
|
||||
uses: docker/login-action@v4
|
||||
with:
|
||||
context: .
|
||||
file: Dockerfile.minimal
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7,ppc64le
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.tags.outputs.minimal }}
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build and push busybox
|
||||
uses: docker/build-push-action@v7
|
||||
with:
|
||||
context: .
|
||||
file: Dockerfile.busybox
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7,ppc64le
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.tags.outputs.busybox }}
|
||||
- name: Determine tags
|
||||
id: tags
|
||||
env:
|
||||
RELEASE_TAG: ${{ github.event.release.tag_name }}
|
||||
SUFFIX: ${{ matrix.suffix }}
|
||||
FLOATING: ${{ matrix.floating }}
|
||||
run: |
|
||||
if [[ "$RELEASE_TAG" != "" ]]; then
|
||||
RELEASE="${RELEASE_TAG#v}"
|
||||
echo "versioned=${RELEASE}${SUFFIX}" >> "$GITHUB_OUTPUT"
|
||||
echo "moving=${FLOATING}" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
DATETIME=$(date +%d%m%y%H%M%S)
|
||||
BRANCH=$(echo "${GITHUB_REF#refs/heads/}" | tr "/" "-")
|
||||
echo "versioned=${DATETIME}-${BRANCH}${SUFFIX}" >> "$GITHUB_OUTPUT"
|
||||
echo "moving=${BRANCH}${SUFFIX}" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
- name: Build and push full
|
||||
uses: docker/build-push-action@v7
|
||||
- name: Create manifest list and push
|
||||
working-directory: /tmp/digests
|
||||
env:
|
||||
VERSIONED: ${{ steps.tags.outputs.versioned }}
|
||||
MOVING: ${{ steps.tags.outputs.moving }}
|
||||
run: |
|
||||
docker buildx imagetools create \
|
||||
-t "${DOCKERHUB_IMAGE}:${VERSIONED}" \
|
||||
-t "${DOCKERHUB_IMAGE}:${MOVING}" \
|
||||
-t "${GHCR_IMAGE}:${VERSIONED}" \
|
||||
-t "${GHCR_IMAGE}:${MOVING}" \
|
||||
$(printf "${GHCR_IMAGE}@sha256:%s " *)
|
||||
|
||||
- name: Get pushed digest
|
||||
id: digest
|
||||
env:
|
||||
VERSIONED: ${{ steps.tags.outputs.versioned }}
|
||||
run: |
|
||||
DIGEST=$(docker buildx imagetools inspect "${DOCKERHUB_IMAGE}:${VERSIONED}" \
|
||||
--format '{{json .Manifest}}' | jq -r .digest)
|
||||
echo "digest=${DIGEST}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Attest Docker Hub image
|
||||
uses: actions/attest-build-provenance@v2
|
||||
with:
|
||||
context: .
|
||||
file: Dockerfile.full
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7,ppc64le
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.tags.outputs.full }}
|
||||
subject-name: ${{ env.DOCKERHUB_IMAGE }}
|
||||
subject-digest: ${{ steps.digest.outputs.digest }}
|
||||
push-to-registry: false
|
||||
|
||||
- name: Attest GHCR image
|
||||
uses: actions/attest-build-provenance@v2
|
||||
with:
|
||||
subject-name: ${{ env.GHCR_IMAGE }}
|
||||
subject-digest: ${{ steps.digest.outputs.digest }}
|
||||
push-to-registry: false
|
||||
|
||||
- name: Sign images
|
||||
if: github.event_name != 'pull_request'
|
||||
env:
|
||||
TAGS_MINIMAL: ${{ steps.tags.outputs.minimal }}
|
||||
TAGS_BUSYBOX: ${{ steps.tags.outputs.busybox }}
|
||||
TAGS_FULL: ${{ steps.tags.outputs.full }}
|
||||
DIGEST: ${{ steps.digest.outputs.digest }}
|
||||
run: |
|
||||
IFS=',' read -ra TAGS <<< "$TAGS_MINIMAL,$TAGS_BUSYBOX,$TAGS_FULL"
|
||||
for tag in "${TAGS[@]}"; do
|
||||
cosign sign --yes "$tag"
|
||||
done
|
||||
cosign sign --yes "${DOCKERHUB_IMAGE}@${DIGEST}"
|
||||
cosign sign --yes "${GHCR_IMAGE}@${DIGEST}"
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
name: Release source tarball
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
tarball:
|
||||
permissions:
|
||||
contents: write
|
||||
id-token: write
|
||||
attestations: write
|
||||
name: "source tarball"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
|
||||
- name: env
|
||||
run: |
|
||||
if [ -f RELEASE ]; then
|
||||
RELEASE=$(tr -d ' \t\r\n' < RELEASE)
|
||||
else
|
||||
RELEASE=$(tr -d ' \t\r\n' < DEVEL)
|
||||
fi
|
||||
echo "RELEASE=$RELEASE" >> $GITHUB_ENV
|
||||
|
||||
- name: Create tarball
|
||||
run: |
|
||||
# git archive is reproducible from the tag: anyone can regenerate the
|
||||
# tarball and compare it against the published checksum.
|
||||
git archive --format=tar.gz -9 \
|
||||
--prefix="3proxy-${{ env.RELEASE }}/" \
|
||||
-o "3proxy-${{ env.RELEASE }}.tar.gz" HEAD
|
||||
tar tzf "3proxy-${{ env.RELEASE }}.tar.gz" >/dev/null
|
||||
ls -l *.tar.gz
|
||||
|
||||
- name: Get artifact
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: "3proxy-${{ env.RELEASE }}-src"
|
||||
path: "*.tar.gz"
|
||||
|
||||
- name: Import signing key
|
||||
if: github.event_name == 'release'
|
||||
env:
|
||||
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
|
||||
run: |
|
||||
if [ -z "$GPG_PRIVATE_KEY" ]; then echo "GPG_PRIVATE_KEY is not set"; exit 1; fi
|
||||
mkdir -p ~/.gnupg && chmod 700 ~/.gnupg
|
||||
printf 'allow-loopback-pinentry\n' > ~/.gnupg/gpg-agent.conf
|
||||
gpgconf --kill gpg-agent || true
|
||||
printf '%s' "$GPG_PRIVATE_KEY" | gpg --batch --import
|
||||
KEYID=$(gpg --list-secret-keys --with-colons | awk -F: '/^sec:/{print $5; exit}')
|
||||
echo "GPG_KEYID=$KEYID" >> $GITHUB_ENV
|
||||
|
||||
- name: Checksums and detached signatures
|
||||
if: github.event_name == 'release'
|
||||
env:
|
||||
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
|
||||
run: |
|
||||
sha256sum *.tar.gz > SHA256SUMS-src
|
||||
for f in *.tar.gz SHA256SUMS-src; do
|
||||
gpg --batch --yes --pinentry-mode loopback --passphrase "$GPG_PASSPHRASE" \
|
||||
-u "$GPG_KEYID" --armor --detach-sign "$f"
|
||||
done
|
||||
sha256sum -c SHA256SUMS-src
|
||||
gpg --verify SHA256SUMS-src.asc SHA256SUMS-src
|
||||
|
||||
- name: Attest build provenance
|
||||
if: github.event_name == 'release'
|
||||
uses: actions/attest-build-provenance@v4
|
||||
with:
|
||||
subject-path: |
|
||||
*.tar.gz
|
||||
|
||||
- name: Upload to release
|
||||
if: github.event_name == 'release'
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
TAG: ${{ github.event.release.tag_name }}
|
||||
run: gh release upload "$TAG" *.tar.gz *.tar.gz.asc SHA256SUMS-src SHA256SUMS-src.asc
|
||||
@@ -0,0 +1,94 @@
|
||||
name: Update version files
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- RELEASE
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
version:
|
||||
permissions:
|
||||
contents: write
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
|
||||
- name: Regenerate version files
|
||||
run: |
|
||||
RELEASE=$(tr -d ' \t\r\n' < RELEASE)
|
||||
if [ -z "$RELEASE" ]; then echo "RELEASE is empty"; exit 1; fi
|
||||
MAJOR=$(echo "$RELEASE" | cut -d . -f 1)
|
||||
SUBMAJOR=$(echo "$RELEASE" | cut -d . -f 2)
|
||||
MINOR=$(echo "$RELEASE" | cut -d . -f 3)
|
||||
SUBMINOR=$(echo "$RELEASE" | cut -d . -f 4)
|
||||
[ -n "$SUBMAJOR" ] || SUBMAJOR=0
|
||||
[ -n "$MINOR" ] || MINOR=0
|
||||
[ -n "$SUBMINOR" ] || SUBMINOR=0
|
||||
|
||||
# The build date is minted once per release and then carried in
|
||||
# version.h, so that rebuilding the same commit yields the same
|
||||
# version string and the same package names.
|
||||
OLDRELEASE=$(sed -n 's/^#define VERSION "3proxy-\(.*\)"$/\1/p' src/version.h 2>/dev/null)
|
||||
OLDBUILDDATE=$(sed -n 's/^#define BUILDDATE "\(.*\)"$/\1/p' src/version.h 2>/dev/null)
|
||||
if [ "$OLDRELEASE" = "$RELEASE" ] && [ -n "$OLDBUILDDATE" ]; then
|
||||
BUILDDATE="$OLDBUILDDATE"
|
||||
else
|
||||
BUILDDATE=$(date -u +%y%m%d%H%M%S)
|
||||
fi
|
||||
echo "release $RELEASE -> $MAJOR $SUBMAJOR $MINOR $SUBMINOR, build date $BUILDDATE"
|
||||
SOURCE_DATE_EPOCH=$(date -u -d "20${BUILDDATE:0:2}-${BUILDDATE:2:2}-${BUILDDATE:4:2} ${BUILDDATE:6:2}:${BUILDDATE:8:2}:${BUILDDATE:10:2}" +%s)
|
||||
YEAR=$(date -u -d @$SOURCE_DATE_EPOCH +%Y)
|
||||
|
||||
DEBVERSION=$(head -1 debian/changelog | cut -d "(" -f 2 | cut -d ")" -f 1)
|
||||
if [ "$DEBVERSION" != "$RELEASE-1" ]; then
|
||||
mv debian/changelog debian/changelog.old
|
||||
{ echo "3proxy ($RELEASE-1) buster; urgency=medium"
|
||||
echo ""
|
||||
echo " *3proxy $RELEASE initial build"
|
||||
echo ""
|
||||
echo " -- z3APA3A <3apa3a@3proxy.org> $(date -R -u -d @$SOURCE_DATE_EPOCH)"
|
||||
echo ""
|
||||
cat debian/changelog.old
|
||||
} > debian/changelog
|
||||
rm -f debian/changelog.old
|
||||
fi
|
||||
|
||||
mv scripts/rh/3proxy.spec scripts/rh/3proxy.spec.old
|
||||
{ echo "Name: 3proxy"
|
||||
echo "Version: $RELEASE"
|
||||
echo "Release: 1%{?dist}"
|
||||
tail --lines=+4 scripts/rh/3proxy.spec.old
|
||||
} > scripts/rh/3proxy.spec
|
||||
rm -f scripts/rh/3proxy.spec.old
|
||||
|
||||
{ echo "#ifndef VERSION"
|
||||
echo "#define VERSION \"3proxy-$RELEASE\""
|
||||
echo "#endif"
|
||||
echo "#ifndef BUILDDATE"
|
||||
echo "#define BUILDDATE \"$BUILDDATE\""
|
||||
echo "#endif"
|
||||
echo "#define MAJOR3PROXY $MAJOR"
|
||||
echo "#define SUBMAJOR3PROXY $SUBMAJOR"
|
||||
echo "#define MINOR3PROXY $MINOR"
|
||||
echo "#define SUBMINOR3PROXY $SUBMINOR"
|
||||
echo "#define RELEASE3PROXY \"3proxy-$RELEASE(\" BUILDDATE \")\\0\""
|
||||
echo "#ifndef YEAR3PROXY"
|
||||
echo "#define YEAR3PROXY \"$YEAR\""
|
||||
echo "#endif"
|
||||
} > src/version.h
|
||||
|
||||
- name: Commit
|
||||
run: |
|
||||
if [ -z "$(git status --porcelain debian/changelog scripts/rh/3proxy.spec src/version.h)" ]; then
|
||||
echo "version files already up to date"
|
||||
exit 0
|
||||
fi
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||
git add debian/changelog scripts/rh/3proxy.spec src/version.h
|
||||
git commit -m "Update version files for $(tr -d ' \t\r\n' < RELEASE)"
|
||||
git push
|
||||
@@ -0,0 +1,29 @@
|
||||
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||
|
||||
mQINBGqIZCIBEADF3zxdMo2dvUGAlQm3aIcQiqmpLMHucvLfSK3fHtwagO8f03CO
|
||||
bEx9EfIK/U6BzLwEJ0CxyClzfvgo9COVpi5EjES9sI2LXzcgc4hGaYO0Q4Unj//0
|
||||
W/G8aarDaLF2NRKMLf07eaYGBRJjqHnmeHgOHdr+SnN0JtMSadWMHoliB8esnabz
|
||||
5CO4JabTrhwoez3DMLSgJNIod7wL6PJJv/2BeRahwNr2CjaXmzZKr/j7fc1MKLij
|
||||
bsvJ5OmLmngZr6CHDa9cBhVhiH+7RgWLCsRlEGxEv7w0afp/T0xDwNAPkGzk5ObC
|
||||
BrdXvypTAbNyUoVT8qSVJwkneZ4S0Ts4rRRNfNpaus4tsCmgyGKzsrbxvbiBOTPW
|
||||
jB/fjkgr6X9M/AQ3yGpXrwXRJrM/nSfjUyOEHXttTC9HpGt41NH/mpC4mDWa1Kxi
|
||||
FMxuo1+dw2kpDKl0Bp78IGdCo5akHwftFr8aHgmfZoGXAGJRHPAWbJGjC2ARy8yp
|
||||
QOpxba0S3VlCU6bs8MDKl6cpWItnlXcl/GD/Qc55bjLXjFv1pbn2RUSYZS+n9wDX
|
||||
64syZf3dZ/N5U4ydmybWfiLFUXqKQLtdO8QAWQGt4TSwKptTmI581/MMCTQ8qWZL
|
||||
zgFj6C/8K0SZ4lMOv+5zfc2+QOoWw7E2Ws3stEKTyWjOMm/QMJAGumqvqwARAQAB
|
||||
tCozcHJveHkgcmVsZWFzZSBzaWduaW5nIDwzcHJveHlAM3Byb3h5Lm9yZz6JAm0E
|
||||
EwEIAFcWIQT8EiFEmfzHuhz/bNwDEjhOOnOUCwUCaohkIhsUgAAAAAAEAA5tYW51
|
||||
MiwyLjUrMS4xMiwwLDMCGwMFCwkIBwICIgIGFQoJCAsCBBYCAwECHgcCF4AACgkQ
|
||||
AxI4TjpzlAsCwRAAtH3OO42yCd2B8Od4yS1yBDkaIFwEm8hF68eou6uaSDkKG8YZ
|
||||
C3DUH7qk0nXEMQu/5J6RWZKlW1C8D3AkUR9A1g54o6mUg4IL5196XsrQRdVu64YF
|
||||
nLCk17Piku1lMk+Re6bZ6uJv5UlSv8d0dvxmAYzjusyPyBC2VXy7B0CoDif6AmXt
|
||||
aw2/V6m0dRrfFo4W9mJKUqTAJcdBOKzEiQb7qLnzuwy4CB5qsvnEQTqymoCXFXzg
|
||||
VDCSKRLXnbDPbIs0TvsCmthn/w1hCgftPq4W0s7EUJBOhbrjF59+AuTb+U1wIXNR
|
||||
1+DPF+V+5RlwWjOWMlsOVGk2jaxjVY8wuaD3rE6ISJkt1pRv/WVdY984rT7Eu94J
|
||||
ZHnxPjFrb2ohFKjoBCt60kbgZbuQ6yvEma5lAF9K63gwMNNyGZvq6QWl58iouzuS
|
||||
3B9t7EwGwFstJfaXVhn/rnIHoExgxVZMbbsmXiGJyE2KcfVmlZcEi0MIyqEeBSDD
|
||||
gjpE4yVO6StBtJKfXra8rMwtsbWBw9MptPhcLvdWtN6TG0CxDyTHhdL1pSLNcwX1
|
||||
CTVpwi6+WmGogcv0WFNn5caQUpu9le/v/5qLRK08KWOH8inMJmTfpJg/9869YJuF
|
||||
vDKdzJd6jug5YQRfV/7YVC2hdSOBLvBuDpRINePrj9CKJ34qG+jRSJ5xwYk=
|
||||
=IS3Y
|
||||
-----END PGP PUBLIC KEY BLOCK-----
|
||||
@@ -1,28 +1,10 @@
|
||||
3proxy-0.9.8 Released August, 7 2026
|
||||
3proxy-0.9.9.4 Released November, 21 2026
|
||||
|
||||
!! 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
|
||||
! Fix: socks: a SOCKS4a request was refused as a connect to the null address, although in SOCKS4a the null address means that the destination is the name which follows it
|
||||
! Fix: auth: a UDP ASSOCIATE is pre-authorized without looking at the destination its rules depend on, so its verdict holds for that association alone and is not kept for later requests
|
||||
! Fix: socks: a UDP association was relayed direct when its parent failed, although the rules demanded the parent; it is refused now
|
||||
! Fix: socks: a host name with control bytes or spaces in it was taken as it stood; it is refused where it is read now
|
||||
! Fix: smtpp: a login name of a port alone, without a host, set the port but named no destination to connect to; such a login is refused now
|
||||
! Fix: proxy: the credentials of an earlier request on a kept-alive connection decided for the requests after it; every request is authorized by its own credentials now
|
||||
! Fix: tlspr: a TLS ServerHello too short for the extensions length it declared was read past its end; it is refused now (#1286)
|
||||
! Fix: pcre: a rule with no ACL was handed to the filters as the connection's data, which they read as a match data block and freed: a pointer into the configuration, dereferenced as another type and given back to malloc; a rule without an ACL now skips the check and goes on with a block of its own
|
||||
+9
-27
@@ -1,28 +1,10 @@
|
||||
3proxy-0.9.8 Вышел 7 Августа 2026
|
||||
3proxy-0.9.9.4 Вышел 21 Ноября 2026
|
||||
|
||||
!! Исправление: 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
|
||||
! Множество мелких исправлений и очистка кода
|
||||
! Исправление: socks: запрос SOCKS4a отвергался как соединение с нулевым адресом, хотя в SOCKS4a нулевой адрес означает, что назначение — имя, следующее за ним
|
||||
! Исправление: auth: UDP ASSOCIATE проходит предварительную авторизацию, не зная назначения, от которого зависят её правила, поэтому её вердикт относится только к этой ассоциации и не сохраняется для последующих запросов
|
||||
! Исправление: socks: UDP-ассоциация передавалась напрямую при сбое родителя, хотя правила требовали родителя; теперь она отвергается
|
||||
! Исправление: socks: имя хоста с управляющими байтами или пробелами принималось как есть; теперь оно отвергается там, где читается
|
||||
! Исправление: smtpp: имя входа из одного порта, без хоста, задавало порт, но не называло назначения для соединения; такое имя входа теперь отвергается
|
||||
! Исправление: proxy: учётные данные раннего запроса в сохранённом соединении решали и для последующих запросов; теперь каждый запрос авторизуется своими учётными данными
|
||||
! Исправление: tlspr: ServerHello TLS, слишком короткий для объявленной длины расширений, читался за его концом; теперь он отвергается (#1286)
|
||||
! Исправление: pcre: правило без ACL передавалось фильтрам как данные соединения, и они читали его как блок данных сопоставления и освобождали: указатель в конфигурацию, разыменованный как другой тип и возвращённый malloc; теперь правило без ACL пропускает проверку и идёт со своим блоком
|
||||
+6
-5
@@ -51,7 +51,7 @@ option(3PROXY_USE_OPENSSL "Enable TLS/SSL support via OpenSSL (fallback when wol
|
||||
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 "Build Linux splice() support, slower than read/write for most traffic (Linux only)" OFF)
|
||||
option(3PROXY_USE_SPLICE "Build Linux splice() support, used by services given -s (Linux only)" ON)
|
||||
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)
|
||||
@@ -664,10 +664,7 @@ foreach(PROXY_NAME proxy socks pop3p imapp smtpp ftppr tcppm udppm tlspr)
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
)
|
||||
|
||||
target_compile_definitions(${PROXY_NAME} PRIVATE
|
||||
WITHMAIN
|
||||
NOPORTMAP
|
||||
)
|
||||
target_compile_definitions(${PROXY_NAME} PRIVATE WITHMAIN)
|
||||
|
||||
if(NOT PROXY_NAME STREQUAL "udppm")
|
||||
target_compile_definitions(${PROXY_NAME} PRIVATE NOUDPMAIN)
|
||||
@@ -679,8 +676,12 @@ foreach(PROXY_NAME proxy socks pop3p imapp smtpp ftppr tcppm udppm tlspr)
|
||||
target_compile_definitions(${PROXY_NAME} PRIVATE ANONYMOUS)
|
||||
endif()
|
||||
|
||||
# port mappers take port, host and port as arguments, the others options
|
||||
# only; one of the two is defined, as in src/Makefile.inc
|
||||
if(PROXY_NAME STREQUAL "tcppm" OR PROXY_NAME STREQUAL "udppm" OR PROXY_NAME STREQUAL "tlspr")
|
||||
target_compile_definitions(${PROXY_NAME} PRIVATE PORTMAP)
|
||||
else()
|
||||
target_compile_definitions(${PROXY_NAME} PRIVATE NOPORTMAP)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
|
||||
+4
-4
@@ -52,14 +52,14 @@ 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)
|
||||
WOLFSSL_CHECK ?= $(shell printf "\#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)
|
||||
OPENSSL_CHECK ?= $(shell printf "\#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)
|
||||
CFLAGS += -DWITH_SSL
|
||||
@@ -68,13 +68,13 @@ 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)
|
||||
PCRE_CHECK ?= $(shell printf "\#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
|
||||
PCRE_OBJS = pcre$(OBJSUFFICS)
|
||||
PCRE_LIBS = $(STATIC_PREFIX) -lpcre2-8 $(STATIC_SUFFIX)
|
||||
endif
|
||||
PAM_CHECK ?= $(shell echo "\#include <security/pam_appl.h>\\n int main(){return 0;}" | tr -d \\\\ | $(CC) -x c $(CFLAGS) -o testpam.o - 2>/dev/null && $(CC) $(LDFLAGS) -o testpam testpam.o -lpam 2>/dev/null && rm testpam testpam.o && echo true||echo false)
|
||||
PAM_CHECK ?= $(shell printf "\#include <security/pam_appl.h>\\n int main(){return 0;}" | tr -d \\\\ | $(CC) -x c $(CFLAGS) -o testpam.o - 2>/dev/null && $(CC) $(LDFLAGS) -o testpam testpam.o -lpam 2>/dev/null && rm testpam testpam.o && echo true||echo false)
|
||||
ifeq ($(PAM_CHECK), true)
|
||||
PLUGINS += PamAuth
|
||||
endif
|
||||
|
||||
+8
-8
@@ -4,9 +4,9 @@
|
||||
# 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.
|
||||
# Linux splice() support is built, but used only by services given the -s
|
||||
# option: it is faster for large transfers and slower for small requests.
|
||||
# Remove -DWITHSPLICE from CFLAGS to build without it.
|
||||
|
||||
BUILDDIR = ../bin/
|
||||
PREFIX ?= 3proxy_
|
||||
@@ -14,7 +14,7 @@ CRYPT_PREFIX ?= $(PREFIX)
|
||||
CC ?= gcc
|
||||
|
||||
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
|
||||
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
|
||||
COUT = -o
|
||||
LN ?= ${CC}
|
||||
DCFLAGS ?= -fPIC
|
||||
@@ -60,14 +60,14 @@ 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)
|
||||
WOLFSSL_CHECK ?= $(shell printf "\#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)
|
||||
OPENSSL_CHECK ?= $(shell printf "\#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)
|
||||
CFLAGS += -DWITH_SSL
|
||||
@@ -76,13 +76,13 @@ 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)
|
||||
PCRE_CHECK ?= $(shell printf "\#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
|
||||
PCRE_OBJS = pcre$(OBJSUFFICS)
|
||||
PCRE_LIBS = $(STATIC_PREFIX) -lpcre2-8 $(STATIC_SUFFIX)
|
||||
endif
|
||||
PAM_CHECK ?= $(shell echo "\#include <security/pam_appl.h>\\n int main(){return 0;}" | tr -d \\\\ | $(CC) -x c $(CFLAGS) -o testpam.o - 2>/dev/null && $(CC) $(LDFLAGS) -o testpam testpam.o -lpam 2>/dev/null && rm testpam testpam.o && echo true||echo false)
|
||||
PAM_CHECK ?= $(shell printf "\#include <security/pam_appl.h>\\n int main(){return 0;}" | tr -d \\\\ | $(CC) -x c $(CFLAGS) -o testpam.o - 2>/dev/null && $(CC) $(LDFLAGS) -o testpam testpam.o -lpam 2>/dev/null && rm testpam testpam.o && echo true||echo false)
|
||||
ifeq ($(PAM_CHECK), true)
|
||||
PLUGINS += PamAuth
|
||||
endif
|
||||
|
||||
+3
-3
@@ -31,20 +31,20 @@ 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)
|
||||
WOLFSSL_CHECK = $(shell printf "\#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)
|
||||
OPENSSL_CHECK = $(shell printf "\#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)
|
||||
PCRE_CHECK = $(shell printf "\#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
|
||||
PCRE_OBJS = pcre$(OBJSUFFICS)
|
||||
|
||||
+4
-4
@@ -54,14 +54,14 @@ 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)
|
||||
WOLFSSL_CHECK ?= $(shell printf "\#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)
|
||||
OPENSSL_CHECK ?= $(shell printf "\#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)
|
||||
CFLAGS += -DWITH_SSL
|
||||
@@ -70,13 +70,13 @@ 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)
|
||||
PCRE_CHECK ?= $(shell printf "\#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
|
||||
PCRE_OBJS = pcre$(OBJSUFFICS)
|
||||
PCRE_LIBS = $(STATIC_PREFIX) -lpcre2-8 $(STATIC_SUFFIX)
|
||||
endif
|
||||
PAM_CHECK ?= $(shell echo "\#include <security/pam_appl.h>\\n int main(){return 0;}" | tr -d \\\\ | $(CC) -x c $(CFLAGS) -o testpam.o - 2>/dev/null && $(CC) $(LDFLAGS) -o testpam testpam.o -lpam 2>/dev/null && rm testpam testpam.o && echo true||echo false)
|
||||
PAM_CHECK ?= $(shell printf "\#include <security/pam_appl.h>\\n int main(){return 0;}" | tr -d \\\\ | $(CC) -x c $(CFLAGS) -o testpam.o - 2>/dev/null && $(CC) $(LDFLAGS) -o testpam testpam.o -lpam 2>/dev/null && rm testpam testpam.o && echo true||echo false)
|
||||
ifeq ($(PAM_CHECK), true)
|
||||
PLUGINS += PamAuth
|
||||
endif
|
||||
|
||||
+4
-4
@@ -47,14 +47,14 @@ ifeq ($(LIBSTATIC), true)
|
||||
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)
|
||||
WOLFSSL_CHECK = $(shell printf "\#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)
|
||||
OPENSSL_CHECK = $(shell printf "\#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 += $(STATIC_PREFIX) $(ZLIB) -l crypto -l ssl $(STATIC_SUFFIX) -lcrypt32
|
||||
CFLAGS += -DWITH_SSL
|
||||
@@ -63,11 +63,11 @@ else
|
||||
ZLIB :=
|
||||
endif
|
||||
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)
|
||||
PAM_CHECK = $(shell printf "\#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) $(STATIC_PREFIX) -lpcre2-8 $(STATIC_SUFFIX) -o testpcre - 2>/dev/null && rm testpcre && echo true||echo false)
|
||||
PCRE_CHECK = $(shell printf "\#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)
|
||||
|
||||
@@ -6,13 +6,52 @@
|
||||
|
||||
### Branches
|
||||
|
||||
- **Master** (stable) branch - 3proxy 0.9
|
||||
- **Devel** branch - 3proxy 10 (don't use it)
|
||||
- **Master** (stable) branch - 3proxy 1.0
|
||||
- **0.9** (LTS) branch - 3proxy 0.9 maintenance branch, this branch
|
||||
- **Devel** branch - 3proxy 2.0-devel (don't use it)
|
||||
|
||||
### Binaries (deb / rpm / Windows zip)
|
||||
|
||||
https://github.com/3proxy/3proxy/releases
|
||||
|
||||
### Package repository (apt / dnf)
|
||||
|
||||
Signed apt and dnf repositories are published at https://3proxy.org/repo/ in
|
||||
two channels: `lts` (0.9 branch) and `current` (master).
|
||||
|
||||
Debian 12 and Ubuntu 22.04 or newer:
|
||||
|
||||
```
|
||||
sudo curl -fsSL https://3proxy.org/repo/3proxy-release-key.asc \
|
||||
-o /usr/share/keyrings/3proxy.asc
|
||||
sudo tee /etc/apt/sources.list.d/3proxy.sources <<EOF
|
||||
Types: deb
|
||||
URIs: https://3proxy.org/repo/deb
|
||||
Suites: lts
|
||||
Components: main
|
||||
Signed-By: /usr/share/keyrings/3proxy.asc
|
||||
EOF
|
||||
sudo apt update && sudo apt install 3proxy
|
||||
```
|
||||
|
||||
AlmaLinux, RHEL, Rocky and CentOS Stream 8, 9 and 10:
|
||||
|
||||
```
|
||||
sudo tee /etc/yum.repos.d/3proxy.repo <<EOF
|
||||
[3proxy]
|
||||
name=3proxy
|
||||
baseurl=https://3proxy.org/repo/rpm/lts/el\$releasever/\$basearch/
|
||||
enabled=1
|
||||
gpgcheck=1
|
||||
repo_gpgcheck=1
|
||||
gpgkey=https://3proxy.org/repo/3proxy-release-key.asc
|
||||
EOF
|
||||
sudo dnf install 3proxy
|
||||
```
|
||||
|
||||
Both the packages and the repository metadata are signed. See
|
||||
https://3proxy.org/repo/ for the `current` channel and for release key details.
|
||||
|
||||
### Docker images
|
||||
|
||||
https://hub.docker.com/r/3proxy/3proxy
|
||||
@@ -29,9 +68,9 @@ Documentation (man pages and HTML) available with download, on https://3proxy.or
|
||||
|
||||
## Docker images
|
||||
|
||||
3 docker configurations are provided, default (full) also tagged as `:latest`, `:busybox` and `:minimal`, all refer to newest stable version. Except busybox, images are distroless and contain only binaries, you can not sh inside the container. `:busybox` contains busybox shell.
|
||||
3 docker configurations are provided, default (full) also tagged as `:lts`, `:lts-busybox` and `:lts-minimal`, all refer to newest 0.9 LTS version. Images built from this branch use the `lts` tags, images built from the master branch use `:latest`, `:busybox` and `:minimal`. Use the `lts` tags to stay on the 0.9 branch, use a version tag (e.g. `:0.9.9`) to pin an exact version. Except busybox, images are distroless and contain only binaries, you can not sh inside the container. `:lts-busybox` contains busybox shell.
|
||||
|
||||
### Default image (`:latest`):
|
||||
### Default image (`:lts`):
|
||||
|
||||
Full installation requires to mount /etc/3proxy/3proxy.cfg files.
|
||||
|
||||
@@ -42,7 +81,7 @@ echo "log
|
||||
nserver 8.8.8.8
|
||||
nscache 65536
|
||||
proxy -p3129" | docker config create 3proxy
|
||||
docker run --read-only -p 3129:3129 --config source=3proxy,target=/etc/3proxy/3proxy.cfg --name 3proxy.full docker.io/3proxy/3proxy
|
||||
docker run --read-only -p 3129:3129 --config source=3proxy,target=/etc/3proxy/3proxy.cfg --name 3proxy.full docker.io/3proxy/3proxy:lts
|
||||
```
|
||||
|
||||
`podman` does not support `config` as above.
|
||||
@@ -60,13 +99,13 @@ podman run --read-only -p 3129:3129 -v /path/to/local/config/directory/3proxy.cf
|
||||
use `log` without pathname in config to log to stdout.
|
||||
plugins are located in /usr/local/3proxy/libexec (/libexec for chroot config) and since 0.9.6 symlinked by /lib and /lib64 in both chroot and non-chroot configurations, so no full path is required in `plugin` command. Use e.g. `plugin SSLPlugin.ls.so ssl_plugin`. SSLPlugin is supported since 0.9.6. Some proxy types (e.g. SOCKSv5 UDPASSCOC, SOCKSv5 BIND functionality, ftp proxy) require access to ephemeral port, you may use e.g. -`-network host` mode or `-P` for `docker run`.
|
||||
|
||||
since 0.9.6 images are distroless (except :busybox) it's recommended to use with read only file system, there are no benefits from chroot. For compatibility, you still can use chroot installation by mounting directory with 3proxy.cfg to /usr/local/3proxy/config.
|
||||
since 0.9.6 images are distroless (except :lts-busybox) it's recommended to use with read only file system, there are no benefits from chroot. For compatibility, you still can use chroot installation by mounting directory with 3proxy.cfg to /usr/local/3proxy/config.
|
||||
|
||||
### Busybox image (`:busybox`):
|
||||
### Busybox image (`:lts-busybox`):
|
||||
|
||||
`full` with busybox added, to allow `sh` and few more commands like `sed` inside container. All libraries are in /lib, so chroot configuration can not use plugins.
|
||||
|
||||
### Interactive `:minimal` image:
|
||||
### Interactive `:lts-minimal` image:
|
||||
|
||||
Dockerfile for "interactive" minimal 3proxy execution, no configuration mounting is required, configuration
|
||||
is accepted from stdin. Use `end` command to indicate the end of configuration. Use `log` for stdout logging.
|
||||
@@ -76,7 +115,7 @@ since 0.9.6 images are distroless (except :busybox) it's recommended to use with
|
||||
|
||||
Run example:
|
||||
|
||||
`docker run --read-only -i -p 3129:3129 --name 3proxy docker.io/3proxy/3proxy:minimal`
|
||||
`docker run --read-only -i -p 3129:3129 --name 3proxy docker.io/3proxy/3proxy:lts-minimal`
|
||||
or
|
||||
`docker start -ai 3proxy` to start existing container
|
||||
|
||||
@@ -92,7 +131,7 @@ end
|
||||
|
||||
Some proxy types (e.g. SOCKSv5 UDPASSCOC, SOCKSv5 BIND functionality, ftp proxy) require access to ephemeral port, you may use e.g. `--network host` mode or `-P` to `docker run`.
|
||||
|
||||
`:minimal` without version specified uses current stable version.
|
||||
`:lts-minimal` without version specified uses current 0.9 LTS version.
|
||||
|
||||
## Building and installation
|
||||
|
||||
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
| Version | Supported |
|
||||
| ------- | ------------------ |
|
||||
| 0.9.8 | :white_check_mark: |
|
||||
| < 0.9.8 | :x: |
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
Report to 3proxy@3proxy.org or via [GitHub security reporting](https://github.com/3proxy/3proxy/security)
|
||||
|
||||
For High/Critical patched version is released within 2 weeks
|
||||
|
||||
## Verifying downloads
|
||||
|
||||
Release binaries and the source tarball are published with SHA256 checksums, an
|
||||
OpenPGP signature and a GitHub build provenance attestation.
|
||||
|
||||
The release signing key is `3proxy-release-key.asc` in the root of this
|
||||
repository, an RSA-4096 key:
|
||||
|
||||
```
|
||||
pub rsa4096 2026-08-21 [SC]
|
||||
FC12 2144 99FC C7BA 1CFF 6CDC 0312 384E 3A73 940B
|
||||
uid 3proxy release signing <3proxy@3proxy.org>
|
||||
```
|
||||
|
||||
Import it once:
|
||||
|
||||
```
|
||||
gpg --import 3proxy-release-key.asc
|
||||
```
|
||||
|
||||
Checksums and the checksum file signature:
|
||||
|
||||
```
|
||||
gpg --verify SHA256SUMS-x86_64.asc SHA256SUMS-x86_64
|
||||
sha256sum -c SHA256SUMS-x86_64
|
||||
```
|
||||
|
||||
The source tarball published with each release is signed as well:
|
||||
|
||||
```
|
||||
gpg --verify SHA256SUMS-src.asc SHA256SUMS-src
|
||||
sha256sum -c SHA256SUMS-src
|
||||
gpg --verify 3proxy-0.9.9.tar.gz.asc 3proxy-0.9.9.tar.gz
|
||||
```
|
||||
|
||||
Prefer it over the `Source code (tar.gz)` link GitHub generates automatically:
|
||||
only the published tarball is signed. It is produced with `git archive` from
|
||||
the release tag, so it can be regenerated and compared byte for byte.
|
||||
|
||||
RPM packages are signed, the signature is checked by rpm itself:
|
||||
|
||||
```
|
||||
sudo rpm --import 3proxy-release-key.asc
|
||||
rpm -K 3proxy-0.9.9.x86_64.rpm
|
||||
```
|
||||
|
||||
DEB packages are published with a detached signature:
|
||||
|
||||
```
|
||||
gpg --verify 3proxy-0.9.9.x86_64.deb.asc 3proxy-0.9.9.x86_64.deb
|
||||
```
|
||||
|
||||
Build provenance (which workflow, commit and runner produced the file) is
|
||||
verified with the GitHub CLI:
|
||||
|
||||
```
|
||||
gh attestation verify 3proxy-0.9.9.x86_64.rpm --owner 3proxy
|
||||
gh attestation verify oci://docker.io/3proxy/3proxy:lts --owner 3proxy
|
||||
```
|
||||
Vendored
+36
@@ -1,3 +1,39 @@
|
||||
3proxy (0.9.9.4-1) buster; urgency=medium
|
||||
|
||||
*3proxy 0.9.9.4 initial build
|
||||
|
||||
-- z3APA3A <3apa3a@3proxy.org> Sat, 21 Nov 2026 09:18:43 +0000
|
||||
|
||||
3proxy (0.9.9.3-1) buster; urgency=medium
|
||||
|
||||
*3proxy 0.9.9.3 initial build
|
||||
|
||||
-- z3APA3A <3apa3a@3proxy.org> Sat, 07 Nov 2026 09:14:32 +0000
|
||||
|
||||
3proxy (0.9.9.2-1) buster; urgency=medium
|
||||
|
||||
*3proxy 0.9.9.2 initial build
|
||||
|
||||
-- z3APA3A <3apa3a@3proxy.org> Sat, 24 Oct 2026 12:03:57 +0000
|
||||
|
||||
3proxy (0.9.9.1-1) buster; urgency=medium
|
||||
|
||||
*3proxy 0.9.9.1 initial build
|
||||
|
||||
-- z3APA3A <3apa3a@3proxy.org> Sat, 10 Oct 2026 16:57:17 +0000
|
||||
|
||||
3proxy (0.9.9.0-1) buster; urgency=medium
|
||||
|
||||
*3proxy 0.9.9.0 initial build
|
||||
|
||||
-- z3APA3A <3apa3a@3proxy.org> Thu, 20 Aug 2026 19:12:35 +0300
|
||||
|
||||
3proxy (0.9.9-1) buster; urgency=medium
|
||||
|
||||
*3proxy 0.9.9 initial build
|
||||
|
||||
-- z3APA3A <3apa3a@3proxy.org> Thu, 20 Aug 2026 18:29:37 +0300
|
||||
|
||||
3proxy (0.9.8-1) buster; urgency=medium
|
||||
|
||||
*3proxy 0.9.8 initial build
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
! Fix: DNS replies are validated now: a reply from an address other than the nameserver the query was sent to, and a reply with a question section not matching the query, are dropped; both were accepted before
|
||||
! Fix: socket leak with SOCKSv5 UDP ASSOCIATE through a parent proxy, sockets were accumulated in CLOSE_WAIT state until descriptors ran out
|
||||
! Fix: file descriptor leak in HTTP proxy on the ftp:// request path
|
||||
! Fix: crash with illegal instruction on some platforms (e.g. some musl based Linux builds), caused by a memcpy on overlapping buffers
|
||||
! Fix: extip and ha (HAProxy PROXY protocol) parents are applied to SOCKSv5 UDP ASSOCIATE now
|
||||
! Fix: only socks5 and socks5+ parents are tried for UDP ASSOCIATE, other parent types can not be used for UDP
|
||||
! Fix: udppm through a SOCKSv5 parent did not work
|
||||
! Fix: -Ne and -Ni options were never applied, the option letter was not parsed; -Ne is not applied to the UDP ASSOCIATE reply anymore, -Ni is applied to it
|
||||
! Fix: -4 / -6 handling for UDP in socks; a single UDP association can use both IPv4 and IPv6 destinations now
|
||||
! Fix: a datagram with a null destination address is dropped now
|
||||
! Fix: DNS over TCP: a reply which did not fit a single read was never processed
|
||||
! Documentation: "How to apply ACLs to UDP traffic" added to HOWTO; authentication cache, ACL and UDP notes added to "Optimizing 3proxy for High Load" and to security recommendations
|
||||
+ SOCKSv5 UDP: the destination of every datagram is authorized, so ACLs limiting the destination address, host name or port apply to UDP traffic now; the parent proxy and the external address are selected for the destination of the datagram and not for the UDP ASSOCIATE request
|
||||
+ socks: -U option to control what happens when the destination changes within an UDP association: log it, authorize it, both (default) or neither
|
||||
+ -C option (for TCP services) to terminate the session as soon as any of the sides closes the connection; by default the session is kept until both sides close it (TCP half-close)
|
||||
+ timeouts: LINGER value added (11th, default 5), used to deliver buffered data after one of the sides has closed its sending side and as SO_LINGER value on outgoing connections
|
||||
@@ -0,0 +1,12 @@
|
||||
! Fix: crash (segmentation fault) on configuration reload (SIGUSR1) on a busy server: a closing session could still use its service after the reload had freed it; the race existed since 0.9.7, the 5 second linger added in 0.9.9 made it much more likely (#1278)
|
||||
! Fix: -Di and -De (bind to interface) were not applied to SOCKSv5 UDP ASSOCIATE and BIND sockets, the FTP proxy data connection and connect back (#1277)
|
||||
! Fix: SOCKSv5 UDP ASSOCIATE over IPv6: the source address of a datagram was truncated and the reply was sent to the wrong address (#1279)
|
||||
! Fix: SOCKSv5 UDP ASSOCIATE: an access rule with host names matched any datagram sent to a literal address; the address is used as the host name now, as it is for TCP requests
|
||||
! Fix: buffer could be insufficient for the headers the HTTP proxy adds after a pcre_rewrite had grown the request
|
||||
! Fix: heap buffer overflow in pcre_rewrite: a $N reference to a group which did not match was written out as its digits, which the space allocated for the result did not count
|
||||
! Fix: pcre_extend did nothing, the rules it appended were never consulted
|
||||
! Fix: certificates generated for TLS MitM (openssl) carried no subject and authority key identifiers and were refused by strict verifiers, including macOS clients, OpenSSL with x509_strict and Python 3.13
|
||||
! Fix: null pointer dereference in ftppr on PASS without USER and in smtpp on a user name without a host
|
||||
! Fix: no service started with wolfSSL on glibc: the default thread stack was too small for wolfSSL thread-local storage, pthread_create() failed and the failure was not reported
|
||||
! Fix: dnspr did not work on Windows, the socket it answers from could not be bound
|
||||
- Windows binaries are no longer signed with a self-signed Authenticode certificate, it gave no trust and triggered antivirus false positives
|
||||
@@ -0,0 +1,14 @@
|
||||
! Fix: dnspr relayed to the client whatever came first to the socket it asked the name server from, from any address and under any id, so a forged answer could be passed on; the query now goes out under a random id, and only an answer from the name server asked, with that id and the same question, is relayed
|
||||
! Fix: a client sending a part of a TLS record and then nothing kept a thread taking all of a CPU, and the read never timed out
|
||||
! Fix: without -Ne, the reply to SOCKS CONNECT and BIND gave the address of the client's connection to the proxy instead of the socket towards the destination: a BIND client was told the proxy's own port and the peer could never reach it (since 0.9.6)
|
||||
! Fix: a client which shut down its sending side (half-close) could get the answer cut short, megabytes short with large answers; likewise an upload after the server half-closed
|
||||
! Fix: with chroot every local time was UTC and every syslog message was lost: the time zone is loaded and syslog connected before chroot; the chroot entry of 3proxy.cfg(5) lists what PAM, LDAP and ODBC still need inside the chroot
|
||||
! Fix: the HTTP proxy closed the server connection of a kept-alive client and opened another one when only the request method changed (a POST after a GET to the same host)
|
||||
! Fix: the last ssl_client_mode in the configuration applied to every service, and a reload changed it for the services still running
|
||||
! Fix: memory leaks: on every refused configuration reload, on every failed TLS handshake, the server CA paths of every TLS service
|
||||
! Fix: Unix sockets: on Linux a proxy listening on a Unix socket relayed only the first bytes of an answer (result 95); an abstract socket (unix:@NAME) was bound under a name padded with zeros, which clients did not reach; tcppm refused port 0 for a unix: target, as given in the manual's example; on a reload the socket file of a listening service was removed
|
||||
! Fix: SIGPIPE could kill 3proxy when a client was gone while services were starting, and standalone services (proxy, socks, ...) at any time; sends use MSG_NOSIGNAL where the system has it
|
||||
! Fix: TLS MitM failed for every connection with wolfSSL built with WOLFSSL_QT (wolfSSL 5.9.1 of Ubuntu 26.04): the source certificate's serial number could not be copied; a serial number made from the hash of the source certificate is used then
|
||||
! Fix: Windows: closing a connection could leave its socket open (SO_LINGER on a non-blocking socket) or reset it while the peer still sent, so the end of an answer could be lost
|
||||
! Fix: standalone port mappers (tcppm, udppm, tlspr) built with CMake were built as if they were not port mappers
|
||||
- splice() is built by default on Linux again and is used only by services given -s
|
||||
@@ -0,0 +1,10 @@
|
||||
! Fix: RADIUS authentication: the reply digest copied the shared secret right after the received bytes, so a reply of 4100 bytes with a secret of 17 or more characters wrote up to 47 bytes of it past the reply buffer on the stack, before the reply was authenticated; the digest is hashed over the reply and the secret in place now, with nothing written past the reply, and a reply is taken only from the address and port of the server the request went to, with the request's identifier and length, which was never checked before
|
||||
! Fix: the PTR answer of a name server could write past the answer buffer on the stack: the label walk ran to the end of the whole message instead of the end of the record's data and could take a compression pointer for a label length (an answer of 3841 bytes or more reached past the buffer itself); the walk now stops at the end of the record's data, and a compressed, empty or truncated name is not accepted
|
||||
! Fix: every connection matching a pcre: (or regex:) rule matched on the one match data block of the rule, which pcre2_match() writes into: two connections matching at the same time raced and corrupted memory, bringing the process down under load; a connection now makes a match data block of its own
|
||||
! Fix: TLS: a read which could only be done once a write was, or a write once a read was (a TLS 1.3 key update answered while the socket cannot take more, for example), ended the connection with an error; each TLS socket remembers now what its pending read and write wait for, and the poll of the TLS layer waits for that
|
||||
! Fix: Windows: a TLS read or write which wanted the socket again was not seen as one and dropped the connection with an unrelated error: the C library's errno was set where the socket error is read
|
||||
! Fix: a client of a connect back (-R) service stayed in accept() for the connection another client of the same service took, until the next one came, past its time out and through a configuration reload; the connect back socket is non-blocking now, and an accept() with nothing to take does not count as one of the client's tries
|
||||
! Fix: ftppr: the answer of a server which logs in on USER alone (230, as anonymous FTP often does) or refuses the login was read but never handed to the client, which was left waiting for the answer to its PASS until the time out (#1284)
|
||||
! Fix: plugins: StringsPlugin, cutting a string table line at its end, wrote NULs past the line, into what the buffer kept of longer lines read before or past its end; FilePlugin passed the TLS state of the connection where the client's parameters were expected, so sending a string table over a TLS connection read a TLS state as a clientparam
|
||||
+ -B (for TCP services but admin) splits the TLS ClientHello passed through tlspr in the middle of the server name (SNI), so DPI systems which do not reassemble it do not see the host name; use it with -ocTCP_NODELAY -osTCP_NODELAY, or the kernel may join the segments again; -s keeps the same effect where -s is not splice (#1283)
|
||||
+ An outgoing connection bound to an external address is bound with IP_BIND_ADDRESS_NO_PORT on Linux 4.2 and later: the port is chosen by connect() for the pair with the destination, so ports in use towards other destinations or closing in TIME_WAIT do not run the ephemeral range out; bind() no longer failed with result 12 or searched long for a port under many connections
|
||||
@@ -0,0 +1,8 @@
|
||||
! Fix: socks: a SOCKS4a request was refused as a connect to the null address, although in SOCKS4a the null address means that the destination is the name which follows it
|
||||
! Fix: auth: a UDP ASSOCIATE is pre-authorized without looking at the destination its rules depend on, so its verdict holds for that association alone and is not kept for later requests
|
||||
! Fix: socks: a UDP association was relayed direct when its parent failed, although the rules demanded the parent; it is refused now
|
||||
! Fix: socks: a host name with control bytes or spaces in it was taken as it stood; it is refused where it is read now
|
||||
! Fix: smtpp: a login name of a port alone, without a host, set the port but named no destination to connect to; such a login is refused now
|
||||
! Fix: proxy: the credentials of an earlier request on a kept-alive connection decided for the requests after it; every request is authorized by its own credentials now
|
||||
! Fix: tlspr: a TLS ServerHello too short for the extensions length it declared was read past its end; it is refused now (#1286)
|
||||
! Fix: pcre: a rule with no ACL was handed to the filters as the connection's data, which they read as a match data block and freed: a pointer into the configuration, dereferenced as another type and given back to malloc; a rule without an ACL now skips the check and goes on with a block of its own
|
||||
+174
-6
@@ -428,13 +428,181 @@ use 3proxy's built-in resolver (nserver / nscache / nscache6).
|
||||
Public resolvers like those from Google have rate limits. For a large number of
|
||||
requests, install a local caching recursor (ISC bind named, PowerDNS recursor, etc).
|
||||
|
||||
<h4>Avoid Large Lists</h4>
|
||||
<h4>Use the Authentication Cache</h4>
|
||||
|
||||
Currently, 3proxy is not optimized to use large ACLs, user lists, etc. All lists
|
||||
are processed linearly. In the devel version, you can use RADIUS authentication to avoid
|
||||
user lists and ACLs in 3proxy itself. Also, RADIUS allows you to easily set an outgoing IP
|
||||
on a per-user basis or implement more sophisticated logic.
|
||||
RADIUS is a new beta feature; test it before using it in production.
|
||||
Authentication and authorization are performed for every request. Password
|
||||
lookup itself is a hash lookup and is cheap, but the ACL is walked linearly,
|
||||
and with RADIUS or plugin authentication every request costs a network round
|
||||
trip. 'authcache' keeps the result of a successful authentication for a number
|
||||
of seconds:
|
||||
<pre>
|
||||
authcache <cachetype> <cachetime> <cachesize>
|
||||
</pre>
|
||||
'cachetype' lists the fields the entry is keyed by, 'cachetime' is the lifetime
|
||||
in seconds, and the optional 'cachesize' limits the number of entries. The
|
||||
cached type must be placed before the real authentication type in the 'auth'
|
||||
command: a cache miss falls through to the next type in the chain, and a hit
|
||||
skips it.
|
||||
|
||||
<p>There are two cached types:
|
||||
<ul>
|
||||
<li>'cache' caches the authentication only; the ACL is still checked on every
|
||||
request. Use it when ACLs must take effect immediately, or when the
|
||||
authentication method returns per-user parameters that the authorization step
|
||||
has to apply.
|
||||
<li>'cacheacl' also caches the authorization result, so the ACL is not walked
|
||||
at all on a hit. This is the one that helps with long ACLs, but the key must
|
||||
cover every field the ACL limits, and it can not be used with redirections.
|
||||
</ul>
|
||||
|
||||
<p><b>'cacheacl' does not work with parent proxies.</b> Redirections are applied
|
||||
while the ACL is walked, so on a 'cacheacl' hit no redirection happens at all:
|
||||
the request is sent directly instead of through the 'parent' proxy of the
|
||||
matching ACL entry, and nothing is reported. The first request for a given key
|
||||
uses the parent and the rest do not, which makes it look intermittent. Use
|
||||
'cache' with parent proxies:
|
||||
<pre>
|
||||
authcache user,pass 60
|
||||
auth cache strong
|
||||
allow user1
|
||||
parent 1000 socks5 10.0.0.1 1080
|
||||
proxy
|
||||
</pre>
|
||||
The one exception is 'parent ... extip': the external address is stored in the
|
||||
cache entry and restored on a hit, but only if 'ext' is a part of the key:
|
||||
<pre>
|
||||
authcache user,pass,ext 60
|
||||
auth cacheacl strong
|
||||
allow user1
|
||||
parent 1000 extip 1.2.3.4 0
|
||||
proxy
|
||||
</pre>
|
||||
Without 'ext' in the key the external address falls back to the default one on
|
||||
every cache hit.
|
||||
|
||||
<p><b>The key must match the ACL.</b> On a 'cacheacl' hit the cached result is
|
||||
reused as is, so any field the ACL limits but the key does not contain makes
|
||||
the cached result apply to a request it was not computed for. Use 'user' and
|
||||
'pass' for the userlist, 'ip' for the sourcelist, 'dstaddr' and 'dsthost' for
|
||||
the targetlist, 'dstport' for the targetportlist and 'dstoper' for the
|
||||
operationlist. For this ACL:
|
||||
<pre>
|
||||
allow user1,user2 * * 80,443
|
||||
deny *
|
||||
</pre>
|
||||
the key needs 'user', 'pass' and 'dstport':
|
||||
<pre>
|
||||
users $/etc/3proxy/passwd
|
||||
authcache user,pass,dstport 60 65536
|
||||
auth cacheacl strong
|
||||
allow user1,user2 * * 80,443
|
||||
deny *
|
||||
proxy
|
||||
</pre>
|
||||
|
||||
<p>With RADIUS the round trip is the expensive part, so cache by whatever
|
||||
identifies the client:
|
||||
<pre>
|
||||
radius secret 1.2.3.4
|
||||
authcache ip,user,pass 600
|
||||
auth cache radius
|
||||
proxy
|
||||
</pre>
|
||||
'cache' rather than 'cacheacl' is used here because RADIUS may return per-user
|
||||
parameters such as the outgoing IP; add 'ext' to the key to cache the external
|
||||
address returned by RADIUS as well.
|
||||
|
||||
<p>Choose 'cachetime' to balance the load against how quickly a password or ACL
|
||||
change has to take effect. Cache entries are <b>not</b> invalidated by a
|
||||
configuration reload, so a long lifetime keeps applying the old decision to
|
||||
existing keys after the new configuration is loaded.
|
||||
|
||||
<p>Note that 'ip' alone, or 'ip,user' without 'pass', assigns every connection
|
||||
from the same address to the same user for the lifetime of the entry without
|
||||
checking the password. That is a deliberate trade-off for high load; do not use
|
||||
it where clients share addresses.
|
||||
|
||||
<h4>Tune UDP Destination Handling with '-U'</h4>
|
||||
|
||||
Within a SOCKSv5 UDP association the destination is taken from every datagram,
|
||||
so 3proxy authorizes and logs every new destination. One association can reach
|
||||
any number of destinations: a DNS forwarder produces one record, but a
|
||||
peer-to-peer or QUIC client can produce hundreds, each costing an authorization
|
||||
(a network round trip with RADIUS or plugin authentication) and a log record.
|
||||
The 'socks' service option '-U' controls this:
|
||||
<pre>
|
||||
socks -U3 # default: log and authorize every new destination
|
||||
socks -U2 # authorize, do not log
|
||||
socks -U1 # log, do not authorize
|
||||
socks -U0 # neither (same as bare -U)
|
||||
</pre>
|
||||
The destination of the first datagram is always authorized and logged, so the
|
||||
association as a whole is still subject to ACLs, authentication and the choice
|
||||
of the parent proxy.
|
||||
|
||||
<p>Before reaching for the option, note that the cost is already avoided when no
|
||||
ACL entry reachable by the client limits the destination: in that case the
|
||||
result can not depend on the destination and no re-authorization is performed
|
||||
whatever '-U' says. '-U' only matters for configurations that do limit the
|
||||
destination.
|
||||
|
||||
<p>For high load:
|
||||
<ul>
|
||||
<li><b>'-U2'</b> is the safe one. Destination ACLs keep working, only the
|
||||
per-destination log records are dropped. Use it when log volume, not CPU, is
|
||||
the problem.
|
||||
<li><b>'-U' ('-U0')</b> removes both costs and is the fastest, but destination
|
||||
ACLs then apply only to the first destination of each association, and the
|
||||
parent proxy and external address chosen for it are kept for the whole
|
||||
association. Use it when UDP destinations are not restricted anyway, or when
|
||||
the restriction is enforced elsewhere (a firewall, or the parent proxy).
|
||||
<li>Keep the default '-U3' when destination ACLs are a security boundary, and
|
||||
make the authorization itself cheap with 'authcache' instead, see "Use the
|
||||
Authentication Cache" above.
|
||||
</ul>
|
||||
|
||||
<h4>Avoid Large ACLs</h4>
|
||||
|
||||
Most of the large data structures are hash tables and scale to a large number of
|
||||
records: the user list loaded by 'users' (including the '$/path/to/file' form),
|
||||
the authentication cache ('authcache'), the DNS cache ('nscache'/'nscache6') and
|
||||
the client table of the UDP portmapper. Their size is not a concern.
|
||||
|
||||
<p>The ACL is the exception and is still processed linearly. Every request walks
|
||||
the access list entry by entry until one matches, and within an entry the
|
||||
userlist, the sourcelist, the targetlist and the targetportlist are walked
|
||||
linearly as well, so the cost is roughly the number of entries multiplied by the
|
||||
size of the lists inside them. The 'bandlimin'/'bandlimout' and
|
||||
'countin'/'countout' rules are separate lists of the same kind and are walked on
|
||||
every request in addition to the access list.
|
||||
|
||||
<p>Two things follow from this:
|
||||
<ul>
|
||||
<li>Order matters. The walk stops at the first matching entry, so put the
|
||||
entries that match most of the traffic first.
|
||||
<li>Prefer fewer, wider entries over many narrow ones. One entry with a long
|
||||
userlist is cheaper than one entry per user, because the outer walk is repeated
|
||||
for every entry while the inner list is only walked for entries that got that
|
||||
far.
|
||||
</ul>
|
||||
|
||||
<p>With a large ACL, cache the authorization result instead of shortening the
|
||||
list. 'cacheacl' walks the ACL once per cache entry rather than once per
|
||||
request:
|
||||
<pre>
|
||||
users $/etc/3proxy/passwd
|
||||
authcache user,pass,dstaddr,dstport 60 65536
|
||||
auth cacheacl strong
|
||||
</pre>
|
||||
Both limitations from "Use the Authentication Cache" above apply: the cache key
|
||||
must contain every field the ACL limits, and 'cacheacl' must not be used
|
||||
together with parent proxies. Where a parent proxy is required, plain 'cache'
|
||||
still removes the authentication cost but leaves the ACL walk on every request.
|
||||
|
||||
<p>RADIUS moves the user list and the ACLs out of 3proxy entirely, and also
|
||||
allows you to set an outgoing IP on a per-user basis or to implement more
|
||||
sophisticated logic. RADIUS is a new beta feature; test it before using it in
|
||||
production.
|
||||
|
||||
<h4>Avoid Changing Configuration Too Often</h4>
|
||||
|
||||
|
||||
+81
-3
@@ -646,13 +646,13 @@ see <a href="#DNSPR">How to set up a DNS proxy (dnspr)</a>.
|
||||
<br>tlspr can be used as a parent with the "tls" type to implement SNI splitting for DPI bypass (similar to NoDPI/GoodByeDPI).
|
||||
The client sends the first part of the TLS ClientHello, tlspr splits it at the SNI extension and sends it in two TCP packets,
|
||||
which can bypass some DPI systems that look for blocked hostnames in TLS handshakes.
|
||||
<br>To enable SNI break, use <code>parent ... tls 0.0.0.0 0</code> and the <code>-s</code> option on the listening service with TCP_NODELAY:
|
||||
<br>To enable SNI break, use <code>parent ... tls 0.0.0.0 0</code> and the <code>-B</code> option on the listening service with TCP_NODELAY:
|
||||
</p><pre>
|
||||
auth iponly
|
||||
allow *
|
||||
parent 1000 tls 0.0.0.0 0
|
||||
allow *
|
||||
proxy -s -i127.0.0.1 -ocTCP_NODELAY -osTCP_NODELAY -p1443
|
||||
proxy -B -i127.0.0.1 -ocTCP_NODELAY -osTCP_NODELAY -p1443
|
||||
</pre>
|
||||
<p>
|
||||
TCP_NODELAY is required to prevent the kernel from merging the split packets.
|
||||
@@ -1338,6 +1338,82 @@ the second hop is 192.168.20.1, and the 3rd one is either 192.168.30.1 with a pr
|
||||
of 30% or 192.168.40.1 with a probability of 70%.
|
||||
</p>
|
||||
|
||||
<li><a name="UDPACL">How to apply ACLs to UDP traffic</a>
|
||||
<p>
|
||||
A SOCKSv5 UDP ASSOCIATE request only asks 3proxy to open a relay port, it
|
||||
carries no destination. The destination is taken from every datagram the client
|
||||
sends afterwards, so a single association may reach any number of destinations.
|
||||
3proxy authorizes the destination of every datagram, so ACLs limiting the
|
||||
destination address, host name or port do apply to UDP traffic.
|
||||
</p>
|
||||
<p>
|
||||
Differences from TCP:
|
||||
</p>
|
||||
<ul>
|
||||
<li>A datagram to a denied destination is dropped, the association is not
|
||||
terminated.
|
||||
<li>The parent proxy and the external address are selected for the destination
|
||||
of the datagram and not for the ASSOCIATE request, and are re-established if a
|
||||
later destination selects another ACL entry. Only <code>socks5</code> and
|
||||
<code>socks5+</code> parents can be used for UDP.
|
||||
<li>ACLs are checked for the datagrams sent by the client only. A datagram
|
||||
received on the association is relayed to the client without an ACL check: with
|
||||
a parent proxy only the datagrams from the parent are accepted, an association
|
||||
without a parent accepts a datagram from any source. The source reported to the
|
||||
client is the actual source of the datagram. The address in the log record is the destination the
|
||||
client sent the datagrams to, the source of the received datagrams is not
|
||||
logged.
|
||||
<li>A client may use a single association to reach many destinations. An ACL
|
||||
entry which limits the destination silently drops the datagrams to every other
|
||||
destination, so limiting the destination of UDP traffic can break such clients
|
||||
in a way which is hard to diagnose. Limit it only when it is really required.
|
||||
<li>Bandwidth limiters and traffic counters which limit the destination are
|
||||
selected when the destination is authorized, so they are selected for the
|
||||
destination of the first datagram and are not re-selected for every following
|
||||
destination. They can not be applied per destination to incoming UDP traffic at
|
||||
all.
|
||||
<li>Every change of the destination host name, address or port is authorized
|
||||
again and logged. Use <code>nscache</code> for host names and the
|
||||
authentication cache for anything more expensive than 'iponly'. The
|
||||
<code>-U</code> option of the <code>socks</code> service turns the logging
|
||||
and/or the re-authorization off; with <code>-U0</code> or <code>-U1</code>
|
||||
only the first destination of an association is authorized.
|
||||
</ul>
|
||||
<p>
|
||||
Limit the destinations a client may send datagrams to:
|
||||
</p><pre>
|
||||
auth iponly
|
||||
allow * * 8.8.8.8 53
|
||||
deny *
|
||||
socks -p1080
|
||||
</pre>
|
||||
<p>
|
||||
The ASSOCIATE request succeeds, datagrams to 8.8.8.8:53 are relayed, datagrams
|
||||
to any other destination are dropped.
|
||||
</p>
|
||||
<p>
|
||||
The same with 'strong' (or RADIUS, or plugin) authentication, where every new
|
||||
destination would otherwise be authenticated again:
|
||||
</p><pre>
|
||||
users user1:CL:password
|
||||
authcache user,pass,dstaddr,dstport 60
|
||||
auth cacheacl strong
|
||||
allow user1 * 8.8.8.8 53
|
||||
deny *
|
||||
socks -p1080
|
||||
</pre>
|
||||
<p>
|
||||
With 'cacheacl' the ACL result is not re-evaluated on a cache hit, so every
|
||||
field the ACL limits must be a part of the cache key: 'user' and 'pass' for the
|
||||
userlist, 'dstaddr' and 'dstport' for the targetlist and the targetportlist,
|
||||
'ip' for the sourcelist, 'dsthost' for host names in the targetlist, 'dstoper'
|
||||
for the operationlist. Without the destination in the key the result cached for
|
||||
one destination is applied to any other destination and the destination is not
|
||||
checked at all. Use plain 'cache' instead of 'cacheacl' if ACLs may change
|
||||
during the cache lifetime, or if a parent proxy is used: on a 'cacheacl' hit
|
||||
the ACL is not walked, so no parent proxy is selected and datagrams are sent
|
||||
directly.
|
||||
</p>
|
||||
<li><A NAME="BANDLIM">How to limit bandwidth</a>
|
||||
<p>
|
||||
3proxy supports bandwidth filters. Use the bandlimin/bandlimout and
|
||||
@@ -1395,10 +1471,12 @@ allowed traffic in megabytes (MB). nocountin allows you to set exclusions.
|
||||
For name resolution and caching, use the commands nserver, nscache / nscache6, and nsrecord.
|
||||
<pre>
|
||||
nserver 192.168.1.2
|
||||
nserver 192.168.1.3:5353/tcp</pre>
|
||||
nserver 192.168.1.3:5353/tcp
|
||||
nserver [2001:4860:4860::8844]</pre>
|
||||
sets DNS resolvers. 192.168.1.3 will be used via TCP/5353 (instead of default UDP/53)
|
||||
only if 192.168.1.2 fails. Up to 5 nservers may be specified.
|
||||
If no nserver is configured, default system name resolution functions are used.
|
||||
An IPv6 address has to be written in square brackets.
|
||||
<pre>
|
||||
nscache 65535
|
||||
nscache6 65535</pre>
|
||||
|
||||
+84
-3
@@ -654,13 +654,13 @@ iptables -t nat -A PREROUTING -p tcp -m multiport --dports 443,993,465 -j REDIRE
|
||||
<br>tlspr может использоваться как родительский прокси типа "tls" для реализации SNI-фрагментации (аналог NoDPI/GoodByeDPI).
|
||||
Клиент отправляет первую часть TLS ClientHello, tlspr разбивает его на расширении SNI и отправляет двумя TCP-пакетами,
|
||||
что позволяет обойти некоторые DPI-системы, ищущие заблокированные имена хостов в TLS-рукопожатиях.
|
||||
<br>Для включения SNI break используйте <code>parent ... tls 0.0.0.0 0</code> и опцию <code>-s</code> на слушающем сервисе с TCP_NODELAY:
|
||||
<br>Для включения SNI break используйте <code>parent ... tls 0.0.0.0 0</code> и опцию <code>-B</code> на слушающем сервисе с TCP_NODELAY:
|
||||
</p><pre>
|
||||
auth iponly
|
||||
allow *
|
||||
parent 1000 tls 0.0.0.0 0
|
||||
allow *
|
||||
proxy -s -i127.0.0.1 -ocTCP_NODELAY -osTCP_NODELAY -p1443
|
||||
proxy -B -i127.0.0.1 -ocTCP_NODELAY -osTCP_NODELAY -p1443
|
||||
</pre>
|
||||
<p>
|
||||
TCP_NODELAY необходим, чтобы ядро не объединяло разделенные пакеты.
|
||||
@@ -1371,6 +1371,85 @@ pcre_extend deny * 192.168.0.1/16
|
||||
192.168.10.1, второе - 192.168.20.1, а третье - либо 192.168.30.1 с
|
||||
вероятностью 0.3 либо 192.168.40.1 с вероятностью 0.7
|
||||
</p>
|
||||
<li><a name="UDPACL"><i>Как применять ACL к UDP трафику</i></a>
|
||||
<p>
|
||||
Запрос SOCKSv5 UDP ASSOCIATE лишь просит 3proxy открыть порт для ретрансляции
|
||||
и не содержит адреса назначения. Адрес назначения берется из каждой
|
||||
датаграммы, отправленной клиентом, поэтому одна ассоциация может обращаться
|
||||
к любому числу адресов назначения. 3proxy авторизует адрес назначения каждой
|
||||
датаграммы, поэтому ACL, ограничивающие адрес, имя хоста или порт
|
||||
назначения, применяются и к UDP трафику.
|
||||
</p>
|
||||
<p>
|
||||
Отличия от TCP:
|
||||
</p>
|
||||
<ul>
|
||||
<li>Датаграмма к запрещенному адресу назначения отбрасывается, ассоциация
|
||||
при этом не завершается.
|
||||
<li>Вышестоящий прокси и внешний адрес выбираются для адреса назначения
|
||||
датаграммы, а не для запроса ASSOCIATE, и устанавливаются заново, если
|
||||
последующий адрес назначения соответствует другой записи ACL. Для UDP
|
||||
могут использоваться только родители типа <code>socks5</code> и
|
||||
<code>socks5+</code>.
|
||||
<li>ACL проверяются только для датаграмм, отправленных клиентом. Датаграмма,
|
||||
полученная в рамках ассоциации, передается клиенту без проверки ACL: при
|
||||
использовании вышестоящего прокси принимаются только датаграммы от него, а
|
||||
ассоциация без вышестоящего прокси принимает датаграмму от любого источника.
|
||||
Клиенту сообщается фактический адрес источника датаграммы. В журнал записывается адрес назначения, на который клиент
|
||||
отправлял датаграммы, а не адрес источника полученных датаграмм.
|
||||
<li>Клиент может использовать одну ассоциацию для обращения ко многим адресам
|
||||
назначения. Запись ACL, ограничивающая адрес назначения, молча отбрасывает
|
||||
датаграммы ко всем остальным адресам назначения, поэтому ограничение адреса
|
||||
назначения для UDP может нарушить работу таких клиентов, и причину трудно
|
||||
установить. Ограничивайте его, только если это действительно необходимо.
|
||||
<li>Ограничители полосы и счетчики трафика, ограничивающие адрес назначения,
|
||||
выбираются при авторизации адреса назначения, поэтому они выбираются для
|
||||
адреса назначения первой датаграммы и не выбираются заново для каждого
|
||||
последующего адреса назначения. К входящему UDP трафику они не могут быть
|
||||
применены по адресу назначения вообще.
|
||||
<li>Каждое изменение имени хоста, адреса или порта назначения
|
||||
авторизуется заново и записывается в журнал. Используйте <code>nscache</code>
|
||||
для имен хостов и кэш аутентификации для всего, что дороже 'iponly'. Опция
|
||||
<code>-U</code> сервиса <code>socks</code> отключает журналирование и/или
|
||||
повторную авторизацию; при <code>-U0</code> или <code>-U1</code>
|
||||
авторизуется только первый адрес назначения ассоциации.
|
||||
</ul>
|
||||
<p>
|
||||
Ограничить адреса назначения, куда клиент может отправлять датаграммы:
|
||||
</p><pre>
|
||||
auth iponly
|
||||
allow * * 8.8.8.8 53
|
||||
deny *
|
||||
socks -p1080
|
||||
</pre>
|
||||
<p>
|
||||
Запрос ASSOCIATE выполняется успешно, датаграммы к 8.8.8.8:53 передаются,
|
||||
датаграммы к любому другому адресу назначения отбрасываются.
|
||||
</p>
|
||||
<p>
|
||||
То же самое с аутентификацией 'strong' (или RADIUS, или через плагин), при
|
||||
которой иначе каждый новый адрес назначения аутентифицировался бы заново:
|
||||
</p><pre>
|
||||
users user1:CL:password
|
||||
authcache user,pass,dstaddr,dstport 60
|
||||
auth cacheacl strong
|
||||
allow user1 * 8.8.8.8 53
|
||||
deny *
|
||||
socks -p1080
|
||||
</pre>
|
||||
<p>
|
||||
При 'cacheacl' результат проверки ACL не вычисляется заново при попадании
|
||||
в кэш, поэтому каждое поле, ограничиваемое в ACL, должно входить в ключ
|
||||
кэша: 'user' и 'pass' для списка пользователей, 'dstaddr' и 'dstport' для списка
|
||||
адресов и списка портов назначения, 'ip' для списка источников, 'dsthost'
|
||||
для имен хостов в списке назначения, 'dstoper' для списка операций. Без
|
||||
адреса назначения в ключе результат, закэшированный для одного адреса
|
||||
назначения, применяется к любому другому, и адрес назначения не
|
||||
проверяется вообще. Используйте 'cache' вместо 'cacheacl', если ACL могут
|
||||
изменяться в течение времени жизни кэша или если используется вышестоящий
|
||||
прокси: при попадании в кэш 'cacheacl' обход ACL не выполняется, поэтому
|
||||
вышестоящий прокси не выбирается и датаграммы отправляются напрямую.
|
||||
</p>
|
||||
<li><a name="BANDLIM"><i>Как ограничивать скорости приема</i></a>
|
||||
<p>
|
||||
3proxy позволяет устанавливать фильтры ширины потребляемого канала. Для этого
|
||||
@@ -1457,11 +1536,13 @@ pcre_extend deny * 192.168.0.1/16
|
||||
nscache и nsrecord.
|
||||
<pre>
|
||||
nserver 192.168.1.2
|
||||
nserver 192.168.1.3:5353/tcp</pre>
|
||||
nserver 192.168.1.3:5353/tcp
|
||||
nserver [2001:4860:4860::8844]</pre>
|
||||
указывает 3proxy какие машины следует использвоать в качестве серверов
|
||||
DNS. Сервер 192.168.1.3 будет использоваться по порту TCP/5353 (вместо дефолтного UDP/53) только при недостижимости
|
||||
192.168.1.2. Можно указать до 5 серверов. Если nserver не указан, будут
|
||||
использованы системные функции разрешения имен.
|
||||
Адрес IPv6 необходимо записывать в квадратных скобках.
|
||||
<pre>
|
||||
nscache 65535
|
||||
nscache6 65535</pre>
|
||||
|
||||
+112
-15
@@ -216,12 +216,34 @@ 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 TCP services, Linux) enable splice(). It is built on
|
||||
Linux by default, but off unless -s is given: splice() is
|
||||
faster for large transfers and the read/write path for small
|
||||
requests. -s0 disables it explicitly; build without
|
||||
-DWITHSPLICE to leave it out. <b><br>
|
||||
-C</b> <br>
|
||||
(for TCP services) a connection closed by any of the sides
|
||||
terminates the session, buffered data is delivered before
|
||||
the sockets are closed. By default the session is kept until
|
||||
both sides close the connection (TCP half-close). Half-close
|
||||
is required for the protocols where one of the sides closes
|
||||
its sending side and expects the answer, but it keeps the
|
||||
socket of the side which has already closed the connection
|
||||
in CLOSE_WAIT state. Use -C to close both sockets as soon as
|
||||
any of the sides closes the connection, -C1 to request the
|
||||
default behaviour explicitly. <b><br>
|
||||
-U</b><i>[MODE]</i> <br>
|
||||
(for socks) what to do when the destination changes within
|
||||
an UDP association: <b>1</b> - log it, <b>2</b> - authorize
|
||||
it, <b>3</b> - both, the default, <b>0</b> (same as bare
|
||||
<b>-U</b>) - neither. The destination of the first datagram
|
||||
is always authorized and logged. With <b>-U0</b> and
|
||||
<b>-U1</b> the destination is not authorized again, so ACLs
|
||||
limiting the destination only apply to the first destination
|
||||
of the association, and the parent proxy and the external
|
||||
address selected for it are kept for the whole association.
|
||||
Use <b>-U2</b> to keep the authorization and to drop the
|
||||
per-destination log records only. <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
|
||||
@@ -400,9 +422,9 @@ and %F as filename.</p>
|
||||
<i><BYTE_SHORT> <BYTE_LONG> <STRING_SHORT>
|
||||
<STRING_LONG> <CONNECTION_SHORT>
|
||||
<CONNECTION_LONG> <DNS> <CHAIN>
|
||||
<CONNECT> <CONNECTBACK></i> <br>
|
||||
<CONNECT> <CONNECTBACK> <LINGER></i> <br>
|
||||
Sets timeout values, defaults 1, 5, 30, 60, 180, 1800, 15,
|
||||
60, 15, 5. <b><br>
|
||||
60, 15, 5, 5. <b><br>
|
||||
BYTE_SHORT</b> short timeout for single byte, is usually
|
||||
used for receiving single byte from stream. <b><br>
|
||||
BYTE_LONG</b> long timeout for single byte, is usually used
|
||||
@@ -419,8 +441,13 @@ CONNECTION_LONG</b> inactivity timeout for long connection
|
||||
DNS</b> timeout for DNS request before requesting next
|
||||
server <b><br>
|
||||
CHAIN</b> timeout for reading data from chained connection
|
||||
<br>
|
||||
default timeouts 1 5 30 60 180 1800 15 60 15 5</p>
|
||||
<b><br>
|
||||
LINGER</b> timeout to deliver buffered data after one of the
|
||||
sides has closed its sending side, also used as SO_LINGER
|
||||
value on outgoing connections. Too small value may cause the
|
||||
tail of the data to be lost on slow connections, too large
|
||||
one delays release of the sockets. <br>
|
||||
default timeouts 1 5 30 60 180 1800 15 60 15 5 5</p>
|
||||
|
||||
<p style="margin-left:6%; margin-top: 1em"><b>maxseg</b>
|
||||
<i><value></i> <br>
|
||||
@@ -461,7 +488,11 @@ experimental.</p>
|
||||
Nameserver to use for name resolutions. If none specified
|
||||
system routines for name resolution is used. Optional port
|
||||
number may be specified. If optional /tcp is added to IP
|
||||
address, name resolution is performed over TCP.</p>
|
||||
address, name resolution is performed over TCP. An IPv6 address
|
||||
has to be enclosed in square brackets: <br>
|
||||
<b>nserver 1.1.1.1</b> <br>
|
||||
<b>nserver [2001:4860:4860::8844]</b> <br>
|
||||
<b>nserver [2001:4860:4860::8844]:5353/tcp</b></p>
|
||||
|
||||
|
||||
<p style="margin-left:6%; margin-top: 1em"><b>authnserver</b>
|
||||
@@ -584,7 +615,15 @@ but the ACL authorization result is also cached and not
|
||||
re-evaluated on each request. Faster than <b>cache</b>, but
|
||||
ACL changes do not take effect for cached users until the
|
||||
cache entry expires. Use <b>cache</b> if ACLs may change
|
||||
during the cache lifetime. <b><br>
|
||||
during the cache lifetime. Because the ACL is not walked on
|
||||
a cache hit, no redirection is applied to a request served
|
||||
from the cache: it is sent directly instead of through the
|
||||
<b>parent</b> proxy of the matching ACL entry, with no error
|
||||
reported. Do not use <b>cacheacl</b> together with parent
|
||||
proxies, use <b>cache</b> instead. The only redirection type
|
||||
which survives is <b>extip</b>, and only if <b>ext</b> is a
|
||||
part of the <b>authcache</b> key, because the external
|
||||
address is then restored from the cache entry. <b><br>
|
||||
radius</b> - authentication with RADIUS. <br>
|
||||
Plugins may add additional authentication types.</p>
|
||||
|
||||
@@ -631,6 +670,19 @@ srvaddr</b> - cache by service (listener) address <b><br>
|
||||
srvport</b> - cache by service (listener) port <br>
|
||||
Multiple types can be combined (e.g.
|
||||
<b>ip,user,dstaddr,dstport</b>). <br>
|
||||
With <b>cacheacl</b> the ACL result is not re-evaluated on a
|
||||
cache hit, so every field the ACL limits must be a part of
|
||||
the cache key, otherwise the result cached for one request
|
||||
is applied to a different one: <b>user</b>/<b>pass</b> for
|
||||
the userlist, <b>ip</b> for the sourcelist,
|
||||
<b>dstaddr</b>/<b>dsthost</b> for the targetlist,
|
||||
<b>dstport</b> for the targetportlist and <b>dstoper</b> for
|
||||
the operationlist. It is especially important for SOCKSv5
|
||||
UDP traffic, where the destination of every datagram is
|
||||
authorized: without <b>dstaddr</b> and <b>dstport</b> in the
|
||||
key the result cached for one destination is applied to any
|
||||
other destination and the destination is not checked at all,
|
||||
see <b>allow</b>. <br>
|
||||
Use auth type <b>cache</b> (or <b>cacheacl</b>) for cached
|
||||
authentication</p>
|
||||
|
||||
@@ -699,8 +751,45 @@ week day numbers or periods, 0 or 7 means Sunday, 1 is
|
||||
Monday, 1-5 means Monday through Friday. <br>
|
||||
Timeperiodlists is a list of time periods in
|
||||
HH:MM:SS-HH:MM:SS format. For example,
|
||||
00:00:00-08:00:00,17:00:00-24:00:00 lists non-working
|
||||
hours.</p>
|
||||
00:00:00-08:00:00,17:00:00-24:00:00 lists non-working hours.
|
||||
<br>
|
||||
A SOCKSv5 UDP ASSOCIATE request carries no destination, the
|
||||
destination of every datagram is taken from the datagram
|
||||
itself. 3proxy authorizes the destination of every datagram,
|
||||
so ACLs limiting the destination address, the destination
|
||||
host name or the destination port do apply to UDP traffic,
|
||||
unless the <b>-U</b> option of the <b>socks</b> service says
|
||||
otherwise. <br>
|
||||
ACLs are only checked for the datagrams sent by the client.
|
||||
A datagram received on the association is relayed to the
|
||||
client without an ACL check: with a parent proxy only the
|
||||
datagrams from the parent are accepted, an association
|
||||
without a parent accepts a datagram from any source. The
|
||||
source reported to the client is the actual source of the
|
||||
datagram. The address in the log record is the destination
|
||||
the client sent the datagrams to, the source of the
|
||||
datagrams received on the association is not logged. <br>
|
||||
A client may use a single association to reach many
|
||||
destinations. An ACL entry which limits the destination
|
||||
silently drops the datagrams to every other destination, so
|
||||
limiting the destination of UDP traffic can break such
|
||||
clients in a way which is hard to diagnose. Limit it only
|
||||
when it is really required. <br>
|
||||
Bandwidth limiters (<b>bandlimin</b>, <b>bandlimout</b>) and
|
||||
traffic counters (<b>countin</b>, <b>countout</b>) which
|
||||
limit the destination are selected when the destination is
|
||||
authorized, so within an UDP association they are selected
|
||||
for the destination of the first datagram and are not
|
||||
re-selected for every following destination. They can not be
|
||||
applied per destination to the incoming UDP traffic at all,
|
||||
because an incoming datagram is not matched against any
|
||||
destination. <br>
|
||||
Only <b>socks5</b> and <b>socks5+</b> parents can be used
|
||||
for UDP. Because every new destination is authorized, use
|
||||
<b>authcache</b>, especially with ´strong´,
|
||||
RADIUS or plugin authentication: <b>cacheacl</b> with the
|
||||
destination in the cache key if no parent proxy is used,
|
||||
<b>cache</b> otherwise, see <b>cacheacl</b>.</p>
|
||||
|
||||
<p style="margin-left:6%; margin-top: 1em"><b>parent</b>
|
||||
<i><weight> <type> <ip> <port>
|
||||
@@ -1047,7 +1136,15 @@ groupname. Unix only.</p>
|
||||
[<i><gid></i>] <br>
|
||||
calls chroot(path) and sets gid/uid. Unix only. uid/gid
|
||||
supported since 0.9, can be numeric or
|
||||
username/groupname</p>
|
||||
username/groupname. The time zone and the syslog connection
|
||||
are set up before the call.
|
||||
Plugins which read their own configuration or load modules
|
||||
while running need them inside the chroot: PAM
|
||||
(<i>/etc/pam.d</i> and the modules it names, read for every
|
||||
authentication), LDAP (<i>ldap.conf</i> and, for ldaps, the
|
||||
CA certificates), ODBC (<i>odbc.ini</i>, <i>odbcinst.ini</i>
|
||||
and the driver libraries, loaded again whenever the
|
||||
connection is reopened).</p>
|
||||
|
||||
|
||||
<p style="margin-left:6%; margin-top: 1em"><b>stacksize</b>
|
||||
|
||||
@@ -25,6 +25,26 @@ with an unreachable DNS server (because gethostbyname will block other threads).
|
||||
user requests can be logged.
|
||||
<li>Use -xyz+A character filtering sequences for 'logformat', especially with
|
||||
ODBC logging, to prevent SQL and log record injections.
|
||||
<li>With the 'cacheacl' authentication type the ACL result is cached and is not
|
||||
re-evaluated on a cache hit, so every field the ACL limits must be a part of
|
||||
the 'authcache' key. Any field the ACL limits but the key does not contain
|
||||
makes the cached result apply to a request it was not computed for, and that
|
||||
limitation is not enforced. Use 'user' and 'pass' for the userlist, 'ip' for
|
||||
the sourcelist, 'dstaddr' and 'dsthost' for the targetlist, 'dstport' for the
|
||||
targetportlist and 'dstoper' for the operationlist. Use plain 'cache' instead
|
||||
of 'cacheacl' if ACLs may change during the cache lifetime; cache entries are
|
||||
not invalidated by a configuration reload.
|
||||
<li>'cacheacl' must not be used together with parent proxies. The ACL is not
|
||||
walked on a cache hit, so no redirection is applied and the request is sent
|
||||
directly instead of through the 'parent' proxy of the matching ACL entry,
|
||||
without any error. If the parent proxy is the only sanctioned path to the
|
||||
network, this silently bypasses it. Use 'cache' instead. 'parent ... extip'
|
||||
is the only redirection which survives, and only if 'ext' is a part of the
|
||||
'authcache' key.
|
||||
<li>The destination of every datagram of a SOCKSv5 UDP association is
|
||||
authorized, but only with the default '-U3' (or '-U2') of the 'socks' service.
|
||||
With '-U0' or '-U1' only the first destination of an association is authorized,
|
||||
so ACLs limiting the destination do not restrict the rest of the association.
|
||||
<li>Immediately report all service crashes to the developers.
|
||||
<li>Participate in code audit :)
|
||||
</ul>
|
||||
|
||||
+110
-11
@@ -190,15 +190,41 @@ any protocol-specific data.
|
||||
.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 -B
|
||||
(for TCP services) split the TLS ClientHello across two TCP segments in the
|
||||
middle of the server name (SNI) when it is passed through tlspr, as with
|
||||
\fBparent ... tls 0.0.0.0 0\fR: some DPI systems looking for blocked host names
|
||||
do not reassemble it. Use with \fB-ocTCP_NODELAY -osTCP_NODELAY\fR, or the kernel
|
||||
may join the segments again. In builds without splice() \fB-s\fR does the same.
|
||||
.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.
|
||||
(for TCP services, Linux) enable splice(). It is built on Linux by default,
|
||||
but off unless -s is given: splice() is faster for large transfers and the
|
||||
read/write path for small requests. -s0 disables it explicitly; build without
|
||||
-DWITHSPLICE to leave it out.
|
||||
.br
|
||||
.B -C
|
||||
(for TCP services) a connection closed by any of the sides terminates the
|
||||
session, buffered data is delivered before the sockets are closed. By default
|
||||
the session is kept until both sides close the connection (TCP half-close).
|
||||
Half-close is required for the protocols where one of the sides closes its
|
||||
sending side and expects the answer, but it keeps the socket of the side which
|
||||
has already closed the connection in CLOSE_WAIT state. Use -C to close both
|
||||
sockets as soon as any of the sides closes the connection, -C1 to request
|
||||
the default behaviour explicitly.
|
||||
.br
|
||||
.B -U\fI[MODE]\fR
|
||||
(for socks) what to do when the destination changes within an UDP association:
|
||||
\fB1\fR - log it, \fB2\fR - authorize it, \fB3\fR - both, the default,
|
||||
\fB0\fR (same as bare \fB-U\fR) - neither. The destination of the first datagram
|
||||
is always authorized and logged. With \fB-U0\fR and \fB-U1\fR the destination is
|
||||
not authorized again, so ACLs limiting the destination only apply to the first
|
||||
destination of the association, and the parent proxy and the external address
|
||||
selected for it are kept for the whole association. Use \fB-U2\fR to keep the
|
||||
authorization and to drop the per-destination log records only.
|
||||
.br
|
||||
(for dnspr) simple, do not use resolver and 3proxy cache, always use external DNS server.
|
||||
.br
|
||||
@@ -427,9 +453,9 @@ can use %A as produced archive name and %F as filename.
|
||||
|
||||
.br
|
||||
.BR timeouts
|
||||
\fI<BYTE_SHORT>\fR \fI<BYTE_LONG>\fR \fI<STRING_SHORT>\fR \fI<STRING_LONG>\fR \fI<CONNECTION_SHORT>\fR \fI<CONNECTION_LONG>\fR \fI<DNS>\fR \fI<CHAIN>\fR \fI<CONNECT>\fR \fI<CONNECTBACK>\fR
|
||||
\fI<BYTE_SHORT>\fR \fI<BYTE_LONG>\fR \fI<STRING_SHORT>\fR \fI<STRING_LONG>\fR \fI<CONNECTION_SHORT>\fR \fI<CONNECTION_LONG>\fR \fI<DNS>\fR \fI<CHAIN>\fR \fI<CONNECT>\fR \fI<CONNECTBACK>\fR \fI<LINGER>\fR
|
||||
.br
|
||||
Sets timeout values, defaults 1, 5, 30, 60, 180, 1800, 15, 60, 15, 5.
|
||||
Sets timeout values, defaults 1, 5, 30, 60, 180, 1800, 15, 60, 15, 5, 5.
|
||||
.br
|
||||
\fBBYTE_SHORT\fR short timeout for single byte, is usually used for receiving single byte from stream.
|
||||
.br
|
||||
@@ -447,7 +473,12 @@ can use %A as produced archive name and %F as filename.
|
||||
.br
|
||||
\fBCHAIN\fR timeout for reading data from chained connection
|
||||
.br
|
||||
default timeouts 1 5 30 60 180 1800 15 60 15 5
|
||||
\fBLINGER\fR timeout to deliver buffered data after one of the sides has closed
|
||||
its sending side, also used as SO_LINGER value on outgoing connections. Too small
|
||||
value may cause the tail of the data to be lost on slow connections, too large one
|
||||
delays release of the sockets.
|
||||
.br
|
||||
default timeouts 1 5 30 60 180 1800 15 60 15 5 5
|
||||
|
||||
.br
|
||||
.BR maxseg
|
||||
@@ -462,7 +493,10 @@ network conditions.
|
||||
\fI<NAS_SECRET>\fR \fI<radius_server_1\fR[:\fIport\fR][/\fIlocal_address_1\fR]\fR \fI<radius_server_2\fR[:\fIport\fR][/\fIlocal_address_2\fR]\fR
|
||||
.br
|
||||
Configures RADIUS servers to be used for logging and authentication (log and auth types
|
||||
must be set to radius). port and local address to use with given server may be specified.
|
||||
must be set to radius). A server is a name or an address, resolved when the
|
||||
configuration is read. port and local address to use with given server may be specified:
|
||||
the port named is the one authentication is asked on, and the accounting requests of
|
||||
the same server go to the port after it (1812 and 1813 by default).
|
||||
.br
|
||||
Attributes within request: User-Name, Password: (username and password if presented by client),
|
||||
Service Type: Authenticate-Only,
|
||||
@@ -486,9 +520,18 @@ Use \fBauthcache\fR to speedup authentication. RADIUS feature is currently exper
|
||||
.br
|
||||
Nameserver to use for name resolutions. If none specified
|
||||
system routines for name resolution is
|
||||
used. Optional port number may be specified.
|
||||
used. A server that answers with an error (FORMERR, SERVFAIL, REFUSED
|
||||
and the like) is passed over for the next one, while a name answered
|
||||
with no data, or as not there, ends the search. Optional port number may be specified.
|
||||
If optional /tcp is added to IP address, name resolution is
|
||||
performed over TCP.
|
||||
An IPv6 address has to be enclosed in square brackets:
|
||||
.br
|
||||
\fBnserver 1.1.1.1\fR
|
||||
.br
|
||||
\fBnserver [2001:4860:4860::8844]\fR
|
||||
.br
|
||||
\fBnserver [2001:4860:4860::8844]:5353/tcp\fR
|
||||
|
||||
.br
|
||||
.BR authnserver
|
||||
@@ -623,6 +666,13 @@ SOCKSv5, FTP, POP3 and HTTP proxy.
|
||||
authorization result is also cached and not re-evaluated on each request. Faster
|
||||
than \fBcache\fR, but ACL changes do not take effect for cached users until the
|
||||
cache entry expires. Use \fBcache\fR if ACLs may change during the cache lifetime.
|
||||
Because the ACL is not walked on a cache hit, no redirection is applied to a
|
||||
request served from the cache: it is sent directly instead of through the
|
||||
\fBparent\fR proxy of the matching ACL entry, with no error reported. Do not use
|
||||
\fBcacheacl\fR together with parent proxies, use \fBcache\fR instead. The only
|
||||
redirection type which survives is \fBextip\fR, and only if \fBext\fR is a part
|
||||
of the \fBauthcache\fR key, because the external address is then restored from
|
||||
the cache entry.
|
||||
.br
|
||||
\fBradius\fR - authentication with RADIUS.
|
||||
.br
|
||||
@@ -678,6 +728,17 @@ assigned to the same user without actual authentication.
|
||||
.br
|
||||
Multiple types can be combined (e.g. \fBip,user,dstaddr,dstport\fR).
|
||||
.br
|
||||
With \fBcacheacl\fR the ACL result is not re-evaluated on a cache hit, so every
|
||||
field the ACL limits must be a part of the cache key, otherwise the result
|
||||
cached for one request is applied to a different one: \fBuser\fR/\fBpass\fR
|
||||
for the userlist, \fBip\fR for the sourcelist, \fBdstaddr\fR/\fBdsthost\fR
|
||||
for the targetlist, \fBdstport\fR for the targetportlist and \fBdstoper\fR
|
||||
for the operationlist. It is especially important for SOCKSv5 UDP traffic,
|
||||
where the destination of every datagram is authorized: without \fBdstaddr\fR
|
||||
and \fBdstport\fR in the key the result cached for one destination is applied
|
||||
to any other destination and the destination is not checked at all, see
|
||||
\fBallow\fR.
|
||||
.br
|
||||
Use auth type \fBcache\fR (or \fBcacheacl\fR) for cached authentication
|
||||
|
||||
.br
|
||||
@@ -762,6 +823,39 @@ non-privileged (1024-65535) ports on the remote side.
|
||||
.br
|
||||
Timeperiodlists is a list of time
|
||||
periods in HH:MM:SS-HH:MM:SS format. For example, 00:00:00-08:00:00,17:00:00-24:00:00 lists non-working hours.
|
||||
.br
|
||||
A SOCKSv5 UDP ASSOCIATE request carries no destination, the destination of
|
||||
every datagram is taken from the datagram itself. 3proxy authorizes the
|
||||
destination of every datagram, so ACLs limiting the destination address, the
|
||||
destination host name or the destination port do apply to UDP traffic, unless
|
||||
the \fB-U\fR option of the \fBsocks\fR service says otherwise.
|
||||
.br
|
||||
ACLs are only checked for the datagrams sent by the client. A datagram received
|
||||
on the association is relayed to the client without an ACL check: with a parent
|
||||
proxy only the datagrams from the parent are accepted, an association without a
|
||||
parent accepts a datagram from any source. The source reported to the client is
|
||||
the actual source of the datagram. The address in the log record is the destination the
|
||||
client sent the datagrams to, the source of the datagrams received on the
|
||||
association is not logged.
|
||||
.br
|
||||
A client may use a single association to reach many destinations. An ACL entry
|
||||
which limits the destination silently drops the datagrams to every other
|
||||
destination, so limiting the destination of UDP traffic can break such clients
|
||||
in a way which is hard to diagnose. Limit it only when it is really required.
|
||||
.br
|
||||
Bandwidth limiters (\fBbandlimin\fR, \fBbandlimout\fR) and traffic counters
|
||||
(\fBcountin\fR, \fBcountout\fR) which limit the destination are selected when
|
||||
the destination is authorized, so within an UDP association they are selected
|
||||
for the destination of the first datagram and are not re-selected for every
|
||||
following destination. They can not be applied per destination to the incoming
|
||||
UDP traffic at all, because an incoming datagram is not matched against any
|
||||
destination.
|
||||
.br
|
||||
Only \fBsocks5\fR and \fBsocks5+\fR parents can be used for UDP. Because
|
||||
every new destination is authorized, use \fBauthcache\fR, especially with
|
||||
\'strong\', RADIUS or plugin authentication: \fBcacheacl\fR with the
|
||||
destination in the cache key if no parent proxy is used, \fBcache\fR
|
||||
otherwise, see \fBcacheacl\fR.
|
||||
|
||||
.br
|
||||
.BR parent
|
||||
@@ -1171,7 +1265,12 @@ for all threads.
|
||||
.BR chroot
|
||||
\fI<path>\fR [\fI<uid>\fR] [\fI<gid>\fR]
|
||||
.br
|
||||
calls chroot(path) and sets gid/uid. Unix only. uid/gid supported since 0.9, can be numeric or username/groupname
|
||||
calls chroot(path) and sets gid/uid. Unix only. uid/gid supported since 0.9, can be numeric or username/groupname.
|
||||
The time zone and the syslog connection are set up before the call.
|
||||
Plugins which read their own configuration or load modules while running need them inside the chroot:
|
||||
PAM (\fI/etc/pam.d\fR and the modules it names, read for every authentication),
|
||||
LDAP (\fIldap.conf\fR and, for ldaps, the CA certificates),
|
||||
ODBC (\fIodbc.ini\fR, \fIodbcinst.ini\fR and the driver libraries, loaded again whenever the connection is reopened).
|
||||
|
||||
.br
|
||||
.BR stacksize
|
||||
|
||||
+2
-2
@@ -76,8 +76,8 @@ destination_port. Port to establish outgoing connections. Required unless the Tr
|
||||
.B -c
|
||||
TLS_CHECK_LEVEL. 0 (default) - allow non-TLS traffic to pass, 1 - require TLS, only check client HELLO packet, 2 - require TLS, check both client and server HELLO, 3 - require TLS, check that the server sends a certificate (not compatible with TLS 1.3), 4 - require mutual TLS, check that the server sends a certificate request and the client sends a certificate (not compatible with TLS 1.3)
|
||||
.TP
|
||||
.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.
|
||||
.B -B
|
||||
Split the TLS Client HELLO packet across two TCP segments, in the middle of the SNI, to make SNI-based DPI detection harder. In builds without splice() \fB-s\fR does the same; with splice() (Linux) \fB-s\fR is splice, see \fB3proxy.cfg\fR(5).
|
||||
.TP
|
||||
.B -Ximap | -Xpop3 | -Xsmtp
|
||||
STARTTLS mode for the given protocol. The proxy speaks the plaintext protocol
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
#
|
||||
# Copyright (C) 2026 3proxy.org
|
||||
#
|
||||
# This is free software, licensed under the BSD 3-Clause License.
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=3proxy
|
||||
PKG_VERSION:=0.9.9.0
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
# A trailing ? tells the download helper the URL is complete and PKG_SOURCE
|
||||
# must not be appended to it.
|
||||
PKG_SOURCE_URL:=https://codeload.github.com/3proxy/3proxy/tar.gz/refs/tags/$(PKG_VERSION)?
|
||||
PKG_HASH:=5af253fa734f61af6d5fe3790022130a14caf25bfce24a6aefd415797d351dd3
|
||||
|
||||
PKG_MAINTAINER:=Vladimir Dubrovin <vlad@3proxy.org>
|
||||
PKG_LICENSE:=BSD-3-Clause
|
||||
PKG_LICENSE_FILES:=copying
|
||||
PKG_CPE_ID:=cpe:/a:3proxy:3proxy
|
||||
|
||||
PKG_BUILD_PARALLEL:=1
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/3proxy
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
SUBMENU:=Web Servers/Proxies
|
||||
TITLE:=tiny free proxy server
|
||||
URL:=https://3proxy.org/
|
||||
DEPENDS:=+libopenssl +libpcre2
|
||||
endef
|
||||
|
||||
define Package/3proxy/description
|
||||
3proxy is a tiny free proxy server supporting HTTP, HTTPS, FTP, SOCKS v4/v4a/v5,
|
||||
POP3, SMTP, IMAP, TCP and UDP port mapping, with access control, bandwidth
|
||||
limiting and traffic accounting.
|
||||
endef
|
||||
|
||||
define Package/3proxy/conffiles
|
||||
/etc/config/3proxy
|
||||
endef
|
||||
|
||||
# Makefile.Linux appends to CFLAGS and LDFLAGS internally; the target flags have
|
||||
# to be added rather than substituted, or the defines it relies on are lost.
|
||||
define Build/Compile
|
||||
$(MAKE) -C $(PKG_BUILD_DIR) -f Makefile.Linux \
|
||||
CC="$(TARGET_CC)" \
|
||||
EXTRA_CFLAGS="$(TARGET_CFLAGS) $(TARGET_CPPFLAGS)" \
|
||||
EXTRA_LDFLAGS="$(TARGET_LDFLAGS)" \
|
||||
PLUGINS=
|
||||
endef
|
||||
|
||||
define Package/3proxy/install
|
||||
$(INSTALL_DIR) $(1)/usr/bin
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/bin/3proxy $(1)/usr/bin/3proxy
|
||||
$(INSTALL_DIR) $(1)/etc/config
|
||||
$(INSTALL_CONF) ./files/3proxy.config $(1)/etc/config/3proxy
|
||||
$(INSTALL_DIR) $(1)/etc/init.d
|
||||
$(INSTALL_BIN) ./files/3proxy.init $(1)/etc/init.d/3proxy
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,3proxy))
|
||||
@@ -0,0 +1,59 @@
|
||||
config 3proxy 'global'
|
||||
option enabled '0'
|
||||
option nscache '65536'
|
||||
# option nscache6 '65536'
|
||||
# static records, added to the cache; 0.0.0.0 blackholes a name
|
||||
# list nsrecord 'ads.example.com 0.0.0.0'
|
||||
option maxconn '128'
|
||||
option auth 'iponly'
|
||||
option log 'syslog'
|
||||
# option timeouts '1 5 30 60 180 1800 15 60 15 5 5'
|
||||
# list include '/etc/3proxy/extra.cfg'
|
||||
list nserver '8.8.8.8'
|
||||
list nserver '8.8.4.4'
|
||||
# list user 'admin:CL:password'
|
||||
# list extra_config 'timeouts 1 5 30 60 180 1800 15 60'
|
||||
# access list used by services which do not define their own
|
||||
list acl 'lan'
|
||||
|
||||
# Access rules are named sections referenced by services. The order of the
|
||||
# references decides precedence: 3proxy stops at the first rule that matches.
|
||||
config acl 'lan'
|
||||
option action 'allow'
|
||||
option src '192.168.1.0/24'
|
||||
|
||||
config acl 'deny_private'
|
||||
option action 'deny'
|
||||
option dst '10.0.0.0/8,172.16.0.0/12,192.168.0.0/16'
|
||||
|
||||
#config acl 'via_upstream'
|
||||
# option action 'allow'
|
||||
# list parent 'upstream'
|
||||
|
||||
# Parent proxies extend an allow rule to build a chain. Weights group them:
|
||||
# parents whose weights sum to 1000 form one group and one is picked at random,
|
||||
# several groups are chained in order.
|
||||
#config parent 'upstream'
|
||||
# option weight '1000'
|
||||
# option type 'socks5'
|
||||
# option ip '10.0.0.1'
|
||||
# option port '1080'
|
||||
# option username ''
|
||||
# option password ''
|
||||
|
||||
config service 'proxy'
|
||||
option enabled '0'
|
||||
option type 'proxy'
|
||||
option port '3128'
|
||||
# option bind ''
|
||||
# option external ''
|
||||
# option extra ''
|
||||
# option auth 'strong'
|
||||
list acl 'deny_private'
|
||||
list acl 'lan'
|
||||
|
||||
config service 'socks'
|
||||
option enabled '0'
|
||||
option type 'socks'
|
||||
option port '1080'
|
||||
list acl 'lan'
|
||||
@@ -0,0 +1,460 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=50
|
||||
USE_PROCD=1
|
||||
|
||||
CFGFILE=/var/etc/3proxy.cfg
|
||||
PROG=/usr/bin/3proxy
|
||||
|
||||
# 3proxy.cfg is order dependent: authentication and access rules apply to the
|
||||
# service lines that follow them, and the access list has to be flushed before
|
||||
# each service. The file is written as one global block followed by one block
|
||||
# per service.
|
||||
|
||||
acl_written=0
|
||||
|
||||
append_line() {
|
||||
echo "$1" >> "$CFGFILE"
|
||||
}
|
||||
|
||||
append_include() {
|
||||
echo "include $1" >> "$CFGFILE"
|
||||
}
|
||||
|
||||
# The limiter directives carry their own ACL pattern rather than attaching to a
|
||||
# preceding allow rule, and 3proxy defaults every omitted field to *, so the
|
||||
# trailing wildcards are dropped again to keep the file readable.
|
||||
# logformat takes a single argument, so a format containing spaces has to be
|
||||
# quoted. Quotes already present in the UCI value are not doubled.
|
||||
append_logformat() {
|
||||
local fmt="$1"
|
||||
|
||||
case "$fmt" in
|
||||
'"'*'"') ;;
|
||||
*) fmt="\"$fmt\"" ;;
|
||||
esac
|
||||
|
||||
echo "logformat $fmt" >> "$CFGFILE"
|
||||
}
|
||||
|
||||
limit_match() {
|
||||
local users src dst ports ops weekdays periods out
|
||||
|
||||
config_get users "$1" users '*'
|
||||
config_get src "$1" src '*'
|
||||
config_get dst "$1" dst '*'
|
||||
config_get ports "$1" ports '*'
|
||||
config_get ops "$1" operations '*'
|
||||
config_get weekdays "$1" weekdays '*'
|
||||
config_get periods "$1" timeperiods '*'
|
||||
|
||||
out="$users $src $dst $ports $ops $weekdays $periods"
|
||||
while [ "${out% \*}" != "$out" ]; do out="${out% \*}"; done
|
||||
|
||||
echo "$out"
|
||||
}
|
||||
|
||||
append_limit() {
|
||||
local type rate period number count_type limit match
|
||||
|
||||
config_get type "$1" type
|
||||
|
||||
case "$type" in
|
||||
bandlimin|bandlimout|nobandlimin|nobandlimout|\
|
||||
connlim|noconnlim|\
|
||||
countin|countout|countall|nocountin|nocountout|nocountall) ;;
|
||||
*)
|
||||
echo "3proxy: limit '$1' has unknown type '$type', ignored" >&2
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
match=$(limit_match "$1")
|
||||
|
||||
case "$type" in
|
||||
bandlimin|bandlimout)
|
||||
config_get rate "$1" rate
|
||||
[ -n "$rate" ] || {
|
||||
echo "3proxy: limit '$1' needs a rate, ignored" >&2
|
||||
return 0
|
||||
}
|
||||
echo "$type $rate $match" >> "$CFGFILE"
|
||||
;;
|
||||
connlim)
|
||||
config_get rate "$1" rate
|
||||
config_get period "$1" period 0
|
||||
[ -n "$rate" ] || {
|
||||
echo "3proxy: limit '$1' needs a rate, ignored" >&2
|
||||
return 0
|
||||
}
|
||||
echo "$type $rate $period $match" >> "$CFGFILE"
|
||||
;;
|
||||
countin|countout|countall)
|
||||
config_get number "$1" number
|
||||
config_get count_type "$1" count_type
|
||||
config_get limit "$1" limit
|
||||
[ -n "$number" ] && [ -n "$count_type" ] && [ -n "$limit" ] || {
|
||||
echo "3proxy: limit '$1' needs number, count_type and limit, ignored" >&2
|
||||
return 0
|
||||
}
|
||||
echo "$type $number $count_type $limit $match" >> "$CFGFILE"
|
||||
;;
|
||||
*)
|
||||
echo "$type $match" >> "$CFGFILE"
|
||||
;;
|
||||
esac
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
append_pcre_extend() {
|
||||
echo "pcre_extend $1" >> "$CFGFILE"
|
||||
}
|
||||
|
||||
append_pcre() {
|
||||
local match_type action regexp rewrite ace
|
||||
|
||||
config_get match_type "$1" match_type
|
||||
config_get action "$1" action
|
||||
config_get regexp "$1" regexp
|
||||
config_get rewrite "$1" rewrite
|
||||
config_get ace "$1" ace
|
||||
|
||||
[ -n "$match_type" ] && [ -n "$action" ] && [ -n "$regexp" ] || {
|
||||
echo "3proxy: pcre '$1' needs match_type, action and regexp, ignored" >&2
|
||||
return 0
|
||||
}
|
||||
|
||||
# Catch bad values here: 3proxy rejects the whole configuration on an
|
||||
# unknown type or action, which would leave the router without a proxy.
|
||||
case "$action" in
|
||||
allow|deny|dunno) ;;
|
||||
*)
|
||||
echo "3proxy: pcre '$1' action '$action' is not allow, deny or dunno, ignored" >&2
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
local part
|
||||
for part in $(echo "$match_type" | tr ',' ' '); do
|
||||
case "$part" in
|
||||
request|cliheader|srvheader|clidata|srvdata) ;;
|
||||
*)
|
||||
echo "3proxy: pcre '$1' match_type '$part' is unknown, ignored" >&2
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -n "$rewrite" ]; then
|
||||
echo "pcre_rewrite $match_type $action $regexp $rewrite${ace:+ $ace}" >> "$CFGFILE"
|
||||
else
|
||||
echo "pcre $match_type $action $regexp${ace:+ $ace}" >> "$CFGFILE"
|
||||
fi
|
||||
|
||||
config_list_foreach "$1" extend append_pcre_extend
|
||||
return 0
|
||||
}
|
||||
|
||||
append_nsrecord() {
|
||||
set -- $1
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "3proxy: nsrecord '$*' needs a hostname and an address, ignored" >&2
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "nsrecord $1 $2" >> "$CFGFILE"
|
||||
nsrecord_written=1
|
||||
return 0
|
||||
}
|
||||
|
||||
append_nserver() {
|
||||
echo "nserver $1" >> "$CFGFILE"
|
||||
}
|
||||
|
||||
append_user() {
|
||||
users="$users $1"
|
||||
}
|
||||
|
||||
# $1 is the name of an acl section referenced by a service, or by the global
|
||||
# section as the default access list.
|
||||
append_acl() {
|
||||
local action users src dst ports
|
||||
|
||||
config_get action "$1" action allow
|
||||
config_get users "$1" users
|
||||
config_get src "$1" src
|
||||
config_get dst "$1" dst
|
||||
config_get ports "$1" ports
|
||||
|
||||
case "$action" in
|
||||
allow|deny) ;;
|
||||
*)
|
||||
echo "3proxy: acl '$1' has unknown action '$action', ignored" >&2
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "$action ${users:-*} ${src:-*} ${dst:-*} ${ports:-*}" >> "$CFGFILE"
|
||||
acl_written=1
|
||||
|
||||
if [ "$action" = "allow" ]; then
|
||||
config_list_foreach "$1" parent append_parent
|
||||
else
|
||||
config_get _parent "$1" parent
|
||||
[ -z "$_parent" ] || echo "3proxy: acl '$1' is a deny rule, its parents are ignored" >&2
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# $1 is the name of a parent section referenced by an acl. "parent" extends the
|
||||
# allow rule that precedes it, so these are emitted directly after their rule.
|
||||
append_parent() {
|
||||
local weight type ip port username password line
|
||||
|
||||
config_get weight "$1" weight 1000
|
||||
config_get type "$1" type
|
||||
config_get ip "$1" ip
|
||||
config_get port "$1" port
|
||||
config_get username "$1" username
|
||||
config_get password "$1" password
|
||||
|
||||
[ -n "$type" ] && [ -n "$ip" ] && [ -n "$port" ] || {
|
||||
echo "3proxy: parent '$1' needs type, ip and port, ignored" >&2
|
||||
return 0
|
||||
}
|
||||
|
||||
line="parent $weight $type $ip $port"
|
||||
if [ -n "$username" ]; then
|
||||
line="$line $username"
|
||||
[ -n "$password" ] && line="$line $password"
|
||||
fi
|
||||
|
||||
echo "$line" >> "$CFGFILE"
|
||||
return 0
|
||||
}
|
||||
|
||||
# TLS parameters that take a value. The UCI option name is the directive name.
|
||||
SSL_VALUE_OPTIONS="ssl_server_cert ssl_server_key ssl_client_cert ssl_client_key
|
||||
ssl_client_ciphersuites ssl_server_ciphersuites
|
||||
ssl_client_cipher_list ssl_server_cipher_list
|
||||
ssl_client_min_proto_version ssl_server_min_proto_version
|
||||
ssl_client_max_proto_version ssl_server_max_proto_version
|
||||
ssl_server_ca_file ssl_server_ca_key ssl_server_ca_dir ssl_server_ca_store
|
||||
ssl_client_ca_file ssl_client_ca_dir ssl_client_ca_store
|
||||
ssl_client_sni ssl_client_alpn ssl_client_mode ssl_certcache"
|
||||
|
||||
# The TLS switches apply to every service below them, so they leak from one
|
||||
# service to the next unless turned back off. These track what is currently in
|
||||
# effect - all off, matching the defaults - so a directive is written only when
|
||||
# a service actually needs a different state.
|
||||
ssl_state_mitm=0
|
||||
ssl_state_server=0
|
||||
ssl_state_client=0
|
||||
ssl_state_client_verify=0
|
||||
ssl_state_server_verify=0
|
||||
|
||||
# $1 section, $2 uci option, $3 state variable, $4 directive on, $5 directive off
|
||||
append_ssl_toggle() {
|
||||
local want have
|
||||
|
||||
config_get_bool want "$1" "$2" 0
|
||||
have=$(eval echo \$$3)
|
||||
|
||||
[ "$want" = "$have" ] && return 0
|
||||
|
||||
if [ "$want" -gt 0 ]; then
|
||||
echo "$4" >> "$CFGFILE"
|
||||
else
|
||||
echo "$5" >> "$CFGFILE"
|
||||
fi
|
||||
|
||||
eval "$3=$want"
|
||||
return 0
|
||||
}
|
||||
|
||||
append_ssl() {
|
||||
local opt value mitm server cert key cverify
|
||||
|
||||
for opt in $SSL_VALUE_OPTIONS; do
|
||||
config_get value "$1" "$opt"
|
||||
[ -n "$value" ] && echo "$opt $value" >> "$CFGFILE"
|
||||
done
|
||||
|
||||
append_ssl_toggle "$1" ssl_mitm ssl_state_mitm ssl_mitm ssl_nomitm
|
||||
append_ssl_toggle "$1" ssl_server ssl_state_server ssl_serv ssl_noserv
|
||||
append_ssl_toggle "$1" ssl_client ssl_state_client ssl_cli ssl_nocli
|
||||
append_ssl_toggle "$1" ssl_client_verify ssl_state_client_verify \
|
||||
ssl_client_verify ssl_client_no_verify
|
||||
append_ssl_toggle "$1" ssl_server_verify ssl_state_server_verify \
|
||||
ssl_server_verify ssl_server_no_verify
|
||||
|
||||
config_get_bool mitm "$1" ssl_mitm 0
|
||||
config_get_bool cverify "$1" ssl_client_verify 0
|
||||
[ "$mitm" -gt 0 ] && [ "$cverify" -gt 0 ] || [ "$mitm" -eq 0 ] || \
|
||||
echo "3proxy: service '$1' spoofs certificates without ssl_client_verify, upstream certificates are not checked" >&2
|
||||
|
||||
config_get_bool server "$1" ssl_server 0
|
||||
if [ "$server" -gt 0 ]; then
|
||||
config_get cert "$1" ssl_server_cert
|
||||
config_get key "$1" ssl_server_key
|
||||
[ -n "$cert" ] && [ -n "$key" ] || \
|
||||
echo "3proxy: service '$1' requires TLS from clients but has no ssl_server_cert/ssl_server_key" >&2
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
append_service() {
|
||||
local enabled type port bind external extra auth args
|
||||
local bind_interface external_interface logformat
|
||||
|
||||
config_get_bool enabled "$1" enabled 0
|
||||
[ "$enabled" -gt 0 ] || return 0
|
||||
|
||||
config_get type "$1" type
|
||||
[ -n "$type" ] || {
|
||||
echo "3proxy: service '$1' has no type, ignored" >&2
|
||||
return 0
|
||||
}
|
||||
|
||||
config_get port "$1" port
|
||||
config_get bind "$1" bind
|
||||
config_get external "$1" external
|
||||
config_get extra "$1" extra
|
||||
config_get bind_interface "$1" bind_interface
|
||||
config_get external_interface "$1" external_interface
|
||||
config_get logformat "$1" logformat
|
||||
config_get auth "$1" auth "$global_auth"
|
||||
|
||||
echo "" >> "$CFGFILE"
|
||||
echo "flush" >> "$CFGFILE"
|
||||
[ -n "$auth" ] && echo "auth $auth" >> "$CFGFILE"
|
||||
|
||||
# Rules referenced by the service, in the order they are listed. A service
|
||||
# without its own list falls back to the global one.
|
||||
acl_written=0
|
||||
config_list_foreach "$1" acl append_acl
|
||||
[ "$acl_written" -gt 0 ] || config_list_foreach global acl append_acl
|
||||
|
||||
[ -n "$logformat" ] && append_logformat "$logformat"
|
||||
|
||||
append_ssl "$1"
|
||||
|
||||
args=""
|
||||
[ -n "$port" ] && args="$args -p$port"
|
||||
[ -n "$bind" ] && args="$args -i$bind"
|
||||
[ -n "$external" ] && args="$args -e$external"
|
||||
[ -n "$bind_interface" ] && args="$args -Di$bind_interface"
|
||||
[ -n "$external_interface" ] && args="$args -De$external_interface"
|
||||
[ -n "$extra" ] && args="$args $extra"
|
||||
|
||||
echo "$type$args" >> "$CFGFILE"
|
||||
return 0
|
||||
}
|
||||
|
||||
write_config() {
|
||||
local nscache nscache6 maxconn log timeouts fakeresolve logformat
|
||||
local authcache_type authcache_time authcache_size
|
||||
local counter_file counter_type counter_name pcre_options
|
||||
|
||||
mkdir -p "$(dirname "$CFGFILE")"
|
||||
: > "$CFGFILE"
|
||||
|
||||
config_get nscache global nscache
|
||||
config_get nscache6 global nscache6
|
||||
config_get maxconn global maxconn
|
||||
config_get global_auth global auth iponly
|
||||
config_get log global log syslog
|
||||
config_get timeouts global timeouts
|
||||
config_get logformat global logformat
|
||||
config_get_bool fakeresolve global fakeresolve 0
|
||||
config_get authcache_type global authcache_type
|
||||
config_get authcache_time global authcache_time
|
||||
config_get authcache_size global authcache_size
|
||||
config_get counter_file global counter_file
|
||||
config_get counter_type global counter_type
|
||||
config_get counter_name global counter_name
|
||||
config_get pcre_options global pcre_options
|
||||
|
||||
config_list_foreach global nserver append_nserver
|
||||
[ -n "$nscache" ] && echo "nscache $nscache" >> "$CFGFILE"
|
||||
[ -n "$nscache6" ] && echo "nscache6 $nscache6" >> "$CFGFILE"
|
||||
|
||||
# Static records are added to the cache, so they have to come after it.
|
||||
nsrecord_written=0
|
||||
config_list_foreach global nsrecord append_nsrecord
|
||||
[ "$nsrecord_written" -eq 0 ] || [ -n "$nscache$nscache6" ] || \
|
||||
echo "3proxy: nsrecord needs nscache or nscache6 to be set" >&2
|
||||
|
||||
case "$log" in
|
||||
syslog) echo "log" >> "$CFGFILE" ;;
|
||||
none|"") ;;
|
||||
*) echo "log $log" >> "$CFGFILE" ;;
|
||||
esac
|
||||
|
||||
users=""
|
||||
config_list_foreach global user append_user
|
||||
[ -n "$users" ] && echo "users$users" >> "$CFGFILE"
|
||||
|
||||
[ -n "$timeouts" ] && echo "timeouts $timeouts" >> "$CFGFILE"
|
||||
[ "$fakeresolve" -gt 0 ] && echo "fakeresolve" >> "$CFGFILE"
|
||||
[ -n "$logformat" ] && append_logformat "$logformat"
|
||||
|
||||
if [ -n "$authcache_type" ]; then
|
||||
[ -n "$authcache_time" ] || authcache_time=600
|
||||
echo "authcache $authcache_type $authcache_time${authcache_size:+ $authcache_size}" >> "$CFGFILE"
|
||||
fi
|
||||
|
||||
if [ -n "$counter_file" ]; then
|
||||
echo "counter $counter_file${counter_type:+ $counter_type}${counter_name:+ $counter_name}" >> "$CFGFILE"
|
||||
fi
|
||||
|
||||
[ -n "$pcre_options" ] && echo "pcre_options $pcre_options" >> "$CFGFILE"
|
||||
|
||||
# Both lists are order sensitive: 3proxy stops at the first match, so the
|
||||
# exempting rules (nobandlimin and friends) have to be listed first.
|
||||
config_list_foreach global pcre append_pcre
|
||||
config_list_foreach global limit append_limit
|
||||
|
||||
config_list_foreach global include append_include
|
||||
config_list_foreach global extra_config append_line
|
||||
|
||||
[ -n "$maxconn" ] && echo "maxconn $maxconn" >> "$CFGFILE"
|
||||
|
||||
config_foreach append_service service
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
start_service() {
|
||||
local enabled
|
||||
|
||||
config_load 3proxy
|
||||
config_get_bool enabled global enabled 0
|
||||
|
||||
[ "$enabled" -gt 0 ] || {
|
||||
echo "3proxy is disabled in /etc/config/3proxy" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
write_config
|
||||
|
||||
procd_open_instance
|
||||
procd_set_param command "$PROG" "$CFGFILE"
|
||||
procd_set_param file "$CFGFILE"
|
||||
procd_set_param respawn
|
||||
procd_set_param stdout 1
|
||||
procd_set_param stderr 1
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger "3proxy"
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
stop
|
||||
start
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
Name: 3proxy
|
||||
Version: 0.9.8
|
||||
Version: 0.9.9.4
|
||||
Release: 1%{?dist}
|
||||
Summary: 3proxy tiny proxy server
|
||||
License: GPL/LGPL/Apache/BSD
|
||||
@@ -9,6 +9,9 @@ Prefix: %{_prefix}
|
||||
Packager: z3APA3A
|
||||
Source: https://github.com/%{packager}/%{name}/archive/%{version}.tar.gz
|
||||
|
||||
%global debug_package %{nil}
|
||||
%global __requires_exclude ^/(usr/)?bin/3proxy$
|
||||
|
||||
%description
|
||||
3proxy is lightweight yet powerful proxy server
|
||||
|
||||
|
||||
+6
-2
@@ -298,7 +298,7 @@ void cyclestep(void){
|
||||
default:
|
||||
break;
|
||||
}
|
||||
dologname (tmpbuf, conf.logname, (conf.archiver)?conf.archiver[1]:NULL, conf.logtype, (conf.logtime - t * conf.rotate));
|
||||
dologname (tmpbuf, conf.logname, (conf.archiver)?conf.archiver[1]:NULL, conf.logtype, (conf.logtime - (time_t)t * conf.rotate));
|
||||
remove ((char *) tmpbuf);
|
||||
if(conf.archiver) {
|
||||
int i;
|
||||
@@ -511,6 +511,11 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
/* before readconfig() starts the services: a client gone while it is
|
||||
written to is an error, not the end */
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
#endif
|
||||
_3proxy_mutex_init(&config_mutex);
|
||||
_3proxy_mutex_init(&bandlim_mutex);
|
||||
_3proxy_mutex_init(&connlim_mutex);
|
||||
@@ -561,7 +566,6 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int
|
||||
signal(SIGCONT, mysigpause);
|
||||
signal(SIGTERM, mysigterm);
|
||||
signal(SIGUSR1, mysigusr1);
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
cyclestep();
|
||||
|
||||
#endif
|
||||
|
||||
@@ -36,6 +36,8 @@ int ACLmatches(struct ace* acentry, struct clientparam * param){
|
||||
struct hostname * hstentry=NULL;
|
||||
int i;
|
||||
int match = 0;
|
||||
int dstdep = 0;
|
||||
int preauth = (param->preauth == 1 && acentry->action <= REDIRECT);
|
||||
|
||||
username = param->username?param->username:(unsigned char *)"-";
|
||||
if(acentry->src) {
|
||||
@@ -45,7 +47,10 @@ int ACLmatches(struct ace* acentry, struct clientparam * param){
|
||||
}
|
||||
if(!ipentry) return 0;
|
||||
}
|
||||
if((acentry->dst && (!SAISNULL(¶m->req) || param->operation==BIND)) || (acentry->dstnames && param->hostname)) {
|
||||
if(preauth && (acentry->dst || acentry->dstnames)) {
|
||||
dstdep = 1;
|
||||
}
|
||||
else if((acentry->dst && (!SAISNULL(¶m->req) || param->operation==BIND)) || (acentry->dstnames && param->hostname)) {
|
||||
for(ipentry = acentry->dst; ipentry; ipentry = ipentry->next)
|
||||
if(IPInentry((struct sockaddr *)¶m->req, ipentry)) {
|
||||
break;
|
||||
@@ -93,7 +98,10 @@ int ACLmatches(struct ace* acentry, struct clientparam * param){
|
||||
}
|
||||
if(!ipentry && !hstentry) return 0;
|
||||
}
|
||||
if(acentry->ports && (*SAPORT(¶m->req) || param->operation == BIND)) {
|
||||
if(preauth && acentry->ports) {
|
||||
dstdep = 1;
|
||||
}
|
||||
else if(acentry->ports && (*SAPORT(¶m->req) || param->operation == BIND)) {
|
||||
for (portentry = acentry->ports; portentry; portentry = portentry->next)
|
||||
if(ntohs(*SAPORT(¶m->req)) >= portentry->startport &&
|
||||
ntohs(*SAPORT(¶m->req)) <= portentry->endport) {
|
||||
@@ -125,6 +133,10 @@ int ACLmatches(struct ace* acentry, struct clientparam * param){
|
||||
}
|
||||
}
|
||||
if(acentry->weight && (acentry->weight < param->weight)) return 0;
|
||||
if(dstdep) {
|
||||
param->dstindep = 0;
|
||||
return acentry->action != DENY;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -132,6 +144,7 @@ int ACLmatches(struct ace* acentry, struct clientparam * param){
|
||||
int checkACL(struct clientparam * param){
|
||||
struct ace* acentry;
|
||||
|
||||
if(param->preauth == 1) param->dstindep = 1;
|
||||
if(!param->srv->acl) {
|
||||
return 0;
|
||||
}
|
||||
@@ -150,7 +163,9 @@ int checkACL(struct clientparam * param){
|
||||
if(param->redirected && acentry->chains && SAISNULL(&acentry->chains->addr) && !*SAPORT(&acentry->chains->addr)) {
|
||||
continue;
|
||||
}
|
||||
if(param->remsock != INVALID_SOCKET && (param->operation != UDPASSOC || param->ctrlsocksrv != INVALID_SOCKET)) {
|
||||
param->lastace = acentry;
|
||||
if(param->preauth) return 2;
|
||||
if((param->operation == UDPASSOC)? (param->ctrlsocksrv != INVALID_SOCKET) : (param->remsock != INVALID_SOCKET)) {
|
||||
return 0;
|
||||
}
|
||||
for(; i < conf.parentretries; i++){
|
||||
@@ -159,9 +174,14 @@ int checkACL(struct clientparam * param){
|
||||
if(!res) break;
|
||||
if(param->remsock != INVALID_SOCKET) param->srv->so._closesocket(param->sostate, param->remsock);
|
||||
param->remsock = INVALID_SOCKET;
|
||||
if(param->ctrlsocksrv != INVALID_SOCKET) {
|
||||
param->srv->so._closesocket(param->sostate, param->ctrlsocksrv);
|
||||
param->ctrlsocksrv = INVALID_SOCKET;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
param->lastace = acentry;
|
||||
return acentry->action;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-2
@@ -102,6 +102,7 @@ int cacheauth(struct clientparam * param){
|
||||
*(SAFAMILY(¶m->sinsl)) = ac.sinsl_family;
|
||||
memcpy(SAADDR(¶m->sinsl), ac.sinsl_addr, SAADDRLEN(¶m->sinsl));
|
||||
}
|
||||
if(param->preauth == 1 && param->srv->acl) param->dstindep = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -110,13 +111,17 @@ int doauth(struct clientparam * param){
|
||||
struct auth *authfuncs;
|
||||
int ret = 0;
|
||||
|
||||
if(param->preauth == 1 && !param->srv->acl) param->dstindep = 1;
|
||||
for(authfuncs=param->srv->authfuncs; authfuncs; authfuncs=authfuncs->next){
|
||||
res = authfuncs->authenticate?(*authfuncs->authenticate)(param):0;
|
||||
if(!res) {
|
||||
if(authfuncs->authorize &&
|
||||
(res = (*authfuncs->authorize)(param)))
|
||||
return res;
|
||||
if(param->srv->authcachetype && authfuncs->authenticate && authfuncs->authenticate != cacheauth && param->username && (!(param->srv->authcachetype&4) || (!param->pwtype && param->password))){
|
||||
/* A UDP ASSOCIATE is pre-authorized without looking at the
|
||||
destination its rules depend on, so its verdict holds for
|
||||
that association alone and is not kept for later requests. */
|
||||
if(param->srv->authcachetype && param->preauth != 1 && authfuncs->authenticate && authfuncs->authenticate != cacheauth && param->username && (!(param->srv->authcachetype&4) || (!param->pwtype && param->password))){
|
||||
struct authcache ac={.username=""};
|
||||
|
||||
if(param->username) {
|
||||
@@ -148,7 +153,7 @@ int doauth(struct clientparam * param){
|
||||
if(ret > 9) return ret;
|
||||
}
|
||||
if(!res){
|
||||
ret = alwaysauth(param);
|
||||
ret = (param->preauth == 2)? 0 : alwaysauth(param);
|
||||
if (param->afterauthfilters){
|
||||
FILTER_ACTION action;
|
||||
|
||||
|
||||
+24
-5
@@ -198,12 +198,20 @@ static int calc_replydigest(char *packet, char *original, const char *secret, in
|
||||
int secretlen;
|
||||
uint8_t calc_digest[AUTH_VECTOR_LEN];
|
||||
uint8_t calc_vector[AUTH_VECTOR_LEN];
|
||||
unsigned int dlen = AUTH_VECTOR_LEN;
|
||||
mdh_ctx *ctx;
|
||||
|
||||
memcpy(calc_vector, packet + 4, AUTH_VECTOR_LEN);
|
||||
memcpy(packet + 4, original, AUTH_VECTOR_LEN);
|
||||
secretlen = strlen(secret);
|
||||
memcpy(packet + len, secret, secretlen);
|
||||
md5_calc(calc_digest, (u_char *)packet, len + secretlen);
|
||||
/* hash the reply, then the secret: nothing is written past the reply */
|
||||
if(!(ctx = mdh_init(MDH_MD5, 16))) return 2;
|
||||
if(!mdh_update(ctx, packet, len) || !mdh_update(ctx, secret, secretlen) ||
|
||||
!mdh_final(ctx, calc_digest, &dlen)) {
|
||||
mdh_free(ctx);
|
||||
return 2;
|
||||
}
|
||||
mdh_free(ctx);
|
||||
|
||||
/*
|
||||
* Return 0 if OK, 2 if not OK.
|
||||
@@ -298,6 +306,7 @@ int radsend(struct clientparam * param, int auth, int stop){
|
||||
int total_length;
|
||||
int len;
|
||||
PROXYSOCKADDRTYPE saremote;
|
||||
PROXYSOCKADDRTYPE safrom;
|
||||
struct pollfd fds[1];
|
||||
char vector[AUTH_VECTOR_LEN];
|
||||
radius_packet_t packet, rpacket;
|
||||
@@ -568,15 +577,25 @@ int radsend(struct clientparam * param, int auth, int stop){
|
||||
continue;
|
||||
}
|
||||
|
||||
salen = sizeof(saremote);
|
||||
|
||||
salen = sizeof(safrom);
|
||||
|
||||
data_len = so._recvfrom(so.state, remsock, (char *)&rpacket, sizeof(packet)-16,
|
||||
0, (struct sockaddr *)&saremote, &salen);
|
||||
0, (struct sockaddr *)&safrom, &salen);
|
||||
|
||||
|
||||
if (data_len < 20) {
|
||||
continue;
|
||||
}
|
||||
/* the reply must come from the server we asked */
|
||||
if(*SAFAMILY(&safrom) != *SAFAMILY(&saremote) ||
|
||||
memcmp(SAADDR(&safrom), SAADDR(&saremote), SAADDRLEN(&saremote)) ||
|
||||
*SAPORT(&safrom) != *SAPORT(&saremote)) {
|
||||
continue;
|
||||
}
|
||||
/* and answer this request, and be of its own length */
|
||||
if(data_len != ntohs(rpacket.length) || rpacket.id != packet.id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if( auth && rpacket.code != PW_AUTHENTICATION_ACK &&
|
||||
rpacket.code != PW_AUTHENTICATION_REJECT ){
|
||||
|
||||
+10
-3
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
static const unsigned char base64digits[] =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
@@ -23,8 +24,10 @@ static const unsigned char base64val[] = {
|
||||
};
|
||||
#define DECODE64(c) ((c > 32 && c<127)? base64val[(int)c] : BAD)
|
||||
|
||||
unsigned char* en64 (const unsigned char *in, unsigned char *out, int inlen)
|
||||
unsigned char* en64 (const unsigned char *in, unsigned char *out, int inlen, int outsize)
|
||||
{
|
||||
if (inlen < 0 || inlen > (INT_MAX - 2) || outsize < 1) return NULL;
|
||||
if (((inlen + 2) / 3) > ((outsize - 1) / 4)) return NULL;
|
||||
for (; inlen > 0; inlen -= 3, in+=3)
|
||||
{
|
||||
|
||||
@@ -42,6 +45,7 @@ int de64 (const char *in, char *out, int maxlen)
|
||||
int len = 0;
|
||||
register unsigned char digit1, digit2, digit3, digit4;
|
||||
|
||||
if (maxlen < 0) return(-1);
|
||||
if (in[0] == '+' && in[1] == ' ')
|
||||
in += 2;
|
||||
if (*in == '\r')
|
||||
@@ -61,20 +65,23 @@ int de64 (const char *in, char *out, int maxlen)
|
||||
if (digit4 != '=' && DECODE64(digit4) == BAD)
|
||||
return(-1);
|
||||
in += 4;
|
||||
if (len >= maxlen) return (len);
|
||||
*out++ = (DECODE64(digit1) << 2) | (DECODE64(digit2) >> 4);
|
||||
++len;
|
||||
if (digit3 != '=')
|
||||
{
|
||||
if (len >= maxlen) return (len);
|
||||
*out++ = ((DECODE64(digit2) << 4) & 0xf0) | (DECODE64(digit3) >> 2);
|
||||
++len;
|
||||
if (digit4 != '=')
|
||||
{
|
||||
if (len >= maxlen) return (len);
|
||||
*out++ = ((DECODE64(digit3) << 6) & 0xc0) | DECODE64(digit4);
|
||||
++len;
|
||||
}
|
||||
}
|
||||
} while
|
||||
(*in && *in != '\r' && digit4 != '=' && (maxlen-=4) >= 4);
|
||||
} while
|
||||
(*in && *in != '\r' && digit4 != '=');
|
||||
|
||||
return (len);
|
||||
}
|
||||
|
||||
+155
-22
@@ -9,6 +9,48 @@
|
||||
|
||||
|
||||
#include "proxy.h"
|
||||
/* returns 0 on success, 1 if atyp is not supported for family, 2 if the
|
||||
address is null. The address is set in both the 0 and the 2 case. */
|
||||
int socks5_setaddr(int family, int atyp, const unsigned char *addr, PROXYSOCKADDRTYPE *sa){
|
||||
int i, len = 4;
|
||||
|
||||
memset(sa, 0, sizeof(*sa));
|
||||
if(atyp == 4){
|
||||
#ifdef NOIPV6
|
||||
return 1;
|
||||
#else
|
||||
if(family == 4) return 1;
|
||||
len = 16;
|
||||
*SAFAMILY(sa) = AF_INET6;
|
||||
memcpy(SAADDR(sa), addr, 16);
|
||||
#endif
|
||||
}
|
||||
#ifndef NOIPV6
|
||||
else if(family == 6){
|
||||
unsigned char prefix[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255};
|
||||
|
||||
*SAFAMILY(sa) = AF_INET6;
|
||||
memcpy(SAADDR(sa), prefix, 12);
|
||||
memcpy(12 + (unsigned char *)SAADDR(sa), addr, 4);
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
*SAFAMILY(sa) = AF_INET;
|
||||
memcpy(SAADDR(sa), addr, 4);
|
||||
}
|
||||
for(i = 0; i < len && !addr[i]; i++);
|
||||
return (i == len)? 2 : 0;
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
#include <sched.h>
|
||||
|
||||
int switch_ns(struct srvparam *srv, int target_fd) {
|
||||
if(target_fd < 0) return 0;
|
||||
if(srv->saved_nsfd >= 0 && setns(srv->saved_nsfd, CLONE_NEWNET)) return -1;
|
||||
return setns(target_fd, CLONE_NEWNET);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
char * copyright = COPYRIGHT;
|
||||
@@ -130,7 +172,7 @@ int timeouts[12] = {
|
||||
60, /* CHAIN_TO */
|
||||
15, /* CONNECT_TO */
|
||||
5, /* CONNBACK_TO */
|
||||
0,
|
||||
5, /* LINGER_TO */
|
||||
0
|
||||
};
|
||||
|
||||
@@ -140,7 +182,7 @@ int timeouts[12] = {
|
||||
EINVAL below it and the thread silently gets the 8M system default stack.
|
||||
*/
|
||||
size_t threadstacksize(int extra){
|
||||
long size = BASESTACKSIZE + extra;
|
||||
long size = BASESTACKSIZE + TLSSTACKSIZE + extra;
|
||||
|
||||
if(size < (long)PTHREAD_STACK_MIN) size = (long)PTHREAD_STACK_MIN;
|
||||
return (size_t)size;
|
||||
@@ -372,7 +414,6 @@ int
|
||||
return shutdown(s, how);
|
||||
}
|
||||
int WINAPI def_closesocket(void* state, SOCKET s){
|
||||
usleep(SLEEPTIME);
|
||||
return closesocket(s);
|
||||
}
|
||||
#else
|
||||
@@ -412,11 +453,18 @@ int
|
||||
#endif
|
||||
}
|
||||
|
||||
/* a peer gone is an error of the send, not SIGPIPE, where the system can
|
||||
say so for a call: SIGPIPE is ignored too, for TLS and splice() */
|
||||
#ifdef MSG_NOSIGNAL
|
||||
#define SENDFLAGS MSG_NOSIGNAL
|
||||
#else
|
||||
#define SENDFLAGS 0
|
||||
#endif
|
||||
ssize_t def_send(void* state, SOCKET s, const void *msg, size_t len, int flags){
|
||||
return send(s, msg, len, flags);
|
||||
return send(s, msg, len, flags | SENDFLAGS);
|
||||
}
|
||||
ssize_t def_sendto(void* state, SOCKET s, const void *msg, size_t len, int flags, const struct sockaddr *to, socklen_t tolen){
|
||||
return sendto(s, msg, len, flags, to, tolen);
|
||||
return sendto(s, msg, len, flags | SENDFLAGS, to, tolen);
|
||||
}
|
||||
ssize_t def_recv(void* state, SOCKET s, void *buf, size_t len, int flags){
|
||||
return recv(s, buf, len, flags);
|
||||
@@ -521,11 +569,26 @@ int parsehost(int family, unsigned char *host, struct sockaddr *sa){
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* A host name is written into the request lines of parent protocols and
|
||||
matched against rules, so a control byte or a space in it could end a
|
||||
line early or pose as another destination. A name carrying one is
|
||||
refused where it is read, and every name a client sends is read on
|
||||
its way to the field. */
|
||||
int badhostname(const char *hostname){
|
||||
const unsigned char *c;
|
||||
|
||||
if(!hostname) return 1;
|
||||
for(c = (const unsigned char *)hostname; *c; c++)
|
||||
if(*c <= ' ' || *c == 0x7f) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parsehostname(char *hostname, struct clientparam *param, uint16_t port){
|
||||
char *sp=NULL,*se=NULL;
|
||||
int ret = 0;
|
||||
|
||||
if(!hostname || !*hostname)return 2;
|
||||
if(badhostname(hostname)) return 1;
|
||||
if(*hostname == '[') se=strchr(hostname, ']');
|
||||
if ((sp = strchr(se?se:hostname, ':'))) {
|
||||
if(strchr(sp+1, ':'))sp = NULL;
|
||||
@@ -539,6 +602,9 @@ int parsehostname(char *hostname, struct clientparam *param, uint16_t port){
|
||||
port = atoi(sp+1);
|
||||
*sp = ':';
|
||||
}
|
||||
/* A port alone overrides the port of a host already set; without
|
||||
one it names no destination to connect to. */
|
||||
if(!param->hostname || !*param->hostname) return 1;
|
||||
*SAPORT(¶m->req) = htons(port);
|
||||
return 0;
|
||||
}
|
||||
@@ -613,6 +679,26 @@ int parseconnusername(char *username, struct clientparam *param, int extpasswd,
|
||||
}
|
||||
|
||||
|
||||
/* What waits for a socket waits in poll(): a call on it never does. */
|
||||
void nonblock(SOCKET sock){
|
||||
#ifdef _WIN32
|
||||
unsigned long ul = 1;
|
||||
ioctlsocket(sock, FIONBIO, &ul);
|
||||
#else
|
||||
fcntl(sock, F_SETFL, O_NONBLOCK | fcntl(sock, F_GETFL));
|
||||
#endif
|
||||
}
|
||||
|
||||
/* accept() with nothing to accept: another took it, or it was gone */
|
||||
int acceptagain(void){
|
||||
#ifdef _WIN32
|
||||
int err = WSAGetLastError();
|
||||
return err == WSAEWOULDBLOCK || err == WSAECONNRESET || err == WSAEINTR;
|
||||
#else
|
||||
return errno == EAGAIN || errno == EWOULDBLOCK || errno == ECONNABORTED || errno == EINTR;
|
||||
#endif
|
||||
}
|
||||
|
||||
int connectwithpoll(struct clientparam *param, SOCKET sock, struct sockaddr *sa, SASIZETYPE size, int to){
|
||||
struct pollfd fds[1];
|
||||
#ifdef _WIN32
|
||||
@@ -635,6 +721,49 @@ int connectwithpoll(struct clientparam *param, SOCKET sock, struct sockaddr *sa,
|
||||
}
|
||||
|
||||
|
||||
/* -Di / -De: ties a socket to the interface asked for, for TCP and UDP alike.
|
||||
Where the option is set per protocol, family is the one of the address the
|
||||
socket will be bound to. */
|
||||
int bindtodevice(struct sockfuncs *sf, void *state, SOCKET sock, const char *device, int family){
|
||||
if(!device) return 0;
|
||||
#if defined SO_BINDTODEVICE
|
||||
if(sf->_setsockopt(state, sock, SOL_SOCKET, SO_BINDTODEVICE, device, strlen(device) + 1))
|
||||
return 1;
|
||||
#elif defined IP_BOUND_IF
|
||||
{
|
||||
int idx;
|
||||
idx = if_nametoindex(device);
|
||||
if(!idx || (family == AF_INET && sf->_setsockopt(state, sock, IPPROTO_IP, IP_BOUND_IF, &idx, sizeof(idx))))
|
||||
return 1;
|
||||
#ifndef NOIPV6
|
||||
#ifndef IPV6_BOUND_IF
|
||||
#define IPV6_BOUND_IF 125
|
||||
#endif
|
||||
if(family == AF_INET6 && sf->_setsockopt(state, sock, IPPROTO_IPV6, IPV6_BOUND_IF, &idx, sizeof(idx))) return 1;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* the external side, a socket to be bound to sinsl */
|
||||
int extbindtodevice(struct clientparam *param, SOCKET sock){
|
||||
#if defined SO_BINDTODEVICE || defined IP_BOUND_IF
|
||||
return bindtodevice(¶m->srv->so, param->sostate, sock, param->srv->obindtodevice, *SAFAMILY(¶m->sinsl));
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* the internal side, a socket to be bound to sincl */
|
||||
int intbindtodevice(struct clientparam *param, SOCKET sock){
|
||||
#if defined SO_BINDTODEVICE || defined IP_BOUND_IF
|
||||
return bindtodevice(¶m->srv->so, param->sostate, sock, param->srv->ibindtodevice, *SAFAMILY(¶m->sincl));
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int doconnect(struct clientparam * param){
|
||||
SASIZETYPE size;
|
||||
|
||||
@@ -644,13 +773,16 @@ int doconnect(struct clientparam * param){
|
||||
|
||||
if (param->operation == ADMIN || (( param->operation == DNSRESOLVE || param->operation == BIND || param->operation == UDPASSOC) && !param->redirected))
|
||||
return 0;
|
||||
if (param->operation == UDPASSOC && param->ctrlsocksrv != INVALID_SOCKET) return 0;
|
||||
if (param->remsock != INVALID_SOCKET){
|
||||
if(param->operation == UDPASSOC) return 0;
|
||||
size = sizeof(param->sinsr);
|
||||
if(param->srv->so._getpeername(param->sostate, param->remsock, (struct sockaddr *)¶m->sinsr, &size)==-1) {return (14);}
|
||||
}
|
||||
else {
|
||||
struct linger lg = {1,conf.timeouts[SINGLEBYTE_S]};
|
||||
#ifndef _WIN32
|
||||
struct linger lg = {1,conf.timeouts[LINGER_TO]};
|
||||
#endif
|
||||
|
||||
if(SAISNULL(¶m->sinsr)){
|
||||
if(SAISNULL(¶m->req)) {
|
||||
@@ -680,24 +812,25 @@ int doconnect(struct clientparam * param){
|
||||
*SAPORT(¶m->sinsl) = 0;
|
||||
setopts(param->remsock, param->srv->srvsockopts);
|
||||
|
||||
#ifndef _WIN32
|
||||
/* not on Windows, see the accepting side in proxymain.c */
|
||||
param->srv->so._setsockopt(param->sostate, param->remsock, SOL_SOCKET, SO_LINGER, (char *)&lg, sizeof(lg));
|
||||
#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))
|
||||
return 12;
|
||||
}
|
||||
#elif defined IP_BOUND_IF
|
||||
if(param->srv->obindtodevice) {
|
||||
int idx;
|
||||
idx = if_nametoindex(param->srv->obindtodevice);
|
||||
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
|
||||
if(extbindtodevice(param, param->remsock)) return 12;
|
||||
#ifdef IP_BIND_ADDRESS_NO_PORT
|
||||
/* A port the kernel chooses is chosen by connect(), for the pair with
|
||||
the destination: one in use towards another destination, or closing
|
||||
from an earlier connection, does as well. bind() would take one of
|
||||
its own, and with many connections find none left, or search long
|
||||
for it. */
|
||||
if((param->operation >= 256 || (param->operation & CONNECT) || param->redirected)
|
||||
# ifdef WITH_UN
|
||||
&& *SAFAMILY(¶m->sinsl) != AF_UNIX
|
||||
# endif
|
||||
){
|
||||
int one = 1;
|
||||
|
||||
param->srv->so._setsockopt(param->sostate, param->remsock, IPPROTO_IP, IP_BIND_ADDRESS_NO_PORT, (char *)&one, sizeof(one));
|
||||
}
|
||||
#endif
|
||||
#ifdef WITH_UN
|
||||
|
||||
+50
-9
@@ -158,7 +158,12 @@ int start_proxy_thread(struct child * chp){
|
||||
pthread_attr_init(&pa);
|
||||
pthread_attr_setstacksize(&pa,threadstacksize(conf.stacksize));
|
||||
pthread_attr_setdetachstate(&pa,PTHREAD_CREATE_DETACHED);
|
||||
pthread_create(&thread, &pa, startsrv, (void *)chp);
|
||||
if(pthread_create(&thread, &pa, startsrv, (void *)chp)){
|
||||
pthread_attr_destroy(&pa);
|
||||
fprintf(stderr, "Failed to create service thread on line %d, try to set larger stacksize\n", linenum);
|
||||
_3proxy_sem_unlock(conf.threadinit);
|
||||
return(40);
|
||||
}
|
||||
pthread_attr_destroy(&pa);
|
||||
#endif
|
||||
_3proxy_sem_lock(conf.threadinit);
|
||||
@@ -331,7 +336,8 @@ static int h_log(int argc, unsigned char ** argv){
|
||||
#ifndef _WIN32
|
||||
conf.logfunc = logsyslog;
|
||||
if(notchanged) return 0;
|
||||
openlog((char *)conf.logtarget+1, LOG_PID, LOG_DAEMON);
|
||||
/* connected now: after a chroot there is no /dev/log to find */
|
||||
openlog((char *)conf.logtarget+1, LOG_PID | LOG_NDELAY, LOG_DAEMON);
|
||||
#endif
|
||||
}
|
||||
#ifdef WITH_ODBC
|
||||
@@ -839,6 +845,24 @@ static int h_parent(int argc, unsigned char **argv){
|
||||
chains->cidr = atoi(cidr + 1);
|
||||
}
|
||||
*SAPORT(&chains->addr) = htons((uint16_t)atoi((char *)argv[4]));
|
||||
switch(chains->type){
|
||||
case R_POP3:
|
||||
case R_SMTP:
|
||||
case R_FTP:
|
||||
case R_ADMIN:
|
||||
case R_TLS:
|
||||
case R_DNS:
|
||||
case R_HA:
|
||||
if(!SAISNULL(&chains->addr) || *SAPORT(&chains->addr)){
|
||||
fprintf(stderr, "Chaining error: chain type (%s) is a local redirection, it requires 0.0.0.0 as address and 0 as port on line %d\n", argv[2], linenum);
|
||||
free(chains->exthost);
|
||||
free(chains);
|
||||
return(4);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if(argc > 5) chains->extuser = (unsigned char *)strdup((char *)argv[5]);
|
||||
if(argc > 6) chains->extpass = (unsigned char *)strdup((char *)argv[6]);
|
||||
if(!acl->chains) {
|
||||
@@ -1432,8 +1456,8 @@ static int h_radius(int argc, unsigned char **argv){
|
||||
*s = 0;
|
||||
s++;
|
||||
}
|
||||
if( !getip46(46, argv[nradservers + 2], (struct sockaddr *)&radiuslist[nradservers].authaddr)) return 1;
|
||||
if( s && !getip46(46, (unsigned char *)s, (struct sockaddr *)&radiuslist[nradservers].localaddr)) return 2;
|
||||
if(parsehost(46, argv[nradservers + 2], (struct sockaddr *)&radiuslist[nradservers].authaddr)) return 1;
|
||||
if(s && parsehost(46, (unsigned char *)s, (struct sockaddr *)&radiuslist[nradservers].localaddr)) return 2;
|
||||
if(!*SAPORT(&radiuslist[nradservers].authaddr))*SAPORT(&radiuslist[nradservers].authaddr) = htons(1812);
|
||||
port = ntohs(*SAPORT(&radiuslist[nradservers].authaddr));
|
||||
radiuslist[nradservers].logaddr = radiuslist[nradservers].authaddr;
|
||||
@@ -1573,6 +1597,14 @@ static int h_setgid(int argc, unsigned char **argv){
|
||||
}
|
||||
|
||||
|
||||
/* What the C library reads on first use from files a chroot hides, read
|
||||
while they can still be found: the time zone, without which every time
|
||||
is UTC. Names looked up through the system cannot be helped this way, the
|
||||
hosts file and resolv.conf are read again for lookups to come. */
|
||||
static void prechroot(void){
|
||||
tzset();
|
||||
}
|
||||
|
||||
static int h_chroot(int argc, unsigned char **argv){
|
||||
uid_t uid = 0;
|
||||
gid_t gid = 0;
|
||||
@@ -1592,6 +1624,8 @@ static int h_chroot(int argc, unsigned char **argv){
|
||||
}
|
||||
if(!chrootp){
|
||||
char *p;
|
||||
|
||||
prechroot();
|
||||
if(chroot((char *)argv[1])) {
|
||||
fprintf(stderr, "Unable to chroot %s", argv[1]);
|
||||
return(1);
|
||||
@@ -1902,6 +1936,7 @@ int readconfig(FILE * fp){
|
||||
|
||||
if( !(buf = malloc(bufsize)) || ! (argv = malloc((NPARAMS + 1) * sizeof(unsigned char *))) ) {
|
||||
fprintf(stderr, "No memory for configuration");
|
||||
if(buf) free(buf);
|
||||
return(10);
|
||||
}
|
||||
for (linenum = 1; fgets((char *)buf, STRINGBUF, fp); linenum++){
|
||||
@@ -1911,7 +1946,8 @@ int readconfig(FILE * fp){
|
||||
argc = parsestr (buf, argv, NPARAMS-1, &buf, &inbuf, &bufsize);
|
||||
if(argc < 1) {
|
||||
fprintf(stderr, "Parse error line %d\n", linenum);
|
||||
return(11);
|
||||
res = 11;
|
||||
goto DONE;
|
||||
}
|
||||
argv[argc] = NULL;
|
||||
if(!strcmp((char *)argv[0], "end") && argc == 1) {
|
||||
@@ -1933,23 +1969,28 @@ int readconfig(FILE * fp){
|
||||
if(!strcmp((char *)argv[0], (char *)cm->command)){
|
||||
if(argc < cm->minargs || (cm->maxargs && argc > cm->maxargs)){
|
||||
fprintf(stderr, "Command: '%s' wrong number of arguments , line %d\n", argv[0], linenum);
|
||||
return(linenum);
|
||||
res = linenum;
|
||||
goto DONE;
|
||||
}
|
||||
res = (*cm->handler)(argc, argv);
|
||||
if(res > 0){
|
||||
fprintf(stderr, "Command: '%s' failed with code %d, line %d\n", argv[0], res, linenum);
|
||||
return(linenum);
|
||||
res = linenum;
|
||||
goto DONE;
|
||||
}
|
||||
if(!res) break;
|
||||
}
|
||||
}
|
||||
if(res != 1)continue;
|
||||
fprintf(stderr, "Unknown command: '%s' line %d\n", argv[0], linenum);
|
||||
return(linenum);
|
||||
res = linenum;
|
||||
goto DONE;
|
||||
}
|
||||
res = 0;
|
||||
DONE:
|
||||
free(buf);
|
||||
free(argv);
|
||||
return 0;
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
+43
-8
@@ -15,6 +15,12 @@
|
||||
|
||||
#define BUFSIZE 16384
|
||||
|
||||
/* An answer to the query asked: our id, a response, and the question
|
||||
byte for byte. */
|
||||
static int dnsanswer(const unsigned char *buf, int len, const unsigned char *q, int qend){
|
||||
return len >= qend && buf[0] == q[0] && buf[1] == q[1] && (buf[2] & 0x80) &&
|
||||
buf[4] == q[4] && buf[5] == q[5] && !memcmp(buf + 12, q + 12, qend - 12);
|
||||
}
|
||||
|
||||
void * dnsprchild(struct clientparam* param) {
|
||||
uint32_t ip = 0;
|
||||
@@ -144,6 +150,20 @@ void * dnsprchild(struct clientparam* param) {
|
||||
else ip = 0;
|
||||
}
|
||||
if(!ip && numservers){
|
||||
/* the question, to check the answer against; the name server is
|
||||
asked under an id of our own, the client's put back in its answer */
|
||||
unsigned char question[1024], cid[2];
|
||||
int qend = (len < i)? len : i;
|
||||
unsigned short id = (unsigned short)myrand();
|
||||
PROXYSOCKADDRTYPE from;
|
||||
time_t deadline;
|
||||
int to;
|
||||
|
||||
cid[0] = buf[0];
|
||||
cid[1] = buf[1];
|
||||
buf[0] = (unsigned char)(id >> 8);
|
||||
buf[1] = (unsigned char)(id & 0xff);
|
||||
memcpy(question, buf, qend);
|
||||
if((param->remsock=param->srv->so._socket(param->sostate, SASOCK(&nservers[0].addr), nservers[0].usetcp? SOCK_STREAM:SOCK_DGRAM, nservers[0].usetcp?IPPROTO_TCP:IPPROTO_UDP)) == INVALID_SOCKET) {
|
||||
RETURN(818);
|
||||
}
|
||||
@@ -172,9 +192,21 @@ void * dnsprchild(struct clientparam* param) {
|
||||
}
|
||||
param->statscli64 += i;
|
||||
param->nwrites++;
|
||||
len = sockrecvfrom(param, param->remsock, (struct sockaddr *)¶m->sinsr, buf, BUFSIZE, conf.timeouts[DNS_TO]*1000);
|
||||
if(len <= 13) {
|
||||
RETURN(821);
|
||||
/* over UDP only an answer from the name server asked is taken, any
|
||||
other read past while the time for it lasts */
|
||||
deadline = time(NULL) + conf.timeouts[DNS_TO];
|
||||
for(;;){
|
||||
to = (int)(deadline - time(NULL));
|
||||
if(to <= 0) RETURN(821);
|
||||
len = sockrecvfrom(param, param->remsock, (struct sockaddr *)&from, buf, BUFSIZE, to*1000);
|
||||
if(len <= 13) {
|
||||
RETURN(821);
|
||||
}
|
||||
if(nservers[0].usetcp) break;
|
||||
if(*SAFAMILY(&from) == *SAFAMILY(¶m->sinsr) &&
|
||||
!memcmp(SAADDR(&from), SAADDR(¶m->sinsr), SAADDRLEN(¶m->sinsr)) &&
|
||||
*SAPORT(&from) == *SAPORT(¶m->sinsr) &&
|
||||
dnsanswer(buf, len, question, qend)) break;
|
||||
}
|
||||
param->statssrv64 += len;
|
||||
param->nreads++;
|
||||
@@ -186,13 +218,16 @@ void * dnsprchild(struct clientparam* param) {
|
||||
len -= 2;
|
||||
if(len < us) len += sockgetlinebuf(param, SERVER, buf+len, us - len, 0, conf.timeouts[SINGLEBYTE_L]);
|
||||
if(len != us) RETURN(832);
|
||||
if(!dnsanswer(buf, len, question, qend)) RETURN(834);
|
||||
}
|
||||
if(buf[6] || buf[7]){
|
||||
if(socksendto(param, param->clisock, (struct sockaddr *)¶m->sincr, buf, len, conf.timeouts[SINGLEBYTE_L]*1000) != len){
|
||||
RETURN(822);
|
||||
}
|
||||
RETURN(0);
|
||||
buf[0] = cid[0];
|
||||
buf[1] = cid[1];
|
||||
/* the answer goes to the client as it is, its code with no records
|
||||
among them: the name not found is the server's word, not ours */
|
||||
if(socksendto(param, param->clisock, (struct sockaddr *)¶m->sincr, buf, len, conf.timeouts[SINGLEBYTE_L]*1000) != len){
|
||||
RETURN(822);
|
||||
}
|
||||
RETURN(0);
|
||||
|
||||
}
|
||||
if(!ip) {
|
||||
|
||||
@@ -36,7 +36,7 @@ int ftplogin(struct clientparam *param, char *nbuf, int *innbuf) {
|
||||
if(i < 3) return 706;
|
||||
buf[i] = 0;
|
||||
if(atoi(buf)/100 != 2) {
|
||||
*innbuf = i;
|
||||
if(innbuf)*innbuf = i;
|
||||
return 702;
|
||||
}
|
||||
sprintf(buf, "USER %.128s\r\n", param->extusername?param->extusername:(unsigned char *)"anonymous");
|
||||
@@ -75,6 +75,9 @@ int ftplogin(struct clientparam *param, char *nbuf, int *innbuf) {
|
||||
return 701;
|
||||
}
|
||||
}
|
||||
/* USER answered at once, logged in (230) or refused: that answer is
|
||||
the client's, waiting for one to its PASS */
|
||||
else if(innbuf)*innbuf = i;
|
||||
if(res != 2) {
|
||||
return 700;
|
||||
}
|
||||
|
||||
+17
-2
@@ -21,14 +21,18 @@ void * ftpprchild(struct clientparam* param) {
|
||||
SOCKET sc = INVALID_SOCKET, ss = INVALID_SOCKET, clidatasock = INVALID_SOCKET;
|
||||
SASIZETYPE sasize;
|
||||
char * req = NULL;
|
||||
#ifndef _WIN32
|
||||
struct linger lg;
|
||||
#endif
|
||||
struct pollfd fds;
|
||||
|
||||
if(!(buf = malloc(BUFSIZE))) RETURN(876);
|
||||
param->ctrlsock = param->clisock;
|
||||
param->operation = CONNECT;
|
||||
#ifndef _WIN32
|
||||
lg.l_onoff = 1;
|
||||
lg.l_linger = conf.timeouts[STRING_L];;
|
||||
lg.l_linger = conf.timeouts[STRING_L];
|
||||
#endif
|
||||
if(socksend(param, param->ctrlsock, (unsigned char *)"220 Ready\r\n", 11, conf.timeouts[STRING_S])!=11) {RETURN (801);}
|
||||
for(;;){
|
||||
i = sockgetlinebuf(param, CLIENT, buf, BUFSIZE - 10, '\n', conf.timeouts[CONNECTION_S]);
|
||||
@@ -64,6 +68,13 @@ void * ftpprchild(struct clientparam* param) {
|
||||
|
||||
}
|
||||
else if (!strncasecmp((char *)buf, "PASS ", 5)){
|
||||
/* The user name carries the server to log in to, and it arrives
|
||||
with USER. Without it there is nothing to log in to, and what
|
||||
follows would read the name and the host as if there were. */
|
||||
if(!param->hostname || !param->extusername){
|
||||
socksend(param, param->ctrlsock, (unsigned char *)"503 Login with USER first\r\n", 27, conf.timeouts[STRING_S]);
|
||||
RETURN(805);
|
||||
}
|
||||
param->extpassword = (unsigned char *)strdup((char *)buf+5);
|
||||
inbuf = BUFSIZE;
|
||||
res = ftplogin(param, (char *)buf, &inbuf);
|
||||
@@ -119,7 +130,8 @@ void * ftpprchild(struct clientparam* param) {
|
||||
param->srv->so._closesocket(param->sostate, clidatasock);
|
||||
clidatasock = INVALID_SOCKET;
|
||||
}
|
||||
if ((clidatasock=socket(SASOCK(¶m->sincl), SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) {RETURN(821);}
|
||||
if ((clidatasock=param->srv->so._socket(param->sostate, SASOCK(¶m->sincl), SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) {RETURN(821);}
|
||||
if(intbindtodevice(param, clidatasock)){RETURN(822);}
|
||||
*SAPORT(¶m->sincl) = 0;
|
||||
if(param->srv->so._bind(param->sostate, clidatasock, (struct sockaddr *)¶m->sincl, SASIZE(¶m->sincl))){RETURN(822);}
|
||||
if (pasv) {
|
||||
@@ -252,8 +264,11 @@ void * ftpprchild(struct clientparam* param) {
|
||||
}
|
||||
sc = param->remsock;
|
||||
param->remsock = ss;
|
||||
#ifndef _WIN32
|
||||
/* not on Windows, see the accepting side in proxymain.c */
|
||||
param->srv->so._setsockopt(param->sostate, param->remsock, SOL_SOCKET, SO_LINGER, (char *)&lg, sizeof(lg));
|
||||
param->srv->so._setsockopt(param->sostate, clidatasock, SOL_SOCKET, SO_LINGER, (char *)&lg, sizeof(lg));
|
||||
#endif
|
||||
param->clisock = clidatasock;
|
||||
res = mapsocket(param, conf.timeouts[CONNECTION_S]);
|
||||
if(param->remsock != INVALID_SOCKET) {
|
||||
|
||||
+6
-6
@@ -70,9 +70,9 @@ int inithashtable(struct hashtable *ht, unsigned tablesize, unsigned poolsize, u
|
||||
_3proxy_mutex_init(&ht->hash_mutex);
|
||||
_3proxy_mutex_lock(&ht->hash_mutex);
|
||||
}
|
||||
if(!(ht->ihashtable = malloc(tablesize * sizeof(uint32_t)))
|
||||
|| !(ht->hashvalues = malloc(poolsize * (sizeof(struct hashentry) + ht->recsize - 4)))
|
||||
|| !(ht->hashhashvalues = malloc(poolsize * ht->hash_size))
|
||||
if(!(ht->ihashtable = malloc((size_t)tablesize * sizeof(uint32_t)))
|
||||
|| !(ht->hashvalues = malloc((size_t)poolsize * (sizeof(struct hashentry) + ht->recsize - 4)))
|
||||
|| !(ht->hashhashvalues = malloc((size_t)poolsize * ht->hash_size))
|
||||
){
|
||||
free(ht->ihashtable);
|
||||
ht->ihashtable = NULL;
|
||||
@@ -126,13 +126,13 @@ static void hashgrow(struct hashtable *ht){
|
||||
if(ht->ihashempty) return;
|
||||
if(ht->poolsize >= ht->growlimit) return;
|
||||
if(newsize > ht->growlimit) newsize = ht->growlimit;
|
||||
newvalues = realloc(ht->hashvalues, newsize * (sizeof(struct hashentry) + ht->recsize - 4));
|
||||
newvalues = realloc(ht->hashvalues, (size_t)newsize * (sizeof(struct hashentry) + ht->recsize - 4));
|
||||
if(!newvalues) return;
|
||||
ht->hashvalues = newvalues;
|
||||
newvalues = realloc(ht->hashhashvalues, newsize * ht->hash_size);
|
||||
newvalues = realloc(ht->hashhashvalues, (size_t)newsize * ht->hash_size);
|
||||
if(!newvalues) return;
|
||||
ht->hashhashvalues = newvalues;
|
||||
memset(ht->hashvalues + (ht->poolsize * (sizeof(struct hashentry) + ht->recsize - 4)), 0, (newsize - ht->poolsize) * (sizeof(struct hashentry) + ht->recsize - 4));
|
||||
memset(ht->hashvalues + ((size_t)ht->poolsize * (sizeof(struct hashentry) + ht->recsize - 4)), 0, (size_t)(newsize - ht->poolsize) * (sizeof(struct hashentry) + ht->recsize - 4));
|
||||
for(i = ht->poolsize + 1; i < newsize; i++) {
|
||||
hvalue(ht,i)->inext = i+1;
|
||||
}
|
||||
|
||||
+4
-6
@@ -182,12 +182,12 @@ void * imappchild(struct clientparam* param) {
|
||||
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);}
|
||||
if(i + res + 2 > (int)sizeof(ibuf)) {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(!en64(ibuf, srvbuf, i + res + 2, (int)sizeof(srvbuf))) {RETURN(693);}
|
||||
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 ||
|
||||
@@ -200,15 +200,13 @@ void * imappchild(struct clientparam* param) {
|
||||
{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(!en64(param->extusername, ibuf, (int)strlen((char *)param->extusername), (int)sizeof(ibuf))) {RETURN(693);}
|
||||
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(!en64(pb, ibuf, (int)strlen((char *)pb), (int)sizeof(ibuf))) {RETURN(693);}
|
||||
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);}
|
||||
|
||||
+60
-16
@@ -220,6 +220,14 @@ struct pcre_filter_data {
|
||||
struct ace *acl;
|
||||
};
|
||||
|
||||
/* What a connection matches with: pcre2_match() writes into its match
|
||||
data, so a thread matching on the rule's own one would race every
|
||||
other thread doing the same. */
|
||||
struct pcre_client_data {
|
||||
struct pcre_filter_data *pcrefd;
|
||||
pcre2_match_data * match_data;
|
||||
};
|
||||
|
||||
static void pcre_data_free(struct pcre_filter_data *pcrefd){
|
||||
_3proxy_mutex_lock(&pcre_mutex);
|
||||
pcrefd->users--;
|
||||
@@ -253,18 +261,36 @@ static void* pcre_filter_open(void * idata, struct srvparam * param){
|
||||
static FILTER_ACTION pcre_filter_client(void *fo, struct clientparam * param, void** fc){
|
||||
int res;
|
||||
struct ace tmpace;
|
||||
struct pcre_filter_data *rule = (struct pcre_filter_data *)fo;
|
||||
struct pcre_client_data *pcd;
|
||||
|
||||
*fc = fo;
|
||||
*fc = NULL;
|
||||
if(!fo) return PASS;
|
||||
#define pcrefd ((struct pcre_filter_data *)fo)
|
||||
if(!pcrefd->acl) return CONTINUE;
|
||||
memset (&tmpace, 0, sizeof(struct ace));
|
||||
tmpace.src = pcrefd->acl->src;
|
||||
res = pl->ACLMatches(&tmpace, param);
|
||||
#undef pcrefd
|
||||
return (res)? CONTINUE:PASS;
|
||||
if(rule->acl){
|
||||
memset (&tmpace, 0, sizeof(struct ace));
|
||||
tmpace.src = rule->acl->src;
|
||||
res = pl->ACLMatches(&tmpace, param);
|
||||
if(!res) return PASS;
|
||||
}
|
||||
/* the connection goes on with a match data of its own */
|
||||
if(!(pcd = pl->mallocfunc(sizeof(struct pcre_client_data)))){
|
||||
*fc = NULL;
|
||||
return rule->action;
|
||||
}
|
||||
pcd->pcrefd = rule;
|
||||
pcd->match_data = NULL;
|
||||
if(rule->re && !(pcd->match_data = pcre2_match_data_create_from_pattern(rule->re, NULL))){
|
||||
pl->freefunc(pcd);
|
||||
*fc = NULL;
|
||||
return rule->action;
|
||||
}
|
||||
*fc = pcd;
|
||||
return CONTINUE;
|
||||
}
|
||||
|
||||
/* What a rewritten buffer keeps free for its caller to append to. */
|
||||
#define PCRE_HEADROOM 1024
|
||||
|
||||
static FILTER_ACTION pcre_filter_buffer(void *fc, struct clientparam *param, unsigned char ** buf_p, int * bufsize_p, int offset, int * length_p){
|
||||
PCRE2_SIZE *ovector;
|
||||
int count = 0;
|
||||
@@ -274,10 +300,11 @@ static FILTER_ACTION pcre_filter_buffer(void *fc, struct clientparam *param, uns
|
||||
char * replace;
|
||||
char * tmpbuf, *target, *newbuf;
|
||||
int nreplaces=0;
|
||||
#define pcrefd ((struct pcre_filter_data *)fc)
|
||||
struct pcre_client_data *pcd = (struct pcre_client_data *)fc;
|
||||
#define pcrefd (pcd->pcrefd)
|
||||
|
||||
for(acl = pcrefd->acl; acl; acl=acl->next){
|
||||
if(pl->ACLMatches(pcrefd->acl, param)){
|
||||
if(pl->ACLMatches(acl, param)){
|
||||
match = 1;
|
||||
break;
|
||||
}
|
||||
@@ -287,9 +314,9 @@ static FILTER_ACTION pcre_filter_buffer(void *fc, struct clientparam *param, uns
|
||||
for(; offset < *length_p; nreplaces++){
|
||||
int repsz;
|
||||
|
||||
count = pcre2_match(pcrefd->re, (PCRE2_SPTR)*buf_p, *length_p, offset, 0, pcrefd->match_data, pcrefd->match_context);
|
||||
count = pcre2_match(pcrefd->re, (PCRE2_SPTR)*buf_p, *length_p, offset, 0, pcd->match_data, pcrefd->match_context);
|
||||
if(count <= 0) break;
|
||||
ovector = pcre2_get_ovector_pointer(pcrefd->match_data);
|
||||
ovector = pcre2_get_ovector_pointer(pcd->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;
|
||||
|
||||
@@ -324,12 +351,17 @@ static FILTER_ACTION pcre_filter_buffer(void *fc, struct clientparam *param, uns
|
||||
else if(*replace == '$' && isnumber(*(replace+1))){
|
||||
replace ++;
|
||||
num = atoi(replace);
|
||||
/* Past the digits first, and only then decide whether
|
||||
the group is one to copy: the pass which measured
|
||||
this string did it in that order, and a reference it
|
||||
counted as nothing must not be written out as its
|
||||
own digits here. */
|
||||
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;
|
||||
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++;
|
||||
}
|
||||
else {
|
||||
*target++ = *replace++;
|
||||
@@ -338,7 +370,13 @@ static FILTER_ACTION pcre_filter_buffer(void *fc, struct clientparam *param, uns
|
||||
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);
|
||||
/* Room beyond what was produced: whoever asked for the
|
||||
filtering usually has something of its own to add, and a
|
||||
buffer sized to the last byte written leaves nowhere to
|
||||
put it. The size reported is the size allocated. */
|
||||
int newsize = ovector[0] + replen + 1 + PCRE_HEADROOM;
|
||||
|
||||
newbuf = pl->mallocfunc(newsize);
|
||||
if(!newbuf){
|
||||
pl->freefunc(tmpbuf);
|
||||
return CONTINUE;
|
||||
@@ -346,7 +384,7 @@ static FILTER_ACTION pcre_filter_buffer(void *fc, struct clientparam *param, uns
|
||||
memcpy(newbuf, *buf_p, ovector[0]);
|
||||
pl->freefunc(*buf_p);
|
||||
*buf_p = (unsigned char *)newbuf;
|
||||
*bufsize_p = ovector[0] + replen + 1;
|
||||
*bufsize_p = newsize;
|
||||
}
|
||||
memcpy(*buf_p + ovector[0], tmpbuf, replen);
|
||||
pl->freefunc(tmpbuf);
|
||||
@@ -362,7 +400,13 @@ static FILTER_ACTION pcre_filter_buffer(void *fc, struct clientparam *param, uns
|
||||
#undef pcrefd
|
||||
}
|
||||
|
||||
static void pcre_filter_clear(void *fo){
|
||||
static void pcre_filter_clear(void *fc){
|
||||
struct pcre_client_data *pcd = (struct pcre_client_data *)fc;
|
||||
|
||||
if(pcd){
|
||||
if(pcd->match_data) pcre2_match_data_free(pcd->match_data);
|
||||
pl->freefunc(pcd);
|
||||
}
|
||||
}
|
||||
|
||||
static void pcre_filter_close(void *fo){
|
||||
|
||||
@@ -109,15 +109,17 @@ struct sockfuncs sso;
|
||||
|
||||
static void genpaths(struct fp_stream *fps){
|
||||
|
||||
size_t len = strlen(path) + 32;
|
||||
|
||||
if(fps->what & (FP_CLIDATA|FP_CLIHEADER)){
|
||||
if(fps->fpd.path_cli) free(fps->fpd.path_cli);
|
||||
fps->fpd.path_cli = malloc(strlen(path) + 10);
|
||||
sprintf(fps->fpd.path_cli, path, counter++);
|
||||
fps->fpd.path_cli = malloc(len);
|
||||
if(fps->fpd.path_cli) sprintf(fps->fpd.path_cli, "%s%07d.tmp", path, counter++);
|
||||
}
|
||||
if(fps->what & (FP_SRVDATA|FP_SRVHEADER)){
|
||||
if(fps->fpd.path_srv) free(fps->fpd.path_srv);
|
||||
fps->fpd.path_srv = malloc(strlen(path) + 10);
|
||||
sprintf(fps->fpd.path_srv, path, counter++);
|
||||
fps->fpd.path_srv = malloc(len);
|
||||
if(fps->fpd.path_srv) sprintf(fps->fpd.path_srv, "%s%07d.tmp", path, counter++);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -139,6 +141,7 @@ static
|
||||
return fps->fpd.h_cli;
|
||||
#else
|
||||
if(fps->fpd.fd_cli != -1) close(fps->fpd.fd_cli);
|
||||
if(!fps->fpd.path_cli) return (fps->fpd.fd_cli = -1);
|
||||
fps->fpd.fd_cli = open(fps->fpd.path_cli, O_BINARY|O_RDWR|O_CREAT|O_TRUNC, 0600);
|
||||
return fps->fpd.fd_cli;
|
||||
#endif
|
||||
@@ -160,6 +163,7 @@ static
|
||||
return fps->fpd.h_srv;
|
||||
#else
|
||||
if(fps->fpd.fd_srv != -1) close(fps->fpd.fd_srv);
|
||||
if(!fps->fpd.path_srv) return (fps->fpd.fd_srv = -1);
|
||||
fps->fpd.fd_srv = open(fps->fpd.path_srv, O_BINARY|O_RDWR|O_CREAT|O_TRUNC, 0600);
|
||||
return fps->fpd.fd_srv;
|
||||
#endif
|
||||
@@ -282,7 +286,7 @@ void processcallbacks(struct fp_stream *fps, int what, char *msg, int size){
|
||||
case GOT_SMTP_REQ:
|
||||
case GOT_SMTP_DATA:
|
||||
fps->state = FLUSH_DATA;
|
||||
pl->socksend(fps->fpd.cp->sostate,fps->fpd.cp->clisock, (unsigned char *)fp_stringtable[1], (int)strlen((char *)fp_stringtable[1]), pl->conf->timeouts[STRING_S]);
|
||||
pl->socksend(NULL, fps->fpd.cp->clisock, (unsigned char *)fp_stringtable[1], (int)strlen((char *)fp_stringtable[1]), pl->conf->timeouts[STRING_S]);
|
||||
fps->state = state;
|
||||
break;
|
||||
case GOT_HTTP_REQUEST:
|
||||
@@ -294,7 +298,7 @@ void processcallbacks(struct fp_stream *fps, int what, char *msg, int size){
|
||||
case GOT_HTTP_SRVDATA:
|
||||
if(!fps->serversent){
|
||||
fps->state = FLUSH_DATA;
|
||||
pl->socksend(fps->fpd.cp->sostate, fps->fpd.cp->clisock, (unsigned char *)fp_stringtable[0], (int)strlen((char *)fp_stringtable[0]), pl->conf->timeouts[STRING_S]);
|
||||
pl->socksend(NULL, fps->fpd.cp->clisock, (unsigned char *)fp_stringtable[0], (int)strlen((char *)fp_stringtable[0]), pl->conf->timeouts[STRING_S]);
|
||||
fps->state = state;
|
||||
}
|
||||
break;
|
||||
@@ -302,7 +306,7 @@ void processcallbacks(struct fp_stream *fps, int what, char *msg, int size){
|
||||
case GOT_FTP_REQ:
|
||||
case GOT_FTP_SRVDATA:
|
||||
fps->state = FLUSH_DATA;
|
||||
pl->socksend(fps->fpd.cp->sostate, fps->fpd.cp->ctrlsock, (unsigned char *)fp_stringtable[1], (int)strlen((char *)fp_stringtable[1]), pl->conf->timeouts[STRING_S]);
|
||||
pl->socksend(NULL, fps->fpd.cp->ctrlsock, (unsigned char *)fp_stringtable[1], (int)strlen((char *)fp_stringtable[1]), pl->conf->timeouts[STRING_S]);
|
||||
fps->state = state;
|
||||
break;
|
||||
default:
|
||||
@@ -354,7 +358,7 @@ static int copyfdtosock(struct fp_stream * fps, DIRECTION which, long len){
|
||||
if(fps->serversent >= fps->srvhdrwritten){
|
||||
sprintf(fps->buf, "%lx\r\n", len);
|
||||
sendchunk = (int)strlen(fps->buf);
|
||||
if(pl->socksend(fps->fpd.cp->sostate, fps->fpd.cp->clisock, (unsigned char *)fps->buf, sendchunk, pl->conf->timeouts[STRING_S]) != sendchunk){
|
||||
if(pl->socksend(NULL, fps->fpd.cp->clisock, (unsigned char *)fps->buf, sendchunk, pl->conf->timeouts[STRING_S]) != sendchunk){
|
||||
return -4;
|
||||
}
|
||||
}
|
||||
@@ -393,13 +397,13 @@ static int copyfdtosock(struct fp_stream * fps, DIRECTION which, long len){
|
||||
#endif
|
||||
return -3;
|
||||
}
|
||||
if(pl->socksend(fps->fpd.cp->sostate, sock, (unsigned char *)fps->buf, res, pl->conf->timeouts[STRING_S]) != res) {
|
||||
if(pl->socksend(NULL, sock, (unsigned char *)fps->buf, res, pl->conf->timeouts[STRING_S]) != res) {
|
||||
return -4;
|
||||
}
|
||||
len -= res;
|
||||
}
|
||||
if(sendchunk){
|
||||
if(pl->socksend(fps->fpd.cp->sostate, sock, (unsigned char *)"\r\n", 2, pl->conf->timeouts[STRING_S]) != 2)
|
||||
if(pl->socksend(NULL, sock, (unsigned char *)"\r\n", 2, pl->conf->timeouts[STRING_S]) != 2)
|
||||
return -4;
|
||||
}
|
||||
fps->state = state;
|
||||
@@ -871,17 +875,17 @@ static int h_cachedir(int argc, unsigned char **argv){
|
||||
size_t len;
|
||||
|
||||
dirp = (argc > 1)? (char *)argv[1] : getenv("TEMP");
|
||||
len = strlen(dirp);
|
||||
len = dirp? strlen(dirp) : 0;
|
||||
if(!dirp || !len || len > 200 || strchr(dirp, '%')) {
|
||||
fprintf(stderr, "FilePlugin: invalid directory path: %s\n", dirp);
|
||||
return (1);
|
||||
}
|
||||
#ifdef _WIN32
|
||||
if(dirp[len-1] == '\\') dirp[len-1] = 0;
|
||||
sprintf(path, "%.256s\\%%07d.tmp", dirp);
|
||||
sprintf(path, "%.256s\\", dirp);
|
||||
#else
|
||||
if(dirp[len-1] == '/') dirp[len-1] = 0;
|
||||
sprintf(path, "%.256s/%%07d.tmp", dirp);
|
||||
sprintf(path, "%.256s/", dirp);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -61,14 +61,9 @@ char **load_string(FILE *f,int max_count_str, int *countloadstr,
|
||||
|
||||
if (strstr(tmpbuf1,"[end]")==NULL)
|
||||
{
|
||||
/* find and replace \n \r*/
|
||||
rstr = tmpbuf1;
|
||||
while (*rstr!='\0')
|
||||
{
|
||||
if (*rstr=='\r' || *rstr=='\n' )
|
||||
{ *rstr='\0'; rstr++; }
|
||||
rstr++;
|
||||
}
|
||||
/* the line's end cut off: what the file says with \n is what is
|
||||
sent */
|
||||
tmpbuf1[strcspn(tmpbuf1, "\r\n")] = '\0';
|
||||
|
||||
while ((rstr=strstr(tmpbuf1,"\\n")))
|
||||
{
|
||||
|
||||
+76
-4
@@ -132,6 +132,12 @@ char * proxy_stringtable[] = {
|
||||
};
|
||||
|
||||
#define LINESIZE 32768
|
||||
/* "Content-Length: " plus 20 digits plus CRLF and a NUL, rounded up */
|
||||
#define CLHDRSIZE 48
|
||||
/* what the headers this proxy adds of its own can come to: a Forwarded or
|
||||
Via with a host name in it, a Connection, a Proxy-support and a
|
||||
Proxy-Authorization carrying an encoded user and password */
|
||||
#define HDRRESERVE 2048
|
||||
#define BUFSIZE (LINESIZE*2)
|
||||
#define FTPBUFSIZE 1536
|
||||
|
||||
@@ -151,6 +157,34 @@ static int send_st(struct clientparam *param, int idx){
|
||||
return socksend(param, param->clisock, (unsigned char *)proxy_stringtable[idx], pst_len(idx), conf.timeouts[STRING_S]);
|
||||
}
|
||||
|
||||
/* Makes room in a buffer whose size is tracked. A filter may hand back one
|
||||
holding exactly what it produced, so nothing may be added to it without
|
||||
asking for the room first. Returns 1 when the room cannot be had. */
|
||||
static int growbuf(unsigned char **buf, int *bufsize, int need){
|
||||
unsigned char *newbuf;
|
||||
|
||||
if(need <= *bufsize) return 0;
|
||||
need += BUFSIZE; /* for what follows too, not just this */
|
||||
if(!(newbuf = realloc(*buf, need))) return 1;
|
||||
*buf = newbuf;
|
||||
*bufsize = need;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Whether a request line names the host the previous one did, whatever its
|
||||
method: the connection to the server is kept for the same host only, and
|
||||
a POST after a GET to it is no reason to open another one. */
|
||||
static int samehost(const unsigned char *line, int len, const unsigned char *host, int hostlen){
|
||||
const unsigned char *p = (const unsigned char *)memchr(line, ' ', len);
|
||||
|
||||
if(!p || hostlen <= 0) return 0;
|
||||
p++;
|
||||
if(!strncasecmp((const char *)p, "http://", 7)) p += 7;
|
||||
if((int)(p - line) + hostlen >= len || strncasecmp((const char *)p, (const char *)host, hostlen))
|
||||
return 0;
|
||||
return p[hostlen] == '/' || p[hostlen] == ' ';
|
||||
}
|
||||
|
||||
static void freeptr(void *p){
|
||||
void **pp = (void **)p;
|
||||
if(*pp) { free(*pp); *pp = NULL; }
|
||||
@@ -245,7 +279,7 @@ void * proxychild(struct clientparam* param) {
|
||||
int clhdrofs_req = -1;
|
||||
int isconnect = 0;
|
||||
int redirect = 0;
|
||||
int prefix = 0, ckeepalive=0;
|
||||
int prefix = 0, hostofs = 0, ckeepalive=0;
|
||||
int ftp = 0;
|
||||
int ssoff = 0;
|
||||
#ifndef ANONYMOUS
|
||||
@@ -280,6 +314,27 @@ for(;;){
|
||||
clhdrofs_req = -1;
|
||||
param->nolongdatfilter = 0;
|
||||
|
||||
/* What the request brought belongs to it alone. A connection can carry
|
||||
a request after another's, so the credentials of an earlier request
|
||||
decide nothing for this one. */
|
||||
if(param->username){
|
||||
free(param->username);
|
||||
param->username = NULL;
|
||||
}
|
||||
if(param->password){
|
||||
free(param->password);
|
||||
param->password = NULL;
|
||||
}
|
||||
param->pwtype = 0;
|
||||
if(param->extusername){
|
||||
free(param->extusername);
|
||||
param->extusername = NULL;
|
||||
}
|
||||
if(param->extpassword){
|
||||
free(param->extpassword);
|
||||
param->extpassword = NULL;
|
||||
}
|
||||
|
||||
|
||||
if(keepalive && (param->cliinbuf == param->clioffset) && (param->remsock != INVALID_SOCKET)){
|
||||
memset(fds, 0, sizeof(fds));
|
||||
@@ -313,7 +368,7 @@ for(;;){
|
||||
buf[i] = 0;
|
||||
|
||||
if(req) {
|
||||
if(!param->transparent && !param->srv->transparent && (i<=prefix || strncasecmp((char *)buf, (char *)req, prefix))){
|
||||
if(!param->transparent && !param->srv->transparent && !samehost(buf, i, req + hostofs, prefix - hostofs)){
|
||||
ckeepalive = 0;
|
||||
if(param->remsock != INVALID_SOCKET){
|
||||
param->srv->so._shutdown(param->sostate, param->remsock, SHUT_RDWR);
|
||||
@@ -368,6 +423,7 @@ for(;;){
|
||||
*se = 0;
|
||||
}
|
||||
prefix = (int)(se - buf);
|
||||
hostofs = (int)(sb - buf);
|
||||
su = (unsigned char*)strrchr((char *)sb, '@');
|
||||
if(su) {
|
||||
su = (unsigned char *)strdup((char *)sb);
|
||||
@@ -587,6 +643,10 @@ for(;;){
|
||||
RETURN(0);
|
||||
}
|
||||
if(action != PASS) RETURN(517);
|
||||
/* A filter may have returned a buffer sized to exactly what it produced.
|
||||
The headers this proxy adds of its own go in after it, so the room for
|
||||
them is taken back before anything is written. */
|
||||
if(growbuf(&buf, &bufsize, inbuf + HDRRESERVE)) RETURN(21);
|
||||
param->nolongdatfilter = 0;
|
||||
|
||||
#endif
|
||||
@@ -620,6 +680,7 @@ for(;;){
|
||||
contentlength64 = param->cliinbuf;
|
||||
param->nolongdatfilter = 1;
|
||||
}
|
||||
if(growbuf(&buf, &bufsize, (int)strlen((char *)buf) + CLHDRSIZE)) RETURN(21);
|
||||
sprintf((char*)buf+strlen((char *)buf), "Content-Length: %"PRIu64"\r\n", contentlength64);
|
||||
}
|
||||
|
||||
@@ -831,12 +892,20 @@ for(;;){
|
||||
send_st(param, 9);
|
||||
}
|
||||
if((unsigned)socksend(param, param->clisock, buf, inbuf, conf.timeouts[STRING_S]) != inbuf){
|
||||
param->srv->so._closesocket(param->sostate, ftps);
|
||||
ftps = INVALID_SOCKET;
|
||||
param->remsock = s;
|
||||
RETURN(781);
|
||||
}
|
||||
inbuf = 0;
|
||||
}
|
||||
else {
|
||||
if(!(newbuf = realloc(buf, bufsize + BUFSIZE))){RETURN (21);}
|
||||
if(!(newbuf = realloc(buf, bufsize + BUFSIZE))){
|
||||
param->srv->so._closesocket(param->sostate, ftps);
|
||||
ftps = INVALID_SOCKET;
|
||||
param->remsock = s;
|
||||
RETURN (21);
|
||||
}
|
||||
buf = newbuf;
|
||||
bufsize += BUFSIZE;
|
||||
}
|
||||
@@ -929,7 +998,8 @@ for(;;){
|
||||
if(param->extusername){
|
||||
hlen += sprintf((char*)buf + hlen, "%s: Basic ", (redirect)?"Proxy-Authorization":"Authorization");
|
||||
sprintf((char*)username, "%.128s:%.128s", param->extusername, param->extpassword?param->extpassword:(unsigned char*)"");
|
||||
hlen = (int)(en64(username, buf + hlen, (int)strlen((char *)username)) - buf);
|
||||
if(!(sb = en64(username, buf + hlen, (int)strlen((char *)username), bufsize - hlen))) {RETURN(21);}
|
||||
hlen = (int)(sb - buf);
|
||||
hlen += sprintf((char*)buf + hlen, "\r\n");
|
||||
}
|
||||
hlen += sprintf((char*)buf + hlen, "\r\n");
|
||||
@@ -1088,6 +1158,7 @@ for(;;){
|
||||
RETURN(0);
|
||||
}
|
||||
if(action != PASS) RETURN(517);
|
||||
if(growbuf(&buf, &bufsize, inbuf + HDRRESERVE)) RETURN(21);
|
||||
|
||||
param->nolongdatfilter = 0;
|
||||
|
||||
@@ -1111,6 +1182,7 @@ for(;;){
|
||||
}
|
||||
if(action != PASS) RETURN(517);
|
||||
contentlength64 = param->srvinbuf;
|
||||
if(growbuf(&buf, &bufsize, (int)strlen((char *)buf) + CLHDRSIZE)) RETURN(21);
|
||||
sprintf((char*)buf+strlen((char *)buf), "Content-Length: %"PRIu64"\r\n", contentlength64);
|
||||
hascontent = 1;
|
||||
}
|
||||
|
||||
+31
-2
@@ -135,6 +135,23 @@ void daemonize(void);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* wolfSSL reserves around 48K of static thread-local storage. glibc counts
|
||||
that against the thread stack, so pthread_create() fails with EINVAL and
|
||||
no thread starts at all. musl places the block next to the stack instead
|
||||
of inside it and needs nothing extra, and OpenSSL has no static TLS.
|
||||
musl identifies itself by no macro of its own, but it does not define
|
||||
__GLIBC__, which any libc header pulled in above would have set.
|
||||
*/
|
||||
#ifndef TLSSTACKSIZE
|
||||
#if defined(__linux__) && !defined(__GLIBC__)
|
||||
#define TLSSTACKSIZE 0
|
||||
#elif defined(WITH_WOLFSSL)
|
||||
#define TLSSTACKSIZE 49152
|
||||
#else
|
||||
#define TLSSTACKSIZE 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
size_t threadstacksize(int extra);
|
||||
#endif
|
||||
@@ -154,7 +171,8 @@ size_t threadstacksize(int extra);
|
||||
#ifndef strncasecmp
|
||||
#define strncasecmp strnicmp
|
||||
#endif
|
||||
#define seterrno3(x) _set_errno(x)
|
||||
/* errno is WSAGetLastError() here */
|
||||
#define seterrno3(x) WSASetLastError(x)
|
||||
#else
|
||||
#define seterrno3(x) (errno = x)
|
||||
#endif
|
||||
@@ -204,6 +222,11 @@ extern int timeouts[12];
|
||||
|
||||
int sockmap(struct clientparam * param, int timeo, int usesplice);
|
||||
int udpsockmap(struct clientparam * param, int timeo);
|
||||
int udpbind(struct clientparam * param);
|
||||
int socks5_setaddr(int family, int atyp, const unsigned char *addr, PROXYSOCKADDRTYPE *sa);
|
||||
#ifdef __linux__
|
||||
int switch_ns(struct srvparam *srv, int target_fd);
|
||||
#endif
|
||||
int socksend(struct clientparam *param, SOCKET sock, unsigned char * buf, int bufsize, int to);
|
||||
int socksendto(struct clientparam *param, SOCKET sock, struct sockaddr * sin, unsigned char * buf, int bufsize, int to);
|
||||
int sockrecvfrom(struct clientparam *param, SOCKET sock, struct sockaddr * sin, unsigned char * buf, int bufsize, int to);
|
||||
@@ -271,7 +294,7 @@ extern int demon;
|
||||
unsigned char * mycrypt(const unsigned char *key, const unsigned char *salt, unsigned char *buf);
|
||||
unsigned char * ntpwdhash (unsigned char *szHash, const unsigned char *szPassword, int tohex);
|
||||
int de64 (const unsigned char *in, unsigned char *out, int maxlen);
|
||||
unsigned char* en64 (const unsigned char *in, unsigned char *out, int inlen);
|
||||
unsigned char* en64 (const unsigned char *in, unsigned char *out, int inlen, int outsize);
|
||||
void tohex(unsigned char *in, unsigned char *out, int len);
|
||||
void fromhex(unsigned char *in, unsigned char *out, int len);
|
||||
|
||||
@@ -312,6 +335,7 @@ void hashdelete(struct hashtable *ht, void* name);
|
||||
int hashresolv(struct hashtable *ht, void* name, void* value, uint32_t *ttl);
|
||||
|
||||
int parsehost(int family, unsigned char *host, struct sockaddr *sa);
|
||||
int badhostname(const char *hostname);
|
||||
int parsehostname(char *hostname, struct clientparam *param, uint16_t port);
|
||||
int parseusername(char *username, struct clientparam *param, int extpasswd);
|
||||
int parseconnusername(char *username, struct clientparam *param, int extpasswd, uint16_t port);
|
||||
@@ -347,6 +371,11 @@ unsigned char * dologname (unsigned char *buf, unsigned char *name, const unsign
|
||||
int readconfig(FILE * fp);
|
||||
void initcommands(void);
|
||||
int connectwithpoll(struct clientparam *param, SOCKET sock, struct sockaddr *sa, SASIZETYPE size, int to);
|
||||
void nonblock(SOCKET sock);
|
||||
int acceptagain(void);
|
||||
int bindtodevice(struct sockfuncs *sf, void *state, SOCKET sock, const char *device, int family);
|
||||
int extbindtodevice(struct clientparam *param, SOCKET sock);
|
||||
int intbindtodevice(struct clientparam *param, SOCKET sock);
|
||||
|
||||
|
||||
uint32_t myrand(void);
|
||||
|
||||
+149
-44
@@ -7,6 +7,31 @@
|
||||
*/
|
||||
|
||||
#include "proxy.h"
|
||||
|
||||
#ifdef WITH_UN
|
||||
/* A service bound to a Unix socket path notes its file, as a service of a
|
||||
newer configuration may bind the same path before this one closes: the
|
||||
file is then the other's, which closing must not remove. */
|
||||
static void unbound(struct srvparam *srv){
|
||||
struct stat st;
|
||||
|
||||
if(*SAFAMILY(&srv->intsa) == AF_UNIX && *SAADDR(&srv->intsa) &&
|
||||
!stat((char *)SAADDR(&srv->intsa), &st)){
|
||||
srv->undev = (uint64_t)st.st_dev;
|
||||
srv->unino = (uint64_t)st.st_ino;
|
||||
}
|
||||
}
|
||||
|
||||
static void ununlink(struct srvparam *srv){
|
||||
struct stat st;
|
||||
|
||||
if(*SAFAMILY(&srv->intsa) == AF_UNIX && *SAADDR(&srv->intsa) &&
|
||||
!stat((char *)SAADDR(&srv->intsa), &st) &&
|
||||
(uint64_t)st.st_dev == srv->undev && (uint64_t)st.st_ino == srv->unino)
|
||||
unlink((char *)SAADDR(&srv->intsa));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
#include <sched.h>
|
||||
#endif
|
||||
@@ -63,6 +88,8 @@ void * threadfunc (void *p) {
|
||||
}
|
||||
param->remsock = param->srv->so._accept(param->sostate, param->srv->cbsock, (struct sockaddr*)¶m->sinsr, &size);
|
||||
if(param->remsock == INVALID_SOCKET) {
|
||||
/* another client of the service took it: not a try */
|
||||
if(acceptagain()) { i++; continue; }
|
||||
dolog(param, (unsigned char *)"Connect back accept() failed");
|
||||
continue;
|
||||
}
|
||||
@@ -84,7 +111,7 @@ void * threadfunc (void *p) {
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
if(socksendto(param, param->remsock, (struct sockaddr*)¶m->sinsr, (unsigned char *)"C", 1, CONNBACK_TO*1000) != 1){
|
||||
if(socksend(param, param->remsock, (unsigned char *)"C", 1, CONNBACK_TO) != 1){
|
||||
dolog(param, (unsigned char *)"Connect back sending command failed");
|
||||
param->srv->so._closesocket(param->sostate, param->remsock);
|
||||
param->remsock = INVALID_SOCKET;
|
||||
@@ -306,7 +333,9 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
unsigned char *cbc_string = NULL, *cbl_string = NULL;
|
||||
PROXYSOCKADDRTYPE cbsa;
|
||||
FILE *fp = NULL;
|
||||
#ifndef _WIN32
|
||||
struct linger lg;
|
||||
#endif
|
||||
int nlog = 5000;
|
||||
#ifdef __linux__
|
||||
int saved_nsfd = -1;
|
||||
@@ -329,7 +358,14 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
#endif
|
||||
#ifdef WITHSPLICE
|
||||
" -s Use splice() - no filtering for data, off by default\n"
|
||||
" -C connection closed by any of the sides terminates the session, by default\n"
|
||||
" the session is kept until both sides close it (TCP half-close)\n"
|
||||
" -U(0-3) (for socks) what to do when the destination changes within an UDP\n"
|
||||
" association: 1 - log, 2 - authorize, 3 - both (default), 0 (same as -U) -\n"
|
||||
" neither. The first destination is always authorized and logged\n"
|
||||
#endif
|
||||
" -B split the TLS ClientHello passed through tlspr at the SNI (DPI bypass),\n"
|
||||
" with -ocTCP_NODELAY -osTCP_NODELAY\n"
|
||||
"-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"
|
||||
" -l log to stderr\n"
|
||||
@@ -386,6 +422,9 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
WSADATA wd;
|
||||
WSAStartup(MAKEWORD( 1, 1 ), &wd);
|
||||
|
||||
#else
|
||||
/* a client gone while it is written to is an error, not the end */
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -500,8 +539,8 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
}
|
||||
break;
|
||||
case 'N':
|
||||
if(argv[i][3] == 'e') getip46(46, (unsigned char *)argv[i]+3, (struct sockaddr *)&srv.extNat);
|
||||
else if(argv[i][3] == 'i') getip46(46, (unsigned char *)argv[i]+3, (struct sockaddr *)&srv.intNat);
|
||||
if(argv[i][2] == 'e') getip46(46, (unsigned char *)argv[i]+3, (struct sockaddr *)&srv.extNat);
|
||||
else if(argv[i][2] == 'i') getip46(46, (unsigned char *)argv[i]+3, (struct sockaddr *)&srv.intNat);
|
||||
else getip46(46, (unsigned char *)argv[i]+2, (struct sockaddr *)&srv.extNat);
|
||||
break;
|
||||
case 'n':
|
||||
@@ -596,6 +635,19 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
case 'g':
|
||||
sscanf(argv[i]+2, "%d,%d,%d", &srv.gracetraf, &srv.gracenum, &srv.gracedelay);
|
||||
break;
|
||||
case 'C':
|
||||
srv.halfclose = *(argv[i]+2)? atoi(argv[i]+2) : 0;
|
||||
break;
|
||||
case 'U':
|
||||
srv.udpauth = *(argv[i]+2)? atoi(argv[i]+2) : 0;
|
||||
break;
|
||||
case 'B':
|
||||
/* the TLS ClientHello split at the SNI (tlspr), which -s is
|
||||
where -s is not splice; s_option means something else
|
||||
for these */
|
||||
if(!isudp && srv.service != S_ADMIN)
|
||||
srv.s_option = 1 + atoi(argv[i]+2);
|
||||
break;
|
||||
case 's':
|
||||
#ifdef WITHSPLICE
|
||||
if(isudp || srv.service == S_ADMIN)
|
||||
@@ -674,7 +726,12 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
else {
|
||||
#endif
|
||||
#ifndef NOPORTMAP
|
||||
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) {
|
||||
/* the port of a Unix socket target is ignored, 0 as the manual has it */
|
||||
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
|
||||
#ifdef WITH_UN
|
||||
&& strncmp(argv[i+1], "unix:", 5)
|
||||
#endif
|
||||
)) {
|
||||
#ifndef STDMAIN
|
||||
haveerror = 1;
|
||||
#endif
|
||||
@@ -819,35 +876,25 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
#ifndef _WIN32
|
||||
opt = 1;
|
||||
if(srv.so._setsockopt(srv.so.state, sock, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(int)))perror("setsockopt()");
|
||||
#else
|
||||
/* A UDP service on Windows answers from a second socket bound to
|
||||
the address it listens on, and Windows only allows that bind
|
||||
when both sockets ask for it. */
|
||||
if(isudp){
|
||||
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));
|
||||
#endif
|
||||
}
|
||||
#if defined SO_BINDTODEVICE
|
||||
if(srv.ibindtodevice && srv.so._setsockopt(srv.so.state, sock, SOL_SOCKET, SO_BINDTODEVICE, srv.ibindtodevice, strlen(srv.ibindtodevice) + 1)) {
|
||||
#if defined SO_BINDTODEVICE || defined IP_BOUND_IF
|
||||
if(bindtodevice(&srv.so, srv.so.state, sock, srv.ibindtodevice, *SAFAMILY(&srv.intsa))) {
|
||||
dolog(&defparam, (unsigned char *)"failed to bind device");
|
||||
return -12;
|
||||
}
|
||||
#elif defined IP_BOUND_IF
|
||||
if(srv.ibindtodevice){
|
||||
int idx;
|
||||
idx = if_nametoindex(srv.ibindtodevice);
|
||||
if(!idx || (*SAFAMILY(&srv.intsa) == AF_INET && setsockopt(sock, IPPROTO_IP, IP_BOUND_IF, &idx, sizeof(idx)))) {
|
||||
dolog(&defparam, (unsigned char *)"failed to bind device");
|
||||
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;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifdef WITH_UN
|
||||
@@ -867,6 +914,9 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
#ifdef WITH_UN
|
||||
unbound(&srv);
|
||||
#endif
|
||||
if(!isudp){
|
||||
if(srv.so._listen (srv.so.state, sock, srv.backlog?srv.backlog : 1+(srv.maxchild>>3))==-1) {
|
||||
sprintf((char *)buf, "listen(): %s", strerror(errno));
|
||||
@@ -945,6 +995,8 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
#endif
|
||||
|
||||
setopts(srv.cbsock, srv.cbssockopts);
|
||||
/* the clients of the service all wait for it: one accepts what comes */
|
||||
nonblock(srv.cbsock);
|
||||
|
||||
if(srv.so._bind(srv.so.state, srv.cbsock, (struct sockaddr*)&cbsa, SASIZE(&cbsa))==-1) {
|
||||
dolog(&defparam, (unsigned char *)"Failed to bind connect back socket");
|
||||
@@ -1001,6 +1053,15 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
setopts(new_sock, srv.cbcsockopts);
|
||||
|
||||
parsehost(srv.family, cbc_string, (struct sockaddr *)&defparam.sincr);
|
||||
#if defined SO_BINDTODEVICE || defined IP_BOUND_IF
|
||||
/* as for a listening socket, an interface that cannot be
|
||||
bound to is not worth retrying */
|
||||
if(bindtodevice(&so, so.state, new_sock, srv.ibindtodevice, *SAFAMILY(&defparam.sincr))) {
|
||||
dolog(&defparam, (unsigned char *)"failed to bind device");
|
||||
so._closesocket(so.state, new_sock);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
if(connectwithpoll(NULL, new_sock,(struct sockaddr *)&defparam.sincr,SASIZE(&defparam.sincr),CONNBACK_TO)) {
|
||||
so._closesocket(so.state, new_sock);
|
||||
new_sock = INVALID_SOCKET;
|
||||
@@ -1008,7 +1069,7 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
continue;
|
||||
}
|
||||
|
||||
if(sockrecvfrom(NULL, new_sock,(struct sockaddr*)&defparam.sincr,buf,1,60*1000) != 1 || *buf!='C') {
|
||||
if(sockrecvfrom(NULL, new_sock, NULL, buf, 1, 60*1000) != 1 || *buf!='C') {
|
||||
so._closesocket(so.state, new_sock);
|
||||
new_sock = INVALID_SOCKET;
|
||||
usleep(SLEEPTIME);
|
||||
@@ -1083,10 +1144,14 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
#else
|
||||
fcntl(new_sock,F_SETFL,O_NONBLOCK | fcntl(new_sock,F_GETFL));
|
||||
#endif
|
||||
#ifndef _WIN32
|
||||
/* Not on Windows: there closesocket() on a non-blocking socket with a linger
|
||||
timeout fails with WSAEWOULDBLOCK while data is queued, leaving the socket
|
||||
open. Without it the close completes in the background, data first. */
|
||||
lg.l_onoff = 1;
|
||||
lg.l_linger = conf.timeouts[STRING_L];
|
||||
|
||||
srv.so._setsockopt(srv.so.state, new_sock, SOL_SOCKET, SO_LINGER, (char *)&lg, sizeof(lg));
|
||||
#endif
|
||||
srv.so._setsockopt(srv.so.state, new_sock, SOL_SOCKET, SO_OOBINLINE, (char *)&opt, sizeof(int));
|
||||
}
|
||||
#ifndef NOUDPMAIN
|
||||
@@ -1247,6 +1312,8 @@ void srvinit(struct srvparam * srv, struct clientparam *param){
|
||||
#ifdef WITHSPLICE
|
||||
srv->usesplice = 0;
|
||||
#endif
|
||||
srv->halfclose = 1;
|
||||
srv->udpauth = 3;
|
||||
memset(param, 0, sizeof(struct clientparam));
|
||||
param->srv = srv;
|
||||
param->version = srv->version;
|
||||
@@ -1302,14 +1369,23 @@ void srvfree(struct srvparam * srv){
|
||||
if(srv->srvsock != INVALID_SOCKET) {
|
||||
so._closesocket(srv->so.state, srv->srvsock);
|
||||
#ifdef WITH_UN
|
||||
if(*SAFAMILY(&srv->intsa) == AF_UNIX && *SAADDR(&srv->intsa))unlink((char *)SAADDR(&srv->intsa));
|
||||
ununlink(srv);
|
||||
#endif
|
||||
}
|
||||
srv->srvsock = INVALID_SOCKET;
|
||||
if(srv->cbsock != INVALID_SOCKET) so._closesocket(srv->so.state, srv->cbsock);
|
||||
srv->cbsock = INVALID_SOCKET;
|
||||
srv->service = S_ZOMBIE;
|
||||
while(srv->child) usleep(SLEEPTIME * 100);
|
||||
/* under the mutex, so the last child has let go of it before it is destroyed */
|
||||
for(;;){
|
||||
struct clientparam *child;
|
||||
|
||||
_3proxy_mutex_lock(&srv->counter_mutex);
|
||||
child = srv->child;
|
||||
_3proxy_mutex_unlock(&srv->counter_mutex);
|
||||
if(!child) break;
|
||||
usleep(SLEEPTIME * 100);
|
||||
}
|
||||
#ifndef STDMAIN
|
||||
if(srv->filter){
|
||||
while(srv->nfilters){
|
||||
@@ -1349,43 +1425,46 @@ void srvfree(struct srvparam * srv){
|
||||
|
||||
|
||||
void freeparam(struct clientparam * param) {
|
||||
if(param->res == 2) return;
|
||||
if(param->srv){
|
||||
if(param->srv->so.freefunc) param->srv->so.freefunc(param->sostate);
|
||||
_3proxy_mutex_lock(¶m->srv->counter_mutex);
|
||||
#ifndef STDMAIN
|
||||
if(param->srv->service == S_UDPPM) hashdelete(&udp_table, param);
|
||||
#endif
|
||||
if(param->prev || param->next || param->srv->child == param){
|
||||
if(param->prev){
|
||||
param->prev->next = param->next;
|
||||
}
|
||||
else
|
||||
param->srv->child = param->next;
|
||||
if(param->next){
|
||||
param->next->prev = param->prev;
|
||||
}
|
||||
(param->srv->childcount)--;
|
||||
if(param->srv->service == S_UDPPM){
|
||||
_3proxy_mutex_lock(¶m->srv->counter_mutex);
|
||||
hashdelete(&udp_table, param);
|
||||
_3proxy_mutex_unlock(¶m->srv->counter_mutex);
|
||||
}
|
||||
_3proxy_mutex_unlock(¶m->srv->counter_mutex);
|
||||
#endif
|
||||
}
|
||||
if(param->clibuf) free(param->clibuf);
|
||||
if(param->srvbuf) free(param->srvbuf);
|
||||
/* Not shut down on Windows: there shutting down receiving resets the
|
||||
connection as soon as the peer sends anything more, and close()
|
||||
alone sends whatever is queued before its FIN. Elsewhere it stays:
|
||||
on the BSDs it discards what is left unread, so the close that
|
||||
follows is not turned into a reset. */
|
||||
if(param->srv) {
|
||||
if(param->ctrlsocksrv != INVALID_SOCKET && param->ctrlsocksrv != param->remsock) {
|
||||
#ifndef _WIN32
|
||||
param->srv->so._shutdown(param->sostate, param->ctrlsocksrv, SHUT_RDWR);
|
||||
#endif
|
||||
param->srv->so._closesocket(param->sostate, param->ctrlsocksrv);
|
||||
}
|
||||
if(param->ctrlsock != INVALID_SOCKET && param->ctrlsock != param->clisock) {
|
||||
#ifndef _WIN32
|
||||
param->srv->so._shutdown(param->sostate, param->ctrlsock, SHUT_RDWR);
|
||||
#endif
|
||||
param->srv->so._closesocket(param->sostate, param->ctrlsock);
|
||||
}
|
||||
if(param->remsock != INVALID_SOCKET) {
|
||||
#ifndef _WIN32
|
||||
param->srv->so._shutdown(param->sostate, param->remsock, SHUT_RDWR);
|
||||
#endif
|
||||
param->srv->so._closesocket(param->sostate, param->remsock);
|
||||
}
|
||||
if(param->clisock != INVALID_SOCKET) {
|
||||
#ifndef _WIN32
|
||||
param->srv->so._shutdown(param->sostate, param->clisock, SHUT_RDWR);
|
||||
#endif
|
||||
param->srv->so._closesocket(param->sostate, param->clisock);
|
||||
}
|
||||
}
|
||||
@@ -1407,6 +1486,24 @@ void freeparam(struct clientparam * param) {
|
||||
}
|
||||
if(param->connlim) stopconnlims(param);
|
||||
#endif
|
||||
/* Leaving the service comes last. Once its last child is gone, srvfree()
|
||||
frees the service along with its socket functions, filters and mutex,
|
||||
and a close above may have lingered for seconds before getting here. */
|
||||
if(param->srv){
|
||||
_3proxy_mutex_lock(¶m->srv->counter_mutex);
|
||||
if(param->prev || param->next || param->srv->child == param){
|
||||
if(param->prev){
|
||||
param->prev->next = param->next;
|
||||
}
|
||||
else
|
||||
param->srv->child = param->next;
|
||||
if(param->next){
|
||||
param->next->prev = param->prev;
|
||||
}
|
||||
(param->srv->childcount)--;
|
||||
}
|
||||
_3proxy_mutex_unlock(¶m->srv->counter_mutex);
|
||||
}
|
||||
if(param->hostname) free(param->hostname);
|
||||
if(param->username) free(param->username);
|
||||
if(param->password) free(param->password);
|
||||
@@ -1646,9 +1743,17 @@ FILTER_ACTION makefilters (struct srvparam *srv, struct clientparam *param){
|
||||
|
||||
for(i=0; i<srv->nfilters; i++){
|
||||
if(!srv->filter[i].filter_client)continue;
|
||||
/* the slots are not cleared when they are allocated */
|
||||
param->filters[param->nfilters].data = NULL;
|
||||
action = (*srv->filter[i].filter_client)(srv->filter[i].data, param, ¶m->filters[param->nfilters].data);
|
||||
if(action == PASS) continue;
|
||||
if(action > CONTINUE) return action;
|
||||
if(action > CONTINUE) {
|
||||
/* a filter refusing the connection is not kept, but it may
|
||||
have made a state for it */
|
||||
if(srv->filter[i].filter_clear && param->filters[param->nfilters].data)
|
||||
(*srv->filter[i].filter_clear)(param->filters[param->nfilters].data);
|
||||
return action;
|
||||
}
|
||||
param->filters[param->nfilters].filter = srv->filter + i;
|
||||
if(srv->filter[i].filter_request)param->reqfilters[param->nreqfilters++] = param->filters + param->nfilters;
|
||||
if(srv->filter[i].filter_connect)param->connectfilters[param->nconnectfilters++] = param->filters + param->nfilters;
|
||||
|
||||
+4
-4
@@ -70,7 +70,7 @@ int clientnegotiate(struct chain * redir, struct clientparam * param, struct soc
|
||||
if(user){
|
||||
len += sprintf((char *)buf + len, "Proxy-Authorization: Basic ");
|
||||
sprintf((char *)username, "%.128s:%.128s", user, pass?pass:(unsigned char *)"");
|
||||
en64(username, buf+len, (int)strlen((char *)username));
|
||||
if(!en64(username, buf+len, (int)strlen((char *)username), 2048 - len)) return 21;
|
||||
len = (int)strlen((char *)buf);
|
||||
len += sprintf((char *)buf + len, "\r\n");
|
||||
}
|
||||
@@ -270,8 +270,6 @@ int handleredirect(struct clientparam * param, struct ace * acentry){
|
||||
int r2;
|
||||
int saved = 0;
|
||||
|
||||
if(param->remsock != INVALID_SOCKET && param->operation != UDPASSOC) {
|
||||
}
|
||||
if((SAISNULL(¶m->req) || !*SAPORT(¶m->req)) && param->operation != UDPASSOC) {
|
||||
return 100;
|
||||
}
|
||||
@@ -287,7 +285,7 @@ int handleredirect(struct clientparam * param, struct ace * acentry){
|
||||
}
|
||||
continue;
|
||||
}
|
||||
param->redirected++;
|
||||
if(cur->type != R_EXTIP && cur->type != R_HA) param->redirected++;
|
||||
done = 1;
|
||||
if(weight <= 0) {
|
||||
weight += 1000;
|
||||
@@ -342,6 +340,7 @@ int handleredirect(struct clientparam * param, struct ace * acentry){
|
||||
}
|
||||
if(cur->next)continue;
|
||||
if(!ha) return 0;
|
||||
if(param->operation == UDPASSOC) return 0;
|
||||
}
|
||||
else if(!*SAPORT(&cur->addr) && !SAISNULL(&cur->addr)) {
|
||||
uint16_t port = *SAPORT(¶m->sinsr);
|
||||
@@ -354,6 +353,7 @@ int handleredirect(struct clientparam * param, struct ace * acentry){
|
||||
}
|
||||
if(param->operation == UDPASSOC){
|
||||
SOCKET s;
|
||||
if(cur->type != R_SOCKS5 && cur->type != R_SOCKS5P) return 70;
|
||||
s = param->remsock;
|
||||
param->remsock = INVALID_SOCKET;
|
||||
param->ctrlsocksrv = s;
|
||||
|
||||
+56
-17
@@ -3,6 +3,19 @@
|
||||
struct nserver nservers[MAXNSERVERS] = {{{0},0}, {{0},0}, {{0},0}, {{0},0}, {{0},0}};
|
||||
struct nserver authnserver;
|
||||
|
||||
static int dnsqmatch(const unsigned char *a, const unsigned char *b, int len){
|
||||
int i;
|
||||
|
||||
for(i = 0; i < len; i++){
|
||||
unsigned char c1 = a[i], c2 = b[i];
|
||||
|
||||
if(c1 >= 'A' && c1 <= 'Z') c1 += 'a' - 'A';
|
||||
if(c2 >= 'A' && c2 <= 'Z') c2 += 'a' - 'A';
|
||||
if(c1 != c2) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
uint32_t udpresolve(int af, unsigned char * name, unsigned char * value, uint32_t *retttl, struct clientparam* param, int makeauth){
|
||||
|
||||
@@ -23,9 +36,12 @@ uint32_t udpresolve(int af, unsigned char * name, unsigned char * value, uint32_
|
||||
SOCKET sock;
|
||||
uint32_t ttl;
|
||||
PROXYSOCKADDRTYPE addr;
|
||||
PROXYSOCKADDRTYPE from;
|
||||
PROXYSOCKADDRTYPE *sinsr, *sinsl;
|
||||
int usetcp = 0;
|
||||
unsigned short serial = 1;
|
||||
unsigned char qbuf[300];
|
||||
int qlen;
|
||||
|
||||
buf = b+2;
|
||||
|
||||
@@ -92,6 +108,9 @@ uint32_t udpresolve(int af, unsigned char * name, unsigned char * value, uint32_
|
||||
buf[len++] = (makeauth == 1)? 0x0c : (af==AF_INET6? 0x1c:0x01);/* PTR:host address */
|
||||
buf[len++] = 0;
|
||||
buf[len++] = 1; /* INET */
|
||||
qlen = len - 12;
|
||||
memcpy(qbuf, buf + 12, qlen);
|
||||
|
||||
if(usetcp){
|
||||
buf-=2;
|
||||
*(unsigned short*)buf = htons(len);
|
||||
@@ -104,30 +123,47 @@ uint32_t udpresolve(int af, unsigned char * name, unsigned char * value, uint32_
|
||||
continue;
|
||||
}
|
||||
if(param) param->statscli64 += len;
|
||||
len = sockrecvfrom(NULL, sock, (struct sockaddr *)sinsr, buf, 4096, conf.timeouts[DNS_TO]*1000);
|
||||
len = sockrecvfrom(NULL, sock, (struct sockaddr *)&from, buf, 4096, conf.timeouts[DNS_TO]*1000);
|
||||
if(len > 13 && usetcp){
|
||||
unsigned short us;
|
||||
us = ntohs(*(unsigned short*)buf);
|
||||
len-=2;
|
||||
buf+=2;
|
||||
if(us > 4096 || us < len) len = 0;
|
||||
else if(us > len){
|
||||
if(sockrecvfrom(NULL, sock, (struct sockaddr *)&from, buf+len, us-len, conf.timeouts[DNS_TO]*1000) != us-len) len = 0;
|
||||
else len = us;
|
||||
}
|
||||
}
|
||||
so._shutdown(so.state, sock, SHUT_RDWR);
|
||||
so._closesocket(so.state, sock);
|
||||
if(len <= 13) {
|
||||
continue;
|
||||
}
|
||||
if(param) param->statssrv64 += len;
|
||||
if(usetcp){
|
||||
unsigned short us;
|
||||
us = ntohs(*(unsigned short*)buf);
|
||||
len-=2;
|
||||
buf+=2;
|
||||
if(us > 4096 || us < len || (us > len && sockrecvfrom(NULL, sock, (struct sockaddr *)sinsr, buf+len, us-len, conf.timeouts[DNS_TO]*1000) != us-len)) {
|
||||
continue;
|
||||
}
|
||||
if(!usetcp && (*SAFAMILY(&from) != *SAFAMILY(sinsr) ||
|
||||
memcmp(SAADDR(&from), SAADDR(sinsr), SAADDRLEN(sinsr)) ||
|
||||
*SAPORT(&from) != *SAPORT(sinsr))) {
|
||||
continue; /* not from the server we asked */
|
||||
}
|
||||
if(*(unsigned short *)buf != serial)continue;
|
||||
if((na = buf[7] + (((unsigned short)buf[6])<<8)) < 1) {
|
||||
return 0;
|
||||
}
|
||||
if(!(buf[2] & 0x80)) continue; /* not a response */
|
||||
nq = buf[5] + (((unsigned short)buf[4])<<8);
|
||||
if (nq != 1) {
|
||||
continue; /* we did only 1 request */
|
||||
}
|
||||
if(len < 12 + qlen || dnsqmatch(buf + 12, qbuf, qlen)) {
|
||||
continue; /* question does not match the query */
|
||||
}
|
||||
if((na = buf[7] + (((unsigned short)buf[6])<<8)) < 1) {
|
||||
switch(buf[3] & 0x0F){
|
||||
case 0: /* the name has no address */
|
||||
case 3: /* the name is not there */
|
||||
return 0;
|
||||
default: /* the server failed: ask the next one */
|
||||
continue;
|
||||
}
|
||||
}
|
||||
for(k = 13; k<len && buf[k]; k++) {
|
||||
}
|
||||
k++;
|
||||
@@ -137,6 +173,7 @@ uint32_t udpresolve(int af, unsigned char * name, unsigned char * value, uint32_
|
||||
k += 4;
|
||||
if(na > 255) na = 255; /* somebody is very evil */
|
||||
for (j = 0; j < na; j++) { /* now there should be answers */
|
||||
if(k >= len) break;
|
||||
while(buf[k] < 192 && buf[k] !=0 && (k+buf[k]+14) < len) k+= (buf[k] + 1);
|
||||
if(!buf[k]) k--;
|
||||
if((k+(af == AF_INET6?28:16)) > len) {
|
||||
@@ -165,15 +202,17 @@ uint32_t udpresolve(int af, unsigned char * name, unsigned char * value, uint32_
|
||||
k+= (12 + flen);
|
||||
continue; /* we need A PTR */
|
||||
}
|
||||
for (s2 = buf + k + 12; s2 < (buf + k + 12 + len) && *s2; ){
|
||||
s1 = s2 + ((unsigned)*s2) + 1;
|
||||
s1 = buf + k + 12 + flen; /* the end of this record's data, inside the answer */
|
||||
for (s2 = buf + k + 12; s2 < s1 && *s2 && *s2 < 64; ){
|
||||
unsigned char *next = s2 + ((unsigned)*s2) + 1;
|
||||
*s2 = '.';
|
||||
s2 = s1;
|
||||
s2 = next;
|
||||
}
|
||||
*s2 = 0;
|
||||
if(s2 >= s1 || *s2 || s2 == buf + k + 12)
|
||||
break; /* the name runs past its data, is compressed or empty */
|
||||
if(param->username)free(param->username);
|
||||
param->username = (unsigned char *)strdup ((char *)buf + k + 13);
|
||||
|
||||
|
||||
return udpresolve(af,param->username, value, NULL, NULL, 2);
|
||||
}
|
||||
}
|
||||
|
||||
+13
-6
@@ -159,7 +159,10 @@ void * smtppchild(struct clientparam* param) {
|
||||
i = de64(buf,username,255);
|
||||
if(i < 1) {RETURN(664);}
|
||||
username[i] = 0;
|
||||
parseconnusername((char *)username, param, 0, 587);
|
||||
/* The name has to carry the host to connect to, and the answer says
|
||||
whether it did: without one there is nowhere to go, and what follows
|
||||
reads the name as if there were. */
|
||||
if(parseconnusername((char *)username, param, 0, 587)) {RETURN(669);}
|
||||
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);}
|
||||
@@ -184,7 +187,7 @@ void * smtppchild(struct clientparam* param) {
|
||||
}
|
||||
if(i < 3 || *username) {RETURN(668);}
|
||||
username[i] = 0;
|
||||
parseconnusername((char *)username+1, param, 0, 587);
|
||||
if(parseconnusername((char *)username+1, param, 0, 587)) {RETURN(670);}
|
||||
res = (int)strlen((char *)username+1) + 2;
|
||||
if(res < i){
|
||||
if(param->extpassword) free(param->extpassword);
|
||||
@@ -192,6 +195,10 @@ void * smtppchild(struct clientparam* param) {
|
||||
}
|
||||
}
|
||||
|
||||
/* A login has to end with a host to connect to: what follows reads the
|
||||
host name, and without one there is nowhere to go. */
|
||||
if(!param->hostname || !param->extusername){RETURN(669);}
|
||||
|
||||
#ifndef WITHMAIN
|
||||
{
|
||||
int action, reqbufsize, reqsize;
|
||||
@@ -237,14 +244,14 @@ void * smtppchild(struct clientparam* param) {
|
||||
param->nwrites++;
|
||||
i = sockgetlinebuf(param, SERVER, buf, sizeof(buf) - 1, '\n', conf.timeouts[STRING_L]);
|
||||
if(i<4 || strncasecmp((char *)buf, "334", 3)) {RETURN(680);}
|
||||
en64(param->extusername, buf, (int)strlen((char *)param->extusername));
|
||||
if(!en64(param->extusername, buf, (int)strlen((char *)param->extusername), (int)sizeof(buf))) {RETURN(683);}
|
||||
socksend(param, param->remsock, buf, (int)strlen((char *)buf), conf.timeouts[STRING_S]);
|
||||
socksend(param, param->remsock, (unsigned char *)"\r\n", 2, conf.timeouts[STRING_S]);
|
||||
param->statscli64+=(i+2);
|
||||
param->nwrites+=2;
|
||||
i = sockgetlinebuf(param, SERVER, buf, sizeof(buf) - 1, '\n', conf.timeouts[STRING_L]);
|
||||
if(i<4 || strncasecmp((char *)buf, "334", 3)) {RETURN(681);}
|
||||
en64(param->extpassword, buf, (int)strlen((char *)param->extpassword));
|
||||
if(!en64(param->extpassword, buf, (int)strlen((char *)param->extpassword), (int)sizeof(buf))) {RETURN(683);}
|
||||
socksend(param, param->remsock, buf, (int)strlen((char *)buf), conf.timeouts[STRING_S]);
|
||||
socksend(param, param->remsock, (unsigned char *)"\r\n", 2, conf.timeouts[STRING_S]);
|
||||
param->statscli64+=(i+2);
|
||||
@@ -259,12 +266,12 @@ void * smtppchild(struct clientparam* param) {
|
||||
*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);}
|
||||
if(i + 1 + res >= (int)sizeof(username)) {RETURN(683);}
|
||||
memcpy(username+1, param->extusername, i);
|
||||
i++;
|
||||
memcpy(username + i, param->extpassword, res);
|
||||
i+=res;
|
||||
en64(username, buf, i);
|
||||
if(!en64(username, buf, i, (int)sizeof(buf))) {RETURN(683);}
|
||||
i = (int)strlen((char *)buf);
|
||||
socksend(param, param->remsock, buf, i, conf.timeouts[STRING_S]);
|
||||
socksend(param, param->remsock, (unsigned char *)"\r\n", 2, conf.timeouts[STRING_S]);
|
||||
|
||||
+18
-10
@@ -60,14 +60,21 @@ int sockrecvfrom(struct clientparam *param, SOCKET sock, struct sockaddr * sin,
|
||||
|
||||
fds.fd = sock;
|
||||
fds.events = POLLIN;
|
||||
if(conf.timetoexit) return EOF;
|
||||
res = param?param->srv->so._poll(param->sostate, &fds, 1, to):so._poll(so.state, &fds, 1, to);
|
||||
if (res<1) return 0;
|
||||
sasize = SASIZE(sin);
|
||||
do {
|
||||
res = param?param->srv->so._recvfrom(param->sostate, sock, (char *)buf, bufsize, 0, (struct sockaddr *)sin, &sasize):so._recvfrom(so.state, sock, (char *)buf, bufsize, 0, (struct sockaddr *)sin, &sasize);
|
||||
} while (res < 0 && (errno == EAGAIN || errno == EINTR));
|
||||
return res;
|
||||
for(;;){
|
||||
if(conf.timetoexit) return EOF;
|
||||
res = param?param->srv->so._poll(param->sostate, &fds, 1, to):so._poll(so.state, &fds, 1, to);
|
||||
if (res<1) return 0;
|
||||
sasize = sizeof(PROXYSOCKADDRTYPE);
|
||||
/* sin NULL for a stream socket: nothing to learn the address into */
|
||||
do {
|
||||
res = param?param->srv->so._recvfrom(param->sostate, sock, (char *)buf, bufsize, 0, (struct sockaddr *)sin, sin? &sasize : NULL):so._recvfrom(so.state, sock, (char *)buf, bufsize, 0, (struct sockaddr *)sin, sin? &sasize : NULL);
|
||||
} while (res < 0 && errno == EINTR);
|
||||
/* readable and still nothing to read: over TLS a record not yet
|
||||
whole. Read again, without polling, it would only be the same until
|
||||
the rest came, a loop taking all of a CPU and never timing out: the
|
||||
socket is polled for it instead. */
|
||||
if(res >= 0 || errno != EAGAIN) return res;
|
||||
}
|
||||
}
|
||||
|
||||
int sockgetcharcli(struct clientparam * param, int timeosec, int timeousec){
|
||||
@@ -171,12 +178,13 @@ int sockgetlinebuf(struct clientparam * param, DIRECTION which, unsigned char *
|
||||
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);
|
||||
/* caller may use param->srvbuf / param->clibuf as buf */
|
||||
memmove(buf + i, base + *offp, n);
|
||||
i += n; *offp += n;
|
||||
if(d || i >= bufsize) return i;
|
||||
}
|
||||
else {
|
||||
memcpy(buf + i, base + *offp, n);
|
||||
memmove(buf + i, base + *offp, n);
|
||||
i += n; *offp += n;
|
||||
if(i >= bufsize) return i;
|
||||
}
|
||||
|
||||
+77
-27
@@ -44,7 +44,35 @@ ssize_t splice(int fd_in, loff_t *off_in, int fd_out, loff_t *off_out, size_t le
|
||||
#define MIN(a,b) ((a>b)?b:a)
|
||||
#define RETURN(xxx) { res = xxx; goto CLEANRET; }
|
||||
|
||||
/* Unless half-close is requested for the service, a connection closed by any
|
||||
of the sides terminates the session, remaining buffered data is delivered
|
||||
before the sockets are closed. */
|
||||
#define SESSIONEND (!halfclose && (CLIENTTERMREAD || SERVERTERMREAD))
|
||||
|
||||
/* A hang-up on a socket there is data to write to. With poll() it comes
|
||||
once both sides are shut down, and the write tried then fails, which ends
|
||||
it. WSAPoll reports it as soon as the peer has half-closed, a peer still
|
||||
reading, and keeps reporting it whether the socket has room or not: room
|
||||
is waited for with select() then, up to timeo seconds. Returns whether to
|
||||
try the write. */
|
||||
static int hupwrite(SOCKET s, short revents, int timeo){
|
||||
#ifdef _WIN32
|
||||
if(!(revents & POLLOUT)){
|
||||
fd_set wfd;
|
||||
struct timeval tv;
|
||||
|
||||
FD_ZERO(&wfd);
|
||||
FD_SET(s, &wfd);
|
||||
tv.tv_sec = timeo;
|
||||
tv.tv_usec = 0;
|
||||
if(select(0, NULL, &wfd, NULL, &tv) < 1) return 0;
|
||||
}
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
int sockmap(struct clientparam * param, int timeo, int usesplice){
|
||||
int halfclose = param->srv->halfclose;
|
||||
uint64_t fromclient=0x7fffffffffffffff, fromserver =0x7fffffffffffffff;
|
||||
uint64_t inclientbuf = 0, inserverbuf = 0;
|
||||
int FROMCLIENT = 1, TOCLIENTBUF = 1, TOSERVER = 1,
|
||||
@@ -54,13 +82,16 @@ int sockmap(struct clientparam * param, int timeo, int usesplice){
|
||||
#endif
|
||||
int HASERROR=0;
|
||||
int CLIENTTERMREAD = 0, CLIENTTERMWRITE = 0, SERVERTERMREAD = 0, SERVERTERMWRITE = 0;
|
||||
/* the side has hung up: closed by the peer after its own was shut down */
|
||||
int CLIENTHUP = 0, SERVERHUP = 0;
|
||||
/* whether the side's socket is in this round's poll() */
|
||||
int clipolled = 1, srvpolled = 1;
|
||||
int after = 0;
|
||||
struct pollfd fds[8];
|
||||
int fdsc = 0;
|
||||
int sleeptime = 0;
|
||||
FILTER_ACTION action;
|
||||
int res = 0;
|
||||
SASIZETYPE sasize;
|
||||
int needaction = 0;
|
||||
int graceclinum=0, gracesrvnum=0, graceclitraf=0, gracesrvtraf=0;
|
||||
time_t gracetime = 0;
|
||||
@@ -129,13 +160,13 @@ int sockmap(struct clientparam * param, int timeo, int usesplice){
|
||||
#ifdef WITHSPLICE
|
||||
|| inserverpipe
|
||||
#endif
|
||||
|| (!SERVERTERMREAD )))
|
||||
|| (!SERVERTERMREAD && !SESSIONEND)))
|
||||
||
|
||||
((!SERVERTERMWRITE) && fromclient && (inclientbuf
|
||||
#ifdef WITHSPLICE
|
||||
|| inclientpipe
|
||||
#endif
|
||||
|| (!CLIENTTERMREAD )))
|
||||
|| (!CLIENTTERMREAD && !SESSIONEND)))
|
||||
){
|
||||
|
||||
|
||||
@@ -214,8 +245,7 @@ log("send to server from buf");
|
||||
param->clioffset = param->cliinbuf = 0;
|
||||
if(fromclient) TOCLIENTBUF = 1;
|
||||
}
|
||||
sasize = SASIZE(¶m->sinsr);
|
||||
res = param->srv->so._sendto(param->sostate, param->remsock, (char *)param->clibuf + param->clioffset, (int)MIN(inclientbuf, fromclient), 0, (struct sockaddr*)¶m->sinsr, sasize);
|
||||
res = param->srv->so._sendto(param->sostate, param->remsock, (char *)param->clibuf + param->clioffset, (int)MIN(inclientbuf, fromclient), 0, NULL, 0);
|
||||
if(res <= 0) {
|
||||
TOSERVER = 0;
|
||||
if(errno && errno != EAGAIN && errno != EINTR){
|
||||
@@ -261,8 +291,7 @@ log("send to client from buf");
|
||||
if(fromserver) TOSERVERBUF = 1;
|
||||
continue;
|
||||
}
|
||||
sasize = SASIZE(¶m->sincr);
|
||||
res = param->srv->so._sendto(param->sostate, param->clisock, (char *)param->srvbuf + param->srvoffset, (int)MIN(inserverbuf,fromserver), 0, (struct sockaddr*)¶m->sincr, sasize);
|
||||
res = param->srv->so._sendto(param->sostate, param->clisock, (char *)param->srvbuf + param->srvoffset, (int)MIN(inserverbuf,fromserver), 0, NULL, 0);
|
||||
if(res <= 0) {
|
||||
TOCLIENT = 0;
|
||||
if(errno && errno != EAGAIN && errno != EINTR){
|
||||
@@ -354,7 +383,7 @@ log(logbuf);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(fromclient>inclientpipe && FROMCLIENT && TOCLIENTPIPE){
|
||||
if(fromclient>inclientpipe && FROMCLIENT && TOCLIENTPIPE && !SESSIONEND){
|
||||
int error;
|
||||
socklen_t len=sizeof(error);
|
||||
#ifdef WITHLOG
|
||||
@@ -396,7 +425,7 @@ log("done read from client to pipe");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if(fromserver > inserverpipe && FROMSERVER && TOSERVERPIPE){
|
||||
if(fromserver > inserverpipe && FROMSERVER && TOSERVERPIPE && !SESSIONEND){
|
||||
int error;
|
||||
socklen_t len=sizeof(error);
|
||||
errno = 0;
|
||||
@@ -449,12 +478,11 @@ log("done read from server to pipe\n");
|
||||
else
|
||||
#endif
|
||||
{
|
||||
if(fromclient > inclientbuf && FROMCLIENT && TOCLIENTBUF){
|
||||
if(fromclient > inclientbuf && FROMCLIENT && TOCLIENTBUF && !SESSIONEND){
|
||||
#ifdef WITHLOG
|
||||
log("read from client to buf");
|
||||
#endif
|
||||
sasize = sizeof(param->sincr);
|
||||
res = param->srv->so._recvfrom(param->sostate, param->clisock, (char *)param->clibuf + param->cliinbuf, (int)MIN((uint64_t)param->clibufsize - param->cliinbuf, fromclient-inclientbuf), 0, (struct sockaddr *)¶m->sincr, &sasize);
|
||||
res = param->srv->so._recvfrom(param->sostate, param->clisock, (char *)param->clibuf + param->cliinbuf, (int)MIN((uint64_t)param->clibufsize - param->cliinbuf, fromclient-inclientbuf), 0, NULL, NULL);
|
||||
if(res <= 0) {
|
||||
FROMCLIENT = 0;
|
||||
if(res == 0) {
|
||||
@@ -482,12 +510,11 @@ log("done read from client to buf");
|
||||
}
|
||||
}
|
||||
|
||||
if(fromserver > inserverbuf && FROMSERVER && TOSERVERBUF){
|
||||
if(fromserver > inserverbuf && FROMSERVER && TOSERVERBUF && !SESSIONEND){
|
||||
#ifdef WITHLOG
|
||||
log("read from server to buf");
|
||||
#endif
|
||||
sasize = sizeof(param->sinsr);
|
||||
res = param->srv->so._recvfrom(param->sostate, param->remsock, (char *)param->srvbuf + param->srvinbuf, (int)MIN((uint64_t)param->srvbufsize - param->srvinbuf, fromserver-inserverbuf), 0, (struct sockaddr *)¶m->sinsr, &sasize);
|
||||
res = param->srv->so._recvfrom(param->sostate, param->remsock, (char *)param->srvbuf + param->srvinbuf, (int)MIN((uint64_t)param->srvbufsize - param->srvinbuf, fromserver-inserverbuf), 0, NULL, NULL);
|
||||
if(res <= 0) {
|
||||
FROMSERVER = 0;
|
||||
if(res == 0) {
|
||||
@@ -547,7 +574,7 @@ log("done read from server to buf");
|
||||
// if(!CLIENTTERMREAD || !CLIENTTERMWRITE){
|
||||
if(!after){
|
||||
fds[fdsc].fd = param->clisock;
|
||||
if(fromclient && !CLIENTTERMREAD && !FROMCLIENT && ((
|
||||
if(fromclient && !CLIENTTERMREAD && !FROMCLIENT && !SESSIONEND && ((
|
||||
#ifdef WITHSPLICE
|
||||
!usesplice &&
|
||||
#endif
|
||||
@@ -563,6 +590,11 @@ log("done read from server to buf");
|
||||
#endif
|
||||
))
|
||||
cli_events |= POLLOUT;
|
||||
/* poll() reports a hang-up whatever is asked, and would
|
||||
return at once every time: the socket is left out then,
|
||||
rather than given as an invalid one, which WSAPoll takes
|
||||
for an error */
|
||||
clipolled = cli_events || !CLIENTHUP;
|
||||
if(cli_events){
|
||||
fds[fdsc].fd = param->clisock;
|
||||
fds[fdsc].events = cli_events;
|
||||
@@ -574,6 +606,8 @@ log("wait writing to client");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else if(!clipolled){
|
||||
}
|
||||
else if(cli_events){
|
||||
if(fds[fdsc].revents & (POLLERR|POLLNVAL)) {
|
||||
CLIENTTERMREAD = 1;
|
||||
@@ -595,19 +629,26 @@ log("ready to write to client");
|
||||
}
|
||||
if(fds[fdsc].revents & (POLLHUP)) {
|
||||
if(fds[fdsc].events & POLLIN) FROMCLIENT = 1;
|
||||
if(fds[fdsc].events & POLLOUT) CLIENTTERMWRITE = 1;
|
||||
if(fds[fdsc].events & POLLOUT){
|
||||
if(hupwrite(param->clisock, fds[fdsc].revents, timeo)) TOCLIENT = 1;
|
||||
else CLIENTTERMWRITE = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(fds[fdsc].revents & (POLLERR|POLLNVAL|POLLHUP)) {
|
||||
} else if(fds[fdsc].revents & (POLLERR|POLLNVAL)) {
|
||||
CLIENTTERMREAD = 1;
|
||||
CLIENTTERMWRITE = 1;
|
||||
} else if(fds[fdsc].revents & POLLHUP) {
|
||||
/* what the client sent before it closed is still to be
|
||||
read, once the buffer has room for it */
|
||||
CLIENTHUP = 1;
|
||||
}
|
||||
fdsc++;
|
||||
if(clipolled) fdsc++;
|
||||
|
||||
// if(!SERVERTERMREAD || !SERVERTERMWRITE){
|
||||
if(!after){
|
||||
fds[fdsc].fd = param->remsock;
|
||||
if(fromserver && !SERVERTERMREAD && !FROMSERVER && ((
|
||||
if(fromserver && !SERVERTERMREAD && !FROMSERVER && !SESSIONEND && ((
|
||||
#ifdef WITHSPLICE
|
||||
!usesplice &&
|
||||
#endif
|
||||
@@ -623,6 +664,7 @@ log("ready to write to client");
|
||||
#endif
|
||||
))
|
||||
srv_events |= POLLOUT;
|
||||
srvpolled = srv_events || !SERVERHUP;
|
||||
if(srv_events){
|
||||
fds[fdsc].fd = param->remsock;
|
||||
fds[fdsc].events = srv_events;
|
||||
@@ -634,6 +676,8 @@ log("wait writing from server");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else if(!srvpolled){
|
||||
}
|
||||
else if(srv_events){
|
||||
if(fds[fdsc].revents & (POLLERR|POLLNVAL)) {
|
||||
#ifdef WITHLOG
|
||||
@@ -662,14 +706,20 @@ log("ready to write to server");
|
||||
log("server terminated connection");
|
||||
#endif
|
||||
if(fds[fdsc].events & POLLIN) FROMSERVER = 1;
|
||||
if(fds[fdsc].events & POLLOUT) SERVERTERMWRITE = 1;
|
||||
if(fds[fdsc].events & POLLOUT){
|
||||
if(hupwrite(param->remsock, fds[fdsc].revents, timeo)) TOSERVER = 1;
|
||||
else SERVERTERMWRITE = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(fds[fdsc].revents & (POLLERR|POLLNVAL|POLLHUP)) {
|
||||
} else if(fds[fdsc].revents & (POLLERR|POLLNVAL)) {
|
||||
SERVERTERMREAD = 1;
|
||||
SERVERTERMWRITE = 1;
|
||||
} else if(fds[fdsc].revents & POLLHUP) {
|
||||
/* the rest of the answer may still be waiting to be read */
|
||||
SERVERHUP = 1;
|
||||
}
|
||||
fdsc++;
|
||||
if(srvpolled) fdsc++;
|
||||
// }
|
||||
#ifdef WITHSPLICE
|
||||
if(usesplice){
|
||||
@@ -780,7 +830,9 @@ log("ready reading from server pipe");
|
||||
#ifdef WITHLOG
|
||||
log("entering poll");
|
||||
#endif
|
||||
res = param->srv->so._poll(param->sostate, fds, fdsc, timeo*1000);
|
||||
res = param->srv->so._poll(param->sostate, fds, fdsc,
|
||||
((CLIENTTERMREAD || SERVERTERMREAD)?
|
||||
MIN(timeo, conf.timeouts[LINGER_TO]) : timeo) * 1000);
|
||||
#ifdef WITHLOG
|
||||
log("leaving poll");
|
||||
#endif
|
||||
@@ -811,9 +863,6 @@ log("timeout");
|
||||
else if(inclientpipe || inserverpipe) res = 94;
|
||||
#endif
|
||||
|
||||
if((param->nwrites > 0 && !SERVERTERMWRITE) || (param->nreads > 0 && !CLIENTTERMWRITE))
|
||||
usleep(SLEEPTIME * 10);
|
||||
|
||||
CLEANRET:
|
||||
|
||||
#ifdef WITHSPLICE
|
||||
@@ -825,3 +874,4 @@ CLEANRET:
|
||||
|
||||
return res;
|
||||
}
|
||||
#undef SESSIONEND
|
||||
+34
-54
@@ -7,15 +7,6 @@
|
||||
*/
|
||||
|
||||
#include "proxy.h"
|
||||
#ifdef __linux__
|
||||
#include <sched.h>
|
||||
|
||||
static int switch_ns(struct srvparam *srv, int target_fd) {
|
||||
if(target_fd < 0) return 0;
|
||||
if(srv->saved_nsfd >= 0 && setns(srv->saved_nsfd, CLONE_NEWNET)) return -1;
|
||||
return setns(target_fd, CLONE_NEWNET);
|
||||
}
|
||||
#endif
|
||||
|
||||
#define RETURN(xxx) { param->res = xxx; goto CLEANRET; }
|
||||
|
||||
@@ -116,38 +107,23 @@ void * sockschild(struct clientparam* param) {
|
||||
}
|
||||
|
||||
size = 4;
|
||||
*SAFAMILY(¶m->sinsr) = *SAFAMILY(¶m->req) = AF_INET;
|
||||
switch(c) {
|
||||
#ifndef NOIPV6
|
||||
case 4:
|
||||
if(param->srv->family == 4) RETURN(997);
|
||||
size = 16;
|
||||
*SAFAMILY(¶m->sinsr) = *SAFAMILY(¶m->req) = AF_INET6;
|
||||
#endif
|
||||
case 1:
|
||||
for (i = 0; i<size; i++){
|
||||
if ((res = sockgetcharcli(param, conf.timeouts[SINGLEBYTE_S], 0)) == EOF) {RETURN(441);}
|
||||
buf[i] = (unsigned char)res;
|
||||
}
|
||||
#ifndef NOIPV6
|
||||
if (c == 1 && param->srv->family==6){
|
||||
char prefix[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255};
|
||||
*SAFAMILY(¶m->sinsr) = *SAFAMILY(¶m->req) = AF_INET6;
|
||||
memcpy(SAADDR(¶m->sinsr), prefix, 12);
|
||||
memcpy(12 + (char *)SAADDR(¶m->sinsr), buf, 4);
|
||||
memcpy(SAADDR(¶m->req), prefix, 12);
|
||||
memcpy(12 + (char *)SAADDR(¶m->req), buf, 4);
|
||||
}
|
||||
else {
|
||||
#endif
|
||||
memcpy(SAADDR(¶m->sinsr), buf, size);
|
||||
memcpy(SAADDR(¶m->req), buf, size);
|
||||
#ifndef NOIPV6
|
||||
}
|
||||
#endif
|
||||
if(command == 1 && SAISNULL(¶m->req)) {
|
||||
RETURN(431);
|
||||
}
|
||||
res = socks5_setaddr(param->srv->family, c, buf, ¶m->req);
|
||||
if(res == 1) {RETURN(997);}
|
||||
/* The null address is no destination to connect to, except in
|
||||
SOCKS4a, where it says that the destination is the name which
|
||||
follows it. */
|
||||
if(res == 2 && ver == 5 && command == 1) {RETURN(431);}
|
||||
param->sinsr = param->req;
|
||||
myinet_ntop(*SAFAMILY(¶m->sinsr), SAADDR(¶m->sinsr), (char *)buf, 64);
|
||||
break;
|
||||
case 3:
|
||||
@@ -164,6 +140,7 @@ void * sockschild(struct clientparam* param) {
|
||||
default:
|
||||
RETURN(997);
|
||||
}
|
||||
if(badhostname((char *)buf)) {RETURN(21);}
|
||||
if(param->hostname)free(param->hostname);
|
||||
param->hostname = (unsigned char *)strdup((char *)buf);
|
||||
if(!param->hostname){RETURN(21);}
|
||||
@@ -186,6 +163,7 @@ void * sockschild(struct clientparam* param) {
|
||||
param->service = S_SOCKS45;
|
||||
if(sockgetlinebuf(param, CLIENT, buf, BUFSIZE - 1, 0, conf.timeouts[STRING_S]) < 0) {RETURN(441);}
|
||||
buf[127] = 0;
|
||||
if(badhostname((char *)buf)) {RETURN(21);}
|
||||
if(param->hostname)free(param->hostname);
|
||||
param->hostname = (unsigned char *)strdup((char *)buf);
|
||||
if(!param->hostname){RETURN(21);}
|
||||
@@ -212,6 +190,7 @@ void * sockschild(struct clientparam* param) {
|
||||
if(command == 2){
|
||||
if ((param->remsock=param->srv->so._socket(param->sostate, SASOCK(¶m->req), SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) {RETURN (11);}
|
||||
setopts(param->remsock, param->srv->lissockopts);
|
||||
if(extbindtodevice(param, param->remsock)) {RETURN (12);}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -219,7 +198,11 @@ void * sockschild(struct clientparam* param) {
|
||||
RETURN(997);
|
||||
}
|
||||
|
||||
if((res = (*param->srv->authfunc)(param))) {
|
||||
if(command == 3) param->preauth = 1;
|
||||
res = (*param->srv->authfunc)(param);
|
||||
param->preauth = 0;
|
||||
if(command == 3 && res == 2) res = 0;
|
||||
if(res) {
|
||||
RETURN(res);
|
||||
}
|
||||
|
||||
@@ -238,18 +221,9 @@ void * sockschild(struct clientparam* param) {
|
||||
#endif
|
||||
|
||||
if(command == 3) {
|
||||
#ifdef __linux__
|
||||
if(switch_ns(param->srv, param->srv->o_nsfd)) {RETURN(11);}
|
||||
#endif
|
||||
if ((param->remsock=param->srv->so._socket(param->sostate, SASOCK(¶m->req), SOCK_DGRAM, IPPROTO_UDP)) == INVALID_SOCKET) {RETURN (11);}
|
||||
#ifdef _WIN32
|
||||
{ unsigned long ul = 1; ioctlsocket(param->remsock, FIONBIO, &ul); }
|
||||
#else
|
||||
fcntl(param->remsock, F_SETFL, O_NONBLOCK | fcntl(param->remsock, F_GETFL));
|
||||
#endif
|
||||
if((res = udpbind(param))) {RETURN(res);}
|
||||
}
|
||||
|
||||
if(command > 1) {
|
||||
else if(command == 2) {
|
||||
if(param->srv->so._bind(param->sostate, param->remsock,(struct sockaddr *)¶m->sinsl,SASIZE(¶m->sinsl))) {
|
||||
*SAPORT(¶m->sinsl) = 0;
|
||||
if(param->srv->so._bind(param->sostate, param->remsock,(struct sockaddr *)¶m->sinsl,SASIZE(¶m->sinsl)))RETURN (12);
|
||||
@@ -258,9 +232,10 @@ fprintf(stderr, "%hu bound to communicate with server\n", *SAPORT(¶m->sinsl)
|
||||
fflush(stderr);
|
||||
#endif
|
||||
}
|
||||
sasize = SASIZE(¶m->sinsl);
|
||||
sasize = sizeof(param->sinsl);
|
||||
param->srv->so._getsockname(param->sostate, param->remsock, (struct sockaddr *)¶m->sinsl, &sasize);
|
||||
if(command == 3) {
|
||||
}
|
||||
if(command == 3) {
|
||||
param->ctrlsock = param->clisock;
|
||||
#ifdef __linux__
|
||||
if(switch_ns(param->srv, param->srv->i_nsfd)) {RETURN(11);}
|
||||
@@ -272,10 +247,11 @@ fflush(stderr);
|
||||
#else
|
||||
fcntl(param->clisock, F_SETFL, O_NONBLOCK | fcntl(param->clisock, F_GETFL));
|
||||
#endif
|
||||
if(intbindtodevice(param, param->clisock)) {RETURN (12);}
|
||||
sin = param->sincl;
|
||||
*SAPORT(&sin) = 0;
|
||||
if(param->srv->so._bind(param->sostate, param->clisock,(struct sockaddr *)&sin,SASIZE(&sin))) {RETURN (12);}
|
||||
sasize = SASIZE(&sin);
|
||||
sasize = sizeof(sin);
|
||||
param->srv->so._getsockname(param->sostate, param->clisock, (struct sockaddr *)&sin, &sasize);
|
||||
#if SOCKSTRACE > 0
|
||||
fprintf(stderr, "%hu binded to communicate with client\n",
|
||||
@@ -283,7 +259,6 @@ fprintf(stderr, "%hu binded to communicate with client\n",
|
||||
);
|
||||
fflush(stderr);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
param->res = 0;
|
||||
|
||||
@@ -298,16 +273,21 @@ CLEANRET:
|
||||
int repcode;
|
||||
|
||||
sasize = sizeof(sin);
|
||||
if(command != 3 && param->remsock != INVALID_SOCKET) param->srv->so._getsockname(param->sostate, param->remsock, (struct sockaddr *)&sin, &sasize);
|
||||
if(!SAISNULL(¶m->srv->extNat)){
|
||||
uint16_t port;
|
||||
port = *SAPORT(&sin);
|
||||
sin = param->srv->extNat;
|
||||
*SAPORT(&sin) = port;
|
||||
/* CONNECT and BIND report the address of the socket towards the
|
||||
destination, UDP ASSOCIATE the one the client sends its datagrams
|
||||
to, as does a request which never got a socket of its own */
|
||||
if(command != 3 && param->remsock != INVALID_SOCKET){
|
||||
param->srv->so._getsockname(param->sostate, param->remsock, (struct sockaddr *)&sin, &sasize);
|
||||
if(!SAISNULL(¶m->srv->extNat)){
|
||||
uint16_t port;
|
||||
port = *SAPORT(&sin);
|
||||
sin = param->srv->extNat;
|
||||
*SAPORT(&sin) = port;
|
||||
}
|
||||
}
|
||||
else {
|
||||
param->srv->so._getsockname(param->sostate, param->clisock, (struct sockaddr *)&sin, &sasize);
|
||||
if(!SAISNULL(¶m->srv->intNat)){
|
||||
if(command == 3 && !SAISNULL(¶m->srv->intNat)){
|
||||
uint16_t port;
|
||||
port = *SAPORT(&sin);
|
||||
sin = param->srv->intNat;
|
||||
|
||||
@@ -74,6 +74,9 @@ static int client_mode = 0;
|
||||
struct SSLsock {
|
||||
SOCKET s;
|
||||
SSL_CONN conn;
|
||||
/* what a read and a write which could not be done wait for, POLLIN
|
||||
or POLLOUT, 0 once one is: TLS may have to write to read */
|
||||
short rwant, wwant;
|
||||
};
|
||||
|
||||
struct SSLstate {
|
||||
@@ -102,10 +105,12 @@ static void addSSL(
|
||||
if (cli_s != INVALID_SOCKET){
|
||||
SOSTATE->cli.s = cli_s;
|
||||
SOSTATE->cli.conn = cli_conn;
|
||||
SOSTATE->cli.rwant = SOSTATE->cli.wwant = 0;
|
||||
}
|
||||
if (srv_s != INVALID_SOCKET){
|
||||
SOSTATE->srv.s = srv_s;
|
||||
SOSTATE->srv.conn = srv_conn;
|
||||
SOSTATE->srv.rwant = SOSTATE->srv.wwant = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,12 +141,14 @@ static ssize_t ssl_send(void *state, SOCKET s, const void *msg, size_t len, int
|
||||
int res, err;
|
||||
if((res = ssl_write(sslq->conn, (void *)msg, len)) <= 0){
|
||||
err = SSL_get_error((SSL *)((ssl_conn*)sslq->conn)->ssl, res);
|
||||
if (err == SSL_ERROR_WANT_WRITE){
|
||||
if (err == SSL_ERROR_WANT_WRITE || err == SSL_ERROR_WANT_READ){
|
||||
sslq->wwant = (err == SSL_ERROR_WANT_READ)? POLLIN : POLLOUT;
|
||||
seterrno3(EAGAIN);
|
||||
return -1;
|
||||
}
|
||||
else seterrno3(err);
|
||||
}
|
||||
else sslq->wwant = 0;
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -158,14 +165,16 @@ static ssize_t ssl_sendto(void *state, SOCKET s, const void *msg, size_t len, in
|
||||
|
||||
if ((sslq = searchSSL(state, s))){
|
||||
int res, err;
|
||||
if((res = ssl_write(sslq->conn, (void *)msg, len)) <= 0) {
|
||||
if((res = ssl_write(sslq->conn, (void *)msg, len)) <= 0){
|
||||
err = SSL_get_error((SSL *)((ssl_conn*)sslq->conn)->ssl, res);
|
||||
if (err == SSL_ERROR_WANT_WRITE){
|
||||
if (err == SSL_ERROR_WANT_WRITE || err == SSL_ERROR_WANT_READ){
|
||||
sslq->wwant = (err == SSL_ERROR_WANT_READ)? POLLIN : POLLOUT;
|
||||
seterrno3(EAGAIN);
|
||||
return -1;
|
||||
}
|
||||
else seterrno3(err);
|
||||
}
|
||||
else sslq->wwant = 0;
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -183,12 +192,14 @@ static ssize_t ssl_recvfrom(void *state, SOCKET s, void *msg, size_t len, int f
|
||||
int res, err;
|
||||
if((res = ssl_read(sslq->conn, (void *)msg, len)) <= 0) {
|
||||
err = SSL_get_error((SSL *)((ssl_conn*)sslq->conn)->ssl, res);
|
||||
if (err == SSL_ERROR_WANT_READ) {
|
||||
if (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE) {
|
||||
sslq->rwant = (err == SSL_ERROR_WANT_WRITE)? POLLOUT : POLLIN;
|
||||
seterrno3(EAGAIN);
|
||||
return -1;
|
||||
}
|
||||
else seterrno3(err);
|
||||
}
|
||||
else sslq->rwant = 0;
|
||||
return res;
|
||||
}
|
||||
return sso._recvfrom(sso.state, s, msg, len, flags, from, fromlen);
|
||||
@@ -205,12 +216,14 @@ static ssize_t ssl_recv(void *state, SOCKET s, void *msg, size_t len, int flags)
|
||||
int res, err;
|
||||
if((res = ssl_read(sslq->conn, (void *)msg, len)) <= 0) {
|
||||
err = SSL_get_error((SSL *)((ssl_conn*)sslq->conn)->ssl, res);
|
||||
if (err == SSL_ERROR_WANT_READ) {
|
||||
if (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE) {
|
||||
sslq->rwant = (err == SSL_ERROR_WANT_WRITE)? POLLOUT : POLLIN;
|
||||
seterrno3(EAGAIN);
|
||||
return -1;
|
||||
}
|
||||
else seterrno3(err);
|
||||
}
|
||||
else sslq->rwant = 0;
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -235,6 +248,8 @@ static int ssl_poll(void *state, struct pollfd *fds, nfds_t nfds, int timeout){
|
||||
struct SSLsock *sslq = NULL;
|
||||
unsigned int i;
|
||||
int ret = 0;
|
||||
short own[64], *events = own, ev;
|
||||
|
||||
for(i = 0; i < nfds; i++){
|
||||
if((fds[i].events & POLLIN) && (sslq = searchSSL(state, fds[i].fd)) && ssl_pending(sslq->conn)){
|
||||
fds[i].revents = POLLIN;
|
||||
@@ -243,8 +258,29 @@ static int ssl_poll(void *state, struct pollfd *fds, nfds_t nfds, int timeout){
|
||||
else fds[i].revents = 0;
|
||||
}
|
||||
if(ret) return ret;
|
||||
for(i = 0; i < nfds; i++) if((sslq = searchSSL(state, fds[i].fd)) && (sslq->rwant || sslq->wwant)) break;
|
||||
if(i == nfds) return sso._poll(state, fds, nfds, timeout);
|
||||
|
||||
/* A read or a write TLS could not do waits for what TLS needs, a read
|
||||
for the socket to be writable: whatever that gets is the caller's
|
||||
chance to try again, revents what it asked for, and its events are
|
||||
given back as they were. */
|
||||
if(nfds > sizeof(own)/sizeof(own[0]) && !(events = malloc(nfds * sizeof(*events)))) return -1;
|
||||
for(i = 0; i < nfds; i++){
|
||||
events[i] = fds[i].events;
|
||||
if(!(sslq = searchSSL(state, fds[i].fd))) continue;
|
||||
ev = fds[i].events & ~(POLLIN|POLLOUT);
|
||||
if(fds[i].events & POLLIN) ev |= sslq->rwant? sslq->rwant : POLLIN;
|
||||
if(fds[i].events & POLLOUT) ev |= sslq->wwant? sslq->wwant : POLLOUT;
|
||||
fds[i].events = ev;
|
||||
}
|
||||
ret = sso._poll(state, fds, nfds, timeout);
|
||||
for(i = 0; i < nfds; i++){
|
||||
if(ret > 0 && fds[i].events != events[i] && (fds[i].revents & ~(POLLERR|POLLHUP|POLLNVAL)))
|
||||
fds[i].revents = events[i] | (fds[i].revents & (POLLERR|POLLHUP|POLLNVAL));
|
||||
fds[i].events = events[i];
|
||||
}
|
||||
if(events != own) free(events);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -779,7 +815,7 @@ static FILTER_ACTION ssl_filter_client(void *fo, struct clientparam * param, voi
|
||||
}
|
||||
|
||||
static FILTER_ACTION ssl_filter_connect(void *fc, struct clientparam * param){
|
||||
if(PCONF->cli && !client_mode) {
|
||||
if(PCONF->cli && !PCONF->client_mode) {
|
||||
if(docli(param)) {
|
||||
return REJECT;
|
||||
}
|
||||
@@ -788,7 +824,7 @@ static FILTER_ACTION ssl_filter_connect(void *fc, struct clientparam * param){
|
||||
}
|
||||
|
||||
static FILTER_ACTION ssl_filter_afterauth(void *fc, struct clientparam * param){
|
||||
if(PCONF->cli && client_mode == 1) {
|
||||
if(PCONF->cli && PCONF->client_mode == 1) {
|
||||
if(docli(param)) {
|
||||
return REJECT;
|
||||
}
|
||||
@@ -806,7 +842,7 @@ static FILTER_ACTION ssl_filter_predata(void *fc, struct clientparam * param){
|
||||
if(!param->redirectfunc) param->redirectfunc = proxyfunc;
|
||||
return CONTINUE;
|
||||
}
|
||||
else if(PCONF->cli && client_mode == 2) {
|
||||
else if(PCONF->cli && PCONF->client_mode == 2) {
|
||||
if(docli(param)) {
|
||||
return REJECT;
|
||||
}
|
||||
@@ -815,7 +851,7 @@ static FILTER_ACTION ssl_filter_predata(void *fc, struct clientparam * param){
|
||||
}
|
||||
|
||||
static FILTER_ACTION ssl_parent(struct clientparam * param){
|
||||
if(PCONF->cli && client_mode == 3) {
|
||||
if(PCONF->cli && PCONF->client_mode == 3) {
|
||||
if(docli(param)) {
|
||||
return REJECT;
|
||||
}
|
||||
@@ -867,6 +903,9 @@ static void ssl_filter_close(void *fo){
|
||||
free(CONFIG->client_ca_file);
|
||||
free(CONFIG->client_ca_dir);
|
||||
free(CONFIG->client_ca_store);
|
||||
free(CONFIG->server_ca_file);
|
||||
free(CONFIG->server_ca_dir);
|
||||
free(CONFIG->server_ca_store);
|
||||
free(CONFIG->client_sni);
|
||||
if(CONFIG->client_alpn_protos.protos_len){
|
||||
free(CONFIG->client_alpn_protos.protos);
|
||||
|
||||
+52
-6
@@ -22,6 +22,7 @@
|
||||
#include <wolfssl/openssl/pem.h>
|
||||
#include <wolfssl/openssl/ssl.h>
|
||||
#include <wolfssl/openssl/err.h>
|
||||
#include <wolfssl/openssl/bn.h>
|
||||
#else
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/x509.h>
|
||||
@@ -29,6 +30,7 @@
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/bn.h>
|
||||
#endif
|
||||
|
||||
#include "proxy.h"
|
||||
@@ -84,7 +86,11 @@ static int copy_ext(X509 *dst_cert, X509 *src_cert, int nid)
|
||||
}
|
||||
|
||||
#ifndef WITH_WOLFSSL
|
||||
static int add_ext(X509 *cert, int nid, const char *value)
|
||||
/* issuer is the certificate the extension should describe as the issuer,
|
||||
* which matters for an authority key identifier: it names the key that
|
||||
* signs, not the key being signed.
|
||||
*/
|
||||
static int add_ext_issuer(X509 *cert, X509 *issuer, int nid, const char *value)
|
||||
{
|
||||
X509_EXTENSION *ex;
|
||||
X509V3_CTX ctx;
|
||||
@@ -92,10 +98,8 @@ static int add_ext(X509 *cert, int nid, const char *value)
|
||||
/* This sets the 'context' of the extensions. */
|
||||
/* No configuration database */
|
||||
X509V3_set_ctx_nodb(&ctx);
|
||||
/* Issuer and subject certs: both the target since it is self signed,
|
||||
* no request and no CRL
|
||||
*/
|
||||
X509V3_set_ctx(&ctx, cert, cert, NULL, NULL, 0);
|
||||
/* No request and no CRL */
|
||||
X509V3_set_ctx(&ctx, issuer, cert, NULL, NULL, 0);
|
||||
/* value is char * prior to OpenSSL 1.1.0 */
|
||||
ex = X509V3_EXT_conf_nid(NULL, &ctx, nid, (char *)value);
|
||||
if (!ex)
|
||||
@@ -105,8 +109,39 @@ static int add_ext(X509 *cert, int nid, const char *value)
|
||||
X509_EXTENSION_free(ex);
|
||||
return err > 0;
|
||||
}
|
||||
|
||||
static int add_ext(X509 *cert, int nid, const char *value)
|
||||
{
|
||||
/* Issuer and subject: both the target, for a self signed certificate */
|
||||
return add_ext_issuer(cert, cert, nid, value);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* A serial number of the copy's own, when the source's cannot be set back:
|
||||
* positive, from the hash of the source certificate, so the same for the
|
||||
* same certificate and different for another. wolfSSL built with
|
||||
* WOLFSSL_QT, as Ubuntu 26.04 has it, returns a serial number without the
|
||||
* ASN.1 header its own X509_set_serialNumber() requires.
|
||||
*/
|
||||
static int set_serial_hash(X509 *cert, const unsigned char *hash)
|
||||
{
|
||||
unsigned char serial[16];
|
||||
BIGNUM *bn;
|
||||
ASN1_INTEGER *ai;
|
||||
int res = 0;
|
||||
|
||||
memcpy(serial, hash, sizeof(serial));
|
||||
serial[0] &= 0x7f;
|
||||
if(!serial[0]) serial[0] = 1;
|
||||
if(!(bn = BN_bin2bn(serial, sizeof(serial), NULL))) return 0;
|
||||
if((ai = BN_to_ASN1_INTEGER(bn, NULL))){
|
||||
res = X509_set_serialNumber(cert, ai);
|
||||
ASN1_INTEGER_free(ai);
|
||||
}
|
||||
BN_free(bn);
|
||||
return res;
|
||||
}
|
||||
|
||||
SSL_CERT ssl_copy_cert(SSL_CERT cert, SSL_CONFIG *config)
|
||||
{
|
||||
int err = -1;
|
||||
@@ -154,7 +189,8 @@ SSL_CERT ssl_copy_cert(SSL_CERT cert, SSL_CONFIG *config)
|
||||
}
|
||||
/* v3 is required, extensions are added below */
|
||||
X509_set_version(dst_cert, 2);
|
||||
if(!X509_set_serialNumber(dst_cert, X509_get_serialNumber(src_cert))
|
||||
if((!X509_set_serialNumber(dst_cert, X509_get_serialNumber(src_cert))
|
||||
&& !set_serial_hash(dst_cert, hash_sha256))
|
||||
|| !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);
|
||||
@@ -199,6 +235,16 @@ SSL_CERT ssl_copy_cert(SSL_CERT cert, SSL_CONFIG *config)
|
||||
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");
|
||||
/* A verifier following RFC 5280 strictly looks for the issuer through a
|
||||
* key identifier and refuses a certificate carrying none: OpenSSL does
|
||||
* with x509_strict, and Python has since 3.13. The identifiers are
|
||||
* generated rather than copied, so they name the CA signing here
|
||||
* instead of the one that signed upstream. keyid,issuer keeps working
|
||||
* when the CA certificate has no subject key identifier of its own.
|
||||
*/
|
||||
add_ext(dst_cert, NID_subject_key_identifier, "hash");
|
||||
add_ext_issuer(dst_cert, config->CA_cert, NID_authority_key_identifier,
|
||||
"keyid,issuer");
|
||||
#else
|
||||
copy_ext(dst_cert, src_cert, NID_basic_constraints);
|
||||
copy_ext(dst_cert, src_cert, NID_ext_key_usage);
|
||||
|
||||
+15
-4
@@ -105,6 +105,7 @@ int
|
||||
|
||||
#ifdef WITH_UN
|
||||
#include <sys/un.h>
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
|
||||
#define ALLOW 0
|
||||
@@ -152,7 +153,9 @@ int
|
||||
#define UN_SAADDR(sa) (((struct sockaddr_un *)sa)->sun_family == AF_UNIX)? (unsigned char *)((struct sockaddr_un *)sa)->sun_path :
|
||||
#define UN_SAADDRLEN(sa) (((struct sockaddr_un *)sa)->sun_family == AF_UNIX)? (int)sizeof(((struct sockaddr_un *)sa)->sun_path) :
|
||||
#define UN_SASOCK(sa) (((struct sockaddr_un *)sa)->sun_family == AF_UNIX)? PF_UNIX :
|
||||
#define UN_SASIZE(sa) (((struct sockaddr_un *)sa)->sun_family == AF_UNIX)? sizeof(struct sockaddr_un) :
|
||||
/* an abstract name (Linux) is its bytes after the leading 0, no more:
|
||||
padded with zeros it would be another name */
|
||||
#define UN_SASIZE(sa) (((struct sockaddr_un *)sa)->sun_family == AF_UNIX)? (((struct sockaddr_un *)sa)->sun_path[0] || !((struct sockaddr_un *)sa)->sun_path[1]? sizeof(struct sockaddr_un) : offsetof(struct sockaddr_un, sun_path) + 1 + strlen(((struct sockaddr_un *)sa)->sun_path + 1)) :
|
||||
#define UN_SAISNULL(sa) (((struct sockaddr_un *)sa)->sun_family == AF_UNIX)? (((struct sockaddr_un *)sa)->sun_path[0] == 0 && ((struct sockaddr_un *)sa)->sun_path[1] == 0) :
|
||||
#else
|
||||
#define UN_SAPORT(sa)
|
||||
@@ -527,6 +530,8 @@ struct srvparam {
|
||||
AUTHFUNC authfunc;
|
||||
PROXYFUNC pf;
|
||||
SOCKET srvsock, cbsock;
|
||||
/* the file of a Unix socket bound to a path, to remove only it */
|
||||
uint64_t undev, unino;
|
||||
int childcount;
|
||||
int maxchild;
|
||||
int backlog;
|
||||
@@ -551,6 +556,8 @@ struct srvparam {
|
||||
#ifdef WITHSPLICE
|
||||
int usesplice;
|
||||
#endif
|
||||
int halfclose;
|
||||
int udpauth;
|
||||
unsigned bufsize;
|
||||
unsigned authcachetype, authcachetime;
|
||||
unsigned logdumpsrv, logdumpcli;
|
||||
@@ -643,7 +650,9 @@ struct clientparam {
|
||||
paused,
|
||||
version,
|
||||
connlim,
|
||||
predatdone;
|
||||
predatdone,
|
||||
preauth,
|
||||
dstindep;
|
||||
|
||||
unsigned char *hostname,
|
||||
*username,
|
||||
@@ -678,6 +687,7 @@ struct clientparam {
|
||||
|
||||
PROXYSOCKADDRTYPE udp_relay[3];
|
||||
int udp_nhops;
|
||||
struct ace *lastace;
|
||||
time_t time_start;
|
||||
};
|
||||
|
||||
@@ -832,7 +842,7 @@ struct pluginlink {
|
||||
int (*ACLMatches)(struct ace* acentry, struct clientparam * param);
|
||||
int (*alwaysauth)(struct clientparam * param);
|
||||
int (*checkACL)(struct clientparam * param);
|
||||
unsigned char* (*en64)(const unsigned char *in, unsigned char *out, int inlen);
|
||||
unsigned char* (*en64)(const unsigned char *in, unsigned char *out, int inlen, int outsize);
|
||||
int (*de64)(const unsigned char *in, unsigned char *out, int maxlen);
|
||||
void (*tohex)(unsigned char *in, unsigned char *out, int len);
|
||||
void (*fromhex)(unsigned char *in, unsigned char *out, int len);
|
||||
@@ -882,7 +892,8 @@ typedef enum {
|
||||
DNS_TO,
|
||||
CHAIN_TO,
|
||||
CONNECT_TO,
|
||||
CONNBACK_TO
|
||||
CONNBACK_TO,
|
||||
LINGER_TO
|
||||
}TIMEOUT;
|
||||
|
||||
typedef enum {
|
||||
|
||||
+14
-10
@@ -224,6 +224,7 @@ int parsehello(int type, unsigned char *hello, unsigned len, char *sni, int * sn
|
||||
else if(type == 2){
|
||||
offset += 3;
|
||||
}
|
||||
if((offset + 2) > len) return -6;
|
||||
elen = size16(hello+offset);
|
||||
offset += 2;
|
||||
if(elen+offset != len) return -9;
|
||||
@@ -334,6 +335,7 @@ void * tlsprchild(struct clientparam* param) {
|
||||
int lv=-1;
|
||||
char proto[PROTOLEN]="-";
|
||||
int snipos = 0;
|
||||
int snlen = 0;
|
||||
PROXYSERVICE stlsproto = param->clientstarttls? param->clientstarttls : param->srv->srvstarttls;
|
||||
|
||||
if(!param->clientstarttls && stlsproto){
|
||||
@@ -356,16 +358,7 @@ void * tlsprchild(struct clientparam* param) {
|
||||
}
|
||||
else if (parsehostname(sni, param, param->srv->targetport? ntohs(param->srv->targetport):starttlsport(stlsproto))) RETURN (100);
|
||||
if (!param->hostname)param->hostname = (unsigned char *)strdup(sni);
|
||||
if(param->srv->s_option && snipos && res > 1){
|
||||
int len;
|
||||
|
||||
len = socksend(param, param->remsock, param->clibuf+param->clioffset,snipos + (res/2), conf.timeouts[STRING_S]);
|
||||
if(len != snipos + (res/2)){
|
||||
RETURN(310);
|
||||
}
|
||||
param->clioffset += snipos + (res/2);
|
||||
|
||||
}
|
||||
snlen = res;
|
||||
}
|
||||
else if (res < 0 && param->srv->requirecert) RETURN(310-res);
|
||||
}
|
||||
@@ -385,6 +378,17 @@ void * tlsprchild(struct clientparam* param) {
|
||||
return (void *)param->redirectfunc;
|
||||
}
|
||||
|
||||
if(param->srv->s_option && snipos && snlen > 1){
|
||||
int len;
|
||||
|
||||
len = socksend(param, param->remsock, param->clibuf+param->clioffset,snipos + (snlen/2), conf.timeouts[STRING_S]);
|
||||
if(len != snipos + (snlen/2)){
|
||||
RETURN(310);
|
||||
}
|
||||
param->clioffset += snipos + (snlen/2);
|
||||
|
||||
}
|
||||
|
||||
if(stlsproto){
|
||||
res = srvstarttls(param, stlsproto);
|
||||
if(res){
|
||||
|
||||
+5
-12
@@ -36,26 +36,19 @@ void * udppmchild(struct clientparam* param) {
|
||||
int i;
|
||||
int len = 0;
|
||||
|
||||
if(parsehostname((char *)param->srv->target, param, ntohs(param->srv->targetport))) { RETURN(201) }
|
||||
if(parsehostname((char *)param->srv->target, param, ntohs(param->srv->targetport))) { RETURN(100) }
|
||||
|
||||
#ifndef NOIPV6
|
||||
memcpy(¶m->sinsl, *SAFAMILY(¶m->req) == AF_INET6 ? (struct sockaddr *)¶m->srv->extsa6 : (struct sockaddr *)¶m->srv->extsa, SASIZE(¶m->req));
|
||||
param->sinsl = *SAFAMILY(¶m->req) == AF_INET6? param->srv->extsa6 : param->srv->extsa;
|
||||
#else
|
||||
memcpy(¶m->sinsl, (struct sockaddr *)¶m->srv->extsa, SASIZE(¶m->req));
|
||||
param->sinsl = param->srv->extsa;
|
||||
#endif
|
||||
*SAPORT(¶m->sinsl) = 0;
|
||||
param->remsock = param->srv->so._socket(param->srv->so.state, SASOCK(¶m->sinsl), SOCK_DGRAM, IPPROTO_UDP);
|
||||
if(param->remsock == INVALID_SOCKET) { RETURN(202); }
|
||||
if(param->srv->so._bind(param->srv->so.state, param->remsock, (struct sockaddr *)¶m->sinsl, SASIZE(¶m->sinsl))) { RETURN(203); }
|
||||
#ifdef _WIN32
|
||||
{ unsigned long ul2 = 1; ioctlsocket(param->remsock, FIONBIO, &ul2); }
|
||||
#else
|
||||
fcntl(param->remsock, F_SETFL, O_NONBLOCK | fcntl(param->remsock, F_GETFL));
|
||||
#endif
|
||||
memcpy(¶m->sinsr, ¶m->req, sizeof(param->req));
|
||||
param->sinsr = param->req;
|
||||
param->operation = UDPASSOC;
|
||||
authres = (*param->srv->authfunc)(param);
|
||||
if(authres) { RETURN(authres); }
|
||||
if((authres = udpbind(param))) { RETURN(authres); }
|
||||
if(!param->srv->s_option)hashadd(&udp_table, param, ¶m, MAX_COUNTER_TIME);
|
||||
if(!param->srvbuf){
|
||||
if(!(param->srvbuf = malloc(UDPBUFSIZE)))RETURN(11);
|
||||
|
||||
+286
-84
@@ -8,6 +8,10 @@
|
||||
|
||||
#include "proxy.h"
|
||||
|
||||
/* space reserved in front of the received datagram to prepend the headers
|
||||
of the second and the third hop of a SOCKS5 UDP chain */
|
||||
#define UDPHDROFF 48
|
||||
|
||||
int socks5_udp_build_hdr(unsigned char *buf, PROXYSOCKADDRTYPE *addr)
|
||||
{
|
||||
buf[0] = buf[1] = buf[2] = 0;
|
||||
@@ -48,69 +52,200 @@ static int socks5_udp_skip_hdr(unsigned char *buf, int len)
|
||||
* param->srv->s_option non-zero: return after first datagram sent to client
|
||||
* param->ctrlsock TCP control socket from the client; INVALID_SOCKET if none.
|
||||
*/
|
||||
|
||||
struct udppoll {
|
||||
struct pollfd fds[4];
|
||||
int nfds;
|
||||
int cli, ctrl, ctrlsrv;
|
||||
};
|
||||
|
||||
static void udpfds(struct clientparam *param, struct udppoll *p)
|
||||
{
|
||||
memset(p->fds, 0, sizeof(p->fds));
|
||||
p->nfds = 0;
|
||||
p->cli = p->ctrl = p->ctrlsrv = -1;
|
||||
|
||||
p->fds[p->nfds].fd = param->remsock; /* always index 0 */
|
||||
p->fds[p->nfds].events = POLLIN;
|
||||
p->nfds++;
|
||||
|
||||
if (!param->waitserver64) {
|
||||
p->fds[p->nfds].fd = param->clisock;
|
||||
p->fds[p->nfds].events = POLLIN;
|
||||
p->cli = p->nfds++;
|
||||
}
|
||||
if (param->ctrlsock != INVALID_SOCKET) {
|
||||
p->fds[p->nfds].fd = param->ctrlsock;
|
||||
p->fds[p->nfds].events = POLLIN;
|
||||
p->ctrl = p->nfds++;
|
||||
}
|
||||
if (param->ctrlsocksrv != INVALID_SOCKET) {
|
||||
p->fds[p->nfds].fd = param->ctrlsocksrv;
|
||||
p->fds[p->nfds].events = POLLIN;
|
||||
p->ctrlsrv = p->nfds++;
|
||||
}
|
||||
}
|
||||
|
||||
static void udplog(struct clientparam *param)
|
||||
{
|
||||
unsigned char buf[400];
|
||||
int len;
|
||||
|
||||
if(!param->srv->logfunc) return;
|
||||
len = sprintf((char *)buf, "UDPMAP ");
|
||||
if(param->hostname) len += sprintf((char *)buf + len, "%.256s", param->hostname);
|
||||
else len += myinet_ntop(*SAFAMILY(¶m->req), SAADDR(¶m->req), (char *)buf + len, 64);
|
||||
sprintf((char *)buf + len, ":%hu", ntohs(*SAPORT(¶m->req)));
|
||||
param->srv->logfunc(param, buf);
|
||||
}
|
||||
|
||||
int udpbind(struct clientparam *param)
|
||||
{
|
||||
SOCKET s;
|
||||
SASIZETYPE sasize;
|
||||
|
||||
#ifdef __linux__
|
||||
if (switch_ns(param->srv, param->srv->o_nsfd)) return 11;
|
||||
#endif
|
||||
s = param->srv->so._socket(param->sostate, SASOCK(¶m->sinsl), SOCK_DGRAM, IPPROTO_UDP);
|
||||
#ifdef __linux__
|
||||
if (switch_ns(param->srv, param->srv->i_nsfd)) {
|
||||
if (s != INVALID_SOCKET) param->srv->so._closesocket(param->sostate, s);
|
||||
return 11;
|
||||
}
|
||||
#endif
|
||||
if (s == INVALID_SOCKET) return 11;
|
||||
#ifdef _WIN32
|
||||
{ unsigned long ul = 1; ioctlsocket(s, FIONBIO, &ul); }
|
||||
#else
|
||||
fcntl(s, F_SETFL, O_NONBLOCK | fcntl(s, F_GETFL));
|
||||
#endif
|
||||
param->remsock = s;
|
||||
if (extbindtodevice(param, param->remsock)) {
|
||||
param->srv->so._closesocket(param->sostate, param->remsock);
|
||||
param->remsock = INVALID_SOCKET;
|
||||
return 12;
|
||||
}
|
||||
if (param->srv->so._bind(param->sostate, param->remsock,
|
||||
(struct sockaddr *)¶m->sinsl, SASIZE(¶m->sinsl))) {
|
||||
*SAPORT(¶m->sinsl) = 0;
|
||||
if (param->srv->so._bind(param->sostate, param->remsock,
|
||||
(struct sockaddr *)¶m->sinsl, SASIZE(¶m->sinsl))) {
|
||||
param->srv->so._closesocket(param->sostate, param->remsock);
|
||||
param->remsock = INVALID_SOCKET;
|
||||
return 12;
|
||||
}
|
||||
}
|
||||
sasize = sizeof(param->sinsl);
|
||||
param->srv->so._getsockname(param->sostate, param->remsock,
|
||||
(struct sockaddr *)¶m->sinsl, &sasize);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void udpreset(struct clientparam *param)
|
||||
{
|
||||
param->redirected = 0;
|
||||
param->udp_nhops = 0;
|
||||
memset(param->udp_relay, 0, sizeof(param->udp_relay));
|
||||
#ifndef NOIPV6
|
||||
param->sinsl = *SAFAMILY(¶m->req) == AF_INET6? param->srv->extsa6 : param->srv->extsa;
|
||||
#else
|
||||
param->sinsl = param->srv->extsa;
|
||||
#endif
|
||||
param->sinsr = param->req;
|
||||
}
|
||||
|
||||
/*
|
||||
* Authorize param->req and (re)build the server side of the association:
|
||||
* a parent proxy chain and/or an external address may be selected by the ACL.
|
||||
* Returns the authorization result. param->remsock is INVALID_SOCKET when
|
||||
* the authorization refused the association or the socket can not be
|
||||
* created; the association can not continue then, so that a parent the
|
||||
* rules demand is never quietly replaced by a direct relay.
|
||||
*/
|
||||
static int udpreconnect(struct clientparam *param)
|
||||
{
|
||||
int res;
|
||||
|
||||
if (param->ctrlsocksrv != INVALID_SOCKET) {
|
||||
param->srv->so._closesocket(param->sostate, param->ctrlsocksrv);
|
||||
param->ctrlsocksrv = INVALID_SOCKET;
|
||||
}
|
||||
if (param->remsock != INVALID_SOCKET) {
|
||||
param->srv->so._closesocket(param->sostate, param->remsock);
|
||||
param->remsock = INVALID_SOCKET;
|
||||
}
|
||||
udpreset(param);
|
||||
res = (*param->srv->authfunc)(param);
|
||||
if (res) {
|
||||
if (param->ctrlsocksrv != INVALID_SOCKET) {
|
||||
param->srv->so._closesocket(param->sostate, param->ctrlsocksrv);
|
||||
param->ctrlsocksrv = INVALID_SOCKET;
|
||||
}
|
||||
if (param->remsock != INVALID_SOCKET) {
|
||||
param->srv->so._closesocket(param->sostate, param->remsock);
|
||||
param->remsock = INVALID_SOCKET;
|
||||
}
|
||||
udpreset(param);
|
||||
return res;
|
||||
}
|
||||
if (udpbind(param)) return 11;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int udpsockmap(struct clientparam *param, int timeo)
|
||||
{
|
||||
PROXYSOCKADDRTYPE sin;
|
||||
PROXYSOCKADDRTYPE cliaddr;
|
||||
PROXYSOCKADDRTYPE from;
|
||||
struct pollfd fds[4];
|
||||
PROXYSOCKADDRTYPE lastdst;
|
||||
struct udppoll p;
|
||||
SASIZETYPE sasize;
|
||||
int len, res, nfds;
|
||||
int nhops = param->udp_nhops;
|
||||
int clisock_idx = -1, ctrlsock_idx = -1, ctrlsocksrv_idx = -1;
|
||||
int len, res, nhops;
|
||||
int firstpacket = 1;
|
||||
|
||||
if(param->srv->service == S_UDPPM) nhops++;
|
||||
int havedst = 0, lastres = 0;
|
||||
char lastname[256] = "";
|
||||
struct ace *lastace = NULL;
|
||||
|
||||
if (param->srvbufsize < UDPBUFSIZE) {
|
||||
unsigned char *newbuf = realloc(param->srvbuf, UDPBUFSIZE);
|
||||
if (!newbuf) return 21;
|
||||
param->srvbuf = newbuf;
|
||||
param->srvbufsize = UDPBUFSIZE;
|
||||
}
|
||||
sin = param->sincr;
|
||||
|
||||
/* Build poll array once — sockets don't change across iterations */
|
||||
nfds = 0;
|
||||
fds[nfds].fd = param->remsock; /* always index 0 */
|
||||
fds[nfds].events = POLLIN;
|
||||
nfds++;
|
||||
|
||||
if (!param->waitserver64) {
|
||||
fds[nfds].fd = param->clisock;
|
||||
fds[nfds].events = POLLIN;
|
||||
clisock_idx = nfds++;
|
||||
cliaddr = param->sincr;
|
||||
if(param->ctrlsock != INVALID_SOCKET){
|
||||
sasize = sizeof(cliaddr);
|
||||
param->srv->so._getpeername(param->sostate, param->ctrlsock, (struct sockaddr *)&cliaddr, &sasize);
|
||||
}
|
||||
sin = cliaddr;
|
||||
|
||||
if (param->ctrlsock != INVALID_SOCKET) {
|
||||
fds[nfds].fd = param->ctrlsock;
|
||||
fds[nfds].events = POLLIN;
|
||||
ctrlsock_idx = nfds++;
|
||||
}
|
||||
|
||||
if (param->ctrlsocksrv != INVALID_SOCKET) {
|
||||
fds[nfds].fd = param->ctrlsocksrv;
|
||||
fds[nfds].events = POLLIN;
|
||||
ctrlsocksrv_idx = nfds++;
|
||||
}
|
||||
nhops = param->udp_nhops;
|
||||
if(param->srv->service == S_UDPPM) nhops++;
|
||||
udpfds(param, &p);
|
||||
|
||||
for (;;) {
|
||||
res = param->srv->so._poll(param->sostate, fds, nfds, timeo * 1000);
|
||||
res = param->srv->so._poll(param->sostate, p.fds, p.nfds, timeo * 1000);
|
||||
if (res < 0) return 481;
|
||||
if (res == 0) return 92;
|
||||
|
||||
/* datagram from client */
|
||||
if (clisock_idx >= 0 && fds[clisock_idx].revents) {
|
||||
int recvoff = 0, k;
|
||||
if (p.cli >= 0 && p.fds[p.cli].revents) {
|
||||
unsigned char *base = param->srvbuf + UDPHDROFF;
|
||||
PROXYSOCKADDRTYPE dst;
|
||||
char dstnamebuf[256];
|
||||
char *dstname = NULL;
|
||||
int i, k, w, off;
|
||||
|
||||
sasize = sizeof(sin);
|
||||
for (k = 1; k < nhops; k++)
|
||||
recvoff += 4 + (int)SAADDRLEN(¶m->udp_relay[k]) + 2;
|
||||
len = param->srv->so._recvfrom(param->sostate, param->clisock,
|
||||
(char *)param->srvbuf + recvoff, UDPBUFSIZE - recvoff,
|
||||
(char *)base, UDPBUFSIZE - UDPHDROFF,
|
||||
0, (struct sockaddr *)&sin, &sasize);
|
||||
if (len < 0 && (errno == EAGAIN || errno == EINTR)) continue;
|
||||
if (len <= 0) return 482;
|
||||
|
||||
if (SAADDRLEN(&sin) != SAADDRLEN(¶m->sincr) ||
|
||||
memcmp(SAADDR(&sin), SAADDR(¶m->sincr), SAADDRLEN(&sin)))
|
||||
if (SAADDRLEN(&sin) != SAADDRLEN(&cliaddr) ||
|
||||
memcmp(SAADDR(&sin), SAADDR(&cliaddr), SAADDRLEN(&sin)))
|
||||
continue;
|
||||
if (firstpacket) {
|
||||
if (!SAISNULL(¶m->req) && *SAPORT(¶m->req) &&
|
||||
@@ -118,70 +253,137 @@ int udpsockmap(struct clientparam *param, int timeo)
|
||||
!memcmp(SAADDR(¶m->req), SAADDR(&sin), SAADDRLEN(¶m->req)) &&
|
||||
memcmp(SAPORT(¶m->req), SAPORT(&sin), 2))
|
||||
continue;
|
||||
param->sincr = sin;
|
||||
cliaddr = sin;
|
||||
firstpacket = 0;
|
||||
} else if (memcmp(SAPORT(&sin), SAPORT(¶m->sincr), 2)) {
|
||||
} else if (memcmp(SAPORT(&sin), SAPORT(&cliaddr), 2)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(param->bandlimfunc && (*param->bandlimfunc)(param, 0, len)) continue;
|
||||
|
||||
if (nhops == 0) {
|
||||
int i;
|
||||
if (len < 10 || param->srvbuf[0] || param->srvbuf[1] || param->srvbuf[2])
|
||||
return 483;
|
||||
switch (param->srvbuf[3]) {
|
||||
case 1:
|
||||
*SAFAMILY(¶m->sinsr) = AF_INET;
|
||||
memcpy(SAADDR(¶m->sinsr), param->srvbuf + 4, 4);
|
||||
i = 8;
|
||||
break;
|
||||
case 4:
|
||||
if (len < 22) return 484;
|
||||
*SAFAMILY(¶m->sinsr) = AF_INET6;
|
||||
memcpy(SAADDR(¶m->sinsr), param->srvbuf + 4, 16);
|
||||
i = 20;
|
||||
break;
|
||||
case 3: {
|
||||
int sz = param->srvbuf[4], j;
|
||||
if (len < 7 + sz) return 485;
|
||||
for (j = 4; j < 4 + sz; j++) param->srvbuf[j] = param->srvbuf[j + 1];
|
||||
param->srvbuf[4 + sz] = 0;
|
||||
i = 5 + sz;
|
||||
if (!getip46(param->srv->family, param->srvbuf + 4,
|
||||
(struct sockaddr *)¶m->sinsr))
|
||||
return 100;
|
||||
break;
|
||||
if (len < 10 || base[0] || base[1] || base[2]) return 483;
|
||||
memset(&dst, 0, sizeof(dst));
|
||||
switch (base[3]) {
|
||||
case 1:
|
||||
if (socks5_setaddr(param->srv->family, 1, base + 4, &dst)) continue;
|
||||
i = 8;
|
||||
break;
|
||||
#ifndef NOIPV6
|
||||
case 4:
|
||||
if (len < 22) return 484;
|
||||
if (socks5_setaddr(param->srv->family, 4, base + 4, &dst)) continue;
|
||||
i = 20;
|
||||
break;
|
||||
#endif
|
||||
case 3: {
|
||||
int sz = base[4];
|
||||
if (len < 7 + sz) return 485;
|
||||
memcpy(dstnamebuf, base + 5, sz);
|
||||
dstnamebuf[sz] = 0;
|
||||
if (badhostname(dstnamebuf)) continue;
|
||||
dstname = dstnamebuf;
|
||||
i = 5 + sz;
|
||||
if (!getip46(param->srv->family, (unsigned char *)dstnamebuf,
|
||||
(struct sockaddr *)&dst)) {
|
||||
if (!nhops) return 100;
|
||||
memset(&dst, 0, sizeof(dst));
|
||||
*SAFAMILY(&dst) = AF_INET;
|
||||
}
|
||||
default: return 997;
|
||||
break;
|
||||
}
|
||||
default: return 997;
|
||||
}
|
||||
/* As for TCP requests, a literal address is the host name,
|
||||
otherwise an ACL with host names only matches any address */
|
||||
if (!dstname) {
|
||||
myinet_ntop(*SAFAMILY(&dst), SAADDR(&dst), dstnamebuf, sizeof(dstnamebuf));
|
||||
dstname = dstnamebuf;
|
||||
}
|
||||
memcpy(SAPORT(&dst), base + i, 2);
|
||||
i += 2;
|
||||
|
||||
if (!havedst
|
||||
|| SAADDRLEN(&lastdst) != SAADDRLEN(&dst)
|
||||
|| memcmp(SAADDR(&lastdst), SAADDR(&dst), SAADDRLEN(&dst))
|
||||
|| memcmp(SAPORT(&lastdst), SAPORT(&dst), 2)
|
||||
|| strncmp(lastname, dstname? dstname : "", sizeof(lastname) - 1)) {
|
||||
int ares = 0, reconnect = 0;
|
||||
|
||||
if ((param->srv->udpauth & 1) && havedst && !lastres) {
|
||||
PROXYSOCKADDRTYPE newdst = dst;
|
||||
|
||||
param->req = lastdst;
|
||||
if (param->hostname) free(param->hostname);
|
||||
param->hostname = *lastname? (unsigned char *)strdup(lastname) : NULL;
|
||||
udplog(param);
|
||||
dst = newdst;
|
||||
}
|
||||
memcpy(SAPORT(¶m->sinsr), param->srvbuf + i, 2);
|
||||
i += 2;
|
||||
if (param->hostname) free(param->hostname);
|
||||
param->hostname = dstname? (unsigned char *)strdup(dstname) : NULL;
|
||||
param->req = dst;
|
||||
if (!nhops) param->sinsr = dst;
|
||||
|
||||
if (!havedst) reconnect = 1;
|
||||
else if (!nhops && *SAFAMILY(&dst) != *SAFAMILY(¶m->sinsl)) reconnect = 1;
|
||||
if (havedst && (param->srv->udpauth & 2) && !param->dstindep) {
|
||||
param->preauth = 2;
|
||||
ares = (*param->srv->authfunc)(param);
|
||||
param->preauth = 0;
|
||||
if (ares == 2) {
|
||||
if (param->lastace != lastace) reconnect = 1;
|
||||
ares = 0;
|
||||
}
|
||||
else if (!ares && (param->redirected ||
|
||||
(lastace && lastace->chains))) reconnect = 1;
|
||||
}
|
||||
if (reconnect) {
|
||||
ares = udpreconnect(param);
|
||||
if (param->remsock == INVALID_SOCKET) return ares;
|
||||
nhops = param->udp_nhops;
|
||||
if(param->srv->service == S_UDPPM) nhops++;
|
||||
udpfds(param, &p);
|
||||
}
|
||||
lastres = ares;
|
||||
lastdst = dst;
|
||||
strncpy(lastname, dstname? dstname : "", sizeof(lastname) - 1);
|
||||
lastname[sizeof(lastname) - 1] = 0;
|
||||
havedst = 1;
|
||||
if (!ares) lastace = param->lastace;
|
||||
else if (param->srv->udpauth & 1) {
|
||||
param->res = ares;
|
||||
udplog(param);
|
||||
param->res = 0;
|
||||
}
|
||||
}
|
||||
if (lastres) continue;
|
||||
|
||||
if (!nhops) {
|
||||
if (len > i) {
|
||||
param->srv->so._sendto(param->sostate, param->remsock,
|
||||
(char *)param->srvbuf + i, len - i, 0,
|
||||
(struct sockaddr *)¶m->sinsr, SASIZE(¶m->sinsr));
|
||||
(char *)base + i, len - i, 0,
|
||||
(struct sockaddr *)¶m->sinsr, SASIZE(¶m->sinsr));
|
||||
param->statscli64 += (len - i);
|
||||
param->nwrites++;
|
||||
}
|
||||
} else {
|
||||
int off = 0;
|
||||
off = 0;
|
||||
for (k = 1; k < nhops; k++)
|
||||
off += socks5_udp_build_hdr(param->srvbuf + off, ¶m->udp_relay[k]);
|
||||
off += 4 + (int)SAADDRLEN(¶m->udp_relay[k]) + 2;
|
||||
for (k = 1, w = UDPHDROFF - off; k < nhops; k++)
|
||||
w += socks5_udp_build_hdr(param->srvbuf + w, ¶m->udp_relay[k]);
|
||||
param->srv->so._sendto(param->sostate, param->remsock,
|
||||
(char *)param->srvbuf, off + len, 0,
|
||||
(struct sockaddr *)¶m->udp_relay[0], SASIZE(¶m->udp_relay[0]));
|
||||
(char *)param->srvbuf + (UDPHDROFF - off), off + len, 0,
|
||||
(struct sockaddr *)¶m->udp_relay[0], SASIZE(¶m->udp_relay[0]));
|
||||
param->statscli64 += len;
|
||||
param->nwrites++;
|
||||
}
|
||||
}
|
||||
|
||||
/* datagram from server / parent relay */
|
||||
if (fds[0].revents) {
|
||||
int hdrsize = (nhops == 0) ? 4 + (int)SAADDRLEN(¶m->sinsr) + 2 : 0;
|
||||
if (p.fds[0].revents) {
|
||||
int hdrsize = (nhops == 0) ? 4 + (int)SAADDRLEN(¶m->sinsl) + 2 : 0;
|
||||
int sendoff = 0, sendlen;
|
||||
sasize = sizeof(from);
|
||||
if (hdrsize > UDPBUFSIZE) return 468;
|
||||
len = param->srv->so._recvfrom(param->sostate, param->remsock,
|
||||
(char *)param->srvbuf + hdrsize, UDPBUFSIZE - hdrsize, 0,
|
||||
(struct sockaddr *)&from, &sasize);
|
||||
@@ -201,9 +403,9 @@ int udpsockmap(struct clientparam *param, int timeo)
|
||||
sendlen = len;
|
||||
if (nhops == 0) {
|
||||
param->srvbuf[0] = param->srvbuf[1] = param->srvbuf[2] = 0;
|
||||
param->srvbuf[3] = (*SAFAMILY(¶m->sinsr) == AF_INET) ? 1 : 4;
|
||||
memcpy(param->srvbuf + 4, SAADDR(¶m->sinsr), SAADDRLEN(¶m->sinsr));
|
||||
memcpy(param->srvbuf + 4 + SAADDRLEN(¶m->sinsr), SAPORT(¶m->sinsr), 2);
|
||||
param->srvbuf[3] = (*SAFAMILY(&from) == AF_INET) ? 1 : 4;
|
||||
memcpy(param->srvbuf + 4, SAADDR(&from), SAADDRLEN(¶m->sinsl));
|
||||
memcpy(param->srvbuf + 4 + SAADDRLEN(¶m->sinsl), SAPORT(&from), 2);
|
||||
sendlen = len + hdrsize;
|
||||
} else if (nhops >= 2) {
|
||||
int off = 0, k;
|
||||
@@ -219,13 +421,13 @@ int udpsockmap(struct clientparam *param, int timeo)
|
||||
}
|
||||
if (sendlen > 0)
|
||||
param->srv->so._sendto(param->sostate, param->clisock,
|
||||
(char *)param->srvbuf + sendoff, sendlen, 0,
|
||||
(struct sockaddr *)&sin, SASIZE(&sin));
|
||||
(char *)param->srvbuf + sendoff, sendlen, 0,
|
||||
(struct sockaddr *)&sin, SASIZE(&sin));
|
||||
if (param->srv->s_option && param->srv->service == S_UDPPM) return 0;
|
||||
}
|
||||
|
||||
if ((ctrlsock_idx >= 0 && fds[ctrlsock_idx].revents) ||
|
||||
(ctrlsocksrv_idx >= 0 && fds[ctrlsocksrv_idx].revents)) return 0;
|
||||
if ((p.ctrl >= 0 && p.fds[p.ctrl].revents) ||
|
||||
(p.ctrlsrv >= 0 && p.fds[p.ctrlsrv].revents)) return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
+5
-5
@@ -1,14 +1,14 @@
|
||||
#ifndef VERSION
|
||||
#define VERSION "3proxy-0.9.8"
|
||||
#define VERSION "3proxy-0.9.9.4"
|
||||
#endif
|
||||
#ifndef BUILDDATE
|
||||
#define BUILDDATE ""
|
||||
#define BUILDDATE "261121091843"
|
||||
#endif
|
||||
#define MAJOR3PROXY 0
|
||||
#define SUBMAJOR3PROXY 9
|
||||
#define MINOR3PROXY 8
|
||||
#define SUBMINOR3PROXY 0
|
||||
#define RELEASE3PROXY "3proxy-0.9.8(" BUILDDATE ")\0"
|
||||
#define MINOR3PROXY 9
|
||||
#define SUBMINOR3PROXY 4
|
||||
#define RELEASE3PROXY "3proxy-0.9.9.4(" BUILDDATE ")\0"
|
||||
#ifndef YEAR3PROXY
|
||||
#define YEAR3PROXY "2026"
|
||||
#endif
|
||||
Reference in new issue
Block a user