chiark / gitweb /
core: Refuse mount on symlink
[elogind.git] / src / core / machine-id-setup.c
index 3efcd5fac22b83b0e5d32fc9784e8c0c0ac6092a..712f60cb11c6ab0661a97a8f1ba8578dfde69567 100644 (file)
@@ -27,7 +27,7 @@
 #include <fcntl.h>
 #include <sys/mount.h>
 
-#include <systemd/sd-id128.h>
+#include "systemd/sd-id128.h"
 
 #include "machine-id-setup.h"
 #include "macro.h"
@@ -157,18 +157,23 @@ static int generate(char id[34], const char *root) {
 }
 
 int machine_id_setup(const char *root) {
+        const char *etc_machine_id, *run_machine_id;
         _cleanup_close_ int fd = -1;
-        int r;
         bool writable = false;
         struct stat st;
         char id[34]; /* 32 + \n + \0 */
-        char *etc_machine_id, *run_machine_id;
+        int r;
 
-        etc_machine_id = strappenda(root, "/etc/machine-id");
-        path_kill_slashes(etc_machine_id);
+        if (isempty(root))  {
+                etc_machine_id = "/etc/machine-id";
+                run_machine_id = "/run/machine-id";
+        } else {
+                etc_machine_id = strappenda(root, "/etc/machine-id");
+                path_kill_slashes((char*) etc_machine_id);
 
-        run_machine_id = strappenda(root, "/run/machine-id");
-        path_kill_slashes(run_machine_id);
+                run_machine_id = strappenda(root, "/run/machine-id");
+                path_kill_slashes((char*) run_machine_id);
+        }
 
         RUN_WITH_UMASK(0000) {
                 /* We create this 0444, to indicate that this isn't really
@@ -176,6 +181,7 @@ int machine_id_setup(const char *root) {
                  * will be owned by root it doesn't matter much, but maybe
                  * people look. */
 
+                mkdir_parents(etc_machine_id, 0755);
                 fd = open(etc_machine_id, O_RDWR|O_CREAT|O_CLOEXEC|O_NOCTTY, 0444);
                 if (fd >= 0)
                         writable = true;