Re: psql: default base and password reading

Поиск
Список
Период
Сортировка
От Bruce Momjian
Тема Re: psql: default base and password reading
Дата
Msg-id 200110130421.f9D4Lra04148@candle.pha.pa.us
обсуждение исходный текст
Ответ на Re: psql: default base and password reading  (Bruce Momjian <pgman@candle.pha.pa.us>)
Ответы Re: psql: default base and password reading  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-patches
> > The password reading patch may be useful, but I suggest that you
> > reverse the meaning of the option, so that you do not change the
> > current behavior.  This would be a normal practice for backward
> > compatibility.
>
> I like the /dev/tty fix.  I assumed we always read passwords from
> /dev/tty and not stdin.  I know of no other software that even allows
> passwords from stdin.  You usually have to use 'expect' for that very
> purpose.  I would not even supply an option to read it from stdin.

Attached is an updated version of the patch.  It does not have the
'template1' default because many people prefer our current behavior.

The patch uses /dev/tty if it can open it, and stdin if it can't.  It
does not have a psql flag to force stdin because there is little reason
to read a password from stdin in any reasonable usage.

In fact, I wonder if we should just fail if we need to prompt for a
password and can't open /dev/tty.  The function is simple_prompt() and
if we can't open /dev/tty, maybe we should just assume the user typed
nothing.

Comments?

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
diff -ruN psql/common.c psql_patched/common.c
--- psql/common.c    Sun Apr 15 02:43:37 2001
+++ psql_patched/common.c    Sun Oct  7 14:58:22 2001
@@ -176,6 +176,7 @@
 {
     int            length;
     char       *destination;
+    static FILE *term = NULL;

 #ifdef HAVE_TERMIOS_H
     struct termios t_orig,
@@ -190,24 +191,28 @@
         fputs(prompt, stderr);

     prompt_state = true;
+    if (!term)
+        term = fopen("/dev/tty", "r");
+    if (term == NULL)
+        term = stdin;

 #ifdef HAVE_TERMIOS_H
     if (!echo)
     {
-        tcgetattr(0, &t);
+        tcgetattr(fileno(term), &t);
         t_orig = t;
         t.c_lflag &= ~ECHO;
-        tcsetattr(0, TCSADRAIN, &t);
+        tcsetattr(fileno(term), TCSADRAIN, &t);
     }
 #endif

-    if (fgets(destination, maxlen, stdin) == NULL)
+    if (fgets(destination, maxlen, term) == NULL)
         destination[0] = '\0';

 #ifdef HAVE_TERMIOS_H
     if (!echo)
     {
-        tcsetattr(0, TCSADRAIN, &t_orig);
+        tcsetattr(fileno(term), TCSADRAIN, &t_orig);
         fputs("\n", stderr);
     }
 #endif
@@ -223,7 +228,7 @@

         do
         {
-            if (fgets(buf, sizeof(buf), stdin) == NULL)
+            if (fgets(buf, sizeof(buf), term) == NULL)
                 break;
             buflen = strlen(buf);
         } while (buflen > 0 && buf[buflen - 1] != '\n');

В списке pgsql-patches по дате отправления:

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: [PATCH] unconditionally enable pltcl-unknown
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: Showing index details with \d on psql