Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/libbb/bb_askpass.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/libbb/bb_askpass.c
r821 r1770 9 9 */ 10 10 11 #include <stdio.h>12 #include <string.h>13 #include <unistd.h>14 #include <fcntl.h>15 #include <signal.h>16 11 #include <termios.h> 17 #include <sys/ioctl.h>18 12 19 13 #include "libbb.h" 20 #define PWD_BUFFER_SIZE 25621 22 14 23 15 /* do nothing signal handler */ … … 28 20 char *bb_askpass(int timeout, const char * prompt) 29 21 { 22 /* Was static char[BIGNUM] */ 23 enum { sizeof_passwd = 128 }; 24 static char *passwd; 25 30 26 char *ret; 31 int i , size;27 int i; 32 28 struct sigaction sa; 33 29 struct termios old, new; 34 static char passwd[PWD_BUFFER_SIZE]; 30 31 if (!passwd) 32 passwd = xmalloc(sizeof_passwd); 33 memset(passwd, 0, sizeof_passwd); 35 34 36 35 tcgetattr(STDIN_FILENO, &old); 37 36 tcflush(STDIN_FILENO, TCIFLUSH); 38 39 size = sizeof(passwd);40 ret = passwd;41 memset(passwd, 0, size);42 37 43 38 fputs(prompt, stdout); … … 56 51 } 57 52 58 if (read(STDIN_FILENO, passwd, size-1) <= 0) { 59 ret = NULL; 60 } else { 61 for(i = 0; i < size && passwd[i]; i++) { 62 if (passwd[i]== '\r' || passwd[i] == '\n') { 63 passwd[i]= 0; 64 break; 65 } 66 } 53 ret = NULL; 54 /* On timeout, read will hopefully be interrupted by SIGALRM, 55 * and we return NULL */ 56 if (read(STDIN_FILENO, passwd, sizeof_passwd-1) > 0) { 57 ret = passwd; 58 i = 0; 59 /* Last byte is guaranteed to be 0 60 (read did not overwrite it) */ 61 do { 62 if (passwd[i] == '\r' || passwd[i] == '\n') 63 passwd[i] = '\0'; 64 } while (passwd[i++]); 67 65 } 68 66 … … 72 70 73 71 tcsetattr(STDIN_FILENO, TCSANOW, &old); 74 fputs("\n", stdout);72 putchar('\n'); 75 73 fflush(stdout); 76 74 return ret; 77 75 } 78
Note:
See TracChangeset
for help on using the changeset viewer.