Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

closed as off topic by Stéphane Chazelas, vonbrand, Renan, jasonwryan, warl0ck Mar 14 '13 at 3:18

Questions on Unix & Linux Stack Exchange are expected to relate to Unix or Linux within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

    
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
add comment

3 Answers 3

up vote 1 down vote accepted

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.

share|improve this answer
add comment

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.

share|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
add comment

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.

share|improve this answer
add comment

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