]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
homework: don't try to shift uidmap for already activated home areas
authorLennart Poettering <lennart@poettering.net>
Wed, 24 Nov 2021 17:31:51 +0000 (18:31 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 24 Nov 2021 17:31:51 +0000 (18:31 +0100)
When we want to operate on an already activated home area we so far
tried to reapply the uidmapping logic. We shouldn't do that, it's
already applied after all.

We only want to apply this for newly activated home areas. Hence check
for the right HomeSetupFlags flag for it HOME_SETUP_ALREADY_ACTIVATED.

The patch is actually in theory a two-liner. Except that so far we don#t
pass the HomeSetupFlags flags down all necessary functions where the
uidmap stuff will eventually run. Hence this larger than intended
commit.

src/home/homework-cifs.c
src/home/homework-cifs.h
src/home/homework-directory.c
src/home/homework-directory.h
src/home/homework-luks.c
src/home/homework-luks.h
src/home/homework.c
src/home/homework.h

index b49b7b3dcdb9db13db2ad501a910f42953813269..ed06d1f221db2b15dcbee6f1eca3972488d1245d 100644 (file)
@@ -145,6 +145,7 @@ int home_setup_cifs(
 
 int home_activate_cifs(
                 UserRecord *h,
+                HomeSetupFlags flags,
                 HomeSetup *setup,
                 PasswordCache *cache,
                 UserRecord **ret_home) {
@@ -165,7 +166,7 @@ int home_activate_cifs(
         if (r < 0)
                 return r;
 
-        r = home_refresh(h, setup, header_home, cache, NULL, &new_home);
+        r = home_refresh(h, flags, setup, header_home, cache, NULL, &new_home);
         if (r < 0)
                 return r;
 
index dda1e0b876d41fb70630599b09ef500b0a5ccd4d..af8c466629ac79c7390c1cdda67072ab1d6c348a 100644 (file)
@@ -6,6 +6,6 @@
 
 int home_setup_cifs(UserRecord *h, HomeSetupFlags flags, HomeSetup *setup);
 
-int home_activate_cifs(UserRecord *h, HomeSetup *setup, PasswordCache *cache, UserRecord **ret_home);
+int home_activate_cifs(UserRecord *h, HomeSetupFlags flags, HomeSetup *setup, PasswordCache *cache, UserRecord **ret_home);
 
 int home_create_cifs(UserRecord *h, HomeSetup *setup, UserRecord **ret_home);
index af13fa026a9502a5a0b1ec5ca77e0a5ef1338512..c2b383b7cd5ab7fa301ff82e62159e30fe072bad 100644 (file)
@@ -58,6 +58,7 @@ int home_setup_directory(UserRecord *h, HomeSetup *setup) {
 
 int home_activate_directory(
                 UserRecord *h,
+                HomeSetupFlags flags,
                 HomeSetup *setup,
                 PasswordCache *cache,
                 UserRecord **ret_home) {
@@ -74,11 +75,11 @@ int home_activate_directory(
         assert_se(hdo = user_record_home_directory(h));
         hd = strdupa_safe(hdo);
 
-        r = home_setup(h, 0, setup, cache, &header_home);
+        r = home_setup(h, flags, setup, cache, &header_home);
         if (r < 0)
                 return r;
 
-        r = home_refresh(h, setup, header_home, cache, NULL, &new_home);
+        r = home_refresh(h, flags, setup, header_home, cache, NULL, &new_home);
         if (r < 0)
                 return r;
 
@@ -279,7 +280,7 @@ int home_resize_directory(
         if (r < 0)
                 return r;
 
-        r = home_maybe_shift_uid(h, setup);
+        r = home_maybe_shift_uid(h, flags, setup);
         if (r < 0)
                 return r;
 
index ecbb2f143cb807dbae50ee3f801aad27a339cfe6..fe03e5deb19cd3ea94212d0ed934e39048625d0c 100644 (file)
@@ -5,6 +5,6 @@
 #include "user-record.h"
 
 int home_setup_directory(UserRecord *h, HomeSetup *setup);
-int home_activate_directory(UserRecord *h, HomeSetup *setup, PasswordCache *cache, UserRecord **ret_home);
+int home_activate_directory(UserRecord *h, HomeSetupFlags flags, HomeSetup *setup, PasswordCache *cache, UserRecord **ret_home);
 int home_create_directory_or_subvolume(UserRecord *h, HomeSetup *setup, UserRecord **ret_home);
 int home_resize_directory(UserRecord *h, HomeSetupFlags flags, HomeSetup *setup, PasswordCache *cache, UserRecord **ret_home);
index 529796ad9c78f18b92744bf45b58afd1cb2fa2b7..2e1c4c61701eb41e8b167aa0135a472b48d14566 100644 (file)
@@ -1511,6 +1511,7 @@ static int home_auto_grow_luks(
 
 int home_activate_luks(
                 UserRecord *h,
+                HomeSetupFlags flags,
                 HomeSetup *setup,
                 PasswordCache *cache,
                 UserRecord **ret_home) {
@@ -1563,6 +1564,7 @@ int home_activate_luks(
 
         r = home_refresh(
                         h,
+                        flags,
                         setup,
                         luks_home_record,
                         cache,
index f0f29b78f7dd1468459f985f6ee774e7fb4bf899..0218de8ccdbc164b24d6568ba2ef3af52232e932 100644 (file)
@@ -7,7 +7,7 @@
 
 int home_setup_luks(UserRecord *h, HomeSetupFlags flags, const char *force_image_path, HomeSetup *setup, PasswordCache *cache, UserRecord **ret_luks_home);
 
-int home_activate_luks(UserRecord *h, HomeSetup *setup, PasswordCache *cache, UserRecord **ret_home);
+int home_activate_luks(UserRecord *h, HomeSetupFlags flags, HomeSetup *setup, PasswordCache *cache, UserRecord **ret_home);
 int home_deactivate_luks(UserRecord *h, HomeSetup *setup);
 int home_trim_luks(UserRecord *h, HomeSetup *setup);
 
index ac52a011edabd86c502fb596223a9aa2d672d185..864171faedc52785deb27722291c1d0361d8e1f2 100644 (file)
@@ -788,6 +788,7 @@ static int chown_recursive_directory(int root_fd, uid_t uid) {
 
 int home_maybe_shift_uid(
                 UserRecord *h,
+                HomeSetupFlags flags,
                 HomeSetup *setup) {
 
         _cleanup_close_ int mount_fd = -1;
@@ -797,6 +798,10 @@ int home_maybe_shift_uid(
         assert(setup);
         assert(setup->root_fd >= 0);
 
+        /* If the home dir is already activated, then the UID shift is already applied. */
+        if (FLAGS_SET(flags, HOME_SETUP_ALREADY_ACTIVATED))
+                return 0;
+
         if (fstat(setup->root_fd, &st) < 0)
                 return log_error_errno(errno, "Failed to stat() home directory: %m");
 
@@ -820,6 +825,7 @@ int home_maybe_shift_uid(
 
 int home_refresh(
                 UserRecord *h,
+                HomeSetupFlags flags,
                 HomeSetup *setup,
                 UserRecord *header_home,
                 PasswordCache *cache,
@@ -840,7 +846,7 @@ int home_refresh(
         if (r < 0)
                 return r;
 
-        r = home_maybe_shift_uid(h, setup);
+        r = home_maybe_shift_uid(h, flags, setup);
         if (r < 0)
                 return r;
 
@@ -868,6 +874,7 @@ static int home_activate(UserRecord *h, UserRecord **ret_home) {
         _cleanup_(home_setup_done) HomeSetup setup = HOME_SETUP_INIT;
         _cleanup_(user_record_unrefp) UserRecord *new_home = NULL;
         _cleanup_(password_cache_free) PasswordCache cache = {};
+        HomeSetupFlags flags = 0;
         int r;
 
         assert(h);
@@ -898,7 +905,7 @@ static int home_activate(UserRecord *h, UserRecord **ret_home) {
         switch (user_record_storage(h)) {
 
         case USER_LUKS:
-                r = home_activate_luks(h, &setup, &cache, &new_home);
+                r = home_activate_luks(h, flags, &setup, &cache, &new_home);
                 if (r < 0)
                         return r;
 
@@ -907,14 +914,14 @@ static int home_activate(UserRecord *h, UserRecord **ret_home) {
         case USER_SUBVOLUME:
         case USER_DIRECTORY:
         case USER_FSCRYPT:
-                r = home_activate_directory(h, &setup, &cache, &new_home);
+                r = home_activate_directory(h, flags, &setup, &cache, &new_home);
                 if (r < 0)
                         return r;
 
                 break;
 
         case USER_CIFS:
-                r = home_activate_cifs(h, &setup, &cache, &new_home);
+                r = home_activate_cifs(h, flags, &setup, &cache, &new_home);
                 if (r < 0)
                         return r;
 
index 750ad331c8efe9ad139ae1ee31a9857f04b13ef9..882a3f500b3bfcf0151e7a8f510f6004a600dce1 100644 (file)
@@ -80,9 +80,9 @@ int keyring_unlink(key_serial_t k);
 
 int home_setup(UserRecord *h, HomeSetupFlags flags, HomeSetup *setup, PasswordCache *cache, UserRecord **ret_header_home);
 
-int home_refresh(UserRecord *h, HomeSetup *setup, UserRecord *header_home, PasswordCache *cache, struct statfs *ret_statfs, UserRecord **ret_new_home);
+int home_refresh(UserRecord *h, HomeSetupFlags flags, HomeSetup *setup, UserRecord *header_home, PasswordCache *cache, struct statfs *ret_statfs, UserRecord **ret_new_home);
 
-int home_maybe_shift_uid(UserRecord *h, HomeSetup *setup);
+int home_maybe_shift_uid(UserRecord *h, HomeSetupFlags flags, HomeSetup *setup);
 int home_populate(UserRecord *h, int dir_fd);
 
 int home_load_embedded_identity(UserRecord *h, int root_fd, UserRecord *header_home, UserReconcileMode mode, PasswordCache *cache, UserRecord **ret_embedded_home, UserRecord **ret_new_home);