| 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>cxx . . $ `<file>/online-accounts-common/debug.h`/ |
| 22 |
#include "utils.h"cxx . . $ `<file>/online-accounts-service/src/utils.h`/ |
| 23 |
|
| 24 |
#include <QDBusConnection> |
| 25 |
#include <QDBusError> |
| 26 |
#include <QDBusMessage> |
| 27 |
#include <QDBusReply> |
| 28 |
#include <sys/apparmor.h> |
| 29 |
|
| 30 |
namespace OnlineAccountsUicxx . . $ OnlineAccountsUi/ { |
| 31 |
|
| 32 |
QStringcxx . . $ QString# apparmorProfileOfPeercxx . . $ OnlineAccountsUi/apparmorProfileOfPeer(240daad04e90b966).(const QDBusMessagecxx . . $ QDBusMessage# &message) |
| 33 |
{ |
| 34 |
static QStringcxx . . $ QString# ourProfilecxx . . $ QString#QString(ced63f7c635d850d).; |
| 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 QStringcxx . . $ QString#QString(85c52e162fed56f9).("unconfined"); |
| 52 |
|
| 53 |
QStringcxx . . $ QString# uniqueConnectionId = message.servicecxx . . $ QDBusMessage#service(6ef7b6c27b00b43d).(); |
| 54 |
/* This is mainly for unit tests: real messages on the session bus always |
| 55 |
* have a service name. */ |
| 56 |
if (uniqueConnectionId.isEmptycxx . . $ QString#isEmpty(50ce9a9e25b4a850).()) return QStringcxx . . $ QString#QString(ced63f7c635d850d).(); |
| 57 |
|
| 58 |
if (ourProfile.isEmptycxx . . $ QString#isEmpty(50ce9a9e25b4a850).()) { |
| 59 |
char *label = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 60 |
char *mode = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 61 |
aa_getcon(&label, &mode); |
| 62 |
ourProfile =cxx . . $ QString#`operator=`(4f35bf974e7f8568). QStringcxx . . $ QString#::fromUtf8cxx . . $ QString#fromUtf8(5ac70cc0fa2a874e).(label); |
| 63 |
freecxx . . $ free(bd21765a0afc8e3c).(label); |
| 64 |
} |
| 65 |
|
| 66 |
QStringcxx . . $ QString# appIdcxx . . $ QString#QString(ced63f7c635d850d).; |
| 67 |
|
| 68 |
QDBusMessagecxx . . $ QDBusMessage# msg = |
| 69 |
QDBusMessagecxx . . $ QDBusMessage#::createMethodCallcxx . . $ QDBusMessage#createMethodCall(53922711d019cf27).("org.freedesktop.DBus"cxx . . $ QString#QString(85c52e162fed56f9)., |
| 70 |
"/org/freedesktop/DBus"cxx . . $ QString#QString(85c52e162fed56f9)., |
| 71 |
"org.freedesktop.DBus"cxx . . $ QString#QString(85c52e162fed56f9)., |
| 72 |
"GetConnectionCredentials"cxx . . $ QString#QString(85c52e162fed56f9).); |
| 73 |
QVariantListcxx . . $ QVariantList# argscxx . . $ QList#QList(ced63f7c635d850d).; |
| 74 |
args <<cxx . . $ QList#`operator<<`(309d1580d8f5dc58). uniqueConnectionIdcxx . . $ QVariant#QVariant(3520e46b33348bf6).; |
| 75 |
msg.setArgumentscxx . . $ QDBusMessage#setArguments(2f4009bfc0c7e161).(args); |
| 76 |
QDBusReplycxx . . $ QDBusReply#<QVariantMapcxx . . $ QVariantMap#> reply = |
| 77 |
QDBusConnectioncxx . . $ QDBusReply#QDBusReply(65337ba3304bf734).::sessionBuscxx . . $ QDBusConnection#sessionBus(45d475f1888103b2).().callcxx . . $ QDBusConnection#call(55e43a351c9b9118).(msg, QDBuscxx . . $ QDBus/::Blockcxx . . $ QDBus/Block.); |
| 78 |
if (reply.isValidcxx . . $ QDBusReply#isValid(50ce9a9e25b4a850).()) { |
| 79 |
QVariantMapcxx . . $ QVariantMap# map = reply.valuecxx . . $ QDBusReply#value(8f5363d873dd4781).(); |
| 80 |
QByteArraycxx . . $ QByteArray# context = map.valuecxx . . $ QMap#value(866b0a4e5fb46e14).("LinuxSecurityLabel"cxx . . $ QString#QString(85c52e162fed56f9).).toByteArraycxx . . $ QVariant#toByteArray(a96750bfbcb1fbe9).(); |
| 81 |
if (!context.isEmptycxx . . $ QByteArray#isEmpty(50ce9a9e25b4a850).()) { |
| 82 |
aa_splitcon(context.datacxx . . $ QByteArray#data(41208ce6ca65dd58).(), NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!); |
| 83 |
appId =cxx . . $ QString#`operator=`(4f35bf974e7f8568). QStringcxx . . $ QString#::fromUtf8cxx . . $ QString#fromUtf8(4e15edac36d215be).(context); |
| 84 |
if (appId ==cxx . . $ `operator==`(5bc2975d2d751687). ourProfile) { |
| 85 |
qDebugcxx . . $ `<external>/10450329605257866924/qlogging.h:164:9`!() <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Same profile as ourselves, assuming unconfined"; |
| 86 |
appId =cxx . . $ QString#`operator=`(d02845eef0c33901). "unconfined"; |
| 87 |
} |
| 88 |
} |
| 89 |
qDebugcxx . . $ `<external>/10450329605257866924/qlogging.h:164:9`!() <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "App ID:" <<cxx . . $ QDebug#`operator<<`(4cf17434affdd8). appId; |
| 90 |
} else { |
| 91 |
QDBusErrorcxx . . $ QDBusError# error = replycxx . . $ QDBusError#QDBusError(8b965b05cb8f2b40)..errorcxx . . $ QDBusReply#error(1a61ff5b6ea1d08d).(); |
| 92 |
qWarningcxx . . $ `<external>/10450329605257866924/qlogging.h:166:9`!() <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Error getting app ID:" <<cxx . . $ QDebug#`operator<<`(4cf17434affdd8). error.namecxx . . $ QDBusError#name(6ef7b6c27b00b43d).() <<cxx . . $ QDebug#`operator<<`(4cf17434affdd8). |
| 93 |
error.messagecxx . . $ QDBusError#message(6ef7b6c27b00b43d).(); |
| 94 |
} |
| 95 |
return appIdcxx . . $ QString#QString(28715ad661ad3cec).; |
| 96 |
} |
| 97 |
|
| 98 |
} // namespace |