Merge lp:~ted/ubuntu-app-launch/appid-from-pid into lp:ubuntu-app-launch/16.10

Proposed by Ted Gould
Status: Work in progress
Proposed branch: lp:~ted/ubuntu-app-launch/appid-from-pid
Merge into: lp:ubuntu-app-launch/16.10
Diff against target: 92 lines (+37/-2)
4 files modified
CMakeLists.txt (+5/-2)
libubuntu-app-launch/CMakeLists.txt (+1/-0)
libubuntu-app-launch/appid.h (+9/-0)
libubuntu-app-launch/application.cpp (+22/-0)
To merge this branch: bzr merge lp:~ted/ubuntu-app-launch/appid-from-pid
Reviewer Review Type Date Requested Status
Indicator Applet Developers Pending
Review via email: mp+294809@code.launchpad.net

Commit message

Add function to get an AppID from a PID

To post a comment you must log in.

Unmerged revisions

231. By Ted Gould

Add a function to build an AppID from a PID

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2016-04-21 01:01:47 +0000
3+++ CMakeLists.txt 2016-05-16 13:48:41 +0000
4@@ -75,12 +75,15 @@
5 pkg_check_modules(CGMANAGER REQUIRED libcgmanager)
6 include_directories(${CGMANAGER_INCLUDE_DIRS})
7
8-pkg_check_modules(MIR mirclient)
9+pkg_check_modules(MIR REQUIRED mirclient)
10 include_directories(${MIR_INCLUDE_DIRS})
11
12-pkg_check_modules(LIBERTINE libertine)
13+pkg_check_modules(LIBERTINE REQUIRED libertine)
14 include_directories(${LIBERTINE_INCLUDE_DIRS})
15
16+pkg_check_modules(APPARMOR REQUIRED libapparmor)
17+include_directories(${APPARMOR_INCLUDE_DIRS})
18+
19 include_directories(${CMAKE_CURRENT_SOURCE_DIR})
20
21 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
22
23=== modified file 'libubuntu-app-launch/CMakeLists.txt'
24--- libubuntu-app-launch/CMakeLists.txt 2016-05-02 13:47:11 +0000
25+++ libubuntu-app-launch/CMakeLists.txt 2016-05-16 13:48:41 +0000
26@@ -90,6 +90,7 @@
27 ${ZEITGEIST_LIBRARIES}
28 ${MIR_LIBRARIES}
29 ${LIBERTINE_LIBRARIES}
30+ ${APPARMOR_LIBRARIES}
31 helpers
32 -Wl,--no-undefined
33 )
34
35=== modified file 'libubuntu-app-launch/appid.h'
36--- libubuntu-app-launch/appid.h 2016-04-18 18:29:32 +0000
37+++ libubuntu-app-launch/appid.h 2016-05-16 13:48:41 +0000
38@@ -154,6 +154,15 @@
39 \param version Version of the package
40 */
41 static AppID discover(const std::string& package, const std::string& appname, const std::string& version);
42+
43+ /** Looks at the AppArmor profile of a PID and determines the
44+ AppID based on the AppArmor profile. This is useful for
45+ trusted services that want to verify and untrusted connection's
46+ owner is who they think it is.
47+
48+ \param pid PID to get an AppID for
49+ */
50+ static AppID fromPid(pid_t pid);
51 };
52
53 bool operator==(const AppID& a, const AppID& b);
54
55=== modified file 'libubuntu-app-launch/application.cpp'
56--- libubuntu-app-launch/application.cpp 2016-05-02 20:06:22 +0000
57+++ libubuntu-app-launch/application.cpp 2016-05-16 13:48:41 +0000
58@@ -20,6 +20,8 @@
59 extern "C" {
60 #include "app-info.h"
61 #include "ubuntu-app-launch.h"
62+
63+#include <sys/apparmor.h>
64 }
65
66 #include "application-impl-click.h"
67@@ -219,5 +221,25 @@
68 return appid;
69 }
70
71+AppID AppID::fromPid(pid_t pid)
72+{
73+ gchar* clabel = nullptr;
74+ gchar* cmode = nullptr;
75+
76+ if (aa_gettaskcon(pid, &clabel, &cmode) != 0)
77+ return {};
78+
79+ if (clabel == nullptr)
80+ return {};
81+
82+ std::string label(clabel);
83+ free(clabel); /* No freeing of the mode per-apparmor docs */
84+
85+ if (label == "unconfined")
86+ return {}; /* Wonder if we should try harder here? */
87+
88+ return find(label);
89+}
90+
91 }; // namespace app_launch
92 }; // namespace ubuntu

Subscribers

People subscribed via source and target branches