debuggers.hg

changeset 22891:88cf07fed7d2

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>
author Ian Jackson <Ian.Jackson@eu.citrix.com>
date Fri Jan 28 18:39:09 2011 +0000 (2011-01-28)
parents 29eaad8e388a
children 52e928af3637
files tools/libxl/libxl.c tools/libxl/libxl_create.c
line diff
     1.1 --- a/tools/libxl/libxl.c	Fri Jan 28 18:38:26 2011 +0000
     1.2 +++ b/tools/libxl/libxl.c	Fri Jan 28 18:39:09 2011 +0000
     1.3 @@ -141,6 +141,28 @@ int libxl_domain_rename(libxl_ctx *ctx, 
     1.4          }
     1.5      }
     1.6  
     1.7 +    if (new_name[0]) {
     1.8 +        /* nonempty names must be unique */
     1.9 +        uint32_t domid_e;
    1.10 +        rc = libxl_name_to_domid(ctx, new_name, &domid_e);
    1.11 +        if (rc == ERROR_INVAL) {
    1.12 +            /* no such domain, good */
    1.13 +        } else if (rc != 0) {
    1.14 +            LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unexpected error"
    1.15 +                       "checking for existing domain");
    1.16 +            goto x_rc;
    1.17 +        } else if (domid_e == domid) {
    1.18 +            /* domain already has this name, ok (but we do still
    1.19 +             * need the rest of the code as we may need to check
    1.20 +             * old_name, for example). */
    1.21 +        } else {
    1.22 +            LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "domain with name \"%s\""
    1.23 +                       " already exists.", new_name);
    1.24 +            rc = ERROR_INVAL;
    1.25 +            goto x_rc;
    1.26 +        }
    1.27 +    }
    1.28 +
    1.29      if (old_name) {
    1.30          got_old_name = xs_read(ctx->xsh, trans, name_path, &got_old_len);
    1.31          if (!got_old_name) {
     2.1 --- a/tools/libxl/libxl_create.c	Fri Jan 28 18:38:26 2011 +0000
     2.2 +++ b/tools/libxl/libxl_create.c	Fri Jan 28 18:39:09 2011 +0000
     2.3 @@ -351,6 +351,7 @@ int libxl__domain_make(libxl_ctx *ctx, l
     2.4  
     2.5  retry_transaction:
     2.6      t = xs_transaction_start(ctx->xsh);
     2.7 +
     2.8      xs_rm(ctx->xsh, t, dom_path);
     2.9      xs_mkdir(ctx->xsh, t, dom_path);
    2.10      xs_set_permissions(ctx->xsh, t, dom_path, roperm, ARRAY_SIZE(roperm));