Discussion:
Request a PTY when running a command
William Orr
2013-07-30 16:14:59 UTC
Permalink
Hi all,

I'm trying to execute a command with sudo. sudo requires that I provide it with an ask pass program or have a PTY. Currently I have code that exec's a program on the remote end (called wshd, wshd exec's sudo), and then requests a PTY. This code returns an error reading "Channel request pty-req failed." If I request a PTY prior to exec'ing a command, wshd never gets exec'd.

What I'm trying to do here is similar to `ssh -t <hostname> sudo whoami`, which exec's sudo, but also forces allocation of a PTY.

I'm using libssh 0.5.4 on RHEL 6.1. Let me know if you need more information.

http://bpaste.net/show/118708/

Thanks!
William Orr
Andreas Schneider
2013-08-04 09:20:51 UTC
Permalink
Post by William Orr
Hi all,
I'm trying to execute a command with sudo. sudo requires that I provide it
with an ask pass program or have a PTY. Currently I have code that exec's
a program on the remote end (called wshd, wshd exec's sudo), and then
requests a PTY. This code returns an error reading "Channel request pty-req
failed." If I request a PTY prior to exec'ing a command, wshd never gets
exec'd.
What I'm trying to do here is similar to `ssh -t <hostname> sudo whoami`,
which exec's sudo, but also forces allocation of a PTY.
I'm using libssh 0.5.4 on RHEL 6.1. Let me know if you need more information.
http://bpaste.net/show/118708/
Did you read our tutorial?

http://api.libssh.org/master/libssh_tutor_shell.html


Cheers,


-- andreas
--
Andreas Schneider GPG-ID: F33E3FC6
www.cryptomilk.org asn-***@public.gmane.org
William Orr
2013-08-04 09:29:42 UTC
Permalink
Post by Andreas Schneider
Post by William Orr
Hi all,
I'm trying to execute a command with sudo. sudo requires that I provide it
with an ask pass program or have a PTY. Currently I have code that exec's
a program on the remote end (called wshd, wshd exec's sudo), and then
requests a PTY. This code returns an error reading "Channel request pty-req
failed." If I request a PTY prior to exec'ing a command, wshd never gets
exec'd.
What I'm trying to do here is similar to `ssh -t <hostname> sudo whoami`,
which exec's sudo, but also forces allocation of a PTY.
I'm using libssh 0.5.4 on RHEL 6.1. Let me know if you need more information.
http://bpaste.net/show/118708/
Did you read our tutorial?
http://api.libssh.org/master/libssh_tutor_shell.html
Cheers,
-- andreas
--
Andreas Schneider GPG-ID: F33E3FC6
I did read your tutorial. I'm not looking to execute a shell, I'm looking to execute a single command, however sudo requires a PTY. So while I do see that I can request a PTY when requesting a shell, I'd like to request a PTY while exec'ing a single command. Like I said in my original post, it's the same behavior as ssh -t <host> <program name>
Andreas Schneider
2013-08-04 10:30:57 UTC
Permalink
Post by William Orr
Post by Andreas Schneider
Did you read our tutorial?
http://api.libssh.org/master/libssh_tutor_shell.html
Cheers,
-- andreas
I did read your tutorial. I'm not looking to execute a shell, I'm looking to
execute a single command, however sudo requires a PTY.
As the name exec already states. It calls exec(v) on the server ...
Post by William Orr
So while I do see
that I can request a PTY when requesting a shell, I'd like to request a PTY
while exec'ing a single command. Like I said in my original post, it's the
same behavior as ssh -t <host> <program name>
See the tutorial I pointed you to. This is how ssh -t is implemented ...




-- andreas
--
Andreas Schneider GPG-ID: F33E3FC6
www.cryptomilk.org asn-***@public.gmane.org
William Orr
2013-08-11 06:59:12 UTC
Permalink
Post by Andreas Schneider
Post by William Orr
Hi all,
I'm trying to execute a command with sudo. sudo requires that I provide it
with an ask pass program or have a PTY. Currently I have code that exec's
a program on the remote end (called wshd, wshd exec's sudo), and then
requests a PTY. This code returns an error reading "Channel request pty-req
failed." If I request a PTY prior to exec'ing a command, wshd never gets
exec'd.
What I'm trying to do here is similar to `ssh -t <hostname> sudo whoami`,
which exec's sudo, but also forces allocation of a PTY.
I'm using libssh 0.5.4 on RHEL 6.1. Let me know if you need more information.
http://bpaste.net/show/118708/
Did you read our tutorial?
http://api.libssh.org/master/libssh_tutor_shell.html
Cheers,
-- andreas
--
Andreas Schneider GPG-ID: F33E3FC6
Thanks for the help.

Now that I've converted my code, I'm having trouble sending more data over stdin. I can execute commands just fine. But the command I'm executing takes binary data from stdin. When I was executing it with wsh_channel_request_exec, I could send binary data to it's stdin just fine. Now that I'm requesting a shell and then executing it, it gets 0s for data. The data hasn't changed, nor does it seem to depend on the data I'm sending. I've ensured that I'm sending non-zero data.

My code worked prior to switching to request_shell.
William Orr
2013-08-13 01:47:55 UTC
Permalink
Post by William Orr
Post by Andreas Schneider
Post by William Orr
Hi all,
I'm trying to execute a command with sudo. sudo requires that I provide it
with an ask pass program or have a PTY. Currently I have code that exec's
a program on the remote end (called wshd, wshd exec's sudo), and then
requests a PTY. This code returns an error reading "Channel request pty-req
failed." If I request a PTY prior to exec'ing a command, wshd never gets
exec'd.
What I'm trying to do here is similar to `ssh -t <hostname> sudo whoami`,
which exec's sudo, but also forces allocation of a PTY.
I'm using libssh 0.5.4 on RHEL 6.1. Let me know if you need more information.
http://bpaste.net/show/118708/
Did you read our tutorial?
http://api.libssh.org/master/libssh_tutor_shell.html
Cheers,
-- andreas
--
Andreas Schneider GPG-ID: F33E3FC6
Thanks for the help.
Now that I've converted my code, I'm having trouble sending more data over stdin. I can execute commands just fine. But the command I'm executing takes binary data from stdin. When I was executing it with wsh_channel_request_exec, I could send binary data to it's stdin just fine. Now that I'm requesting a shell and then executing it, it gets 0s for data. The data hasn't changed, nor does it seem to depend on the data I'm sending. I've ensured that I'm sending non-zero data.
My code worked prior to switching to request_shell.
I found the source of the problem: libssh is sending out an extra null byte before writing my data to stdin. Is there any particular reason for that? This did not happen with exec.

My binary protocol first sends 4 bytes of message size information, and then a message. When sending the message size, my code will error if any more or less than 4 bytes is sent. Since the client is NOT erring, libssh is sending an extra null byte before actually sending my message. Again, this has only happened after I switched from using ssh_channel_request_exec to ssh_channel_request_shell.

Any insight would be great.

Thanks!
Andreas Schneider
2013-08-13 06:33:22 UTC
Permalink
Post by William Orr
Post by William Orr
Post by Andreas Schneider
Post by William Orr
Hi all,
I'm trying to execute a command with sudo. sudo requires that I provide it
with an ask pass program or have a PTY. Currently I have code that exec's
a program on the remote end (called wshd, wshd exec's sudo), and then
requests a PTY. This code returns an error reading "Channel request pty-req
failed." If I request a PTY prior to exec'ing a command, wshd never gets
exec'd.
What I'm trying to do here is similar to `ssh -t <hostname> sudo whoami`,
which exec's sudo, but also forces allocation of a PTY.
I'm using libssh 0.5.4 on RHEL 6.1. Let me know if you need more information.
http://bpaste.net/show/118708/
Did you read our tutorial?
http://api.libssh.org/master/libssh_tutor_shell.html
Cheers,
-- andreas
Thanks for the help.
Now that I've converted my code, I'm having trouble sending more data over
stdin. I can execute commands just fine. But the command I'm executing
takes binary data from stdin. When I was executing it with
wsh_channel_request_exec, I could send binary data to it's stdin just
fine. Now that I'm requesting a shell and then executing it, it gets 0s
for data. The data hasn't changed, nor does it seem to depend on the data
I'm sending. I've ensured that I'm sending non-zero data.
My code worked prior to switching to request_shell.
I found the source of the problem: libssh is sending out an extra null byte
before writing my data to stdin. Is there any particular reason for that?
This did not happen with exec.
The libssh code doesn't send an extra null byte. At least I don't see
something in the code.

Are you sure libssh is sending it?
Are you sure the ssh server is not adding it?
Can you see it on the wire (ssh_set_pcap_file)?


-- andreas
--
Andreas Schneider GPG-ID: F33E3FC6
www.cryptomilk.org asn-***@public.gmane.org
William Orr
2013-08-13 16:46:40 UTC
Permalink
Post by Andreas Schneider
Post by William Orr
Post by William Orr
Post by Andreas Schneider
Post by William Orr
Hi all,
I'm trying to execute a command with sudo. sudo requires that I provide it
with an ask pass program or have a PTY. Currently I have code that exec's
a program on the remote end (called wshd, wshd exec's sudo), and then
requests a PTY. This code returns an error reading "Channel request pty-req
failed." If I request a PTY prior to exec'ing a command, wshd never gets
exec'd.
What I'm trying to do here is similar to `ssh -t <hostname> sudo whoami`,
which exec's sudo, but also forces allocation of a PTY.
I'm using libssh 0.5.4 on RHEL 6.1. Let me know if you need more information.
http://bpaste.net/show/118708/
Did you read our tutorial?
http://api.libssh.org/master/libssh_tutor_shell.html
Cheers,
-- andreas
Thanks for the help.
Now that I've converted my code, I'm having trouble sending more data over
stdin. I can execute commands just fine. But the command I'm executing
takes binary data from stdin. When I was executing it with
wsh_channel_request_exec, I could send binary data to it's stdin just
fine. Now that I'm requesting a shell and then executing it, it gets 0s
for data. The data hasn't changed, nor does it seem to depend on the data
I'm sending. I've ensured that I'm sending non-zero data.
My code worked prior to switching to request_shell.
I found the source of the problem: libssh is sending out an extra null byte
before writing my data to stdin. Is there any particular reason for that?
This did not happen with exec.
The libssh code doesn't send an extra null byte. At least I don't see
something in the code.
Are you sure libssh is sending it?
Are you sure the ssh server is not adding it?
Can you see it on the wire (ssh_set_pcap_file)?
-- andreas
--
Andreas Schneider GPG-ID: F33E3FC6
Hey Andreas,

Thanks for mentioning the pcap API, that's really useful for debugging!

You're right, I can't see that on the wire. Looks like the SSH server must be adding it.

Thanks for the help!

Loading...