mirror of https://gitee.com/openkylin/libvirt.git
util: authconfig: use VIR_AUTOFREE instead of VIR_FREE for scalar types
By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar <skrtbhtngr@gmail.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
0e32987ecb
commit
757c090899
|
@ -105,10 +105,9 @@ int virAuthConfigLookup(virAuthConfigPtr auth,
|
||||||
const char *credname,
|
const char *credname,
|
||||||
const char **value)
|
const char **value)
|
||||||
{
|
{
|
||||||
char *authgroup = NULL;
|
VIR_AUTOFREE(char *) authgroup = NULL;
|
||||||
char *credgroup = NULL;
|
VIR_AUTOFREE(char *) credgroup = NULL;
|
||||||
const char *authcred;
|
const char *authcred;
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
*value = NULL;
|
*value = NULL;
|
||||||
|
|
||||||
|
@ -118,47 +117,38 @@ int virAuthConfigLookup(virAuthConfigPtr auth,
|
||||||
hostname = "localhost";
|
hostname = "localhost";
|
||||||
|
|
||||||
if (virAsprintf(&authgroup, "auth-%s-%s", service, hostname) < 0)
|
if (virAsprintf(&authgroup, "auth-%s-%s", service, hostname) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (!virKeyFileHasGroup(auth->keyfile, authgroup)) {
|
if (!virKeyFileHasGroup(auth->keyfile, authgroup)) {
|
||||||
VIR_FREE(authgroup);
|
VIR_FREE(authgroup);
|
||||||
if (virAsprintf(&authgroup, "auth-%s-%s", service, "default") < 0)
|
if (virAsprintf(&authgroup, "auth-%s-%s", service, "default") < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!virKeyFileHasGroup(auth->keyfile, authgroup)) {
|
if (!virKeyFileHasGroup(auth->keyfile, authgroup))
|
||||||
ret = 0;
|
return 0;
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(authcred = virKeyFileGetValueString(auth->keyfile, authgroup, "credentials"))) {
|
if (!(authcred = virKeyFileGetValueString(auth->keyfile, authgroup, "credentials"))) {
|
||||||
virReportError(VIR_ERR_CONF_SYNTAX,
|
virReportError(VIR_ERR_CONF_SYNTAX,
|
||||||
_("Missing item 'credentials' in group '%s' in '%s'"),
|
_("Missing item 'credentials' in group '%s' in '%s'"),
|
||||||
authgroup, auth->path);
|
authgroup, auth->path);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virAsprintf(&credgroup, "credentials-%s", authcred) < 0)
|
if (virAsprintf(&credgroup, "credentials-%s", authcred) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (!virKeyFileHasGroup(auth->keyfile, credgroup)) {
|
if (!virKeyFileHasGroup(auth->keyfile, credgroup)) {
|
||||||
virReportError(VIR_ERR_CONF_SYNTAX,
|
virReportError(VIR_ERR_CONF_SYNTAX,
|
||||||
_("Missing group 'credentials-%s' referenced from group '%s' in '%s'"),
|
_("Missing group 'credentials-%s' referenced from group '%s' in '%s'"),
|
||||||
authcred, authgroup, auth->path);
|
authcred, authgroup, auth->path);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!virKeyFileHasValue(auth->keyfile, credgroup, credname)) {
|
if (!virKeyFileHasValue(auth->keyfile, credgroup, credname))
|
||||||
ret = 0;
|
return 0;
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
*value = virKeyFileGetValueString(auth->keyfile, credgroup, credname);
|
*value = virKeyFileGetValueString(auth->keyfile, credgroup, credname);
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FREE(authgroup);
|
|
||||||
VIR_FREE(credgroup);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue