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. --- cfg.mk | 2 + src/security/virt-aa-helper.c | 187 +++++++++++++++++++++-------------------- 2 files changed, 98 insertions(+), 91 deletions(-) diff --git a/cfg.mk b/cfg.mk index d47af80..03d77d5 100644 --- a/cfg.mk +++ b/cfg.mk @@ -337,6 +337,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 3b13298..12adbbb 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-2010 Canonical Ltd. * * See COPYING.LIB for the License of this software @@ -82,28 +84,28 @@ vahDeinit(vahControl * ctl) static void vah_usage(void) { - fprintf(stdout, "\n%s [options] [< def.xml]\n\n" - " Options:\n" - " -a | --add load profile\n" - " -c | --create create profile from template\n" - " -D | --delete unload and delete profile\n" - " -f | --add-file <file> add file to profile\n" - " -F | --append-file <file> append file to profile\n" - " -r | --replace reload profile\n" - " -R | --remove unload profile\n" - " -h | --help this help\n" - " -u | --uuid <uuid> uuid (profile name)\n" - "\n", progname); - - fprintf(stdout, "This command is intended to be used by libvirtd " - "and not used directly.\n"); + fprintf(stdout, _("\n%s [options] [< def.xml]\n\n + Options:\n + -a | --add load profile\n + -c | --create create profile from template\n + -D | --delete unload and delete profile\n + -f | --add-file <file> add file to profile\n + -F | --append-file <file> append file to profile\n + -r | --replace reload profile\n + -R | --remove unload profile\n + -h | --help this help\n + -u | --uuid <uuid> uuid (profile name)\n +\n", progname); + + fputs(_("This command is intended to be used by libvirtd " + "and not used directly.\n")); return; } static void 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 (ctl != NULL) @@ -115,13 +117,13 @@ vah_error(vahControl * ctl, int doexit, const char *str) static void vah_warning(const char *str) { - fprintf(stderr, _("%s: warning: %s\n"), progname, str); + fprintf(stderr, _("%s: warning: %s%c"), progname, str, '\n'); } static void 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; 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'; @@ -155,7 +157,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; } @@ -163,7 +165,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; } @@ -171,7 +173,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; } @@ -192,7 +194,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; } @@ -200,12 +202,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[] = { @@ -214,12 +216,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; } } @@ -251,19 +254,19 @@ update_include_file(const char *include_file, const char *included_files, if (append && virFileExists(include_file)) { 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; } } else { 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; } } 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; } @@ -275,18 +278,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' */ VIR_FORCE_CLOSE(fd); - vah_error(NULL, 0, "failed to write to profile"); + vah_error(NULL, 0, _("failed to write to profile")); goto clean; } 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; } rc = 0; @@ -317,45 +320,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; } @@ -363,12 +366,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'; @@ -382,18 +385,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' */ 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; } 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; } rc = 0; @@ -532,7 +535,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; } @@ -547,7 +550,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; @@ -597,7 +600,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); @@ -613,20 +616,20 @@ verify_xpath_context(xmlXPathContextPtr ctxt) char *tmp = NULL; if (!ctxt) { - vah_warning("Invalid context"); + vah_warning(_("Invalid context")); goto error; } /* check if have <name> */ if (!(tmp = virXPathString("string(./name[1])", ctxt))) { - vah_warning("Could not find <name>"); + vah_warning(_("Could not find <name>")); goto error; } VIR_FREE(tmp); /* check if have <uuid> */ if (!(tmp = virXPathString("string(./uuid[1])", ctxt))) { - vah_warning("Could not find <uuid>"); + vah_warning(_("Could not find <uuid>")); goto error; } VIR_FREE(tmp); @@ -665,22 +668,22 @@ 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; @@ -691,7 +694,7 @@ caps_mockup(vahControl * ctl, const char *xmlStr) 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); @@ -704,7 +707,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; } } @@ -737,7 +740,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; } @@ -749,24 +752,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; } @@ -792,14 +795,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 @@ -813,7 +816,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; } @@ -883,12 +886,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; } @@ -1009,7 +1012,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; } @@ -1058,7 +1061,7 @@ vahParseArgv(vahControl * ctl, int argc, char **argv) case 'f': case 'F': 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'; break; case 'h': @@ -1073,10 +1076,10 @@ 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; case 'p': if (STREQ(optarg, "1")) @@ -1085,15 +1088,15 @@ vahParseArgv(vahControl * ctl, int argc, char **argv) ctl->allowDiskFormatProbing = false; 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(); @@ -1103,16 +1106,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; } @@ -1144,10 +1147,11 @@ 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], '/'))) @@ -1158,15 +1162,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); @@ -1179,8 +1183,9 @@ main(int argc, char **argv) } else if (ctl->cmd == 'c' || ctl->cmd == 'r') { char *included_files = NULL; - if (ctl->cmd == 'c' && virFileExists(profile)) - vah_error(ctl, 1, "profile exists"); + if (ctl->cmd == 'c' && virFileExists(profile)) { + vah_error(ctl, 1, _("profile exists")); + } if (ctl->append && ctl->newfile) { if (vah_add_file(&buf, ctl->newfile, "rw") != 0) @@ -1198,7 +1203,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); @@ -1219,7 +1224,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; } @@ -1229,7 +1234,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.3.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list