From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14017 invoked from network); 15 May 2008 16:30:07 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00 autolearn=ham version=3.2.4 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 15 May 2008 16:30:07 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 93608 invoked from network); 15 May 2008 16:30:02 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 15 May 2008 16:30:02 -0000 Received: (qmail 13800 invoked by alias); 15 May 2008 16:29:58 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 25041 Received: (qmail 13787 invoked from network); 15 May 2008 16:29:57 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 15 May 2008 16:29:57 -0000 Received: from smtpoutm.mac.com (smtpoutm.mac.com [17.148.16.71]) by bifrost.dotsrc.org (Postfix) with ESMTP id 6E10880589A4 for ; Thu, 15 May 2008 18:29:51 +0200 (CEST) Received: from mac.com (asmtp006-s [10.150.69.69]) by smtpoutm.mac.com (Xserve/smtpout008/MantshX 4.0) with ESMTP id m4FGTnvl016069 for ; Thu, 15 May 2008 09:29:50 -0700 (PDT) Received: from [192.168.1.254] (static-141-157-25-210.balt.east.verizon.net [141.157.25.210]) (authenticated bits=0) by mac.com (Xserve/asmtp006/MantshX 4.0) with ESMTP id m4FGPf83009836 for ; Thu, 15 May 2008 09:25:42 -0700 (PDT) Mime-Version: 1.0 (Apple Message framework v752.3) In-Reply-To: <20080515145054.GC5190@sc.homeunix.net> References: <34AE8142-F5DA-44FD-96BA-61BDE12BC74E@mac.com> <200805151318.m4FDIvKS015244@news01.csr.com> <20080515145054.GC5190@sc.homeunix.net> Content-Type: text/plain; charset=ISO-8859-1; delsp=yes; format=flowed Message-Id: <22C7A43F-E19E-451D-A980-E79140BF8B3A@mac.com> Content-Transfer-Encoding: quoted-printable From: Jaime Vargas Subject: Re: zpty woes Date: Thu, 15 May 2008 12:25:44 -0400 To: zsh-workers@sunsite.dk X-Mailer: Apple Mail (2.752.3) X-Virus-Scanned: ClamAV 0.91.2/7129/Thu May 15 18:00:53 2008 on bifrost X-Virus-Status: Clean Still doesn't work for me. Below is the modified script and the debug =20= output. #!/opt/csw/bin/zsh set -x zmodload zsh/zpty die() {print -r -- $1 >&2; exit 1;} zpty scppty scp hello.world jvargas@aoma6000-4-9.aoma.rhbss.com:~/ 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+=3D"$line"$'\n' done zpty -d scppty print $result I changed my credentials for security. Basically it now hangs waitng =20 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+=3D'1> scp hello.world =20 '\''jvargas@aoma6000-4-9.aoma.rhbss.com:~/'\'' ' +./zpty-test.zsh:14> zpty -r scppty line +./zpty-test.zsh:16> result+=3D'THIS IS A PROPRIETARY RANDOM HOUSE =20 SYSTEM, RESTRICTED TO AUTHORIZED ' +./zpty-test.zsh:14> zpty -r scppty line +./zpty-test.zsh:16> result+=3D'PERSONNEL AND FOR OFFICIAL, AUTHORIZED =20= RANDOM HOUSE BUSINESS ONLY. ' +./zpty-test.zsh:14> zpty -r scppty line +./zpty-test.zsh:16> result+=3D'ANYONE USING THIS SYSTEM, NETWORK OR =20 DATA IS SUBJECT TO MONITORING ' +./zpty-test.zsh:14> zpty -r scppty line +./zpty-test.zsh:16> result+=3D'AT ANY TIME. ANYONE USING THIS SYSTEM =20= THEREBY EXPRESSLY CONSENTS ' +./zpty-test.zsh:14> zpty -r scppty line +./zpty-test.zsh:16> result+=3D'TO SUCH MONITORING AND IS FURTHER =20 ADVISED THAT ANY EVIDENCE OF ' +./zpty-test.zsh:14> zpty -r scppty line +./zpty-test.zsh:16> result+=3D'CRIMINAL AND/OR OTHERWISE IMPROPER OR =20= UNAUTHORIZED ACTIVITY MAY ' +./zpty-test.zsh:14> zpty -r scppty line +./zpty-test.zsh:16> result+=3D'BE PROVIDED TO LAW ENFORCEMENT =20 OFFICIALS FOR PROSECUTION AND/OR ' +./zpty-test.zsh:14> zpty -r scppty line +./zpty-test.zsh:16> result+=3D'USED BY RANDOM HOUSE AS IT SEES FIT. ' +./zpty-test.zsh:14> zpty -r scppty line +./zpty-test.zsh:16> result+=3D' ' +./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 =20 >>> 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 =20 >> 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 =20 >> at the >> code a while ago and it seemed unnecessarily obscure. However, I =20 >> 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 =20 >> 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 =20= >> with >> "zpty -b scppty ...". I think (although the code is obscure) that =20= >> with >> your "*:" pattern this will work, i.e. although it doesn't block =20 >> 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 =20 >> 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) =3D -1 EIO (Input/output = error) > read(12, 0xb7ba04c8, 1) =3D -1 EIO (Input/output = error) > read(12, 0xb7ba04c8, 1) =3D -1 EIO (Input/output = error) > read(12, 0xb7ba04c8, 1) =3D -1 EIO (Input/output = error) > read(12, 0xb7ba04c8, 1) =3D -1 EIO (Input/output = error) > read(12, 0xb7ba04c8, 1) =3D -1 EIO (Input/output = error) > read(12, 0xb7ba04c8, 1) =3D -1 EIO (Input/output = error) > read(12, 0xb7ba04c8, 1) =3D -1 EIO (Input/output = error) > read(12, 0xb7ba04c8, 1) =3D -1 EIO (Input/output = error) > [...] > > And the other problem I mentionned in another email about the > PS4 output not being correct. > > --=20 > St=E9phane 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 =20 >>> 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 =20 >> 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 =20 >> at the >> code a while ago and it seemed unnecessarily obscure. However, I =20 >> 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 =20 >> 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 =20= >> with >> "zpty -b scppty ...". I think (although the code is obscure) that =20= >> with >> your "*:" pattern this will work, i.e. although it doesn't block =20 >> 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 =20 >> 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) =3D -1 EIO (Input/output = error) > read(12, 0xb7ba04c8, 1) =3D -1 EIO (Input/output = error) > read(12, 0xb7ba04c8, 1) =3D -1 EIO (Input/output = error) > read(12, 0xb7ba04c8, 1) =3D -1 EIO (Input/output = error) > read(12, 0xb7ba04c8, 1) =3D -1 EIO (Input/output = error) > read(12, 0xb7ba04c8, 1) =3D -1 EIO (Input/output = error) > read(12, 0xb7ba04c8, 1) =3D -1 EIO (Input/output = error) > read(12, 0xb7ba04c8, 1) =3D -1 EIO (Input/output = error) > read(12, 0xb7ba04c8, 1) =3D -1 EIO (Input/output = error) > [...] > > And the other problem I mentionned in another email about the > PS4 output not being correct. > > --=20 > St=E9phane