mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
util: auth: 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
757c090899
commit
12614e7e25
@ -41,10 +41,9 @@ int
|
||||
virAuthGetConfigFilePathURI(virURIPtr uri,
|
||||
char **path)
|
||||
{
|
||||
int ret = -1;
|
||||
size_t i;
|
||||
const char *authenv = virGetEnvBlockSUID("LIBVIRT_AUTH_FILE");
|
||||
char *userdir = NULL;
|
||||
VIR_AUTOFREE(char *) userdir = NULL;
|
||||
|
||||
*path = NULL;
|
||||
|
||||
@ -53,7 +52,7 @@ virAuthGetConfigFilePathURI(virURIPtr uri,
|
||||
if (authenv) {
|
||||
VIR_DEBUG("Using path from env '%s'", authenv);
|
||||
if (VIR_STRDUP(*path, authenv) < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -63,17 +62,17 @@ virAuthGetConfigFilePathURI(virURIPtr uri,
|
||||
uri->params[i].value) {
|
||||
VIR_DEBUG("Using path from URI '%s'", uri->params[i].value);
|
||||
if (VIR_STRDUP(*path, uri->params[i].value) < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!(userdir = virGetUserConfigDirectory()))
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
if (virAsprintf(path, "%s/auth.conf", userdir) < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
VIR_DEBUG("Checking for readability of '%s'", *path);
|
||||
if (access(*path, R_OK) == 0)
|
||||
@ -82,7 +81,7 @@ virAuthGetConfigFilePathURI(virURIPtr uri,
|
||||
VIR_FREE(*path);
|
||||
|
||||
if (VIR_STRDUP(*path, SYSCONFDIR "/libvirt/auth.conf") < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
VIR_DEBUG("Checking for readability of '%s'", *path);
|
||||
if (access(*path, R_OK) == 0)
|
||||
@ -91,13 +90,9 @@ virAuthGetConfigFilePathURI(virURIPtr uri,
|
||||
VIR_FREE(*path);
|
||||
|
||||
done:
|
||||
ret = 0;
|
||||
|
||||
VIR_DEBUG("Using auth file '%s'", NULLSTR(*path));
|
||||
cleanup:
|
||||
VIR_FREE(userdir);
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -155,7 +150,7 @@ virAuthGetUsernamePath(const char *path,
|
||||
{
|
||||
unsigned int ncred;
|
||||
virConnectCredential cred;
|
||||
char *prompt;
|
||||
VIR_AUTOFREE(char *) prompt = NULL;
|
||||
char *ret = NULL;
|
||||
|
||||
if (virAuthGetCredential(servicename, hostname, "username", path, &ret) < 0)
|
||||
@ -192,8 +187,6 @@ virAuthGetUsernamePath(const char *path,
|
||||
break;
|
||||
}
|
||||
|
||||
VIR_FREE(prompt);
|
||||
|
||||
return cred.result;
|
||||
}
|
||||
|
||||
@ -205,18 +198,13 @@ virAuthGetUsername(virConnectPtr conn,
|
||||
const char *defaultUsername,
|
||||
const char *hostname)
|
||||
{
|
||||
char *ret;
|
||||
char *path;
|
||||
VIR_AUTOFREE(char *) path = NULL;
|
||||
|
||||
if (virAuthGetConfigFilePath(conn, &path) < 0)
|
||||
return NULL;
|
||||
|
||||
ret = virAuthGetUsernamePath(path, auth, servicename,
|
||||
return virAuthGetUsernamePath(path, auth, servicename,
|
||||
defaultUsername, hostname);
|
||||
|
||||
VIR_FREE(path);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@ -229,7 +217,7 @@ virAuthGetPasswordPath(const char *path,
|
||||
{
|
||||
unsigned int ncred;
|
||||
virConnectCredential cred;
|
||||
char *prompt;
|
||||
VIR_AUTOFREE(char *) prompt = NULL;
|
||||
char *ret = NULL;
|
||||
|
||||
if (virAuthGetCredential(servicename, hostname, "password", path, &ret) < 0)
|
||||
@ -263,8 +251,6 @@ virAuthGetPasswordPath(const char *path,
|
||||
break;
|
||||
}
|
||||
|
||||
VIR_FREE(prompt);
|
||||
|
||||
return cred.result;
|
||||
}
|
||||
|
||||
@ -276,15 +262,10 @@ virAuthGetPassword(virConnectPtr conn,
|
||||
const char *username,
|
||||
const char *hostname)
|
||||
{
|
||||
char *ret;
|
||||
char *path;
|
||||
VIR_AUTOFREE(char *) path = NULL;
|
||||
|
||||
if (virAuthGetConfigFilePath(conn, &path) < 0)
|
||||
return NULL;
|
||||
|
||||
ret = virAuthGetPasswordPath(path, auth, servicename, username, hostname);
|
||||
|
||||
VIR_FREE(path);
|
||||
|
||||
return ret;
|
||||
return virAuthGetPasswordPath(path, auth, servicename, username, hostname);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user