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.
---
I don't have an environment set up to build with apparmor, so
outside testing would be appreciated (I guess I need to look
into getting myself an ubuntu VM, to at least play more with
apparmor code). But by inspection, this patch looks sane.
cfg.mk | 2 +
src/security/virt-aa-helper.c | 141 +++++++++++++++++++++--------------------
2 files changed, 74 insertions(+), 69 deletions(-)
diff --git a/cfg.mk b/cfg.mk
index 7773d06..f5051d4 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -186,6 +186,8 @@ msg_gen_function += qemudReportError
msg_gen_function += regerror
msg_gen_function += remoteDispatchFormatError
msg_gen_function += umlReportError
+msg_gen_function += vah_error
+msg_gen_function += vah_warning
msg_gen_function += vboxError
msg_gen_function += virConfError
msg_gen_function += virDomainReportError
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c
index ae923e8..1945f05 100644
--- a/src/security/virt-aa-helper.c
+++ b/src/security/virt-aa-helper.c
@@ -1,6 +1,8 @@
/*
* virt-aa-helper: wrapper program used by AppArmor security driver.
+ *
+ * Copyright (C) 2010 Red Hat, Inc.
* Copyright (C) 2009 Canonical Ltd.
*
* See COPYING.LIB for the License of this software
@@ -133,12 +135,12 @@ replace_string(char *orig, const size_t len, const char *oldstr,
char *tmp = 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;
}
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;
}
tmp[0] = '\0';
@@ -150,7 +152,7 @@ replace_string(char *orig, const size_t len, const char *oldstr,
/* add the replacement string */
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);
return -1;
}
@@ -158,7 +160,7 @@ replace_string(char *orig, const size_t len, const char *oldstr,
/* add everything after oldstr */
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);
return -1;
}
@@ -166,7 +168,7 @@ replace_string(char *orig, const size_t len, const char *oldstr,
strlen(orig) - (idx + strlen(oldstr)));
if (virStrcpy(orig, tmp, len) == NULL) {
- vah_error(NULL, 0, "error replacing string");
+ vah_error(NULL, 0, _("error replacing string"));
VIR_FREE(tmp);
return -1;
}
@@ -187,7 +189,7 @@ parserCommand(const char *profile_name, const char cmd)
int ret;
if (strchr("arR", cmd) == NULL) {
- vah_error(NULL, 0, "invalid flag");
+ vah_error(NULL, 0, _("invalid flag"));
return -1;
}
@@ -195,12 +197,12 @@ parserCommand(const char *profile_name, const char cmd)
if (snprintf(profile, PATH_MAX, "%s/%s",
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;
}
if (!virFileExists(profile)) {
- vah_error(NULL, 0, "profile does not exist");
+ vah_error(NULL, 0, _("profile does not exist"));
return -1;
} else {
const char * const argv[] = {
@@ -209,12 +211,13 @@ parserCommand(const char *profile_name, const char cmd)
if ((ret = virRun(argv, &status)) != 0 ||
(WIFEXITED(status) && WEXITSTATUS(status) != 0)) {
if (ret != 0) {
- vah_error(NULL, 0, "failed to run apparmor_parser");
+ vah_error(NULL, 0, _("failed to run apparmor_parser"));
return -1;
- } else if (cmd == 'R' && WIFEXITED(status) &&
WEXITSTATUS(status) == 234) {
- vah_warning("unable to unload already unloaded profile
(non-fatal)");
+ } else if (cmd == 'R' && WIFEXITED(status) &&
+ WEXITSTATUS(status) == 234) {
+ vah_warning(_("unable to unload already unloaded profile"));
} else {
- vah_error(NULL, 0, "apparmor_parser exited with error");
+ vah_error(NULL, 0, _("apparmor_parser exited with error"));
return -1;
}
}
@@ -237,13 +240,13 @@ update_include_file(const char *include_file, const char
*included_files)
"# DO NOT EDIT THIS FILE DIRECTLY. IT IS MANAGED BY LIBVIRT.\n";
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"));
return rc;
}
plen = strlen(pcontent);
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;
}
@@ -266,18 +269,18 @@ update_include_file(const char *include_file, const char
*included_files)
/* write the file */
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;
}
if (safewrite(fd, pcontent, plen) < 0) { /* don't write the '\0' */
close(fd);
- vah_error(NULL, 0, "failed to write to profile");
+ vah_error(NULL, 0, _("failed to write to profile"));
goto clean;
}
if (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;
}
rc = 0;
@@ -307,45 +310,45 @@ create_profile(const char *profile, const char *profile_name,
int rc = -1;
if (virFileExists(profile)) {
- vah_error(NULL, 0, "profile exists");
+ vah_error(NULL, 0, _("profile exists"));
goto end;
}
if (snprintf(template, PATH_MAX, "%s/TEMPLATE",
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;
}
if (!virFileExists(template)) {
- vah_error(NULL, 0, "template does not exist");
+ vah_error(NULL, 0, _("template does not exist"));
goto end;
}
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;
}
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;
}
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;
}
/* '\nprofile <profile_name>\0' */
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;
}
/* '\n<profile_files>\n}\0' */
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);
goto clean_tcontent;
}
@@ -353,12 +356,12 @@ create_profile(const char *profile, const char *profile_name,
plen = tlen + strlen(replace_name) - strlen(template_name) +
strlen(replace_files) - strlen(template_end) + 1;
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;
}
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;
}
pcontent[0] = '\0';
@@ -372,18 +375,18 @@ create_profile(const char *profile, const char *profile_name,
/* write the file */
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;
}
if (safewrite(fd, pcontent, plen - 1) < 0) { /* don't write the '\0'
*/
close(fd);
- vah_error(NULL, 0, "failed to write to profile");
+ vah_error(NULL, 0, _("failed to write to profile"));
goto clean_all;
}
if (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;
}
rc = 0;
@@ -522,7 +525,7 @@ valid_path(const char *path, const bool readonly)
};
if (path == NULL || strlen(path) > PATH_MAX - 1) {
- vah_error(NULL, 0, "bad pathname");
+ vah_error(NULL, 0, _("bad pathname"));
return -1;
}
@@ -537,7 +540,7 @@ valid_path(const char *path, const bool readonly)
return 1;
if (!virFileExists(path))
- vah_warning("path does not exist, skipping file type checks");
+ vah_warning(_("path does not exist, skipping file type checks"));
else {
if (stat(path, &sb) == -1)
return -1;
@@ -587,7 +590,7 @@ catchXMLError (void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
if (virAsprintf(&err_str, "XML error at line %d: %s",
ctxt->lastError.line,
ctxt->lastError.message) == -1)
- vah_error(NULL, 0, "Could not get XML error");
+ vah_error(NULL, 0, _("could not get XML error"));
else {
vah_error(NULL, 0, err_str);
VIR_FREE(err_str);
@@ -624,29 +627,29 @@ caps_mockup(vahControl * ctl, const char *xmlStr)
XML_PARSE_NOWARNING);
if (!xml) {
if (virGetLastError() == NULL)
- vah_error(NULL, 0, "failed to parse xml document");
+ vah_error(NULL, 0, _("failed to parse xml document"));
goto cleanup;
}
if ((root = xmlDocGetRootElement(xml)) == NULL) {
- vah_error(NULL, 0, "missing root element");
+ vah_error(NULL, 0, _("missing root element"));
goto cleanup;
}
if (!xmlStrEqual(root->name, BAD_CAST "domain")) {
- vah_error(NULL, 0, "incorrect root element");
+ vah_error(NULL, 0, _("incorrect root element"));
goto cleanup;
}
if ((ctxt = xmlXPathNewContext(xml)) == NULL) {
- vah_error(ctl, 0, "could not allocate memory");
+ vah_error(ctl, 0, _("could not allocate memory"));
goto cleanup;
}
ctxt->node = root;
ctl->hvm = virXPathString("string(./os/type[1])", ctxt);
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;
}
ctl->arch = virXPathString("string(./os/type[1]/@arch)", ctxt);
@@ -659,7 +662,7 @@ caps_mockup(vahControl * ctl, const char *xmlStr)
/* Really, this never fails - look at the man-page. */
uname (&utsname);
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;
}
}
@@ -692,7 +695,7 @@ get_definition(vahControl * ctl, const char *xmlStr)
goto exit;
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;
}
@@ -704,24 +707,24 @@ get_definition(vahControl * ctl, const char *xmlStr)
NULL,
0,
NULL)) == NULL) {
- vah_error(ctl, 0, "could not allocate memory");
+ vah_error(ctl, 0, _("could not allocate memory"));
goto exit;
}
ctl->def = virDomainDefParseString(ctl->caps, xmlStr,
VIR_DOMAIN_XML_INACTIVE);
if (ctl->def == NULL) {
- vah_error(ctl, 0, "could not parse XML");
+ vah_error(ctl, 0, _("could not parse XML"));
goto exit;
}
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;
}
if (valid_name(ctl->def->name) != 0) {
- vah_error(ctl, 0, "bad name");
+ vah_error(ctl, 0, _("bad name"));
goto exit;
}
@@ -747,14 +750,14 @@ vah_add_file(virBufferPtr buf, const char *path, const char *perms)
*/
if (STRNEQLEN(path, "/", 1)) {
vah_warning(path);
- vah_warning(" skipped non-absolute path");
+ vah_warning(_(" skipped non-absolute path"));
return 0;
}
if (virFileExists(path)) {
if ((tmp = realpath(path, NULL)) == NULL) {
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;
}
} else
@@ -768,7 +771,7 @@ vah_add_file(virBufferPtr buf, const char *path, const char *perms)
if (rc != 0) {
if (rc > 0) {
vah_error(NULL, 0, path);
- vah_error(NULL, 0, " skipped restricted file");
+ vah_error(NULL, 0, _(" skipped restricted file"));
}
goto clean;
}
@@ -813,12 +816,12 @@ get_files(vahControl * ctl)
/* 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) {
- vah_error(ctl, 0, "could not allocate memory");
+ vah_error(ctl, 0, _("could not allocate memory"));
return rc;
}
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;
}
@@ -840,7 +843,7 @@ get_files(vahControl * ctl)
path = NULL;
if (ret < 0) {
- vah_warning("could not open path, skipping");
+ vah_warning(_("could not open path, skipping"));
continue;
}
@@ -936,7 +939,7 @@ get_files(vahControl * ctl)
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
- vah_error(NULL, 0, "failed to allocate file buffer");
+ vah_error(NULL, 0, _("failed to allocate file buffer"));
goto clean;
}
@@ -982,7 +985,7 @@ vahParseArgv(vahControl * ctl, int argc, char **argv)
break;
case 'f':
if ((ctl->newdisk = strdup(optarg)) == NULL)
- vah_error(ctl, 1, "could not allocate memory for disk");
+ vah_error(ctl, 1, _("could not allocate memory for
disk"));
break;
case 'h':
vah_usage();
@@ -996,21 +999,21 @@ vahParseArgv(vahControl * ctl, int argc, char **argv)
break;
case 'u':
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,
PROFILE_NAME_SIZE) == NULL)
- vah_error(ctl, 1, "error copying UUID");
+ vah_error(ctl, 1, _("error copying UUID"));
break;
default:
- vah_error(ctl, 1, "unsupported option");
+ vah_error(ctl, 1, _("unsupported option"));
break;
}
}
if (strchr("acDrR", ctl->cmd) == NULL)
- vah_error(ctl, 1, "bad command");
+ vah_error(ctl, 1, _("bad command"));
if (valid_uuid(ctl->uuid) != 0)
- vah_error(ctl, 1, "invalid UUID");
+ vah_error(ctl, 1, _("invalid UUID"));
if (!ctl->cmd) {
vah_usage();
@@ -1020,16 +1023,16 @@ vahParseArgv(vahControl * ctl, int argc, char **argv)
if (ctl->cmd == 'c' || ctl->cmd == 'r') {
char *xmlStr = NULL;
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) {
VIR_FREE(xmlStr);
- vah_error(ctl, 1, "could not get VM definition");
+ vah_error(ctl, 1, _("could not get VM definition"));
}
VIR_FREE(xmlStr);
if (get_files(ctl) != 0)
- vah_error(ctl, 1, "invalid VM definition");
+ vah_error(ctl, 1, _("invalid VM definition"));
}
return 0;
}
@@ -1054,10 +1057,10 @@ main(int argc, char **argv)
/* clear the environment */
environ = NULL;
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) {
- vah_error(ctl, 1, "could not set IFS");
+ vah_error(ctl, 1, _("could not set IFS"));
}
if (!(progname = strrchr(argv[0], '/')))
@@ -1068,15 +1071,15 @@ main(int argc, char **argv)
memset(ctl, 0, sizeof(vahControl));
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",
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",
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')
rc = parserLoad(ctl->uuid);
@@ -1090,7 +1093,7 @@ main(int argc, char **argv)
char *included_files = NULL;
if (ctl->cmd == 'c' && virFileExists(profile))
- vah_error(ctl, 1, "profile exists");
+ vah_error(ctl, 1, _("profile exists"));
virBufferVSprintf(&buf, " \"%s/log/libvirt/**/%s.log\"
w,\n",
LOCAL_STATE_DIR, ctl->def->name);
@@ -1103,7 +1106,7 @@ main(int argc, char **argv)
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
- vah_error(ctl, 1, "failed to allocate buffer");
+ vah_error(ctl, 1, _("failed to allocate buffer"));
}
included_files = virBufferContentAndReset(&buf);
@@ -1123,7 +1126,7 @@ main(int argc, char **argv)
char *tmp = NULL;
if (virAsprintf(&tmp, " #include <libvirt/%s.files>\n",
ctl->uuid) == -1) {
- vah_error(ctl, 0, "could not allocate memory");
+ vah_error(ctl, 0, _("could not allocate memory"));
goto clean;
}
@@ -1133,7 +1136,7 @@ main(int argc, char **argv)
vah_info(tmp);
rc = 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);
}
VIR_FREE(tmp);
--
1.7.0.1