X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/888667d540945078e5c1638c157057ed0154acb5..9e738e51025fb8e0cc7ca6ff872b1756c9ce84d4:/MobileCydia.mm?ds=sidebyside diff --git a/MobileCydia.mm b/MobileCydia.mm index 68bd2b28..e0adf360 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -239,29 +239,29 @@ union SplitHash { }; // }}} -static void setreugid(uid_t uid, gid_t gid) { - _assert(setreuid(uid, uid) != -1); - _assert(setregid(gid, gid) != -1); -} +#define seteugid(uid, gid) do { \ + _assert(setreuid(0, uid) != -1); \ + _assert(setregid(0, gid) != -1); \ +} while (false) -static void setreguid(gid_t gid, uid_t uid) { - _assert(setregid(gid, gid) != -1); - _assert(setreuid(uid, uid) != -1); -} +#define seteguid(uid, gid) do { \ + _assert(setregid(0, gid) != -1); \ + _assert(setreuid(0, uid) != -1); \ +} while (false) struct Root { Root() { _trace(); - setreugid(0, 0); + seteugid(0, 0); _assert(pthread_setugid_np(0, 0) != -1); - setreguid(501, 501); + seteguid(501, 501); } ~Root() { _trace(); - setreugid(0, 0); + seteugid(0, 0); _assert(pthread_setugid_np(KAUTH_UID_NONE, KAUTH_GID_NONE) != -1); - setreguid(501, 501); + seteguid(501, 501); } }; @@ -709,6 +709,7 @@ static const NSString *UI_; static int Finish_; static bool RestartSubstrate_; +static bool UpgradeCydia_; static NSArray *Finishes_; #define SpringBoard_ "/System/Library/LaunchDaemons/com.apple.SpringBoard.plist" @@ -819,7 +820,7 @@ bool Changed_; static time_t now_; bool IsWildcat_; -static CGFloat ScreenScale_; +CGFloat ScreenScale_; static NSString *Idiom_; static _H Firmware_; static NSString *Major_; @@ -3132,6 +3133,10 @@ struct PackageNameOrdering : } } - (NSArray *) warnings { +@synchronized (database_) { + if ([database_ era] != era_ || file_.end()) + return nil; + NSMutableArray *warnings([NSMutableArray arrayWithCapacity:4]); const char *name(iterator_.Name()); @@ -3152,6 +3157,7 @@ struct PackageNameOrdering : bool user = false; bool _private = false; bool stash = false; + bool dbstash = false; bool dsstore = false; bool repository = [[self section] isEqualToString:@"Repositories"]; @@ -3166,6 +3172,8 @@ struct PackageNameOrdering : _private = true; else if (!stash && [file isEqualToString:@"/var/stash"]) stash = true; + else if (!dbstash && [file isEqualToString:@"/var/db/stash"]) + dbstash = true; else if (!dsstore && [file hasSuffix:@"/.DS_Store"]) dsstore = true; @@ -3178,12 +3186,14 @@ struct PackageNameOrdering : [warnings addObject:[NSString stringWithFormat:UCLocalize("FILES_INSTALLED_TO"), @"/private"]]; if (stash) [warnings addObject:[NSString stringWithFormat:UCLocalize("FILES_INSTALLED_TO"), @"/var/stash"]]; + if (dbstash) + [warnings addObject:[NSString stringWithFormat:UCLocalize("FILES_INSTALLED_TO"), @"/var/db/stash"]]; if (dsstore) [warnings addObject:[NSString stringWithFormat:UCLocalize("FILES_INSTALLED_TO"), @".DS_Store"]]; } return [warnings count] == 0 ? nil : warnings; -} +} } - (NSArray *) applications { NSString *me([[NSBundle mainBundle] bundleIdentifier]); @@ -4946,6 +4956,10 @@ static _H Diversions_; return [CydiaWebViewController requestWithHeaders:[super webView:view resource:resource willSendRequest:request redirectResponse:response fromDataSource:source]]; } +- (NSURLRequest *) webThreadWebView:(WebView *)view resource:(id)resource willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source { + return [CydiaWebViewController requestWithHeaders:[super webThreadWebView:view resource:resource willSendRequest:request redirectResponse:response fromDataSource:source]]; +} + + (NSURLRequest *) requestWithHeaders:(NSURLRequest *)request { NSMutableURLRequest *copy([[request mutableCopy] autorelease]); @@ -5167,6 +5181,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { issues_ = [NSMutableArray arrayWithCapacity:4]; + UpgradeCydia_ = false; + for (Package *package in packages) { pkgCache::PkgIterator iterator([package iterator]); NSString *name([package id]); @@ -5278,6 +5294,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [removes addObject:name]; } + if ([name isEqualToString:@"cydia"]) + UpgradeCydia_ = true; + substrate_ |= DepSubstrate(policy->GetCandidateVer(iterator)); substrate_ |= DepSubstrate(iterator.CurrentVer()); } @@ -6299,10 +6318,13 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { if ([context isEqualToString:@"modify"]) { if (button != [sheet cancelButtonIndex]) { - [self performSelector:@selector(_clickButtonWithName:) withObject:buttons_[button].first afterDelay:0]; + if (IsWildcat_) + [self performSelector:@selector(_clickButtonWithName:) withObject:buttons_[button].first afterDelay:0]; + else + [self _clickButtonWithName:buttons_[button].first]; } - [sheet dismissWithClickedButtonIndex:-1 animated:YES]; + [sheet dismissWithClickedButtonIndex:button animated:YES]; } } @@ -7106,9 +7128,11 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi // on the iPad, this view controller is ALSO visible. :( if (IsWildcat_) - if (UIViewController *top = [self topViewController]) - if (top != visible) - [top reloadData]; + if (UIViewController *modal = [self modalViewController]) + if ([modal modalPresentationStyle] == UIModalPresentationFormSheet) + if (UIViewController *top = [self topViewController]) + if (top != visible) + [top reloadData]; } - (void) unloadData { @@ -8601,7 +8625,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi case 1: { NSString *href = [[alert textField] text]; - static Pcre href_r("^http(s?)://[^# ]*$"); + static Pcre href_r("^(http(s?)://|file:///)[^# ]*$"); if (!href_r(href)) { UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:Colon_, Error_, UCLocalize("INVALID_URL")] @@ -9056,7 +9080,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi if (NSData *data = [NSPropertyListSerialization dataFromPropertyList:Metadata_ format:NSPropertyListBinaryFormat_v1_0 errorDescription:&error]) { _trace(); NSError *error(nil); - if (!_root([data writeToFile:@"/var/lib/cydia/metadata.plist" options:NSAtomicWrite error:&error])); + if (!_root([data writeToFile:@"/var/lib/cydia/metadata.plist" options:NSAtomicWrite error:&error])) NSLog(@"failure to save metadata data: %@", error); _trace(); @@ -9099,7 +9123,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi bool recently = false; if (update != nil) { NSTimeInterval interval([update timeIntervalSinceNow]); - if (interval <= 0 && interval > -(15*60)) + if (interval > -(15*60)) recently = true; } @@ -9168,6 +9192,7 @@ _profile(reloadDataWithInvocation) [self setApplicationIconBadgeNumber:0]; } + Queuing_ = false; [self _updateData]; if (hud != nil) @@ -9210,8 +9235,6 @@ _end - (void) presentModalViewController:(UIViewController *)controller force:(BOOL)force { UINavigationController *navigation([[[UINavigationController alloc] initWithRootViewController:controller] autorelease]); - if (IsWildcat_) - [navigation setModalPresentationStyle:UIModalPresentationFormSheet]; UIViewController *parent; if (emulated_ == nil) @@ -9223,6 +9246,8 @@ _end parent = tabbar_; } + if (IsWildcat_) + [navigation setModalPresentationStyle:UIModalPresentationFormSheet]; [parent presentModalViewController:navigation animated:YES]; } @@ -9358,7 +9383,14 @@ _end - (void) _uicache { _trace(); - system("/usr/bin/uicache"); + + if (UpgradeCydia_ && Finish_ > 0) { + seteugid(0, 0); + system("su -c /usr/bin/uicache mobile"); + } else { + system("/usr/bin/uicache"); + } + _trace(); } @@ -9722,6 +9754,8 @@ _end } - (void) applicationDidEnterBackground:(UIApplication *)application { + if (kCFCoreFoundationVersionNumber < 1000 && [self isSafeToSuspend]) + return [self terminateWithSuccess]; [self saveState]; } @@ -9732,12 +9766,12 @@ _end NSTimeInterval interval([closed timeIntervalSinceNow]); - if (interval <= -(30)) { + if (interval <= -(30*60)) { [tabbar_ setSelectedIndex:0]; [[[tabbar_ viewControllers] objectAtIndex:0] popToRootViewControllerAnimated:NO]; } - if (interval <= -(15)) { + if (interval <= -(15*60)) { if (IsReachable("cydia.saurik.com")) { [tabbar_ beginUpdate]; [appcache_ reloadURLWithCache:YES]; @@ -9990,7 +10024,6 @@ _trace(); NSDate *closed = [Metadata_ objectForKey:@"LastClosed"]; if (valid && closed != nil) { NSTimeInterval interval([closed timeIntervalSinceNow]); - // XXX: Is 30 minutes the optimal time here? if (interval <= -(30*60)) valid = NO; } @@ -10137,7 +10170,8 @@ MSHook(id, NSUserDefaults$objectForKey$, NSUserDefaults *self, SEL _cmd, NSStrin } int main(int argc, char *argv[]) { - setreugid(501, 501); + seteugid(0, 0); + seteguid(501, 501); NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]); @@ -10454,7 +10488,8 @@ int main(int argc, char *argv[]) { _root(CydiaWriteSources()); _trace(); - _root(MetaFile_.Open("/var/lib/cydia/metadata.cb0")); + mkdir("/var/mobile/Library/Cydia", 0755); + MetaFile_.Open("/var/mobile/Library/Cydia/metadata.cb0"); _trace(); if (Packages_ != nil) { @@ -10486,6 +10521,9 @@ int main(int argc, char *argv[]) { /*if (substrate && access("/Library/MobileSubstrate/MobileSubstrate.dylib", F_OK) == 0) dlopen("/Library/MobileSubstrate/MobileSubstrate.dylib", RTLD_LAZY | RTLD_GLOBAL);*/ + if (kCFCoreFoundationVersionNumber > 1000) + _root(system([[NSString stringWithFormat:@"/usr/libexec/cydia/setnsfpn /var/lib"] UTF8String])); + int version([[NSString stringWithContentsOfFile:@"/var/lib/cydia/firmware.ver"] intValue]); if (access("/User", F_OK) != 0 || version != 6) {