auth-manager: add helper function nm_auth_call_result_eval()

This makes NMAuthCallResult not only usable from within a NMAuthChain.
It makes sense to just call nm-auth-manager directly, but then we need
a way to convert the more detailed result into an NMAuthCallResult
value.
This commit is contained in:
Thomas Haller
2018-04-09 17:03:58 +02:00
parent 798b2a7527
commit f0bddb44e0
3 changed files with 30 additions and 17 deletions

View File

@@ -23,6 +23,31 @@
#include "nm-auth-subject.h"
/*****************************************************************************/
typedef enum {
NM_AUTH_CALL_RESULT_UNKNOWN,
NM_AUTH_CALL_RESULT_YES,
NM_AUTH_CALL_RESULT_AUTH,
NM_AUTH_CALL_RESULT_NO,
} NMAuthCallResult;
static inline NMAuthCallResult
nm_auth_call_result_eval (gboolean is_authorized,
gboolean is_challenge,
GError *error)
{
if (error)
return NM_AUTH_CALL_RESULT_UNKNOWN;
if (is_authorized)
return NM_AUTH_CALL_RESULT_YES;
if (is_challenge)
return NM_AUTH_CALL_RESULT_AUTH;
return NM_AUTH_CALL_RESULT_NO;
}
/*****************************************************************************/
#define NM_TYPE_AUTH_MANAGER (nm_auth_manager_get_type ())
#define NM_AUTH_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_AUTH_MANAGER, NMAuthManager))
#define NM_AUTH_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_AUTH_MANAGER, NMAuthManagerClass))

View File

@@ -247,7 +247,7 @@ pk_call_cb (NMAuthManager *auth_manager,
gpointer user_data)
{
AuthCall *call;
NMAuthCallResult call_result = NM_AUTH_CALL_RESULT_UNKNOWN;
NMAuthCallResult call_result;
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
return;
@@ -262,17 +262,10 @@ pk_call_cb (NMAuthManager *auth_manager,
/* Don't ruin the chain. Just leave the result unknown. */
nm_log_warn (LOGD_CORE, "error requesting auth for %s: %s",
call->permission, error->message);
} else {
if (is_authorized) {
/* Caller has the permission */
call_result = NM_AUTH_CALL_RESULT_YES;
} else if (is_challenge) {
/* Caller could authenticate to get the permission */
call_result = NM_AUTH_CALL_RESULT_AUTH;
} else
call_result = NM_AUTH_CALL_RESULT_NO;
}
call_result = nm_auth_call_result_eval (is_authorized, is_challenge, error);
nm_auth_chain_set_data (call->chain, call->permission, GUINT_TO_POINTER (call_result), NULL);
auth_call_complete (call);

View File

@@ -23,14 +23,9 @@
#include "nm-connection.h"
typedef struct NMAuthChain NMAuthChain;
#include "nm-auth-manager.h"
typedef enum {
NM_AUTH_CALL_RESULT_UNKNOWN,
NM_AUTH_CALL_RESULT_YES,
NM_AUTH_CALL_RESULT_AUTH,
NM_AUTH_CALL_RESULT_NO,
} NMAuthCallResult;
typedef struct NMAuthChain NMAuthChain;
typedef void (*NMAuthChainResultFunc) (NMAuthChain *chain,
GError *error,