1 #include <TargetConditionals.h>
11 #include <sys/types.h>
12 #include <sys/sysctl.h>
14 #include <sys/xattr.h>
15 #include <sys/mount.h>
16 #include <sys/param.h>
17 #include <CommonCrypto/CommonDigest.h>
18 #include <libkern/OSAtomic.h>
21 #include <MobileKeyBag/MobileKeyBag.h>
23 #include "hfs-tests.h"
24 #include "test-utils.h"
27 TEST(chflags
, .run_as_root
= true)
29 #define PROFILECTL "/usr/local/bin/profilectl"
30 #define TEST_DIR "/tmp"
32 int run_chflags(__unused test_ctx_t
*ctx
)
34 // The root file system needs to be HFS
37 assert(statfs("/tmp", &sfs
) == 0);
38 if (strcmp(sfs
.f_fstypename
, "hfs")) {
39 printf("chflags needs hfs as root file system - skipping.\n");
44 asprintf(&file
, "%s/chflags-metadata-test.data", TEST_DIR
);
47 char filedata
[4] = "Asdf";
49 // Change system passcode
50 assert_no_err(systemx(PROFILECTL
, "changepass", "", "1234", NULL
));
53 assert_no_err(systemx(PROFILECTL
, "unlock", "1234", NULL
));
55 // Wait until the device is locked
56 while (MKBGetDeviceLockState(NULL
) != kMobileKeyBagDeviceIsUnlocked
)
59 assert_with_errno((fd
= open(file
,
60 O_CREAT
| O_RDWR
| O_TRUNC
, 0666)) >= 0);
62 check_io(write(fd
, filedata
, sizeof(filedata
)), sizeof(filedata
));
64 // Set the file to class A
65 assert_no_err(fcntl(fd
, F_SETPROTECTIONCLASS
, 1));
67 assert_no_err(fchflags(fd
, UF_IMMUTABLE
));
72 assert_no_err(systemx(PROFILECTL
, "lock", NULL
));
74 // Wait until the device is locked
75 while (MKBGetDeviceLockState(NULL
) != kMobileKeyBagDeviceIsLocked
)
78 // should be able to remove the file.
79 assert_no_err(systemx("/bin/unlink", file
, NULL
));
83 assert_no_err(systemx(PROFILECTL
, "unlock", "1234", NULL
));
85 // Change system passcode back
86 assert_no_err(systemx(PROFILECTL
, "changepass", "1234", "", NULL
));
91 #endif // TARGET_OS_EMBEDDED