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

Glynn Clements glynn at gclements.plus.com
Wed Nov 15 19:11:54 EST 2006


[I hit "send" too soon on the previous attempt.]

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

Roughly:

	#include <termios.h>
	#include <unistd.h>

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

However, BSD historically used gtty/stty instead of tc{get,set}attr,
and some older systems used ioctl(TCGETS)/ioctl(TCSETS) (IIRC, Linux'
tc{get,set}attr are implemented on top of the ioctl()s).

And Windows uses something completely different (conio.h, maybe?).

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-dev mailing list