44 #include <sys/types.h>
45 #include <sys/socket.h>
46 #include <sys/ioctl.h>
53 #if defined(HAVE_POLKIT) && defined(SO_PEERCRED)
55 #include <polkit/polkit.h>
58 unsigned IsClientAuthorized(
int socket,
const char* action,
const char* reader)
63 PolkitSubject *subject;
64 PolkitAuthority *authority;
65 PolkitAuthorizationResult *result;
66 PolkitDetails *details;
68 char action_name[128];
70 snprintf(action_name,
sizeof(action_name),
"org.debian.pcsc-lite.%s", action);
73 ret = getsockopt(socket, SOL_SOCKET, SO_PEERCRED, &cr, &cr_len);
77 Log2(PCSC_LOG_CRITICAL,
78 "Error obtaining client process credentials: %s", strerror(e));
82 authority = polkit_authority_get_sync(NULL, NULL);
83 if (authority == NULL)
85 Log1(PCSC_LOG_CRITICAL,
"polkit_authority_get_sync failed");
89 subject = polkit_unix_process_new_for_owner(cr.pid, 0, cr.uid);
92 Log1(PCSC_LOG_CRITICAL,
"polkit_unix_process_new_for_owner failed");
97 details = polkit_details_new();
100 Log1(PCSC_LOG_CRITICAL,
"polkit_details_new failed");
106 polkit_details_insert(details,
"reader", reader);
108 result = polkit_authority_check_authorization_sync(authority, subject,
109 action_name, details,
110 POLKIT_CHECK_AUTHORIZATION_FLAGS_NONE,
116 Log2(PCSC_LOG_CRITICAL,
"Error in authorization: %s", error->message);
122 if (polkit_authorization_result_get_is_authorized(result))
134 Log4(PCSC_LOG_CRITICAL,
135 "Process %u (user: %u) is NOT authorized for action: %s",
136 (
unsigned)cr.pid, (
unsigned)cr.uid, action);
139 g_object_unref(subject);
141 g_object_unref(details);
143 g_object_unref(authority);
150 int IsClientAuthorized(
int socket,
const char* action,
const char* reader)