Sunday, September 28, 2014

Unix Prog: Terminal Logins

1. Oldest way to login
In the oldest system, dumb terminals that were connected to the host with hard-wired connections. These logins came through a terminal device driver in the kernel. A host has a fixed number of terminal devices, so there is known upper limit on the number of simultaneous logins.

And window system are developed to provide more ways to interact with host.

2. BSD Terminal Login


1) The system administrator creates a file, usually /etc/ttys, that has one line per terminal device. Each line specifies the name of the device and other parameters that are passed to the getty program.

2) Init process read each line of /etc/ttys, for every terminal device that allows the login, does a fork followed by an exec of the program getty.

3) "getty" then calls "open" for the terminal device, which assigns the file descriptor 0, 1, 2, and then display "login: ", waiting for user to enter the user name

4) After user input the the user name, getty will execute the "login" program with user name and self-made environment variables.

execle("/bin/login", "login", "-p", username, (char*)0, envp);

5) "login" program will fetch the user record with "getpwnam" with our user name from passwd file, then it will call getpass to display prompt "Password:", waiting for user input password. After user input the password, it will call crypt to encrypt the input and compare with encrypted password from the shadow password entry.

6) If login correctly, "login" will
change to our home directory
change the ownership of terminal device, so user could own it
change the access permissions for terminal device so user could have permission to read from and write to it.
set group ids by calling setgid and initgroups
initialize the environment variable
change to user id(setuid)
invoke login shell "/bin/sh" or other specified shell
and many more......

7) after login shell is invoked, it will read some start-up files like "./profile" for the bourne shell/korn shell;".bash_profile, .bash_login" for GNU shell, ".cshrc, .login" for the c shell, in order to change some of the environment variables and add many additional variables to the environment.

Note: getty, login, login shell. All of their parent process is "init process".

3. Mac OS X Terminal Login
Same as BSD Terminal Login

4. Linux Terminal Login
Same as BSD Terminal Login, the only difference is the configuration file describing the terminal device is /etc/inittab instead of /etc/ttys

5. Solaris Terminal Login
Solaris provide one more different way compared to traditional getty way.
Its init process will "fork" SAC(Service access Controller), SAC will then fork and exec "ttymon"(monitor all terminal ports). If needed, ttymon will fork and exec the "login" to handle login process. So at Solaris, "login, login shell"'s parent process is ttymon instead of "init".

6. Network Login -- BSD
The main difference between network login and login through a serial terminal is: in network login, "login" is a service, waiting for network connection request coming.



1) inetd process waits for most network connections, inetd is called "Internet superserver"
2) once the request arrive, inetd does a "fork" and "exec" of the appropriate program
3) Take telnet as example, if user type: "telnet hostname"
The client opens a TCP connection to hostname, and the program that's started on hostname is called TELNET server, the client and the server then exchange data across the TCP connection using the TELNET application protocol.
4) telnetd then opens a pseudo-terminal device and splits into two processes using fork. The parent(telnetd) handles communication across the network connection, and the child does an exec of the login program.

No comments:

Post a Comment