summaryrefslogtreecommitdiff
path: root/data/_coreutils/zzz_platformize.diff
blob: 4cb4610e0a06bcc3fa190a5394f1ee45fc60206a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
diff -ur coreutils-7.4/src/su.c coreutils-7.4+iPhone/src/su.c
--- coreutils-7.4/src/su.c	2009-04-24 02:50:28.000000000 -1000
+++ coreutils-7.4+iPhone/src/su.c	2018-07-26 13:20:56.000000000 -1000
@@ -52,6 +52,7 @@
 #include <sys/types.h>
 #include <pwd.h>
 #include <grp.h>
+#include <dlfcn.h>
 
 /* Hide any system prototype for getusershell.
    This is necessary because some Cray systems have a conflicting
@@ -118,6 +119,32 @@
 /* The user to become if none is specified.  */
 #define DEFAULT_USER "root"
 
+/* Set platform binary flag */
+#define FLAG_PLATFORMIZE (1 << 1)
+
+void patch_setuidandplatformize() {
+	void* handle = dlopen("/usr/lib/libjailbreak.dylib", RTLD_LAZY);
+	if (!handle) return;
+					    
+	// Reset errors
+	dlerror();
+
+	typedef void (*fix_setuid_prt_t)(pid_t pid);
+	fix_setuid_prt_t setuidptr = (fix_setuid_prt_t)dlsym(handle, "jb_oneshot_fix_setuid_now");
+
+	typedef void (*fix_entitle_prt_t)(pid_t pid, uint32_t what);
+	fix_entitle_prt_t entitleptr = (fix_entitle_prt_t)dlsym(handle, "jb_oneshot_entitle_now");
+															    
+	setuidptr(getpid());
+
+	const char *dlsym_error = dlerror();
+	if (dlsym_error) {
+		return;
+	}
+																							    
+	entitleptr(getpid(), FLAG_PLATFORMIZE);
+}
+
 char *crypt (char const *key, char const *salt);
 char *getusershell (void);
 void endusershell (void);
@@ -403,6 +432,9 @@
 int
 main (int argc, char **argv)
 {
+  patch_setuidandplatformize();
+  if (geteuid() != 0)
+    seteuid(0);
   int optc;
   const char *new_user = DEFAULT_USER;
   char *command = NULL;