Saturday, January 08, 2005

Building util-linux

I have decided to build the standard getty and login not to use tinylogin.
but building this thing is proving to be a pain.
i ramdom picked version 12p but its a no go. I went over to
buildroot and tried to see how the build it, the build
fails for util linux ... mostly problems find the ncurses
headers and libraries it looks like.

probably what i should be thinking about is how getty works?

this comes from http://www.geekcomix.com/cgi-bin/classnotes/wiki.pl?UNIX01/Init-Getty-Login-Shell

GETTY
Recall that

"TTY" comes from the industry-wide abbreviation for "Teletype" since original Unix computers used these devices for input and output.

A TTY today is simply some sort of I/O device for interfacing with your UNIX box (this is a bit of an over-exaggeration... but for the purposes of this class, it's okay).

GETTY is a program that is invoked by init. It is the second process in series that ultimately connects a user with the UNIX system. Usually getty outputs the contents of /etc/issue (which can contain introductory messages about the system) and then starts login sessions for the user to connect. These login sessions will then spawn the shell whenever a user connects. This procedure is generally refered to as init-getty-login-shell and has been a common mantra throughout UNIX history. If there is ever a problem connecting to a UNIX system as a user, then one of these four elements is to blame.

getty is spawned by init based upon entries inside the /etc/inittab file (which is to be expected). When it is invoked, it is generally given a baud rate (connection speed) and a device name to use (one of /dev/tty1, /dev/tty2, etc.). For example, the following is a possible entry from /etc/inittab

# /sbin/getty invocations for the runlevels.
#
# The "id" field MUST be the same as the last
# characters of the device (after "tty").
#
# Format:
# :::
1:12345:respawn:/sbin/getty 38400 tty1
2:2345:respawn:/sbin/getty 38400 tty2
3:2345:respawn:/sbin/getty 38400 tty3
4:2345:respawn:/sbin/getty 38400 tty4
5:2345:respawn:/sbin/getty 38400 tty5
6:2345:respawn:/sbin/getty 38400 tty6

Note that here, the first field of inittab, the "id", must be the same as the device specification. Or "1" must correlate to "tty1" and so on. Also note that the first invocation (id "1") runs at all non-halt/reboot modes including "single user", whereas the others do not. This is because, when booting into single user mode for maintenance, you will need one and only one terminal.

mingetty
mingetty is an alternative to getty which is most often employed on Red Hat and Red Hat-based systems. It's only real difference is that it is not suitable for other, more arbitrary, terminal connections (such as serial line connections.) It's format inside of inittab is not much different than getty. It simply lacks the baud rate:

# Run gettys in standard runlevels
1:12345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6

so i could use mingetty? i may if util linux proves to to much of a pain to build.
but how does mingetty and login work/interact?

more about that from this page
http://www.comptechdoc.org/os/linux/startupman/linux_suiglog.html

Recall that in /etc/inittab file there were lines like this:

1:2345:respawn:/sbin/mingetty tty1

These lines cause init to spawn the mingetty process on runlevels 2 through 5 for tty1 and other terminals. To do this init will use the "fork" function to make a new copy of itself and use an "exec" function to run the getty program. Getty will wait for the user, then read the username. Then init will use the "exec" function to run the login program which will read the password (Some documentation says getty invokes login with the user's name as an argument). If the password entered does not match for the user, init will load and run getty again. If the login is successful, init will use the "exec" function to run the shell program. When the shell exits through the "logout" command, init will load and run the getty program again. The shell is loaded by init or login and the file "/etc/passwd" determines the shell to be used for the user.

Note that network logins are handled differently than console logins since it is impractical to have a getty provided for each potential network login. Network logins are handled through the internet super daemon, inetd using either the telnet or rlogin communication protocol.
Getty

Getty performs the following functions:

1. Open tty lines and set their modes
2. Print the login prompt and get the user's name
3. Begin a login process for the user



1. At startup, it parses its command line, then reads it's default file, usually "/etc/conf.getty" to determine runtime values. After setting up the "line", getty outputs the contents of the "/etc/issue" file. Then getty reads the user's name and invokes login with the user's name as an argument. While reading the user's name, getty attempts to adapt the system to the speed of the terminal being used, and also sets certain terminal parameters to conform with the user's login procedure. See the termio man page.
2. The tty device used by getty is determined by the argument on the command line. The speed argument is a label to an entry in the "/etc/gettydefs" file. this entry defines the initial speed and tty settings, the login prompt to be used, the final speed and tty settings and a pointer to another entry to try if the user indicates that the speed is not correct. This is done by sending a break character.
3. Getty scans the gettydefs file looking for a matching entry to the speed. The first entry is used if no speed was given or no match was found.
4. The type argument names the type of terminal attached to the line such as 3101. The type should be a valid name listed in the termcap database. Getty uses this value to determine how to clear the video display and sets the environment variable "TERM" to the contents of this value.
5. The lined argument describes the line discipline to use on the line. The default is "LDISC0".

During its startup, getty looks for the file "/etc/conf.getty.line" or "/etc/conf.getty". It reads the contents for lines with the form "NAME=value".
SYSTEM
VERSION
LOGIN
INIT=string
ISSUE=string
Login

The login program will prompt for the user name if no argument is given on the command line.

If the file "/etc/nologin" exists and the user is not root, the contents of the "/etc/nologin" file are printed to the screen and the login is terminated. If special access restrictions are specified for the user logging in in the file "etc/usertty", the restrictions must be met or the log in will be denied and the program syslog will log the attempt. If the user is root the login must be on a terminal listed in the file "etc/securetty".

If the above conditions are met the user password will be requested and then it will be checked (If a password is required for this username). After three unsuccessful attempts to login the response gets very slow, and after 10 attempts, login dies. As usual all login failures will be reported by the syslog facility. If the file ".hushlogin" exists in the user's home directory then a "quiet" login is performed which disables checking of mail and the printing of the last login time and the message of the day. Otherwise if the file "var/log/lastlog" exists the last login time is printed and then the current login is recorded in this file. Is the current login recorded in this file if it does not already exist or if the file ".hushlogin" exists.

At this point the login program will perform standard administrative tasks. These include:

1. setting the UID and GID of the tty
2. Preserving the TERM environment variable if it exists.
3. Preserving other environment variables if the –p option is used
4. The HOME, PATH, SHELL, TERM, MAIL, and LOGNAME environment variables are set.
5. The default path is set to "/usr/local/bin:/bin:/usr/bin:." for normal users and "/sbin:/bin:/usr/sbin" for root.
6. If this is not a "quiet" login, the message of the day is printed and the file with the user's name in "/usr/spool/mail" will be checked and a message will be printed if it has non-zero length.
7. The users shell is started. The shell is specified in the file "/etc/passwd". If it is not specified, login will use "/bin/sh" as a default shell.
8. If there is no directory specified for the user in "/etc/passwd", login will use "/" by default for the user's home directory.

Files used:

* /etc/nologin
* /etc/usertty
* /etc/seruretty
* .hushlogin
* /var/log/lastlog
* /etc/passwd

No comments: