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

@@ -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);