Skip to content

Commit

Permalink
Only fix permissions of relevant directories rather then the entirety…
Browse files Browse the repository at this point in the history
… of /var/jb/var/mobile, skip permission fixup if either /var/jb/var or /var/jb/var/mobile is a symlink
  • Loading branch information
opa334 committed May 7, 2024
1 parent b85cdc4 commit 644c7d2
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions BaseBin/libjailbreak/src/util.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,19 @@
}
}

void JBFixMobilePermissions(void)
void _JBFixMobilePermissionsOfDirectory(NSString *directoryPath, BOOL recursive)
{
@autoreleasepool {
struct stat s;
struct stat s;
NSURL *directoryURL = [NSURL fileURLWithPath:directoryPath];

// Anything in /var/mobile should owned by mobile...
// For some reason some packages seem to fuck this up, so we automatically fix it every userspace reboot and on rejailbreak
NSString *mobilePath = NSJBRootPath(@"/var/mobile");
NSURL *mobileURL = [NSURL fileURLWithPath:mobilePath];

if (stat(mobileURL.fileSystemRepresentation, &s) == 0) {
if (s.st_uid != 501 || s.st_gid != 501) {
chown(mobileURL.fileSystemRepresentation, 501, 501);
}
if (stat(directoryURL.fileSystemRepresentation, &s) == 0) {
if (s.st_uid != 501 || s.st_gid != 501) {
chown(directoryURL.fileSystemRepresentation, 501, 501);
}
}

NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtURL:mobileURL includingPropertiesForKeys:nil options:0 errorHandler:nil];
if (recursive) {
NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtURL:directoryURL includingPropertiesForKeys:nil options:0 errorHandler:nil];
for (NSURL *fileURL in enumerator) {
if (stat(fileURL.fileSystemRepresentation, &s) == 0) {
if (s.st_uid != 501 || s.st_gid != 501) {
Expand All @@ -42,4 +38,26 @@ void JBFixMobilePermissions(void)
}
}
}
}

void JBFixMobilePermissions(void)
{
@autoreleasepool {
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:NSJBRootPath(@"/var") error:nil];
if ([attributes[NSFileType] isEqualToString:NSFileTypeSymbolicLink]) {
// /var/jb/var is a symlink, abort
return;
}
attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:NSJBRootPath(@"/var/mobile") error:nil];
if ([attributes[NSFileType] isEqualToString:NSFileTypeSymbolicLink]) {
// /var/jb/var/mobile is a symlink, abort
return;
}

_JBFixMobilePermissionsOfDirectory(NSJBRootPath(@"/var/mobile"), NO);
_JBFixMobilePermissionsOfDirectory(NSJBRootPath(@"/var/mobile/Library"), NO);
_JBFixMobilePermissionsOfDirectory(NSJBRootPath(@"/var/mobile/Library/SplashBoard"), YES);
_JBFixMobilePermissionsOfDirectory(NSJBRootPath(@"/var/mobile/Library/Application Support"), YES);
_JBFixMobilePermissionsOfDirectory(NSJBRootPath(@"/var/mobile/Library/Preferences"), YES);
}
}

0 comments on commit 644c7d2

Please sign in to comment.