Commit afbb33cf afbb33cf9ff750e93a9a4c1f51a3b62d584f056e by Sergey Poznyakoff

Fix a bug in field-map handling.

* libmailutils/cfg/driver.c (parse_mapping): Fix expected value type.
* libmu_auth/sql.c (get_field): Remove left-over mu_assoc_ref call
(see 622bc770).
1 parent afda9ba4
...@@ -72,7 +72,7 @@ is the same as for the global section described above, e.g.: ...@@ -72,7 +72,7 @@ is the same as for the global section described above, e.g.:
72 72
73 If the "tls" section is absent, but "tls-mode" is specified and it's 73 If the "tls" section is absent, but "tls-mode" is specified and it's
74 value is anything but "no", the settings from the global "tls" section 74 value is anything but "no", the settings from the global "tls" section
75 will be used. Im this case, it is an error if the global "tls" 75 will be used. In this case, it is an error if the global "tls"
76 section is not defined. 76 section is not defined.
77 77
78 78
......
...@@ -617,10 +617,15 @@ static int ...@@ -617,10 +617,15 @@ static int
617 parse_mapping (void *item, void *data) 617 parse_mapping (void *item, void *data)
618 { 618 {
619 struct mapping_closure *clos = data; 619 struct mapping_closure *clos = data;
620 char *str = item; 620 struct mu_config_value *cval = item;
621 char const *str;
621 size_t len; 622 size_t len;
622 char *key, *val; 623 char *key, *val;
623 int rc; 624 int rc;
625
626 if (mu_cfg_assert_value_type (cval, MU_CFG_STRING))
627 return 1;
628 str = cval->v.string;
624 629
625 len = strcspn (str, "="); 630 len = strcspn (str, "=");
626 if (str[len] == 0) 631 if (str[len] == 0)
......
...@@ -214,20 +214,23 @@ mu_sql_expand_query (const char *query, const char *ustr) ...@@ -214,20 +214,23 @@ mu_sql_expand_query (const char *query, const char *ustr)
214 static int 214 static int
215 get_field (mu_sql_connection_t conn, const char *id, char **ret, int mandatory) 215 get_field (mu_sql_connection_t conn, const char *id, char **ret, int mandatory)
216 { 216 {
217 const char **name = mu_assoc_ref (mu_sql_module_config.field_map, id); 217 int rc;
218 int rc = mu_sql_get_field (conn, 0, name ? *name : id, ret); 218 const char *name = mu_assoc_get (mu_sql_module_config.field_map, id);
219 if (!name)
220 name = id;
221 rc = mu_sql_get_field (conn, 0, name, ret);
219 if (rc) 222 if (rc)
220 { 223 {
221 if (mandatory || rc != MU_ERR_NOENT) 224 if (mandatory || rc != MU_ERR_NOENT)
222 mu_error (_("cannot get SQL field `%s' (`%s'): %s"), 225 mu_error (_("cannot get SQL field `%s' (`%s'): %s"),
223 id, name ? *name : id, mu_strerror (rc)); 226 id, name, mu_strerror (rc));
224 } 227 }
225 else if (!*ret) 228 else if (!*ret)
226 { 229 {
227 if (mandatory) 230 if (mandatory)
228 { 231 {
229 mu_error (_("SQL field `%s' (`%s') has NULL value"), 232 mu_error (_("SQL field `%s' (`%s') has NULL value"),
230 id, name ? *name : id); 233 id, name);
231 rc = MU_ERR_READ; 234 rc = MU_ERR_READ;
232 } 235 }
233 else 236 else
......