[Opendnssec-commits] [keihatsu.kirei.se/svn/dnssec] r4141 - in trunk/OpenDNSSEC/enforcer: common ksm ksm/include/ksm

Sion Lloyd sion at nominet.org.uk
Mon Oct 25 17:26:40 CEST 2010


Author: sion
Date: 2010-10-25 17:26:40 +0200 (Mon, 25 Oct 2010)
New Revision: 4141

Modified:
   trunk/OpenDNSSEC/enforcer/common/kaspaccess.c
   trunk/OpenDNSSEC/enforcer/ksm/database_connection_mysql.c
   trunk/OpenDNSSEC/enforcer/ksm/include/ksm/string_util2.h
   trunk/OpenDNSSEC/enforcer/ksm/string_util2.c
Log:
Allow connection to different MySQL ports, pivotal story 1688621. (Note, if connecting to localhost then the port is not used; so you can not test it this way.)


Modified: trunk/OpenDNSSEC/enforcer/common/kaspaccess.c
===================================================================
--- trunk/OpenDNSSEC/enforcer/common/kaspaccess.c	2010-10-25 14:11:31 UTC (rev 4140)
+++ trunk/OpenDNSSEC/enforcer/common/kaspaccess.c	2010-10-25 15:26:40 UTC (rev 4141)
@@ -129,7 +129,7 @@
 kaspConnect(DAEMONCONFIG* config, DB_HANDLE	*handle)
 {
     /* Note that all these XML derived strings are unsigned chars */
-	if (DbConnect(handle, (char *)config->schema, (char *)config->host, (char *)config->password, (char *)config->user) != 0) {
+	if (DbConnect(handle, (char *)config->schema, (char *)config->host, (char *)config->password, (char *)config->user, (char *)config->port) != 0) {
         unlink(config->pidfile);
         exit(-1);
     }

Modified: trunk/OpenDNSSEC/enforcer/ksm/database_connection_mysql.c
===================================================================
--- trunk/OpenDNSSEC/enforcer/ksm/database_connection_mysql.c	2010-10-25 14:11:31 UTC (rev 4140)
+++ trunk/OpenDNSSEC/enforcer/ksm/database_connection_mysql.c	2010-10-25 15:26:40 UTC (rev 4141)
@@ -42,6 +42,7 @@
 #include "ksm/database.h"
 #include "ksm/dbsdef.h"
 #include "ksm/message.h"
+#include "ksm/string_util2.h"
 
 static MYSQL* m_dbhandle = NULL;  /* Non-NULL if connected */
 
@@ -100,6 +101,8 @@
     const char* host = NULL;        /* Host on which database resides */
     const char* password = NULL;    /* Connection password */
     const char* user = NULL;        /* Connection username */
+    const char* char_port = NULL;   /* Char version of connection port */
+    unsigned int port = 0;          /* For mysql_real_connect */
     va_list     ap;                 /* Argument pointer */
     int         status = 0;         /* Return status */
 
@@ -113,8 +116,18 @@
     host = va_arg(ap, const char*);
     password = va_arg(ap, const char*);
     user = va_arg(ap, const char*);
+    char_port = va_arg(ap, const char*);
     va_end(ap);
 
+    /* Convert the port, we will leave it as 0 if there is nothing set */
+    if (char_port != NULL) {
+        status = StrStrtoui(char_port, &port);
+
+        if (status != 0) {
+            return status;
+        }
+    }
+
     /* ... and connect */
 
     connection = mysql_init(NULL);
@@ -123,7 +136,7 @@
         /* Connect to the database */
 
         ptrstatus = mysql_real_connect(connection, host, user, password,
-            database, 0, NULL, CLIENT_INTERACTIVE);
+            database, port, NULL, CLIENT_INTERACTIVE);
         if (ptrstatus) {
 
             /* Enable autocommit */

Modified: trunk/OpenDNSSEC/enforcer/ksm/include/ksm/string_util2.h
===================================================================
--- trunk/OpenDNSSEC/enforcer/ksm/include/ksm/string_util2.h	2010-10-25 14:11:31 UTC (rev 4140)
+++ trunk/OpenDNSSEC/enforcer/ksm/include/ksm/string_util2.h	2010-10-25 15:26:40 UTC (rev 4141)
@@ -60,6 +60,7 @@
 int StrStrtol(const char* string, long* value);
 int StrStrtoul(const char* string, unsigned long* value);
 int StrStrtoi(const char* string, int* value);
+int StrStrtoui(const char* string, unsigned int* value);
 int StrIsDigits(const char* string);
 
 #ifdef __cplusplus

Modified: trunk/OpenDNSSEC/enforcer/ksm/string_util2.c
===================================================================
--- trunk/OpenDNSSEC/enforcer/ksm/string_util2.c	2010-10-25 14:11:31 UTC (rev 4140)
+++ trunk/OpenDNSSEC/enforcer/ksm/string_util2.c	2010-10-25 15:26:40 UTC (rev 4141)
@@ -527,8 +527,49 @@
     return status;
 }
 
+/*+
+ * StrStrtoui - Convert String to unsigned int
+ *
+ * Description:
+ *      Converts a string to a "unsigned int".
+ *
+ *      This version strips out tabs and whitespace characters.
+ *
+ * Arguments:
+ *      const char* string (input)
+ *          String to convert.
+ *
+ *      unsigned int* value (returned)
+ *          Return value.
+ *
+ * Returns:
+ *      int
+ *          0   Success
+ *          1   Conversion failed
+-*/
 
+int StrStrtoui(const char* string, unsigned int* value)
+{
+    unsigned long    longval;    /* "long" to be passed to StrStrtol */
+    int     status;     /* Status return */
 
+    if (value == NULL) {
+        MsgLog(KSM_INVARG, "NULL value");
+        return 1;
+    }
+    status = StrStrtoul(string, &longval);
+    if (status == 0) {
+        if (longval <= UINT_MAX) {
+            *value = (unsigned int) longval;
+        }
+        else {
+            status = 1;     /* Integer overflow */
+        }
+    }
+
+    return status;
+}
+
 /*+
  * StrIsDigits - Check String for All Digits
  *




More information about the Opendnssec-commits mailing list