static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl) { static int ps; int ok; char result[BUFSIZ]; int maxsize = BUFSIZ - 1; char *p; intr_signal = 0; ok = 0; ps = 0; pushsig(); ps = 1; if (!echo && !noecho_console(ui)) goto error; ps = 2; result[0] = '\0'; p = fgets(result, maxsize, tty_in); if (!p) goto error; if (feof(tty_in)) goto error; if (ferror(tty_in)) goto error; if ((p = strchr(result, '\n')) != NULL) { if (strip_nl) *p = '\0'; } else if (!read_till_nl(tty_in)) goto error; if (UI_set_result(ui, uis, result) >= 0) ok = 1; error: if (intr_signal == SIGINT) ok = -1; if (!echo) fprintf(tty_out, "\n"); if (ps >= 2 && !echo && !echo_console(ui)) ok = 0; if (ps >= 1) popsig(); OPENSSL_cleanse(result, BUFSIZ); return ok; }
/* return 0 if ok, 1 (or -1) otherwise */ int des_read_pw(char *buf, char *buff, int size, const char *prompt, int verify) { # ifdef OPENSSL_SYS_VMS struct IOSB iosb; $DESCRIPTOR(terminal, "TT"); long tty_orig[3], tty_new[3]; long status; unsigned short channel = 0; # else # if !defined(OPENSSL_SYS_MSDOS) || defined(__DJGPP__) TTY_STRUCT tty_orig, tty_new; # endif # endif int number; int ok; /* * statics are simply to avoid warnings about longjmp clobbering things */ static int ps; int is_a_tty; static FILE *tty; char *p; if (setjmp(save)) { ok = 0; goto error; } number = 5; ok = 0; ps = 0; is_a_tty = 1; tty = NULL; # ifdef OPENSSL_SYS_MSDOS if ((tty = fopen("con", "r")) == NULL) tty = stdin; # elif defined(MAC_OS_pre_X) || defined(OPENSSL_SYS_VXWORKS) tty = stdin; # else # ifndef OPENSSL_SYS_MPE if ((tty = fopen("/dev/tty", "r")) == NULL) # endif tty = stdin; # endif # if defined(TTY_get) && !defined(OPENSSL_SYS_VMS) if (TTY_get(fileno(tty), &tty_orig) == -1) { # ifdef ENOTTY if (errno == ENOTTY) is_a_tty = 0; else # endif # ifdef EINVAL /* * Ariel Glenn [email protected] reports that solaris can return * EINVAL instead. This should be ok */ if (errno == EINVAL) is_a_tty = 0; else # endif return (-1); } memcpy(&(tty_new), &(tty_orig), sizeof(tty_orig)); # endif # ifdef OPENSSL_SYS_VMS status = sys$assign(&terminal, &channel, 0, 0); if (status != SS$_NORMAL) return (-1); status = sys$qiow(0, channel, IO$_SENSEMODE, &iosb, 0, 0, tty_orig, 12, 0, 0, 0, 0); if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL)) return (-1); # endif pushsig(); ps = 1; # ifdef TTY_FLAGS tty_new.TTY_FLAGS &= ~ECHO; # endif # if defined(TTY_set) && !defined(OPENSSL_SYS_VMS) if (is_a_tty && (TTY_set(fileno(tty), &tty_new) == -1)) # ifdef OPENSSL_SYS_MPE ; /* MPE lies -- echo really has been disabled */ # else return (-1); # endif # endif # ifdef OPENSSL_SYS_VMS tty_new[0] = tty_orig[0]; tty_new[1] = tty_orig[1] | TT$M_NOECHO; tty_new[2] = tty_orig[2]; status = sys$qiow(0, channel, IO$_SETMODE, &iosb, 0, 0, tty_new, 12, 0, 0, 0, 0); if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL)) return (-1); # endif ps = 2; while ((!ok) && (number--)) { fputs(prompt, stderr); fflush(stderr); buf[0] = '\0'; fgets(buf, size, tty); if (feof(tty)) goto error; if (ferror(tty)) goto error; if ((p = (char *)strchr(buf, '\n')) != NULL) *p = '\0'; else read_till_nl(tty); if (verify) { fprintf(stderr, "\nVerifying password - %s", prompt); fflush(stderr); buff[0] = '\0'; fgets(buff, size, tty); if (feof(tty)) goto error; if ((p = (char *)strchr(buff, '\n')) != NULL) *p = '\0'; else read_till_nl(tty); if (strcmp(buf, buff) != 0) { fprintf(stderr, "\nVerify failure"); fflush(stderr); break; /* continue; */ } } ok = 1; } error: fprintf(stderr, "\n"); # if 0 perror("fgets(tty)"); # endif /* What can we do if there is an error? */ # if defined(TTY_set) && !defined(OPENSSL_SYS_VMS) if (ps >= 2) TTY_set(fileno(tty), &tty_orig); # endif # ifdef OPENSSL_SYS_VMS if (ps >= 2) status = sys$qiow(0, channel, IO$_SETMODE, &iosb, 0, 0, tty_orig, 12, 0, 0, 0, 0); # endif if (ps >= 1) popsig(); if (stdin != tty) fclose(tty); # ifdef OPENSSL_SYS_VMS status = sys$dassgn(channel); # endif return (!ok); }
static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl) { static int ps; int ok; char result[BUFSIZ]; int maxsize = BUFSIZ-1; #if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE) char *p; intr_signal=0; ok=0; ps=0; pushsig(); ps=1; if (!echo && !noecho_console(ui)) goto error; ps=2; result[0]='\0'; #ifdef OPENSSL_SYS_MSDOS if (!echo) { noecho_fgets(result,maxsize,tty_in); p=result; /* FIXME: noecho_fgets doesn't return errors */ } else p=fgets(result,maxsize,tty_in); #else p=fgets(result,maxsize,tty_in); #endif if(!p) goto error; if (feof(tty_in)) goto error; if (ferror(tty_in)) goto error; if ((p=(char *)strchr(result,'\n')) != NULL) { if (strip_nl) *p='\0'; } else if (!read_till_nl(tty_in)) goto error; if (UI_set_result(ui, uis, result) >= 0) ok=1; error: if (intr_signal == SIGINT) ok=-1; if (!echo) fprintf(tty_out,"\n"); if (ps >= 2 && !echo && !echo_console(ui)) ok=0; if (ps >= 1) popsig(); #else ok=1; #endif OPENSSL_cleanse(result,BUFSIZ); return ok; }
static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl) { static int ps; int ok; char result[BUFSIZ]; int maxsize = BUFSIZ - 1; #if !defined(OPENSSL_SYS_WINCE) char *p = NULL; int echo_eol = !echo; intr_signal = 0; ok = 0; ps = 0; pushsig(); ps = 1; if (!echo && !noecho_console(ui)) goto error; ps = 2; result[0] = '\0'; # if defined(_WIN32) if (is_a_tty) { DWORD numread; # if defined(CP_UTF8) if (GetEnvironmentVariableW(L"OPENSSL_WIN32_UTF8", NULL, 0) != 0) { WCHAR wresult[BUFSIZ]; if (ReadConsoleW(GetStdHandle(STD_INPUT_HANDLE), wresult, maxsize, &numread, NULL)) { if (numread >= 2 && wresult[numread-2] == L'\r' && wresult[numread-1] == L'\n') { wresult[numread-2] = L'\n'; numread--; } wresult[numread] = '\0'; if (WideCharToMultiByte(CP_UTF8, 0, wresult, -1, result, sizeof(result), NULL, 0) > 0) p = result; OPENSSL_cleanse(wresult, sizeof(wresult)); } } else # endif if (ReadConsoleA(GetStdHandle(STD_INPUT_HANDLE), result, maxsize, &numread, NULL)) { if (numread >= 2 && result[numread-2] == '\r' && result[numread-1] == '\n') { result[numread-2] = '\n'; numread--; } result[numread] = '\0'; p = result; } } else # elif defined(OPENSSL_SYS_MSDOS) if (!echo) { noecho_fgets(result, maxsize, tty_in); p = result; /* FIXME: noecho_fgets doesn't return errors */ } else # endif p = fgets(result, maxsize, tty_in); if (p == NULL) goto error; if (feof(tty_in)) goto error; if (ferror(tty_in)) goto error; if ((p = (char *)strchr(result, '\n')) != NULL) { if (strip_nl) *p = '\0'; } else if (!read_till_nl(tty_in)) goto error; if (UI_set_result(ui, uis, result) >= 0) ok = 1; error: if (intr_signal == SIGINT) ok = -1; if (echo_eol) fprintf(tty_out, "\n"); if (ps >= 2 && !echo && !echo_console(ui)) ok = 0; if (ps >= 1) popsig(); #else ok = 1; #endif OPENSSL_cleanse(result, BUFSIZ); return ok; }