Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
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;
}