mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
util: authconfig: use g_key_file_*
Replace libvirt's virKeyFile by glib's GKeyFile. Signed-off-by: Rafael Fonseca <r4f4rfs@gmail.com> Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
4cc90c2e62
commit
5084091a5a
@ -22,14 +22,13 @@
|
|||||||
|
|
||||||
#include "virauthconfig.h"
|
#include "virauthconfig.h"
|
||||||
|
|
||||||
#include "virkeyfile.h"
|
|
||||||
#include "virlog.h"
|
#include "virlog.h"
|
||||||
#include "virerror.h"
|
#include "virerror.h"
|
||||||
#include "virstring.h"
|
#include "virstring.h"
|
||||||
#include "viralloc.h"
|
#include "viralloc.h"
|
||||||
|
|
||||||
struct _virAuthConfig {
|
struct _virAuthConfig {
|
||||||
virKeyFilePtr keyfile;
|
GKeyFile *keyfile;
|
||||||
char *path;
|
char *path;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -46,10 +45,10 @@ virAuthConfigPtr virAuthConfigNew(const char *path)
|
|||||||
|
|
||||||
auth->path = g_strdup(path);
|
auth->path = g_strdup(path);
|
||||||
|
|
||||||
if (!(auth->keyfile = virKeyFileNew()))
|
if (!(auth->keyfile = g_key_file_new()))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (virKeyFileLoadFile(auth->keyfile, path) < 0)
|
if (!g_key_file_load_from_file(auth->keyfile, path, 0, NULL))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
return auth;
|
return auth;
|
||||||
@ -71,10 +70,10 @@ virAuthConfigPtr virAuthConfigNewData(const char *path,
|
|||||||
|
|
||||||
auth->path = g_strdup(path);
|
auth->path = g_strdup(path);
|
||||||
|
|
||||||
if (!(auth->keyfile = virKeyFileNew()))
|
if (!(auth->keyfile = g_key_file_new()))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (virKeyFileLoadData(auth->keyfile, path, data, len) < 0)
|
if (!g_key_file_load_from_data(auth->keyfile, data, len, 0, NULL))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
return auth;
|
return auth;
|
||||||
@ -90,7 +89,7 @@ void virAuthConfigFree(virAuthConfigPtr auth)
|
|||||||
if (!auth)
|
if (!auth)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
virKeyFileFree(auth->keyfile);
|
g_key_file_free(auth->keyfile);
|
||||||
VIR_FREE(auth->path);
|
VIR_FREE(auth->path);
|
||||||
VIR_FREE(auth);
|
VIR_FREE(auth);
|
||||||
}
|
}
|
||||||
@ -115,15 +114,15 @@ int virAuthConfigLookup(virAuthConfigPtr auth,
|
|||||||
|
|
||||||
authgroup = g_strdup_printf("auth-%s-%s", service, hostname);
|
authgroup = g_strdup_printf("auth-%s-%s", service, hostname);
|
||||||
|
|
||||||
if (!virKeyFileHasGroup(auth->keyfile, authgroup)) {
|
if (!g_key_file_has_group(auth->keyfile, authgroup)) {
|
||||||
VIR_FREE(authgroup);
|
VIR_FREE(authgroup);
|
||||||
authgroup = g_strdup_printf("auth-%s-%s", service, "default");
|
authgroup = g_strdup_printf("auth-%s-%s", service, "default");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!virKeyFileHasGroup(auth->keyfile, authgroup))
|
if (!g_key_file_has_group(auth->keyfile, authgroup))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!(authcred = virKeyFileGetValueString(auth->keyfile, authgroup, "credentials"))) {
|
if (!(authcred = g_key_file_get_string(auth->keyfile, authgroup, "credentials", NULL))) {
|
||||||
virReportError(VIR_ERR_CONF_SYNTAX,
|
virReportError(VIR_ERR_CONF_SYNTAX,
|
||||||
_("Missing item 'credentials' in group '%s' in '%s'"),
|
_("Missing item 'credentials' in group '%s' in '%s'"),
|
||||||
authgroup, auth->path);
|
authgroup, auth->path);
|
||||||
@ -132,17 +131,14 @@ int virAuthConfigLookup(virAuthConfigPtr auth,
|
|||||||
|
|
||||||
credgroup = g_strdup_printf("credentials-%s", authcred);
|
credgroup = g_strdup_printf("credentials-%s", authcred);
|
||||||
|
|
||||||
if (!virKeyFileHasGroup(auth->keyfile, credgroup)) {
|
if (!g_key_file_has_group(auth->keyfile, credgroup)) {
|
||||||
virReportError(VIR_ERR_CONF_SYNTAX,
|
virReportError(VIR_ERR_CONF_SYNTAX,
|
||||||
_("Missing group 'credentials-%s' referenced from group '%s' in '%s'"),
|
_("Missing group 'credentials-%s' referenced from group '%s' in '%s'"),
|
||||||
authcred, authgroup, auth->path);
|
authcred, authgroup, auth->path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!virKeyFileHasValue(auth->keyfile, credgroup, credname))
|
*value = g_key_file_get_string(auth->keyfile, credgroup, credname, NULL);
|
||||||
return 0;
|
|
||||||
|
|
||||||
*value = virKeyFileGetValueString(auth->keyfile, credgroup, credname);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user