blob: 3d8b8e540b0c7a39ac216b990964f3bee0c368d0 [file] [log] [blame]
Robert Griebl1fca5582002-06-04 20:45:46 +00001/* vi: set sw=4 ts=4: */
"Robert P. J. Day"801ab142006-07-12 07:56:04 +00002/*
3 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
4 */
5
Bernhard Reutner-Fischer92582f22006-09-13 15:42:47 +00006#include "busybox.h"
Robert Griebl1fca5582002-06-04 20:45:46 +00007#include <utmp.h>
8#include <sys/resource.h>
Bernhard Reutner-Fischer92582f22006-09-13 15:42:47 +00009#include <syslog.h>
Eric Andersen27f64e12002-06-23 04:24:25 +000010
Denis Vlasenkoc0415a92007-03-24 17:04:07 +000011#if ENABLE_SELINUX
Rob Landley60158cb2005-05-03 06:25:50 +000012#include <selinux/selinux.h> /* for is_selinux_enabled() */
13#include <selinux/get_context_list.h> /* for get_default_context() */
14#include <selinux/flask.h> /* for security class definitions */
15#include <errno.h>
Eric Andersen9e480452003-07-03 10:07:04 +000016#endif
Robert Griebl1fca5582002-06-04 20:45:46 +000017
Denis Vlasenko942e4292006-09-08 17:25:04 +000018enum {
19 TIMEOUT = 60,
20 EMPTY_USERNAME_COUNT = 10,
21 USERNAME_SIZE = 32,
Denis Vlasenko9a9edf22006-09-08 17:29:53 +000022 TTYNAME_SIZE = 32,
Denis Vlasenko942e4292006-09-08 17:25:04 +000023};
Eric Andersen0fbff132002-06-22 17:49:29 +000024
Denis Vlasenkoc0415a92007-03-24 17:04:07 +000025static char* short_tty;
Denis Vlasenko7ccf5cc2006-09-14 17:03:18 +000026
27#if ENABLE_FEATURE_UTMP
28/* vv Taken from tinylogin utmp.c vv */
29/*
30 * read_or_build_utent - see if utmp file is correct for this process
31 *
32 * System V is very picky about the contents of the utmp file
33 * and requires that a slot for the current process exist.
34 * The utmp file is scanned for an entry with the same process
35 * ID. If no entry exists the process exits with a message.
36 *
37 * The "picky" flag is for network and other logins that may
38 * use special flags. It allows the pid checks to be overridden.
39 * This means that getty should never invoke login with any
40 * command line flags.
41 */
Denis Vlasenko66fabdb2006-09-17 14:45:09 +000042
Denis Vlasenkoc0415a92007-03-24 17:04:07 +000043static void read_or_build_utent(struct utmp *utptr, int picky)
Denis Vlasenko7ccf5cc2006-09-14 17:03:18 +000044{
45 struct utmp *ut;
46 pid_t pid = getpid();
47
48 setutent();
49
50 /* First, try to find a valid utmp entry for this process. */
51 while ((ut = getutent()))
52 if (ut->ut_pid == pid && ut->ut_line[0] && ut->ut_id[0] &&
53 (ut->ut_type == LOGIN_PROCESS || ut->ut_type == USER_PROCESS))
54 break;
55
56 /* If there is one, just use it, otherwise create a new one. */
57 if (ut) {
Denis Vlasenkoc0415a92007-03-24 17:04:07 +000058 *utptr = *ut;
Denis Vlasenko7ccf5cc2006-09-14 17:03:18 +000059 } else {
60 if (picky)
61 bb_error_msg_and_die("no utmp entry found");
62
Denis Vlasenkoc0415a92007-03-24 17:04:07 +000063 memset(utptr, 0, sizeof(*utptr));
64 utptr->ut_type = LOGIN_PROCESS;
65 utptr->ut_pid = pid;
66 strncpy(utptr->ut_line, short_tty, sizeof(utptr->ut_line));
Denis Vlasenko7ccf5cc2006-09-14 17:03:18 +000067 /* This one is only 4 chars wide. Try to fit something
68 * remotely meaningful by skipping "tty"... */
Denis Vlasenkoc0415a92007-03-24 17:04:07 +000069 strncpy(utptr->ut_id, short_tty + 3, sizeof(utptr->ut_id));
70 strncpy(utptr->ut_user, "LOGIN", sizeof(utptr->ut_user));
71 utptr->ut_time = time(NULL);
Denis Vlasenko7ccf5cc2006-09-14 17:03:18 +000072 }
73 if (!picky) /* root login */
Denis Vlasenkoc0415a92007-03-24 17:04:07 +000074 memset(utptr->ut_host, 0, sizeof(utptr->ut_host));
Denis Vlasenko7ccf5cc2006-09-14 17:03:18 +000075}
76
77/*
78 * write_utent - put a USER_PROCESS entry in the utmp file
79 *
80 * write_utent changes the type of the current utmp entry to
81 * USER_PROCESS. the wtmp file will be updated as well.
82 */
Denis Vlasenkoc0415a92007-03-24 17:04:07 +000083static void write_utent(struct utmp *utptr, const char *username)
Denis Vlasenko7ccf5cc2006-09-14 17:03:18 +000084{
Denis Vlasenkoc0415a92007-03-24 17:04:07 +000085 utptr->ut_type = USER_PROCESS;
86 strncpy(utptr->ut_user, username, sizeof(utptr->ut_user));
87 utptr->ut_time = time(NULL);
Denis Vlasenko7ccf5cc2006-09-14 17:03:18 +000088 /* other fields already filled in by read_or_build_utent above */
89 setutent();
Denis Vlasenkoc0415a92007-03-24 17:04:07 +000090 pututline(utptr);
Denis Vlasenko7ccf5cc2006-09-14 17:03:18 +000091 endutent();
92#if ENABLE_FEATURE_WTMP
93 if (access(bb_path_wtmp_file, R_OK|W_OK) == -1) {
94 close(creat(bb_path_wtmp_file, 0664));
95 }
Denis Vlasenkoc0415a92007-03-24 17:04:07 +000096 updwtmp(bb_path_wtmp_file, utptr);
Denis Vlasenko7ccf5cc2006-09-14 17:03:18 +000097#endif
98}
Denis Vlasenko66fabdb2006-09-17 14:45:09 +000099#else /* !ENABLE_FEATURE_UTMP */
Denis Vlasenkoc0415a92007-03-24 17:04:07 +0000100#define read_or_build_utent(utptr, picky) ((void)0)
101#define write_utent(utptr, username) ((void)0)
Denis Vlasenko66fabdb2006-09-17 14:45:09 +0000102#endif /* !ENABLE_FEATURE_UTMP */
Denis Vlasenko7ccf5cc2006-09-14 17:03:18 +0000103
104static void die_if_nologin_and_non_root(int amroot)
105{
106 FILE *fp;
107 int c;
108
109 if (access(bb_path_nologin_file, F_OK))
110 return;
111
112 fp = fopen(bb_path_nologin_file, "r");
113 if (fp) {
114 while ((c = getc(fp)) != EOF)
115 putchar((c=='\n') ? '\r' : c);
116 fflush(stdout);
117 fclose(fp);
118 } else
119 puts("\r\nSystem closed for routine maintenance\r");
120 if (!amroot)
121 exit(1);
122 puts("\r\n[Disconnect bypassed -- root login allowed.]\r");
123}
Robert Griebl1fca5582002-06-04 20:45:46 +0000124
Bernhard Reutner-Fischer92582f22006-09-13 15:42:47 +0000125#if ENABLE_FEATURE_SECURETTY
Denis Vlasenko7ccf5cc2006-09-14 17:03:18 +0000126static int check_securetty(void)
127{
128 FILE *fp;
129 int i;
130 char buf[BUFSIZ];
131
132 fp = fopen(bb_path_securetty_file, "r");
133 if (!fp) {
134 /* A missing securetty file is not an error. */
135 return 1;
136 }
137 while (fgets(buf, sizeof(buf)-1, fp)) {
Denis Vlasenkobf0a2012006-12-26 10:42:51 +0000138 for (i = strlen(buf)-1; i>=0; --i) {
Denis Vlasenko7ccf5cc2006-09-14 17:03:18 +0000139 if (!isspace(buf[i]))
140 break;
141 }
142 buf[++i] = '\0';
143 if ((buf[0]=='\0') || (buf[0]=='#'))
144 continue;
145 if (strcmp(buf, short_tty) == 0) {
146 fclose(fp);
147 return 1;
148 }
149 }
150 fclose(fp);
151 return 0;
152}
Robert Griebl1fca5582002-06-04 20:45:46 +0000153#else
Denis Vlasenko9a9edf22006-09-08 17:29:53 +0000154static inline int check_securetty(void) { return 1; }
Robert Griebl1fca5582002-06-04 20:45:46 +0000155#endif
156
Denis Vlasenko7ccf5cc2006-09-14 17:03:18 +0000157static void get_username_or_die(char *buf, int size_buf)
158{
159 int c, cntdown;
160 cntdown = EMPTY_USERNAME_COUNT;
161prompt:
162 /* skip whitespace */
163 print_login_prompt();
164 do {
165 c = getchar();
166 if (c == EOF) exit(1);
167 if (c == '\n') {
168 if (!--cntdown) exit(1);
169 goto prompt;
170 }
171 } while (isspace(c));
172
173 *buf++ = c;
174 if (!fgets(buf, size_buf-2, stdin))
175 exit(1);
176 if (!strchr(buf, '\n'))
177 exit(1);
178 while (isgraph(*buf)) buf++;
179 *buf = '\0';
180}
181
182static void motd(void)
183{
184 FILE *fp;
185 int c;
186
187 fp = fopen(bb_path_motd_file, "r");
188 if (fp) {
189 while ((c = getc(fp)) != EOF)
190 putchar(c);
191 fclose(fp);
192 }
193}
Robert Griebl1fca5582002-06-04 20:45:46 +0000194
Denis Vlasenko942e4292006-09-08 17:25:04 +0000195static void alarm_handler(int sig ATTRIBUTE_UNUSED)
Robert Griebl1fca5582002-06-04 20:45:46 +0000196{
Denis Vlasenko2f50aa42006-09-08 17:56:52 +0000197 /* This is the escape hatch! Poor serial line users and the like
198 * arrive here when their connection is broken.
199 * We don't want to block here */
Denis Vlasenkoc0415a92007-03-24 17:04:07 +0000200 ndelay_on(1);
201 ndelay_on(2);
Denis Vlasenko2f50aa42006-09-08 17:56:52 +0000202 bb_info_msg("\r\nLogin timed out after %d seconds\r", TIMEOUT);
Denis Vlasenko942e4292006-09-08 17:25:04 +0000203 exit(EXIT_SUCCESS);
Robert Griebl1fca5582002-06-04 20:45:46 +0000204}
205
Denis Vlasenko06af2162007-02-03 17:28:39 +0000206int login_main(int argc, char **argv);
Rob Landleydfba7412006-03-06 20:47:33 +0000207int login_main(int argc, char **argv)
Robert Griebl1fca5582002-06-04 20:45:46 +0000208{
Denis Vlasenko66fabdb2006-09-17 14:45:09 +0000209 enum {
210 LOGIN_OPT_f = (1<<0),
211 LOGIN_OPT_h = (1<<1),
212 LOGIN_OPT_p = (1<<2),
213 };
Robert Griebl1fca5582002-06-04 20:45:46 +0000214 char fromhost[512];
Eric Andersen0fbff132002-06-22 17:49:29 +0000215 char username[USERNAME_SIZE];
Glenn L McGrathdc4e75e2003-09-02 02:36:18 +0000216 const char *tmp;
Robert Griebl1fca5582002-06-04 20:45:46 +0000217 int amroot;
Denis Vlasenko67b23e62006-10-03 21:00:06 +0000218 unsigned opt;
Denis Vlasenko942e4292006-09-08 17:25:04 +0000219 int count = 0;
Denis Vlasenko9a9edf22006-09-08 17:29:53 +0000220 struct passwd *pw;
Denis Vlasenko66fabdb2006-09-17 14:45:09 +0000221 char *opt_host = NULL;
222 char *opt_user = NULL;
Denis Vlasenkoc0415a92007-03-24 17:04:07 +0000223 char full_tty[TTYNAME_SIZE];
Denis Vlasenko66fabdb2006-09-17 14:45:09 +0000224 USE_SELINUX(security_context_t user_sid = NULL;)
Denis Vlasenkoc0415a92007-03-24 17:04:07 +0000225 USE_FEATURE_UTMP(struct utmp utent;)
Robert Griebl1fca5582002-06-04 20:45:46 +0000226
Denis Vlasenkoc0415a92007-03-24 17:04:07 +0000227 short_tty = full_tty;
Denis Vlasenko942e4292006-09-08 17:25:04 +0000228 username[0] = '\0';
229 amroot = (getuid() == 0);
230 signal(SIGALRM, alarm_handler);
231 alarm(TIMEOUT);
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000232
Denis Vlasenko67b23e62006-10-03 21:00:06 +0000233 opt = getopt32(argc, argv, "f:h:p", &opt_user, &opt_host);
Denis Vlasenko66fabdb2006-09-17 14:45:09 +0000234 if (opt & LOGIN_OPT_f) {
235 if (!amroot)
236 bb_error_msg_and_die("-f is for root only");
Denis Vlasenko22f6dcb2006-09-26 16:31:01 +0000237 safe_strncpy(username, opt_user, sizeof(username));
Robert Griebl1fca5582002-06-04 20:45:46 +0000238 }
Denis Vlasenko22f6dcb2006-09-26 16:31:01 +0000239 if (optind < argc) /* user from command line (getty) */
240 safe_strncpy(username, argv[optind], sizeof(username));
Robert Griebl1fca5582002-06-04 20:45:46 +0000241
Denis Vlasenko9a9edf22006-09-08 17:29:53 +0000242 /* Let's find out and memorize our tty */
Denis Vlasenko942e4292006-09-08 17:25:04 +0000243 if (!isatty(0) || !isatty(1) || !isatty(2))
Robert Griebl1fca5582002-06-04 20:45:46 +0000244 return EXIT_FAILURE; /* Must be a terminal */
Denis Vlasenko9a9edf22006-09-08 17:29:53 +0000245 safe_strncpy(full_tty, "UNKNOWN", sizeof(full_tty));
Denis Vlasenko942e4292006-09-08 17:25:04 +0000246 tmp = ttyname(0);
Denis Vlasenko9a9edf22006-09-08 17:29:53 +0000247 if (tmp) {
248 safe_strncpy(full_tty, tmp, sizeof(full_tty));
249 if (strncmp(full_tty, "/dev/", 5) == 0)
250 short_tty = full_tty + 5;
251 }
Robert Griebl1fca5582002-06-04 20:45:46 +0000252
Denis Vlasenkoc0415a92007-03-24 17:04:07 +0000253 read_or_build_utent(&utent, !amroot);
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000254
Denis Vlasenko942e4292006-09-08 17:25:04 +0000255 if (opt_host) {
Denis Vlasenko66fabdb2006-09-17 14:45:09 +0000256 USE_FEATURE_UTMP(
Denis Vlasenko9a9edf22006-09-08 17:29:53 +0000257 safe_strncpy(utent.ut_host, opt_host, sizeof(utent.ut_host));
Denis Vlasenko66fabdb2006-09-17 14:45:09 +0000258 )
Denis Vlasenko89f0b342006-11-18 22:04:09 +0000259 snprintf(fromhost, sizeof(fromhost)-1, " on '%.100s' from "
260 "'%.200s'", short_tty, opt_host);
Denis Vlasenkoc0415a92007-03-24 17:04:07 +0000261 } else
Denis Vlasenko89f0b342006-11-18 22:04:09 +0000262 snprintf(fromhost, sizeof(fromhost)-1, " on '%.100s'", short_tty);
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000263
Bernhard Reutner-Fischerb180e5a2006-05-26 14:24:56 +0000264 bb_setpgrp;
Eric Andersen0fbff132002-06-22 17:49:29 +0000265
Denis Vlasenko8f8f2682006-10-03 21:00:43 +0000266 openlog(applet_name, LOG_PID | LOG_CONS | LOG_NOWAIT, LOG_AUTH);
Robert Griebl1fca5582002-06-04 20:45:46 +0000267
Denis Vlasenko942e4292006-09-08 17:25:04 +0000268 while (1) {
Denis Vlasenko942e4292006-09-08 17:25:04 +0000269 if (!username[0])
Denis Vlasenko9a9edf22006-09-08 17:29:53 +0000270 get_username_or_die(username, sizeof(username));
Robert Griebl1fca5582002-06-04 20:45:46 +0000271
Denis Vlasenko942e4292006-09-08 17:25:04 +0000272 pw = getpwnam(username);
273 if (!pw) {
Denis Vlasenko9a9edf22006-09-08 17:29:53 +0000274 safe_strncpy(username, "UNKNOWN", sizeof(username));
275 goto auth_failed;
Robert Griebl1fca5582002-06-04 20:45:46 +0000276 }
277
Denis Vlasenko9a9edf22006-09-08 17:29:53 +0000278 if (pw->pw_passwd[0] == '!' || pw->pw_passwd[0] == '*')
279 goto auth_failed;
280
Denis Vlasenko66fabdb2006-09-17 14:45:09 +0000281 if (opt & LOGIN_OPT_f)
Denis Vlasenko9a9edf22006-09-08 17:29:53 +0000282 break; /* -f USER: success without asking passwd */
283
284 if (pw->pw_uid == 0 && !check_securetty())
285 goto auth_failed;
Robert Griebl1fca5582002-06-04 20:45:46 +0000286
287 /* Don't check the password if password entry is empty (!) */
Denis Vlasenko942e4292006-09-08 17:25:04 +0000288 if (!pw->pw_passwd[0])
Denis Vlasenko66fabdb2006-09-17 14:45:09 +0000289 break;
Robert Griebl1fca5582002-06-04 20:45:46 +0000290
291 /* authorization takes place here */
Denis Vlasenko942e4292006-09-08 17:25:04 +0000292 if (correct_password(pw))
Denis Vlasenko66fabdb2006-09-17 14:45:09 +0000293 break;
Robert Griebl1fca5582002-06-04 20:45:46 +0000294
Denis Vlasenko9a9edf22006-09-08 17:29:53 +0000295auth_failed:
Denis Vlasenko66fabdb2006-09-17 14:45:09 +0000296 opt &= ~LOGIN_OPT_f;
Rob Landley84cb7672006-01-06 20:59:09 +0000297 bb_do_delay(FAIL_DELAY);
Robert Griebl1fca5582002-06-04 20:45:46 +0000298 puts("Login incorrect");
Denis Vlasenko942e4292006-09-08 17:25:04 +0000299 if (++count == 3) {
Denis Vlasenko89f0b342006-11-18 22:04:09 +0000300 syslog(LOG_WARNING, "invalid password for '%s'%s",
Denis Vlasenko9a9edf22006-09-08 17:29:53 +0000301 username, fromhost);
Robert Griebl1fca5582002-06-04 20:45:46 +0000302 return EXIT_FAILURE;
Denis Vlasenko942e4292006-09-08 17:25:04 +0000303 }
Denis Vlasenko9a9edf22006-09-08 17:29:53 +0000304 username[0] = '\0';
Eric Andersen0fbff132002-06-22 17:49:29 +0000305 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000306
Denis Vlasenko942e4292006-09-08 17:25:04 +0000307 alarm(0);
Denis Vlasenko9a9edf22006-09-08 17:29:53 +0000308 die_if_nologin_and_non_root(pw->pw_uid == 0);
Robert Griebl1fca5582002-06-04 20:45:46 +0000309
Denis Vlasenkoc0415a92007-03-24 17:04:07 +0000310 write_utent(&utent, username);
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000311
Rob Landley60158cb2005-05-03 06:25:50 +0000312#ifdef CONFIG_SELINUX
Denis Vlasenko942e4292006-09-08 17:25:04 +0000313 if (is_selinux_enabled()) {
Rob Landleyd1f8c1c2006-03-27 23:04:42 +0000314 security_context_t old_tty_sid, new_tty_sid;
Rob Landley60158cb2005-05-03 06:25:50 +0000315
Denis Vlasenko942e4292006-09-08 17:25:04 +0000316 if (get_default_context(username, NULL, &user_sid)) {
Denis Vlasenko89f0b342006-11-18 22:04:09 +0000317 bb_error_msg_and_die("cannot get SID for %s",
Denis Vlasenko6bbd1742006-09-08 17:26:20 +0000318 username);
Rob Landley60158cb2005-05-03 06:25:50 +0000319 }
Denis Vlasenko942e4292006-09-08 17:25:04 +0000320 if (getfilecon(full_tty, &old_tty_sid) < 0) {
Denis Vlasenko4a5cf162006-11-20 00:48:22 +0000321 bb_perror_msg_and_die("getfilecon(%s) failed",
Denis Vlasenko6bbd1742006-09-08 17:26:20 +0000322 full_tty);
Rob Landley60158cb2005-05-03 06:25:50 +0000323 }
Denis Vlasenko6bbd1742006-09-08 17:26:20 +0000324 if (security_compute_relabel(user_sid, old_tty_sid,
325 SECCLASS_CHR_FILE, &new_tty_sid) != 0) {
Denis Vlasenko4a5cf162006-11-20 00:48:22 +0000326 bb_perror_msg_and_die("security_change_sid(%s) failed",
Denis Vlasenko6bbd1742006-09-08 17:26:20 +0000327 full_tty);
Rob Landley60158cb2005-05-03 06:25:50 +0000328 }
Denis Vlasenko942e4292006-09-08 17:25:04 +0000329 if (setfilecon(full_tty, new_tty_sid) != 0) {
Denis Vlasenko4a5cf162006-11-20 00:48:22 +0000330 bb_perror_msg_and_die("chsid(%s, %s) failed",
Denis Vlasenko6bbd1742006-09-08 17:26:20 +0000331 full_tty, new_tty_sid);
Rob Landley60158cb2005-05-03 06:25:50 +0000332 }
Rob Landley60158cb2005-05-03 06:25:50 +0000333 }
334#endif
Denis Vlasenko2f50aa42006-09-08 17:56:52 +0000335 /* Try these, but don't complain if they fail.
336 * _f_chown is safe wrt race t=ttyname(0);...;chown(t); */
337 fchown(0, pw->pw_uid, pw->pw_gid);
338 fchmod(0, 0600);
Robert Griebl1fca5582002-06-04 20:45:46 +0000339
Denis Vlasenko2e502912006-09-08 17:22:45 +0000340 if (ENABLE_LOGIN_SCRIPTS) {
Denis Vlasenko53091ec2007-03-26 13:35:09 +0000341 char *t_argv[2];
342
343 t_argv[0] = getenv("LOGIN_PRE_SUID_SCRIPT");
344 if (t_argv[0]) {
345 t_argv[1] = NULL;
346 setenv("LOGIN_TTY", full_tty, 1);
347 setenv("LOGIN_USER", pw->pw_name, 1);
348 setenv("LOGIN_UID", utoa(pw->pw_uid), 1);
349 setenv("LOGIN_GID", utoa(pw->pw_gid), 1);
350 setenv("LOGIN_SHELL", pw->pw_shell, 1);
351 xspawn(argv); /* NOMMU-friendly */
352 unsetenv("LOGIN_TTY");
353 unsetenv("LOGIN_USER");
354 unsetenv("LOGIN_UID");
355 unsetenv("LOGIN_GID");
356 unsetenv("LOGIN_SHELL");
357 wait(NULL);
Denis Vlasenko2e502912006-09-08 17:22:45 +0000358 }
359 }
360
Denis Vlasenko942e4292006-09-08 17:25:04 +0000361 change_identity(pw);
362 tmp = pw->pw_shell;
363 if (!tmp || !*tmp)
Glenn L McGrathdc4e75e2003-09-02 02:36:18 +0000364 tmp = DEFAULT_SHELL;
Denis Vlasenko66fabdb2006-09-17 14:45:09 +0000365 setup_environment(tmp, 1, !(opt & LOGIN_OPT_p), pw);
Robert Griebl1fca5582002-06-04 20:45:46 +0000366
Denis Vlasenko942e4292006-09-08 17:25:04 +0000367 motd();
Robert Griebl1fca5582002-06-04 20:45:46 +0000368
Denis Vlasenko942e4292006-09-08 17:25:04 +0000369 if (pw->pw_uid == 0)
Denis Vlasenko2f50aa42006-09-08 17:56:52 +0000370 syslog(LOG_INFO, "root login%s", fromhost);
Eric Andersen9e480452003-07-03 10:07:04 +0000371#ifdef CONFIG_SELINUX
Rob Landleyd1f8c1c2006-03-27 23:04:42 +0000372 /* well, a simple setexeccon() here would do the job as well,
373 * but let's play the game for now */
374 set_current_security_context(user_sid);
Eric Andersen9e480452003-07-03 10:07:04 +0000375#endif
Denis Vlasenko6ae80792006-10-31 17:34:44 +0000376
377 // util-linux login also does:
378 // /* start new session */
379 // setsid();
380 // /* TIOCSCTTY: steal tty from other process group */
381 // if (ioctl(0, TIOCSCTTY, 1)) error_msg...
382
Denis Vlasenko8c764872006-10-31 18:30:56 +0000383 /* set signals to defaults */
384 signal(SIGALRM, SIG_DFL);
385 /* Is this correct? This way user can ctrl-c out of /etc/profile,
386 * potentially creating security breach (tested with bash 3.0).
387 * But without this, bash 3.0 will not enable ctrl-c either.
388 * Maybe bash is buggy?
389 * Need to find out what standards say about /bin/login -
390 * should it leave SIGINT etc enabled or disabled? */
Denis Vlasenko6ae80792006-10-31 17:34:44 +0000391 signal(SIGINT, SIG_DFL);
392
393 run_shell(tmp, 1, 0, 0); /* exec the shell finally */
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000394
Robert Griebl1fca5582002-06-04 20:45:46 +0000395 return EXIT_FAILURE;
396}