static int virAuthGetCredential(virConnectPtr conn, const char *servicename, const char *credname, char **value) { int ret = -1; char *path = NULL; virAuthConfigPtr config = NULL; const char *tmp; *value = NULL; if (virAuthGetConfigFilePath(conn, &path) < 0) goto cleanup; if (path == NULL) { ret = 0; goto cleanup; } if (!(config = virAuthConfigNew(path))) goto cleanup; if (virAuthConfigLookup(config, servicename, conn->uri->server, credname, &tmp) < 0) goto cleanup; if (tmp && !(*value = strdup(tmp))) { virReportOOMError(); goto cleanup; } ret = 0; cleanup: virAuthConfigFree(config); VIR_FREE(path); return ret; }
char * virAuthGetPassword(virConnectPtr conn, virConnectAuthPtr auth, const char *servicename, const char *username, const char *hostname) { char *ret; char *path; if (virAuthGetConfigFilePath(conn, &path) < 0) return NULL; ret = virAuthGetPasswordPath(path, auth, servicename, username, hostname); VIR_FREE(path); return ret; }