Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 509 lines (424 sloc) 11.135 kB
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
1 /* vi: set sw=4 ts=4: */
801ab14 Add one-line GPL boilerplate to numerous (but not all yet) source files.
"Robert P. J. Day" authored
2 /*
3 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
4 */
5
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
6 #include <fcntl.h>
7 #include <signal.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <syslog.h>
12 #include <termios.h>
13 #include <unistd.h>
14 #include <utmp.h>
15 #include <sys/resource.h>
16 #include <sys/stat.h>
17 #include <sys/types.h>
2e50291 login: style fixes
Denis Vlasenko authored
18 #include <sys/wait.h>
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
19 #include <ctype.h>
20 #include <time.h>
21
27f64e1 Port over the last of the tinylogin applets
Eric Andersen authored
22 #include "busybox.h"
9e48045 Patch from Russell Coker:
Eric Andersen authored
23 #ifdef CONFIG_SELINUX
60158cb @landley A patch from Takeharu KATO to update/fix SE-Linux support.
landley authored
24 #include <selinux/selinux.h> /* for is_selinux_enabled() */
25 #include <selinux/get_context_list.h> /* for get_default_context() */
26 #include <selinux/flask.h> /* for security class definitions */
27 #include <errno.h>
9e48045 Patch from Russell Coker:
Eric Andersen authored
28 #endif
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
29
8deb686 @vapier Patch by jonlar in Bug 312 to split the U_W_TMP feature into sep UTMP…
vapier authored
30 #ifdef CONFIG_FEATURE_UTMP
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
31 // import from utmp.c
32 static void checkutmp(int picky);
33 static void setutmp(const char *name, const char *line);
71ae64b last_patch61 from vodz:
Eric Andersen authored
34 /* Stuff global to this file */
14f5c8d Patch from Bernhard Fischer to make a bunch of symbols static
Eric Andersen authored
35 static struct utmp utent;
fdfe298 last_patch60 from vodz:
Eric Andersen authored
36 #endif
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
37
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
38 enum {
39 TIMEOUT = 60,
40 EMPTY_USERNAME_COUNT = 10,
41 USERNAME_SIZE = 32,
42 };
0fbff13 Several login cleanups from vodz
Eric Andersen authored
43
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
44 static int check_nologin(int amroot);
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
45
46 #if defined CONFIG_FEATURE_SECURETTY
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
47 static int check_tty(const char *tty);
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
48
49 #else
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
50 static inline int check_tty(const char *tty) { return 1; }
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
51
52 #endif
53
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
54 static int is_my_tty(const char *tty);
55 static int login_prompt(char *buf_name);
56 static void motd(void);
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
57
58
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
59 static void alarm_handler(int sig ATTRIBUTE_UNUSED)
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
60 {
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
61 fprintf(stderr, "\nLogin timed out after %d seconds.\n", TIMEOUT);
62 exit(EXIT_SUCCESS);
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
63 }
64
65
dfba741 @landley Robert P. Day removed 8 gazillion occurrences of "extern" on function
landley authored
66 int login_main(int argc, char **argv)
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
67 {
68 char tty[BUFSIZ];
69 char full_tty[200];
70 char fromhost[512];
0fbff13 Several login cleanups from vodz
Eric Andersen authored
71 char username[USERNAME_SIZE];
dc4e75e move all "-/bin/sh" "/bin/sh" and "sh" to libbb/messages.c file as one
Glenn L McGrath authored
72 const char *tmp;
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
73 int amroot;
74 int flag;
75 int failed;
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
76 int count = 0;
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
77 struct passwd *pw, pw_copy;
27f64e1 Port over the last of the tinylogin applets
Eric Andersen authored
78 #ifdef CONFIG_WHEEL_GROUP
79 struct group *grp;
80 #endif
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
81 int opt_preserve = 0;
82 int opt_fflag = 0;
83 char *opt_host = 0;
c7bda1c Remove trailing whitespace. Update copyright to include 2004.
Eric Andersen authored
84 int alarmstarted = 0;
9e48045 Patch from Russell Coker:
Eric Andersen authored
85 #ifdef CONFIG_SELINUX
d1f8c1c @landley From Jan Kiszka: This patch fixes the security labelling of the login…
landley authored
86 security_context_t user_sid = NULL;
9e48045 Patch from Russell Coker:
Eric Andersen authored
87 #endif
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
88
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
89 username[0] = '\0';
90 amroot = (getuid() == 0);
91 signal(SIGALRM, alarm_handler);
92 alarm(TIMEOUT);
d8ceba9 Ronny L Nilsson writes:
Eric Andersen authored
93 alarmstarted = 1;
c7bda1c Remove trailing whitespace. Update copyright to include 2004.
Eric Andersen authored
94
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
95 while ((flag = getopt(argc, argv, "f:h:p")) != EOF) {
96 switch (flag) {
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
97 case 'p':
98 opt_preserve = 1;
99 break;
100 case 'f':
101 /*
aff114c Larry Doolittle writes:
Eric Andersen authored
102 * username must be a separate token
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
103 * (-f root, *NOT* -froot). --marekm
104 */
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
105 if (optarg != argv[optind-1])
106 bb_show_usage();
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
107
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
108 if (!amroot) /* Auth bypass only if real UID is zero */
109 bb_error_msg_and_die("-f permission denied");
c7bda1c Remove trailing whitespace. Update copyright to include 2004.
Eric Andersen authored
110
0fbff13 Several login cleanups from vodz
Eric Andersen authored
111 safe_strncpy(username, optarg, USERNAME_SIZE);
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
112 opt_fflag = 1;
113 break;
114 case 'h':
115 opt_host = optarg;
116 break;
117 default:
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
118 bb_show_usage();
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
119 }
120 }
121
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
122 if (optind < argc) /* user from command line (getty) */
0fbff13 Several login cleanups from vodz
Eric Andersen authored
123 safe_strncpy(username, argv[optind], USERNAME_SIZE);
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
124
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
125 if (!isatty(0) || !isatty(1) || !isatty(2))
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
126 return EXIT_FAILURE; /* Must be a terminal */
127
8deb686 @vapier Patch by jonlar in Bug 312 to split the U_W_TMP feature into sep UTMP…
vapier authored
128 #ifdef CONFIG_FEATURE_UTMP
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
129 checkutmp(!amroot);
fdfe298 last_patch60 from vodz:
Eric Andersen authored
130 #endif
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
131
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
132 tmp = ttyname(0);
133 if (tmp && (strncmp(tmp, "/dev/", 5) == 0))
134 safe_strncpy(tty, tmp + 5, sizeof(tty));
135 else if (tmp && *tmp == '/')
136 safe_strncpy(tty, tmp, sizeof(tty));
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
137 else
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
138 safe_strncpy(tty, "UNKNOWN", sizeof(tty));
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
139
8deb686 @vapier Patch by jonlar in Bug 312 to split the U_W_TMP feature into sep UTMP…
vapier authored
140 #ifdef CONFIG_FEATURE_UTMP
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
141 if (amroot)
142 memset(utent.ut_host, 0, sizeof(utent.ut_host));
71ae64b last_patch61 from vodz:
Eric Andersen authored
143 #endif
c7bda1c Remove trailing whitespace. Update copyright to include 2004.
Eric Andersen authored
144
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
145 if (opt_host) {
8deb686 @vapier Patch by jonlar in Bug 312 to split the U_W_TMP feature into sep UTMP…
vapier authored
146 #ifdef CONFIG_FEATURE_UTMP
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
147 safe_strncpy(utent.ut_host, opt_host, sizeof(utent.ut_host));
71ae64b last_patch61 from vodz:
Eric Andersen authored
148 #endif
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
149 snprintf(fromhost, sizeof(fromhost)-1, " on `%.100s' from `%.200s'", tty, opt_host);
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
150 }
151 else
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
152 snprintf(fromhost, sizeof(fromhost)-1, " on `%.100s'", tty);
c7bda1c Remove trailing whitespace. Update copyright to include 2004.
Eric Andersen authored
153
b180e5a @aldot - use portability wrapper define bb_setpgrp.
aldot authored
154 bb_setpgrp;
0fbff13 Several login cleanups from vodz
Eric Andersen authored
155
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
156 openlog("login", LOG_PID | LOG_CONS | LOG_NOWAIT, LOG_AUTH);
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
157
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
158 while (1) {
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
159 failed = 0;
160
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
161 if (!username[0])
162 if (!login_prompt(username))
0fbff13 Several login cleanups from vodz
Eric Andersen authored
163 return EXIT_FAILURE;
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
164
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
165 if (!alarmstarted && (TIMEOUT > 0)) {
166 alarm(TIMEOUT);
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
167 alarmstarted = 1;
168 }
169
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
170 pw = getpwnam(username);
171 if (!pw) {
0fbff13 Several login cleanups from vodz
Eric Andersen authored
172 pw_copy.pw_name = "UNKNOWN";
173 pw_copy.pw_passwd = "!";
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
174 opt_fflag = 0;
175 failed = 1;
c7bda1c Remove trailing whitespace. Update copyright to include 2004.
Eric Andersen authored
176 } else
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
177 pw_copy = *pw;
178
179 pw = &pw_copy;
180
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
181 if ((pw->pw_passwd[0] == '!') || (pw->pw_passwd[0] == '*'))
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
182 failed = 1;
c7bda1c Remove trailing whitespace. Update copyright to include 2004.
Eric Andersen authored
183
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
184 if (opt_fflag) {
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
185 opt_fflag = 0;
186 goto auth_ok;
187 }
188
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
189 if (!failed && (pw->pw_uid == 0) && (!check_tty(tty)))
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
190 failed = 1;
191
192 /* Don't check the password if password entry is empty (!) */
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
193 if (!pw->pw_passwd[0])
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
194 goto auth_ok;
195
196 /* authorization takes place here */
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
197 if (correct_password(pw))
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
198 goto auth_ok;
199
200 failed = 1;
c7bda1c Remove trailing whitespace. Update copyright to include 2004.
Eric Andersen authored
201
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
202 auth_ok:
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
203 if (!failed)
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
204 break;
205
84cb767 @landley patch from tito: consolidate delay functions as bb_do_delay()
landley authored
206 bb_do_delay(FAIL_DELAY);
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
207 puts("Login incorrect");
0fbff13 Several login cleanups from vodz
Eric Andersen authored
208 username[0] = 0;
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
209 if (++count == 3) {
210 syslog(LOG_WARNING, "invalid password for `%s'%s'\n", pw->pw_name, fromhost);
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
211 return EXIT_FAILURE;
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
212 }
0fbff13 Several login cleanups from vodz
Eric Andersen authored
213 }
c7bda1c Remove trailing whitespace. Update copyright to include 2004.
Eric Andersen authored
214
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
215 alarm(0);
216 if (check_nologin(pw->pw_uid == 0))
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
217 return EXIT_FAILURE;
218
8deb686 @vapier Patch by jonlar in Bug 312 to split the U_W_TMP feature into sep UTMP…
vapier authored
219 #ifdef CONFIG_FEATURE_UTMP
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
220 setutmp(username, tty);
fdfe298 last_patch60 from vodz:
Eric Andersen authored
221 #endif
60158cb @landley A patch from Takeharu KATO to update/fix SE-Linux support.
landley authored
222
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
223 if (*tty != '/')
224 snprintf(full_tty, sizeof(full_tty)-1, "/dev/%s", tty);
60158cb @landley A patch from Takeharu KATO to update/fix SE-Linux support.
landley authored
225 else
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
226 safe_strncpy(full_tty, tty, sizeof(full_tty)-1);
60158cb @landley A patch from Takeharu KATO to update/fix SE-Linux support.
landley authored
227
9e48045 Patch from Russell Coker:
Eric Andersen authored
228 #ifdef CONFIG_SELINUX
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
229 if (is_selinux_enabled()) {
d1f8c1c @landley From Jan Kiszka: This patch fixes the security labelling of the login…
landley authored
230 security_context_t old_tty_sid, new_tty_sid;
9e48045 Patch from Russell Coker:
Eric Andersen authored
231
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
232 if (get_default_context(username, NULL, &user_sid)) {
9e48045 Patch from Russell Coker:
Eric Andersen authored
233 fprintf(stderr, "Unable to get SID for %s\n", username);
234 exit(1);
235 }
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
236 if (getfilecon(full_tty, &old_tty_sid) < 0) {
237 fprintf(stderr, "getfilecon(%.100s) failed: "
238 "%.100s\n", full_tty, strerror(errno));
9e48045 Patch from Russell Coker:
Eric Andersen authored
239 return EXIT_FAILURE;
240 }
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
241 if (security_compute_relabel(user_sid, old_tty_sid, SECCLASS_CHR_FILE,
242 &new_tty_sid) != 0) {
243 fprintf(stderr, "security_change_sid(%.100s) failed: "
244 "%.100s\n", full_tty, strerror(errno));
9e48045 Patch from Russell Coker:
Eric Andersen authored
245 return EXIT_FAILURE;
246 }
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
247 if (setfilecon(full_tty, new_tty_sid) != 0) {
248 fprintf(stderr, "chsid(%.100s, %s) failed: "
249 "%.100s\n", full_tty, new_tty_sid, strerror(errno));
9e48045 Patch from Russell Coker:
Eric Andersen authored
250 return EXIT_FAILURE;
251 }
252 }
253 #endif
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
254 if (!is_my_tty(full_tty))
255 syslog(LOG_ERR, "unable to determine TTY name, got %s\n", full_tty);
c7bda1c Remove trailing whitespace. Update copyright to include 2004.
Eric Andersen authored
256
257 /* Try these, but don't complain if they fail
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
258 * (for example when the root fs is read only) */
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
259 chown(full_tty, pw->pw_uid, pw->pw_gid);
260 chmod(full_tty, 0600);
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
261
2e50291 login: style fixes
Denis Vlasenko authored
262 if (ENABLE_LOGIN_SCRIPTS) {
263 char *script = getenv("LOGIN_PRE_SUID_SCRIPT");
264 if (script) {
265 char *t_argv[2] = { script, NULL };
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
266 switch (fork()) {
2e50291 login: style fixes
Denis Vlasenko authored
267 case -1: break;
268 case 0: /* child */
269 xchdir("/");
270 setenv("LOGIN_TTY", full_tty, 1);
271 setenv("LOGIN_USER", pw->pw_name, 1);
272 setenv("LOGIN_UID", utoa(pw->pw_uid), 1);
273 setenv("LOGIN_GID", utoa(pw->pw_gid), 1);
274 setenv("LOGIN_SHELL", pw->pw_shell, 1);
275 execvp(script, t_argv);
276 exit(1);
277 default: /* parent */
278 wait(NULL);
279 }
280 }
281 }
282
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
283 change_identity(pw);
284 tmp = pw->pw_shell;
285 if (!tmp || !*tmp)
dc4e75e move all "-/bin/sh" "/bin/sh" and "sh" to libbb/messages.c file as one
Glenn L McGrath authored
286 tmp = DEFAULT_SHELL;
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
287 setup_environment(tmp, 1, !opt_preserve, pw);
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
288
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
289 motd();
290 signal(SIGALRM, SIG_DFL); /* default alarm signal */
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
291
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
292 if (pw->pw_uid == 0)
293 syslog(LOG_INFO, "root login %s\n", fromhost);
9e48045 Patch from Russell Coker:
Eric Andersen authored
294 #ifdef CONFIG_SELINUX
d1f8c1c @landley From Jan Kiszka: This patch fixes the security labelling of the login…
landley authored
295 /* well, a simple setexeccon() here would do the job as well,
296 * but let's play the game for now */
297 set_current_security_context(user_sid);
9e48045 Patch from Russell Coker:
Eric Andersen authored
298 #endif
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
299 run_shell(tmp, 1, 0, 0); /* exec the shell finally. */
c7bda1c Remove trailing whitespace. Update copyright to include 2004.
Eric Andersen authored
300
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
301 return EXIT_FAILURE;
302 }
303
304
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
305 static int login_prompt(char *buf_name)
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
306 {
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
307 char buf[1024];
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
308 char *sp, *ep;
0fbff13 Several login cleanups from vodz
Eric Andersen authored
309 int i;
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
310
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
311 for (i=0; i<EMPTY_USERNAME_COUNT; i++) {
9e5d6c0 run telnet from inetd, present login prompt if login is configured,
Glenn L McGrath authored
312 print_login_prompt();
313
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
314 if (!fgets(buf, sizeof(buf)-1, stdin))
9e5d6c0 run telnet from inetd, present login prompt if login is configured,
Glenn L McGrath authored
315 return 0;
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
316
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
317 if (!strchr(buf, '\n'))
9e5d6c0 run telnet from inetd, present login prompt if login is configured,
Glenn L McGrath authored
318 return 0;
319
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
320 for (sp = buf; isspace(*sp); sp++) { }
321 for (ep = sp; isgraph(*ep); ep++) { }
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
322
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
323 *ep = '\0';
0fbff13 Several login cleanups from vodz
Eric Andersen authored
324 safe_strncpy(buf_name, sp, USERNAME_SIZE);
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
325 if (buf_name[0])
0fbff13 Several login cleanups from vodz
Eric Andersen authored
326 return 1;
327 }
328 return 0;
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
329 }
330
331
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
332 static int check_nologin(int amroot)
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
333 {
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
334 if (access(bb_path_nologin_file, F_OK) == 0) {
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
335 FILE *fp;
336 int c;
337
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
338 fp = fopen(bb_path_nologin_file, "r");
339 if (fp) {
340 while ((c = getc(fp)) != EOF)
341 putchar((c=='\n') ? '\r' : c);
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
342
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
343 fflush(stdout);
344 fclose(fp);
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
345 } else {
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
346 puts("\r\nSystem closed for routine maintenance.\r");
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
347 }
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
348 if (!amroot)
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
349 return 1;
c7bda1c Remove trailing whitespace. Update copyright to include 2004.
Eric Andersen authored
350
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
351 puts("\r\n[Disconnect bypassed -- root login allowed.]\r");
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
352 }
353 return 0;
354 }
355
356 #ifdef CONFIG_FEATURE_SECURETTY
357
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
358 static int check_tty(const char *tty)
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
359 {
360 FILE *fp;
361 int i;
362 char buf[BUFSIZ];
363
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
364 fp = fopen(bb_path_securetty_file, "r");
365 if (fp) {
366 while (fgets(buf, sizeof(buf)-1, fp)) {
367 for(i = strlen(buf)-1; i>=0; --i) {
368 if (!isspace(buf[i]))
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
369 break;
370 }
371 buf[++i] = '\0';
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
372 if ((buf[0]=='\0') || (buf[0]=='#'))
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
373 continue;
374
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
375 if (strcmp(buf, tty)== 0) {
376 fclose(fp);
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
377 return 1;
378 }
379 }
380 fclose(fp);
381 return 0;
382 }
f870148 A missing securetty file is not an error.
Eric Andersen authored
383 /* A missing securetty file is not an error. */
69b5756 A missing /etc/securetty is not an error when checking the tty name -…
Robert Griebl authored
384 return 1;
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
385 }
386
387 #endif
388
389 /* returns 1 if true */
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
390 static int is_my_tty(const char *tty)
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
391 {
392 struct stat by_name, by_fd;
393
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
394 if (stat(tty, &by_name) || fstat(0, &by_fd))
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
395 return 0;
c7bda1c Remove trailing whitespace. Update copyright to include 2004.
Eric Andersen authored
396
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
397 if (by_name.st_rdev != by_fd.st_rdev)
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
398 return 0;
399 else
400 return 1;
401 }
402
403
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
404 static void motd(void)
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
405 {
406 FILE *fp;
6822983 Remove all usage of the "register" storage class specifier.
"Robert P. J. Day" authored
407 int c;
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
408
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
409 fp = fopen(bb_path_motd_file, "r");
410 if (fp) {
411 while ((c = getc(fp)) != EOF)
412 putchar(c);
413 fclose(fp);
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
414 }
415 }
416
417
8deb686 @vapier Patch by jonlar in Bug 312 to split the U_W_TMP feature into sep UTMP…
vapier authored
418 #ifdef CONFIG_FEATURE_UTMP
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
419 // vv Taken from tinylogin utmp.c vv
420
421 #define NO_UTENT \
422 "No utmp entry. You must exec \"login\" from the lowest level \"sh\""
423 #define NO_TTY \
424 "Unable to determine your tty name."
425
426 /*
427 * checkutmp - see if utmp file is correct for this process
428 *
429 * System V is very picky about the contents of the utmp file
430 * and requires that a slot for the current process exist.
431 * The utmp file is scanned for an entry with the same process
432 * ID. If no entry exists the process exits with a message.
433 *
434 * The "picky" flag is for network and other logins that may
435 * use special flags. It allows the pid checks to be overridden.
436 * This means that getty should never invoke login with any
437 * command line flags.
438 */
439
440 static void checkutmp(int picky)
441 {
442 char *line;
443 struct utmp *ut;
444 pid_t pid = getpid();
445
446 setutent();
447
448 /* First, try to find a valid utmp entry for this process. */
449 while ((ut = getutent()))
450 if (ut->ut_pid == pid && ut->ut_line[0] && ut->ut_id[0] &&
451 (ut->ut_type == LOGIN_PROCESS || ut->ut_type == USER_PROCESS))
452 break;
453
454 /* If there is one, just use it, otherwise create a new one. */
455 if (ut) {
456 utent = *ut;
457 } else {
77bb33c destroy potential overflow for x86_64. Added ATTRIBUTE_UNUSED
"Vladimir N. Oleynik" authored
458 time_t t_tmp;
459
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
460 if (picky) {
461 puts(NO_UTENT);
462 exit(1);
463 }
464 line = ttyname(0);
465 if (!line) {
466 puts(NO_TTY);
467 exit(1);
468 }
469 if (strncmp(line, "/dev/", 5) == 0)
470 line += 5;
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
471 memset(&utent, 0, sizeof(utent));
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
472 utent.ut_type = LOGIN_PROCESS;
473 utent.ut_pid = pid;
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
474 strncpy(utent.ut_line, line, sizeof(utent.ut_line));
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
475 /* XXX - assumes /dev/tty?? */
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
476 strncpy(utent.ut_id, utent.ut_line + 3, sizeof(utent.ut_id));
477 strncpy(utent.ut_user, "LOGIN", sizeof(utent.ut_user));
77bb33c destroy potential overflow for x86_64. Added ATTRIBUTE_UNUSED
"Vladimir N. Oleynik" authored
478 t_tmp = (time_t)utent.ut_time;
479 time(&t_tmp);
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
480 }
481 }
482
483 /*
484 * setutmp - put a USER_PROCESS entry in the utmp file
485 *
486 * setutmp changes the type of the current utmp entry to
487 * USER_PROCESS. the wtmp file will be updated as well.
488 */
489
77bb33c destroy potential overflow for x86_64. Added ATTRIBUTE_UNUSED
"Vladimir N. Oleynik" authored
490 static void setutmp(const char *name, const char *line ATTRIBUTE_UNUSED)
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
491 {
39e7510 more destroy potential overflow for x86_64.
"Vladimir N. Oleynik" authored
492 time_t t_tmp = (time_t)utent.ut_time;
781e42d @aldot - introduce and use bb_path_wtmp_file for portability (saves 11 Bytes).
aldot authored
493
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
494 utent.ut_type = USER_PROCESS;
942e429 login: previous commit comment was wrong :)
Denis Vlasenko authored
495 strncpy(utent.ut_user, name, sizeof(utent.ut_user));
39e7510 more destroy potential overflow for x86_64.
"Vladimir N. Oleynik" authored
496 time(&t_tmp);
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
497 /* other fields already filled in by checkutmp above */
498 setutent();
499 pututline(&utent);
500 endutent();
8deb686 @vapier Patch by jonlar in Bug 312 to split the U_W_TMP feature into sep UTMP…
vapier authored
501 #ifdef CONFIG_FEATURE_WTMP
781e42d @aldot - introduce and use bb_path_wtmp_file for portability (saves 11 Bytes).
aldot authored
502 if (access(bb_path_wtmp_file, R_OK|W_OK) == -1) {
503 close(creat(bb_path_wtmp_file, 0664));
aad29b3 Fixup getty, login, etc so the utmp and wtmp are updated, allowing
Eric Andersen authored
504 }
781e42d @aldot - introduce and use bb_path_wtmp_file for portability (saves 11 Bytes).
aldot authored
505 updwtmp(bb_path_wtmp_file, &utent);
8deb686 @vapier Patch by jonlar in Bug 312 to split the U_W_TMP feature into sep UTMP…
vapier authored
506 #endif
1fca558 Bigger patch for (partial) tinylogin integration
Robert Griebl authored
507 }
8deb686 @vapier Patch by jonlar in Bug 312 to split the U_W_TMP feature into sep UTMP…
vapier authored
508 #endif /* CONFIG_FEATURE_UTMP */
Something went wrong with that request. Please try again.