45#include <sys/socket.h>
54#if defined(HAVE_POLKIT) && defined(SO_PEERCRED)
56#include <polkit/polkit.h>
59unsigned IsClientAuthorized(
int socket,
const char* action,
const char* reader)
64 PolkitSubject *subject;
65 PolkitAuthority *authority;
66 PolkitAuthorizationResult *result;
67 PolkitDetails *details;
69 char action_name[128];
71 snprintf(action_name,
sizeof(action_name),
"org.debian.pcsc-lite.%s", action);
74 ret = getsockopt(socket, SOL_SOCKET, SO_PEERCRED, &cr, &cr_len);
78 Log2(PCSC_LOG_CRITICAL,
79 "Error obtaining client process credentials: %s", strerror(e));
83 authority = polkit_authority_get_sync(NULL, &error);
84 if (authority == NULL)
86 Log2(PCSC_LOG_CRITICAL,
"polkit_authority_get_sync failed: %s",
92 subject = polkit_unix_process_new_for_owner(cr.pid, 0, cr.uid);
95 Log1(PCSC_LOG_CRITICAL,
"polkit_unix_process_new_for_owner failed");
100 details = polkit_details_new();
103 Log1(PCSC_LOG_CRITICAL,
"polkit_details_new failed");
109 polkit_details_insert(details,
"reader", reader);
111 result = polkit_authority_check_authorization_sync(authority, subject,
112 action_name, details,
113 POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION,
119 Log2(PCSC_LOG_CRITICAL,
"Error in authorization: %s", error->message);
125 if (polkit_authorization_result_get_is_authorized(result))
137 Log4(PCSC_LOG_CRITICAL,
138 "Process %u (user: %u) is NOT authorized for action: %s",
139 (
unsigned)cr.pid, (
unsigned)cr.uid, action);
143 g_object_unref(result);
145 g_object_unref(subject);
147 g_object_unref(details);
149 g_object_unref(authority);
156unsigned IsClientAuthorized(
int socket,
const char* action,
const char* reader)