1 #include <pulsecore/cynara.h>
4 #include <pulsecore/log.h>
6 #include <cynara-creds-socket.h>
7 #include <cynara-client.h>
8 #include <cynara-session.h>
10 void cynara_log(const char *string, int cynara_status) {
11 const int buflen = 255;
14 int ret = cynara_strerror(cynara_status, buf, buflen);
15 if (ret != CYNARA_API_SUCCESS) {
16 strncpy(buf, "cynara_strerror failed", buflen);
17 buf[buflen - 1] = '\0';
19 if (cynara_status < 0)
20 pa_log_error("%s: %s", string, buf);
22 pa_log_debug("%s: %s", string, buf);
25 bool cynara_check_privilege(int fd, const char *privilege, pid_t allowed_pid) {
26 cynara *p_cynara = NULL;
27 cynara_configuration *p_conf = NULL;
37 ret = cynara_configuration_create(&p_conf);
38 cynara_log("cynara_configuration_create()", ret);
39 if (ret != CYNARA_API_SUCCESS) {
43 ret = cynara_configuration_set_cache_size(p_conf, 0);
44 cynara_log("cynara_configuration_set_cache_size()", ret);
45 if (ret != CYNARA_API_SUCCESS) {
49 ret = cynara_initialize(&p_cynara, p_conf);
50 cynara_log("cynara_initialize()", ret);
51 if (ret != CYNARA_API_SUCCESS) {
55 ret = cynara_creds_socket_get_user(fd, USER_METHOD_DEFAULT, &user);
56 cynara_log("cynara_creds_socket_get_user()", ret);
57 if (ret != CYNARA_API_SUCCESS) {
61 ret = cynara_creds_socket_get_pid(fd, &pid);
62 cynara_log("cynara_creds_socket_get_pid()", ret);
63 if (ret != CYNARA_API_SUCCESS) {
67 if (pid == allowed_pid) {
68 pa_log_info("identical to allowed pid");
73 ret = cynara_creds_socket_get_client(fd, CLIENT_METHOD_DEFAULT, &client);
74 cynara_log("cynara_creds_socket_get_client()", ret);
75 if (ret != CYNARA_API_SUCCESS) {
79 session = cynara_session_from_pid(pid);
80 if (session == NULL) {
81 pa_log_error("cynara_session_from_pid(): failed");
86 pa_log_debug("cynara credentials - client: %s, session: %s, user: %s, privilege: %s", client, session, user, privilege);
88 ret = cynara_check(p_cynara, client, session, user, privilege);
89 cynara_log("cynara_check()", ret);
90 if (ret == CYNARA_API_ACCESS_ALLOWED) {
95 cynara_configuration_destroy(p_conf);
96 cynara_finish(p_cynara);