aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2005-12-19 02:50:10 +0000
committerRob Landley <rob@landley.net>2005-12-19 02:50:10 +0000
commit68eb9dd371b61b22420bc5c6849915560cf855b7 (patch)
tree2b2c9be78aa27f985c2059f78fde6fc777fbaad8
parent553d83d427741a13e7e66be0aa903c3edceb5823 (diff)
downloadbusybox-w32-68eb9dd371b61b22420bc5c6849915560cf855b7.tar.gz
busybox-w32-68eb9dd371b61b22420bc5c6849915560cf855b7.tar.bz2
busybox-w32-68eb9dd371b61b22420bc5c6849915560cf855b7.zip
Patch from Tito to make vlock much smaller.
-rw-r--r--loginutils/vlock.c108
1 files changed, 14 insertions, 94 deletions
diff --git a/loginutils/vlock.c b/loginutils/vlock.c
index b15b0ace0..141767c93 100644
--- a/loginutils/vlock.c
+++ b/loginutils/vlock.c
@@ -45,29 +45,7 @@ static struct passwd *pw;
45static struct vt_mode ovtm; 45static struct vt_mode ovtm;
46static struct termios oterm; 46static struct termios oterm;
47static int vfd; 47static int vfd;
48static int o_lock_all = 0; 48static unsigned long o_lock_all;
49
50#ifdef CONFIG_FEATURE_SHADOWPASSWDS
51static struct spwd *spw;
52
53/* getspuid - get a shadow entry by uid */
54static struct spwd *getspuid(uid_t uid)
55{
56 struct spwd *sp;
57 struct passwd *mypw;
58
59 if ((mypw = getpwuid(getuid())) == NULL) {
60 return (NULL);
61 }
62 setspent();
63 while ((sp = getspent()) != NULL) {
64 if (strcmp(mypw->pw_name, sp->sp_namp) == 0)
65 break;
66 }
67 endspent();
68 return (sp);
69}
70#endif
71 49
72static void release_vt(int signo) 50static void release_vt(int signo)
73{ 51{
@@ -93,52 +71,23 @@ extern int vlock_main(int argc, char **argv)
93 sigset_t sig; 71 sigset_t sig;
94 struct sigaction sa; 72 struct sigaction sa;
95 struct vt_mode vtm; 73 struct vt_mode vtm;
96 int times = 0;
97 struct termios term; 74 struct termios term;
98 75
99 if (argc > 2) { 76 if (argc > 2) {
100 bb_show_usage(); 77 bb_show_usage();
101 } 78 }
102 79
103 if (argc == 2) { 80 o_lock_all = bb_getopt_ulflags (argc, argv, "a");
104 if (strcmp(argv[1], "-a")) {
105 bb_show_usage();
106 } else {
107 o_lock_all = 1;
108 }
109 }
110 81
111 if ((pw = getpwuid(getuid())) == NULL) { 82 if((pw = getpwuid(getuid())) == NULL) {
112 bb_error_msg_and_die("no password for uid %d\n", getuid()); 83 bb_error_msg_and_die("Unknown uid %d", getuid());
113 }
114#ifdef CONFIG_FEATURE_SHADOWPASSWDS
115 if ((strcmp(pw->pw_passwd, "x") == 0)
116 || (strcmp(pw->pw_passwd, "*") == 0)) {
117
118 if ((spw = getspuid(getuid())) == NULL) {
119 bb_error_msg_and_die("could not read shadow password for uid %d: %s\n",
120 getuid(), strerror(errno));
121 }
122 if (spw->sp_pwdp) {
123 pw->pw_passwd = spw->sp_pwdp;
124 }
125 } 84 }
126#endif /* CONFIG_FEATURE_SHADOWPASSWDS */
127 if (pw->pw_passwd[0] == '!' || pw->pw_passwd[0] == '*') {
128 bb_error_msg_and_die("Account disabled for uid %d\n", getuid());
129 }
130
131 /* we no longer need root privs */
132 setuid(getuid());
133 setgid(getgid());
134 85
135 if ((vfd = open("/dev/tty", O_RDWR)) < 0) { 86 vfd = bb_xopen(CURRENT_TTY, O_RDWR);
136 bb_error_msg_and_die("/dev/tty");
137 };
138 87
139 if (ioctl(vfd, VT_GETMODE, &vtm) < 0) { 88 if (ioctl(vfd, VT_GETMODE, &vtm) < 0) {
140 bb_error_msg_and_die("/dev/tty"); 89 bb_perror_msg_and_die("VT_GETMODE");
141 }; 90 }
142 91
143 /* mask a bunch of signals */ 92 /* mask a bunch of signals */
144 sigprocmask(SIG_SETMASK, NULL, &sig); 93 sigprocmask(SIG_SETMASK, NULL, &sig);
@@ -181,45 +130,16 @@ extern int vlock_main(int argc, char **argv)
181 tcsetattr(STDIN_FILENO, TCSANOW, &term); 130 tcsetattr(STDIN_FILENO, TCSANOW, &term);
182 131
183 do { 132 do {
184 char *pass, *crypt_pass; 133 printf("Virtual Console%s locked.\n%s's ", (o_lock_all) ? "s" : "", pw->pw_name);
185 char prompt[100];
186
187 if (o_lock_all) {
188 printf("All Virtual Consoles locked.\n");
189 } else {
190 printf("This Virtual Console locked.\n");
191 }
192 fflush(stdout); 134 fflush(stdout);
193 135 if (correct_password (pw)) {
194 snprintf(prompt, 100, "%s's password: ", pw->pw_name); 136 break;
195
196 if ((pass = bb_askpass(0, prompt)) == NULL) {
197 restore_terminal();
198 bb_perror_msg_and_die("password");
199 }
200
201 crypt_pass = pw_encrypt(pass, pw->pw_passwd);
202 if (strcmp(crypt_pass, pw->pw_passwd) == 0) {
203 memset(pass, 0, strlen(pass));
204 memset(crypt_pass, 0, strlen(crypt_pass));
205 restore_terminal();
206 return 0;
207 }
208 memset(pass, 0, strlen(pass));
209 memset(crypt_pass, 0, strlen(crypt_pass));
210
211 if (isatty(STDIN_FILENO) == 0) {
212 restore_terminal();
213 bb_perror_msg_and_die("isatty");
214 }
215
216 sleep(++times);
217 printf("Password incorrect.\n");
218 if (times >= 3) {
219 sleep(15);
220 times = 2;
221 } 137 }
138 sleep(10);
139 puts("Password incorrect.");
222 } while (1); 140 } while (1);
141 restore_terminal();
142 return 0;
223} 143}
224 144
225/* 145/*