// login defines
-#define DEFAULT_USER "UNKNOWN"
-#define DEFAULT_PWD "!"
-#define DEFAULT_SHELL "/bin/sh"
#define TIMEOUT 60
#define FAIL_DELAY 3
+#define EMPTY_USERNAME_COUNT 10
#define MOTD_FILE "/etc/motd"
#define NOLOGIN_FILE "/etc/nologin"
#define SECURETTY_FILE "/etc/securetty"
+#define USERNAME_SIZE 32
+
/* Stuff global to this file */
struct utmp utent;
#endif
static int is_my_tty ( const char *tty );
-static const char *login_prompt ( void );
+static int login_prompt ( char *buf_name );
static void motd ( void );
-static void set_env(int argc, char *const *argv);
static void alarm_handler ( int sig )
{
- error_msg ( "\nLogin timed out after %d seconds.\n", TIMEOUT );
+ fprintf (stderr, "\nLogin timed out after %d seconds.\n", TIMEOUT );
exit ( EXIT_SUCCESS );
}
char tty[BUFSIZ];
char full_tty[200];
char fromhost[512];
+ char username[USERNAME_SIZE];
char *tmp;
int amroot;
int flag;
int opt_preserve = 0;
int opt_fflag = 0;
char *opt_host = 0;
- const char *username = 0;
int alarmstarted = 0;
+ username[0]=0;
amroot = ( getuid ( ) == 0 );
signal ( SIGALRM, alarm_handler );
while (( flag = getopt(argc, argv, "f:h:p")) != EOF ) {
switch ( flag ) {
case 'p':
- printf ( "PRESERVE\n" );
opt_preserve = 1;
break;
case 'f':
show_usage ( );
if ( !amroot ) /* Auth bypass only if real UID is zero */
- error_msg_and_die ( "login: -f permission denied\n" );
-
- printf ( "USERNAME: %s\n", optarg );
+ error_msg_and_die ( "-f permission denied" );
- username = optarg;
+ safe_strncpy(username, optarg, USERNAME_SIZE);
opt_fflag = 1;
break;
case 'h':
}
}
- if ( optind < argc ) // got a username
- username = argv [optind++];
+ if (optind < argc) // user from command line (getty)
+ safe_strncpy(username, argv[optind], USERNAME_SIZE);
if ( !isatty ( 0 ) || !isatty ( 1 ) || !isatty ( 2 ))
return EXIT_FAILURE; /* Must be a terminal */
else
snprintf ( fromhost, sizeof( fromhost ) - 1, " on `%.100s'", tty );
+ setpgrp();
+
openlog ( "login", LOG_PID | LOG_CONS | LOG_NOWAIT, LOG_AUTH );
while ( 1 ) {
failed = 0;
- if ( !username || !username[0] )
- username = login_prompt ( );
+ if ( !username[0] )
+ if(!login_prompt ( username ))
+ return EXIT_FAILURE;
if ( !alarmstarted && ( TIMEOUT > 0 )) {
alarm ( TIMEOUT );
}
if (!( pw = getpwnam ( username ))) {
- pw_copy. pw_name = DEFAULT_USER;
- pw_copy. pw_passwd = DEFAULT_PWD;
- pw_copy. pw_shell = DEFAULT_SHELL;
+ pw_copy.pw_name = "UNKNOWN";
+ pw_copy.pw_passwd = "!";
opt_fflag = 0;
failed = 1;
} else
goto auth_ok;
}
- if (( pw-> pw_uid == 0 ) && ( !check_tty ( tty )))
+ if (!failed && ( pw-> pw_uid == 0 ) && ( !check_tty ( tty )))
failed = 1;
/* Don't check the password if password entry is empty (!) */
if ( correct_password ( pw ))
goto auth_ok;
- syslog ( LOG_WARNING, "invalid password for `%s'%s\n", pw-> pw_name, fromhost);
failed = 1;
auth_ok:
}
puts("Login incorrect");
- if ( ++count == 3 )
+ username[0] = 0;
+ if ( ++count == 3 ) {
+ syslog ( LOG_WARNING, "invalid password for `%s'%s\n", pw->pw_name, fromhost);
return EXIT_FAILURE;
}
+ }
alarm ( 0 );
if ( check_nologin ( pw-> pw_uid == 0 ))
-static const char *login_prompt ( void )
+static int login_prompt ( char *buf_name )
{
char buf [1024];
char *sp, *ep;
+ int i;
+ for(i=0; i<EMPTY_USERNAME_COUNT; i++) {
gethostname ( buf, sizeof( buf ));
printf ( "\nBusyBox on %s login: ", buf );
fflush ( stdout );
if ( !fgets ( buf, sizeof( buf ) - 1, stdin ))
return 0;
- if ( !strchr ( buf, '\n' ));
+ if ( !strchr ( buf, '\n' ))
return 0;
for ( sp = buf; isspace ( *sp ); sp++ ) { }
for ( ep = sp; isgraph ( *ep ); ep++ ) { }
*ep = 0;
- return sp;
+ safe_strncpy(buf_name, sp, USERNAME_SIZE);
+ if(buf_name[0])
+ return 1;
+ }
+ return 0;
}