Ahem: add new faq entry to list at top of FAQ.html
[oweals/busybox.git] / loginutils / vlock.c
index a26999f895f648aefb6de39ada645b71efec8616..b66a3b1ae162ab4faa916412bd2e0e15336904b4 100644 (file)
@@ -29,6 +29,7 @@
  * It now works with md5, sha1, etc passwords. */
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <sys/vt.h>
 #include <signal.h>
 #include <string.h>
 #include "busybox.h"
 
 static struct passwd *pw;
-static struct spwd *spw;
 static struct vt_mode ovtm;
 static struct termios oterm;
 static int vfd;
 static int o_lock_all = 0;
 
+#ifdef CONFIG_FEATURE_SHADOWPASSWDS
+static struct spwd *spw;
+
 /* getspuid - get a shadow entry by uid */
-struct spwd *getspuid(uid_t uid)
+static struct spwd *getspuid(uid_t uid)
 {
        struct spwd *sp;
        struct passwd *mypw;
@@ -64,6 +67,7 @@ struct spwd *getspuid(uid_t uid)
        endspent();
        return (sp);
 }
+#endif
 
 static void release_vt(int signo)
 {
@@ -93,26 +97,26 @@ extern int vlock_main(int argc, char **argv)
        struct termios term;
 
        if (argc > 2) {
-               show_usage();
+               bb_show_usage();
        }
 
        if (argc == 2) {
                if (strncmp(argv[1], "-a", 2)) {
-                       show_usage();
+                       bb_show_usage();
                } else {
                        o_lock_all = 1;
                }
        }
 
        if ((pw = getpwuid(getuid())) == NULL) {
-               error_msg_and_die("no password for uid %d\n", getuid());
+               bb_error_msg_and_die("no password for uid %d\n", getuid());
        }
 #ifdef CONFIG_FEATURE_SHADOWPASSWDS
        if ((strcmp(pw->pw_passwd, "x") == 0)
                || (strcmp(pw->pw_passwd, "*") == 0)) {
 
                if ((spw = getspuid(getuid())) == NULL) {
-                       error_msg_and_die("could not read shadow password for uid %d: %s\n",
+                       bb_error_msg_and_die("could not read shadow password for uid %d: %s\n",
                                           getuid(), strerror(errno));
                }
                if (spw->sp_pwdp) {
@@ -121,7 +125,7 @@ extern int vlock_main(int argc, char **argv)
        }
 #endif                                                 /* CONFIG_FEATURE_SHADOWPASSWDS */
        if (pw->pw_passwd[0] == '!' || pw->pw_passwd[0] == '*') {
-               error_msg_and_die("Account disabled for uid %d\n", getuid());
+               bb_error_msg_and_die("Account disabled for uid %d\n", getuid());
        }
 
        /* we no longer need root privs */
@@ -129,11 +133,11 @@ extern int vlock_main(int argc, char **argv)
        setgid(getgid());
 
        if ((vfd = open("/dev/tty", O_RDWR)) < 0) {
-               error_msg_and_die("/dev/tty");
+               bb_error_msg_and_die("/dev/tty");
        };
 
        if (ioctl(vfd, VT_GETMODE, &vtm) < 0) {
-               error_msg_and_die("/dev/tty");
+               bb_error_msg_and_die("/dev/tty");
        };
 
        /* mask a bunch of signals */
@@ -189,10 +193,9 @@ extern int vlock_main(int argc, char **argv)
 
                snprintf(prompt, 100, "%s's password: ", pw->pw_name);
 
-               if ((pass = getpass(prompt)) == NULL) {
-                       perror("getpass");
+               if ((pass = bb_askpass(0, prompt)) == NULL) {
                        restore_terminal();
-                       exit(1);
+                       bb_perror_msg_and_die("password");
                }
 
                crypt_pass = pw_encrypt(pass, pw->pw_passwd);
@@ -206,9 +209,8 @@ extern int vlock_main(int argc, char **argv)
                memset(crypt_pass, 0, strlen(crypt_pass));
 
                if (isatty(STDIN_FILENO) == 0) {
-                       perror("isatty");
                        restore_terminal();
-                       exit(1);
+                       bb_perror_msg_and_die("isatty");
                }
 
                sleep(++times);