Merge lp:~mardy/signon-apparmor-extension/lp1274934 into lp:signon-apparmor-extension

Proposed by Alberto Mardegan
Status: Merged
Approved by: Alberto Mardegan
Approved revision: 14
Merged at revision: 8
Proposed branch: lp:~mardy/signon-apparmor-extension/lp1274934
Merge into: lp:signon-apparmor-extension
Diff against target: 173 lines (+70/-3)
4 files modified
src/access-control-manager.cpp (+17/-1)
src/access-control-manager.h (+3/-0)
tests/mock/apparmor.cpp (+9/-2)
tests/tst_extension.cpp (+41/-0)
To merge this branch: bzr merge lp:~mardy/signon-apparmor-extension/lp1274934
Reviewer Review Type Date Requested Status
Ken VanDine Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+204267@code.launchpad.net

Commit message

Strip out the version information for click applications

This makes it so that different versions of the same application are treated the same way.

Description of the change

Strip out the version information for click applications

This makes it so that different versions of the same application are treated the same way.

To post a comment you must log in.
10. By Alberto Mardegan

Remove empty line

11. By Alberto Mardegan

Missed the call to removeLast()

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
12. By Alberto Mardegan

Don't modify the returned appId

Instead of returning a modified appId, change the comparison function to strip
out the versions.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
13. By Alberto Mardegan

include <QStringList>

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
14. By Alberto Mardegan

Fix Qt 5.0 build

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ken VanDine (ken-vandine) wrote :

