Google Answers Logo
View Question
 
Q: C# System.Diagnostic.Process /bin/login ( No Answer,   0 Comments )
Question  
Subject: C# System.Diagnostic.Process /bin/login
Category: Computers > Programming
Asked by: bjschnei-ga
List Price: $20.00
Posted: 16 Jul 2004 10:38 PDT
Expires: 20 Aug 2004 13:35 PDT
Question ID: 375016
I am playing with C# web services on Linux using Mono version 1.0.  I
am attempting to create a telnet web service.  I am trying to use the
/bin/login process and connect to its standard input and output as
follows:

          ProcessStartInfo psI = new ProcessStartInfo("/bin/login");
          psI.UseShellExecute = false;
          psI.RedirectStandardInput = true;
          psI.RedirectStandardOutput = true;
          psI.RedirectStandardError = true;
          psI.CreateNoWindow = true;

          //psI.Arguments ="/bin/login";

      ProcessData pd = new ProcessData();

      pd.p = new Process();
          pd.p.StartInfo = psI;


          pd.p.Start();
          pd.sw = pd.p.StandardInput;
          pd.sr = pd.p.StandardOutput;
          pd.err = pd.p.StandardError;

I then later try to read and write to the process
if(pdata.sr.Peek() != -1)
{
 return pdata.sr.ReadToEnd();
}
return pdata.err.ReadToEnd();



and
pd.sw.WriteLine(theData);

I am getting no output data from the login process, and sending input
results in the following error:
The remote server returned an error: (500) Internal Server Error.
Win32 IO returned ERROR_NO_MORE_FILES. Path: [Unknown]

Why can I not get I/O to this process

Request for Question Clarification by maniac-ga on 16 Jul 2004 17:30 PDT
Hello Bjschnei,

Hmm. If you change
  /bin/login
to something like
  /bin/ed  (or some other interactive program)
does the code you are describing work as expected?

I'm assuming your code is basically correct but there may be special
case code in /bin/login that prevents you from "spoofing" the
connection. I can suggest alternative methods based on the results of
the test I suggest above.
  --Maniac

Clarification of Question by bjschnei-ga on 16 Jul 2004 20:25 PDT
I wrote a simple test program that excepted data, and echoed it
back...that worked fine. i changed the process to /usr/bin/telnet, and
as an argument passed it localhost which i have found some confusing
results.

When using telnet as the code is now, I get the expected data, which
ends with a login prompt -> but there is an extended delay.  If i then
try to putData, supplying the username, i get the ERROR_NO_MORE_FILES

if i change getData to return 1 character at a time, and in the middle
of getting characters, make a call to putData, i don't get the error
-> haven't played with it enought to see what is causing this
behavior..getting kind of frustrated with it so i needed a brake..i.e
google answers..but anyway..what appears to be happening here, is that
ReadToEnd is not returning until telnet app ends(telnet must be timing
out)..and then when i try later write to it, it fails...not sure why..

in anycase, reading one char at a time with /bin/login results in no
data, and i can't send any either...

playing with /bin/login, i have concluded that the only way i can run
it from an existing shell(xterm) is by using the command: exec
/bin/login ...which really doesn't help much because i can't call exec
from my web service....

Request for Question Clarification by maniac-ga on 17 Jul 2004 18:15 PDT
Hell BjSchnei,

I suspected some odd behavior with /bin/login and your clarification
confirms it. Let me provide some background:

The program /bin/login (for Linux), as documented in
  man login
or on line at:
  http://www.die.net/doc/linux/man/man1/login.1.html
[go to the "bugs" section]
describes the method used to ensure you don't password sniff [uses
vhangup]. There are also a number of checks [see earlier sections]
that verify that the "terminal" you are using is acceptable for
connections / the user name supplied. I don't know what C# uses under
the hood for connections to standard input / output but I'll guess
pipes - they appear to be unacceptable for /bin/login.

Your use of telnet appears to get you farther but still does not do
the job. A couple solutions come to mind:

[1] Review the source code for the server side of rlogin, rsh or
telnet. For example:
http://www.rpmfind.net//linux/RPM/PLD/dists/ra/PLD/i386/PLD/RPMS/rlogind-0.17-4.i386.html
has the source to the rlogin daemon. Be sure to get the source RPM. If
you don't use an RPM based distribution, let me know so I can give you
instructions for another Linux distribution. You can then do the
similar method in C# to get the same behavior.

[2] Use pseudo terminals (or pty's). You would make a connection to
the master side of a pty and /bin/login runs on the slave side. In
this case, /bin/login can still do all the terminal specific actions
and your program can handle them. I know xterm uses this method but it
can be very complicated to set up.

Let me know if you want to pursue one or both of these methods.
  --Maniac
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy