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