dovecot-2.0: Moved askpass() from master/ to lib/. Added t_askpa...
dovecot at dovecot.org
dovecot at dovecot.org
Fri Oct 9 01:43:22 EEST 2009
details: http://hg.dovecot.org/dovecot-2.0/rev/3721ae3917fc
changeset: 10003:3721ae3917fc
user: Timo Sirainen <tss at iki.fi>
date: Thu Oct 08 18:33:50 2009 -0400
description:
Moved askpass() from master/ to lib/. Added t_askpass().
diffstat:
6 files changed, 71 insertions(+), 62 deletions(-)
src/lib/Makefile.am | 2 +
src/lib/askpass.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++
src/lib/askpass.h | 7 +++++
src/master/Makefile.am | 2 -
src/master/askpass.c | 54 -----------------------------------------
src/master/askpass.h | 6 ----
diffs (183 lines):
diff -r d9cb9d03e50e -r 3721ae3917fc src/lib/Makefile.am
--- a/src/lib/Makefile.am Thu Oct 08 18:24:24 2009 -0400
+++ b/src/lib/Makefile.am Thu Oct 08 18:33:50 2009 -0400
@@ -11,6 +11,7 @@ liblib_la_SOURCES = \
liblib_la_SOURCES = \
array.c \
aqueue.c \
+ askpass.c \
backtrace-string.c \
base64.c \
bsearch-insert-pos.c \
@@ -115,6 +116,7 @@ headers = \
aqueue.h \
array.h \
array-decl.h \
+ askpass.h \
backtrace-string.h \
base64.h \
bsearch-insert-pos.h \
diff -r d9cb9d03e50e -r 3721ae3917fc src/lib/askpass.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib/askpass.c Thu Oct 08 18:33:50 2009 -0400
@@ -0,0 +1,62 @@
+/* Copyright (c) 2006-2009 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "askpass.h"
+
+#include <stdio.h>
+#include <termios.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+void askpass(const char *prompt, char *buf, size_t buf_size)
+{
+ struct termios old_tio, tio;
+ bool restore_tio = FALSE;
+ ssize_t ret;
+ size_t pos;
+ char ch;
+ int fd;
+
+ if (!isatty(STDIN_FILENO))
+ i_fatal("stdin isn't a TTY");
+
+ fputs(prompt, stderr);
+ fflush(stderr);
+
+ fd = open("/dev/tty", O_RDONLY);
+ if (fd < 0)
+ i_fatal("open(/dev/tty) failed: %m");
+
+ /* turn off echo */
+ if (tcgetattr(fd, &old_tio) == 0) {
+ restore_tio = TRUE;
+ tio = old_tio;
+ tio.c_lflag &= ~(ECHO | ECHONL);
+ (void)tcsetattr(fd, TCSAFLUSH, &tio);
+ }
+
+ /* read the password */
+ pos = 0;
+ while ((ret = read(fd, &ch, 1)) > 0) {
+ if (pos >= buf_size-1)
+ break;
+ if (ch == '\n' || ch == '\r')
+ break;
+ buf[pos++] = ch;
+ }
+ buf[pos] = '\0';
+
+ if (restore_tio)
+ (void)tcsetattr(fd, TCSAFLUSH, &old_tio);
+
+ fputs("\n", stderr); fflush(stderr);
+ (void)close(fd);
+}
+
+const char *t_askpass(const char *prompt)
+{
+ char buf[1024];
+
+ askpass(prompt, buf, sizeof(buf));
+ return t_strdup(buf);
+}
diff -r d9cb9d03e50e -r 3721ae3917fc src/lib/askpass.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib/askpass.h Thu Oct 08 18:33:50 2009 -0400
@@ -0,0 +1,7 @@
+#ifndef ASKPASS_H
+#define ASKPASS_H
+
+void askpass(const char *prompt, char *buf, size_t buf_size);
+const char *t_askpass(const char *prompt);
+
+#endif
diff -r d9cb9d03e50e -r 3721ae3917fc src/master/Makefile.am
--- a/src/master/Makefile.am Thu Oct 08 18:24:24 2009 -0400
+++ b/src/master/Makefile.am Thu Oct 08 18:33:50 2009 -0400
@@ -19,7 +19,6 @@ dovecot_DEPENDENCIES = $(libs)
dovecot_DEPENDENCIES = $(libs)
dovecot_SOURCES = \
- askpass.c \
capabilities-posix.c \
dup2-array.c \
main.c \
@@ -35,7 +34,6 @@ dovecot_SOURCES = \
service.c
noinst_HEADERS = \
- askpass.h \
capabilities.h \
common.h \
dup2-array.h \
diff -r d9cb9d03e50e -r 3721ae3917fc src/master/askpass.c
--- a/src/master/askpass.c Thu Oct 08 18:24:24 2009 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-/* Copyright (c) 2006-2009 Dovecot authors, see the included COPYING file */
-
-#include "lib.h"
-#include "askpass.h"
-
-#include <stdio.h>
-#include <termios.h>
-#include <fcntl.h>
-#include <unistd.h>
-
-void askpass(const char *prompt, char *buf, size_t buf_size)
-{
- struct termios old_tio, tio;
- bool restore_tio = FALSE;
- ssize_t ret;
- size_t pos;
- char ch;
- int fd;
-
- if (!isatty(STDIN_FILENO))
- i_fatal("stdin isn't a TTY");
-
- fputs(prompt, stderr);
- fflush(stderr);
-
- fd = open("/dev/tty", O_RDONLY);
- if (fd < 0)
- i_fatal("open(/dev/tty) failed: %m");
-
- /* turn off echo */
- if (tcgetattr(fd, &old_tio) == 0) {
- restore_tio = TRUE;
- tio = old_tio;
- tio.c_lflag &= ~(ECHO | ECHONL);
- (void)tcsetattr(fd, TCSAFLUSH, &tio);
- }
-
- /* read the password */
- pos = 0;
- while ((ret = read(fd, &ch, 1)) > 0) {
- if (pos >= buf_size-1)
- break;
- if (ch == '\n' || ch == '\r')
- break;
- buf[pos++] = ch;
- }
- buf[pos] = '\0';
-
- if (restore_tio)
- (void)tcsetattr(fd, TCSAFLUSH, &old_tio);
-
- fputs("\n", stderr); fflush(stderr);
- (void)close(fd);
-}
diff -r d9cb9d03e50e -r 3721ae3917fc src/master/askpass.h
--- a/src/master/askpass.h Thu Oct 08 18:24:24 2009 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-#ifndef ASKPASS_H
-#define ASKPASS_H
-
-void askpass(const char *prompt, char *buf, size_t buf_size);
-
-#endif
More information about the dovecot-cvs
mailing list