Re: Hiding password in fisql and bsqldb
"Frediano Ziglio" <[email protected]>
| Newsgroups | gmane.comp.db.tds.freetds |
|---|---|
| Message-ID | <[email protected]> |
2008/12/23 James K. Lowden <[email protected]>: > Peter Chase wrote: >> I'm trying to use fisql and bsqldb in a bash script and I'm having >> problems finding a way to hide the password from the ps command without >> requiring user input. > > Yeah, it's a problem. On my agenda for some time is adding the ability to > use $HOME/.netrc for that purpose, as some ftp clients do. sqsh uses > .sqshrc to do the same thing (except limited to one > server+username+password tuple). > > It would be a welcome patch. > Just an easy patch that ask password if not supplied with -P (code mainly from tsql) freddy77 _______________________________________________ FreeTDS mailing list [email protected] http://lists.ibiblio.org/mailman/listinfo/freetds
pwd.diff
(application/octet-stream, 1.6 KB)
Index: src/apps/bsqldb.c
===================================================================
RCS file: /cvs/freetds/freetds/src/apps/bsqldb.c,v
retrieving revision 1.33
diff -u -1 -0 -r1.33 bsqldb.c
--- src/apps/bsqldb.c 23 Apr 2008 21:35:45 -0000 1.33
+++ src/apps/bsqldb.c 23 Dec 2008 08:14:19 -0000
@@ -748,20 +748,21 @@
escaped = '1';
}
}
}
LOGINREC *
get_login(int argc, char *argv[], OPTIONS *options)
{
LOGINREC *login;
int ch;
+ int got_password = 0;
extern char *optarg;
assert(options && argv);
options->appname = tds_basename(argv[0]);
options->colsep = default_colsep; /* may be overridden by -t */
login = dblogin();
@@ -777,20 +778,21 @@
} else {
DBSETLHOST(login, options->hostname);
}
while ((ch = getopt(argc, argv, "U:P:S:dD:i:o:e:t:hqv")) != -1) {
switch (ch) {
case 'U':
DBSETLUSER(login, optarg);
break;
case 'P':
+ got_password = 1;
DBSETLPWD(login, optarg);
break;
case 'S':
options->servername = strdup(optarg);
break;
case 'd':
case 'D':
options->database = strdup(optarg);
break;
case 'i':
@@ -814,21 +816,28 @@
break;
case 'v':
options->fverbose = 1;
break;
case '?':
default:
usage(options->appname);
exit(1);
}
}
-
+
+ if (!got_password) {
+ char password[128];
+
+ readpassphrase("Password: ", password, sizeof(password), RPP_ECHO_OFF);
+ DBSETLPWD(login, password);
+ }
+
if (!options->servername) {
usage(options->appname);
exit(1);
}
return login;
}
int
err_handler(DBPROCESS * dbproc, int severity, int dberr, int oserr, char *dberrstr, char *oserrstr)