]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mysql: Don't require connect setting to have host-parameter if option_file is set.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 31 Dec 2015 02:26:01 +0000 (04:26 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 31 Dec 2015 02:27:03 +0000 (04:27 +0200)
The option_file could also specify the host.

src/lib-sql/driver-mysql.c

index 72a3d1fb910913138b905165a9182040f513582e..1f3da9b46ffc4bf69e8478603f5ddb31e9a78d93 100644 (file)
@@ -72,7 +72,8 @@ extern const struct sql_result driver_mysql_error_result;
 
 static const char *mysql_prefix(struct mysql_db *db)
 {
-       return t_strdup_printf("mysql(%s)", db->host);
+       return db->host == NULL ? "mysql" :
+               t_strdup_printf("mysql(%s)", db->host);
 }
 
 static int driver_mysql_connect(struct sql_db *_db)
@@ -88,7 +89,12 @@ static int driver_mysql_connect(struct sql_db *_db)
 
        sql_db_set_state(&db->api, SQL_DB_STATE_CONNECTING);
 
-       if (*db->host == '/') {
+       if (db->host == NULL) {
+               /* assume option_file overrides the host, or if not we'll just
+                  connect to localhost */
+               unix_socket = NULL;
+               host = NULL;
+       } else if (*db->host == '/') {
                unix_socket = db->host;
                host = NULL;
        } else {
@@ -235,7 +241,7 @@ static void driver_mysql_parse_connect_string(struct mysql_db *db,
                        *field = p_strdup(db->pool, value);
        }
 
-       if (db->host == NULL)
+       if (db->host == NULL && db->option_file == NULL)
                i_fatal("mysql: No hosts given in connect string");
 
        db->mysql = mysql_init(NULL);