Skip to content

Commit

Permalink
Merge branch 'opa334:2.x' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
m1337v authored May 5, 2024
2 parents 45bdf6c + 05f030d commit ed75c45
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
14 changes: 1 addition & 13 deletions Application/Dopamine/Jailbreak/DOBootstrapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -525,19 +525,7 @@ - (void)prepareBootstrapWithCompletion:(void (^)(NSError *))completion
[[NSFileManager defaultManager] createDirectoryAtPath:mobilePreferencesPath withIntermediateDirectories:YES attributes:attributes error:nil];
}

// Dopamine 2.0 - 2.0.4 would bootstrap with wrong permissions
// Try to detect and fix it
NSString *mobilePath = NSJBRootPath(@"/var/mobile");
struct stat s;
stat(mobilePath.fileSystemRepresentation, &s);
if (s.st_uid != 501 || s.st_gid != 501) {
chown(mobilePath.fileSystemRepresentation, 501, 501);
NSURL *mobileURL = [NSURL fileURLWithPath:mobilePath];
NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtURL:mobileURL includingPropertiesForKeys:nil options:0 errorHandler:nil];
for (NSURL *fileURL in enumerator) {
chown(fileURL.fileSystemRepresentation, 501, 501);
}
}
JBFixMobilePermissions();

completion(nil);
};
Expand Down
2 changes: 2 additions & 0 deletions BaseBin/launchdhook/src/update.m
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,6 @@ void jbupdate_finalize_stage2(const char *prevVersion, const char *newVersion)
arm64_kcall_init();
#endif
}

JBFixMobilePermissions();
}
2 changes: 2 additions & 0 deletions BaseBin/libjailbreak/src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,6 @@ NSString *NSJBRootPath(NSString *relativePath);
NSString *NSPrebootUUIDPath(NSString *relativePath);
#endif

void JBFixMobilePermissions(void);

#endif
28 changes: 28 additions & 0 deletions BaseBin/libjailbreak/src/util.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "info.h"
#import <Foundation/Foundation.h>
#import "util.h"
#import <sys/stat.h>

NSString *NSJBRootPath(NSString *relativePath)
{
Expand All @@ -14,4 +15,31 @@
@autoreleasepool {
return [NSString stringWithUTF8String:prebootUUIDPath(relativePath.UTF8String)];
}
}

void JBFixMobilePermissions(void)
{
@autoreleasepool {
struct stat s;

// 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);
}
}

NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtURL:mobileURL 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) {
chown(fileURL.fileSystemRepresentation, 501, 501);
}
}
}
}
}

0 comments on commit ed75c45

Please sign in to comment.