44 #include <sys/types.h> 45 #include <sys/socket.h> 46 #include <sys/ioctl.h> 54 #if defined(HAVE_POLKIT) && defined(SO_PEERCRED) 56 #include <polkit/polkit.h> 59 unsigned 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, NULL);
84 if (authority == NULL)
86 Log1(PCSC_LOG_CRITICAL,
"polkit_authority_get_sync failed");
90 subject = polkit_unix_process_new_for_owner(cr.pid, 0, cr.uid);
93 Log1(PCSC_LOG_CRITICAL,
"polkit_unix_process_new_for_owner failed");
98 details = polkit_details_new();
101 Log1(PCSC_LOG_CRITICAL,
"polkit_details_new failed");
107 polkit_details_insert(details,
"reader", reader);
109 result = polkit_authority_check_authorization_sync(authority, subject,
110 action_name, details,
111 POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION,
117 Log2(PCSC_LOG_CRITICAL,
"Error in authorization: %s", error->message);
123 if (polkit_authorization_result_get_is_authorized(result))
135 Log4(PCSC_LOG_CRITICAL,
136 "Process %u (user: %u) is NOT authorized for action: %s",
137 (
unsigned)cr.pid, (
unsigned)cr.uid, action);
140 g_object_unref(subject);
142 g_object_unref(details);
144 g_object_unref(authority);
151 unsigned IsClientAuthorized(
int socket,
const char* action,
const char* reader)