use %p when printing pointers, not %x
[oweals/busybox.git] / loginutils / login.c
index 21e807615ca3cbeae59d2db564a13a4d3f905167..277fc98ee19a16f1a69d3bdede46fdd18f4147cf 100644 (file)
@@ -52,14 +52,14 @@ static int login_prompt ( char *buf_name );
 static void motd ( void );
 
 
-static void alarm_handler ( int sig )
+static void alarm_handler ( int sig ATTRIBUTE_UNUSED)
 {
        fprintf (stderr, "\nLogin timed out after %d seconds.\n", TIMEOUT );
        exit ( EXIT_SUCCESS );
 }
 
 
-extern int login_main(int argc, char **argv)
+int login_main(int argc, char **argv)
 {
        char tty[BUFSIZ];
        char full_tty[200];
@@ -79,7 +79,7 @@ extern int login_main(int argc, char **argv)
        char *opt_host = 0;
        int alarmstarted = 0;
 #ifdef CONFIG_SELINUX
-       security_context_t stat_sid = NULL, sid = NULL, old_tty_sid=NULL, new_tty_sid=NULL;
+       security_context_t user_sid = NULL;
 #endif
 
        username[0]=0;
@@ -101,7 +101,7 @@ extern int login_main(int argc, char **argv)
                        if ( optarg != argv[optind-1] )
                                bb_show_usage( );
 
-                       if ( !amroot )          /* Auth bypass only if real UID is zero */
+                       if ( !amroot )          /* Auth bypass only if real UID is zero */
                                bb_error_msg_and_die ( "-f permission denied" );
 
                        safe_strncpy(username, optarg, USERNAME_SIZE);
@@ -223,22 +223,19 @@ auth_ok:
 #ifdef CONFIG_SELINUX
        if (is_selinux_enabled())
        {
-               struct stat st;
-               int rc;
+               security_context_t old_tty_sid, new_tty_sid;
 
-               if (get_default_context(username, NULL, &sid))
+               if (get_default_context(username, NULL, &user_sid))
                {
                        fprintf(stderr, "Unable to get SID for %s\n", username);
                        exit(1);
                }
-               rc = getfilecon(full_tty,&stat_sid);
-               freecon(stat_sid);
-               if ((rc<0) || (stat(full_tty, &st)<0))
+               if (getfilecon(full_tty, &old_tty_sid) < 0)
                {
-                       fprintf(stderr, "stat_secure(%.100s) failed: %.100s\n", full_tty, strerror(errno));
+                       fprintf(stderr, "getfilecon(%.100s) failed: %.100s\n", full_tty, strerror(errno));
                        return EXIT_FAILURE;
                }
-               if (security_compute_relabel (sid, old_tty_sid, SECCLASS_CHR_FILE, &new_tty_sid) != 0)
+               if (security_compute_relabel(user_sid, old_tty_sid, SECCLASS_CHR_FILE, &new_tty_sid) != 0)
                {
                        fprintf(stderr, "security_change_sid(%.100s) failed: %.100s\n", full_tty, strerror(errno));
                        return EXIT_FAILURE;
@@ -248,9 +245,6 @@ auth_ok:
                        fprintf(stderr, "chsid(%.100s, %s) failed: %.100s\n", full_tty, new_tty_sid, strerror(errno));
                        return EXIT_FAILURE;
                }
-               freecon(sid);
-               freecon(old_tty_sid);
-               freecon(new_tty_sid);
        }
 #endif
        if ( !is_my_tty ( full_tty ))
@@ -273,7 +267,9 @@ auth_ok:
        if ( pw-> pw_uid == 0 )
                syslog ( LOG_INFO, "root login %s\n", fromhost );
 #ifdef CONFIG_SELINUX
-       set_current_security_context(sid);
+       /* well, a simple setexeccon() here would do the job as well,
+        * but let's play the game for now */
+       set_current_security_context(user_sid);
 #endif
        run_shell ( tmp, 1, 0, 0);      /* exec the shell finally. */
 
@@ -432,6 +428,8 @@ static void checkutmp(int picky)
        if (ut) {
                utent = *ut;
        } else {
+               time_t t_tmp;
+               
                if (picky) {
                        puts(NO_UTENT);
                        exit(1);
@@ -450,7 +448,8 @@ static void checkutmp(int picky)
                /* XXX - assumes /dev/tty?? */
                strncpy(utent.ut_id, utent.ut_line + 3, sizeof utent.ut_id);
                strncpy(utent.ut_user, "LOGIN", sizeof utent.ut_user);
-               time(&utent.ut_time);
+               t_tmp = (time_t)utent.ut_time;
+               time(&t_tmp);
        }
 }
 
@@ -461,11 +460,13 @@ static void checkutmp(int picky)
  *     USER_PROCESS.  the wtmp file will be updated as well.
  */
 
-static void setutmp(const char *name, const char *line)
+static void setutmp(const char *name, const char *line ATTRIBUTE_UNUSED)
 {
+       time_t t_tmp = (time_t)utent.ut_time;
+       
        utent.ut_type = USER_PROCESS;
        strncpy(utent.ut_user, name, sizeof utent.ut_user);
-       time(&utent.ut_time);
+       time(&t_tmp);
        /* other fields already filled in by checkutmp above */
        setutent();
        pututline(&utent);