Re: Pseudo-tty as piped to NSTask -- help?
Re: Pseudo-tty as piped to NSTask -- help?
- Subject: Re: Pseudo-tty as piped to NSTask -- help?
- From: Fritz Anderson <email@hidden>
- Date: Fri, 12 Sep 2003 13:05:22 -0500
Let me keep this alive with some more detail (the only response was a
counsel of despair).
I noticed that ssh seemed to think it had obtained a password string
from my client process. It collects passwords character-by-character in
a loop, the control of which looks like
for (p = buf; (nr = read(input, &ch, 1)) == 1 && ch != '\n' && ch !=
'\r';) {
if (p < end) {
// etc.
}
*p++ = ch;
}
}
... in other words, it seems to expect that read() to block. I
therefore went back to openpty, where I created my pseudoterminal, and
set its I/O to noncanonical, untimed, single-character.
It didn't help.
Can anyone confirm my suspicion that the lack of blocking is my
problem? If so, how do I solve it?
-- F
On 11 Sep 2003, at 4:46 PM, Fritz Anderson wrote:
>
A job assignment has me writing an application that, at least for the
>
moment, has me putting a front end on the ssh tool, using the
>
typed-password authentication method. The ssh tool won't accept a
>
password unless its stdin stream is a tty.
>
>
Assembling the pieces with a Cocoa eye, I have:
>
>
(1) ssh as an NSTask, with my application hooked to it through
>
setStandardInput: and setStandardOutput: .
>
>
(2) Because ssh needs a terminal, I use openpty to get a pair of file
>
descriptors for a master/slave pseudo-TTY pair. I wrap these in
>
NSFileHandles via initWithFileDescriptor:. I did this a couple of days
>
ago, and a trip to the Darwin list confirmed that this was the right
>
tack to take.
>
>
(Side note: I discover that a subclass of NSFileHandle can't issue
>
[super initWithFileDescriptor:closeOnDealloc:] -- the selector isn't
>
recognized. This was frustrating; I'd hoped to embed the bookkeeping
>
on the slave terminal in a subclass mostly concerned with the master
>
terminal's I/O.)
>
>
openpty() succeeds. I create an NSFileHandle from the slave
>
descriptor. I pass the slave NSFileHandle in both the
>
setStandardInput: and setStandardOutput: messages while setting up the
>
ssh NSTask. My app does I/O on the NSFileHandle built on the master
>
descriptor, and in fact characters sent in the master end get echoed
>
back.
>
>
MY PROBLEM: What I don't see is the ssh tool recognizing what I've
>
provided, as a tty device. The password prompt is not sent, the tool
>
does not pause for a password to be entered, and the password I send
>
blindly to the tool is not used.
>
>
I am terribly naive on UNIX issues, and so I am probably missing
>
something obvious. Could someone set me straight?
>
>
(Would it matter -- I think it should not -- that I did not specify
>
terminal type or geometry in the openpty() call?)
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.