mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-30 01:43:23 +00:00
* src/storage_conf.c: fix storage pool mode parsing, and refactoring
patch by Ryota Ozaki Daniel
This commit is contained in:
parent
bdd6894713
commit
a3262d812b
@ -1,3 +1,8 @@
|
|||||||
|
Thu Mar 12 21:13:40 CET 2009 Daniel Veillard <veilard@redhat.com>
|
||||||
|
|
||||||
|
* src/storage_conf.c: fix storage pool mode parsing, and refactoring
|
||||||
|
patch by Ryota Ozaki
|
||||||
|
|
||||||
Wed Mar 11 14:42:24 CET 2009 Daniel Veillard <veilard@redhat.com>
|
Wed Mar 11 14:42:24 CET 2009 Daniel Veillard <veilard@redhat.com>
|
||||||
|
|
||||||
* src/xs_internal.c: fix xen events handling problem (Dan Berrange)
|
* src/xs_internal.c: fix xen events handling problem (Dan Berrange)
|
||||||
|
@ -371,15 +371,33 @@ virStoragePoolDefParseAuthChap(virConnectPtr conn,
|
|||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virStoragePoolDefParsePerms(virConnectPtr conn,
|
virStorageDefParsePerms(virConnectPtr conn,
|
||||||
xmlXPathContextPtr ctxt,
|
xmlXPathContextPtr ctxt,
|
||||||
virStoragePermsPtr perms) {
|
virStoragePermsPtr perms,
|
||||||
|
const char *permxpath,
|
||||||
|
int defaultmode) {
|
||||||
char *mode;
|
char *mode;
|
||||||
long v;
|
long v;
|
||||||
|
int ret = -1;
|
||||||
|
xmlNodePtr relnode;
|
||||||
|
xmlNodePtr node;
|
||||||
|
|
||||||
mode = virXPathString(conn, "string(/pool/permissions/mode)", ctxt);
|
node = virXPathNode(conn, permxpath, ctxt);
|
||||||
|
if (node == NULL) {
|
||||||
|
/* Set default values if there is not <permissions> element */
|
||||||
|
perms->mode = defaultmode;
|
||||||
|
perms->uid = getuid();
|
||||||
|
perms->gid = getgid();
|
||||||
|
perms->label = NULL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
relnode = ctxt->node;
|
||||||
|
ctxt->node = node;
|
||||||
|
|
||||||
|
mode = virXPathString(conn, "string(./mode)", ctxt);
|
||||||
if (!mode) {
|
if (!mode) {
|
||||||
perms->mode = 0700;
|
perms->mode = defaultmode;
|
||||||
} else {
|
} else {
|
||||||
char *end = NULL;
|
char *end = NULL;
|
||||||
perms->mode = strtol(mode, &end, 8);
|
perms->mode = strtol(mode, &end, 8);
|
||||||
@ -387,36 +405,39 @@ virStoragePoolDefParsePerms(virConnectPtr conn,
|
|||||||
if (*end || perms->mode < 0 || perms->mode > 0777) {
|
if (*end || perms->mode < 0 || perms->mode > 0777) {
|
||||||
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
||||||
"%s", _("malformed octal mode"));
|
"%s", _("malformed octal mode"));
|
||||||
return -1;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virXPathNode(conn, "/pool/permissions/owner", ctxt) == NULL) {
|
if (virXPathNode(conn, "./owner", ctxt) == NULL) {
|
||||||
perms->uid = getuid();
|
perms->uid = getuid();
|
||||||
} else {
|
} else {
|
||||||
if (virXPathLong(conn, "number(/pool/permissions/owner)", ctxt, &v) < 0) {
|
if (virXPathLong(conn, "number(./owner)", ctxt, &v) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
||||||
"%s", _("malformed owner element"));
|
"%s", _("malformed owner element"));
|
||||||
return -1;
|
goto error;
|
||||||
}
|
}
|
||||||
perms->uid = (int)v;
|
perms->uid = (int)v;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virXPathNode(conn, "/pool/permissions/group", ctxt) == NULL) {
|
if (virXPathNode(conn, "./group", ctxt) == NULL) {
|
||||||
perms->gid = getgid();
|
perms->gid = getgid();
|
||||||
} else {
|
} else {
|
||||||
if (virXPathLong(conn, "number(/pool/permissions/group)", ctxt, &v) < 0) {
|
if (virXPathLong(conn, "number(./group)", ctxt, &v) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
||||||
"%s", _("malformed group element"));
|
"%s", _("malformed group element"));
|
||||||
return -1;
|
goto error;
|
||||||
}
|
}
|
||||||
perms->gid = (int)v;
|
perms->gid = (int)v;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* NB, we're ignoring missing labels here - they'll simply inherit */
|
/* NB, we're ignoring missing labels here - they'll simply inherit */
|
||||||
perms->label = virXPathString(conn, "string(/pool/permissions/label)", ctxt);
|
perms->label = virXPathString(conn, "string(./label)", ctxt);
|
||||||
|
|
||||||
return 0;
|
ret = 0;
|
||||||
|
error:
|
||||||
|
ctxt->node = relnode;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -579,7 +600,8 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virStoragePoolDefParsePerms(conn, ctxt, &ret->target.perms) < 0)
|
if (virStorageDefParsePerms(conn, ctxt, &ret->target.perms,
|
||||||
|
"/pool/target/permissions", 0700) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -800,55 +822,6 @@ virStoragePoolDefFormat(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
virStorageVolDefParsePerms(virConnectPtr conn,
|
|
||||||
xmlXPathContextPtr ctxt,
|
|
||||||
virStoragePermsPtr perms) {
|
|
||||||
char *mode;
|
|
||||||
long v;
|
|
||||||
|
|
||||||
mode = virXPathString(conn, "string(/volume/permissions/mode)", ctxt);
|
|
||||||
if (!mode) {
|
|
||||||
perms->mode = 0600;
|
|
||||||
} else {
|
|
||||||
char *end = NULL;
|
|
||||||
perms->mode = strtol(mode, &end, 8);
|
|
||||||
VIR_FREE(mode);
|
|
||||||
if (*end || perms->mode < 0 || perms->mode > 0777) {
|
|
||||||
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
|
||||||
"%s", _("malformed octal mode"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (virXPathNode(conn, "/volume/permissions/owner", ctxt) == NULL) {
|
|
||||||
perms->uid = getuid();
|
|
||||||
} else {
|
|
||||||
if (virXPathLong(conn, "number(/volume/permissions/owner)", ctxt, &v) < 0) {
|
|
||||||
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
|
||||||
"%s", _("missing owner element"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
perms->uid = (int)v;
|
|
||||||
}
|
|
||||||
if (virXPathNode(conn, "/volume/permissions/group", ctxt) == NULL) {
|
|
||||||
perms->gid = getgid();
|
|
||||||
} else {
|
|
||||||
if (virXPathLong(conn, "number(/volume/permissions/group)", ctxt, &v) < 0) {
|
|
||||||
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
|
||||||
"%s", _("missing group element"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
perms->gid = (int)v;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* NB, we're ignoring missing labels here - they'll simply inherit */
|
|
||||||
perms->label = virXPathString(conn, "string(/volume/permissions/label)", ctxt);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virStorageSize(virConnectPtr conn,
|
virStorageSize(virConnectPtr conn,
|
||||||
const char *unit,
|
const char *unit,
|
||||||
@ -997,7 +970,8 @@ virStorageVolDefParseDoc(virConnectPtr conn,
|
|||||||
VIR_FREE(format);
|
VIR_FREE(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virStorageVolDefParsePerms(conn, ctxt, &ret->target.perms) < 0)
|
if (virStorageDefParsePerms(conn, ctxt, &ret->target.perms,
|
||||||
|
"/volume/target/permissions", 0600) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
|
||||||
@ -1019,7 +993,8 @@ virStorageVolDefParseDoc(virConnectPtr conn,
|
|||||||
VIR_FREE(format);
|
VIR_FREE(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virStorageVolDefParsePerms(conn, ctxt, &ret->backingStore.perms) < 0)
|
if (virStorageDefParsePerms(conn, ctxt, &ret->backingStore.perms,
|
||||||
|
"/volume/backingStore/permissions", 0600) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user