3228e85fa927785f7b52ad8320ef9f3484509424
galt
  Wed Aug 5 01:00:31 2015 -0700
Initial check-in for Add-SSL-Support-Options to jksql.c and to hgsql-and-family functions.

diff --git src/hg/lib/sqlProg.c src/hg/lib/sqlProg.c
index dcadd13..a6ca8ed 100644
--- src/hg/lib/sqlProg.c
+++ src/hg/lib/sqlProg.c
@@ -1,25 +1,26 @@
 /* sqlProg - functions for building command line programs to deal with
  * sql databases.*/
 
 /* Copyright (C) 2014 The Regents of the University of California 
  * See README in this or parent directory for licensing information. */
 #include "common.h"
 #include "sqlProg.h"
 #include "hgConfig.h"
 #include "obscure.h"
 #include "portable.h"
+#include "jksql.h"
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <signal.h>
 
 char *tempFileNameToRemove = NULL;
 int killChildPid = 0;
 
 /* trap signals to remove the temporary file and terminate the child process */
 
 static void sqlProgCatchSignal(int sigNum)
 /* handler for various terminal signals for removing the temp file */
 {
 
 if (tempFileNameToRemove)
     unlink(tempFileNameToRemove);
@@ -76,46 +77,45 @@
 {
 if (fileExists(path))
     {
     char *cnf = NULL;
     size_t cnfSize = 0;
     readInGulp(path, &cnf, &cnfSize);
     if (write (fileNo, cnf, cnfSize) == -1)
         {
         freeMem(cnf);
 	errAbort("Writing %s to file %s failed with errno %d", path, defaultFileName, errno);
         }
     freeMem(cnf);
     }
 }
 
-
 int sqlMakeDefaultsFile(char* defaultFileName, char* profile, char* group)
 /* Create a temporary file in the supplied directory to be passed to
  * mysql with --defaults-file.  Writes a mysql options set for
  * the mysql group [group] with the profile.host, profile.user, and
  * profile.password values returned from cfgVal().  If group is not
  * client or mysql, a --defaults-group-suffix=group must be passed to
  * mysql to actually invoke the settings.
  * passFileName cannot be static, and the last 6 characters must
  * be XXXXXX.  Those characters will be modified to form a unique suffix.
  * Returns a file descriptor for the file or dies with an error */
 {
 int fileNo;
 char paddedGroup [256]; /* string with brackets around the group name */
-char fileData[256];  /* constructed variable=value data for the mysql config file */
-char field[256];  /* constructed profile.field name to pass to cfgVal */
+//char fileData[256];  /* constructed variable=value data for the mysql config file */
+//char field[256];  /* constructed profile.field name to pass to cfgVal */
 char path[1024];
 
 if ((fileNo=mkstemp(defaultFileName)) == -1)
     errAbort("Could not create unique temporary file %s", defaultFileName);
 tempFileNameToRemove = defaultFileName;
 
 /* pick up the global and local defaults
  *  -- the order matters: later settings over-ride earlier ones. */
 
 safef(path, sizeof path, "/etc/my.cnf");
 copyCnfToDefaultsFile(path, defaultFileName, fileNo);
 
 safef(path, sizeof path, "/etc/mysql/my.cnf");
 copyCnfToDefaultsFile(path, defaultFileName, fileNo);
 
@@ -123,44 +123,36 @@
 copyCnfToDefaultsFile(path, defaultFileName, fileNo);
 
 //  SYSCONFDIR/my.cnf should be next, but I do not think it matters. maybe it is just /var/lib/mysql anyways.
 
 safef(path, sizeof path, "%s/my.cnf", getenv("MYSQL_HOME"));
 copyCnfToDefaultsFile(path, defaultFileName, fileNo);
 
 safef(path, sizeof path, "%s/.my.cnf", getenv("HOME"));
 copyCnfToDefaultsFile(path, defaultFileName, fileNo);
 
 /* write out the group name, user, host, and password */
 safef(paddedGroup, sizeof(paddedGroup), "[%s]\n", group);
 if (write (fileNo, paddedGroup, strlen(paddedGroup)) == -1)
     errAbort("Writing group to temporary file %s failed with errno %d", defaultFileName, errno);
 
-safef(field, sizeof(field), "%s.host", profile);
-safef(fileData, sizeof(fileData), "host=%s\n", cfgVal(field));
-if (write (fileNo, fileData, strlen(fileData)) == -1)
-    errAbort("Writing host to temporary file %s failed with errno %d", defaultFileName, errno);
-
-safef(field, sizeof(field), "%s.user", profile);
-safef(fileData, sizeof(fileData), "user=%s\n", cfgVal(field));
-if (write (fileNo, fileData, strlen(fileData)) == -1)
-    errAbort("Writing user to temporary file %s failed with errno %d", defaultFileName, errno);
+char *settings = sqlProfileToMyCnf(profile);
+if (!settings)
+    errAbort("profile %s not found in sqlProfileToMyCnf() -- failed for file %s failed with errno %d", profile, defaultFileName, errno);
+if (write (fileNo, settings, strlen(settings)) == -1)
+    errAbort("Writing profile %s settings=[%s] as my.cnf format failed for file %s failed with errno %d", profile, settings, defaultFileName, errno);
 
-safef(field, sizeof(field), "%s.password", profile);
-safef(fileData, sizeof(fileData), "password=%s\n", cfgVal(field));
-if (write (fileNo, fileData, strlen(fileData)) == -1)
-    errAbort("Writing password to temporary file %s failed with errno %d", defaultFileName, errno);
 
 return fileNo;
 }
 
 
 void sqlExecProg(char *prog, char **progArgs, int userArgc, char *userArgv[])
 /* Exec one of the sql programs using user and password from ~/.hg.conf.
  * progArgs is NULL-terminate array of program-specific arguments to add,
  * which maybe NULL. userArgv are arguments passed in from the command line.
  * The program is execvp-ed, this function does not return. */
 {
 sqlExecProgProfile("db", prog, progArgs, userArgc, userArgv);
 }