]> git.pld-linux.org Git - packages/mingetty.git/blob - mingetty-autologin.patch
removed deleting nonexistent file (mingetty.c~)
[packages/mingetty.git] / mingetty-autologin.patch
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
4 @@ -3,7 +3,7 @@
5  mingetty \- minimal getty for consoles
6  .SH SYNOPSIS
7  .B mingetty
8 -[\-\-noclear] [\-\-long\-hostname]
9 +[\-\-noclear] [\-\-long\-hostname] [\-\-autologin username]
10  .I tty
11  .PP
12  .SH DESCRIPTION
13 @@ -27,6 +27,41 @@
14  By default the hostname is only printed until the first dot.
15  With this option enabled, the full text from gethostname() is shown.
16  .TP
17 +.B \-\-autologin username
18 +Log the specified user onto the console (normally
19 +.IR  /dev/tty1 )
20 +when the system is first booted without prompting for a username or
21 +password.
22 +.IP
23 +When the autologin option is supplied,
24 +.B mingetty 
25 +will check that the controlling terminal is the console (normally
26 +.IR /dev/tty1 ), 
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
30 +passed to the
31 +.B login 
32 +program.  Otherwise, a normal interactive login is performed.
33 +.IP
34 +The
35 +.B login 
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
40 +.IR nologin , 
41 +.IR usertty , 
42 +or
43 +.I securetty 
44 +files.
45 +.IP
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, 
48 +.B mingetty
49 +will revert to performing normal interactive logins for all subsequent
50 +login requests.
51 +.TP
52  .B \-\-mono
53  Set terminal type to "linux-m" instead of default "linux" (for mono consoles)
54  .TP
55 @@ -73,7 +108,8 @@
56  .PP
57  .SH FILES
58  .IR /etc/issue ,
59 -.IR /var/run/utmp .
60 +.IR /var/run/utmp ,
61 +.IR /var/log/autologin .
62  .PP
63  .SH "SEE ALSO"
64  .BR mgetty (8),
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
68 @@ -17,7 +17,7 @@
69   *  should be very reliable. For a modem getty, I'd also use nothing else
70   *  but mgetty.
71   *
72 - *  Usage: mingetty [--noclear] tty
73 + *  Usage: mingetty [--noclear] [--autologin username] tty
74   *  Example entry in /etc/inittab: 1:123:respawn:/sbin/mingetty tty1
75   *
76   *  This program is free software; you can redistribute it and/or
77 @@ -53,6 +53,20 @@
78  #endif
79  
80  #ifdef linux
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);
86 +
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"
90 +
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"
94 +
95  #include <sys/param.h>
96  #define USE_SYSLOG
97  #endif
98 @@ -84,6 +98,8 @@
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 */
107 @@ -398,6 +414,62 @@
108         return logname;
109  }
110  
111 +/*
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.
118 + */
119 +static int autologin_ok(void)
120 +{
121 +       char c, *cp;
122 +       int stat_err, fd;
123 +       struct sysinfo info;
124 +       struct stat sbuf;
125 +
126 +       /* Autologins are restricted to AUTO_TTY if non-empty. */
127 +       if (AUTO_TTY[0] && strcmp(tty, AUTO_TTY))
128 +               return 0;
129 +
130 +       /* An all-alphanumeric autologin name must be supplied. */
131 +       if (autologin_name == NULL || autologin_name[0] == '\0')
132 +               return 0;
133 +       for (cp = autologin_name; (c = *cp); cp++)
134 +               if (!isalnum(c) && c != '_')
135 +                       return 0;
136 +
137 +       /* Get the uptime in info.uptime, and the last autologin time
138 +           in sbuf.st_mtime. */
139 +       sysinfo(&info);
140 +       stat_err = stat(AUTO_LAST, &sbuf);
141 +
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)
146 +               return 0;
147 +
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)
152 +               return 0;
153 +
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)
159 +               return 0;
160 +       if (close(fd) != 0)
161 +               return 0;
162 +
163 +       /* All tests are okay, so grant the autologin request. */
164 +       return 1;
165 +}
166 +
167  static void usage (void)
168  {
169         error ("usage: '%s tty' with e.g. tty=tty1", progname);
170 @@ -406,6 +478,7 @@
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},
178 @@ -441,6 +514,9 @@
179                                 strncpy(login_program, optarg, 1024);
180                                 login_program[1023] = '\0';
181                                 break;
182 +                       case 'a':
183 +                               autologin_name = optarg;
184 +                               break;
185                         default:
186                                 usage ();
187                 }
188 @@ -476,17 +552,21 @@
189         /* flush input and output queues, important for modems */
190         ioctl (0, TCFLSH, 2);
191  
192 -       while ((logname = get_logname ()) == 0);
193 -
194 -       if (!remote_login) {
195 -                 if (!another_login)
196 -                           strncpy(login_program, _PATH_LOGIN, 1024);
197 -                 execl (login_program, login_program, "--", logname, NULL);
198 -       } else {
199 -                 if (!another_login)
200 -                           strncpy(login_program, _PATH_SSH, 1024);
201 -                 execl (login_program, login_program, "-l", logname, remote_host, NULL);
202 -       }
203 +       if (autologin_ok()) {
204 +               execl (_PATH_LOGIN, _PATH_LOGIN, "-f", autologin_name, NULL);
205 +       } else {
206 +      while ((logname = get_logname ()) == 0);
207 +
208 +      if (!remote_login) {
209 +           if (!another_login)
210 +                strncpy(login_program, _PATH_LOGIN, 1024);
211 +           execl (login_program, login_program, "--", logname, NULL);
212 +      } else {
213 +           if (!another_login)
214 +                strncpy(login_program, _PATH_SSH, 1024);
215 +           execl (login_program, login_program, "-l", logname, remote_host, NULL);
216 +      }
217 +   }
218         error ("%s: can't exec %s: %s", login_program, tty, sys_errlist[errno]);
219         exit (0);
220  }
This page took 0.116842 seconds and 3 git commands to generate.