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

Glynn Clements glynn at gclements.plus.com
Wed Nov 15 18:57:35 EST 2006


Markus Neteler wrote:

> 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).

struct termios tios, tios2;

tcgetattr(STDIN_FILENO, &tios);
tios2 = tios;
tios2.c_lflag &= ~ECHO;
tcsetattr(STDIN_FILENO, TCSAFLUSH, &tios2);

read password

tcsetattr(STDIN_FILENO, TCSANOW, &tios);

> 
> Markus
> ? 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") );
>      }
> _______________________________________________
> grass-dev mailing list
> grass-dev at grass.itc.it
> http://grass.itc.it/mailman/listinfo/grass-dev




More information about the grass-dev mailing list