mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 11:35:19 +00:00
virAuthGetPasswordPath: Use virAuthAskCredential for callback interaction
Replace the open-coded variant by the new helper. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
This commit is contained in:
parent
616e79c065
commit
b342c555e5
@ -215,8 +215,7 @@ virAuthGetPasswordPath(const char *path,
|
|||||||
const char *username,
|
const char *username,
|
||||||
const char *hostname)
|
const char *hostname)
|
||||||
{
|
{
|
||||||
unsigned int ncred;
|
g_autoptr(virConnectCredential) cred = NULL;
|
||||||
virConnectCredential cred;
|
|
||||||
g_autofree char *prompt = NULL;
|
g_autofree char *prompt = NULL;
|
||||||
char *ret = NULL;
|
char *ret = NULL;
|
||||||
|
|
||||||
@ -231,42 +230,12 @@ virAuthGetPasswordPath(const char *path,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&cred, 0, sizeof(virConnectCredential));
|
|
||||||
|
|
||||||
prompt = g_strdup_printf(_("Enter %s's password for %s"), username, hostname);
|
prompt = g_strdup_printf(_("Enter %s's password for %s"), username, hostname);
|
||||||
|
|
||||||
for (ncred = 0; ncred < auth->ncredtype; ncred++) {
|
if (!(cred = virAuthAskCredential(auth, prompt, false)))
|
||||||
if (auth->credtype[ncred] != VIR_CRED_PASSPHRASE &&
|
return NULL;
|
||||||
auth->credtype[ncred] != VIR_CRED_NOECHOPROMPT) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!auth->cb) {
|
return g_steal_pointer(&cred->result);
|
||||||
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
||||||
_("Missing authentication callback"));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
cred.type = auth->credtype[ncred];
|
|
||||||
cred.prompt = prompt;
|
|
||||||
cred.challenge = hostname;
|
|
||||||
cred.defresult = NULL;
|
|
||||||
cred.result = NULL;
|
|
||||||
cred.resultlen = 0;
|
|
||||||
|
|
||||||
if ((*(auth->cb))(&cred, 1, auth->cbdata) < 0) {
|
|
||||||
virReportError(VIR_ERR_AUTH_FAILED, "%s",
|
|
||||||
_("Password request failed"));
|
|
||||||
VIR_FREE(cred.result);
|
|
||||||
}
|
|
||||||
|
|
||||||
return cred.result;
|
|
||||||
}
|
|
||||||
|
|
||||||
virReportError(VIR_ERR_AUTH_FAILED, "%s",
|
|
||||||
_("Missing VIR_CRED_PASSPHRASE or VIR_CRED_NOECHOPROMPT "
|
|
||||||
"credential type"));
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user