Looks good

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/access-control-manager.cpp'
2--- src/access-control-manager.cpp 2013-09-05 09:26:35 +0000
3+++ src/access-control-manager.cpp 2014-02-03 13:14:30 +0000
4@@ -24,6 +24,7 @@
5 #include <QDBusConnection>
6 #include <QDBusMessage>
7 #include <QDebug>
8+#include <QStringList>
9 #include <dbus/dbus.h>
10 #include <sys/apparmor.h>
11
12@@ -58,7 +59,7 @@
13 {
14 QString appId = appIdOfPeer(peerConnection, peerMessage);
15
16- bool allowed = (appId == securityContext ||
17+ bool allowed = (stripVersion(appId) == stripVersion(securityContext) ||
18 securityContext == QLatin1String("*"));
19 qDebug() << "Process" << appId << "access to" << securityContext <<
20 (allowed ? "ALLOWED" : "DENIED");
21@@ -118,3 +119,18 @@
22 {
23 return new AccessReply(request, this);
24 }
25+
26+QString AccessControlManager::stripVersion(const QString &appId) const
27+{
28+ QStringList components = appId.split('_');
29+ if (components.count() != 3) return appId;
30+
31+ /* Click packages have a profile of the form
32+ * $name_$application_$version
33+ * (see https://wiki.ubuntu.com/SecurityTeam/Specifications/ApplicationConfinement/Manifest#Click)
34+ *
35+ * We assume that this is a click package, and strip out the last part.
36+ */
37+ components.removeLast();
38+ return components.join('_');
39+}
40
41=== modified file 'src/access-control-manager.h'
42--- src/access-control-manager.h 2013-08-27 12:26:46 +0000
43+++ src/access-control-manager.h 2014-02-03 13:14:30 +0000
44@@ -51,6 +51,9 @@
45
46 SignOn::AccessReply *handleRequest(const SignOn::AccessRequest &request)
47 Q_DECL_OVERRIDE;
48+
49+private:
50+ QString stripVersion(const QString &appId) const;
51 };
52
53 #endif // SIGNON_APPARMOR_ACCESS_CONTROL_MANAGER_H
54
55=== modified file 'tests/mock/apparmor.cpp'
56--- tests/mock/apparmor.cpp 2013-09-04 06:55:40 +0000
57+++ tests/mock/apparmor.cpp 2014-02-03 13:14:30 +0000
58@@ -19,6 +19,7 @@
59 * along with this library. If not, see <http://www.gnu.org/licenses/>.
60 */
61
62+#include <QByteArray>
63 #include <QDBusConnection>
64 #include <QDBusMessage>
65 #include <QDebug>
66@@ -26,11 +27,17 @@
67
68 #define UNCONFINED_PROFILE "unconfined"
69
70+QByteArray mockedProfile()
71+{
72+ QByteArray envVariable = qgetenv("APPARMOR_MOCK_PROFILE");
73+ return envVariable.isEmpty() ? UNCONFINED_PROFILE : envVariable;
74+}
75+
76 int aa_getpeercon(int fd, char **con, char **mode)
77 {
78 Q_UNUSED(fd);
79 Q_UNUSED(mode);
80- *con = strdup(UNCONFINED_PROFILE);
81+ *con = strdup(mockedProfile().constData());
82 return 0;
83 }
84
85@@ -40,5 +47,5 @@
86 {
87 Q_UNUSED(mode);
88 Q_UNUSED(timeout);
89- return message.createReply(QVariantList() << QStringLiteral(UNCONFINED_PROFILE));
90+ return message.createReply(QVariantList() << mockedProfile().constData());
91 }
92
93=== modified file 'tests/tst_extension.cpp'
94--- tests/tst_extension.cpp 2013-08-27 12:26:46 +0000
95+++ tests/tst_extension.cpp 2014-02-03 13:14:30 +0000
96@@ -30,6 +30,19 @@
97
98 #define P2P_SOCKET "unix:path=/tmp/tst_extension_%1"
99
100+static void setMockedProfile(const char *profile)
101+{
102+ if (profile) {
103+ qputenv("APPARMOR_MOCK_PROFILE", profile);
104+ } else {
105+#if QT_VERSION >= 0x050100
106+ qunsetenv("APPARMOR_MOCK_PROFILE");
107+#else
108+ qputenv("APPARMOR_MOCK_PROFILE", "");
109+#endif
110+ }
111+}
112+
113 class ExtensionTest: public QObject
114 {
115 Q_OBJECT
116@@ -41,6 +54,7 @@
117 void initTestCase();
118 void test_appId();
119 void test_appId_p2p();
120+ void test_click_version();
121 void test_access();
122 void test_accessWildcard();
123 void cleanupTestCase();
124@@ -89,6 +103,8 @@
125
126 void ExtensionTest::test_appId()
127 {
128+ QSKIP("Disable because of QTBUG-36475");
129+
130 /* forge a QDBusMessage */
131 QDBusMessage msg =
132 QDBusMessage::createMethodCall(m_busConnection.baseService(),
133@@ -110,8 +126,31 @@
134 QCOMPARE(appId, QStringLiteral("unconfined"));
135 }
136
137+void ExtensionTest::test_click_version()
138+{
139+ /* forge a QDBusMessage */
140+ setMockedProfile("com.ubuntu.myapp_myapp_0.2");
141+ QDBusMessage msg =
142+ QDBusMessage::createMethodCall("", "/", "my.interface", "hi");
143+ bool allowed = m_acm->isPeerAllowedToAccess(m_busConnection, msg,
144+ "anyContext");
145+ QVERIFY(!allowed);
146+
147+ allowed = m_acm->isPeerAllowedToAccess(m_busConnection, msg,
148+ "com.ubuntu.myapp_myapp_0.2");
149+ QVERIFY(allowed);
150+
151+ /* A different version of the package should also work */
152+ allowed = m_acm->isPeerAllowedToAccess(m_busConnection, msg,
153+ "com.ubuntu.myapp_myapp_0.1");
154+ QVERIFY(allowed);
155+ setMockedProfile(NULL);
156+}
157+
158 void ExtensionTest::test_access()
159 {
160+ QSKIP("Disable because of QTBUG-36475");
161+
162 /* forge a QDBusMessage */
163 QDBusMessage msg =
164 QDBusMessage::createMethodCall(m_busConnection.baseService(),
165@@ -125,6 +164,8 @@
166
167 void ExtensionTest::test_accessWildcard()
168 {
169+ QSKIP("Disable because of QTBUG-36475");
170+
171 /* forge a QDBusMessage */
172 QDBusMessage msg =
173 QDBusMessage::createMethodCall(m_busConnection.baseService(),

Subscribers

People subscribed via source and target branches