]> git.saurik.com Git - cydia.git/blame - exec.mm
Themes, automagic SpringBoard, and source data fixes.
[cydia.git] / exec.mm
CommitLineData
51a1ffdf
JF
1#include <Foundation/Foundation.h>
2#include <CoreFoundation/CoreFoundation.h>
3
4#include <sys/types.h>
5#include <pwd.h>
6#include <unistd.h>
7
8#include <stdio.h>
9#include <stdlib.h>
10
11const char *Firmware_ = NULL;
12
13unsigned Major_;
14unsigned Minor_;
15unsigned BugFix_;
16
17#define FW_LEAST(major, minor, bugfix) \
18 (major < Major_ || major == Major_ && \
19 (minor < Minor_ || minor == Minor_ && \
20 bugfix <= BugFix_))
21
22int main(int argc, char *argv[]) {
23 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
24
25 if (NSDictionary *sysver = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"]) {
26 if (NSString *prover = [sysver valueForKey:@"ProductVersion"]) {
5f6bff8c 27 Firmware_ = strdup([prover UTF8String]);
51a1ffdf
JF
28 NSArray *versions = [prover componentsSeparatedByString:@"."];
29 int count = [versions count];
30 Major_ = count > 0 ? [[versions objectAtIndex:0] intValue] : 0;
31 Minor_ = count > 1 ? [[versions objectAtIndex:1] intValue] : 0;
32 BugFix_ = count > 2 ? [[versions objectAtIndex:2] intValue] : 0;
33 }
34 }
35
36 [pool release];
37
38 const char *user;
39 if (FW_LEAST(1,1,3))
40 user = "mobile";
41 else
42 user = "root";
43
44 if (argc == 1)
45 printf("%s\n", user);
46 else {
47 struct passwd *passwd = getpwnam(user);
48
49 if (setreuid(passwd->pw_uid, 0) == -1) {
50 perror("setreuid");
51 exit(1);
52 }
53
54 if (setregid(passwd->pw_gid, 0) == -1) {
55 perror("setregid");
56 exit(1);
57 }
58
59 if (execvp(argv[1], argv + 1) == -1) {
60 perror("execvp");
61 exit(1);
62 }
63 }
64
65 return 0;
66}