[libvirt] [PATCH 0/2] Fix network names with quotes

The following series implements... --- Shivaprasad G Bhat (2): fix domaincommon.rng to accept network name with quotes escape quotes for dsmasq conf contents docs/schemas/domaincommon.rng | 2 +- src/util/virdnsmasq.c | 25 +++++++++++++++---- src/util/virpidfile.c | 15 ++++++++---- .../nat-network-name-with-quotes.conf | 20 +++++++++++++++ .../nat-network-name-with-quotes.xml | 26 ++++++++++++++++++++ tests/networkxml2conftest.c | 1 + 6 files changed, 79 insertions(+), 10 deletions(-) create mode 100644 tests/networkxml2confdata/nat-network-name-with-quotes.conf create mode 100644 tests/networkxml2confdata/nat-network-name-with-quotes.xml -- Signature

The network name is currently of type "deviceName" but it should be "text" as name is defined in the network.rng. Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com> --- docs/schemas/domaincommon.rng | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 7c6fa5c..5dc48f7 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -2065,7 +2065,7 @@ <interleave> <element name="source"> <attribute name="network"> - <ref name="deviceName"/> + <text/> </attribute> <optional> <attribute name="portgroup">

On 06/01/2015 04:07 AM, Shivaprasad G Bhat wrote:
The network name is currently of type "deviceName" but it should be "text" as name is defined in the network.rng.
Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com> --- docs/schemas/domaincommon.rng | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 7c6fa5c..5dc48f7 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -2065,7 +2065,7 @@ <interleave> <element name="source"> <attribute name="network"> - <ref name="deviceName"/> + <text/> </attribute> <optional> <attribute name="portgroup">
Since the name element in the network XML is defined as <text/>, it makes sense to do the same here. ACK.

