Failing to use sambal command on irb console / rails console
jhonatsz opened this issue · 8 comments
=> #<Sambal::Client:0x00005581c1efc368 @timeout=10, @output=#<File:/dev/pts/2>, @input=#<File:/dev/pts/2>, @pid=7649, @connected=true>
irb(main):005:0> client.ls
Failed to do ls "*"
Traceback (most recent call last):
7: from /usr/local/bin/irb:23:in `<main>'
6: from /usr/local/bin/irb:23:in `load'
5: from /usr/local/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `<top (required)>'
4: from (irb):5
3: from /usr/local/bundle/gems/sambal-0.2.2/lib/sambal/client.rb:98:in `ls'
2: from /usr/local/bundle/gems/sambal-0.2.2/lib/sambal/client.rb:266:in `ask_wrapped'
1: from /usr/local/bundle/gems/sambal-0.2.2/lib/sambal/client.rb:259:in `ask'
RuntimeError (Failed to do ls "*")
These are the scenarios ive tried with sambal client on rails and its seems like im failing to use commands on rails console only
- smbclient (ok)
- rails console (fail)
- telnet (ok)
my gem version is 0.2.2
It's likely something about the rails console environment that causes this. Perhaps causes issues with the pty. Been a long time since I worked on this. Maybe reading https://ruby-doc.org/stdlib-2.5.3/libdoc/pty/rdoc/PTY.html would help?
will take a look into this one. though right now been able to make it work by switching from debian to ubuntu image. This seems to solve my issue. But the cons is i need to build an ubuntu image with ruby first instead of using the official ruby image based on debian.
my initial thought was why is this lib not working on any debian os env
I am having the same problem using debian.
I dont quite understand the solution that you have sugested @jhonatsz
Does that mean that when you install the gem in ubuntu it works?
Is it possible to use the ubuntu gem in debian?
@danielnielsennumber1 there is no ubuntu gem, i did switch my base image to ubuntu and install ruby that works for me.
That makes sense.
Since im using debian as my system OS i cant just do that.
Im trying to debug on this problem to find a solution.
I have monkeypatched the gem so i can get the input/output ptys(they are the same though)
It seems like the PTY does not get the last line from the smbclient. "smb: >"
It just hangs forever. Im not sure if the problem is in the smbclient end or pty.
❯ smbclient '**host and share**' -U *user**/*pass**
Try "help" to get a list of possible commands.
smb: \> ls *
. D 0 Thu Dec 6 10:17:05 2018
.. D 0 Thu Dec 6 10:17:05 2018
Faktura D 0 Fri Apr 8 15:09:29 2022
fakturatest D 0 Thu Dec 6 11:59:00 2018
kontoudtog D 0 Mon Sep 6 09:18:56 2021
test D 0 Tue Sep 11 10:16:22 2018
262143231 blocks of size 4096. 114399680 blocks available
smb: \>
from (pry):25:in `gets'
[15] [spec_crm][development] pry(main)> client.input.puts("ls * ")
=> nil
[16] [spec_crm][development] pry(main)> client.output.gets
=> "ls * \r\n"
[17] [spec_crm][development] pry(main)> client.output.gets
=> "\e[?2004l\r . D 0 Thu Dec 6 10:17:05 2018\r\n"
[18] [spec_crm][development] pry(main)> client.output.gets
=> " .. D 0 Thu Dec 6 10:17:05 2018\r\n"
[19] [spec_crm][development] pry(main)> client.output.gets
=> " Faktura D 0 Fri Apr 8 15:09:29 2022\r\n"
[20] [spec_crm][development] pry(main)> client.output.gets
=> " fakturatest D 0 Thu Dec 6 11:59:00 2018\r\n"
[21] [spec_crm][development] pry(main)> client.output.gets
=> " kontoudtog D 0 Mon Sep 6 09:18:56 2021\r\n"
[22] [spec_crm][development] pry(main)> client.output.gets
=> " test D 0 Tue Sep 11 10:16:22 2018\r\n"
[23] [spec_crm][development] pry(main)> client.output.gets
=> "\r\n"
[24] [spec_crm][development] pry(main)> client.output.gets
=> "\t\t262143231 blocks of size 4096. 114399680 blocks available\r\n"
[25] [spec_crm][development] pry(main)> client.output.gets
^CInterrupt:
from (pry):36:in `gets'
If i do two writes I can get past the hang the first time and i see some strange characters
=> "\e[?2004hsmb: \> ls * \r\n"
[71] [spec_crm][development] pry(main)> client.input.puts("ls * ")
=> nil
[72] [spec_crm][development] pry(main)> client.input.puts("ls * ")
=> nil
[73] [spec_crm][development] pry(main)> client.output.gets
=> "ls * \r\n"
[74] [spec_crm][development] pry(main)> client.output.gets
=> "\e[?2004l\r . D 0 Thu Dec 6 10:17:05 2018\r\n"
[75] [spec_crm][development] pry(main)> client.output.gets
=> " .. D 0 Thu Dec 6 10:17:05 2018\r\n"
[76] [spec_crm][development] pry(main)> client.output.gets
=> " Faktura D 0 Fri Apr 8 15:09:29 2022\r\n"
[77] [spec_crm][development] pry(main)> client.output.gets
=> " fakturatest D 0 Thu Dec 6 11:59:00 2018\r\n"
[78] [spec_crm][development] pry(main)> client.output.gets
=> " kontoudtog D 0 Mon Sep 6 09:18:56 2021\r\n"
[79] [spec_crm][development] pry(main)> client.output.gets
=> " test D 0 Tue Sep 11 10:16:22 2018\r\n"
[80] [spec_crm][development] pry(main)> client.output.gets
=> "\r\n"
[81] [spec_crm][development] pry(main)> client.output.gets
=> "\t\t262143231 blocks of size 4096. 114399680 blocks available\r\n"
[82] [spec_crm][development] pry(main)> client.output.gets
=> "\e[?2004hsmb: \\> ls * \r\n"
[83] [spec_crm][development] pry(main)> client.output.gets
=> "\e[?2004l\r . D 0 Thu Dec 6 10:17:05 2018\r\n"
[84] [spec_crm][development] pry(main)> client.output.gets
=> " .. D 0 Thu Dec 6 10:17:05 2018\r\n"
[85] [spec_crm][development] pry(main)> client.output.gets
=> " Faktura D 0 Fri Apr 8 15:09:29 2022\r\n"
[86] [spec_crm][development] pry(main)> client.output.gets
=> " fakturatest D 0 Thu Dec 6 11:59:00 2018\r\n"
[87] [spec_crm][development] pry(main)> client.output.gets
=> " kontoudtog D 0 Mon Sep 6 09:18:56 2021\r\n"
[88] [spec_crm][development] pry(main)> client.output.gets
=> " test D 0 Tue Sep 11 10:16:22 2018\r\n"
[89] [spec_crm][development] pry(main)> client.output.gets
=> "\r\n"
[90] [spec_crm][development] pry(main)> client.output.gets
=> "\t\t262143231 blocks of size 4096. 114399680 blocks available\r\n"
[91] [spec_crm][development] pry(main)> client.output.gets
since my usecase is quite simple im just gonna use system for now. But maybe this will help someone else who has the problem who knows more about ptys and control chars.
I don't have any suggestions on how to resolve this issue, but I can confirm that it is different between Debian and Ubuntu.
After experiencing the issue that my connections were succeeding, but I couldn't navigate on Debian, I spun up a separate Ubuntu instance (WSL2) and rebuilt my dev environment. The connections were fine straight away in there.
Thanks @stuartluscombe @danielnielsennumber1 for having time checking it out.