[GRASS-dev] db.login: interactive PW implemented

Markus Neteler neteler at itc.it
Wed Nov 15 10:28:22 EST 2006


Hi,

when using db.login, I disliked to enter the password 
in cleartext on command line. I have implemented an interactive
password query. The behaviour is now like this:

Example 1: Username and password specified: 
  db.login user=bacava pass=secret

Example 2: Username and empty password specified: 
  db.login user=bacava pass=""

Example 3: Username specified, password will be queried interactively: 
  db.login user=bacava

The only thing which I don't know how to fix is that
G_gets() echoes the password. I wonder if we could have
a G_gets_silent() or something (lib/gis/gets.c).

Markus
-------------- next part --------------
? OBJ.x86_64-unknown-linux-gnu
Index: main.c
===================================================================
RCS file: /grassrepository/grass6/db/db.login/main.c,v
retrieving revision 1.5
diff -u -r1.5 main.c
--- main.c	15 Nov 2006 13:36:28 -0000	1.5
+++ main.c	15 Nov 2006 13:56:06 -0000
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
 #include <string.h>
 #include <grass/gis.h>
 #include <grass/dbmi.h>
@@ -53,6 +54,8 @@
 	exit(EXIT_FAILURE);
 
     /* set connection */
+    if (!password->answer && isatty(fileno(stdin)) )
+        G_message("Enter your password:");
     if (  db_set_login ( driver->answer, database->answer, user->answer, password->answer ) == DB_FAILED ) {
 	G_fatal_error ( _("Cannot set user/password") );
     }


More information about the grass-dev mailing list