File: modulehandler.cpp

package info (click to toggle)
openvpn3-client 25%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,276 kB
  • sloc: cpp: 190,085; python: 7,218; ansic: 1,866; sh: 1,361; java: 402; lisp: 81; makefile: 17
file content (56 lines) | stat: -rw-r--r-- 1,645 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//  OpenVPN 3 Linux client -- Next generation OpenVPN client
//
//  SPDX-License-Identifier: AGPL-3.0-only
//
//  Copyright (C) 2017-  OpenVPN Inc <sales@openvpn.net>
//  Copyright (C) 2024-  Răzvan Cojocaru <razvan.cojocaru@openvpn.com>
//

#include <dbus/constants.hpp>

#include "constants.hpp"
#include "modulehandler.hpp"


namespace DevPosture {

ModuleHandler::ModuleHandler(Module::UPtr mod, const bool external)
    : DBus::Object::Base(PATH_DEVPOSTURE + "/modules/" + mod->name(),
                         Constants::GenInterface("devicecheck")),
      module_(std::move(mod)),
      prop_name_(module_->name()),
      prop_type_(module_->type()),
      prop_version_(module_->version()),
      prop_external_(external)

{
    auto r_args = AddMethod(
        "Run",
        [this](DBus::Object::Method::Arguments::Ptr args)
        {
            GVariantBuilder *b = glib2::Builder::Create("a{sv}");

            for (const auto &[key, value] : module_->Run({}))
            {
                g_variant_builder_add(b, "{sv}", key.c_str(), glib2::Value::Create(value));
            }

            args->SetMethodReturn(glib2::Builder::FinishWrapped(b));
        });

    r_args->AddInput("input", "a{sv}");
    r_args->AddOutput("result", "a{sv}");

    AddProperty("type", prop_type_, /* readwrite */ false);
    AddProperty("name", prop_name_, /* readwrite */ false);
    AddProperty("version", prop_version_, /* readwrite */ false);
    AddProperty("external", prop_external_, /* readwrite */ false);
}


const bool ModuleHandler::Authorize(const DBus::Authz::Request::Ptr authzreq)
{
    return true;
}

} // namespace DevPosture