forked from canonical/snapd
-
Notifications
You must be signed in to change notification settings - Fork 1
/
user-support.c
71 lines (62 loc) · 2.16 KB
/
user-support.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* Copyright (C) 2015 Canonical Ltd
*
* 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 warranty of
* MERCHANTABILITY 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 <http://www.gnu.org/licenses/>.
*
*/
#include "config.h"
#include "user-support.h"
#include <errno.h>
#include <stdlib.h>
#include <sys/stat.h>
#include "../libsnap-confine-private/string-utils.h"
#include "../libsnap-confine-private/utils.h"
void setup_user_data(void)
{
const char *user_data = getenv("SNAP_USER_DATA");
if (user_data == NULL)
return;
// Only support absolute paths.
if (user_data[0] != '/') {
die("user data directory must be an absolute path");
}
debug("creating user data directory: %s", user_data);
if (sc_nonfatal_mkpath(user_data, 0755) < 0) {
if (errno == EROFS && !sc_startswith(user_data, "/home/")) {
// clear errno or it will be displayed in die()
errno = 0;
die("Sorry, home directories outside of /home are not currently supported. \nSee https://forum.snapcraft.io/t/11209 for details.");
}
die("cannot create user data directory: %s", user_data);
};
}
void setup_user_xdg_runtime_dir(void)
{
const char *xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
if (xdg_runtime_dir == NULL)
return;
// Only support absolute paths.
if (xdg_runtime_dir[0] != '/') {
die("XDG_RUNTIME_DIR must be an absolute path");
}
errno = 0;
debug("creating user XDG_RUNTIME_DIR directory: %s", xdg_runtime_dir);
if (sc_nonfatal_mkpath(xdg_runtime_dir, 0755) < 0) {
die("cannot create user XDG_RUNTIME_DIR directory: %s",
xdg_runtime_dir);
}
// if successfully created the directory (ie, not EEXIST), then chmod it.
if (errno == 0 && chmod(xdg_runtime_dir, 0700) != 0) {
die("cannot change permissions of user XDG_RUNTIME_DIR directory to 0700");
}
}