diff options
| author | Michael Vogt <michael.vogt@gmail.com> | 2016-06-07 09:41:38 +0200 |
|---|---|---|
| committer | Michael Vogt <michael.vogt@gmail.com> | 2016-06-07 09:41:38 +0200 |
| commit | b00f0eba14b5eeea1455c002e8bd1d9df576a693 (patch) | |
| tree | a83d395189c96f3442045527ca2e96bf53f15dc7 | |
| parent | 4a353504e642c6c3604c6ad4d88cfa4b95e29bfe (diff) | |
| parent | ef8e286076e21d0f9c5073b5c2023f716998a9bf (diff) | |
Merge pull request #31 from ubuntu-core/modularity
Remove support for creating user data directory
| -rw-r--r-- | src/main.c | 97 |
1 files changed, 3 insertions, 94 deletions
diff --git a/src/main.c b/src/main.c index 0684291d38..4b7ea6bc81 100644 --- a/src/main.c +++ b/src/main.c @@ -16,110 +16,22 @@ */ #include "config.h" -#include <unistd.h> #include <stdio.h> #include <stdlib.h> -#include <limits.h> -#include <sys/mount.h> +#include <unistd.h> #ifdef STRICT_CONFINEMENT #include <sys/apparmor.h> #endif // ifdef STRICT_CONFINEMENT -#include <errno.h> -#include <sched.h> -#include <string.h> -#include <fcntl.h> -#include "utils.h" -#include "snap.h" #include "classic.h" #include "mount-support.h" +#include "snap.h" +#include "utils.h" #ifdef STRICT_CONFINEMENT #include "seccomp-support.h" #include "udev-support.h" #endif // ifdef STRICT_CONFINEMENT -void mkpath(const char *const path) -{ - // If asked to create an empty path, return immediately. - if (strlen(path) == 0) { - return; - } - // We're going to use strtok_r, which needs to modify the path, so - // we'll make a copy of it. - char *path_copy = strdup(path); - if (path_copy == NULL) { - die("failed to create user data directory"); - } - // Open flags to use while we walk the user data path: - // - Don't follow symlinks - // - Don't allow child access to file descriptor - // - Only open a directory (fail otherwise) - int open_flags = O_NOFOLLOW | O_CLOEXEC | O_DIRECTORY; - - // We're going to create each path segment via openat/mkdirat calls - // instead of mkdir calls, to avoid following symlinks and placing the - // user data directory somewhere we never intended for it to go. The - // first step is to get an initial file descriptor. - int fd = AT_FDCWD; - if (path_copy[0] == '/') { - fd = open("/", open_flags); - if (fd < 0) { - free(path_copy); - die("failed to create user data directory"); - } - } - // strtok_r needs a pointer to keep track of where it is in the string. - char *path_walker; - - // Initialize tokenizer and obtain first path segment. - char *path_segment = strtok_r(path_copy, "/", &path_walker); - while (path_segment) { - // Try to create the directory. It's okay if it already - // existed, but any other error is fatal. - if (mkdirat(fd, path_segment, 0755) < 0 && errno != EEXIST) { - close(fd); // we die regardless of return code - free(path_copy); - die("failed to create user data directory"); - } - // Open the parent directory we just made (and close the - // previous one) so we can continue down the path. - int previous_fd = fd; - fd = openat(fd, path_segment, open_flags); - if (close(previous_fd) != 0) { - free(path_copy); - die("could not close path segment"); - } - if (fd < 0) { - free(path_copy); - die("failed to create user data directory"); - } - // Obtain the next path segment. - path_segment = strtok_r(NULL, "/", &path_walker); - } - - // Close the descriptor for the final directory in the path. - if (close(fd) != 0) { - free(path_copy); - die("could not close final directory"); - } - - free(path_copy); -} - -void setup_user_data() -{ - 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"); - } - - mkpath(user_data); -} - int main(int argc, char **argv) { const int NR_ARGS = 2; @@ -188,9 +100,6 @@ int main(int argc, char **argv) if (real_uid != 0 && getegid() == 0) die("dropping privs did not work"); } - // Ensure that the user data path exists. - setup_user_data(); - // https://wiki.ubuntu.com/SecurityTeam/Specifications/SnappyConfinement #ifdef STRICT_CONFINEMENT |
