aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>1997-09-19 23:31:27 +0000
committerEric S. Raymond <esr@thyrsus.com>1997-09-19 23:31:27 +0000
commit87174d260475db2f469cdb948597c1f9f39376b7 (patch)
tree3935a6c25dfeb441d2992154f6e5bbabb38b0fd7
parent7052f7f510a90d1cce53bb1541ef99d092033503 (diff)
downloadfetchmail-87174d260475db2f469cdb948597c1f9f39376b7.tar.gz
fetchmail-87174d260475db2f469cdb948597c1f9f39376b7.tar.bz2
fetchmail-87174d260475db2f469cdb948597c1f9f39376b7.zip
Add patch allowing password to be piped in.
svn path=/trunk/; revision=1377
-rw-r--r--NEWS1
-rw-r--r--getpass.c54
2 files changed, 36 insertions, 19 deletions
diff --git a/NEWS b/NEWS
index 0b906115..aa1d2048 100644
--- a/NEWS
+++ b/NEWS
@@ -19,6 +19,7 @@ fetchmail-4.2.4 (Thu Sep 18 16:19:10 EDT 1997)
* Small compilation cleanups, thanks to Florian laRoche.
* Removed the length consistency check, it mysteriously fails under POP3.
* Added Alexander Kourakos's patch to improve address rewriting.
+* Added Wilfried Teiken's patch allowing the password to be piped in.
fetchmail-4.2.3 (Thu Sep 18 16:19:10 EDT 1997)
* Fix a bug in IMAP message-size retrieval.
diff --git a/getpass.c b/getpass.c
index f3d6d48f..e942f26c 100644
--- a/getpass.c
+++ b/getpass.c
@@ -7,6 +7,8 @@
project: fetchmail
programmer: Carl Harris, ceharris@mal.com
description: getpass() replacement which allows for long passwords.
+ This version hacked by Wilfred Teiken, allowing the
+ password to be piped to fetchmail.
***********************************************************************/
@@ -81,29 +83,39 @@ char *prompt;
static char pbuf[INPUT_BUF_SIZE];
RETSIGTYPE (*sig)();
RETSIGTYPE sigint_handler();
-
+ int istty=tcgetpgrp(0)!=-1;
/* get the file descriptor for the input device */
- if ((fi = fdopen(open("/dev/tty", 2), "r")) == NULL)
- fi = stdin;
+
+ if(istty)
+ {
+ if ((fi = fdopen(open("/dev/tty", 2), "r")) == NULL)
+ fi = stdin;
+ else
+ setbuf(fi, (char *)NULL);
+ }
else
- setbuf(fi, (char *)NULL);
+ fi=stdin;
/* store descriptor for the tty */
ttyfd = fileno(fi);
- /* preserve tty state before turning off echo */
- save_tty_state();
+ if(istty)
+ {
+ /* preserve tty state before turning off echo */
+ save_tty_state();
- /* now that we have the current tty state, we can catch SIGINT and
- exit gracefully */
- sig = signal(SIGINT, sigint_handler);
+ /* now that we have the current tty state, we can catch SIGINT and
+ exit gracefully */
+ sig = signal(SIGINT, sigint_handler);
- /* turn off echo on the tty */
- disable_tty_echo();
+ /* turn off echo on the tty */
+ disable_tty_echo();
+ }
/* display the prompt and get the input string */
- fprintf(stderr, "%s", prompt); fflush(stderr);
+ if(istty)
+ fprintf(stderr, "%s", prompt); fflush(stderr);
for (p=pbuf; (c = getc(fi))!='\n' && c!=EOF;) {
if (p < &pbuf[INPUT_BUF_SIZE - 1])
*p++ = c;
@@ -111,14 +123,18 @@ char *prompt;
*p = '\0';
/* write a newline so cursor won't appear to hang */
- fprintf(stderr, "\n"); fflush(stderr);
-
- /* restore previous state of the tty */
- restore_tty_state();
-
- /* restore previous state of SIGINT */
- signal(SIGINT, sig);
+ if(fi!=stdin)
+ {
+ fprintf(stderr, "\n"); fflush(stderr);
+ }
+ if(istty)
+ {
+ /* restore previous state of the tty */
+ restore_tty_state();
+ /* restore previous state of SIGINT */
+ signal(SIGINT, sig);
+ }
if (fi != stdin)
fclose(fi);