summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Kelley <simon@thekelleys.org.uk>2012-08-10 17:10:54 +0100
committerSimon Kelley <simon@thekelleys.org.uk>2012-08-10 17:10:54 +0100
commitad094275b09782a526cba6413aeb574b132089dd (patch)
treee20d828e369965e2bd2677920018670d69976a25
parentc740e4f342a2a5de9d9e09bfe450e8996d25a9c7 (diff)
downloaddnsmasq-ad094275b09782a526cba6413aeb574b132089dd.tar.gz
Alternate DBus service name via --enable-dbusv2.63rc4
-rw-r--r--CHANGELOG5
-rw-r--r--dbus/DBus-interface3
-rw-r--r--man/dnsmasq.86
-rw-r--r--src/config.h2
-rw-r--r--src/dbus.c30
-rw-r--r--src/dnsmasq.h1
-rw-r--r--src/option.c12
7 files changed, 44 insertions, 15 deletions
diff --git a/CHANGELOG b/CHANGELOG
index c58d8f2..8828694 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -40,6 +40,11 @@ version 2.63
Update French translation. Thanks to Gildas Le Nadan.
+ Allow a DBus service name to be given with --enable-dbus
+ which overrides the default,
+ uk.org.thekelleys.dnsmasq. Thanks to Mathieu
+ Trudel-Lapierre for the patch.
+
version 2.62
Update German translation. Thanks to Conrad Kostecki.
diff --git a/dbus/DBus-interface b/dbus/DBus-interface
index 8d578ca..9fa08f2 100644
--- a/dbus/DBus-interface
+++ b/dbus/DBus-interface
@@ -19,7 +19,8 @@ and avoids startup races with the provider of nameserver information.
Dnsmasq provides one service on the DBus: uk.org.thekelleys.dnsmasq
-and a single object: /uk/org/thekelleys/dnsmasq
+and a single object: /uk/org/thekelleys/dnsmasq
+The name of the service may be changed by giving an argument to --enable-dbus.
1. METHODS
----------
diff --git a/man/dnsmasq.8 b/man/dnsmasq.8
index 9b2a689..89bc8a4 100644
--- a/man/dnsmasq.8
+++ b/man/dnsmasq.8
@@ -271,11 +271,13 @@ time is the one used.
Don't read /etc/resolv.conf. Get upstream servers only from the command
line or the dnsmasq configuration file.
.TP
-.B \-1, --enable-dbus
+.B \-1, --enable-dbus[=<service-name>]
Allow dnsmasq configuration to be updated via DBus method calls. The
configuration which can be changed is upstream DNS servers (and
corresponding domains) and cache clear. Requires that dnsmasq has
-been built with DBus support.
+been built with DBus support. If the service name is given, dnsmasq
+provides service at that name, rather than the default which is
+.B uk.org.thekelleys.dnsmasq
.TP
.B \-o, --strict-order
By default, dnsmasq will send queries to any of the upstream servers
diff --git a/src/config.h b/src/config.h
index 4a9fa2c..1a08e95 100644
--- a/src/config.h
+++ b/src/config.h
@@ -40,7 +40,7 @@
#define LOG_MAX 5 /* log-queue length */
#define RANDFILE "/dev/urandom"
#define EDNS0_OPTION_MAC 5 /* dyndns.org temporary assignment */
-#define DNSMASQ_SERVICE "uk.org.thekelleys.dnsmasq" /* DBUS interface specifics */
+#define DNSMASQ_SERVICE "uk.org.thekelleys.dnsmasq" /* Default - may be overridden by config */
#define DNSMASQ_PATH "/uk/org/thekelleys/dnsmasq"
/* compile-time options: uncomment below to enable or do eg.
diff --git a/src/dbus.c b/src/dbus.c
index a6e3e98..16a05e8 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -20,7 +20,7 @@
#include <dbus/dbus.h>
-const char* introspection_xml =
+const char* introspection_xml_template =
"<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
"\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
"<node name=\"" DNSMASQ_PATH "\">\n"
@@ -29,7 +29,7 @@ const char* introspection_xml =
" <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
" </method>\n"
" </interface>\n"
-" <interface name=\"" DNSMASQ_SERVICE "\">\n"
+" <interface name=\"%s\">\n"
" <method name=\"ClearCache\">\n"
" </method>\n"
" <method name=\"GetVersion\">\n"
@@ -56,6 +56,8 @@ const char* introspection_xml =
" </interface>\n"
"</node>\n";
+static char *introspection_xml = NULL;
+
struct watch {
DBusWatch *watch;
struct watch *next;
@@ -266,11 +268,21 @@ DBusHandlerResult message_handler(DBusConnection *connection,
if (dbus_message_is_method_call(message, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
{
- DBusMessage *reply = dbus_message_new_method_return(message);
+ DBusMessage *reply;
- dbus_message_append_args(reply, DBUS_TYPE_STRING, &introspection_xml, DBUS_TYPE_INVALID);
- dbus_connection_send (connection, reply, NULL);
- dbus_message_unref (reply);
+ /* string length: "%s" provides space for termination zero */
+ if (!introspection_xml &&
+ (introspection_xml = whine_malloc(strlen(introspection_xml_template) + strlen(daemon->dbus_name))))
+ sprintf(introspection_xml, introspection_xml_template, daemon->dbus_name);
+
+ if (introspection_xml)
+ {
+ reply = dbus_message_new_method_return(message);
+
+ dbus_message_append_args(reply, DBUS_TYPE_STRING, &introspection_xml, DBUS_TYPE_INVALID);
+ dbus_connection_send (connection, reply, NULL);
+ dbus_message_unref (reply);
+ }
}
else if (strcmp(method, "GetVersion") == 0)
{
@@ -315,7 +327,7 @@ char *dbus_init(void)
dbus_connection_set_watch_functions(connection, add_watch, remove_watch,
NULL, NULL, NULL);
dbus_error_init (&dbus_error);
- dbus_bus_request_name (connection, DNSMASQ_SERVICE, 0, &dbus_error);
+ dbus_bus_request_name (connection, daemon->dbus_name, 0, &dbus_error);
if (dbus_error_is_set (&dbus_error))
return (char *)dbus_error.message;
@@ -325,7 +337,7 @@ char *dbus_init(void)
daemon->dbus = connection;
- if ((message = dbus_message_new_signal(DNSMASQ_PATH, DNSMASQ_SERVICE, "Up")))
+ if ((message = dbus_message_new_signal(DNSMASQ_PATH, daemon->dbus_name, "Up")))
{
dbus_connection_send(connection, message, NULL);
dbus_message_unref(message);
@@ -430,7 +442,7 @@ void emit_dbus_signal(int action, struct dhcp_lease *lease, char *hostname)
else
return;
- if (!(message = dbus_message_new_signal(DNSMASQ_PATH, DNSMASQ_SERVICE, action_str)))
+ if (!(message = dbus_message_new_signal(DNSMASQ_PATH, daemon->dbus_name, action_str)))
return;
dbus_message_iter_init_append(message, &args);
diff --git a/src/dnsmasq.h b/src/dnsmasq.h
index de26e8d..b131c96 100644
--- a/src/dnsmasq.h
+++ b/src/dnsmasq.h
@@ -777,6 +777,7 @@ extern struct daemon {
struct tftp_prefix *if_prefix; /* per-interface TFTP prefixes */
unsigned int duid_enterprise, duid_config_len;
unsigned char *duid_config;
+ char *dbus_name;
/* globally used stuff for DNS */
char *packet; /* packet buffer */
diff --git a/src/option.c b/src/option.c
index 8e7107e..22c08e7 100644
--- a/src/option.c
+++ b/src/option.c
@@ -184,7 +184,7 @@ static const struct myoption opts[] =
{ "localise-queries", 0, 0, 'y' },
{ "txt-record", 1, 0, 'Y' },
{ "dns-rr", 1, 0, LOPT_RR },
- { "enable-dbus", 0, 0, '1' },
+ { "enable-dbus", 2, 0, '1' },
{ "bootp-dynamic", 2, 0, '3' },
{ "dhcp-mac", 1, 0, '4' },
{ "no-ping", 0, 0, '5' },
@@ -326,7 +326,7 @@ static struct {
{ LOPT_INTNAME, ARG_DUP, "<name>,<interface>", gettext_noop("Give DNS name to IPv4 address of interface."), NULL },
{ 'z', OPT_NOWILD, NULL, gettext_noop("Bind only to interfaces in use."), NULL },
{ 'Z', OPT_ETHERS, NULL, gettext_noop("Read DHCP static host information from %s."), ETHERSFILE },
- { '1', OPT_DBUS, NULL, gettext_noop("Enable the DBus interface for setting upstream servers, etc."), NULL },
+ { '1', ARG_ONE, "[=<busname>]", gettext_noop("Enable the DBus interface for setting upstream servers, etc."), NULL },
{ '2', ARG_DUP, "<interface>", gettext_noop("Do not provide DHCP on this interface, only provide DNS."), NULL },
{ '3', ARG_DUP, "[=tag:<tag>]...", gettext_noop("Enable dynamic address allocation for bootp."), NULL },
{ '4', ARG_DUP, "set:<tag>,<mac address>", gettext_noop("Map MAC address (with wildcards) to option set."), NULL },
@@ -1285,6 +1285,14 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
break;
}
+ case '1': /* --enable-dbus */
+ set_option_bool(OPT_DBUS);
+ if (arg)
+ daemon->dbus_name = opt_string_alloc(arg);
+ else
+ daemon->dbus_name = DNSMASQ_SERVICE;
+ break;
+
case '8': /* --log-facility */
/* may be a filename */
if (strchr(arg, '/') || strcmp (arg, "-") == 0)