--- src/esx/esx_driver.c | 8 ++-- src/esx/esx_util.c | 83 ---------------------------------------------- src/esx/esx_util.h | 7 ---- src/util/util.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/util/util.h | 5 +++ 5 files changed, 98 insertions(+), 94 deletions(-) diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index c47af1c..3f8b900 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -354,7 +354,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED) goto failure; } } else { - username = esxUtil_RequestUsername(auth, "root", conn->uri->server); + username = virRequestUsername(auth, "root", conn->uri->server); if (username == NULL) { ESX_ERROR(VIR_ERR_AUTH_FAILED, "Username request failed"); @@ -366,7 +366,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED) goto failure; } - password = esxUtil_RequestPassword(auth, username, conn->uri->server); + password = virRequestPassword(auth, username, conn->uri->server); if (password == NULL) { ESX_ERROR(VIR_ERR_AUTH_FAILED, "Password request failed"); @@ -491,14 +491,14 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED) goto failure; } - username = esxUtil_RequestUsername(auth, "administrator", vCenter); + username = virRequestUsername(auth, "administrator", vCenter); if (username == NULL) { ESX_ERROR(VIR_ERR_AUTH_FAILED, "Username request failed"); goto failure; } - password = esxUtil_RequestPassword(auth, username, vCenter); + password = virRequestPassword(auth, username, vCenter); if (password == NULL) { ESX_ERROR(VIR_ERR_AUTH_FAILED, "Password request failed"); diff --git a/src/esx/esx_util.c b/src/esx/esx_util.c index dcbd86c..3cbd2b1 100644 --- a/src/esx/esx_util.c +++ b/src/esx/esx_util.c @@ -49,89 +49,6 @@ -char * -esxUtil_RequestUsername(virConnectAuthPtr auth, const char *defaultUsername, - const char *hostname) -{ - unsigned int ncred; - virConnectCredential cred; - char *prompt = NULL; - - memset(&cred, 0, sizeof(virConnectCredential)); - - if (virAsprintf(&prompt, "Enter username for %s [%s]", hostname, - defaultUsername) < 0) { - return NULL; - } - - for (ncred = 0; ncred < auth->ncredtype; ncred++) { - if (auth->credtype[ncred] != VIR_CRED_AUTHNAME) { - continue; - } - - cred.type = VIR_CRED_AUTHNAME; - cred.prompt = prompt; - cred.challenge = hostname; - cred.defresult = defaultUsername; - cred.result = NULL; - cred.resultlen = 0; - - if ((*(auth->cb))(&cred, 1, auth->cbdata) < 0) { - VIR_FREE(cred.result); - } - - break; - } - - VIR_FREE(prompt); - - return cred.result; -} - - - -char * -esxUtil_RequestPassword(virConnectAuthPtr auth, const char *username, - const char *hostname) -{ - unsigned int ncred; - virConnectCredential cred; - char *prompt; - - memset(&cred, 0, sizeof(virConnectCredential)); - - if (virAsprintf(&prompt, "Enter %s password for %s", username, - hostname) < 0) { - return NULL; - } - - for (ncred = 0; ncred < auth->ncredtype; ncred++) { - if (auth->credtype[ncred] != VIR_CRED_PASSPHRASE && - auth->credtype[ncred] != VIR_CRED_NOECHOPROMPT) { - continue; - } - - 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) { - VIR_FREE(cred.result); - } - - break; - } - - VIR_FREE(prompt); - - return cred.result; -} - - - int esxUtil_ParseQuery(xmlURIPtr uri, char **transport, char **vCenter, int *noVerify, int *autoAnswer) diff --git a/src/esx/esx_util.h b/src/esx/esx_util.h index b5cb419..f4f971c 100644 --- a/src/esx/esx_util.h +++ b/src/esx/esx_util.h @@ -28,13 +28,6 @@ # include "internal.h" # include "conf.h" -char *esxUtil_RequestUsername(virConnectAuthPtr auth, - const char *defaultUsername, - const char *hostname); - -char *esxUtil_RequestPassword(virConnectAuthPtr auth, const char *username, - const char *hostname); - int esxUtil_ParseQuery(xmlURIPtr uri, char **transport, char **vCenter, int *noVerify, int *autoAnswer); diff --git a/src/util/util.c b/src/util/util.c index 87b0714..4292f01 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -2676,3 +2676,92 @@ int virBuildPathInternal(char **path, ...) return ret; } + + + +char * +virRequestUsername(virConnectAuthPtr auth, const char *defaultUsername, + const char *hostname) +{ + unsigned int ncred; + virConnectCredential cred; + char *prompt; + + memset(&cred, 0, sizeof (virConnectCredential)); + + if (defaultUsername != NULL) { + if (virAsprintf(&prompt, _("Enter username for %s [%s]"), hostname, + defaultUsername) < 0) { + return NULL; + } + } else { + if (virAsprintf(&prompt, _("Enter username for %s"), hostname) < 0) { + return NULL; + } + } + + for (ncred = 0; ncred < auth->ncredtype; ncred++) { + if (auth->credtype[ncred] != VIR_CRED_AUTHNAME) { + continue; + } + + cred.type = VIR_CRED_AUTHNAME; + cred.prompt = prompt; + cred.challenge = hostname; + cred.defresult = defaultUsername; + cred.result = NULL; + cred.resultlen = 0; + + if ((*(auth->cb))(&cred, 1, auth->cbdata) < 0) { + VIR_FREE(cred.result); + } + + break; + } + + VIR_FREE(prompt); + + return cred.result; +} + + + +char * +virRequestPassword(virConnectAuthPtr auth, const char *username, + const char *hostname) +{ + unsigned int ncred; + virConnectCredential cred; + char *prompt; + + memset(&cred, 0, sizeof (virConnectCredential)); + + if (virAsprintf(&prompt, _("Enter %s password for %s"), username, + hostname) < 0) { + return NULL; + } + + for (ncred = 0; ncred < auth->ncredtype; ncred++) { + if (auth->credtype[ncred] != VIR_CRED_PASSPHRASE && + auth->credtype[ncred] != VIR_CRED_NOECHOPROMPT) { + continue; + } + + 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) { + VIR_FREE(cred.result); + } + + break; + } + + VIR_FREE(prompt); + + return cred.result; +} diff --git a/src/util/util.h b/src/util/util.h index e8fc565..9796e0a 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -268,4 +268,9 @@ void virFileWaitForDevices(void); # define virBuildPath(path, ...) virBuildPathInternal(path, __VA_ARGS__, NULL) int virBuildPathInternal(char **path, ...) ATTRIBUTE_SENTINEL; +char *virRequestUsername(virConnectAuthPtr auth, const char *defaultUsername, + const char *hostname); +char *virRequestPassword(virConnectAuthPtr auth, const char *username, + const char *hostname); + #endif /* __VIR_UTIL_H__ */ -- 1.6.3.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list