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;
if (authenv) {
VIR_DEBUG("Using path from env '%s'", authenv);
if (VIR_STRDUP(*path, authenv) < 0)
- goto cleanup;
+ return -1;
return 0;
}
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)
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)
VIR_FREE(*path);
done:
- ret = 0;
-
VIR_DEBUG("Using auth file '%s'", NULLSTR(*path));
- cleanup:
- VIR_FREE(userdir);
- return ret;
+ return 0;
}
{
unsigned int ncred;
virConnectCredential cred;
- char *prompt;
+ VIR_AUTOFREE(char *) prompt = NULL;
char *ret = NULL;
if (virAuthGetCredential(servicename, hostname, "username", path, &ret) < 0)
break;
}
- VIR_FREE(prompt);
-
return cred.result;
}
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;
}
{
unsigned int ncred;
virConnectCredential cred;
- char *prompt;
+ VIR_AUTOFREE(char *) prompt = NULL;
char *ret = NULL;
if (virAuthGetCredential(servicename, hostname, "password", path, &ret) < 0)
break;
}
- VIR_FREE(prompt);
-
return cred.result;
}
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);
}