chcon: fix issues with recurse and retval for retained files
authorsagivd <sagivdev@gmail.com>
Sat, 25 Aug 2018 10:49:24 +0000 (13:49 +0300)
committerDenys Vlasenko <vda.linux@googlemail.com>
Mon, 3 Sep 2018 14:02:26 +0000 (16:02 +0200)
- recurse is not acting as expected (looks like broken old code)
- when not using verbose output, return value for retained files is 1,
  which is not expected.

Signed-off-by: sagivd <sagivdev@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
selinux/chcon.c

index 3ddb2dd46d21bdee59d3c64b79858b7edd8ac62d..92eb76737578c1eebaa053092533202a8f4ab0d0 100644 (file)
@@ -131,8 +131,10 @@ static int FAST_FUNC change_filedir_context(
                        bb_error_msg("can't change context of %s to %s",
                                        fname, context_string);
                }
-       } else if (option_mask32 & OPT_VERBOSE) {
-               printf("context of %s retained as %s\n", fname, context_string);
+       } else {
+               if (option_mask32 & OPT_VERBOSE) {
+                       printf("context of %s retained as %s\n", fname, context_string);
+               }
                rc = TRUE;
        }
 skip:
@@ -202,7 +204,7 @@ int chcon_main(int argc UNUSED_PARAM, char **argv)
                fname[fname_len] = '\0';
 
                if (recursive_action(fname,
-                                       1<<option_mask32 & OPT_RECURSIVE,
+                                       ((option_mask32 & OPT_RECURSIVE) ? ACTION_RECURSIVE : 0),
                                        change_filedir_context,
                                        change_filedir_context,
                                        NULL, 0) != TRUE)