int rc = -1;
/* create string that is '<str> \0' for accurate matching */
- if (virAsprintf(&tmp, "%s ", str) == -1) {
- virReportOOMError();
+ if (virAsprintf(&tmp, "%s ", str) == -1)
return rc;
- }
if (check_enforcing != 0) {
/* create string that is '<str> (enforce)\0' for accurate matching */
if (virAsprintf(&etmp, "%s (enforce)", str) == -1) {
VIR_FREE(tmp);
- virReportOOMError();
return rc;
}
}
int rc = -1;
int len;
- if (virAsprintf(&profile, "%s/%s", APPARMOR_DIR "/libvirt", str) == -1) {
- virReportOOMError();
+ if (virAsprintf(&profile, "%s/%s", APPARMOR_DIR "/libvirt", str) == -1)
return rc;
- }
if (!virFileExists(profile))
goto failed;
}
/* create string that is ' <str> flags=(complain)\0' */
- if (virAsprintf(&tmp, " %s flags=(complain)", str) == -1) {
- virReportOOMError();
+ if (virAsprintf(&tmp, " %s flags=(complain)", str) == -1)
goto failed;
- }
if (strstr(content, tmp) != NULL)
rc = 0;
char *name = NULL;
virUUIDFormat(def->uuid, uuidstr);
- if (virAsprintf(&name, "%s%s", AA_PREFIX, uuidstr) < 0) {
- virReportOOMError();
+ if (virAsprintf(&name, "%s%s", AA_PREFIX, uuidstr) < 0)
return NULL;
- }
return name;
}
/* see if template file exists */
if (virAsprintf(&template, "%s/TEMPLATE",
- APPARMOR_DIR "/libvirt") == -1) {
- virReportOOMError();
+ APPARMOR_DIR "/libvirt") == -1)
return rc;
- }
if (!virFileExists(template)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
if (secdef->imagelabel == NULL)
return 0;
- if (virAsprintf(&proc, "/proc/self/fd/%d", fd) == -1) {
- virReportOOMError();
+ if (virAsprintf(&proc, "/proc/self/fd/%d", fd) == -1)
return rc;
- }
if (virFileResolveLink(proc, &fd_path) < 0) {
/* it's a deleted file, presumably. Ignore? */
case VIR_DOMAIN_CHR_TYPE_PIPE:
if ((virAsprintf(&in, "%s.in", dev->data.file.path) < 0) ||
- (virAsprintf(&out, "%s.out", dev->data.file.path) < 0)) {
- virReportOOMError();
+ (virAsprintf(&out, "%s.out", dev->data.file.path) < 0))
goto done;
- }
if (virFileExists(in) && virFileExists(out)) {
if ((virSecurityDACSetOwnership(in, user, group) < 0) ||
(virSecurityDACSetOwnership(out, user, group) < 0)) {
case VIR_DOMAIN_CHR_TYPE_PIPE:
if ((virAsprintf(&out, "%s.out", dev->data.file.path) < 0) ||
- (virAsprintf(&in, "%s.in", dev->data.file.path) < 0)) {
- virReportOOMError();
+ (virAsprintf(&in, "%s.in", dev->data.file.path) < 0))
goto done;
- }
if (virFileExists(in) && virFileExists(out)) {
if ((virSecurityDACRestoreSecurityFileLabel(out) < 0) ||
(virSecurityDACRestoreSecurityFileLabel(in) < 0)) {
case VIR_DOMAIN_SECLABEL_DYNAMIC:
if (virAsprintf(&seclabel->label, "%u:%u",
(unsigned int) priv->user,
- (unsigned int) priv->group) < 0) {
- virReportOOMError();
+ (unsigned int) priv->group) < 0)
return rc;
- }
if (seclabel->label == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot generate dac user and group id "
allowDiskFormatProbing, defaultConfined,
requireConfined);
- if (VIR_ALLOC_N(privateData, drv->privateDataLen) < 0) {
- virReportOOMError();
+ if (VIR_ALLOC_N(privateData, drv->privateDataLen) < 0)
return NULL;
- }
if (!(mgr = virObjectLockableNew(virSecurityManagerClass))) {
VIR_FREE(privateData);
/* The seclabel must be added to @vm prior calling domainGenSecurityLabel
* which may require seclabel to be presented already */
if (generated &&
- VIR_APPEND_ELEMENT_QUIET(vm->seclabels, vm->nseclabels, seclabel) < 0) {
- virReportOOMError();
+ VIR_APPEND_ELEMENT(vm->seclabels, vm->nseclabels, seclabel) < 0)
goto cleanup;
- }
if (sec_managers[i]->drv->domainGenSecurityLabel(sec_managers[i], vm) < 0) {
if (VIR_DELETE_ELEMENT(vm->seclabels,
return virSecurityStackGetNested(mgr);
}
- if (VIR_ALLOC_N(list, 2) < 0) {
- virReportOOMError();
+ if (VIR_ALLOC_N(list, 2) < 0)
return NULL;
- }
list[0] = mgr;
list[1] = NULL;
VIR_DEBUG("Try cat %s:c%d,c%d", sens, c1 + catMin, c2 + catMin);
if (c1 == c2) {
- if (virAsprintf(&mcs, "%s:c%d", sens, catMin + c1) < 0) {
- virReportOOMError();
+ if (virAsprintf(&mcs, "%s:c%d", sens, catMin + c1) < 0)
return NULL;
- }
} else {
if (c1 > c2) {
int t = c1;
c1 = c2;
c2 = t;
}
- if (virAsprintf(&mcs, "%s:c%d,c%d", sens, catMin + c1, catMin + c2) < 0) {
- virReportOOMError();
+ if (virAsprintf(&mcs, "%s:c%d,c%d", sens, catMin + c1, catMin + c2) < 0)
return NULL;
- }
}
if (virHashLookup(data->mcs, mcs) == NULL)
}
if (!(range = context_range_get(ctx))) {
- virReportOOMError();
+ virReportSystemError(errno, "%s", _("unable to get selinux context range"));
goto cleanup;
}
if (VIR_STRDUP(mcs, range) < 0)
if (!disk_seclabel)
return -1;
disk_seclabel->norelabel = true;
- if (VIR_APPEND_ELEMENT_QUIET(disk->seclabels, disk->nseclabels,
- disk_seclabel) < 0) {
- virReportOOMError();
+ if (VIR_APPEND_ELEMENT(disk->seclabels, disk->nseclabels,
+ disk_seclabel) < 0) {
virSecurityDeviceLabelDefFree(disk_seclabel);
return -1;
}
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_STORAGE: {
if (vroot) {
if (virAsprintf(&path, "%s/%s", vroot,
- dev->source.caps.u.storage.block) < 0) {
- virReportOOMError();
+ dev->source.caps.u.storage.block) < 0)
return -1;
- }
} else {
if (VIR_STRDUP(path, dev->source.caps.u.storage.block) < 0)
return -1;
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC: {
if (vroot) {
if (virAsprintf(&path, "%s/%s", vroot,
- dev->source.caps.u.misc.chardev) < 0) {
- virReportOOMError();
+ dev->source.caps.u.misc.chardev) < 0)
return -1;
- }
} else {
if (VIR_STRDUP(path, dev->source.caps.u.misc.chardev) < 0)
return -1;
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_STORAGE: {
if (vroot) {
if (virAsprintf(&path, "%s/%s", vroot,
- dev->source.caps.u.storage.block) < 0) {
- virReportOOMError();
+ dev->source.caps.u.storage.block) < 0)
return -1;
- }
} else {
if (VIR_STRDUP(path, dev->source.caps.u.storage.block) < 0)
return -1;
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC: {
if (vroot) {
if (virAsprintf(&path, "%s/%s", vroot,
- dev->source.caps.u.misc.chardev) < 0) {
- virReportOOMError();
+ dev->source.caps.u.misc.chardev) < 0)
return -1;
- }
} else {
if (VIR_STRDUP(path, dev->source.caps.u.misc.chardev) < 0)
return -1;
case VIR_DOMAIN_CHR_TYPE_PIPE:
if ((virAsprintf(&in, "%s.in", dev_source->data.file.path) < 0) ||
- (virAsprintf(&out, "%s.out", dev_source->data.file.path) < 0)) {
- virReportOOMError();
+ (virAsprintf(&out, "%s.out", dev_source->data.file.path) < 0))
goto done;
- }
if (virFileExists(in) && virFileExists(out)) {
if ((virSecuritySELinuxSetFilecon(in, imagelabel) < 0) ||
(virSecuritySELinuxSetFilecon(out, imagelabel) < 0)) {
case VIR_DOMAIN_CHR_TYPE_PIPE:
if ((virAsprintf(&out, "%s.out", dev_source->data.file.path) < 0) ||
- (virAsprintf(&in, "%s.in", dev_source->data.file.path) < 0)) {
- virReportOOMError();
+ (virAsprintf(&in, "%s.in", dev_source->data.file.path) < 0))
goto done;
- }
if (virFileExists(in) && virFileExists(out)) {
if ((virSecuritySELinuxRestoreSecurityFileLabel(mgr, out) < 0) ||
(virSecuritySELinuxRestoreSecurityFileLabel(mgr, in) < 0)) {
if (secdef->label) {
ctx = context_new(secdef->label);
if (!ctx) {
- virReportOOMError();
+ virReportSystemError(errno, _("unable to create selinux context for: %s"),
+ secdef->label);
goto cleanup;
}
range = context_range_get(ctx);
if (secdef->imagelabel &&
virAsprintf(&opts,
",context=\"%s\"",
- (const char*) secdef->imagelabel) < 0) {
- virReportOOMError();
+ (const char*) secdef->imagelabel) < 0)
return NULL;
- }
}
if (!opts && VIR_STRDUP(opts, "") < 0)
while (tmp && tmp->next)
tmp = tmp->next;
- if (VIR_ALLOC(item) < 0) {
- virReportOOMError();
+ if (VIR_ALLOC(item) < 0)
return -1;
- }
item->securityManager = nested;
if (tmp)
tmp->next = item;
for (item = priv->itemsHead; item; item = item->next)
len++;
- if (VIR_ALLOC_N(list, len + 1) < 0) {
- virReportOOMError();
+ if (VIR_ALLOC_N(list, len + 1) < 0)
return NULL;
- }
for (item = priv->itemsHead; item; item = item->next, i++)
list[i] = item->securityManager;
return -1;
}
- if (VIR_ALLOC_N(tmp, len) < 0) {
+ if (VIR_ALLOC_N_QUIET(tmp, len) < 0) {
vah_error(NULL, 0, _("could not allocate memory for string"));
return -1;
}
snprintf(flag, 3, "-%c", cmd);
- if (virAsprintf(&profile, "%s/%s",
- APPARMOR_DIR "/libvirt", profile_name) < 0) {
+ if (virAsprintfQuiet(&profile, "%s/%s",
+ APPARMOR_DIR "/libvirt", profile_name) < 0) {
vah_error(NULL, 0, _("profile name exceeds maximum length"));
return -1;
}
}
if (append && virFileExists(include_file)) {
- if (virAsprintf(&pcontent, "%s%s", existing, included_files) == -1) {
+ if (virAsprintfQuiet(&pcontent, "%s%s", existing, included_files) == -1) {
vah_error(NULL, 0, _("could not allocate memory for profile"));
goto cleanup;
}
} else {
- if (virAsprintf(&pcontent, "%s%s", warning, included_files) == -1) {
+ if (virAsprintfQuiet(&pcontent, "%s%s", warning, included_files) == -1) {
vah_error(NULL, 0, _("could not allocate memory for profile"));
goto cleanup;
}
goto end;
}
- if (virAsprintf(&template, "%s/TEMPLATE", APPARMOR_DIR "/libvirt") < 0) {
+ if (virAsprintfQuiet(&template, "%s/TEMPLATE", APPARMOR_DIR "/libvirt") < 0) {
vah_error(NULL, 0, _("template name exceeds maximum length"));
goto end;
}
}
/* '\nprofile <profile_name>\0' */
- if (virAsprintf(&replace_name, "\nprofile %s", profile_name) == -1) {
+ if (virAsprintfQuiet(&replace_name, "\nprofile %s", profile_name) == -1) {
vah_error(NULL, 0, _("could not allocate memory for profile name"));
goto clean_tcontent;
}
/* '\n<profile_files>\n}\0' */
- if (virAsprintf(&replace_files, "\n%s\n}", profile_files) == -1) {
+ if (virAsprintfQuiet(&replace_files, "\n%s\n}", profile_files) == -1) {
vah_error(NULL, 0, _("could not allocate memory for profile files"));
VIR_FREE(replace_name);
goto clean_tcontent;
goto clean_replace;
}
- if (VIR_ALLOC_N(pcontent, plen) < 0) {
+ if (VIR_ALLOC_N_QUIET(pcontent, plen) < 0) {
vah_error(NULL, 0, _("could not allocate memory for profile"));
goto clean_replace;
}
if (type == VIR_DOMAIN_CHR_TYPE_PIPE) {
/* add the pipe input */
- if (virAsprintf(&pipe_in, "%s.in", path) == -1) {
+ if (virAsprintfQuiet(&pipe_in, "%s.in", path) == -1) {
vah_error(NULL, 0, _("could not allocate memory"));
goto cleanup;
}
goto clean_pipe_in;
/* add the pipe output */
- if (virAsprintf(&pipe_out, "%s.out", path) == -1) {
+ if (virAsprintfQuiet(&pipe_out, "%s.out", path) == -1) {
vah_error(NULL, 0, _("could not allocate memory"));
goto clean_pipe_in;
}
/* verify uuid is same as what we were given on the command line */
virUUIDFormat(ctl->def->uuid, uuidstr);
- if (virAsprintf(&uuid, "%s%s", AA_PREFIX, uuidstr) == -1) {
+ if (virAsprintfQuiet(&uuid, "%s%s", AA_PREFIX, uuidstr) == -1) {
vah_error(ctl, 0, _("could not allocate memory"));
return rc;
}
if (vahParseArgv(ctl, argc, argv) != 0)
vah_error(ctl, 1, _("could not parse arguments"));
- if (virAsprintf(&profile, "%s/%s",
- APPARMOR_DIR "/libvirt", ctl->uuid) < 0)
+ if (virAsprintfQuiet(&profile, "%s/%s",
+ APPARMOR_DIR "/libvirt", ctl->uuid) < 0)
vah_error(ctl, 0, _("could not allocate memory"));
- if (virAsprintf(&include_file, "%s/%s.files",
- APPARMOR_DIR "/libvirt", ctl->uuid) < 0)
+ if (virAsprintfQuiet(&include_file, "%s/%s.files",
+ APPARMOR_DIR "/libvirt", ctl->uuid) < 0)
vah_error(ctl, 0, _("could not allocate memory"));
if (ctl->cmd == 'a')
/* create the profile from TEMPLATE */
if (ctl->cmd == 'c') {
char *tmp = NULL;
- if (virAsprintf(&tmp, " #include <libvirt/%s.files>\n",
- ctl->uuid) == -1) {
+ if (virAsprintfQuiet(&tmp, " #include <libvirt/%s.files>\n",
+ ctl->uuid) == -1) {
vah_error(ctl, 0, _("could not allocate memory"));
goto cleanup;
}