Robert Griebl | 1fca558 | 2002-06-04 20:45:46 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
"Robert P. J. Day" | 801ab14 | 2006-07-12 07:56:04 +0000 | [diff] [blame] | 2 | /* |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 3 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
"Robert P. J. Day" | 801ab14 | 2006-07-12 07:56:04 +0000 | [diff] [blame] | 4 | */ |
Pere Orga | 6a3e01d | 2011-04-01 22:56:30 +0200 | [diff] [blame] | 5 | |
| 6 | //usage:#define login_trivial_usage |
| 7 | //usage: "[-p] [-h HOST] [[-f] USER]" |
| 8 | //usage:#define login_full_usage "\n\n" |
| 9 | //usage: "Begin a new session on the system\n" |
Pere Orga | 6a3e01d | 2011-04-01 22:56:30 +0200 | [diff] [blame] | 10 | //usage: "\n -f Don't authenticate (user already authenticated)" |
| 11 | //usage: "\n -h Name of the remote host" |
| 12 | //usage: "\n -p Preserve environment" |
| 13 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 14 | #include "libbb.h" |
Bernhard Reutner-Fischer | f470196 | 2008-01-27 12:50:12 +0000 | [diff] [blame] | 15 | #include <syslog.h> |
Robert Griebl | 1fca558 | 2002-06-04 20:45:46 +0000 | [diff] [blame] | 16 | #include <sys/resource.h> |
Eric Andersen | 27f64e1 | 2002-06-23 04:24:25 +0000 | [diff] [blame] | 17 | |
Denis Vlasenko | c0415a9 | 2007-03-24 17:04:07 +0000 | [diff] [blame] | 18 | #if ENABLE_SELINUX |
Denys Vlasenko | 37f5bef | 2010-04-05 03:18:40 +0200 | [diff] [blame] | 19 | # include <selinux/selinux.h> /* for is_selinux_enabled() */ |
| 20 | # include <selinux/get_context_list.h> /* for get_default_context() */ |
| 21 | # include <selinux/flask.h> /* for security class definitions */ |
Eric Andersen | 9e48045 | 2003-07-03 10:07:04 +0000 | [diff] [blame] | 22 | #endif |
Robert Griebl | 1fca558 | 2002-06-04 20:45:46 +0000 | [diff] [blame] | 23 | |
Denis Vlasenko | d6e81c7 | 2007-08-21 10:58:18 +0000 | [diff] [blame] | 24 | #if ENABLE_PAM |
Denis Vlasenko | c6c2345 | 2007-08-22 18:14:44 +0000 | [diff] [blame] | 25 | /* PAM may include <locale.h>. We may need to undefine bbox's stub define: */ |
Denys Vlasenko | 37f5bef | 2010-04-05 03:18:40 +0200 | [diff] [blame] | 26 | # undef setlocale |
Denis Vlasenko | c6c2345 | 2007-08-22 18:14:44 +0000 | [diff] [blame] | 27 | /* For some obscure reason, PAM is not in pam/xxx, but in security/xxx. |
| 28 | * Apparently they like to confuse people. */ |
Denys Vlasenko | 37f5bef | 2010-04-05 03:18:40 +0200 | [diff] [blame] | 29 | # include <security/pam_appl.h> |
| 30 | # include <security/pam_misc.h> |
Denis Vlasenko | d6e81c7 | 2007-08-21 10:58:18 +0000 | [diff] [blame] | 31 | static const struct pam_conv conv = { |
| 32 | misc_conv, |
| 33 | NULL |
| 34 | }; |
| 35 | #endif |
| 36 | |
Denis Vlasenko | 942e429 | 2006-09-08 17:25:04 +0000 | [diff] [blame] | 37 | enum { |
| 38 | TIMEOUT = 60, |
| 39 | EMPTY_USERNAME_COUNT = 10, |
Tanguy Pruvot | 823694d | 2012-11-18 13:20:29 +0100 | [diff] [blame] | 40 | /* Some users found 32 chars limit to be too low: */ |
| 41 | USERNAME_SIZE = 64, |
Denis Vlasenko | 9a9edf2 | 2006-09-08 17:29:53 +0000 | [diff] [blame] | 42 | TTYNAME_SIZE = 32, |
Denis Vlasenko | 942e429 | 2006-09-08 17:25:04 +0000 | [diff] [blame] | 43 | }; |
Eric Andersen | 0fbff13 | 2002-06-22 17:49:29 +0000 | [diff] [blame] | 44 | |
Tanguy Pruvot | 8a6c2c2 | 2012-04-28 00:24:09 +0200 | [diff] [blame] | 45 | struct globals { |
| 46 | struct termios tty_attrs; |
| 47 | } FIX_ALIASING; |
| 48 | #define G (*(struct globals*)&bb_common_bufsiz1) |
| 49 | #define INIT_G() do { } while (0) |
| 50 | |
Denis Vlasenko | 7ccf5cc | 2006-09-14 17:03:18 +0000 | [diff] [blame] | 51 | |
Denis Vlasenko | f312e32 | 2007-06-12 22:04:57 +0000 | [diff] [blame] | 52 | #if ENABLE_FEATURE_NOLOGIN |
Denis Vlasenko | 68404f1 | 2008-03-17 09:00:54 +0000 | [diff] [blame] | 53 | static void die_if_nologin(void) |
Denis Vlasenko | 7ccf5cc | 2006-09-14 17:03:18 +0000 | [diff] [blame] | 54 | { |
| 55 | FILE *fp; |
| 56 | int c; |
Denis Vlasenko | 694b514 | 2008-11-07 01:12:16 +0000 | [diff] [blame] | 57 | int empty = 1; |
Denis Vlasenko | 7ccf5cc | 2006-09-14 17:03:18 +0000 | [diff] [blame] | 58 | |
Denis Vlasenko | 5415c85 | 2008-07-21 23:05:26 +0000 | [diff] [blame] | 59 | fp = fopen_for_read("/etc/nologin"); |
Denis Vlasenko | 694b514 | 2008-11-07 01:12:16 +0000 | [diff] [blame] | 60 | if (!fp) /* assuming it does not exist */ |
| 61 | return; |
| 62 | |
| 63 | while ((c = getc(fp)) != EOF) { |
| 64 | if (c == '\n') |
| 65 | bb_putchar('\r'); |
| 66 | bb_putchar(c); |
| 67 | empty = 0; |
| 68 | } |
| 69 | if (empty) |
Denis Vlasenko | 7ccf5cc | 2006-09-14 17:03:18 +0000 | [diff] [blame] | 70 | puts("\r\nSystem closed for routine maintenance\r"); |
Denis Vlasenko | 694b514 | 2008-11-07 01:12:16 +0000 | [diff] [blame] | 71 | |
| 72 | fclose(fp); |
Denys Vlasenko | 8131eea | 2009-11-02 14:19:51 +0100 | [diff] [blame] | 73 | fflush_all(); |
Denis Vlasenko | 694b514 | 2008-11-07 01:12:16 +0000 | [diff] [blame] | 74 | /* Users say that they do need this prior to exit: */ |
| 75 | tcdrain(STDOUT_FILENO); |
Bernhard Reutner-Fischer | 636a1f8 | 2008-05-19 09:29:47 +0000 | [diff] [blame] | 76 | exit(EXIT_FAILURE); |
Denis Vlasenko | 7ccf5cc | 2006-09-14 17:03:18 +0000 | [diff] [blame] | 77 | } |
Denis Vlasenko | f312e32 | 2007-06-12 22:04:57 +0000 | [diff] [blame] | 78 | #else |
Denys Vlasenko | 37f5bef | 2010-04-05 03:18:40 +0200 | [diff] [blame] | 79 | # define die_if_nologin() ((void)0) |
Denis Vlasenko | f312e32 | 2007-06-12 22:04:57 +0000 | [diff] [blame] | 80 | #endif |
Robert Griebl | 1fca558 | 2002-06-04 20:45:46 +0000 | [diff] [blame] | 81 | |
Denis Vlasenko | d6e81c7 | 2007-08-21 10:58:18 +0000 | [diff] [blame] | 82 | #if ENABLE_FEATURE_SECURETTY && !ENABLE_PAM |
Tanguy Pruvot | 8a6c2c2 | 2012-04-28 00:24:09 +0200 | [diff] [blame] | 83 | static int check_securetty(const char *short_tty) |
Denis Vlasenko | 7ccf5cc | 2006-09-14 17:03:18 +0000 | [diff] [blame] | 84 | { |
Denis Vlasenko | 084266e | 2008-07-26 23:08:31 +0000 | [diff] [blame] | 85 | char *buf = (char*)"/etc/securetty"; /* any non-NULL is ok */ |
Denis Vlasenko | 5415c85 | 2008-07-21 23:05:26 +0000 | [diff] [blame] | 86 | parser_t *parser = config_open2("/etc/securetty", fopen_for_read); |
Denis Vlasenko | 084266e | 2008-07-26 23:08:31 +0000 | [diff] [blame] | 87 | while (config_read(parser, &buf, 1, 1, "# \t", PARSE_NORMAL)) { |
| 88 | if (strcmp(buf, short_tty) == 0) |
| 89 | break; |
| 90 | buf = NULL; |
Denis Vlasenko | 7ccf5cc | 2006-09-14 17:03:18 +0000 | [diff] [blame] | 91 | } |
Denis Vlasenko | 084266e | 2008-07-26 23:08:31 +0000 | [diff] [blame] | 92 | config_close(parser); |
| 93 | /* buf != NULL here if config file was not found, empty |
| 94 | * or line was found which equals short_tty */ |
| 95 | return buf != NULL; |
Denis Vlasenko | 7ccf5cc | 2006-09-14 17:03:18 +0000 | [diff] [blame] | 96 | } |
Robert Griebl | 1fca558 | 2002-06-04 20:45:46 +0000 | [diff] [blame] | 97 | #else |
Tanguy Pruvot | 8a6c2c2 | 2012-04-28 00:24:09 +0200 | [diff] [blame] | 98 | static ALWAYS_INLINE int check_securetty(const char *short_tty UNUSED_PARAM) { return 1; } |
Robert Griebl | 1fca558 | 2002-06-04 20:45:46 +0000 | [diff] [blame] | 99 | #endif |
| 100 | |
Denis Vlasenko | 4eff8ef | 2009-02-02 00:15:00 +0000 | [diff] [blame] | 101 | #if ENABLE_SELINUX |
| 102 | static void initselinux(char *username, char *full_tty, |
| 103 | security_context_t *user_sid) |
| 104 | { |
| 105 | security_context_t old_tty_sid, new_tty_sid; |
| 106 | |
| 107 | if (!is_selinux_enabled()) |
| 108 | return; |
| 109 | |
| 110 | if (get_default_context(username, NULL, user_sid)) { |
Denys Vlasenko | 6331cf0 | 2009-11-13 09:08:27 +0100 | [diff] [blame] | 111 | bb_error_msg_and_die("can't get SID for %s", username); |
Denis Vlasenko | 4eff8ef | 2009-02-02 00:15:00 +0000 | [diff] [blame] | 112 | } |
| 113 | if (getfilecon(full_tty, &old_tty_sid) < 0) { |
| 114 | bb_perror_msg_and_die("getfilecon(%s) failed", full_tty); |
| 115 | } |
Denis Vlasenko | 8e5de2a | 2009-02-24 17:10:24 +0000 | [diff] [blame] | 116 | if (security_compute_relabel(*user_sid, old_tty_sid, |
Denis Vlasenko | 4eff8ef | 2009-02-02 00:15:00 +0000 | [diff] [blame] | 117 | SECCLASS_CHR_FILE, &new_tty_sid) != 0) { |
| 118 | bb_perror_msg_and_die("security_change_sid(%s) failed", full_tty); |
| 119 | } |
| 120 | if (setfilecon(full_tty, new_tty_sid) != 0) { |
| 121 | bb_perror_msg_and_die("chsid(%s, %s) failed", full_tty, new_tty_sid); |
| 122 | } |
| 123 | } |
| 124 | #endif |
| 125 | |
| 126 | #if ENABLE_LOGIN_SCRIPTS |
| 127 | static void run_login_script(struct passwd *pw, char *full_tty) |
| 128 | { |
| 129 | char *t_argv[2]; |
| 130 | |
| 131 | t_argv[0] = getenv("LOGIN_PRE_SUID_SCRIPT"); |
| 132 | if (t_argv[0]) { |
| 133 | t_argv[1] = NULL; |
| 134 | xsetenv("LOGIN_TTY", full_tty); |
| 135 | xsetenv("LOGIN_USER", pw->pw_name); |
| 136 | xsetenv("LOGIN_UID", utoa(pw->pw_uid)); |
| 137 | xsetenv("LOGIN_GID", utoa(pw->pw_gid)); |
| 138 | xsetenv("LOGIN_SHELL", pw->pw_shell); |
Denys Vlasenko | e4dcba1 | 2010-10-28 18:57:19 +0200 | [diff] [blame] | 139 | spawn_and_wait(t_argv); /* NOMMU-friendly */ |
Denis Vlasenko | 4eff8ef | 2009-02-02 00:15:00 +0000 | [diff] [blame] | 140 | unsetenv("LOGIN_TTY"); |
| 141 | unsetenv("LOGIN_USER"); |
| 142 | unsetenv("LOGIN_UID"); |
| 143 | unsetenv("LOGIN_GID"); |
| 144 | unsetenv("LOGIN_SHELL"); |
| 145 | } |
| 146 | } |
| 147 | #else |
| 148 | void run_login_script(struct passwd *pw, char *full_tty); |
| 149 | #endif |
| 150 | |
Tanguy Pruvot | 8a6c2c2 | 2012-04-28 00:24:09 +0200 | [diff] [blame] | 151 | #if ENABLE_LOGIN_SESSION_AS_CHILD && ENABLE_PAM |
| 152 | static void login_pam_end(pam_handle_t *pamh) |
| 153 | { |
| 154 | int pamret; |
| 155 | |
| 156 | pamret = pam_setcred(pamh, PAM_DELETE_CRED); |
| 157 | if (pamret != PAM_SUCCESS) { |
| 158 | bb_error_msg("pam_%s failed: %s (%d)", "setcred", |
| 159 | pam_strerror(pamh, pamret), pamret); |
| 160 | } |
| 161 | pamret = pam_close_session(pamh, 0); |
| 162 | if (pamret != PAM_SUCCESS) { |
| 163 | bb_error_msg("pam_%s failed: %s (%d)", "close_session", |
| 164 | pam_strerror(pamh, pamret), pamret); |
| 165 | } |
| 166 | pamret = pam_end(pamh, pamret); |
| 167 | if (pamret != PAM_SUCCESS) { |
| 168 | bb_error_msg("pam_%s failed: %s (%d)", "end", |
| 169 | pam_strerror(pamh, pamret), pamret); |
| 170 | } |
| 171 | } |
| 172 | #endif /* ENABLE_PAM */ |
| 173 | |
Denis Vlasenko | 7ccf5cc | 2006-09-14 17:03:18 +0000 | [diff] [blame] | 174 | static void get_username_or_die(char *buf, int size_buf) |
| 175 | { |
| 176 | int c, cntdown; |
Denis Vlasenko | d8540f7 | 2007-06-14 07:53:06 +0000 | [diff] [blame] | 177 | |
Denis Vlasenko | 7ccf5cc | 2006-09-14 17:03:18 +0000 | [diff] [blame] | 178 | cntdown = EMPTY_USERNAME_COUNT; |
Denis Vlasenko | d8540f7 | 2007-06-14 07:53:06 +0000 | [diff] [blame] | 179 | prompt: |
Denis Vlasenko | 7ccf5cc | 2006-09-14 17:03:18 +0000 | [diff] [blame] | 180 | print_login_prompt(); |
Denis Vlasenko | d8540f7 | 2007-06-14 07:53:06 +0000 | [diff] [blame] | 181 | /* skip whitespace */ |
Denis Vlasenko | 7ccf5cc | 2006-09-14 17:03:18 +0000 | [diff] [blame] | 182 | do { |
| 183 | c = getchar(); |
Denys Vlasenko | f2cbb03 | 2009-10-23 03:16:08 +0200 | [diff] [blame] | 184 | if (c == EOF) |
| 185 | exit(EXIT_FAILURE); |
Denis Vlasenko | 7ccf5cc | 2006-09-14 17:03:18 +0000 | [diff] [blame] | 186 | if (c == '\n') { |
Denys Vlasenko | f2cbb03 | 2009-10-23 03:16:08 +0200 | [diff] [blame] | 187 | if (!--cntdown) |
| 188 | exit(EXIT_FAILURE); |
Denis Vlasenko | 7ccf5cc | 2006-09-14 17:03:18 +0000 | [diff] [blame] | 189 | goto prompt; |
| 190 | } |
Denys Vlasenko | f2cbb03 | 2009-10-23 03:16:08 +0200 | [diff] [blame] | 191 | } while (isspace(c)); /* maybe isblank? */ |
Denis Vlasenko | 7ccf5cc | 2006-09-14 17:03:18 +0000 | [diff] [blame] | 192 | |
| 193 | *buf++ = c; |
| 194 | if (!fgets(buf, size_buf-2, stdin)) |
Bernhard Reutner-Fischer | 636a1f8 | 2008-05-19 09:29:47 +0000 | [diff] [blame] | 195 | exit(EXIT_FAILURE); |
Denis Vlasenko | 7ccf5cc | 2006-09-14 17:03:18 +0000 | [diff] [blame] | 196 | if (!strchr(buf, '\n')) |
Bernhard Reutner-Fischer | 636a1f8 | 2008-05-19 09:29:47 +0000 | [diff] [blame] | 197 | exit(EXIT_FAILURE); |
Denys Vlasenko | f2cbb03 | 2009-10-23 03:16:08 +0200 | [diff] [blame] | 198 | while ((unsigned char)*buf > ' ') |
| 199 | buf++; |
Denis Vlasenko | 7ccf5cc | 2006-09-14 17:03:18 +0000 | [diff] [blame] | 200 | *buf = '\0'; |
| 201 | } |
| 202 | |
| 203 | static void motd(void) |
| 204 | { |
Denis Vlasenko | 0de3c55 | 2007-04-12 12:31:02 +0000 | [diff] [blame] | 205 | int fd; |
Denis Vlasenko | 7ccf5cc | 2006-09-14 17:03:18 +0000 | [diff] [blame] | 206 | |
Denis Vlasenko | 0de3c55 | 2007-04-12 12:31:02 +0000 | [diff] [blame] | 207 | fd = open(bb_path_motd_file, O_RDONLY); |
Denis Vlasenko | 5281630 | 2007-11-06 05:26:51 +0000 | [diff] [blame] | 208 | if (fd >= 0) { |
Denys Vlasenko | 8131eea | 2009-11-02 14:19:51 +0100 | [diff] [blame] | 209 | fflush_all(); |
Denis Vlasenko | 0de3c55 | 2007-04-12 12:31:02 +0000 | [diff] [blame] | 210 | bb_copyfd_eof(fd, STDOUT_FILENO); |
| 211 | close(fd); |
Denis Vlasenko | 7ccf5cc | 2006-09-14 17:03:18 +0000 | [diff] [blame] | 212 | } |
| 213 | } |
Robert Griebl | 1fca558 | 2002-06-04 20:45:46 +0000 | [diff] [blame] | 214 | |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 215 | static void alarm_handler(int sig UNUSED_PARAM) |
Robert Griebl | 1fca558 | 2002-06-04 20:45:46 +0000 | [diff] [blame] | 216 | { |
Tanguy Pruvot | 8a6c2c2 | 2012-04-28 00:24:09 +0200 | [diff] [blame] | 217 | /* This is the escape hatch! Poor serial line users and the like |
Denis Vlasenko | 2f50aa4 | 2006-09-08 17:56:52 +0000 | [diff] [blame] | 218 | * arrive here when their connection is broken. |
| 219 | * We don't want to block here */ |
Tanguy Pruvot | 8a6c2c2 | 2012-04-28 00:24:09 +0200 | [diff] [blame] | 220 | ndelay_on(STDOUT_FILENO); |
| 221 | /* Test for correct attr restoring: |
| 222 | * run "getty 0 -" from a shell, enter bogus username, stop at |
| 223 | * password prompt, let it time out. Without the tcsetattr below, |
| 224 | * when you are back at shell prompt, echo will be still off. |
| 225 | */ |
| 226 | tcsetattr_stdin_TCSANOW(&G.tty_attrs); |
| 227 | printf("\r\nLogin timed out after %u seconds\r\n", TIMEOUT); |
Denys Vlasenko | 8131eea | 2009-11-02 14:19:51 +0100 | [diff] [blame] | 228 | fflush_all(); |
Denis Vlasenko | 5281630 | 2007-11-06 05:26:51 +0000 | [diff] [blame] | 229 | /* unix API is brain damaged regarding O_NONBLOCK, |
| 230 | * we should undo it, or else we can affect other processes */ |
Tanguy Pruvot | 8a6c2c2 | 2012-04-28 00:24:09 +0200 | [diff] [blame] | 231 | ndelay_off(STDOUT_FILENO); |
Denis Vlasenko | 400d8bb | 2008-02-24 13:36:01 +0000 | [diff] [blame] | 232 | _exit(EXIT_SUCCESS); |
Robert Griebl | 1fca558 | 2002-06-04 20:45:46 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 235 | int login_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 236 | int login_main(int argc UNUSED_PARAM, char **argv) |
Robert Griebl | 1fca558 | 2002-06-04 20:45:46 +0000 | [diff] [blame] | 237 | { |
Denis Vlasenko | 66fabdb | 2006-09-17 14:45:09 +0000 | [diff] [blame] | 238 | enum { |
| 239 | LOGIN_OPT_f = (1<<0), |
| 240 | LOGIN_OPT_h = (1<<1), |
| 241 | LOGIN_OPT_p = (1<<2), |
| 242 | }; |
Denis Vlasenko | d6e81c7 | 2007-08-21 10:58:18 +0000 | [diff] [blame] | 243 | char *fromhost; |
Eric Andersen | 0fbff13 | 2002-06-22 17:49:29 +0000 | [diff] [blame] | 244 | char username[USERNAME_SIZE]; |
Denis Vlasenko | 2ec94a7 | 2008-11-07 12:59:31 +0000 | [diff] [blame] | 245 | int run_by_root; |
Denis Vlasenko | 67b23e6 | 2006-10-03 21:00:06 +0000 | [diff] [blame] | 246 | unsigned opt; |
Denis Vlasenko | 942e429 | 2006-09-08 17:25:04 +0000 | [diff] [blame] | 247 | int count = 0; |
Denis Vlasenko | 9a9edf2 | 2006-09-08 17:29:53 +0000 | [diff] [blame] | 248 | struct passwd *pw; |
Denys Vlasenko | 37f5bef | 2010-04-05 03:18:40 +0200 | [diff] [blame] | 249 | char *opt_host = NULL; |
Denis Vlasenko | cdf6277 | 2008-03-17 08:42:43 +0000 | [diff] [blame] | 250 | char *opt_user = opt_user; /* for compiler */ |
Denis Vlasenko | 512c8ae | 2009-02-02 00:15:57 +0000 | [diff] [blame] | 251 | char *full_tty; |
Tanguy Pruvot | 8a6c2c2 | 2012-04-28 00:24:09 +0200 | [diff] [blame] | 252 | char *short_tty; |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 253 | IF_SELINUX(security_context_t user_sid = NULL;) |
Denis Vlasenko | a29a5e4 | 2007-11-07 00:23:47 +0000 | [diff] [blame] | 254 | #if ENABLE_PAM |
| 255 | int pamret; |
| 256 | pam_handle_t *pamh; |
| 257 | const char *pamuser; |
| 258 | const char *failed_msg; |
| 259 | struct passwd pwdstruct; |
| 260 | char pwdbuf[256]; |
Ian Wienand | 260fb55 | 2010-12-20 11:33:38 -0800 | [diff] [blame] | 261 | char **pamenv; |
Denis Vlasenko | a29a5e4 | 2007-11-07 00:23:47 +0000 | [diff] [blame] | 262 | #endif |
Tanguy Pruvot | 8a6c2c2 | 2012-04-28 00:24:09 +0200 | [diff] [blame] | 263 | #if ENABLE_LOGIN_SESSION_AS_CHILD |
| 264 | pid_t child_pid; |
| 265 | #endif |
Robert Griebl | 1fca558 | 2002-06-04 20:45:46 +0000 | [diff] [blame] | 266 | |
Tanguy Pruvot | 8a6c2c2 | 2012-04-28 00:24:09 +0200 | [diff] [blame] | 267 | INIT_G(); |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 268 | |
Denis Vlasenko | 2ec94a7 | 2008-11-07 12:59:31 +0000 | [diff] [blame] | 269 | /* More of suid paranoia if called by non-root: */ |
| 270 | /* Clear dangerous stuff, set PATH */ |
| 271 | run_by_root = !sanitize_env_if_suid(); |
Denis Vlasenko | c9ca0a3 | 2008-02-18 11:08:33 +0000 | [diff] [blame] | 272 | |
Denis Vlasenko | 0de3c55 | 2007-04-12 12:31:02 +0000 | [diff] [blame] | 273 | /* Mandatory paranoia for suid applet: |
| 274 | * ensure that fd# 0,1,2 are opened (at least to /dev/null) |
| 275 | * and any extra open fd's are closed. |
| 276 | * (The name of the function is misleading. Not daemonizing here.) */ |
| 277 | bb_daemonize_or_rexec(DAEMON_ONLY_SANITIZE | DAEMON_CLOSE_EXTRA_FDS, NULL); |
| 278 | |
Tanguy Pruvot | 8a6c2c2 | 2012-04-28 00:24:09 +0200 | [diff] [blame] | 279 | username[0] = '\0'; |
Denis Vlasenko | fe7cd64 | 2007-08-18 15:32:12 +0000 | [diff] [blame] | 280 | opt = getopt32(argv, "f:h:p", &opt_user, &opt_host); |
Denis Vlasenko | 66fabdb | 2006-09-17 14:45:09 +0000 | [diff] [blame] | 281 | if (opt & LOGIN_OPT_f) { |
Denis Vlasenko | 2ec94a7 | 2008-11-07 12:59:31 +0000 | [diff] [blame] | 282 | if (!run_by_root) |
Denis Vlasenko | 66fabdb | 2006-09-17 14:45:09 +0000 | [diff] [blame] | 283 | bb_error_msg_and_die("-f is for root only"); |
Denis Vlasenko | 22f6dcb | 2006-09-26 16:31:01 +0000 | [diff] [blame] | 284 | safe_strncpy(username, opt_user, sizeof(username)); |
Robert Griebl | 1fca558 | 2002-06-04 20:45:46 +0000 | [diff] [blame] | 285 | } |
Denis Vlasenko | 1d42665 | 2008-03-17 09:09:09 +0000 | [diff] [blame] | 286 | argv += optind; |
| 287 | if (argv[0]) /* user from command line (getty) */ |
| 288 | safe_strncpy(username, argv[0], sizeof(username)); |
Robert Griebl | 1fca558 | 2002-06-04 20:45:46 +0000 | [diff] [blame] | 289 | |
Tanguy Pruvot | 8a6c2c2 | 2012-04-28 00:24:09 +0200 | [diff] [blame] | 290 | /* Save tty attributes - and by doing it, check that it's indeed a tty */ |
| 291 | if (tcgetattr(STDIN_FILENO, &G.tty_attrs) < 0 |
| 292 | || !isatty(STDOUT_FILENO) |
| 293 | /*|| !isatty(STDERR_FILENO) - no, guess some people might want to redirect this */ |
| 294 | ) { |
Denys Vlasenko | e4dcba1 | 2010-10-28 18:57:19 +0200 | [diff] [blame] | 295 | return EXIT_FAILURE; /* Must be a terminal */ |
Tanguy Pruvot | 8a6c2c2 | 2012-04-28 00:24:09 +0200 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | /* We install timeout handler only _after_ we saved G.tty_attrs */ |
| 299 | signal(SIGALRM, alarm_handler); |
| 300 | alarm(TIMEOUT); |
| 301 | |
| 302 | /* Find out and memorize our tty name */ |
Denis Vlasenko | 512c8ae | 2009-02-02 00:15:57 +0000 | [diff] [blame] | 303 | full_tty = xmalloc_ttyname(STDIN_FILENO); |
| 304 | if (!full_tty) |
| 305 | full_tty = xstrdup("UNKNOWN"); |
Denys Vlasenko | f8d8aa1 | 2010-04-06 18:50:05 +0200 | [diff] [blame] | 306 | short_tty = skip_dev_pfx(full_tty); |
Robert Griebl | 1fca558 | 2002-06-04 20:45:46 +0000 | [diff] [blame] | 307 | |
Denys Vlasenko | 37f5bef | 2010-04-05 03:18:40 +0200 | [diff] [blame] | 308 | if (opt_host) { |
Denis Vlasenko | d6e81c7 | 2007-08-21 10:58:18 +0000 | [diff] [blame] | 309 | fromhost = xasprintf(" on '%s' from '%s'", short_tty, opt_host); |
Denis Vlasenko | 4e12b1a | 2008-12-23 23:36:47 +0000 | [diff] [blame] | 310 | } else { |
Denis Vlasenko | d6e81c7 | 2007-08-21 10:58:18 +0000 | [diff] [blame] | 311 | fromhost = xasprintf(" on '%s'", short_tty); |
Denis Vlasenko | 4e12b1a | 2008-12-23 23:36:47 +0000 | [diff] [blame] | 312 | } |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 313 | |
Denis Vlasenko | d6e81c7 | 2007-08-21 10:58:18 +0000 | [diff] [blame] | 314 | /* Was breaking "login <username>" from shell command line: */ |
| 315 | /*bb_setpgrp();*/ |
Eric Andersen | 0fbff13 | 2002-06-22 17:49:29 +0000 | [diff] [blame] | 316 | |
Denis Vlasenko | 54ac03a | 2009-03-11 15:59:49 +0000 | [diff] [blame] | 317 | openlog(applet_name, LOG_PID | LOG_CONS, LOG_AUTH); |
Robert Griebl | 1fca558 | 2002-06-04 20:45:46 +0000 | [diff] [blame] | 318 | |
Denis Vlasenko | 942e429 | 2006-09-08 17:25:04 +0000 | [diff] [blame] | 319 | while (1) { |
Paul Fox | 6e1b62b | 2007-11-07 15:51:35 +0000 | [diff] [blame] | 320 | /* flush away any type-ahead (as getty does) */ |
Jeremie Koenig | f812eac | 2010-05-27 15:37:32 +0200 | [diff] [blame] | 321 | tcflush(0, TCIFLUSH); |
Paul Fox | 6e1b62b | 2007-11-07 15:51:35 +0000 | [diff] [blame] | 322 | |
Denis Vlasenko | 942e429 | 2006-09-08 17:25:04 +0000 | [diff] [blame] | 323 | if (!username[0]) |
Denis Vlasenko | 9a9edf2 | 2006-09-08 17:29:53 +0000 | [diff] [blame] | 324 | get_username_or_die(username, sizeof(username)); |
Robert Griebl | 1fca558 | 2002-06-04 20:45:46 +0000 | [diff] [blame] | 325 | |
Denis Vlasenko | d6e81c7 | 2007-08-21 10:58:18 +0000 | [diff] [blame] | 326 | #if ENABLE_PAM |
| 327 | pamret = pam_start("login", username, &conv, &pamh); |
| 328 | if (pamret != PAM_SUCCESS) { |
Denis Vlasenko | a29a5e4 | 2007-11-07 00:23:47 +0000 | [diff] [blame] | 329 | failed_msg = "start"; |
Denis Vlasenko | d6e81c7 | 2007-08-21 10:58:18 +0000 | [diff] [blame] | 330 | goto pam_auth_failed; |
| 331 | } |
| 332 | /* set TTY (so things like securetty work) */ |
| 333 | pamret = pam_set_item(pamh, PAM_TTY, short_tty); |
| 334 | if (pamret != PAM_SUCCESS) { |
Denis Vlasenko | a29a5e4 | 2007-11-07 00:23:47 +0000 | [diff] [blame] | 335 | failed_msg = "set_item(TTY)"; |
Denis Vlasenko | d6e81c7 | 2007-08-21 10:58:18 +0000 | [diff] [blame] | 336 | goto pam_auth_failed; |
| 337 | } |
Ryan Phillips | cf9074b | 2011-03-22 18:27:21 +0100 | [diff] [blame] | 338 | /* set RHOST */ |
| 339 | if (opt_host) { |
| 340 | pamret = pam_set_item(pamh, PAM_RHOST, opt_host); |
| 341 | if (pamret != PAM_SUCCESS) { |
| 342 | failed_msg = "set_item(RHOST)"; |
| 343 | goto pam_auth_failed; |
| 344 | } |
| 345 | } |
Tanguy Pruvot | 8a6c2c2 | 2012-04-28 00:24:09 +0200 | [diff] [blame] | 346 | if (!(opt & LOGIN_OPT_f)) { |
| 347 | pamret = pam_authenticate(pamh, 0); |
| 348 | if (pamret != PAM_SUCCESS) { |
| 349 | failed_msg = "authenticate"; |
| 350 | goto pam_auth_failed; |
| 351 | /* TODO: or just "goto auth_failed" |
| 352 | * since user seems to enter wrong password |
| 353 | * (in this case pamret == 7) |
| 354 | */ |
| 355 | } |
Denis Vlasenko | 82f3b16 | 2007-09-03 11:56:27 +0000 | [diff] [blame] | 356 | } |
| 357 | /* check that the account is healthy */ |
| 358 | pamret = pam_acct_mgmt(pamh, 0); |
| 359 | if (pamret != PAM_SUCCESS) { |
Denis Vlasenko | a29a5e4 | 2007-11-07 00:23:47 +0000 | [diff] [blame] | 360 | failed_msg = "acct_mgmt"; |
Denis Vlasenko | 82f3b16 | 2007-09-03 11:56:27 +0000 | [diff] [blame] | 361 | goto pam_auth_failed; |
| 362 | } |
| 363 | /* read user back */ |
Denis Vlasenko | a29a5e4 | 2007-11-07 00:23:47 +0000 | [diff] [blame] | 364 | pamuser = NULL; |
| 365 | /* gcc: "dereferencing type-punned pointer breaks aliasing rules..." |
| 366 | * thus we cast to (void*) */ |
| 367 | if (pam_get_item(pamh, PAM_USER, (void*)&pamuser) != PAM_SUCCESS) { |
| 368 | failed_msg = "get_item(USER)"; |
| 369 | goto pam_auth_failed; |
Denis Vlasenko | d6e81c7 | 2007-08-21 10:58:18 +0000 | [diff] [blame] | 370 | } |
Denis Vlasenko | a29a5e4 | 2007-11-07 00:23:47 +0000 | [diff] [blame] | 371 | if (!pamuser || !pamuser[0]) |
| 372 | goto auth_failed; |
| 373 | safe_strncpy(username, pamuser, sizeof(username)); |
| 374 | /* Don't use "pw = getpwnam(username);", |
| 375 | * PAM is said to be capable of destroying static storage |
| 376 | * used by getpwnam(). We are using safe(r) function */ |
| 377 | pw = NULL; |
| 378 | getpwnam_r(username, &pwdstruct, pwdbuf, sizeof(pwdbuf), &pw); |
| 379 | if (!pw) |
| 380 | goto auth_failed; |
| 381 | pamret = pam_open_session(pamh, 0); |
| 382 | if (pamret != PAM_SUCCESS) { |
| 383 | failed_msg = "open_session"; |
| 384 | goto pam_auth_failed; |
| 385 | } |
| 386 | pamret = pam_setcred(pamh, PAM_ESTABLISH_CRED); |
| 387 | if (pamret != PAM_SUCCESS) { |
| 388 | failed_msg = "setcred"; |
| 389 | goto pam_auth_failed; |
| 390 | } |
| 391 | break; /* success, continue login process */ |
| 392 | |
Denis Vlasenko | d6e81c7 | 2007-08-21 10:58:18 +0000 | [diff] [blame] | 393 | pam_auth_failed: |
Denys Vlasenko | c297ea9 | 2009-09-25 01:50:45 +0200 | [diff] [blame] | 394 | /* syslog, because we don't want potential attacker |
| 395 | * to know _why_ login failed */ |
| 396 | syslog(LOG_WARNING, "pam_%s call failed: %s (%d)", failed_msg, |
Denis Vlasenko | a29a5e4 | 2007-11-07 00:23:47 +0000 | [diff] [blame] | 397 | pam_strerror(pamh, pamret), pamret); |
Denis Vlasenko | d6e81c7 | 2007-08-21 10:58:18 +0000 | [diff] [blame] | 398 | safe_strncpy(username, "UNKNOWN", sizeof(username)); |
| 399 | #else /* not PAM */ |
Denis Vlasenko | 942e429 | 2006-09-08 17:25:04 +0000 | [diff] [blame] | 400 | pw = getpwnam(username); |
| 401 | if (!pw) { |
Denis Vlasenko | 65e14b4 | 2007-06-08 15:27:06 +0000 | [diff] [blame] | 402 | strcpy(username, "UNKNOWN"); |
| 403 | goto fake_it; |
Robert Griebl | 1fca558 | 2002-06-04 20:45:46 +0000 | [diff] [blame] | 404 | } |
| 405 | |
Denis Vlasenko | 9a9edf2 | 2006-09-08 17:29:53 +0000 | [diff] [blame] | 406 | if (pw->pw_passwd[0] == '!' || pw->pw_passwd[0] == '*') |
| 407 | goto auth_failed; |
| 408 | |
Denis Vlasenko | 66fabdb | 2006-09-17 14:45:09 +0000 | [diff] [blame] | 409 | if (opt & LOGIN_OPT_f) |
Denis Vlasenko | 9a9edf2 | 2006-09-08 17:29:53 +0000 | [diff] [blame] | 410 | break; /* -f USER: success without asking passwd */ |
| 411 | |
Tanguy Pruvot | 8a6c2c2 | 2012-04-28 00:24:09 +0200 | [diff] [blame] | 412 | if (pw->pw_uid == 0 && !check_securetty(short_tty)) |
Denis Vlasenko | 9a9edf2 | 2006-09-08 17:29:53 +0000 | [diff] [blame] | 413 | goto auth_failed; |
Robert Griebl | 1fca558 | 2002-06-04 20:45:46 +0000 | [diff] [blame] | 414 | |
| 415 | /* Don't check the password if password entry is empty (!) */ |
Denis Vlasenko | 942e429 | 2006-09-08 17:25:04 +0000 | [diff] [blame] | 416 | if (!pw->pw_passwd[0]) |
Denis Vlasenko | 66fabdb | 2006-09-17 14:45:09 +0000 | [diff] [blame] | 417 | break; |
Denis Vlasenko | 65e14b4 | 2007-06-08 15:27:06 +0000 | [diff] [blame] | 418 | fake_it: |
Tanguy Pruvot | 8a6c2c2 | 2012-04-28 00:24:09 +0200 | [diff] [blame] | 419 | /* Password reading and authorization takes place here. |
| 420 | * Note that reads (in no-echo mode) trash tty attributes. |
| 421 | * If we get interrupted by SIGALRM, we need to restore attrs. |
| 422 | */ |
Denis Vlasenko | 942e429 | 2006-09-08 17:25:04 +0000 | [diff] [blame] | 423 | if (correct_password(pw)) |
Denis Vlasenko | 66fabdb | 2006-09-17 14:45:09 +0000 | [diff] [blame] | 424 | break; |
Denis Vlasenko | d6e81c7 | 2007-08-21 10:58:18 +0000 | [diff] [blame] | 425 | #endif /* ENABLE_PAM */ |
Denis Vlasenko | 0de3c55 | 2007-04-12 12:31:02 +0000 | [diff] [blame] | 426 | auth_failed: |
Denis Vlasenko | 66fabdb | 2006-09-17 14:45:09 +0000 | [diff] [blame] | 427 | opt &= ~LOGIN_OPT_f; |
Denys Vlasenko | 7d4e7a2 | 2011-03-08 21:07:05 +0100 | [diff] [blame] | 428 | bb_do_delay(LOGIN_FAIL_DELAY); |
Denis Vlasenko | 82f3b16 | 2007-09-03 11:56:27 +0000 | [diff] [blame] | 429 | /* TODO: doesn't sound like correct English phrase to me */ |
Robert Griebl | 1fca558 | 2002-06-04 20:45:46 +0000 | [diff] [blame] | 430 | puts("Login incorrect"); |
Denis Vlasenko | 942e429 | 2006-09-08 17:25:04 +0000 | [diff] [blame] | 431 | if (++count == 3) { |
Denis Vlasenko | 89f0b34 | 2006-11-18 22:04:09 +0000 | [diff] [blame] | 432 | syslog(LOG_WARNING, "invalid password for '%s'%s", |
Denis Vlasenko | 9a9edf2 | 2006-09-08 17:29:53 +0000 | [diff] [blame] | 433 | username, fromhost); |
Alexander Shishkin | 78b286f | 2010-10-27 19:52:40 +0300 | [diff] [blame] | 434 | |
| 435 | if (ENABLE_FEATURE_CLEAN_UP) |
| 436 | free(fromhost); |
| 437 | |
Robert Griebl | 1fca558 | 2002-06-04 20:45:46 +0000 | [diff] [blame] | 438 | return EXIT_FAILURE; |
Denis Vlasenko | 942e429 | 2006-09-08 17:25:04 +0000 | [diff] [blame] | 439 | } |
Denis Vlasenko | 9a9edf2 | 2006-09-08 17:29:53 +0000 | [diff] [blame] | 440 | username[0] = '\0'; |
Denis Vlasenko | 2ec94a7 | 2008-11-07 12:59:31 +0000 | [diff] [blame] | 441 | } /* while (1) */ |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 442 | |
Denis Vlasenko | 942e429 | 2006-09-08 17:25:04 +0000 | [diff] [blame] | 443 | alarm(0); |
Denis Vlasenko | 2ec94a7 | 2008-11-07 12:59:31 +0000 | [diff] [blame] | 444 | /* We can ignore /etc/nologin if we are logging in as root, |
| 445 | * it doesn't matter whether we are run by root or not */ |
| 446 | if (pw->pw_uid != 0) |
Denis Vlasenko | 68404f1 | 2008-03-17 09:00:54 +0000 | [diff] [blame] | 447 | die_if_nologin(); |
Robert Griebl | 1fca558 | 2002-06-04 20:45:46 +0000 | [diff] [blame] | 448 | |
Tanguy Pruvot | 8a6c2c2 | 2012-04-28 00:24:09 +0200 | [diff] [blame] | 449 | #if ENABLE_LOGIN_SESSION_AS_CHILD |
| 450 | child_pid = vfork(); |
| 451 | if (child_pid != 0) { |
| 452 | if (child_pid < 0) |
| 453 | bb_perror_msg("vfork"); |
| 454 | else { |
| 455 | if (safe_waitpid(child_pid, NULL, 0) == -1) |
| 456 | bb_perror_msg("waitpid"); |
| 457 | update_utmp(child_pid, DEAD_PROCESS, NULL, NULL, NULL); |
| 458 | } |
| 459 | IF_PAM(login_pam_end(pamh);) |
| 460 | return 0; |
| 461 | } |
| 462 | #endif |
| 463 | |
| 464 | IF_SELINUX(initselinux(username, full_tty, &user_sid);) |
Rob Landley | 60158cb | 2005-05-03 06:25:50 +0000 | [diff] [blame] | 465 | |
Denis Vlasenko | 2f50aa4 | 2006-09-08 17:56:52 +0000 | [diff] [blame] | 466 | /* Try these, but don't complain if they fail. |
| 467 | * _f_chown is safe wrt race t=ttyname(0);...;chown(t); */ |
| 468 | fchown(0, pw->pw_uid, pw->pw_gid); |
| 469 | fchmod(0, 0600); |
Robert Griebl | 1fca558 | 2002-06-04 20:45:46 +0000 | [diff] [blame] | 470 | |
Denys Vlasenko | 3a41611 | 2010-04-05 22:10:38 +0200 | [diff] [blame] | 471 | update_utmp(getpid(), USER_PROCESS, short_tty, username, run_by_root ? opt_host : NULL); |
Denys Vlasenko | 37f5bef | 2010-04-05 03:18:40 +0200 | [diff] [blame] | 472 | |
Denis Vlasenko | 5281630 | 2007-11-06 05:26:51 +0000 | [diff] [blame] | 473 | /* We trust environment only if we run by root */ |
Denis Vlasenko | 3266aa9 | 2009-04-01 11:24:04 +0000 | [diff] [blame] | 474 | if (ENABLE_LOGIN_SCRIPTS && run_by_root) |
Denis Vlasenko | 4eff8ef | 2009-02-02 00:15:00 +0000 | [diff] [blame] | 475 | run_login_script(pw, full_tty); |
Denis Vlasenko | 2e50291 | 2006-09-08 17:22:45 +0000 | [diff] [blame] | 476 | |
Denis Vlasenko | 942e429 | 2006-09-08 17:25:04 +0000 | [diff] [blame] | 477 | change_identity(pw); |
Denys Vlasenko | bd74e3d | 2011-03-06 18:49:40 +0100 | [diff] [blame] | 478 | setup_environment(pw->pw_shell, |
Denys Vlasenko | fd686a2 | 2010-02-26 09:52:45 +0100 | [diff] [blame] | 479 | (!(opt & LOGIN_OPT_p) * SETUP_ENV_CLEARENV) + SETUP_ENV_CHANGEENV, |
| 480 | pw); |
Robert Griebl | 1fca558 | 2002-06-04 20:45:46 +0000 | [diff] [blame] | 481 | |
Ian Wienand | 260fb55 | 2010-12-20 11:33:38 -0800 | [diff] [blame] | 482 | #if ENABLE_PAM |
| 483 | /* Modules such as pam_env will setup the PAM environment, |
| 484 | * which should be copied into the new environment. */ |
| 485 | pamenv = pam_getenvlist(pamh); |
| 486 | if (pamenv) while (*pamenv) { |
| 487 | putenv(*pamenv); |
| 488 | pamenv++; |
| 489 | } |
| 490 | #endif |
| 491 | |
Denis Vlasenko | 942e429 | 2006-09-08 17:25:04 +0000 | [diff] [blame] | 492 | motd(); |
Robert Griebl | 1fca558 | 2002-06-04 20:45:46 +0000 | [diff] [blame] | 493 | |
Denis Vlasenko | 942e429 | 2006-09-08 17:25:04 +0000 | [diff] [blame] | 494 | if (pw->pw_uid == 0) |
Denis Vlasenko | 2f50aa4 | 2006-09-08 17:56:52 +0000 | [diff] [blame] | 495 | syslog(LOG_INFO, "root login%s", fromhost); |
Denis Vlasenko | 4eff8ef | 2009-02-02 00:15:00 +0000 | [diff] [blame] | 496 | |
Alexander Shishkin | 78b286f | 2010-10-27 19:52:40 +0300 | [diff] [blame] | 497 | if (ENABLE_FEATURE_CLEAN_UP) |
| 498 | free(fromhost); |
| 499 | |
Rob Landley | d1f8c1c | 2006-03-27 23:04:42 +0000 | [diff] [blame] | 500 | /* well, a simple setexeccon() here would do the job as well, |
| 501 | * but let's play the game for now */ |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 502 | IF_SELINUX(set_current_security_context(user_sid);) |
Denis Vlasenko | 6ae8079 | 2006-10-31 17:34:44 +0000 | [diff] [blame] | 503 | |
| 504 | // util-linux login also does: |
| 505 | // /* start new session */ |
| 506 | // setsid(); |
| 507 | // /* TIOCSCTTY: steal tty from other process group */ |
| 508 | // if (ioctl(0, TIOCSCTTY, 1)) error_msg... |
Denis Vlasenko | 0de3c55 | 2007-04-12 12:31:02 +0000 | [diff] [blame] | 509 | // BBox login used to do this (see above): |
| 510 | // bb_setpgrp(); |
| 511 | // If this stuff is really needed, add it and explain why! |
Denis Vlasenko | 6ae8079 | 2006-10-31 17:34:44 +0000 | [diff] [blame] | 512 | |
Denis Vlasenko | 2ec94a7 | 2008-11-07 12:59:31 +0000 | [diff] [blame] | 513 | /* Set signals to defaults */ |
Denis Vlasenko | 3fa36e2 | 2008-11-09 00:15:11 +0000 | [diff] [blame] | 514 | /* Non-ignored signals revert to SIG_DFL on exec anyway */ |
| 515 | /*signal(SIGALRM, SIG_DFL);*/ |
Denis Vlasenko | 2ec94a7 | 2008-11-07 12:59:31 +0000 | [diff] [blame] | 516 | |
Denis Vlasenko | 8c76487 | 2006-10-31 18:30:56 +0000 | [diff] [blame] | 517 | /* Is this correct? This way user can ctrl-c out of /etc/profile, |
| 518 | * potentially creating security breach (tested with bash 3.0). |
| 519 | * But without this, bash 3.0 will not enable ctrl-c either. |
| 520 | * Maybe bash is buggy? |
| 521 | * Need to find out what standards say about /bin/login - |
Denis Vlasenko | 2ec94a7 | 2008-11-07 12:59:31 +0000 | [diff] [blame] | 522 | * should we leave SIGINT etc enabled or disabled? */ |
Denis Vlasenko | 6ae8079 | 2006-10-31 17:34:44 +0000 | [diff] [blame] | 523 | signal(SIGINT, SIG_DFL); |
| 524 | |
Denis Vlasenko | a2f6101 | 2007-09-10 13:15:28 +0000 | [diff] [blame] | 525 | /* Exec login shell with no additional parameters */ |
Denys Vlasenko | bd74e3d | 2011-03-06 18:49:40 +0100 | [diff] [blame] | 526 | run_shell(pw->pw_shell, 1, NULL, NULL); |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 527 | |
Denis Vlasenko | a2f6101 | 2007-09-10 13:15:28 +0000 | [diff] [blame] | 528 | /* return EXIT_FAILURE; - not reached */ |
Robert Griebl | 1fca558 | 2002-06-04 20:45:46 +0000 | [diff] [blame] | 529 | } |