-#ifdef CONFIG_FEATURE_U_W_TMP
- if ( amroot )
- memset ( utent.ut_host, 0, sizeof utent.ut_host );
-#endif
-
- if ( opt_host ) {
-#ifdef CONFIG_FEATURE_U_W_TMP
- safe_strncpy ( utent.ut_host, opt_host, sizeof( utent. ut_host ));
-#endif
- snprintf ( fromhost, sizeof( fromhost ) - 1, " on `%.100s' from `%.200s'", tty, opt_host );
+int login_main(int argc, char **argv);
+int login_main(int argc, char **argv)
+{
+ enum {
+ LOGIN_OPT_f = (1<<0),
+ LOGIN_OPT_h = (1<<1),
+ LOGIN_OPT_p = (1<<2),
+ };
+ char fromhost[512];
+ char username[USERNAME_SIZE];
+ const char *tmp;
+ int amroot;
+ unsigned opt;
+ int count = 0;
+ struct passwd *pw;
+ char *opt_host = NULL;
+ char *opt_user = NULL;
+ char full_tty[TTYNAME_SIZE];
+ USE_SELINUX(security_context_t user_sid = NULL;)
+ USE_FEATURE_UTMP(struct utmp utent;)
+
+ short_tty = full_tty;
+ username[0] = '\0';
+ amroot = (getuid() == 0);
+ signal(SIGALRM, alarm_handler);
+ alarm(TIMEOUT);
+
+ opt = getopt32(argc, argv, "f:h:p", &opt_user, &opt_host);
+ if (opt & LOGIN_OPT_f) {
+ if (!amroot)
+ bb_error_msg_and_die("-f is for root only");
+ safe_strncpy(username, opt_user, sizeof(username));
+ }
+ if (optind < argc) /* user from command line (getty) */
+ safe_strncpy(username, argv[optind], sizeof(username));
+
+ /* Let's find out and memorize our tty */
+ if (!isatty(0) || !isatty(1) || !isatty(2))
+ return EXIT_FAILURE; /* Must be a terminal */
+ safe_strncpy(full_tty, "UNKNOWN", sizeof(full_tty));
+ tmp = ttyname(0);
+ if (tmp) {
+ safe_strncpy(full_tty, tmp, sizeof(full_tty));
+ if (strncmp(full_tty, "/dev/", 5) == 0)
+ short_tty = full_tty + 5;