Re: [libvirt] [PATCH 1/2] Forbid new-line char in name of new domain

2016-11-22 Thread Michal Privoznik
On 11.11.2016 10:17, Sławek Kapłoński wrote:
> New line character in name of domain is now forbidden because it
> mess virsh output and can be confusing for users.
> Validation of name is done in drivers, after parsing XML to avoid
> problems with dissappeared domains which was already created with
> new-line char in name.
> ---
>  src/bhyve/bhyve_driver.c   | 3 +++
>  src/esx/esx_driver.c   | 3 +++
>  src/libxl/libxl_driver.c   | 3 +++
>  src/lxc/lxc_driver.c   | 3 +++
>  src/openvz/openvz_driver.c | 3 +++
>  src/qemu/qemu_driver.c | 3 +++
>  src/test/test_driver.c | 3 +++
>  src/uml/uml_driver.c   | 3 +++
>  src/vmware/vmware_driver.c | 3 +++
>  src/vz/vz_driver.c | 3 +++
>  src/xen/xen_driver.c   | 3 +++
>  src/xenapi/xenapi_driver.c | 3 +++
>  12 files changed, 36 insertions(+)
> 
> diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
> index 38fb9f0..17f8524 100644
> --- a/src/bhyve/bhyve_driver.c
> +++ b/src/bhyve/bhyve_driver.c
> @@ -541,6 +541,9 @@ bhyveDomainDefineXMLFlags(virConnectPtr conn, const char 
> *xml, unsigned int flag
> NULL, parse_flags)) == NULL)
>  goto cleanup;
>  
> +if (virXMLCheckIllegalChars("name", def->name, "\n") < 0)
> +goto cleanup;
> +
>  if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0)
>  goto cleanup;
>  
> diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
> index 17ef00f..166d4bc 100644
> --- a/src/esx/esx_driver.c
> +++ b/src/esx/esx_driver.c
> @@ -3051,6 +3051,9 @@ esxDomainDefineXMLFlags(virConnectPtr conn, const char 
> *xml, unsigned int flags)
>  if (!def)
>  return NULL;
>  
> +if (virXMLCheckIllegalChars("name", def->name, "\n") < 0)
> +goto cleanup;
> +
>  /* Check if an existing domain should be edited */
>  if (esxVI_LookupVirtualMachineByUuid(priv->primary, def->uuid, NULL,
>   ,
> diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
> index b2f3b16..3efa91e 100644
> --- a/src/libxl/libxl_driver.c
> +++ b/src/libxl/libxl_driver.c
> @@ -2791,6 +2791,9 @@ libxlDomainDefineXMLFlags(virConnectPtr conn, const 
> char *xml, unsigned int flag
>  NULL, parse_flags)))
>  goto cleanup;
>  
> +if (virXMLCheckIllegalChars("name", def->name, "\n") < 0)
> +goto cleanup;
> +
>  if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0)
>  goto cleanup;
>  
> diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
> index 4a0165a..a6776a1 100644
> --- a/src/lxc/lxc_driver.c
> +++ b/src/lxc/lxc_driver.c
> @@ -475,6 +475,9 @@ lxcDomainDefineXMLFlags(virConnectPtr conn, const char 
> *xml, unsigned int flags)
>  NULL, parse_flags)))
>  goto cleanup;
>  
> +if (virXMLCheckIllegalChars("name", def->name, "\n") < 0)
> +goto cleanup;
> +
>  if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0)
>  goto cleanup;
>  
> diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
> index 38a562e..1dfb1cc 100644
> --- a/src/openvz/openvz_driver.c
> +++ b/src/openvz/openvz_driver.c
> @@ -1000,6 +1000,9 @@ openvzDomainDefineXMLFlags(virConnectPtr conn, const 
> char *xml, unsigned int fla
>   NULL, parse_flags)) == NULL)
>  goto cleanup;
>  
> +if (virXMLCheckIllegalChars("name", vmdef->name, "\n") < 0)
> +goto cleanup;
> +
>  if (!(vm = virDomainObjListAdd(driver->domains, vmdef,
> driver->xmlopt,
> 0, NULL)))
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index a82e58b..8d337eb 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -7339,6 +7339,9 @@ qemuDomainDefineXMLFlags(virConnectPtr conn,
>  NULL, parse_flags)))
>  goto cleanup;
>  
> +if (virXMLCheckIllegalChars("name", def->name, "\n") < 0)
> +goto cleanup;
> +
>  if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0)
>  goto cleanup;
>  
> diff --git a/src/test/test_driver.c b/src/test/test_driver.c
> index 236874f..1b54839 100644
> --- a/src/test/test_driver.c
> +++ b/src/test/test_driver.c
> @@ -2641,6 +2641,9 @@ static virDomainPtr 
> testDomainDefineXMLFlags(virConnectPtr conn,
> NULL, parse_flags)) == NULL)
>  goto cleanup;
>  
> +if (virXMLCheckIllegalChars("name", def->name, "\n") < 0)
> +goto cleanup;
> +
>  if (testDomainGenerateIfnames(def) < 0)
>  goto cleanup;
>  if (!(dom = virDomainObjListAdd(privconn->domains,
> diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
> index 4f4a69b..ad89e3e 100644
> --- a/src/uml/uml_driver.c
> +++ b/src/uml/uml_driver.c
> @@ -2074,6 +2074,9 @@ umlDomainDefineXMLFlags(virConnectPtr conn, const char 
> *xml, 

[libvirt] [PATCH 1/2] Forbid new-line char in name of new domain

2016-11-11 Thread Sławek Kapłoński
New line character in name of domain is now forbidden because it
mess virsh output and can be confusing for users.
Validation of name is done in drivers, after parsing XML to avoid
problems with dissappeared domains which was already created with
new-line char in name.
---
 src/bhyve/bhyve_driver.c   | 3 +++
 src/esx/esx_driver.c   | 3 +++
 src/libxl/libxl_driver.c   | 3 +++
 src/lxc/lxc_driver.c   | 3 +++
 src/openvz/openvz_driver.c | 3 +++
 src/qemu/qemu_driver.c | 3 +++
 src/test/test_driver.c | 3 +++
 src/uml/uml_driver.c   | 3 +++
 src/vmware/vmware_driver.c | 3 +++
 src/vz/vz_driver.c | 3 +++
 src/xen/xen_driver.c   | 3 +++
 src/xenapi/xenapi_driver.c | 3 +++
 12 files changed, 36 insertions(+)

diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index 38fb9f0..17f8524 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -541,6 +541,9 @@ bhyveDomainDefineXMLFlags(virConnectPtr conn, const char 
*xml, unsigned int flag
NULL, parse_flags)) == NULL)
 goto cleanup;
 
+if (virXMLCheckIllegalChars("name", def->name, "\n") < 0)
+goto cleanup;
+
 if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0)
 goto cleanup;
 
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 17ef00f..166d4bc 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -3051,6 +3051,9 @@ esxDomainDefineXMLFlags(virConnectPtr conn, const char 
*xml, unsigned int flags)
 if (!def)
 return NULL;
 
+if (virXMLCheckIllegalChars("name", def->name, "\n") < 0)
+goto cleanup;
+
 /* Check if an existing domain should be edited */
 if (esxVI_LookupVirtualMachineByUuid(priv->primary, def->uuid, NULL,
  ,
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index b2f3b16..3efa91e 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -2791,6 +2791,9 @@ libxlDomainDefineXMLFlags(virConnectPtr conn, const char 
*xml, unsigned int flag
 NULL, parse_flags)))
 goto cleanup;
 
+if (virXMLCheckIllegalChars("name", def->name, "\n") < 0)
+goto cleanup;
+
 if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0)
 goto cleanup;
 
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 4a0165a..a6776a1 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -475,6 +475,9 @@ lxcDomainDefineXMLFlags(virConnectPtr conn, const char 
*xml, unsigned int flags)
 NULL, parse_flags)))
 goto cleanup;
 
