[GRASS-SVN] r40369 - grass/branches/develbranch_6/lib/db/dbmi_base
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Jan 10 19:41:03 EST 2010
Author: hamish
Date: 2010-01-10 19:41:03 -0500 (Sun, 10 Jan 2010)
New Revision: 40369
Modified:
grass/branches/develbranch_6/lib/db/dbmi_base/login.c
Log:
change to new db login file, this time with '|' as fs so it can survive spaces in the db pathname and passwd (#809, merge from trunk)
Modified: grass/branches/develbranch_6/lib/db/dbmi_base/login.c
===================================================================
--- grass/branches/develbranch_6/lib/db/dbmi_base/login.c 2010-01-11 00:39:09 UTC (rev 40368)
+++ grass/branches/develbranch_6/lib/db/dbmi_base/login.c 2010-01-11 00:41:03 UTC (rev 40369)
@@ -6,6 +6,7 @@
#include <unistd.h>
#include <grass/gis.h>
#include <grass/dbmi.h>
+#include <grass/glocale.h>
typedef struct
{
@@ -27,7 +28,7 @@
if (!file) {
file = (char *)malloc(1000);
- sprintf(file, "%s/.grasslogin6", G_home());
+ sprintf(file, "%s/.grasslogin64", G_home());
}
return file;
}
@@ -58,7 +59,7 @@
}
/*
- Read file if exists
+ Read the DB login file if it exists
return: -1 error (cannot read file)
number of items (0 also if file does not exist)
*/
@@ -73,7 +74,7 @@
login->n = 0;
file = login_filename();
- G_debug(3, "file = <%s>", file);
+ G_debug(3, "DB login file = <%s>", file);
if (stat(file, &info) != 0) {
G_debug(3, "login file does not exist");
@@ -88,14 +89,13 @@
G_chop(buf);
usr[0] = pwd[0] = '\0';
- /* FIXME: not safe for spaces in DB path name */
- ret = sscanf(buf, "%[^ ] %[^ ] %[^ ] %[^ ]", dr, db, usr, pwd);
+ ret = sscanf(buf, "%[^|]|%[^|]|%[^|]|%[^\n]", dr, db, usr, pwd);
- G_debug(3, "ret = %d : dr=[%s] db=[%s] us=[%s] pw=[%s]",
+ G_debug(3, "ret = %d : drv=[%s] db=[%s] usr=[%s] pwd=[%s]",
ret, dr, db, usr, pwd);
if (ret < 2) {
- G_warning("Login file corrupted");
+ G_warning(_("Login file corrupted"));
continue;
}
@@ -108,7 +108,7 @@
}
/*
- Write file
+ Write the DB login file
return: -1 error (cannot read file)
0 OK
*/
@@ -120,7 +120,7 @@
file = login_filename();
- G_debug(3, "file = %s", file);
+ G_debug(3, "DB login file = <%s>", file);
fd = fopen(file, "w");
if (fd == NULL)
@@ -131,12 +131,12 @@
chmod(file, S_IRUSR | S_IWUSR);
for (i = 0; i < login->n; i++) {
- fprintf(fd, "%s %s", login->data[i].driver, login->data[i].database);
+ fprintf(fd, "%s|%s", login->data[i].driver, login->data[i].database);
if (login->data[i].user) {
- fprintf(fd, " %s", login->data[i].user);
+ fprintf(fd, "|%s", login->data[i].user);
if (login->data[i].password)
- fprintf(fd, " %s", login->data[i].password);
+ fprintf(fd, "|%s", login->data[i].password);
}
fprintf(fd, "\n");
}
@@ -158,8 +158,8 @@
int i, found;
LOGIN login;
- G_debug(3, "db_set_login(): %s %s %s %s", driver, database, user,
- password);
+ G_debug(3, "db_set_login(): drv=[%s] db=[%s] usr=[%s] pwd=[%s]",
+ driver, database, user, password);
init_login(&login);
@@ -207,7 +207,7 @@
int i;
LOGIN login;
- G_debug(3, "db_get_login(): %s %s", driver, database);
+ G_debug(3, "db_get_login(): drv=[%s] db=[%s]", driver, database);
user[0] = '\0';
password[0] = '\0';
More information about the grass-commit
mailing list