Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: zpty woes
- X-seq: zsh-workers 25041
- From: Jaime Vargas <jev@xxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: Re: zpty woes
- Date: Thu, 15 May 2008 12:25:44 -0400
- In-reply-to: <20080515145054.GC5190@xxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <34AE8142-F5DA-44FD-96BA-61BDE12BC74E@xxxxxxx> <200805151318.m4FDIvKS015244@xxxxxxxxxxxxxx> <20080515145054.GC5190@xxxxxxxxxxxxxxx>
Still doesn't work for me. Below is the modified script and the debug
output.
#!/opt/csw/bin/zsh
set -x
zmodload zsh/zpty
die() {print -r -- $1 >&2; exit 1;}
zpty scppty scp hello.world jvargas@xxxxxxxxxxxxxxxxxxxxxxxxxxx:~/
zpty -t scppty || die "fuck"
zpty -r scppty line "*:" || die "no password asked"
zpty -w scppty "3lp&tbw"
while zpty -r scppty line;
do
result+="$line"$'\n'
done
zpty -d scppty
print $result
I changed my credentials for security. Basically it now hangs waitng
for password and doesnt' do anything. -- Jaime
nerd% ./zpty-test.zsh
+./zpty-test.zsh:5> zmodload zsh/zpty
+./zpty-test.zsh:10> zpty scppty scp hello.world 'luser@host:~/'
+./zpty-test.zsh:11> zpty -t scppty
+./zpty-test.zsh:12> zpty -r scppty line '*:'
+./zpty-test.zsh:13> zpty -w scppty 'TopSecret'
+./zpty-test.zsh:14> zpty -r scppty line
+./zpty-test.zsh:16> result+='1> scp hello.world
'\''jvargas@xxxxxxxxxxxxxxxxxxxxxxxxxxx:~/'\''
'
+./zpty-test.zsh:14> zpty -r scppty line
+./zpty-test.zsh:16> result+='THIS IS A PROPRIETARY RANDOM HOUSE
SYSTEM, RESTRICTED TO AUTHORIZED
'
+./zpty-test.zsh:14> zpty -r scppty line
+./zpty-test.zsh:16> result+='PERSONNEL AND FOR OFFICIAL, AUTHORIZED
RANDOM HOUSE BUSINESS ONLY.
'
+./zpty-test.zsh:14> zpty -r scppty line
+./zpty-test.zsh:16> result+='ANYONE USING THIS SYSTEM, NETWORK OR
DATA IS SUBJECT TO MONITORING
'
+./zpty-test.zsh:14> zpty -r scppty line
+./zpty-test.zsh:16> result+='AT ANY TIME. ANYONE USING THIS SYSTEM
THEREBY EXPRESSLY CONSENTS
'
+./zpty-test.zsh:14> zpty -r scppty line
+./zpty-test.zsh:16> result+='TO SUCH MONITORING AND IS FURTHER
ADVISED THAT ANY EVIDENCE OF
'
+./zpty-test.zsh:14> zpty -r scppty line
+./zpty-test.zsh:16> result+='CRIMINAL AND/OR OTHERWISE IMPROPER OR
UNAUTHORIZED ACTIVITY MAY
'
+./zpty-test.zsh:14> zpty -r scppty line
+./zpty-test.zsh:16> result+='BE PROVIDED TO LAW ENFORCEMENT
OFFICIALS FOR PROSECUTION AND/OR
'
+./zpty-test.zsh:14> zpty -r scppty line
+./zpty-test.zsh:16> result+='USED BY RANDOM HOUSE AS IT SEES FIT.
'
+./zpty-test.zsh:14> zpty -r scppty line
+./zpty-test.zsh:16> result+='
'
+./zpty-test.zsh:14> zpty -r scppty line
..... it waits forever here.
On May 15, 2008, at 10:50 AM, Stephane Chazelas wrote:
On Thu, May 15, 2008 at 02:18:57PM +0100, Peter Stephenson wrote:
Jaime Vargas wrote:
In the script attached, when trying to follwing line always fails.
zpty -r scppty line "*:" || echo "no password asked" && exit
It appears that the "password" string from the ssh session is
discarded
by the psuedo terminal.
Is there a way to fix this? or Am I missing something?
Yes and yes, but it's annoying and I spent a few minutes
rediscovering
the arcana. zpty attempts to read in whole lines, while the password
prompt isn't a whole line. I came across this myself and looked
at the
code a while ago and it seemed unnecessarily obscure. However, I
worked
around it and don't have time to make it work sensibly in all the
possible cases, so I'm not touching it. (If anyone's interested
it's in
ptyread() in Src/Modules/zpty.c and could definitely do with someone
taking it over; it's pretty much self-contained.)
To work around this, you need to use non-blocking mode, i.e. start
with
"zpty -b scppty ...". I think (although the code is obscure) that
with
your "*:" pattern this will work, i.e. although it doesn't block
it will
carry on reading until it gets the password input. If not, you would
need to delay (the zsh/zselect module allows you to do this in
100ths of
a second) and retry. (Waiting for a pattern with noblocking is
effectively a busy wait so even this isn't ideal---you can add the -t
option to the -r command line to test first, but then it *won't* wait
if there's no input and you do have to delay in your script.)
[...]
It works for me without "-b", why would you say "-b" is
necessary?
The problem I've found is that zpty -r doesn't return when the
command in the pty has terminated. A strace -p shows:
read(12, 0xb7ba04c8, 1) = -1 EIO (Input/output error)
read(12, 0xb7ba04c8, 1) = -1 EIO (Input/output error)
read(12, 0xb7ba04c8, 1) = -1 EIO (Input/output error)
read(12, 0xb7ba04c8, 1) = -1 EIO (Input/output error)
read(12, 0xb7ba04c8, 1) = -1 EIO (Input/output error)
read(12, 0xb7ba04c8, 1) = -1 EIO (Input/output error)
read(12, 0xb7ba04c8, 1) = -1 EIO (Input/output error)
read(12, 0xb7ba04c8, 1) = -1 EIO (Input/output error)
read(12, 0xb7ba04c8, 1) = -1 EIO (Input/output error)
[...]
And the other problem I mentionned in another email about the
PS4 output not being correct.
--
Stéphane
On May 15, 2008, at 10:50 AM, Stephane Chazelas wrote:
On Thu, May 15, 2008 at 02:18:57PM +0100, Peter Stephenson wrote:
Jaime Vargas wrote:
In the script attached, when trying to follwing line always fails.
zpty -r scppty line "*:" || echo "no password asked" && exit
It appears that the "password" string from the ssh session is
discarded
by the psuedo terminal.
Is there a way to fix this? or Am I missing something?
Yes and yes, but it's annoying and I spent a few minutes
rediscovering
the arcana. zpty attempts to read in whole lines, while the password
prompt isn't a whole line. I came across this myself and looked
at the
code a while ago and it seemed unnecessarily obscure. However, I
worked
around it and don't have time to make it work sensibly in all the
possible cases, so I'm not touching it. (If anyone's interested
it's in
ptyread() in Src/Modules/zpty.c and could definitely do with someone
taking it over; it's pretty much self-contained.)
To work around this, you need to use non-blocking mode, i.e. start
with
"zpty -b scppty ...". I think (although the code is obscure) that
with
your "*:" pattern this will work, i.e. although it doesn't block
it will
carry on reading until it gets the password input. If not, you would
need to delay (the zsh/zselect module allows you to do this in
100ths of
a second) and retry. (Waiting for a pattern with noblocking is
effectively a busy wait so even this isn't ideal---you can add the -t
option to the -r command line to test first, but then it *won't* wait
if there's no input and you do have to delay in your script.)
[...]
It works for me without "-b", why would you say "-b" is
necessary?
The problem I've found is that zpty -r doesn't return when the
command in the pty has terminated. A strace -p shows:
read(12, 0xb7ba04c8, 1) = -1 EIO (Input/output error)
read(12, 0xb7ba04c8, 1) = -1 EIO (Input/output error)
read(12, 0xb7ba04c8, 1) = -1 EIO (Input/output error)
read(12, 0xb7ba04c8, 1) = -1 EIO (Input/output error)
read(12, 0xb7ba04c8, 1) = -1 EIO (Input/output error)
read(12, 0xb7ba04c8, 1) = -1 EIO (Input/output error)
read(12, 0xb7ba04c8, 1) = -1 EIO (Input/output error)
read(12, 0xb7ba04c8, 1) = -1 EIO (Input/output error)
read(12, 0xb7ba04c8, 1) = -1 EIO (Input/output error)
[...]
And the other problem I mentionned in another email about the
PS4 output not being correct.
--
Stéphane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author