+if (virXMLCheckIllegalChars("name", def->name, "\n") < 0)
+goto cleanup;
+
 if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0)
 goto cleanup;
 
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index 38a562e..1dfb1cc 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -1000,6 +1000,9 @@ openvzDomainDefineXMLFlags(virConnectPtr conn, const char 
*xml, unsigned int fla
  NULL, parse_flags)) == NULL)
 goto cleanup;
 
+if (virXMLCheckIllegalChars("name", vmdef->name, "\n") < 0)
+goto cleanup;
+
 if (!(vm = virDomainObjListAdd(driver->domains, vmdef,
driver->xmlopt,
0, NULL)))
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index a82e58b..8d337eb 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7339,6 +7339,9 @@ qemuDomainDefineXMLFlags(virConnectPtr conn,
 NULL, parse_flags)))
 goto cleanup;
 
+if (virXMLCheckIllegalChars("name", def->name, "\n") < 0)
+goto cleanup;
+
 if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0)
 goto cleanup;
 
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 236874f..1b54839 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -2641,6 +2641,9 @@ static virDomainPtr 
testDomainDefineXMLFlags(virConnectPtr conn,
NULL, parse_flags)) == NULL)
 goto cleanup;
 
+if (virXMLCheckIllegalChars("name", def->name, "\n") < 0)
+goto cleanup;
+
 if (testDomainGenerateIfnames(def) < 0)
 goto cleanup;
 if (!(dom = virDomainObjListAdd(privconn->domains,
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index 4f4a69b..ad89e3e 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -2074,6 +2074,9 @@ umlDomainDefineXMLFlags(virConnectPtr conn, const char 
*xml, unsigned int flags)
 NULL, parse_flags)))
 goto cleanup;
 
+if (virXMLCheckIllegalChars("name", def->name, "\n") < 0)
+goto cleanup;
+
 if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0)
 goto cleanup;
 
diff --git