1 diff -Nru mingetty-0.9.4.orig/mingetty.8 mingetty-0.9.4/mingetty.8
2 --- mingetty-0.9.4.orig/mingetty.8 Sun Apr 29 19:38:31 2001
3 +++ mingetty-0.9.4/mingetty.8 Sun Apr 29 19:40:47 2001
5 mingetty \- minimal getty for consoles
8 -[\-\-noclear] [\-\-long\-hostname]
9 +[\-\-noclear] [\-\-long\-hostname] [\-\-autologin username]
14 By default the hostname is only printed until the first dot.
15 With this option enabled, the full text from gethostname() is shown.
17 +.B \-\-autologin username
18 +Log the specified user onto the console (normally
20 +when the system is first booted without prompting for a username or
23 +When the autologin option is supplied,
25 +will check that the controlling terminal is the console (normally
27 +that a reasonable username has been supplied, and that this is the
28 +first autologin request since the system has booted. If all of these
29 +conditions have been met, a request for an unauthenticated login is
32 +program. Otherwise, a normal interactive login is performed.
36 +program may deny the request for an unauthenticated login. Typically
37 +this will happen when the user is root, has a UID of 0, or whenever a
38 +normal interactive login would be denied due to the access
39 +restrictions specified in the
46 +Only a single autologin request will be issued after a system boot.
47 +If the automated login request is denied, or if the user logs out,
49 +will revert to performing normal interactive logins for all subsequent
53 Set terminal type to "linux-m" instead of default "linux" (for mono consoles)
61 +.IR /var/log/autologin .
65 diff -Nru mingetty-0.9.4.orig/mingetty.c mingetty-0.9.4/mingetty.c
66 --- mingetty-0.9.4.orig/mingetty.c Sun Apr 29 19:38:31 2001
67 +++ mingetty-0.9.4/mingetty.c Sun Apr 29 19:44:14 2001
69 * should be very reliable. For a modem getty, I'd also use nothing else
72 - * Usage: mingetty [--noclear] tty
73 + * Usage: mingetty [--noclear] [--autologin username] tty
74 * Example entry in /etc/inittab: 1:123:respawn:/sbin/mingetty tty1
76 * This program is free software; you can redistribute it and/or
81 +/* Autologin stuff. Currently Linux-specific, since there's no
82 + standard way of getting the system boot time. The kernel.h and the
83 + sysinfo prototype are used to get the system uptime under Linux. */
84 +#include <linux/kernel.h>
85 +int sysinfo(struct sysinfo *info);
87 +/* AUTO_LAST points to a timestamp file used to limit autologins to
88 + one per system boot. */
89 +#define AUTO_LAST "/var/log/autologin"
91 +/* AUTO_TTY is the tty on which autologins will be accepted. If set
92 + to an empty string, autologins will be accepted on any tty. */
93 +#define AUTO_TTY "tty1"
95 #include <sys/param.h>
99 static int noclear = 0;
100 /* Print the whole string of gethostname() instead of just until the next "." */
101 static int longhostname = 0;
102 +/* If supplied, attempt an automatic login with this username. */
103 +static char *autologin_name = NULL;
104 /* Set mono terminal type */
105 static int mono_term = 0;
106 /* Log onto remote host */
112 + * autologin_ok -- returns 1 if it's okay to auto-login when:
113 + * this login is from /dev/tty1; and
114 + * there was a login name passed with the --autologin option; and
115 + * the autologin_name contains only "nice" characters; and
116 + * this is the first autologin attempt since the last boot;
117 + * return 0 otherwise.
119 +static int autologin_ok(void)
123 + struct sysinfo info;
126 + /* Autologins are restricted to AUTO_TTY if non-empty. */
127 + if (AUTO_TTY[0] && strcmp(tty, AUTO_TTY))
130 + /* An all-alphanumeric autologin name must be supplied. */
131 + if (autologin_name == NULL || autologin_name[0] == '\0')
133 + for (cp = autologin_name; (c = *cp); cp++)
134 + if (!isalnum(c) && c != '_')
137 + /* Get the uptime in info.uptime, and the last autologin time
138 + in sbuf.st_mtime. */
140 + stat_err = stat(AUTO_LAST, &sbuf);
142 + /* If a stat error other than "no such file" occurs, I don't
143 + know what went wrong, so I'll proceed with caution by
144 + denying the autologin request. */
145 + if (stat_err && errno != ENOENT)
148 + /* If there's been an autologin granted since the last boot,
149 + deny this and any subsequent attempts. Note that this test
150 + is skipped if the AUTO_LAST file doesn't exist. */
151 + if (!stat_err && time(NULL) - info.uptime < sbuf.st_mtime)
154 + /* Create the AUTO_LAST file. The mtime of this file provides
155 + a persistent record of the last time that an autologin
156 + request was granted. Deny the autologin request if either
157 + the file open or file close fails. */
158 + if ((fd=open(AUTO_LAST, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0)
160 + if (close(fd) != 0)
163 + /* All tests are okay, so grant the autologin request. */
167 static void usage (void)
169 error ("usage: '%s tty' with e.g. tty=tty1", progname);
171 static struct option const long_options[] = {
172 { "noclear", no_argument, &noclear, 1},
173 { "long-hostname", no_argument, &longhostname, 1},
174 + { "autologin", required_argument, NULL, 'a'},
175 { "mono", no_argument, &mono_term, 1},
176 { "remote-host", required_argument, NULL, 2},
177 { "login-program", required_argument, NULL, 3},
179 strncpy(login_program, optarg, 1024);
180 login_program[1023] = '\0';
183 + autologin_name = optarg;
188 @@ -476,17 +552,21 @@
189 /* flush input and output queues, important for modems */
190 ioctl (0, TCFLSH, 2);
192 - while ((logname = get_logname ()) == 0);
194 - if (!remote_login) {
195 - if (!another_login)
196 - strncpy(login_program, _PATH_LOGIN, 1024);
197 - execl (login_program, login_program, "--", logname, NULL);
199 - if (!another_login)
200 - strncpy(login_program, _PATH_SSH, 1024);
201 - execl (login_program, login_program, "-l", logname, remote_host, NULL);
203 + if (autologin_ok()) {
204 + execl (_PATH_LOGIN, _PATH_LOGIN, "-f", autologin_name, NULL);
206 + while ((logname = get_logname ()) == 0);
208 + if (!remote_login) {
209 + if (!another_login)
210 + strncpy(login_program, _PATH_LOGIN, 1024);
211 + execl (login_program, login_program, "--", logname, NULL);
213 + if (!another_login)
214 + strncpy(login_program, _PATH_SSH, 1024);
215 + execl (login_program, login_program, "-l", logname, remote_host, NULL);
218 error ("%s: can't exec %s: %s", login_program, tty, sys_errlist[errno]);