static int virAuthGetCredential(const char *servicename, const char *hostname, const char *credname, const char *path, char **value) { int ret = -1; virAuthConfigPtr config = NULL; const char *tmp; *value = NULL; if (path == NULL) return 0; if (!(config = virAuthConfigNew(path))) goto cleanup; if (virAuthConfigLookup(config, servicename, hostname, credname, &tmp) < 0) goto cleanup; if (VIR_STRDUP(*value, tmp) < 0) goto cleanup; ret = 0; cleanup: virAuthConfigFree(config); return ret; }
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; }
static int testAuthLookup(const void *args) { int ret = -1; const struct ConfigLookupData *data = args; const char *actual = NULL; int rv; rv = virAuthConfigLookup(data->config, data->service, data->hostname, data->credname, &actual); if (rv < 0) goto cleanup; if (data->expect) { if (!actual || !STREQ(actual, data->expect)) { VIR_WARN("Expected value '%s' for '%s' '%s' '%s', but got '%s'", data->expect, data->hostname, data->service, data->credname, NULLSTR(actual)); goto cleanup; } } else { if (actual) { VIR_WARN("Did not expect a value for '%s' '%s' '%s', but got '%s'", data->hostname, data->service, data->credname, actual); goto cleanup; } } ret = 0; cleanup: return ret; }