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

Markus Neteler neteler at itc.it
Thu Nov 16 12:23:02 EST 2006


Glynn Clements wrote on 11/16/2006 03:03 PM:
> Glynn Clements 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).
>>     
>
> BTW, there is some code in 5.3 to do this (when I wrote my previous
> message, I could have sworn that something in GRASS did this, but I
> couldn't find it at that time), in:
>
> 	src/libes/unused/unsupported/dig_to_dlg/tty.c
> 	src/libes/unused/unsupported/dlglabel/tty.c
> 	src/paint/Interface/driverlib/io.c
> 	src/paint/drivers.junk/anadex/open.c
> 	src/paint/drivers.junk/epson.24.180/open.c
> 	src/paint/drivers.junk/epson.24.90/open.c
> 	src/paint/drivers.junk/epson.8.90/open.c
> 	src.contrib/SCS/paint/Drivers/driverlib/io.c
> 	src.contrib/SCS/paint/Interface/driverlib/io.c
>
> [Note that most of the above are essentially clones of each other.]
>
> Of the above, src/paint/Interface/driverlib/io.c includes code for all
> three interfaces, decided by header checks.
>
> tcsetattr() uses "struct termios" from <termios.h>, ioctl(TCSETA) uses
> "struct termio" from <termio.h>, while stty() uses "struct sgttyb"
> from <sgtty.h>.
>
> Also, note that using stty() requires $(COMPATLIB) to be added to the
> link flags.
>
>   
>> And Windows uses something completely different (conio.h, maybe?).
>>     
>
> Windows has separate getch() and getche() functions; the latter echoes
> characters as they are typed, the former doesn't. You can't disable
> echoing for stdio.
>
> BTW, some Unices (including Linux) have a getpass() function (not
> defined by any standard, AFAICT). This specifically opens /dev/tty
> rather than using stdin, so it works even if stdin is redirected.
>
>   

Thanks, but I am afraid that I am unable to decide/implement the further
suggestions - too
complicated for me.

Markus




More information about the grass-dev mailing list