~binli/ubuntu/vivid/pulseaudio/fix-atoi

« back to all changes in this revision

Viewing changes to .pc/0410-Add-thread-to-activate-trust-store-interface.patch/src/modules/trust-store/truststore.cc

  • Committer: Bin Li
  • Date: 2016-07-05 03:39:49 UTC
  • Revision ID: bin.li@canonical.com-20160705033949-rz4p9x4hbi2danxk
first version based on pulseaudio_6.0-0ubuntu9.27

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifdef HAVE_CONFIG_H
 
2
#include <config.h>
 
3
#endif
 
4
 
 
5
#include <memory>
 
6
#include <core/dbus/bus.h>
 
7
#include <core/trust/dbus_agent.h>
 
8
#include <core/trust/agent.h>
 
9
 
 
10
#include <pulse/cdecl.h>
 
11
 
 
12
PA_C_DECL_BEGIN
 
13
#include <pulsecore/core-util.h>
 
14
#include <pulse/xmalloc.h>
 
15
#include <pulsecore/log.h>
 
16
 
 
17
#include "truststore.h"
 
18
PA_C_DECL_END
 
19
 
 
20
class TrustStore {
 
21
public:
 
22
    std::shared_ptr<core::trust::Agent> agent;
 
23
};
 
24
 
 
25
pa_trust_store* pa_trust_store_new() {
 
26
    try {
 
27
        auto bus = std::make_shared<core::dbus::Bus>(core::dbus::WellKnownBus::session);
 
28
        auto agent = core::trust::dbus::create_multi_user_agent_for_bus_connection(bus, "PulseAudio");
 
29
        auto ts = new TrustStore();
 
30
        ts->agent = agent;
 
31
        return (pa_trust_store *) ts;
 
32
    } catch(const std::exception &e) {
 
33
        pa_log_error("Could not create Ubuntu touch trust store connection: %s",
 
34
            e.what());
 
35
    } catch(...) {
 
36
        pa_log_error("Could not create Ubuntu touch trust store connection");
 
37
        return NULL;
 
38
    }
 
39
}
 
40
 
 
41
void pa_trust_store_free(pa_trust_store *t) {
 
42
    pa_assert(t != NULL);
 
43
    auto ts = (TrustStore*) t;
 
44
    delete ts;
 
45
}
 
46
 
 
47
bool pa_trust_store_check(pa_trust_store *t, const char *appname,
 
48
                          uid_t uid, pid_t pid, const char *description) {
 
49
    auto ts = (TrustStore*) t;
 
50
    try {
 
51
 
 
52
        core::trust::Agent::RequestParameters params {
 
53
            core::trust::Uid{uid},
 
54
            core::trust::Pid{pid},
 
55
            appname,
 
56
            core::trust::Feature{0},
 
57
            description
 
58
        };
 
59
        pa_log_debug("Asking Ubuntu touch trust store for permission (app: %s)",
 
60
            params.application.id.c_str());
 
61
        auto answer = ts->agent->authenticate_request_with_parameters(params);
 
62
        if (answer == core::trust::Request::Answer::granted) {
 
63
            pa_log_debug("Request granted.");
 
64
            return true;
 
65
        }
 
66
        pa_log_info("Request denied.");
 
67
    } catch(const std::exception &e) {
 
68
        pa_log_error("Could not ask Ubuntu touch trust store for permission: %s",
 
69
            e.what());
 
70
    } catch(...) {
 
71
        pa_log_error("Could not ask Ubuntu touch trust store for permission");
 
72
    }
 
73
    return false;
 
74
}