提交 232b7417 编写于 作者: J John Ferlan

secret: Adjust logic to build file path in secretLoad

The 'secretLoad' was essentially open coding virFileBuildPath.

Adjust the logic to have the caller build the path and pass it. The net
sum of ignoring the virFileBuildPath failure is the same as before where
the failure to virAsprintf the path would have been ignored anyway in
the secretLoad error path.
Signed-off-by: NJohn Ferlan <jferlan@redhat.com>
上级 0e458e66
...@@ -309,16 +309,16 @@ secretDeleteSaved(const virSecretObj *secret) ...@@ -309,16 +309,16 @@ secretDeleteSaved(const virSecretObj *secret)
static int static int
secretLoadValidateUUID(virSecretDefPtr def, secretLoadValidateUUID(virSecretDefPtr def,
const char *xml_basename) const char *file)
{ {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(def->uuid, uuidstr); virUUIDFormat(def->uuid, uuidstr);
if (!virFileMatchesNameSuffix(xml_basename, uuidstr, ".xml")) { if (!virFileMatchesNameSuffix(file, uuidstr, ".xml")) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("<uuid> does not match secret file name '%s'"), _("<uuid> does not match secret file name '%s'"),
xml_basename); file);
return -1; return -1;
} }
...@@ -395,22 +395,16 @@ secretLoadValue(virSecretObjPtr secret) ...@@ -395,22 +395,16 @@ secretLoadValue(virSecretObjPtr secret)
} }
static virSecretObjPtr static virSecretObjPtr
secretLoad(const char *xml_basename) secretLoad(const char *file,
const char *path)
{ {
virSecretDefPtr def = NULL; virSecretDefPtr def = NULL;
virSecretObjPtr secret = NULL, ret = NULL; virSecretObjPtr secret = NULL, ret = NULL;
char *xml_filename;
if (virAsprintf(&xml_filename, "%s/%s", driver->configDir, if (!(def = virSecretDefParseFile(path)))
xml_basename) < 0)
goto cleanup; goto cleanup;
if (!(def = virSecretDefParseFile(xml_filename))) if (secretLoadValidateUUID(def, file) < 0)
goto cleanup;
VIR_FREE(xml_filename);
if (secretLoadValidateUUID(def, xml_basename) < 0)
goto cleanup; goto cleanup;
if (VIR_ALLOC(secret) < 0) if (VIR_ALLOC(secret) < 0)
...@@ -427,7 +421,6 @@ secretLoad(const char *xml_basename) ...@@ -427,7 +421,6 @@ secretLoad(const char *xml_basename)
cleanup: cleanup:
secretFree(secret); secretFree(secret);
virSecretDefFree(def); virSecretDefFree(def);
VIR_FREE(xml_filename);
return ret; return ret;
} }
...@@ -447,6 +440,7 @@ loadSecrets(virSecretObjPtr *dest) ...@@ -447,6 +440,7 @@ loadSecrets(virSecretObjPtr *dest)
} }
while (virDirRead(dir, &de, NULL) > 0) { while (virDirRead(dir, &de, NULL) > 0) {
char *path;
virSecretObjPtr secret; virSecretObjPtr secret;
if (STREQ(de->d_name, ".") || STREQ(de->d_name, "..")) if (STREQ(de->d_name, ".") || STREQ(de->d_name, ".."))
...@@ -455,15 +449,20 @@ loadSecrets(virSecretObjPtr *dest) ...@@ -455,15 +449,20 @@ loadSecrets(virSecretObjPtr *dest)
if (!virFileHasSuffix(de->d_name, ".xml")) if (!virFileHasSuffix(de->d_name, ".xml"))
continue; continue;
if (!(secret = secretLoad(de->d_name))) { if (!(path = virFileBuildPath(driver->configDir, de->d_name, NULL)))
continue;
if (!(secret = secretLoad(de->d_name, path))) {
virErrorPtr err = virGetLastError(); virErrorPtr err = virGetLastError();
VIR_ERROR(_("Error reading secret: %s"), VIR_ERROR(_("Error reading secret: %s"),
err != NULL ? err->message: _("unknown error")); err != NULL ? err->message: _("unknown error"));
virResetError(err); virResetError(err);
VIR_FREE(path);
continue; continue;
} }
VIR_FREE(path);
listInsert(&list, secret); listInsert(&list, secret);
} }
/* Ignore error reported by readdir, if any. It's better to keep the /* Ignore error reported by readdir, if any. It's better to keep the
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册