[freetds] patch for freebcp: take password from stdin instead of command line

Constantin Vasilyev vasilyev at ncbi.nlm.nih.gov
Tue Oct 3 22:41:13 EDT 2006


It is useful for database client tool to be able to hide password.
Patch below makes freebcp to read password from stdin if '-' is supplied
as a parameter for -P option ( -P- ). This way the password can't be seen
by others via ps -f.

Constantin Vasilyev
NCBI Contractor, DBA


---8<--------------------------------------------------------------


Index: freebcp.c
===================================================================
RCS file: /cvsroot/freetds/freetds/src/apps/freebcp.c,v
retrieving revision 1.45
diff -u -r1.45 freebcp.c
--- freebcp.c   12 Jun 2006 19:45:59 -0000      1.45
+++ freebcp.c   4 Oct 2006 02:14:02 -0000
@@ -257,7 +257,16 @@
                        break;
                case 'P':
                        pdata->Pflag++;
-                       pdata->pass = strdup(optarg);
+                       if ((strcmp(optarg, "-")) == 0) {
+                               char pwd[255], *nl;
+                               memset(pwd, 0, 255);
+                               fgets(pwd, 255, stdin);
+                               nl = strchr(pwd, '\n');
+                               if(nl) *nl = '\0';
+                               pdata->pass = strdup(pwd);
+                       } else {
+                               pdata->pass = strdup(optarg);
+                       }
                        break;
                case 'I':
                        pdata->Iflag++;



More information about the FreeTDS mailing list