diff options
author | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2004-05-01 01:27:30 +0000 |
---|---|---|
committer | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2004-05-01 01:27:30 +0000 |
commit | 8d859aac9cf9066bb763cf3d3c4d508e060d6472 (patch) | |
tree | c8d14b02f851c42acde95b53c77527e5461c885b | |
parent | 3ea55efd82b6f4cb283c3038b9832d87877e3dde (diff) | |
download | busybox-w32-8d859aac9cf9066bb763cf3d3c4d508e060d6472.tar.gz busybox-w32-8d859aac9cf9066bb763cf3d3c4d508e060d6472.tar.bz2 busybox-w32-8d859aac9cf9066bb763cf3d3c4d508e060d6472.zip |
Do not use getpass(3)
git-svn-id: svn://busybox.net/trunk/busybox@8793 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | include/libbb.h | 1 | ||||
-rw-r--r-- | libbb/Makefile.in | 2 | ||||
-rw-r--r-- | libbb/bb_askpass.c | 87 | ||||
-rw-r--r-- | libbb/correct_password.c | 4 | ||||
-rw-r--r-- | loginutils/passwd.c | 6 | ||||
-rw-r--r-- | loginutils/sulogin.c | 28 | ||||
-rw-r--r-- | loginutils/vlock.c | 8 |
7 files changed, 98 insertions, 38 deletions
diff --git a/include/libbb.h b/include/libbb.h index a01a0ca3e..b65043cf3 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -233,6 +233,7 @@ extern long my_getgrnam(const char *name); | |||
233 | extern char * my_getpwuid(char *name, long uid); | 233 | extern char * my_getpwuid(char *name, long uid); |
234 | extern char * my_getgrgid(char *group, long gid); | 234 | extern char * my_getgrgid(char *group, long gid); |
235 | extern long my_getpwnamegid(const char *name); | 235 | extern long my_getpwnamegid(const char *name); |
236 | extern char *bb_askpass(int timeout, const char * prompt); | ||
236 | 237 | ||
237 | extern int device_open(const char *device, int mode); | 238 | extern int device_open(const char *device, int mode); |
238 | 239 | ||
diff --git a/libbb/Makefile.in b/libbb/Makefile.in index 632208184..eff3224b1 100644 --- a/libbb/Makefile.in +++ b/libbb/Makefile.in | |||
@@ -46,7 +46,7 @@ LIBBB_SRC:= \ | |||
46 | xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \ | 46 | xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \ |
47 | get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \ | 47 | get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \ |
48 | getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \ | 48 | getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \ |
49 | perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c \ | 49 | perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c bb_askpass.c \ |
50 | warn_ignoring_args.c concat_subpath_file.c vfork_daemon_rexec.c | 50 | warn_ignoring_args.c concat_subpath_file.c vfork_daemon_rexec.c |
51 | 51 | ||
52 | LIBBB_OBJS=$(patsubst %.c,$(LIBBB_DIR)%.o, $(LIBBB_SRC)) | 52 | LIBBB_OBJS=$(patsubst %.c,$(LIBBB_DIR)%.o, $(LIBBB_SRC)) |
diff --git a/libbb/bb_askpass.c b/libbb/bb_askpass.c new file mode 100644 index 000000000..1ae1520d9 --- /dev/null +++ b/libbb/bb_askpass.c | |||
@@ -0,0 +1,87 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * Ask for a password | ||
4 | * I use a static buffer in this function. Plan accordingly. | ||
5 | * | ||
6 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | */ | ||
22 | |||
23 | #include <stdio.h> | ||
24 | #include <string.h> | ||
25 | #include <unistd.h> | ||
26 | #include <fcntl.h> | ||
27 | #include <signal.h> | ||
28 | #include <termios.h> | ||
29 | #include <sys/ioctl.h> | ||
30 | #define PWD_BUFFER_SIZE 256 | ||
31 | |||
32 | |||
33 | /* do nothing signal handler */ | ||
34 | static void askpass_timeout(int ignore) | ||
35 | { | ||
36 | } | ||
37 | |||
38 | char *bb_askpass(int timeout, const char * prompt) | ||
39 | { | ||
40 | char *ret; | ||
41 | int i, size; | ||
42 | struct sigaction sa; | ||
43 | struct termios old, new; | ||
44 | static char passwd[PWD_BUFFER_SIZE]; | ||
45 | |||
46 | tcgetattr(STDIN_FILENO, &old); | ||
47 | |||
48 | size = sizeof(passwd); | ||
49 | ret = passwd; | ||
50 | memset(passwd, 0, size); | ||
51 | |||
52 | fputs(prompt, stdout); | ||
53 | fflush(stdout); | ||
54 | |||
55 | tcgetattr(STDIN_FILENO, &new); | ||
56 | new.c_iflag &= ~(IUCLC|IXON|IXOFF|IXANY); | ||
57 | new.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|TOSTOP); | ||
58 | tcsetattr(STDIN_FILENO, TCSANOW, &new); | ||
59 | |||
60 | if (timeout) { | ||
61 | sa.sa_flags = 0; | ||
62 | sa.sa_handler = askpass_timeout; | ||
63 | sigaction(SIGALRM, &sa, NULL); | ||
64 | alarm(timeout); | ||
65 | } | ||
66 | |||
67 | if (read(STDIN_FILENO, passwd, size-1) <= 0) { | ||
68 | ret = NULL; | ||
69 | } else { | ||
70 | for(i = 0; i < size && passwd[i]; i++) { | ||
71 | if (passwd[i]== '\r' || passwd[i] == '\n') { | ||
72 | passwd[i]= 0; | ||
73 | break; | ||
74 | } | ||
75 | } | ||
76 | } | ||
77 | |||
78 | if (timeout) { | ||
79 | alarm(0); | ||
80 | } | ||
81 | |||
82 | tcsetattr(STDIN_FILENO, TCSANOW, &old); | ||
83 | fputs("\n", stdout); | ||
84 | fflush(stdout); | ||
85 | return ret; | ||
86 | } | ||
87 | |||
diff --git a/libbb/correct_password.c b/libbb/correct_password.c index 1da83c441..e3ff44689 100644 --- a/libbb/correct_password.c +++ b/libbb/correct_password.c | |||
@@ -66,10 +66,10 @@ int correct_password ( const struct passwd *pw ) | |||
66 | if ( correct == 0 || correct[0] == '\0' ) | 66 | if ( correct == 0 || correct[0] == '\0' ) |
67 | return 1; | 67 | return 1; |
68 | 68 | ||
69 | unencrypted = getpass ( "Password: " ); | 69 | unencrypted = bb_askpass ( 0, "Password: " ); |
70 | if ( !unencrypted ) | 70 | if ( !unencrypted ) |
71 | { | 71 | { |
72 | fputs ( "getpass: cannot open /dev/tty\n", stderr ); | 72 | fputs ( "cannot open /dev/tty\n", stderr ); |
73 | return 0; | 73 | return 0; |
74 | } | 74 | } |
75 | encrypted = crypt ( unencrypted, correct ); | 75 | encrypted = crypt ( unencrypted, correct ); |
diff --git a/loginutils/passwd.c b/loginutils/passwd.c index 269e529f3..d0b2afc19 100644 --- a/loginutils/passwd.c +++ b/loginutils/passwd.c | |||
@@ -332,7 +332,7 @@ static int new_password(const struct passwd *pw, int amroot, int algo) | |||
332 | time_t start, now; | 332 | time_t start, now; |
333 | 333 | ||
334 | if (!amroot && crypt_passwd[0]) { | 334 | if (!amroot && crypt_passwd[0]) { |
335 | if (!(clear = getpass("Old password:"))) { | 335 | if (!(clear = bb_askpass(0, "Old password:"))) { |
336 | /* return -1; */ | 336 | /* return -1; */ |
337 | return 1; | 337 | return 1; |
338 | } | 338 | } |
@@ -356,7 +356,7 @@ static int new_password(const struct passwd *pw, int amroot, int algo) | |||
356 | } else { | 356 | } else { |
357 | orig[0] = '\0'; | 357 | orig[0] = '\0'; |
358 | } | 358 | } |
359 | if (! (cp=getpass("Enter the new password (minimum of 5, maximum of 8 characters)\n" | 359 | if (! (cp=bb_askpass(0, "Enter the new password (minimum of 5, maximum of 8 characters)\n" |
360 | "Please use a combination of upper and lower case letters and numbers.\n" | 360 | "Please use a combination of upper and lower case letters and numbers.\n" |
361 | "Enter new password: "))) | 361 | "Enter new password: "))) |
362 | { | 362 | { |
@@ -375,7 +375,7 @@ static int new_password(const struct passwd *pw, int amroot, int algo) | |||
375 | return 1; | 375 | return 1; |
376 | } | 376 | } |
377 | } | 377 | } |
378 | if (!(cp = getpass("Re-enter new password: "))) { | 378 | if (!(cp = bb_askpass(0, "Re-enter new password: "))) { |
379 | bzero(orig, sizeof orig); | 379 | bzero(orig, sizeof orig); |
380 | /* return -1; */ | 380 | /* return -1; */ |
381 | return 1; | 381 | return 1; |
diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c index bb4716e0d..f21b09571 100644 --- a/loginutils/sulogin.c +++ b/loginutils/sulogin.c | |||
@@ -5,7 +5,6 @@ | |||
5 | #include <stdlib.h> | 5 | #include <stdlib.h> |
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <syslog.h> | 7 | #include <syslog.h> |
8 | #include <termios.h> | ||
9 | #include <unistd.h> | 8 | #include <unistd.h> |
10 | #include <utmp.h> | 9 | #include <utmp.h> |
11 | #include <sys/resource.h> | 10 | #include <sys/resource.h> |
@@ -55,7 +54,6 @@ extern int sulogin_main(int argc, char **argv) | |||
55 | const char *name = "root"; | 54 | const char *name = "root"; |
56 | int timeout = 0; | 55 | int timeout = 0; |
57 | static char pass[BUFSIZ]; | 56 | static char pass[BUFSIZ]; |
58 | struct termios termio; | ||
59 | struct passwd pwent; | 57 | struct passwd pwent; |
60 | struct passwd *pwd; | 58 | struct passwd *pwd; |
61 | time_t start, now; | 59 | time_t start, now; |
@@ -64,28 +62,6 @@ extern int sulogin_main(int argc, char **argv) | |||
64 | struct spwd *spwd = NULL; | 62 | struct spwd *spwd = NULL; |
65 | #endif /* CONFIG_FEATURE_SHADOWPASSWDS */ | 63 | #endif /* CONFIG_FEATURE_SHADOWPASSWDS */ |
66 | 64 | ||
67 | tcgetattr(0, &termio); | ||
68 | /* set control chars */ | ||
69 | termio.c_cc[VINTR] = 3; /* C-c */ | ||
70 | termio.c_cc[VQUIT] = 28; /* C-\ */ | ||
71 | termio.c_cc[VERASE] = 127; /* C-? */ | ||
72 | termio.c_cc[VKILL] = 21; /* C-u */ | ||
73 | termio.c_cc[VEOF] = 4; /* C-d */ | ||
74 | termio.c_cc[VSTART] = 17; /* C-q */ | ||
75 | termio.c_cc[VSTOP] = 19; /* C-s */ | ||
76 | termio.c_cc[VSUSP] = 26; /* C-z */ | ||
77 | /* use line dicipline 0 */ | ||
78 | termio.c_line = 0; | ||
79 | /* Make it be sane */ | ||
80 | termio.c_cflag &= CBAUD|CBAUDEX|CSIZE|CSTOPB|PARENB|PARODD; | ||
81 | termio.c_cflag |= CREAD|HUPCL|CLOCAL; | ||
82 | /* input modes */ | ||
83 | termio.c_iflag = ICRNL | IXON | IXOFF; | ||
84 | /* output modes */ | ||
85 | termio.c_oflag = OPOST | ONLCR; | ||
86 | /* local modes */ | ||
87 | termio.c_lflag = ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE | IEXTEN; | ||
88 | tcsetattr(0, TCSANOW, &termio); | ||
89 | openlog("sulogin", LOG_PID | LOG_CONS | LOG_NOWAIT, LOG_AUTH); | 65 | openlog("sulogin", LOG_PID | LOG_CONS | LOG_NOWAIT, LOG_AUTH); |
90 | if (argc > 1) { | 66 | if (argc > 1) { |
91 | if (strncmp(argv[1], "-t", 2) == 0) { | 67 | if (strncmp(argv[1], "-t", 2) == 0) { |
@@ -132,7 +108,6 @@ extern int sulogin_main(int argc, char **argv) | |||
132 | 108 | ||
133 | 109 | ||
134 | signal(SIGALRM, catchalarm); | 110 | signal(SIGALRM, catchalarm); |
135 | alarm(timeout); | ||
136 | if (!(pwd = getpwnam(name))) { | 111 | if (!(pwd = getpwnam(name))) { |
137 | syslog(LOG_WARNING, "No password entry for `root'\n"); | 112 | syslog(LOG_WARNING, "No password entry for `root'\n"); |
138 | bb_error_msg_and_die("No password entry for `root'\n"); | 113 | bb_error_msg_and_die("No password entry for `root'\n"); |
@@ -150,7 +125,7 @@ extern int sulogin_main(int argc, char **argv) | |||
150 | } | 125 | } |
151 | #endif /* CONFIG_FEATURE_SHADOWPASSWDS */ | 126 | #endif /* CONFIG_FEATURE_SHADOWPASSWDS */ |
152 | while (1) { | 127 | while (1) { |
153 | cp = getpass(SULOGIN_PROMPT); | 128 | cp = bb_askpass(timeout, SULOGIN_PROMPT); |
154 | if (!cp || !*cp) { | 129 | if (!cp || !*cp) { |
155 | puts("\n"); | 130 | puts("\n"); |
156 | fflush(stdout); | 131 | fflush(stdout); |
@@ -174,7 +149,6 @@ extern int sulogin_main(int argc, char **argv) | |||
174 | syslog(LOG_WARNING, "Incorrect root password\n"); | 149 | syslog(LOG_WARNING, "Incorrect root password\n"); |
175 | } | 150 | } |
176 | bzero(pass, strlen(pass)); | 151 | bzero(pass, strlen(pass)); |
177 | alarm(0); | ||
178 | signal(SIGALRM, SIG_DFL); | 152 | signal(SIGALRM, SIG_DFL); |
179 | puts("Entering System Maintenance Mode\n"); | 153 | puts("Entering System Maintenance Mode\n"); |
180 | fflush(stdout); | 154 | fflush(stdout); |
diff --git a/loginutils/vlock.c b/loginutils/vlock.c index 7abf120d9..def484ae6 100644 --- a/loginutils/vlock.c +++ b/loginutils/vlock.c | |||
@@ -193,10 +193,9 @@ extern int vlock_main(int argc, char **argv) | |||
193 | 193 | ||
194 | snprintf(prompt, 100, "%s's password: ", pw->pw_name); | 194 | snprintf(prompt, 100, "%s's password: ", pw->pw_name); |
195 | 195 | ||
196 | if ((pass = getpass(prompt)) == NULL) { | 196 | if ((pass = bb_askpass(0, prompt)) == NULL) { |
197 | perror("getpass"); | ||
198 | restore_terminal(); | 197 | restore_terminal(); |
199 | exit(1); | 198 | bb_perror_msg_and_die("password"); |
200 | } | 199 | } |
201 | 200 | ||
202 | crypt_pass = pw_encrypt(pass, pw->pw_passwd); | 201 | crypt_pass = pw_encrypt(pass, pw->pw_passwd); |
@@ -210,9 +209,8 @@ extern int vlock_main(int argc, char **argv) | |||
210 | memset(crypt_pass, 0, strlen(crypt_pass)); | 209 | memset(crypt_pass, 0, strlen(crypt_pass)); |
211 | 210 | ||
212 | if (isatty(STDIN_FILENO) == 0) { | 211 | if (isatty(STDIN_FILENO) == 0) { |
213 | perror("isatty"); | ||
214 | restore_terminal(); | 212 | restore_terminal(); |
215 | exit(1); | 213 | bb_perror_msg_and_die("isatty"); |
216 | } | 214 | } |
217 | 215 | ||
218 | sleep(++times); | 216 | sleep(++times); |