I have a service that execs a command when a user connects to it through a socket, and redirects everything it receives to the executed program. It works ok with shells like bash, giving the user a remote shell.Instead of forking bash or sh, I'd like to run something that asks for user and password, like /bin/loginIs that the correct command to run? Isn't there anything that a non-root service could use to do the same? I thinks getty calls /bin/login, but can I just run it as a user?I guess I could install telnetd and redirect to telnet localhost but I'd rather not run a telnet server.
present users a login prompt? /bin/login? getty?
shell;security;login;getty
How to ask for a password?print $promptread $responseIf you want to know how to authenticate your users, ideally you'd write your program as being pam-aware, following one of the pam developer guides all ofer the Interwebs.  One example is http://www.linux-pam.org/Linux-PAM-html/Linux-PAM_ADG.html.  You may also have a helper program on the system which you can use for this purpose, such as unix_chkpwd, which you could use after spawning a child process and switching to the target user.  But the pam application developer interface is pretty easy, so doing the auth yourself is probably well within reason.