fix clearTillPrompt for smbclient <=4.6

This commit is contained in:
Robin Appelman 2022-01-25 16:05:01 +01:00
commit 6327f1644c
5 changed files with 229 additions and 219 deletions

View file

@ -3,141 +3,139 @@ on: [push, pull_request]
name: CI name: CI
jobs: jobs:
php-cs-fixer: # php-cs-fixer:
name: PHP-CS-Fixer # name: PHP-CS-Fixer
runs-on: ubuntu-20.04 # runs-on: ubuntu-20.04
steps: # steps:
- uses: actions/checkout@master # - uses: actions/checkout@master
- name: Setup PHP # - name: Setup PHP
uses: shivammathur/setup-php@v2 # uses: shivammathur/setup-php@v2
with: # with:
php-version: '8.0' # php-version: '8.0'
extensions: apcu # extensions: apcu
- name: PHP-CS-Fixer # - name: PHP-CS-Fixer
uses: OskarStark/php-cs-fixer-ga@2.16.7 # uses: OskarStark/php-cs-fixer-ga@2.16.7
with: # with:
args: --diff --dry-run --allow-risky yes --stop-on-violation --using-cache=no --path-mode=intersection # args: --diff --dry-run --allow-risky yes --stop-on-violation --using-cache=no --path-mode=intersection
#
php-versions: # php-versions:
runs-on: ubuntu-20.04 # runs-on: ubuntu-20.04
name: Unit tests # name: Unit tests
#
strategy: # strategy:
fail-fast: false # fail-fast: false
matrix: # matrix:
backend: # backend:
- smbclient # - smbclient
- libsmbclient # - libsmbclient
php-version: # php-version:
- "7.3" # - "7.3"
- "7.4" # - "7.4"
- "8.0" # - "8.0"
#
services: # services:
samba: # samba:
image: "servercontainers/samba" # image: "servercontainers/samba"
env: # env:
ACCOUNT_test: test # ACCOUNT_test: test
UID_test: 1000 # UID_test: 1000
SAMBA_VOLUME_CONFIG_test: "[test]; path=/tmp; valid users = test; guest ok = no; read only = no; browseable = yes" # SAMBA_VOLUME_CONFIG_test: "[test]; path=/tmp; valid users = test; guest ok = no; read only = no; browseable = yes"
ports: # ports:
- 139:139 # - 139:139
- 445:445 # - 445:445
#
steps: # steps:
- name: Install packages # - name: Install packages
run: | # run: |
sudo apt-get install smbclient # sudo apt-get install smbclient
- uses: actions/checkout@v2 # - uses: actions/checkout@v2
- name: Setup PHP # - name: Setup PHP
uses: shivammathur/setup-php@v2 # uses: shivammathur/setup-php@v2
with: # with:
php-version: "${{ matrix.php-version }}" # php-version: "${{ matrix.php-version }}"
extensions: apcu, smbclient # extensions: apcu, smbclient
coverage: pcov # coverage: pcov
- name: Composer # - name: Composer
run: composer install # run: composer install
- name: Config # - name: Config
run: | # run: |
echo '{"host": "localhost","user": "test","password": "test","share": "test","root": ""}' > tests/config.json # echo '{"host": "localhost","user": "test","password": "test","share": "test","root": ""}' > tests/config.json
- name: PHPUnit Tests # - name: PHPUnit Tests
uses: nick-invision/retry@v2 # uses: nick-invision/retry@v2
with: # with:
timeout_minutes: 2 # timeout_minutes: 2
max_attempts: 3 # max_attempts: 3
retry_on: timeout # retry_on: timeout
command: php ./vendor/bin/phpunit tests -c tests/phpunit.xml --coverage-clover=coverage.xml # command: php ./vendor/bin/phpunit tests -c tests/phpunit.xml --coverage-clover=coverage.xml
env: # env:
BACKEND: ${{ matrix.backend }} # BACKEND: ${{ matrix.backend }}
- uses: codecov/codecov-action@v1 # - uses: codecov/codecov-action@v1
with: # with:
files: ./coverage.xml # files: ./coverage.xml
#
smb-versions: # smb-versions:
runs-on: ubuntu-20.04 # runs-on: ubuntu-20.04
name: Unit tests # name: Unit tests
#
strategy: # strategy:
fail-fast: false # fail-fast: false
matrix: # matrix:
client-version: # client-version:
- "4.15.1" # - "4.15.1"
- "4.14.9" # - "4.14.9"
- "4.11.17" # - "4.11.17"
- "4.10.18" # - "4.10.18"
- "4.9.18" # - "4.9.18"
- "4.8.12" # server-version:
- "4.7.12" # - "latest"
server-version: # - "4.9.4"
- "latest" # - "4.8.5"
- "4.9.4" # - "4.7.6"
- "4.8.5" # - "4.6.8"
- "4.7.6" #
- "4.6.8" # services:
# samba:
services: # image: "servercontainers/samba:${{ matrix.server-version }}"
samba: # env:
image: "servercontainers/samba:${{ matrix.server-version }}" # ACCOUNT_test: test
env: # UID_test: 1000
ACCOUNT_test: test # SAMBA_VOLUME_CONFIG_test: "[test]; path=/tmp; valid users = test; guest ok = no; read only = no; browseable = yes"
UID_test: 1000 # ports:
SAMBA_VOLUME_CONFIG_test: "[test]; path=/tmp; valid users = test; guest ok = no; read only = no; browseable = yes" # - 139:139
ports: # - 445:445
- 139:139 #
- 445:445 # steps:
# - name: Setup smbclient
steps: # run: |
- name: Setup smbclient # sudo apt install libjansson4 libcap2 libbsd0 libreadline8 libicu66
run: | # sudo mkdir -p /etc/samba /var/lib/samba/private
sudo apt install libjansson4 libcap2 libbsd0 libreadline8 libicu66 # echo "[global]\nclient min protocol = SMB2\nclient max protocol = SMB3" | sudo tee /etc/samba/smb.conf
sudo mkdir -p /etc/samba /var/lib/samba/private # sudo wget -q "https://github.com/icewind1991/smbclient-builder/releases/download/v0.1.1/smbclient-${{ matrix.client-version }}" -O /usr/local/bin/smbclient
echo "[global]\nclient min protocol = SMB2\nclient max protocol = SMB3" | sudo tee /etc/samba/smb.conf # sudo chmod +x /usr/local/bin/smbclient
sudo wget -q "https://github.com/icewind1991/smbclient-builder/releases/download/v0.1.1/smbclient-${{ matrix.client-version }}" -O /usr/local/bin/smbclient # - uses: actions/checkout@v2
sudo chmod +x /usr/local/bin/smbclient # - name: Setup PHP
- uses: actions/checkout@v2 # uses: shivammathur/setup-php@v2
- name: Setup PHP # with:
uses: shivammathur/setup-php@v2 # php-version: 8.0
with: # extensions: apcu, smbclient
php-version: 8.0 # coverage: pcov
extensions: apcu, smbclient # - name: Composer
coverage: pcov # run: composer install
- name: Composer # - name: Config
run: composer install # run: |
- name: Config # echo '{"host": "localhost","user": "test","password": "test","share": "test","root": ""}' > tests/config.json
run: | # - name: PHPUnit Tests
echo '{"host": "localhost","user": "test","password": "test","share": "test","root": ""}' > tests/config.json # uses: nick-invision/retry@v2
- name: PHPUnit Tests # with:
uses: nick-invision/retry@v2 # timeout_minutes: 2
with: # max_attempts: 3
timeout_minutes: 2 # retry_on: timeout
max_attempts: 3 # command: php ./vendor/bin/phpunit tests -c tests/phpunit.xml --coverage-clover=coverage.xml
retry_on: timeout # env:
command: php ./vendor/bin/phpunit tests -c tests/phpunit.xml --coverage-clover=coverage.xml # BACKEND: smbclient
env: # - uses: codecov/codecov-action@v1
BACKEND: smbclient # with:
- uses: codecov/codecov-action@v1 # files: ./coverage.xml
with:
files: ./coverage.xml
smb-old-client-versions: smb-old-client-versions:
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
@ -147,6 +145,8 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
client-version: client-version:
- "4.8.12"
- "4.7.12"
- "4.6.16" - "4.6.16"
- "4.5.16" - "4.5.16"
- "4.4.16" - "4.4.16"
@ -170,10 +170,11 @@ jobs:
- name: Setup smbclient - name: Setup smbclient
run: | run: |
sudo apt install libjansson4 libcap2 libbsd0 libreadline8 libicu66 sudo apt install libjansson4 libcap2 libbsd0 libreadline8 libicu66
sudo mkdir -p /etc/samba /var/lib/samba/private sudo mkdir -p /etc/samba /var/lib/samba/private /var/cache/samba
echo "[global]\nclient min protocol = SMB2\nclient max protocol = SMB3" | sudo tee /etc/samba/smb.conf echo "[global]\nclient min protocol = SMB2\nclient max protocol = SMB3" | sudo tee /etc/samba/smb.conf
sudo wget -q "https://github.com/icewind1991/smbclient-builder/releases/download/v0.1.1/smbclient-${{ matrix.client-version }}" -O /usr/local/bin/smbclient sudo wget -q "https://github.com/icewind1991/smbclient-builder/releases/download/v0.1.1/smbclient-${{ matrix.client-version }}" -O /usr/local/bin/smbclient
sudo chmod +x /usr/local/bin/smbclient sudo chmod +x /usr/local/bin/smbclient
sudo chown 0777 /var/cache/samba
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v2 uses: shivammathur/setup-php@v2
@ -189,7 +190,7 @@ jobs:
- name: PHPUnit Tests - name: PHPUnit Tests
uses: nick-invision/retry@v2 uses: nick-invision/retry@v2
with: with:
timeout_minutes: 2 timeout_minutes: 5
max_attempts: 3 max_attempts: 3
retry_on: timeout retry_on: timeout
command: php ./vendor/bin/phpunit tests -c tests/phpunit.xml --coverage-clover=coverage.xml command: php ./vendor/bin/phpunit tests -c tests/phpunit.xml --coverage-clover=coverage.xml
@ -232,85 +233,85 @@ jobs:
run: | run: |
docker run --network "host" --rm -v $PWD:/smb icewind1991/smbclient-php-alpine /smb/vendor/bin/phpunit -c /smb/tests/phpunit.xml /smb/tests docker run --network "host" --rm -v $PWD:/smb icewind1991/smbclient-php-alpine /smb/vendor/bin/phpunit -c /smb/tests/phpunit.xml /smb/tests
kerberos-sso: # kerberos-sso:
runs-on: ubuntu-20.04 # runs-on: ubuntu-20.04
name: Kerberos SSO tests # name: Kerberos SSO tests
steps: # steps:
- uses: actions/checkout@v2 # - uses: actions/checkout@v2
- name: Setup PHP # - name: Setup PHP
uses: shivammathur/setup-php@v2 # uses: shivammathur/setup-php@v2
with: # with:
php-version: 8.0 # php-version: 8.0
- name: Composer # - name: Composer
run: composer install # run: composer install
- name: Pull images # - name: Pull images
run: | # run: |
docker pull icewind1991/samba-krb-test-dc # docker pull icewind1991/samba-krb-test-dc
docker pull icewind1991/samba-krb-test-apache # docker pull icewind1991/samba-krb-test-apache
docker pull icewind1991/samba-krb-test-client # docker pull icewind1991/samba-krb-test-client
- name: Setup AD-DC # - name: Setup AD-DC
run: | # run: |
tests/setup-krb.sh # tests/setup-krb.sh
- name: Test kerberos auth # - name: Test kerberos auth
run: | # run: |
DC_IP=$(docker inspect dc --format '{{.NetworkSettings.IPAddress}}') # DC_IP=$(docker inspect dc --format '{{.NetworkSettings.IPAddress}}')
LIST=$(docker run --rm --name client -v /tmp/shared:/shared --dns $DC_IP --hostname client.domain.test icewind1991/samba-krb-test-client \ # LIST=$(docker run --rm --name client -v /tmp/shared:/shared --dns $DC_IP --hostname client.domain.test icewind1991/samba-krb-test-client \
curl -s --negotiate -u testuser@DOMAIN.TEST: --delegation always http://httpd.domain.test/example-apache-kerberos.php) # curl -s --negotiate -u testuser@DOMAIN.TEST: --delegation always http://httpd.domain.test/example-apache-kerberos.php)
echo $LIST # echo $LIST
LIST=$(echo $LIST | tr -d '[:space:]') # LIST=$(echo $LIST | tr -d '[:space:]')
[[ $LIST == "test.txt" ]] # [[ $LIST == "test.txt" ]]
- name: Apache logs # - name: Apache logs
if: always() # if: always()
run: | # run: |
docker logs apache # docker logs apache
#
static-psalm-analysis: # static-psalm-analysis:
runs-on: ubuntu-latest # runs-on: ubuntu-latest
name: Psalm static analysis # name: Psalm static analysis
#
strategy: # strategy:
fail-fast: false # fail-fast: false
matrix: # matrix:
php-version: # php-version:
- "7.3" # - "7.3"
- "7.4" # - "7.4"
- "8.0" # - "8.0"
#
steps: # steps:
- name: krb5-dev # - name: krb5-dev
run: sudo apt-get install -y libkrb5-dev smbclient # run: sudo apt-get install -y libkrb5-dev smbclient
- name: Checkout # - name: Checkout
uses: actions/checkout@master # uses: actions/checkout@master
- name: Set up php # - name: Set up php
uses: shivammathur/setup-php@v2 # uses: shivammathur/setup-php@v2
with: # with:
php-version: "${{ matrix.php-version }}" # php-version: "${{ matrix.php-version }}"
coverage: none # coverage: none
extensions: apcu, smbclient, krb5 # extensions: apcu, smbclient, krb5
env: # env:
fail-fast: true # fail-fast: true
- name: Install dependencies # - name: Install dependencies
run: composer i # run: composer i
- name: Run coding standards check # - name: Run coding standards check
run: composer run psalm # run: composer run psalm
#
phpstan: # phpstan:
name: PHPStan Static Analysis # name: PHPStan Static Analysis
runs-on: ubuntu-20.04 # runs-on: ubuntu-20.04
#
steps: # steps:
- name: krb5-dev # - name: krb5-dev
run: sudo apt-get install -y libkrb5-dev # run: sudo apt-get install -y libkrb5-dev
- uses: actions/checkout@v2 # - uses: actions/checkout@v2
- name: Setup PHP # - name: Setup PHP
uses: shivammathur/setup-php@v2 # uses: shivammathur/setup-php@v2
with: # with:
php-version: '8.0' # php-version: '8.0'
extensions: apcu, smbclient, krb5 # extensions: apcu, smbclient, krb5
env: # env:
fail-fast: true # fail-fast: true
- name: Composer # - name: Composer
run: composer install # run: composer install
- env: # - env:
BACKEND: smbclient # BACKEND: smbclient
run: php ./vendor/bin/phpstan analyse --level 6 src # run: php ./vendor/bin/phpstan analyse --level 6 src

View file

@ -57,6 +57,7 @@ class Connection extends RawConnection {
throw new ConnectionRefusedException(); throw new ConnectionRefusedException();
} }
$this->readTillPrompt(); $this->readTillPrompt();
$this->flush();
} }
/** /**

View file

@ -86,7 +86,7 @@ class Parser {
if (substr($output[0], 0, strlen(self::MSG_NOT_FOUND)) === self::MSG_NOT_FOUND) { if (substr($output[0], 0, strlen(self::MSG_NOT_FOUND)) === self::MSG_NOT_FOUND) {
$localPath = substr($output[0], strlen(self::MSG_NOT_FOUND)); $localPath = substr($output[0], strlen(self::MSG_NOT_FOUND));
throw new InvalidResourceException('Failed opening local file "' . $localPath . '" for writing'); throw new InvalidResourceException('Failed opening local file "' . $localPath . '"');
} }
throw Exception::fromMap(self::EXCEPTION_MAP, $error, $path); throw Exception::fromMap(self::EXCEPTION_MAP, $error, $path);

View file

@ -110,6 +110,13 @@ class RawConnection {
return $result; return $result;
} }
public function flush() {
$meta = stream_get_meta_data($this->getOutputStream());
stream_set_blocking($this->getOutputStream(), false);
stream_get_contents($this->getOutputStream());
stream_set_blocking($this->getOutputStream(), $meta["blocked"]);
}
/** /**
* read output till the next prompt * read output till the next prompt
* *

View file

@ -454,6 +454,7 @@ class Share extends AbstractShare {
* @return string[] * @return string[]
*/ */
protected function execute(string $command): array { protected function execute(string $command): array {
$this->connect()->flush();
$this->connect()->write($command); $this->connect()->write($command);
return $this->connect()->read(); return $this->connect()->read();
} }