8 #include <grass/dbmi.h>
9 #include <grass/glocale.h>
25 static const char *login_filename(
void)
30 file = (
char *)
malloc(1000);
48 if (login->
n == login->
a) {
51 (
DATA *) realloc((
void *)login->
data, login->
a *
sizeof(
DATA));
72 char buf[2001], dr[500], db[500], usr[500], pwd[500];
75 file = login_filename();
77 G_debug(3,
"DB login file = <%s>", file);
79 if (
stat(file, &info) != 0) {
80 G_debug(3,
"login file does not exist");
84 fd = fopen(file,
"r");
88 while (
G_getl2(buf, 2000, fd)) {
91 usr[0] = pwd[0] =
'\0';
92 ret = sscanf(buf,
"%[^|]|%[^|]|%[^|]|%[^\n]", dr, db, usr, pwd);
94 G_debug(3,
"ret = %d : drv=[%s] db=[%s] usr=[%s] pwd=[%s]",
95 ret, dr, db, usr, pwd);
121 file = login_filename();
123 G_debug(3,
"DB login file = <%s>", file);
125 fd = fopen(file,
"w");
131 chmod(file, S_IRUSR | S_IWUSR);
133 for (i = 0; i < login->
n; i++) {
136 fprintf(fd,
"|%s", login->
data[i].
user);
156 const char *password)
161 G_debug(3,
"db_set_login(): drv=[%s] db=[%s] usr=[%s] pwd=[%s]",
162 driver, database, user, password);
170 for (i = 0; i < login.
n; i++) {
171 if (strcmp(login.
data[i].
driver, driver) == 0 &&
189 add_login(&login, driver, database, user, password);
205 const char **password)
210 G_debug(3,
"db_get_login(): drv=[%s] db=[%s]", driver, database);
220 for (i = 0; i < login.
n; i++) {
221 if (strcmp(login.
data[i].
driver, driver) == 0 &&
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
int write_file(LOGIN *login)
char * G_store(const char *s)
Copy string to allocated memory.
void init_login(LOGIN *login)
char * G_chop(char *line)
Chop leading and trailing white spaces:
int G_getl2(char *buf, int n, FILE *fd)
gets a line of text from a file of any pedigree
char * G_home(void)
user's home directory
int db_set_login(const char *driver, const char *database, const char *user, const char *password)
Set user/password for driver/database.
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int G_debug(int level, const char *msg,...)
Print debugging message.
int read_file(LOGIN *login)
int db_get_login(const char *driver, const char *database, const char **user, const char **password)
Get user/password for driver/database if driver/database is not found, user/password are set to NULL...
void add_login(LOGIN *login, const char *dr, const char *db, const char *usr, const char *pwd)