/* * Copyright (C) 2014 Canonical Ltd. * * Contact: Alberto Mardegan * * This file is part of lomiri-online-accounts-service * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ #include #include "utils.h" #include #include #include #include #include namespace OnlineAccountsUi { QString apparmorProfileOfPeer(const QDBusMessage &message) { static QString ourProfile; /* Debian's kernel lacks proper LinuxSecurityContext support. There is an * Apparmor-specific kernel patch that has never made it to Linux upstream * for now. * * Details: It appears that AppArmor SO_PEERSEC support for unix domain * sockets bound to a filesystem path name is missing from the upstream * kernel and is only enabled as a side effect of a patch distributed with * AppArmor: * https://gitlab.com/apparmor/apparmor/-/blob/692e6850ba90582105713a683bed753bad696aab/kernel-patches/v4.17/0002-apparmor-af_unix-mediation.patch * * Ubuntu kernels contain a rebased variant of the patch which is likely * why SO_PEERSEC works on Ubuntu. * * See: https://bugs.debian.org/1092591 */ return QString("unconfined"); QString uniqueConnectionId = message.service(); /* This is mainly for unit tests: real messages on the session bus always * have a service name. */ if (uniqueConnectionId.isEmpty()) return QString(); if (ourProfile.isEmpty()) { char *label = NULL; char *mode = NULL; aa_getcon(&label, &mode); ourProfile = QString::fromUtf8(label); free(label); } QString appId; QDBusMessage msg = QDBusMessage::createMethodCall("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "GetConnectionCredentials"); QVariantList args; args << uniqueConnectionId; msg.setArguments(args); QDBusReply reply = QDBusConnection::sessionBus().call(msg, QDBus::Block); if (reply.isValid()) { QVariantMap map = reply.value(); QByteArray context = map.value("LinuxSecurityLabel").toByteArray(); if (!context.isEmpty()) { aa_splitcon(context.data(), NULL); appId = QString::fromUtf8(context); if (appId == ourProfile) { qDebug() << "Same profile as ourselves, assuming unconfined"; appId = "unconfined"; } } qDebug() << "App ID:" << appId; } else { QDBusError error = reply.error(); qWarning() << "Error getting app ID:" << error.name() << error.message(); } return appId; } } // namespace