Debian Codegraph @

online-accounts-service/src/utils.cpp

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * Contact: Alberto Mardegan <[email protected]>
5 *
6 * This file is part of lomiri-online-accounts-service
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include <online-accounts-common/debug.h>
22 #include "utils.h"
23
24 #include <QDBusConnection>
25 #include <QDBusError>
26 #include <QDBusMessage>
27 #include <QDBusReply>
28 #include <sys/apparmor.h>
29
30 namespace OnlineAccountsUi {
31
32 QString apparmorProfileOfPeer(const QDBusMessage &message)
33 {
34 static QString ourProfile;
35
•36 /* Debian's kernel lacks proper LinuxSecurityContext support. There is an
37 * Apparmor-specific kernel patch that has never made it to Linux upstream
38 * for now.
39 *
40 * Details: It appears that AppArmor SO_PEERSEC support for unix domain
41 * sockets bound to a filesystem path name is missing from the upstream
42 * kernel and is only enabled as a side effect of a patch distributed with
43 * AppArmor:
44 * https://gitlab.com/apparmor/apparmor/-/blob/692e6850ba90582105713a683bed753bad696aab/kernel-patches/v4.17/0002-apparmor-af_unix-mediation.patch
45 *
46 * Ubuntu kernels contain a rebased variant of the patch which is likely
47 * why SO_PEERSEC works on Ubuntu.
48 *
49 * See: https://bugs.debian.org/1092591
50 */
51 return QString("unconfined");
52
53 QString uniqueConnectionId = message.service();
54 /* This is mainly for unit tests: real messages on the session bus always
55 * have a service name. */
56 if (uniqueConnectionId.isEmpty()) return QString();
57
58 if (ourProfile.isEmpty()) {
59 char *label = NULL;
60 char *mode = NULL;
61 aa_getcon(&label, &mode);
62 ourProfile = QString::fromUtf8(label);
63 free(label);
64 }
65
66 QString appId;
67
68 QDBusMessage msg =
69 QDBusMessage::createMethodCall("org.freedesktop.DBus",
70 "/org/freedesktop/DBus",
71 "org.freedesktop.DBus",
72 "GetConnectionCredentials");
73 QVariantList args;
74 args << uniqueConnectionId;
75 msg.setArguments(args);
76 QDBusReply<QVariantMap> reply =
77 QDBusConnection::sessionBus().call(msg, QDBus::Block);
78 if (reply.isValid()) {
79 QVariantMap map = reply.value();
80 QByteArray context = map.value("LinuxSecurityLabel").toByteArray();
81 if (!context.isEmpty()) {
82 aa_splitcon(context.data(), NULL);
83 appId = QString::fromUtf8(context);
84 if (appId == ourProfile) {
85 qDebug() << "Same profile as ourselves, assuming unconfined";
86 appId = "unconfined";
87 }
88 }
89 qDebug() << "App ID:" << appId;
90 } else {
91 QDBusError error = reply.error();
92 qWarning() << "Error getting app ID:" << error.name() <<
93 error.message();
94 }
95 return appId;
96 }
97
98 } // namespace