dnsmasq conf file contents needs to have quotes escaped for it to work. Because of this, the network-create/start for a network with quotes in the name fails. The patch escapes strings for the entries that go into the conf file. Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com> --- src/util/virdnsmasq.c | 25 +++++++++++++++---- src/util/virpidfile.c | 15 ++++++++---- .../nat-network-name-with-quotes.conf | 20 +++++++++++++++ .../nat-network-name-with-quotes.xml | 26 ++++++++++++++++++++ tests/networkxml2conftest.c | 1 + 5 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 tests/networkxml2confdata/nat-network-name-with-quotes.conf create mode 100644 tests/networkxml2confdata/nat-network-name-with-quotes.xml diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c index 6a2a2fb..18e53a3 100644 --- a/src/util/virdnsmasq.c +++ b/src/util/virdnsmasq.c @@ -151,6 +151,7 @@ addnhostsNew(const char *name, const char *config_dir) { dnsmasqAddnHostsfile *addnhostsfile; + virBuffer buf = VIR_BUFFER_INITIALIZER; if (VIR_ALLOC(addnhostsfile) < 0) return NULL; @@ -158,13 +159,20 @@ addnhostsNew(const char *name, addnhostsfile->hosts = NULL; addnhostsfile->nhosts = 0; - if (virAsprintf(&addnhostsfile->path, "%s/%s.%s", config_dir, name, - DNSMASQ_ADDNHOSTSFILE_SUFFIX) < 0) + virBufferAsprintf(&buf, "%s", config_dir); + virBufferEscapeString(&buf, "/%s", name); + virBufferAsprintf(&buf, ".%s", DNSMASQ_ADDNHOSTSFILE_SUFFIX); + + if (virBufferCheckError(&buf) < 0) + goto error; + + if (!(addnhostsfile->path = virBufferContentAndReset(&buf))) goto error; return addnhostsfile; error: + virBufferFreeAndReset(&buf); addnhostsFree(addnhostsfile); return NULL; } @@ -357,6 +365,7 @@ hostsfileNew(const char *name, const char *config_dir) { dnsmasqHostsfile *hostsfile; + virBuffer buf = VIR_BUFFER_INITIALIZER; if (VIR_ALLOC(hostsfile) < 0) return NULL; @@ -364,13 +373,19 @@ hostsfileNew(const char *name, hostsfile->hosts = NULL; hostsfile->nhosts = 0; - if (virAsprintf(&hostsfile->path, "%s/%s.%s", config_dir, name, - DNSMASQ_HOSTSFILE_SUFFIX) < 0) - goto error; + virBufferAsprintf(&buf, "%s", config_dir); + virBufferEscapeString(&buf, "/%s", name); + virBufferAsprintf(&buf, ".%s", DNSMASQ_HOSTSFILE_SUFFIX); + if (virBufferCheckError(&buf) < 0) + goto error; + + if (!(hostsfile->path = virBufferContentAndReset(&buf))) + goto error; return hostsfile; error: + virBufferFreeAndReset(&buf); hostsfileFree(hostsfile); return NULL; } diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c index 8144ff9..58ab29f 100644 --- a/src/util/virpidfile.c +++ b/src/util/virpidfile.c @@ -45,12 +45,19 @@ VIR_LOG_INIT("util.pidfile"); char *virPidFileBuildPath(const char *dir, const char* name) { - char *pidfile; + virBuffer buf = VIR_BUFFER_INITIALIZER; - if (virAsprintf(&pidfile, "%s/%s.pid", dir, name) < 0) - return NULL; + virBufferAsprintf(&buf, "%s", dir); + virBufferEscapeString(&buf, "/%s.pid", name); - return pidfile; + if (virBufferCheckError(&buf) < 0) + goto error; + + return virBufferContentAndReset(&buf); + + error: + virBufferFreeAndReset(&buf); + return NULL; } diff --git a/tests/networkxml2confdata/nat-network-name-with-quotes.conf b/tests/networkxml2confdata/nat-network-name-with-quotes.conf new file mode 100644 index 0000000..a1c839e --- /dev/null +++ b/tests/networkxml2confdata/nat-network-name-with-quotes.conf @@ -0,0 +1,20 @@ +##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE +##OVERWRITTEN AND LOST. Changes to this configuration should be made using: +## virsh net-edit default"with"quotes" +## or other application using the libvirt API. +## +## dnsmasq conf file created by libvirt +strict-order +except-interface=lo +bind-interfaces +listen-address=192.168.122.1 +listen-address=192.168.123.1 +listen-address=fc00:db8:ac10:fe01::1 +listen-address=fc00:db8:ac10:fd01::1 +listen-address=10.24.10.1 +srv-host=_name._tcp +dhcp-range=192.168.122.2,192.168.122.254 +dhcp-no-override +dhcp-lease-max=253 +dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default"with"quotes".hostsfile +addn-hosts=/var/lib/libvirt/dnsmasq/default"with"quotes".addnhosts diff --git a/tests/networkxml2confdata/nat-network-name-with-quotes.xml b/tests/networkxml2confdata/nat-network-name-with-quotes.xml new file mode 100644 index 0000000..eba75d2 --- /dev/null +++ b/tests/networkxml2confdata/nat-network-name-with-quotes.xml @@ -0,0 +1,26 @@ +<network> + <name>default"with"quotes"</name> + <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid> + <forward dev='eth1' mode='nat'> + <interface dev='eth1'/> + </forward> + <bridge name='virbr0' stp='on' delay='0'/> + <dns> + <srv service='name' protocol='tcp'/> + </dns> + <ip address='192.168.122.1' netmask='255.255.255.0'> + <dhcp> + <range start='192.168.122.2' end='192.168.122.254'/> + <host mac='00:16:3e:77:e2:ed' name='a.example.com' ip='192.168.122.10'/> + <host mac='00:16:3e:3e:a9:1a' name='b.example.com' ip='192.168.122.11'/> + </dhcp> + </ip> + <ip family='ipv4' address='192.168.123.1' netmask='255.255.255.0'> + </ip> + <ip family='ipv6' address='fc00:db8:ac10:fe01::1' prefix='64'> + </ip> + <ip family='ipv6' address='fc00:db8:ac10:fd01::1' prefix='64'> + </ip> + <ip family='ipv4' address='10.24.10.1'> + </ip> +</network> diff --git a/tests/networkxml2conftest.c b/tests/networkxml2conftest.c index fe95e8c..a5f2711 100644 --- a/tests/networkxml2conftest.c +++ b/tests/networkxml2conftest.c @@ -115,6 +115,7 @@ mymain(void) DO_TEST("netboot-network", restricted); DO_TEST("netboot-proxy-network", restricted); DO_TEST("nat-network-dns-srv-record-minimal", restricted); + DO_TEST("nat-network-name-with-quotes", restricted); DO_TEST("routed-network", full); DO_TEST("nat-network", dhcpv6); DO_TEST("nat-network-dns-txt-record", full);

On 01.06.2015 10:06, Shivaprasad G Bhat wrote:
The following series implements...
---
Shivaprasad G Bhat (2): fix domaincommon.rng to accept network name with quotes escape quotes for dsmasq conf contents
docs/schemas/domaincommon.rng | 2 +- src/util/virdnsmasq.c | 25 +++++++++++++++---- src/util/virpidfile.c | 15 ++++++++---- .../nat-network-name-with-quotes.conf | 20 +++++++++++++++ .../nat-network-name-with-quotes.xml | 26 ++++++++++++++++++++ tests/networkxml2conftest.c | 1 + 6 files changed, 79 insertions(+), 10 deletions(-) create mode 100644 tests/networkxml2confdata/nat-network-name-with-quotes.conf create mode 100644 tests/networkxml2confdata/nat-network-name-with-quotes.xml
There's nothing wrong with the patches. I'm just curious, what's the use case? I always thought that name should be something simple. On the other hand, we do something similar with domain names IIRC. Michal

On Mon, Jun 8, 2015 at 7:09 PM, Michal Privoznik <mprivozn@redhat.com> wrote:
On 01.06.2015 10:06, Shivaprasad G Bhat wrote:
The following series implements...
---
Shivaprasad G Bhat (2): fix domaincommon.rng to accept network name with quotes escape quotes for dsmasq conf contents
docs/schemas/domaincommon.rng | 2 +- src/util/virdnsmasq.c | 25 +++++++++++++++---- src/util/virpidfile.c | 15 ++++++++---- .../nat-network-name-with-quotes.conf | 20 +++++++++++++++ .../nat-network-name-with-quotes.xml | 26 ++++++++++++++++++++ tests/networkxml2conftest.c | 1 + 6 files changed, 79 insertions(+), 10 deletions(-) create mode 100644 tests/networkxml2confdata/nat-network-name-with-quotes.conf create mode 100644 tests/networkxml2confdata/nat-network-name-with-quotes.xml
There's nothing wrong with the patches. I'm just curious, what's the use case? I always thought that name should be something simple. On the other hand, we do something similar with domain names IIRC.
Hi Michal, I too am not sure if the client apps use the quotes. My tester reported it having issues as he was trying combinations including non-english language characters. I saw the quotes being handled diligently everywhere except here. So posted the patches fixing them. Thanks, Shiva
Michal

On Tue, Jun 09, 2015 at 07:44:36PM +0530, Shivaprasad bhat wrote:
On Mon, Jun 8, 2015 at 7:09 PM, Michal Privoznik <mprivozn@redhat.com> wrote:
On 01.06.2015 10:06, Shivaprasad G Bhat wrote:
The following series implements...
---
Shivaprasad G Bhat (2): fix domaincommon.rng to accept network name with quotes escape quotes for dsmasq conf contents
docs/schemas/domaincommon.rng | 2 +- src/util/virdnsmasq.c | 25 +++++++++++++++---- src/util/virpidfile.c | 15 ++++++++---- .../nat-network-name-with-quotes.conf | 20 +++++++++++++++ .../nat-network-name-with-quotes.xml | 26 ++++++++++++++++++++ tests/networkxml2conftest.c | 1 + 6 files changed, 79 insertions(+), 10 deletions(-) create mode 100644 tests/networkxml2confdata/nat-network-name-with-quotes.conf create mode 100644 tests/networkxml2confdata/nat-network-name-with-quotes.xml
There's nothing wrong with the patches. I'm just curious, what's the use case? I always thought that name should be something simple. On the other hand, we do something similar with domain names IIRC.
Hi Michal,
I too am not sure if the client apps use the quotes. My tester reported it having issues as he was trying combinations including non-english language characters.
I saw the quotes being handled diligently everywhere except here. So posted the patches fixing them.
I was able to define a guest using quotes in the name, and start it successfully. So on that basis, I think we should allow it for networks and other object types whereever possible, for sake of consistency. IOW, I don't care whether there's an explicit use case mentioned - it is justiable based on existing practice :-) $ virsh list Id Name State ---------------------------------------------------- 3 ser"foo"ial running $ ps -axuwf | grep qemu berrange 18386 0.3 0.2 1398604 48240 ? Sl 15:26 0:03 /usr/bin/qemu-system-x86_64 -machine accel=kvm -name ser"foo"ial -S -machine pc-i440fx-1.4,accel=tcg,usb=off -cpu SandyBridge,+erms,+smep,+fsgsbase,+rdrand,+f16c,+osxsave,+pcid,+pdcm,+xtpr,+tm2,+est,+smx,+vmx,+ds_cpl,+monitor,+dtes64,+pbe,+tm,+ht,+ss,+acpi,+ds,+vm $ ls $XDG_RUNTIME_DIR/libvirt/qemu/run/ ser"foo"ial.pid ser"foo"ial.xml Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
participants (5)
-
Daniel P. Berrange
-
Laine Stump
-
Michal Privoznik
-
Shivaprasad bhat
-
Shivaprasad G Bhat