[GRASS-CVS] markus: grass6/db/db.login main.c,1.3.4.1,1.3.4.2

grass at intevation.de grass at intevation.de
Thu Nov 29 05:23:57 EST 2007


Author: markus

Update of /grassrepository/grass6/db/db.login
In directory doto:/tmp/cvs-serv12859

Modified Files:
      Tag: releasebranch_6_2
	main.c 
Log Message:
also interactively query PW (backported)

Index: main.c
===================================================================
RCS file: /grassrepository/grass6/db/db.login/main.c,v
retrieving revision 1.3.4.1
retrieving revision 1.3.4.2
diff -u -d -r1.3.4.1 -r1.3.4.2
--- main.c	23 Aug 2006 07:34:45 -0000	1.3.4.1
+++ main.c	29 Nov 2007 10:23:55 -0000	1.3.4.2
@@ -1,6 +1,26 @@
+/****************************************************************************
+ *
+ * MODULE:       db.login
+ * AUTHOR(S):    Radim Blazek <radim.blazek gmail.com> (original contributor)
+ *               Glynn Clements <glynn gclements.plus.com>, Markus Neteler <neteler itc.it>
+ * PURPOSE:      
+ * COPYRIGHT:    (C) 2004-2006 by the GRASS Development Team
+ *
+ *               This program is free software under the GNU General Public
+ *               License (>=v2). Read the file COPYING that comes with GRASS
+ *               for details.
+ *
+ *****************************************************************************/
 #include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
 #include <string.h>
+
+#include <grass/config.h>
+#ifdef HAVE_TERMIOS_H
+#include <termios.h>
+#endif
+
 #include <grass/gis.h>
 #include <grass/dbmi.h>
 #include <grass/glocale.h>
@@ -10,13 +30,17 @@
 {
     struct Option *driver, *database, *user, *password;
     struct GModule *module;
+#ifdef HAVE_TERMIOS_H
+    struct termios tios, tios2;
+#endif
+    char answer[200];
     
     /* Initialize the GIS calls */
     G_gisinit(argv[0]) ;
 
     module              = G_define_module();
-    module->keywords = _("database, SQL");
-    module->description = "Set user/password for driver/database.";
+    module->keywords    = _("database, SQL");
+    module->description = _("Sets user/password for driver/database.");
     
     driver = G_define_option() ;
     driver->key        = "driver" ;
@@ -35,31 +59,57 @@
     database->description= "Database name" ;
     database->answer     = db_get_default_database_name();
 
-    user = G_define_option() ;
+    user             = G_define_option() ;
     user->key        = "user" ;
     user->type       = TYPE_STRING ;
     user->required   = NO  ;
     user->multiple   = NO ;
-    user->description= "User" ;    
+    user->description= _("Username") ;
 
-    password = G_define_option() ;
+    password             = G_define_option() ;
     password->key        = "password" ;
     password->type       = TYPE_STRING ;
-    password->required   = NO  ;
+    password->required   = NO ;
     password->multiple   = NO ;
-    password->description= "Password" ;
+    password->description= _("Password") ;
 
     if(G_parser(argc, argv))
-	exit(1);
+	exit(EXIT_FAILURE);
 
     /* set connection */
+    if (!password->answer && isatty(fileno(stdin)) ){
+        for(;;) {
+#ifdef HAVE_TERMIOS_H
+          tcgetattr(STDIN_FILENO, &tios);
+          tios2 = tios;
+          tios2.c_lflag &= ~ECHO;
+          tcsetattr(STDIN_FILENO, TCSAFLUSH, &tios2);
+#endif
+          do {
+              fprintf (stderr,_("\nEnter database password for connection\n<%s:%s:user=%s>\n"), driver->answer, database->answer, user->answer);
+              fprintf (stderr, _("Hit RETURN to cancel request\n"));
+              fprintf (stderr,">");
+          } while(!G_gets(answer));
+#ifdef HAVE_TERMIOS_H
+          tcsetattr(STDIN_FILENO, TCSANOW, &tios);
+#endif
+          G_strip(answer);
+          if(strlen(answer)==0) {
+	     G_message(_("Exiting. Not changing current settings"));
+	     return -1;
+	  } else {
+	     G_message(_("New password set"));
+	     password->answer = G_store(answer);
+	     break;
+	  }
+	}
+    }
     if (  db_set_login ( driver->answer, database->answer, user->answer, password->answer ) == DB_FAILED ) {
-	G_fatal_error ( _("Cannot set user/password") );
+	G_fatal_error ( _("Unable to set user/password") );
     }
 
     if ( password->answer )
-        G_warning ( _("The password was stored in file.") );
+        G_warning ( _("The password was stored in file") );
 	
-    exit(0);
+    exit(EXIT_SUCCESS);
 }
-




More information about the grass-commit mailing list