diff options
author | Ian Jackson <Ian.Jackson@eu.citrix.com> | 2011-01-28 18:39:09 +0000 |
---|---|---|
committer | Ian Jackson <Ian.Jackson@eu.citrix.com> | 2011-01-28 18:39:09 +0000 |
commit | 36ac3bcd564975302e6e6df556b854687c0d1f93 (patch) | |
tree | 97e8aac0189381c01a0535947db20ee2477091ee | |
parent | efdadb8156974e75bd2aa6eb61a69a4becf84bb0 (diff) | |
download | xen-36ac3bcd564975302e6e6df556b854687c0d1f93.tar.gz xen-36ac3bcd564975302e6e6df556b854687c0d1f93.tar.bz2 xen-36ac3bcd564975302e6e6df556b854687c0d1f93.zip |
libxl: prevent creation of domains with duplicate names
libxl_domain_rename is where domain names are assigned. Therefore
this is where we check that no two domains have the same name. As a
special exception, domains whose names are "" are not considered to
clash.
We also take special care not to mind if we try to rename a domain to
the name it already has.
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
-rw-r--r-- | tools/libxl/libxl.c | 22 | ||||
-rw-r--r-- | tools/libxl/libxl_create.c | 1 |
2 files changed, 23 insertions, 0 deletions
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 9658d6714e..2d2b884baf 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -141,6 +141,28 @@ int libxl_domain_rename(libxl_ctx *ctx, uint32_t domid, } } + if (new_name[0]) { + /* nonempty names must be unique */ + uint32_t domid_e; + rc = libxl_name_to_domid(ctx, new_name, &domid_e); + if (rc == ERROR_INVAL) { + /* no such domain, good */ + } else if (rc != 0) { + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unexpected error" + "checking for existing domain"); + goto x_rc; + } else if (domid_e == domid) { + /* domain already has this name, ok (but we do still + * need the rest of the code as we may need to check + * old_name, for example). */ + } else { + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "domain with name \"%s\"" + " already exists.", new_name); + rc = ERROR_INVAL; + goto x_rc; + } + } + if (old_name) { got_old_name = xs_read(ctx->xsh, trans, name_path, &got_old_len); if (!got_old_name) { diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index 1879de048d..dc2621468e 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -351,6 +351,7 @@ int libxl__domain_make(libxl_ctx *ctx, libxl_domain_create_info *info, retry_transaction: t = xs_transaction_start(ctx->xsh); + xs_rm(ctx->xsh, t, dom_path); xs_mkdir(ctx->xsh, t, dom_path); xs_set_permissions(ctx->xsh, t, dom_path, roperm, ARRAY_SIZE(roperm)); |