瀏覽代碼

Add the openssh 6.8p1 readpassphrase implementation

This way glibc users don't have to fall back to getpass.

Windows users are still out of luck
Nick Mathewson 10 年之前
父節點
當前提交
b9b658e727
共有 5 個文件被更改,包括 25 次插入5 次删除
  1. 2 0
      configure.ac
  2. 2 0
      src/common/compat.c
  3. 8 1
      src/common/include.am
  4. 10 3
      src/ext/readpassphrase.c
  5. 3 1
      src/ext/readpassphrase.h

+ 2 - 0
configure.ac

@@ -423,6 +423,8 @@ if test "$bwin32" != true; then
   AC_CHECK_FUNCS(pthread_create)
   AC_CHECK_FUNCS(pthread_create)
 fi
 fi
 
 
+AM_CONDITIONAL(BUILD_READPASSPHRASE_C, test x$ac_cv_func_readpassphrase = xno && test $bwin32 = false)
+
 dnl ------------------------------------------------------
 dnl ------------------------------------------------------
 dnl Where do you live, libevent?  And how do we call you?
 dnl Where do you live, libevent?  And how do we call you?
 
 

+ 2 - 0
src/common/compat.c

@@ -69,6 +69,8 @@
 #endif
 #endif
 #ifdef HAVE_READPASSPHRASE_H
 #ifdef HAVE_READPASSPHRASE_H
 #include <readpassphrase.h>
 #include <readpassphrase.h>
+#elif !defined(_WIN32)
+#include "readpassphrase.h"
 #endif
 #endif
 
 
 #ifndef HAVE_GETTIMEOFDAY
 #ifndef HAVE_GETTIMEOFDAY

+ 8 - 1
src/common/include.am

@@ -51,6 +51,12 @@ if THREADS_WIN32
 threads_impl_source=src/common/compat_winthreads.c
 threads_impl_source=src/common/compat_winthreads.c
 endif
 endif
 
 
+if BUILD_READPASSPHRASE_C
+readpassphrase_source=src/ext/readpassphrase.c
+else
+readpassphrase_source=
+endif
+
 LIBOR_A_SOURCES = \
 LIBOR_A_SOURCES = \
   src/common/address.c					\
   src/common/address.c					\
   src/common/backtrace.c				\
   src/common/backtrace.c				\
@@ -67,7 +73,8 @@ LIBOR_A_SOURCES = \
   src/ext/csiphash.c					\
   src/ext/csiphash.c					\
   src/ext/trunnel/trunnel.c				\
   src/ext/trunnel/trunnel.c				\
   $(libor_extra_source)					\
   $(libor_extra_source)					\
-  $(threads_impl_source)
+  $(threads_impl_source)				\
+  $(readpassphrase_source)
 
 
 src/common/log.o: micro-revision.i
 src/common/log.o: micro-revision.i
 
 

+ 10 - 3
src/ext/readpassphrase.c

@@ -22,7 +22,7 @@
 
 
 /* OPENBSD ORIGINAL: lib/libc/gen/readpassphrase.c */
 /* OPENBSD ORIGINAL: lib/libc/gen/readpassphrase.c */
 
 
-#include "includes.h"
+#include "orconfig.h"
 
 
 #ifndef HAVE_READPASSPHRASE
 #ifndef HAVE_READPASSPHRASE
 
 
@@ -35,6 +35,10 @@
 #include <string.h>
 #include <string.h>
 #include <unistd.h>
 #include <unistd.h>
 
 
+#ifndef _PATH_TTY
+# define _PATH_TTY "/dev/tty"
+#endif
+
 #ifdef TCSASOFT
 #ifdef TCSASOFT
 # define _T_FLUSH	(TCSAFLUSH|TCSASOFT)
 # define _T_FLUSH	(TCSAFLUSH|TCSASOFT)
 #else
 #else
@@ -61,6 +65,7 @@ static void handler(int);
 char *
 char *
 readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags)
 readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags)
 {
 {
+	ssize_t bytes_written = 0;
 	ssize_t nr;
 	ssize_t nr;
 	int input, output, save_errno, i, need_restart;
 	int input, output, save_errno, i, need_restart;
 	char ch, *p, *end;
 	char ch, *p, *end;
@@ -132,7 +137,7 @@ restart:
 	/* No I/O if we are already backgrounded. */
 	/* No I/O if we are already backgrounded. */
 	if (signo[SIGTTOU] != 1 && signo[SIGTTIN] != 1) {
 	if (signo[SIGTTOU] != 1 && signo[SIGTTIN] != 1) {
 		if (!(flags & RPP_STDIN))
 		if (!(flags & RPP_STDIN))
-			(void)write(output, prompt, strlen(prompt));
+			bytes_written = write(output, prompt, strlen(prompt));
 		end = buf + bufsiz - 1;
 		end = buf + bufsiz - 1;
 		p = buf;
 		p = buf;
 		while ((nr = read(input, &ch, 1)) == 1 && ch != '\n' && ch != '\r') {
 		while ((nr = read(input, &ch, 1)) == 1 && ch != '\n' && ch != '\r') {
@@ -151,9 +156,11 @@ restart:
 		*p = '\0';
 		*p = '\0';
 		save_errno = errno;
 		save_errno = errno;
 		if (!(term.c_lflag & ECHO))
 		if (!(term.c_lflag & ECHO))
-			(void)write(output, "\n", 1);
+			bytes_written = write(output, "\n", 1);
 	}
 	}
 
 
+	(void) bytes_written;
+
 	/* Restore old terminal settings and signals. */
 	/* Restore old terminal settings and signals. */
 	if (memcmp(&term, &oterm, sizeof(term)) != 0) {
 	if (memcmp(&term, &oterm, sizeof(term)) != 0) {
 		while (tcsetattr(input, _T_FLUSH, &oterm) == -1 &&
 		while (tcsetattr(input, _T_FLUSH, &oterm) == -1 &&

+ 3 - 1
src/ext/readpassphrase.h

@@ -25,7 +25,7 @@
 #ifndef _READPASSPHRASE_H_
 #ifndef _READPASSPHRASE_H_
 #define _READPASSPHRASE_H_
 #define _READPASSPHRASE_H_
 
 
-#include "includes.h"
+#include "orconfig.h"
 
 
 #ifndef HAVE_READPASSPHRASE
 #ifndef HAVE_READPASSPHRASE
 
 
@@ -39,6 +39,8 @@
 
 
 char * readpassphrase(const char *, char *, size_t, int);
 char * readpassphrase(const char *, char *, size_t, int);
 
 
+#define HAVE_READPASSPHRASE
+
 #endif /* HAVE_READPASSPHRASE */
 #endif /* HAVE_READPASSPHRASE */
 
 
 #endif /* !_READPASSPHRASE_H_ */
 #endif /* !_READPASSPHRASE_H_ */