mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-21 20:15:17 +00:00
virt-aa-helper: translate error messages
These messages are visible to the user, so they should be consistently translated. * cfg.mk (msg_gen_function): Add vah_error, vah_warning. * src/security/virt-aa-helper.c: Translate messages. (catchXMLError): Fix capitalization.
This commit is contained in:
parent
144c06d4ee
commit
c811d46fab
2
cfg.mk
2
cfg.mk
@ -337,6 +337,8 @@ msg_gen_function += qemudReportError
|
|||||||
msg_gen_function += regerror
|
msg_gen_function += regerror
|
||||||
msg_gen_function += remoteDispatchFormatError
|
msg_gen_function += remoteDispatchFormatError
|
||||||
msg_gen_function += umlReportError
|
msg_gen_function += umlReportError
|
||||||
|
msg_gen_function += vah_error
|
||||||
|
msg_gen_function += vah_warning
|
||||||
msg_gen_function += vboxError
|
msg_gen_function += vboxError
|
||||||
msg_gen_function += virConfError
|
msg_gen_function += virConfError
|
||||||
msg_gen_function += virDomainReportError
|
msg_gen_function += virDomainReportError
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* virt-aa-helper: wrapper program used by AppArmor security driver.
|
* virt-aa-helper: wrapper program used by AppArmor security driver.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Red Hat, Inc.
|
||||||
* Copyright (C) 2009-2010 Canonical Ltd.
|
* Copyright (C) 2009-2010 Canonical Ltd.
|
||||||
*
|
*
|
||||||
* See COPYING.LIB for the License of this software
|
* See COPYING.LIB for the License of this software
|
||||||
@ -82,28 +84,28 @@ vahDeinit(vahControl * ctl)
|
|||||||
static void
|
static void
|
||||||
vah_usage(void)
|
vah_usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stdout, "\n%s [options] [< def.xml]\n\n"
|
fprintf(stdout, _("\n%s [options] [< def.xml]\n\n
|
||||||
" Options:\n"
|
Options:\n
|
||||||
" -a | --add load profile\n"
|
-a | --add load profile\n
|
||||||
" -c | --create create profile from template\n"
|
-c | --create create profile from template\n
|
||||||
" -D | --delete unload and delete profile\n"
|
-D | --delete unload and delete profile\n
|
||||||
" -f | --add-file <file> add file to profile\n"
|
-f | --add-file <file> add file to profile\n
|
||||||
" -F | --append-file <file> append file to profile\n"
|
-F | --append-file <file> append file to profile\n
|
||||||
" -r | --replace reload profile\n"
|
-r | --replace reload profile\n
|
||||||
" -R | --remove unload profile\n"
|
-R | --remove unload profile\n
|
||||||
" -h | --help this help\n"
|
-h | --help this help\n
|
||||||
" -u | --uuid <uuid> uuid (profile name)\n"
|
-u | --uuid <uuid> uuid (profile name)\n
|
||||||
"\n", progname);
|
\n", progname);
|
||||||
|
|
||||||
fprintf(stdout, "This command is intended to be used by libvirtd "
|
fputs(_("This command is intended to be used by libvirtd "
|
||||||
"and not used directly.\n");
|
"and not used directly.\n"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
vah_error(vahControl * ctl, int doexit, const char *str)
|
vah_error(vahControl * ctl, int doexit, const char *str)
|
||||||
{
|
{
|
||||||
fprintf(stderr, _("%s: error: %s\n"), progname, str);
|
fprintf(stderr, _("%s: error: %s%c"), progname, str, '\n');
|
||||||
|
|
||||||
if (doexit) {
|
if (doexit) {
|
||||||
if (ctl != NULL)
|
if (ctl != NULL)
|
||||||
@ -115,13 +117,13 @@ vah_error(vahControl * ctl, int doexit, const char *str)
|
|||||||
static void
|
static void
|
||||||
vah_warning(const char *str)
|
vah_warning(const char *str)
|
||||||
{
|
{
|
||||||
fprintf(stderr, _("%s: warning: %s\n"), progname, str);
|
fprintf(stderr, _("%s: warning: %s%c"), progname, str, '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
vah_info(const char *str)
|
vah_info(const char *str)
|
||||||
{
|
{
|
||||||
fprintf(stderr, _("%s:\n%s\n"), progname, str);
|
fprintf(stderr, _("%s:\n%s%c"), progname, str, '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -138,12 +140,12 @@ replace_string(char *orig, const size_t len, const char *oldstr,
|
|||||||
char *tmp = NULL;
|
char *tmp = NULL;
|
||||||
|
|
||||||
if ((pos = strstr(orig, oldstr)) == NULL) {
|
if ((pos = strstr(orig, oldstr)) == NULL) {
|
||||||
vah_error(NULL, 0, "could not find replacement string");
|
vah_error(NULL, 0, _("could not find replacement string"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC_N(tmp, len) < 0) {
|
if (VIR_ALLOC_N(tmp, len) < 0) {
|
||||||
vah_error(NULL, 0, "could not allocate memory for string");
|
vah_error(NULL, 0, _("could not allocate memory for string"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
tmp[0] = '\0';
|
tmp[0] = '\0';
|
||||||
@ -155,7 +157,7 @@ replace_string(char *orig, const size_t len, const char *oldstr,
|
|||||||
|
|
||||||
/* add the replacement string */
|
/* add the replacement string */
|
||||||
if (strlen(tmp) + strlen(repstr) > len - 1) {
|
if (strlen(tmp) + strlen(repstr) > len - 1) {
|
||||||
vah_error(NULL, 0, "not enough space in target buffer");
|
vah_error(NULL, 0, _("not enough space in target buffer"));
|
||||||
VIR_FREE(tmp);
|
VIR_FREE(tmp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -163,7 +165,7 @@ replace_string(char *orig, const size_t len, const char *oldstr,
|
|||||||
|
|
||||||
/* add everything after oldstr */
|
/* add everything after oldstr */
|
||||||
if (strlen(tmp) + strlen(orig) - (idx + strlen(oldstr)) > len - 1) {
|
if (strlen(tmp) + strlen(orig) - (idx + strlen(oldstr)) > len - 1) {
|
||||||
vah_error(NULL, 0, "not enough space in target buffer");
|
vah_error(NULL, 0, _("not enough space in target buffer"));
|
||||||
VIR_FREE(tmp);
|
VIR_FREE(tmp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -171,7 +173,7 @@ replace_string(char *orig, const size_t len, const char *oldstr,
|
|||||||
strlen(orig) - (idx + strlen(oldstr)));
|
strlen(orig) - (idx + strlen(oldstr)));
|
||||||
|
|
||||||
if (virStrcpy(orig, tmp, len) == NULL) {
|
if (virStrcpy(orig, tmp, len) == NULL) {
|
||||||
vah_error(NULL, 0, "error replacing string");
|
vah_error(NULL, 0, _("error replacing string"));
|
||||||
VIR_FREE(tmp);
|
VIR_FREE(tmp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -192,7 +194,7 @@ parserCommand(const char *profile_name, const char cmd)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (strchr("arR", cmd) == NULL) {
|
if (strchr("arR", cmd) == NULL) {
|
||||||
vah_error(NULL, 0, "invalid flag");
|
vah_error(NULL, 0, _("invalid flag"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,12 +202,12 @@ parserCommand(const char *profile_name, const char cmd)
|
|||||||
|
|
||||||
if (snprintf(profile, PATH_MAX, "%s/%s",
|
if (snprintf(profile, PATH_MAX, "%s/%s",
|
||||||
APPARMOR_DIR "/libvirt", profile_name) > PATH_MAX - 1) {
|
APPARMOR_DIR "/libvirt", profile_name) > PATH_MAX - 1) {
|
||||||
vah_error(NULL, 0, "profile name exceeds maximum length");
|
vah_error(NULL, 0, _("profile name exceeds maximum length"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!virFileExists(profile)) {
|
if (!virFileExists(profile)) {
|
||||||
vah_error(NULL, 0, "profile does not exist");
|
vah_error(NULL, 0, _("profile does not exist"));
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
const char * const argv[] = {
|
const char * const argv[] = {
|
||||||
@ -214,12 +216,13 @@ parserCommand(const char *profile_name, const char cmd)
|
|||||||
if ((ret = virRun(argv, &status)) != 0 ||
|
if ((ret = virRun(argv, &status)) != 0 ||
|
||||||
(WIFEXITED(status) && WEXITSTATUS(status) != 0)) {
|
(WIFEXITED(status) && WEXITSTATUS(status) != 0)) {
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
vah_error(NULL, 0, "failed to run apparmor_parser");
|
vah_error(NULL, 0, _("failed to run apparmor_parser"));
|
||||||
return -1;
|
return -1;
|
||||||
} else if (cmd == 'R' && WIFEXITED(status) && WEXITSTATUS(status) == 234) {
|
} else if (cmd == 'R' && WIFEXITED(status) &&
|
||||||
vah_warning("unable to unload already unloaded profile (non-fatal)");
|
WEXITSTATUS(status) == 234) {
|
||||||
|
vah_warning(_("unable to unload already unloaded profile"));
|
||||||
} else {
|
} else {
|
||||||
vah_error(NULL, 0, "apparmor_parser exited with error");
|
vah_error(NULL, 0, _("apparmor_parser exited with error"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -251,19 +254,19 @@ update_include_file(const char *include_file, const char *included_files,
|
|||||||
|
|
||||||
if (append && virFileExists(include_file)) {
|
if (append && virFileExists(include_file)) {
|
||||||
if (virAsprintf(&pcontent, "%s%s", existing, included_files) == -1) {
|
if (virAsprintf(&pcontent, "%s%s", existing, included_files) == -1) {
|
||||||
vah_error(NULL, 0, "could not allocate memory for profile");
|
vah_error(NULL, 0, _("could not allocate memory for profile"));
|
||||||
goto clean;
|
goto clean;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (virAsprintf(&pcontent, "%s%s", warning, included_files) == -1) {
|
if (virAsprintf(&pcontent, "%s%s", warning, included_files) == -1) {
|
||||||
vah_error(NULL, 0, "could not allocate memory for profile");
|
vah_error(NULL, 0, _("could not allocate memory for profile"));
|
||||||
goto clean;
|
goto clean;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plen = strlen(pcontent);
|
plen = strlen(pcontent);
|
||||||
if (plen > MAX_FILE_LEN) {
|
if (plen > MAX_FILE_LEN) {
|
||||||
vah_error(NULL, 0, "invalid length for new profile");
|
vah_error(NULL, 0, _("invalid length for new profile"));
|
||||||
goto clean;
|
goto clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,18 +278,18 @@ update_include_file(const char *include_file, const char *included_files,
|
|||||||
|
|
||||||
/* write the file */
|
/* write the file */
|
||||||
if ((fd = open(include_file, O_CREAT | O_TRUNC | O_WRONLY, 0644)) == -1) {
|
if ((fd = open(include_file, O_CREAT | O_TRUNC | O_WRONLY, 0644)) == -1) {
|
||||||
vah_error(NULL, 0, "failed to create include file");
|
vah_error(NULL, 0, _("failed to create include file"));
|
||||||
goto clean;
|
goto clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (safewrite(fd, pcontent, plen) < 0) { /* don't write the '\0' */
|
if (safewrite(fd, pcontent, plen) < 0) { /* don't write the '\0' */
|
||||||
VIR_FORCE_CLOSE(fd);
|
VIR_FORCE_CLOSE(fd);
|
||||||
vah_error(NULL, 0, "failed to write to profile");
|
vah_error(NULL, 0, _("failed to write to profile"));
|
||||||
goto clean;
|
goto clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_CLOSE(fd) != 0) {
|
if (VIR_CLOSE(fd) != 0) {
|
||||||
vah_error(NULL, 0, "failed to close or write to profile");
|
vah_error(NULL, 0, _("failed to close or write to profile")_;
|
||||||
goto clean;
|
goto clean;
|
||||||
}
|
}
|
||||||
rc = 0;
|
rc = 0;
|
||||||
@ -317,45 +320,45 @@ create_profile(const char *profile, const char *profile_name,
|
|||||||
int rc = -1;
|
int rc = -1;
|
||||||
|
|
||||||
if (virFileExists(profile)) {
|
if (virFileExists(profile)) {
|
||||||
vah_error(NULL, 0, "profile exists");
|
vah_error(NULL, 0, _("profile exists"));
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (snprintf(template, PATH_MAX, "%s/TEMPLATE",
|
if (snprintf(template, PATH_MAX, "%s/TEMPLATE",
|
||||||
APPARMOR_DIR "/libvirt") > PATH_MAX - 1) {
|
APPARMOR_DIR "/libvirt") > PATH_MAX - 1) {
|
||||||
vah_error(NULL, 0, "template name exceeds maximum length");
|
vah_error(NULL, 0, _("template name exceeds maximum length"));
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!virFileExists(template)) {
|
if (!virFileExists(template)) {
|
||||||
vah_error(NULL, 0, "template does not exist");
|
vah_error(NULL, 0, _("template does not exist"));
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((tlen = virFileReadAll(template, MAX_FILE_LEN, &tcontent)) < 0) {
|
if ((tlen = virFileReadAll(template, MAX_FILE_LEN, &tcontent)) < 0) {
|
||||||
vah_error(NULL, 0, "failed to read AppArmor template");
|
vah_error(NULL, 0, _("failed to read AppArmor template"));
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strstr(tcontent, template_name) == NULL) {
|
if (strstr(tcontent, template_name) == NULL) {
|
||||||
vah_error(NULL, 0, "no replacement string in template");
|
vah_error(NULL, 0, _("no replacement string in template"));
|
||||||
goto clean_tcontent;
|
goto clean_tcontent;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strstr(tcontent, template_end) == NULL) {
|
if (strstr(tcontent, template_end) == NULL) {
|
||||||
vah_error(NULL, 0, "no replacement string in template");
|
vah_error(NULL, 0, _("no replacement string in template"));
|
||||||
goto clean_tcontent;
|
goto clean_tcontent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* '\nprofile <profile_name>\0' */
|
/* '\nprofile <profile_name>\0' */
|
||||||
if (virAsprintf(&replace_name, "\nprofile %s", profile_name) == -1) {
|
if (virAsprintf(&replace_name, "\nprofile %s", profile_name) == -1) {
|
||||||
vah_error(NULL, 0, "could not allocate memory for profile name");
|
vah_error(NULL, 0, _("could not allocate memory for profile name"));
|
||||||
goto clean_tcontent;
|
goto clean_tcontent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* '\n<profile_files>\n}\0' */
|
/* '\n<profile_files>\n}\0' */
|
||||||
if (virAsprintf(&replace_files, "\n%s\n}", profile_files) == -1) {
|
if (virAsprintf(&replace_files, "\n%s\n}", profile_files) == -1) {
|
||||||
vah_error(NULL, 0, "could not allocate memory for profile files");
|
vah_error(NULL, 0, _("could not allocate memory for profile files"));
|
||||||
VIR_FREE(replace_name);
|
VIR_FREE(replace_name);
|
||||||
goto clean_tcontent;
|
goto clean_tcontent;
|
||||||
}
|
}
|
||||||
@ -363,12 +366,12 @@ create_profile(const char *profile, const char *profile_name,
|
|||||||
plen = tlen + strlen(replace_name) - strlen(template_name) +
|
plen = tlen + strlen(replace_name) - strlen(template_name) +
|
||||||
strlen(replace_files) - strlen(template_end) + 1;
|
strlen(replace_files) - strlen(template_end) + 1;
|
||||||
if (plen > MAX_FILE_LEN || plen < tlen) {
|
if (plen > MAX_FILE_LEN || plen < tlen) {
|
||||||
vah_error(NULL, 0, "invalid length for new profile");
|
vah_error(NULL, 0, _("invalid length for new profile"));
|
||||||
goto clean_replace;
|
goto clean_replace;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC_N(pcontent, plen) < 0) {
|
if (VIR_ALLOC_N(pcontent, plen) < 0) {
|
||||||
vah_error(NULL, 0, "could not allocate memory for profile");
|
vah_error(NULL, 0, _("could not allocate memory for profile"));
|
||||||
goto clean_replace;
|
goto clean_replace;
|
||||||
}
|
}
|
||||||
pcontent[0] = '\0';
|
pcontent[0] = '\0';
|
||||||
@ -382,18 +385,18 @@ create_profile(const char *profile, const char *profile_name,
|
|||||||
|
|
||||||
/* write the file */
|
/* write the file */
|
||||||
if ((fd = open(profile, O_CREAT | O_EXCL | O_WRONLY, 0644)) == -1) {
|
if ((fd = open(profile, O_CREAT | O_EXCL | O_WRONLY, 0644)) == -1) {
|
||||||
vah_error(NULL, 0, "failed to create profile");
|
vah_error(NULL, 0, _("failed to create profile"));
|
||||||
goto clean_all;
|
goto clean_all;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (safewrite(fd, pcontent, plen - 1) < 0) { /* don't write the '\0' */
|
if (safewrite(fd, pcontent, plen - 1) < 0) { /* don't write the '\0' */
|
||||||
VIR_FORCE_CLOSE(fd);
|
VIR_FORCE_CLOSE(fd);
|
||||||
vah_error(NULL, 0, "failed to write to profile");
|
vah_error(NULL, 0, _("failed to write to profile"));
|
||||||
goto clean_all;
|
goto clean_all;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_CLOSE(fd) != 0) {
|
if (VIR_CLOSE(fd) != 0) {
|
||||||
vah_error(NULL, 0, "failed to close or write to profile");
|
vah_error(NULL, 0, _("failed to close or write to profile")_;
|
||||||
goto clean_all;
|
goto clean_all;
|
||||||
}
|
}
|
||||||
rc = 0;
|
rc = 0;
|
||||||
@ -532,7 +535,7 @@ valid_path(const char *path, const bool readonly)
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (path == NULL || strlen(path) > PATH_MAX - 1) {
|
if (path == NULL || strlen(path) > PATH_MAX - 1) {
|
||||||
vah_error(NULL, 0, "bad pathname");
|
vah_error(NULL, 0, _("bad pathname"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -547,7 +550,7 @@ valid_path(const char *path, const bool readonly)
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (!virFileExists(path))
|
if (!virFileExists(path))
|
||||||
vah_warning("path does not exist, skipping file type checks");
|
vah_warning(_("path does not exist, skipping file type checks"));
|
||||||
else {
|
else {
|
||||||
if (stat(path, &sb) == -1)
|
if (stat(path, &sb) == -1)
|
||||||
return -1;
|
return -1;
|
||||||
@ -597,7 +600,7 @@ catchXMLError (void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
|
|||||||
if (virAsprintf(&err_str, "XML error at line %d: %s",
|
if (virAsprintf(&err_str, "XML error at line %d: %s",
|
||||||
ctxt->lastError.line,
|
ctxt->lastError.line,
|
||||||
ctxt->lastError.message) == -1)
|
ctxt->lastError.message) == -1)
|
||||||
vah_error(NULL, 0, "Could not get XML error");
|
vah_error(NULL, 0, _("could not get XML error"));
|
||||||
else {
|
else {
|
||||||
vah_error(NULL, 0, err_str);
|
vah_error(NULL, 0, err_str);
|
||||||
VIR_FREE(err_str);
|
VIR_FREE(err_str);
|
||||||
@ -613,20 +616,20 @@ verify_xpath_context(xmlXPathContextPtr ctxt)
|
|||||||
char *tmp = NULL;
|
char *tmp = NULL;
|
||||||
|
|
||||||
if (!ctxt) {
|
if (!ctxt) {
|
||||||
vah_warning("Invalid context");
|
vah_warning(_("Invalid context"));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check if have <name> */
|
/* check if have <name> */
|
||||||
if (!(tmp = virXPathString("string(./name[1])", ctxt))) {
|
if (!(tmp = virXPathString("string(./name[1])", ctxt))) {
|
||||||
vah_warning("Could not find <name>");
|
vah_warning(_("Could not find <name>"));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
VIR_FREE(tmp);
|
VIR_FREE(tmp);
|
||||||
|
|
||||||
/* check if have <uuid> */
|
/* check if have <uuid> */
|
||||||
if (!(tmp = virXPathString("string(./uuid[1])", ctxt))) {
|
if (!(tmp = virXPathString("string(./uuid[1])", ctxt))) {
|
||||||
vah_warning("Could not find <uuid>");
|
vah_warning(_("Could not find <uuid>"));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
VIR_FREE(tmp);
|
VIR_FREE(tmp);
|
||||||
@ -665,22 +668,22 @@ caps_mockup(vahControl * ctl, const char *xmlStr)
|
|||||||
XML_PARSE_NOWARNING);
|
XML_PARSE_NOWARNING);
|
||||||
if (!xml) {
|
if (!xml) {
|
||||||
if (virGetLastError() == NULL)
|
if (virGetLastError() == NULL)
|
||||||
vah_error(NULL, 0, "failed to parse xml document");
|
vah_error(NULL, 0, _("failed to parse xml document"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((root = xmlDocGetRootElement(xml)) == NULL) {
|
if ((root = xmlDocGetRootElement(xml)) == NULL) {
|
||||||
vah_error(NULL, 0, "missing root element");
|
vah_error(NULL, 0, _("missing root element"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!xmlStrEqual(root->name, BAD_CAST "domain")) {
|
if (!xmlStrEqual(root->name, BAD_CAST "domain")) {
|
||||||
vah_error(NULL, 0, "incorrect root element");
|
vah_error(NULL, 0, _("incorrect root element"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ctxt = xmlXPathNewContext(xml)) == NULL) {
|
if ((ctxt = xmlXPathNewContext(xml)) == NULL) {
|
||||||
vah_error(ctl, 0, "could not allocate memory");
|
vah_error(ctl, 0, _("could not allocate memory"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
ctxt->node = root;
|
ctxt->node = root;
|
||||||
@ -691,7 +694,7 @@ caps_mockup(vahControl * ctl, const char *xmlStr)
|
|||||||
|
|
||||||
ctl->hvm = virXPathString("string(./os/type[1])", ctxt);
|
ctl->hvm = virXPathString("string(./os/type[1])", ctxt);
|
||||||
if (!ctl->hvm || STRNEQ(ctl->hvm, "hvm")) {
|
if (!ctl->hvm || STRNEQ(ctl->hvm, "hvm")) {
|
||||||
vah_error(ctl, 0, "os.type is not 'hvm'");
|
vah_error(ctl, 0, _("os.type is not 'hvm'"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
ctl->arch = virXPathString("string(./os/type[1]/@arch)", ctxt);
|
ctl->arch = virXPathString("string(./os/type[1]/@arch)", ctxt);
|
||||||
@ -704,7 +707,7 @@ caps_mockup(vahControl * ctl, const char *xmlStr)
|
|||||||
/* Really, this never fails - look at the man-page. */
|
/* Really, this never fails - look at the man-page. */
|
||||||
uname (&utsname);
|
uname (&utsname);
|
||||||
if ((ctl->arch = strdup(utsname.machine)) == NULL) {
|
if ((ctl->arch = strdup(utsname.machine)) == NULL) {
|
||||||
vah_error(ctl, 0, "could not allocate memory");
|
vah_error(ctl, 0, _("could not allocate memory"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -737,7 +740,7 @@ get_definition(vahControl * ctl, const char *xmlStr)
|
|||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
if ((ctl->caps = virCapabilitiesNew(ctl->arch, 1, 1)) == NULL) {
|
if ((ctl->caps = virCapabilitiesNew(ctl->arch, 1, 1)) == NULL) {
|
||||||
vah_error(ctl, 0, "could not allocate memory");
|
vah_error(ctl, 0, _("could not allocate memory"));
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -749,24 +752,24 @@ get_definition(vahControl * ctl, const char *xmlStr)
|
|||||||
NULL,
|
NULL,
|
||||||
0,
|
0,
|
||||||
NULL)) == NULL) {
|
NULL)) == NULL) {
|
||||||
vah_error(ctl, 0, "could not allocate memory");
|
vah_error(ctl, 0, _("could not allocate memory"));
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctl->def = virDomainDefParseString(ctl->caps, xmlStr,
|
ctl->def = virDomainDefParseString(ctl->caps, xmlStr,
|
||||||
VIR_DOMAIN_XML_INACTIVE);
|
VIR_DOMAIN_XML_INACTIVE);
|
||||||
if (ctl->def == NULL) {
|
if (ctl->def == NULL) {
|
||||||
vah_error(ctl, 0, "could not parse XML");
|
vah_error(ctl, 0, _("could not parse XML"));
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ctl->def->name) {
|
if (!ctl->def->name) {
|
||||||
vah_error(ctl, 0, "could not find name in XML");
|
vah_error(ctl, 0, _("could not find name in XML"));
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (valid_name(ctl->def->name) != 0) {
|
if (valid_name(ctl->def->name) != 0) {
|
||||||
vah_error(ctl, 0, "bad name");
|
vah_error(ctl, 0, _("bad name"));
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -792,14 +795,14 @@ vah_add_file(virBufferPtr buf, const char *path, const char *perms)
|
|||||||
*/
|
*/
|
||||||
if (STRNEQLEN(path, "/", 1)) {
|
if (STRNEQLEN(path, "/", 1)) {
|
||||||
vah_warning(path);
|
vah_warning(path);
|
||||||
vah_warning(" skipped non-absolute path");
|
vah_warning(_(" skipped non-absolute path"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virFileExists(path)) {
|
if (virFileExists(path)) {
|
||||||
if ((tmp = realpath(path, NULL)) == NULL) {
|
if ((tmp = realpath(path, NULL)) == NULL) {
|
||||||
vah_error(NULL, 0, path);
|
vah_error(NULL, 0, path);
|
||||||
vah_error(NULL, 0, " could not find realpath for disk");
|
vah_error(NULL, 0, _(" could not find realpath for disk"));
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
@ -813,7 +816,7 @@ vah_add_file(virBufferPtr buf, const char *path, const char *perms)
|
|||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
if (rc > 0) {
|
if (rc > 0) {
|
||||||
vah_error(NULL, 0, path);
|
vah_error(NULL, 0, path);
|
||||||
vah_error(NULL, 0, " skipped restricted file");
|
vah_error(NULL, 0, _(" skipped restricted file"));
|
||||||
}
|
}
|
||||||
goto clean;
|
goto clean;
|
||||||
}
|
}
|
||||||
@ -883,12 +886,12 @@ get_files(vahControl * ctl)
|
|||||||
/* verify uuid is same as what we were given on the command line */
|
/* verify uuid is same as what we were given on the command line */
|
||||||
virUUIDFormat(ctl->def->uuid, uuidstr);
|
virUUIDFormat(ctl->def->uuid, uuidstr);
|
||||||
if (virAsprintf(&uuid, "%s%s", AA_PREFIX, uuidstr) == -1) {
|
if (virAsprintf(&uuid, "%s%s", AA_PREFIX, uuidstr) == -1) {
|
||||||
vah_error(ctl, 0, "could not allocate memory");
|
vah_error(ctl, 0, _("could not allocate memory"));
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (STRNEQ(uuid, ctl->uuid)) {
|
if (STRNEQ(uuid, ctl->uuid)) {
|
||||||
vah_error(ctl, 0, "given uuid does not match XML uuid");
|
vah_error(ctl, 0, _("given uuid does not match XML uuid"));
|
||||||
goto clean;
|
goto clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1009,7 +1012,7 @@ get_files(vahControl * ctl)
|
|||||||
|
|
||||||
if (virBufferError(&buf)) {
|
if (virBufferError(&buf)) {
|
||||||
virBufferFreeAndReset(&buf);
|
virBufferFreeAndReset(&buf);
|
||||||
vah_error(NULL, 0, "failed to allocate file buffer");
|
vah_error(NULL, 0, _("failed to allocate file buffer"));
|
||||||
goto clean;
|
goto clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1058,7 +1061,7 @@ vahParseArgv(vahControl * ctl, int argc, char **argv)
|
|||||||
case 'f':
|
case 'f':
|
||||||
case 'F':
|
case 'F':
|
||||||
if ((ctl->newfile = strdup(optarg)) == NULL)
|
if ((ctl->newfile = strdup(optarg)) == NULL)
|
||||||
vah_error(ctl, 1, "could not allocate memory for disk");
|
vah_error(ctl, 1, _("could not allocate memory for disk")_;
|
||||||
ctl->append = arg == 'F';
|
ctl->append = arg == 'F';
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
@ -1073,10 +1076,10 @@ vahParseArgv(vahControl * ctl, int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
if (strlen(optarg) > PROFILE_NAME_SIZE - 1)
|
if (strlen(optarg) > PROFILE_NAME_SIZE - 1)
|
||||||
vah_error(ctl, 1, "invalid UUID");
|
vah_error(ctl, 1, _("invalid UUID"));
|
||||||
if (virStrcpy((char *) ctl->uuid, optarg,
|
if (virStrcpy((char *) ctl->uuid, optarg,
|
||||||
PROFILE_NAME_SIZE) == NULL)
|
PROFILE_NAME_SIZE) == NULL)
|
||||||
vah_error(ctl, 1, "error copying UUID");
|
vah_error(ctl, 1, _("error copying UUID"));
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
if (STREQ(optarg, "1"))
|
if (STREQ(optarg, "1"))
|
||||||
@ -1085,15 +1088,15 @@ vahParseArgv(vahControl * ctl, int argc, char **argv)
|
|||||||
ctl->allowDiskFormatProbing = false;
|
ctl->allowDiskFormatProbing = false;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
vah_error(ctl, 1, "unsupported option");
|
vah_error(ctl, 1, _("unsupported option"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (strchr("acDrR", ctl->cmd) == NULL)
|
if (strchr("acDrR", ctl->cmd) == NULL)
|
||||||
vah_error(ctl, 1, "bad command");
|
vah_error(ctl, 1, _("bad command"));
|
||||||
|
|
||||||
if (valid_uuid(ctl->uuid) != 0)
|
if (valid_uuid(ctl->uuid) != 0)
|
||||||
vah_error(ctl, 1, "invalid UUID");
|
vah_error(ctl, 1, _("invalid UUID"));
|
||||||
|
|
||||||
if (!ctl->cmd) {
|
if (!ctl->cmd) {
|
||||||
vah_usage();
|
vah_usage();
|
||||||
@ -1103,16 +1106,16 @@ vahParseArgv(vahControl * ctl, int argc, char **argv)
|
|||||||
if (ctl->cmd == 'c' || ctl->cmd == 'r') {
|
if (ctl->cmd == 'c' || ctl->cmd == 'r') {
|
||||||
char *xmlStr = NULL;
|
char *xmlStr = NULL;
|
||||||
if (virFileReadLimFD(STDIN_FILENO, MAX_FILE_LEN, &xmlStr) < 0)
|
if (virFileReadLimFD(STDIN_FILENO, MAX_FILE_LEN, &xmlStr) < 0)
|
||||||
vah_error(ctl, 1, "could not read xml file");
|
vah_error(ctl, 1, _("could not read xml file"));
|
||||||
|
|
||||||
if (get_definition(ctl, xmlStr) != 0 || ctl->def == NULL) {
|
if (get_definition(ctl, xmlStr) != 0 || ctl->def == NULL) {
|
||||||
VIR_FREE(xmlStr);
|
VIR_FREE(xmlStr);
|
||||||
vah_error(ctl, 1, "could not get VM definition");
|
vah_error(ctl, 1, _("could not get VM definition"));
|
||||||
}
|
}
|
||||||
VIR_FREE(xmlStr);
|
VIR_FREE(xmlStr);
|
||||||
|
|
||||||
if (get_files(ctl) != 0)
|
if (get_files(ctl) != 0)
|
||||||
vah_error(ctl, 1, "invalid VM definition");
|
vah_error(ctl, 1, _("invalid VM definition"));
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1144,10 +1147,11 @@ main(int argc, char **argv)
|
|||||||
/* clear the environment */
|
/* clear the environment */
|
||||||
environ = NULL;
|
environ = NULL;
|
||||||
if (setenv("PATH", "/sbin:/usr/sbin", 1) != 0) {
|
if (setenv("PATH", "/sbin:/usr/sbin", 1) != 0) {
|
||||||
vah_error(ctl, 1, "could not set PATH");
|
vah_error(ctl, 1, _("could not set PATH"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setenv("IFS", " \t\n", 1) != 0) {
|
if (setenv("IFS", " \t\n", 1) != 0) {
|
||||||
vah_error(ctl, 1, "could not set IFS");
|
vah_error(ctl, 1, _("could not set IFS"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(progname = strrchr(argv[0], '/')))
|
if (!(progname = strrchr(argv[0], '/')))
|
||||||
@ -1158,15 +1162,15 @@ main(int argc, char **argv)
|
|||||||
memset(ctl, 0, sizeof(vahControl));
|
memset(ctl, 0, sizeof(vahControl));
|
||||||
|
|
||||||
if (vahParseArgv(ctl, argc, argv) != 0)
|
if (vahParseArgv(ctl, argc, argv) != 0)
|
||||||
vah_error(ctl, 1, "could not parse arguments");
|
vah_error(ctl, 1, _("could not parse arguments"));
|
||||||
|
|
||||||
if (snprintf(profile, PATH_MAX, "%s/%s",
|
if (snprintf(profile, PATH_MAX, "%s/%s",
|
||||||
APPARMOR_DIR "/libvirt", ctl->uuid) > PATH_MAX - 1)
|
APPARMOR_DIR "/libvirt", ctl->uuid) > PATH_MAX - 1)
|
||||||
vah_error(ctl, 1, "profile name exceeds maximum length");
|
vah_error(ctl, 1, _("profile name exceeds maximum length"));
|
||||||
|
|
||||||
if (snprintf(include_file, PATH_MAX, "%s/%s.files",
|
if (snprintf(include_file, PATH_MAX, "%s/%s.files",
|
||||||
APPARMOR_DIR "/libvirt", ctl->uuid) > PATH_MAX - 1)
|
APPARMOR_DIR "/libvirt", ctl->uuid) > PATH_MAX - 1)
|
||||||
vah_error(ctl, 1, "disk profile name exceeds maximum length");
|
vah_error(ctl, 1, _("disk profile name exceeds maximum length"));
|
||||||
|
|
||||||
if (ctl->cmd == 'a')
|
if (ctl->cmd == 'a')
|
||||||
rc = parserLoad(ctl->uuid);
|
rc = parserLoad(ctl->uuid);
|
||||||
@ -1179,8 +1183,9 @@ main(int argc, char **argv)
|
|||||||
} else if (ctl->cmd == 'c' || ctl->cmd == 'r') {
|
} else if (ctl->cmd == 'c' || ctl->cmd == 'r') {
|
||||||
char *included_files = NULL;
|
char *included_files = NULL;
|
||||||
|
|
||||||
if (ctl->cmd == 'c' && virFileExists(profile))
|
if (ctl->cmd == 'c' && virFileExists(profile)) {
|
||||||
vah_error(ctl, 1, "profile exists");
|
vah_error(ctl, 1, _("profile exists"));
|
||||||
|
}
|
||||||
|
|
||||||
if (ctl->append && ctl->newfile) {
|
if (ctl->append && ctl->newfile) {
|
||||||
if (vah_add_file(&buf, ctl->newfile, "rw") != 0)
|
if (vah_add_file(&buf, ctl->newfile, "rw") != 0)
|
||||||
@ -1198,7 +1203,7 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
if (virBufferError(&buf)) {
|
if (virBufferError(&buf)) {
|
||||||
virBufferFreeAndReset(&buf);
|
virBufferFreeAndReset(&buf);
|
||||||
vah_error(ctl, 1, "failed to allocate buffer");
|
vah_error(ctl, 1, _("failed to allocate buffer"));
|
||||||
}
|
}
|
||||||
|
|
||||||
included_files = virBufferContentAndReset(&buf);
|
included_files = virBufferContentAndReset(&buf);
|
||||||
@ -1219,7 +1224,7 @@ main(int argc, char **argv)
|
|||||||
char *tmp = NULL;
|
char *tmp = NULL;
|
||||||
if (virAsprintf(&tmp, " #include <libvirt/%s.files>\n",
|
if (virAsprintf(&tmp, " #include <libvirt/%s.files>\n",
|
||||||
ctl->uuid) == -1) {
|
ctl->uuid) == -1) {
|
||||||
vah_error(ctl, 0, "could not allocate memory");
|
vah_error(ctl, 0, _("could not allocate memory"));
|
||||||
goto clean;
|
goto clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1229,7 +1234,7 @@ main(int argc, char **argv)
|
|||||||
vah_info(tmp);
|
vah_info(tmp);
|
||||||
rc = 0;
|
rc = 0;
|
||||||
} else if ((rc = create_profile(profile, ctl->uuid, tmp)) != 0) {
|
} else if ((rc = create_profile(profile, ctl->uuid, tmp)) != 0) {
|
||||||
vah_error(ctl, 0, "could not create profile");
|
vah_error(ctl, 0, _("could not create profile"));
|
||||||
unlink(include_file);
|
unlink(include_file);
|
||||||
}
|
}
|
||||||
VIR_FREE(tmp);
|
VIR_FREE(tmp);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user