The program in general is I want to implement telnet program.

On the client side user send its logging name and password, and if it is correct he starts to send commands to the server

On the Server side I am check on the user authentication on the system and if it is true I must run his default shell which is stored in the passwd file, to execute his commands.

The problem that when I tried to run his shell using the system C function the shell is run and then closed, because the system() use fork() and exec(), and after it finished the opened shell for the user is closed.

How can I run a new shell in my process and keep it running for the following command execution?

  • But it is a question related to UNIX also, not mainly for programming, and there is a tag for in C in this site, so I can post a programming questions that related to UNIX – MUE Mar 14 '13 at 6:16
  • So, according to you, this site has a mistake to leave a C Language tag here, not me. I asked according to tags – MUE Mar 14 '13 at 21:18
  • Having a [c] tag doesn't mean "oh, programming questions must be allowed here"; that's why there's an FAQ that lists what things are on- and off-topic. If you actually look at the [c] tag, most of the questions about programming in C are closed; the rest are vaguely related to C but don't involve writing C code, which is clearly SO's domain. I find it hard to believe that you don't already know that programming belongs on SO, since you asked enough questions there to get banned – Michael Mrozek Mar 14 '13 at 21:26

You can't just use system. You have to fork and exec yourself and use pipes in both directions. You'd also have to use some kind of terminal interface if you wanted to catch Ctrl key input.

| improve this answer | |

Before going there, go read the specifications of the telnet protocol (RFC 854, see also the Wikipedia entry for the full list of RFCs involved). Telnet is a very complex protocol, as it was designed to connect between machines of a wild variety of operating systems, down to different character coding. Moreover, it is recommended to never use it, as it is horribly insecure.

If you want to run commands remotely use ssh.

| improve this answer | |
  • I know that telnet is insecure, but I didn't mean that I want to use it, I just want to make a simple implementation for it, as a way to improve my skill in system programming under UNIX. – MUE Mar 13 '13 at 20:32
  • There is nothing simple in implementing telnet... you have to read (and display) input from the user while accepting (and displaying) remote output, the server has to get a pseudo terminal and arrange for a getty(8) to run on it to interact with the user. And that is just a minimal telnet-style interaction, jettisoning all the negotiation and exotic settings. – vonbrand Mar 13 '13 at 20:36
  • but getty is not a c function, I cannot use in my server. – MUE Mar 13 '13 at 20:44

You might want to start with something a lot simpler to get started in this sort of thing, as it sounds as if you are new to it. Perhaps the old talk / talkd command line program and daemon would be more approachable? Some valuable resources include APUE, or Advanced Programming in the UNIX Environment (Stevens), UNP, or UNIX Network Programming (Also by Stevens) and Effective TCP/IP Programming (Snader) to get you more familiar with the type of work you'll be doing, and TCP/IP specifically.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.