example.php not working #95

Open
opened 2020-08-13 12:16:09 +02:00 by ondics · 5 comments
ondics commented 2020-08-13 12:16:09 +02:00 (Migrated from github.com)
$ smbclient -U samba -L samba

gives:

Enter MYGROUP\samba's password:

        Sharename       Type      Comment
        ---------       ----      -------
        myshare         Disk
        IPC$            IPC       IPC Service (file server)
Reconnecting with SMB1 for workgroup listing.

        Server               Comment
        ---------            -------

        Workgroup            Master
        ---------            -------

example.php is configured as follows:

$host = 'samba';
$user = 'samba';
$workgroup = '';
$password = 'samba';
$share = 'myshare';

$auth = new \Icewind\SMB\BasicAuth($user, $workgroup, $password);
$serverFactory = new \Icewind\SMB\ServerFactory();
$server = $serverFactory->createServer($host, $auth);
$shares = $server->listShares();
foreach ($shares as $s) {
        echo $s->getName() . "\n";
}

$share = $server->getShare($share);
$files = $share->dir('/');            // PHP hangs in this line forever!!!
foreach ($files as $file) {
        echo $file->getName() . "\n";
}

Output:

myshare

And then, example.php hangs forever. What is going wrong here? How to debug?

My OS is Alpine (Docker). PHP Version 7.2.12

$ smbclient -U samba -L samba gives: ``` Enter MYGROUP\samba's password: Sharename Type Comment --------- ---- ------- myshare Disk IPC$ IPC IPC Service (file server) Reconnecting with SMB1 for workgroup listing. Server Comment --------- ------- Workgroup Master --------- ------- ``` example.php is configured as follows: ``` $host = 'samba'; $user = 'samba'; $workgroup = ''; $password = 'samba'; $share = 'myshare'; $auth = new \Icewind\SMB\BasicAuth($user, $workgroup, $password); $serverFactory = new \Icewind\SMB\ServerFactory(); $server = $serverFactory->createServer($host, $auth); $shares = $server->listShares(); foreach ($shares as $s) { echo $s->getName() . "\n"; } $share = $server->getShare($share); $files = $share->dir('/'); // PHP hangs in this line forever!!! foreach ($files as $file) { echo $file->getName() . "\n"; } ``` Output: myshare And then, example.php hangs forever. What is going wrong here? How to debug? My OS is Alpine (Docker). PHP Version 7.2.12
WeeSee commented 2020-08-14 10:15:33 +02:00 (Migrated from github.com)

I have the same problem. When executing

strace php example.php

the last lines are:

fstat(13, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0
fcntl(13, F_SETFD, FD_CLOEXEC)          = 0
close(15)                               = 0
fstat(14, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0
fcntl(14, F_SETFD, FD_CLOEXEC)          = 0
wait4(285, 0x7fff30d0d0a4, WNOHANG|WSTOPPED, NULL) = 0
wait4(285, 0x7fff30d0d174, WNOHANG|WSTOPPED, NULL) = 0
write(5, "\n", 1)                       = 1
read(6, "Try \"help\" to get a list of poss"..., 8192) = 47
read(6, "smb: \\> ", 8192)              = 8
read(6, "smb: \\> ", 16376)             = 8

This seems to be a wrong command submitted to smbclient so that smbclient goes into interactive mode.

What next?

Working with Alpine Linux and

$ smbclient --version
Version 4.8.12
I have the same problem. When executing strace php example.php the last lines are: ``` fstat(13, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0 fcntl(13, F_SETFD, FD_CLOEXEC) = 0 close(15) = 0 fstat(14, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0 fcntl(14, F_SETFD, FD_CLOEXEC) = 0 wait4(285, 0x7fff30d0d0a4, WNOHANG|WSTOPPED, NULL) = 0 wait4(285, 0x7fff30d0d174, WNOHANG|WSTOPPED, NULL) = 0 write(5, "\n", 1) = 1 read(6, "Try \"help\" to get a list of poss"..., 8192) = 47 read(6, "smb: \\> ", 8192) = 8 read(6, "smb: \\> ", 16376) = 8 ``` This seems to be a wrong command submitted to smbclient so that smbclient goes into interactive mode. What next? Working with Alpine Linux and $ smbclient --version Version 4.8.12
WeeSee commented 2020-08-14 11:10:15 +02:00 (Migrated from github.com)

Found it,

I had just installed smbclient in the Alpine image:

apk add samba-client

So, the smbclient was used by this repo and not libsmbclient-php.

Then I added phpsmbclient to the image in the Dockerfile:

RUN apk --update --virtual build-deps add --no-cache  \
        autoconf \
        make \
        gcc \
        g++ \
        gmp-dev \
    && apk add --no-cache \
        samba-client \
        samba-dev  \
    && pecl channel-update pecl.php.net \
    && pecl install smbclient  \
    && docker-php-ext-enable smbclient \
    && docker-php-source delete \
    && docker-php-ext-install -j16 gmp \
    && rm -rf /tmp/* \
    && apk del build-deps

Now the libsmbclient-php is selected and everything works like charm.

Found it, I had just installed smbclient in the Alpine image: apk add samba-client So, the smbclient was used by this repo and not [libsmbclient-php](https://github.com/eduardok/libsmbclient-php). Then I added `phpsmbclient` to the image in the Dockerfile: ``` RUN apk --update --virtual build-deps add --no-cache \ autoconf \ make \ gcc \ g++ \ gmp-dev \ && apk add --no-cache \ samba-client \ samba-dev \ && pecl channel-update pecl.php.net \ && pecl install smbclient \ && docker-php-ext-enable smbclient \ && docker-php-source delete \ && docker-php-ext-install -j16 gmp \ && rm -rf /tmp/* \ && apk del build-deps ``` Now the [libsmbclient-php](https://github.com/eduardok/libsmbclient-php) is selected and everything works like charm.
WeeSee commented 2020-08-14 11:10:43 +02:00 (Migrated from github.com)

Issue can be closed. I'm happy.

Issue can be closed. I'm happy.
MatthiasKuehneEllerhold commented 2020-08-14 11:25:38 +02:00 (Migrated from github.com)

So it seems like this problem only happens when this lib is using the smbclient executable instead of the extension?

So it seems like this problem only happens when this lib is using the `smbclient` executable instead of the extension?
WeeSee commented 2020-08-14 11:27:01 +02:00 (Migrated from github.com)

So it seems like this problem only happens when this lib is using the smbclient executable instead of the extension?

Yes. This is what happened here.

Using the smbclient leads to the smbclientcommand line mode and then waits for input- forever :-(

> > > So it seems like this problem only happens when this lib is using the `smbclient` executable instead of the extension? Yes. This is what happened here. Using the `smbclient` leads to the `smbclient`command line mode and then waits for input- forever :-(
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
icewind/SMB#95
No description provided.