summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Kelley <simon@thekelleys.org.uk>2022-11-07 23:00:34 +0000
committerSimon Kelley <simon@thekelleys.org.uk>2022-11-07 23:00:34 +0000
commit6c596f1cc1d92b2b90ef5ce043ace314eefa868b (patch)
tree14cc1b3a60445734e71a9335a1733a0f9eb4eb4b
parentdafa16c400ee9e96b8aec98a80cf3d57c6be4bbd (diff)
downloaddnsmasq-6c596f1cc1d92b2b90ef5ce043ace314eefa868b.tar.gz
Make specifying nameservers by name work for DBus API.
-rw-r--r--src/dbus.c74
-rw-r--r--src/dnsmasq.h1
-rw-r--r--src/option.c3
3 files changed, 59 insertions, 19 deletions
diff --git a/src/dbus.c b/src/dbus.c
index 870912a..ef80711 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -379,21 +379,6 @@ static DBusMessage* dbus_read_servers_ex(DBusMessage *message, int strings)
strcpy(str_addr, str);
}
- /* parse the IP address */
- if ((addr_err = parse_server(str_addr, &sdetails)) ||
- (addr_err = parse_server_addr(&sdetails)))
- {
- error = dbus_message_new_error_printf(message, DBUS_ERROR_INVALID_ARGS,
- "Invalid IP address '%s': %s",
- str, addr_err);
- break;
- }
-
- /* 0.0.0.0 for server address == NULL, for Dbus */
- if (addr.in.sin_family == AF_INET &&
- addr.in.sin_addr.s_addr == 0)
- flags |= SERV_LITERAL_ADDRESS;
-
if (strings)
{
char *p;
@@ -407,7 +392,31 @@ static DBusMessage* dbus_read_servers_ex(DBusMessage *message, int strings)
else
p = NULL;
- add_update_server(flags | SERV_FROM_DBUS, &addr, &source_addr, interface, str_domain, NULL);
+ if (strings && strlen(str_addr) == 0)
+ add_update_server(SERV_LITERAL_ADDRESS | SERV_FROM_DBUS, &addr, &source_addr, interface, str_domain, NULL);
+ else
+ {
+ if ((addr_err = parse_server(str_addr, &sdetails)))
+ {
+ error = dbus_message_new_error_printf(message, DBUS_ERROR_INVALID_ARGS,
+ "Invalid IP address '%s': %s",
+ str, addr_err);
+ break;
+ }
+
+ while (parse_server_next(&sdetails))
+ {
+ if ((addr_err = parse_server_addr(&sdetails)))
+ {
+ error = dbus_message_new_error_printf(message, DBUS_ERROR_INVALID_ARGS,
+ "Invalid IP address '%s': %s",
+ str, addr_err);
+ break;
+ }
+
+ add_update_server(flags | SERV_FROM_DBUS, &addr, &source_addr, interface, str_domain, NULL);
+ }
+ }
} while ((str_domain = p));
}
else
@@ -421,11 +430,40 @@ static DBusMessage* dbus_read_servers_ex(DBusMessage *message, int strings)
if (dbus_message_iter_get_arg_type(&string_iter) == DBUS_TYPE_STRING)
dbus_message_iter_get_basic(&string_iter, &str);
dbus_message_iter_next (&string_iter);
+
+ if ((addr_err = parse_server(str_addr, &sdetails)))
+ {
+ error = dbus_message_new_error_printf(message, DBUS_ERROR_INVALID_ARGS,
+ "Invalid IP address '%s': %s",
+ str, addr_err);
+ break;
+ }
- add_update_server(flags | SERV_FROM_DBUS, &addr, &source_addr, interface, str, NULL);
+ while (parse_server_next(&sdetails))
+ {
+ if ((addr_err = parse_server_addr(&sdetails)))
+ {
+ error = dbus_message_new_error_printf(message, DBUS_ERROR_INVALID_ARGS,
+ "Invalid IP address '%s': %s",
+ str, addr_err);
+ break;
+ }
+
+ /* 0.0.0.0 for server address == NULL, for Dbus */
+ if (addr.in.sin_family == AF_INET &&
+ addr.in.sin_addr.s_addr == 0)
+ flags |= SERV_LITERAL_ADDRESS;
+ else
+ flags &= ~SERV_LITERAL_ADDRESS;
+
+ add_update_server(flags | SERV_FROM_DBUS, &addr, &source_addr, interface, str, NULL);
+ }
} while (dbus_message_iter_get_arg_type(&string_iter) == DBUS_TYPE_STRING);
}
-
+
+ if (sdetails.resolved)
+ freeaddrinfo(sdetails.hostinfo);
+
/* jump to next element in outer array */
dbus_message_iter_next(&array_iter);
}
diff --git a/src/dnsmasq.h b/src/dnsmasq.h
index 9f06a7f..7b59823 100644
--- a/src/dnsmasq.h
+++ b/src/dnsmasq.h
@@ -1478,6 +1478,7 @@ void reset_option_bool(unsigned int opt);
struct hostsfile *expand_filelist(struct hostsfile *list);
char *parse_server(char *arg, struct server_details *sdetails);
char *parse_server_addr(struct server_details *sdetails);
+int parse_server_next(struct server_details *sdetails);
int option_read_dynfile(char *file, int flags);
/* forward.c */
diff --git a/src/option.c b/src/option.c
index ab36050..d067a16 100644
--- a/src/option.c
+++ b/src/option.c
@@ -1049,10 +1049,11 @@ char *parse_server_addr(struct server_details *sdetails)
}
else
return _("bad address");
+
return NULL;
}
-static int parse_server_next(struct server_details *sdetails)
+int parse_server_next(struct server_details *sdetails)
{
/* Looping over resolved addresses? */
if (sdetails->hostinfo)