Merge lp:~chipaca/snap-confine/mktmpdir into lp:~snappy-dev/snap-confine/trunk

Proposed by John Lenton
Status: Merged
Merged at revision: 64
Proposed branch: lp:~chipaca/snap-confine/mktmpdir
Merge into: lp:~snappy-dev/snap-confine/trunk
Prerequisite: lp:~chipaca/snap-confine/unshare
Diff against target: 51 lines (+31/-3)
1 file modified
src/main.c (+31/-3)
To merge this branch: bzr merge lp:~chipaca/snap-confine/mktmpdir
Reviewer Review Type Date Requested Status
Michael Vogt (community) Approve
Review via email: mp+259908@code.launchpad.net

Commit message

Make a best-effort attempt at creating the old TMPDIR.

To post a comment you must log in.
Revision history for this message
Michael Vogt (mvo) wrote :

This looks good, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/main.c'
2--- src/main.c 2015-05-22 09:39:09 +0000
3+++ src/main.c 2015-05-22 09:39:09 +0000
4@@ -232,6 +232,32 @@
5 }
6 }
7
8+// best-effort attempt at creating the old /tmp/snaps/* TMPDIR.
9+void mkoldtmpdir() {
10+ char *dir = getenv("TMPDIR");
11+ if (!dir || !*dir) {
12+ // TMPDIR not set, or empty
13+ return;
14+ }
15+
16+ if (strncmp(dir, "/tmp/snaps/", strlen("/tmp/snaps/")) != 0) {
17+ // TMPDIR is not /tmp/snaps/*
18+ return;
19+ }
20+
21+ int n = 4;
22+ char buf[MAX_BUF] = "/tmp";
23+ char *d = strtok(dir+4, "/");
24+ while (d) {
25+ n += must_snprintf(buf+n, MAX_BUF-n, "/%s", d);
26+ if (mkdir(buf, 01777) < 0) {
27+ return;
28+ }
29+
30+ d = strtok(NULL, "/");
31+ }
32+}
33+
34 int main(int argc, char **argv)
35 {
36 const int NR_ARGS = 3;
37@@ -286,9 +312,11 @@
38 die("dropping privs did not work");
39 }
40
41- //https://wiki.ubuntu.com/SecurityTeam/Specifications/SnappyConfinement#ubuntu-snapp-launch
42-
43- int rc = 0;
44+ mkoldtmpdir();
45+
46+ //https://wiki.ubuntu.com/SecurityTeam/Specifications/SnappyConfinement#ubuntu-snapp-launch
47+
48+ int rc = 0;
49 // set apparmor rules
50 rc = aa_change_onexec(aa_profile);
51 if (rc != 0) {

Subscribers

People subscribed via source and target branches